ladybird/Libraries/LibWeb/WebGL/OpenGLContext.h
Aliaksandr Kalenik a80babffb6 LibWeb+Compositor: Run canvas contexts in the Compositor
Canvas rendering is a major remaining path where WebContent directly
owns GPU-facing drawing state. Back 2D and WebGL canvas contexts with
remote Compositor transports, so WebContent talks to canvas surfaces
through IPC while the Compositor owns the rasterization resources.

This is a large step toward GPU sandboxing because canvas GPU work now
lives behind the Compositor boundary. It also gives OffscreenCanvas the
process-independent canvas plumbing that HTMLCanvasElement now uses,
making worker-owned canvases possible without another WebContent-local
rendering path.
2026-06-17 19:07:32 +02:00

78 lines
2 KiB
C++

/*
* Copyright (c) 2024, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullOwnPtr.h>
#include <AK/NonnullRefPtr.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Vector.h>
#include <LibGfx/BitmapExport.h>
#include <LibGfx/Forward.h>
#include <LibGfx/Size.h>
#include <LibWeb/Export.h>
#include <LibWeb/WebGL/GLFunctions.h>
namespace Web::WebGL {
WEB_API Optional<Gfx::ExportFormat> texture_export_format(GLenum format, GLenum type);
class WEB_API OpenGLContext : public GLFunctions {
public:
using WebGLVersion = WebGL::WebGLVersion;
struct DrawingBufferOptions {
bool depth;
bool stencil;
bool antialias;
};
static OwnPtr<OpenGLContext> create(NonnullRefPtr<Gfx::SkiaBackendContext>, WebGLVersion, DrawingBufferOptions);
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, DrawingBufferOptions);
~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_opengl_extensions();
private:
NonnullRefPtr<Gfx::SkiaBackendContext> m_skia_backend_context;
Gfx::IntSize m_size;
RefPtr<Gfx::PaintingSurface> m_painting_surface;
#ifdef AK_OS_MACOS
OwnPtr<Gfx::SharedImageBuffer> m_shared_image_buffer;
#endif
NonnullOwnPtr<Impl> m_impl;
Optional<Vector<String>> m_requestable_extensions;
WebGLVersion m_webgl_version;
[[maybe_unused]] DrawingBufferOptions m_drawing_buffer_options;
void free_surface_resources();
#if defined(AK_OS_MACOS)
void allocate_iosurface_painting_surface();
#elif defined(USE_VULKAN_DMABUF_IMAGES)
void allocate_vkimage_painting_surface();
#endif
};
}