mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb/WebGL2: Check if WebGLSync object belongs to the current context
This commit is contained in:
parent
3d2874bc4e
commit
3005cc30b4
Notes:
github-actions[bot]
2025-10-21 21:33:59 +00:00
Author: https://github.com/Lubrsi
Commit: 3005cc30b4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6538
Reviewed-by: https://github.com/gmta ✅
4 changed files with 47 additions and 5 deletions
|
|
@ -756,21 +756,53 @@ GC::Root<WebGLSync> WebGL2RenderingContextImpl::fence_sync(WebIDL::UnsignedLong
|
|||
void WebGL2RenderingContextImpl::delete_sync(GC::Root<WebGLSync> sync)
|
||||
{
|
||||
m_context->make_current();
|
||||
glDeleteSync((GLsync)(sync ? sync->sync_handle() : nullptr));
|
||||
|
||||
GLsync sync_handle = nullptr;
|
||||
if (sync) {
|
||||
auto handle_or_error = sync->sync_handle(this);
|
||||
if (handle_or_error.is_error()) {
|
||||
set_error(GL_INVALID_OPERATION);
|
||||
return;
|
||||
}
|
||||
sync_handle = static_cast<GLsync>(handle_or_error.release_value());
|
||||
}
|
||||
|
||||
glDeleteSync(sync_handle);
|
||||
}
|
||||
|
||||
WebIDL::UnsignedLong WebGL2RenderingContextImpl::client_wait_sync(GC::Root<WebGLSync> sync, WebIDL::UnsignedLong flags, WebIDL::UnsignedLongLong timeout)
|
||||
{
|
||||
m_context->make_current();
|
||||
return glClientWaitSync((GLsync)(sync ? sync->sync_handle() : nullptr), flags, timeout);
|
||||
|
||||
GLsync sync_handle = nullptr;
|
||||
if (sync) {
|
||||
auto handle_or_error = sync->sync_handle(this);
|
||||
if (handle_or_error.is_error()) {
|
||||
set_error(GL_INVALID_OPERATION);
|
||||
return GL_WAIT_FAILED;
|
||||
}
|
||||
sync_handle = static_cast<GLsync>(handle_or_error.release_value());
|
||||
}
|
||||
|
||||
return glClientWaitSync(sync_handle, flags, timeout);
|
||||
}
|
||||
|
||||
JS::Value WebGL2RenderingContextImpl::get_sync_parameter(GC::Root<WebGLSync> sync, WebIDL::UnsignedLong pname)
|
||||
{
|
||||
m_context->make_current();
|
||||
|
||||
GLsync sync_handle = nullptr;
|
||||
if (sync) {
|
||||
auto handle_or_error = sync->sync_handle(this);
|
||||
if (handle_or_error.is_error()) {
|
||||
set_error(GL_INVALID_OPERATION);
|
||||
return JS::js_null();
|
||||
}
|
||||
sync_handle = static_cast<GLsync>(handle_or_error.release_value());
|
||||
}
|
||||
|
||||
GLint result = 0;
|
||||
glGetSynciv((GLsync)(sync ? sync->sync_handle() : nullptr), pname, 1, nullptr, &result);
|
||||
glGetSynciv(sync_handle, pname, 1, nullptr, &result);
|
||||
return JS::Value(result);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,9 +34,10 @@ protected:
|
|||
|
||||
bool invalidated() const { return m_invalidated; }
|
||||
|
||||
private:
|
||||
// FIXME: It should be GC::Ptr instead of raw pointer, but we need to make WebGLRenderingContextBase inherit from PlatformObject first.
|
||||
WebGLRenderingContextBase* m_context;
|
||||
|
||||
private:
|
||||
GLuint m_handle { 0 };
|
||||
|
||||
bool m_invalidated { false };
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include <LibWeb/Bindings/WebGLSyncPrototype.h>
|
||||
#include <LibWeb/WebGL/WebGLSync.h>
|
||||
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
namespace Web::WebGL {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(WebGLSync);
|
||||
|
|
@ -32,4 +34,11 @@ void WebGLSync::initialize(JS::Realm& realm)
|
|||
Base::initialize(realm);
|
||||
}
|
||||
|
||||
ErrorOr<GLsyncInternal> WebGLSync::sync_handle(WebGLRenderingContextBase const* context) const
|
||||
{
|
||||
if (context == m_context)
|
||||
return m_sync_handle;
|
||||
return Error::from_errno(GL_INVALID_OPERATION);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public:
|
|||
|
||||
virtual ~WebGLSync() override;
|
||||
|
||||
GLsyncInternal sync_handle() const { return m_sync_handle; }
|
||||
ErrorOr<GLsyncInternal> sync_handle(WebGLRenderingContextBase const* context) const;
|
||||
|
||||
protected:
|
||||
explicit WebGLSync(JS::Realm&, WebGLRenderingContextBase&, GLsyncInternal handle);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue