ladybird/Libraries/LibWeb/WebGL/OpenGLContext.h
Erik Kurzinger df09472d4d LibGfx: Free WebGL painting surface resources on resize
If a WebGL canvas is resized through the set_size function, we will
re-create the painting surface. However, this currently leaks all of the
associated EGL/OpenGL objects. This change introduces the
free_surface_resources function which will free all resources associated
with the painting surface. It will be called before allocating a new
surface and during context destruction. It keeps track of the OpenGL
texture for the color buffer in m_impl instead of just storing it on the
stack.
2025-08-19 00:30:22 +02:00

59 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;
#ifdef AK_OS_MACOS
void free_surface_resources();
#endif
};
}