ladybird/Libraries/LibWeb/WebGL/OpenGLContext.h
Erik Kurzinger 8fd1df4f8b
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
LibGfx: Enable WebGL on Linux
This enabled WebGL on Linux. It uses ANGLE's OpenGL backend running atop
EGL_PLATFORM_SURFACELESS_MESA. Eventually we should probably switch to
the Vulkan backend but that doesn't seem to be enabled in the vcpkg
angle package. Anyway, switching later should be trivial.

The painting surface is allocated through Vulkan and then imported into
EGL as a dma-buf. The DRM format modifier mechanism, along with Vulkan
initializing the image with VK_IMAGE_LAYOUT_GENERAL, should ensure
surface compatibility across the two APIs.

For now, we will synchronize rendering and presentation using glFinish,
although this is admittedly suboptimal. Really we should grab an
EGLSync, export that to an fd, import it into Skia and have it wait for
it before reading from the image. That can be implemented in a future
change, though.
2025-08-19 00:30:22 +02:00

57 lines
1.3 KiB
C++

/*
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGfx/Forward.h>
#include <LibGfx/Size.h>
namespace Web::WebGL {
class OpenGLContext {
public:
enum class WebGLVersion {
WebGL1,
WebGL2,
};
static OwnPtr<OpenGLContext> create(NonnullRefPtr<Gfx::SkiaBackendContext>, WebGLVersion);
void notify_content_will_change();
void clear_buffer_to_default_values();
void allocate_painting_surface_if_needed();
struct Impl;
OpenGLContext(NonnullRefPtr<Gfx::SkiaBackendContext>, Impl, WebGLVersion);
~OpenGLContext();
void make_current();
void present(bool preserve_drawing_buffer);
void set_size(Gfx::IntSize const&);
RefPtr<Gfx::PaintingSurface> surface();
u32 default_framebuffer() const;
u32 default_renderbuffer() const;
Vector<String> get_supported_extensions();
void request_extension(char const* extension_name);
private:
NonnullRefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;
Gfx::IntSize m_size;
RefPtr<Gfx::PaintingSurface> m_painting_surface;
NonnullOwnPtr<Impl> m_impl;
Optional<Vector<String>> m_requestable_extensions;
WebGLVersion m_webgl_version;
void free_surface_resources();
};
}