mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 15:27:42 +00:00
LibWeb/WebGL: Forward the render context ref count to HTMLCanvasElement
This allows HTMLCanvasElement and WebGL rendering contexts to share their lifetime, as JS allows them to arbitrarily access them at any time and WebGLRCB.canvas expects a non-null return value.
This commit is contained in:
parent
adf8341c4e
commit
0ec8a19a34
2 changed files with 18 additions and 9 deletions
|
@ -12,7 +12,7 @@
|
||||||
namespace Web::WebGL {
|
namespace Web::WebGL {
|
||||||
|
|
||||||
WebGLRenderingContextBase::WebGLRenderingContextBase(HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)
|
WebGLRenderingContextBase::WebGLRenderingContextBase(HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters)
|
||||||
: m_canvas_element(canvas_element)
|
: RefCountForwarder(canvas_element)
|
||||||
, m_context(move(context))
|
, m_context(move(context))
|
||||||
, m_context_creation_parameters(move(context_creation_parameters))
|
, m_context_creation_parameters(move(context_creation_parameters))
|
||||||
, m_actual_context_parameters(move(actual_context_parameters))
|
, m_actual_context_parameters(move(actual_context_parameters))
|
||||||
|
@ -67,15 +67,23 @@ void WebGLRenderingContextBase::present()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HTML::HTMLCanvasElement& WebGLRenderingContextBase::canvas_element()
|
||||||
|
{
|
||||||
|
return ref_count_target();
|
||||||
|
}
|
||||||
|
|
||||||
|
HTML::HTMLCanvasElement const& WebGLRenderingContextBase::canvas_element() const
|
||||||
|
{
|
||||||
|
return ref_count_target();
|
||||||
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextBase::needs_to_present()
|
void WebGLRenderingContextBase::needs_to_present()
|
||||||
{
|
{
|
||||||
m_should_present = true;
|
m_should_present = true;
|
||||||
|
|
||||||
if (!m_canvas_element)
|
if (!canvas_element().layout_node())
|
||||||
return;
|
return;
|
||||||
if (!m_canvas_element->layout_node())
|
canvas_element().layout_node()->set_needs_display();
|
||||||
return;
|
|
||||||
m_canvas_element->layout_node()->set_needs_display();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebGLRenderingContextBase::set_error(GLenum error)
|
void WebGLRenderingContextBase::set_error(GLenum error)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/RefCounted.h>
|
#include <AK/RefCountForwarder.h>
|
||||||
#include <AK/WeakPtr.h>
|
#include <AK/WeakPtr.h>
|
||||||
#include <AK/Weakable.h>
|
#include <AK/Weakable.h>
|
||||||
#include <LibGL/GLContext.h>
|
#include <LibGL/GLContext.h>
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
namespace Web::WebGL {
|
namespace Web::WebGL {
|
||||||
|
|
||||||
class WebGLRenderingContextBase
|
class WebGLRenderingContextBase
|
||||||
: public RefCounted<WebGLRenderingContextBase>
|
: public RefCountForwarder<HTML::HTMLCanvasElement>
|
||||||
, public Weakable<WebGLRenderingContextBase> {
|
, public Weakable<WebGLRenderingContextBase> {
|
||||||
public:
|
public:
|
||||||
virtual ~WebGLRenderingContextBase();
|
virtual ~WebGLRenderingContextBase();
|
||||||
|
@ -63,8 +63,6 @@ protected:
|
||||||
WebGLRenderingContextBase(HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters);
|
WebGLRenderingContextBase(HTML::HTMLCanvasElement& canvas_element, NonnullOwnPtr<GL::GLContext> context, WebGLContextAttributes context_creation_parameters, WebGLContextAttributes actual_context_parameters);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WeakPtr<HTML::HTMLCanvasElement> m_canvas_element;
|
|
||||||
|
|
||||||
NonnullOwnPtr<GL::GLContext> m_context;
|
NonnullOwnPtr<GL::GLContext> m_context;
|
||||||
|
|
||||||
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#context-creation-parameters
|
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#context-creation-parameters
|
||||||
|
@ -87,6 +85,9 @@ private:
|
||||||
|
|
||||||
GLenum m_error { GL_NO_ERROR };
|
GLenum m_error { GL_NO_ERROR };
|
||||||
|
|
||||||
|
HTML::HTMLCanvasElement& canvas_element();
|
||||||
|
HTML::HTMLCanvasElement const& canvas_element() const;
|
||||||
|
|
||||||
void needs_to_present();
|
void needs_to_present();
|
||||||
void set_error(GLenum error);
|
void set_error(GLenum error);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue