diff --git a/Libraries/LibWeb/WebGL/Types.h b/Libraries/LibWeb/WebGL/Types.h index 3fabe9b9ce6..19f80c93e92 100644 --- a/Libraries/LibWeb/WebGL/Types.h +++ b/Libraries/LibWeb/WebGL/Types.h @@ -12,5 +12,6 @@ namespace Web::WebGL { using GLenum = unsigned int; +using GLuint = unsigned int; } diff --git a/Libraries/LibWeb/WebGL/WebGLBuffer.cpp b/Libraries/LibWeb/WebGL/WebGLBuffer.cpp index 3f8ff3331ad..3085b249ce9 100644 --- a/Libraries/LibWeb/WebGL/WebGLBuffer.cpp +++ b/Libraries/LibWeb/WebGL/WebGLBuffer.cpp @@ -1,11 +1,13 @@ /* * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #include +#include #include #include @@ -13,9 +15,9 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLBuffer); -GC::Ptr WebGLBuffer::create(JS::Realm& realm, GLuint handle) +GC::Ref WebGLBuffer::create(JS::Realm& realm, GLuint handle) { - return realm.heap().allocate(realm, handle); + return realm.create(realm, handle); } WebGLBuffer::WebGLBuffer(JS::Realm& realm, GLuint handle) @@ -25,4 +27,10 @@ WebGLBuffer::WebGLBuffer(JS::Realm& realm, GLuint handle) WebGLBuffer::~WebGLBuffer() = default; +void WebGLBuffer::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLBuffer); +} + } diff --git a/Libraries/LibWeb/WebGL/WebGLBuffer.h b/Libraries/LibWeb/WebGL/WebGLBuffer.h index 2e9ca1166a2..6171a647c6f 100644 --- a/Libraries/LibWeb/WebGL/WebGLBuffer.h +++ b/Libraries/LibWeb/WebGL/WebGLBuffer.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ @@ -17,12 +18,14 @@ class WebGLBuffer final : public WebGLObject { GC_DECLARE_ALLOCATOR(WebGLBuffer); public: - static GC::Ptr create(JS::Realm& realm, GLuint handle); + static GC::Ref create(JS::Realm& realm, GLuint handle); virtual ~WebGLBuffer(); protected: explicit WebGLBuffer(JS::Realm&, GLuint handle); + + virtual void initialize(JS::Realm&) override; }; } diff --git a/Libraries/LibWeb/WebGL/WebGLFramebuffer.cpp b/Libraries/LibWeb/WebGL/WebGLFramebuffer.cpp index 6da513a11fd..5fe785ef1ee 100644 --- a/Libraries/LibWeb/WebGL/WebGLFramebuffer.cpp +++ b/Libraries/LibWeb/WebGL/WebGLFramebuffer.cpp @@ -1,10 +1,12 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #include +#include #include #include @@ -12,9 +14,9 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLFramebuffer); -GC::Ptr WebGLFramebuffer::create(JS::Realm& realm, GLuint handle) +GC::Ref WebGLFramebuffer::create(JS::Realm& realm, GLuint handle) { - return realm.heap().allocate(realm, handle); + return realm.create(realm, handle); } WebGLFramebuffer::WebGLFramebuffer(JS::Realm& realm, GLuint handle) @@ -24,4 +26,10 @@ WebGLFramebuffer::WebGLFramebuffer(JS::Realm& realm, GLuint handle) WebGLFramebuffer::~WebGLFramebuffer() = default; +void WebGLFramebuffer::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLFramebuffer); +} + } diff --git a/Libraries/LibWeb/WebGL/WebGLFramebuffer.h b/Libraries/LibWeb/WebGL/WebGLFramebuffer.h index f5d5f5d77e7..456fea99053 100644 --- a/Libraries/LibWeb/WebGL/WebGLFramebuffer.h +++ b/Libraries/LibWeb/WebGL/WebGLFramebuffer.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ @@ -15,12 +16,14 @@ class WebGLFramebuffer final : public WebGLObject { GC_DECLARE_ALLOCATOR(WebGLFramebuffer); public: - static GC::Ptr create(JS::Realm& realm, GLuint handle); + static GC::Ref create(JS::Realm& realm, GLuint handle); virtual ~WebGLFramebuffer(); protected: explicit WebGLFramebuffer(JS::Realm&, GLuint handle); + + virtual void initialize(JS::Realm&) override; }; } diff --git a/Libraries/LibWeb/WebGL/WebGLObject.cpp b/Libraries/LibWeb/WebGL/WebGLObject.cpp index 3b3345bf128..d5ec2089762 100644 --- a/Libraries/LibWeb/WebGL/WebGLObject.cpp +++ b/Libraries/LibWeb/WebGL/WebGLObject.cpp @@ -1,10 +1,13 @@ /* * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include namespace Web::WebGL { @@ -17,4 +20,10 @@ WebGLObject::WebGLObject(JS::Realm& realm, GLuint handle) WebGLObject::~WebGLObject() = default; +void WebGLObject::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLObject); +} + } diff --git a/Libraries/LibWeb/WebGL/WebGLObject.h b/Libraries/LibWeb/WebGL/WebGLObject.h index cb9772865d1..9683a0d2e97 100644 --- a/Libraries/LibWeb/WebGL/WebGLObject.h +++ b/Libraries/LibWeb/WebGL/WebGLObject.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ @@ -10,8 +11,6 @@ #include #include -typedef unsigned int GLuint; - namespace Web::WebGL { class WebGLObject : public Bindings::PlatformObject { @@ -28,6 +27,8 @@ public: protected: explicit WebGLObject(JS::Realm&, GLuint handle); + virtual void initialize(JS::Realm&) override; + bool invalidated() const { return m_invalidated; } private: diff --git a/Libraries/LibWeb/WebGL/WebGLProgram.cpp b/Libraries/LibWeb/WebGL/WebGLProgram.cpp index fc071de0969..09c1bf90ed4 100644 --- a/Libraries/LibWeb/WebGL/WebGLProgram.cpp +++ b/Libraries/LibWeb/WebGL/WebGLProgram.cpp @@ -1,11 +1,13 @@ /* * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #include +#include #include #include @@ -13,9 +15,9 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLProgram); -GC::Ptr WebGLProgram::create(JS::Realm& realm, GLuint handle) +GC::Ref WebGLProgram::create(JS::Realm& realm, GLuint handle) { - return realm.heap().allocate(realm, handle); + return realm.create(realm, handle); } WebGLProgram::WebGLProgram(JS::Realm& realm, GLuint handle) @@ -25,4 +27,10 @@ WebGLProgram::WebGLProgram(JS::Realm& realm, GLuint handle) WebGLProgram::~WebGLProgram() = default; +void WebGLProgram::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLProgram); +} + } diff --git a/Libraries/LibWeb/WebGL/WebGLProgram.h b/Libraries/LibWeb/WebGL/WebGLProgram.h index e322028f9bd..97de2cd238d 100644 --- a/Libraries/LibWeb/WebGL/WebGLProgram.h +++ b/Libraries/LibWeb/WebGL/WebGLProgram.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ @@ -17,12 +18,14 @@ class WebGLProgram final : public WebGLObject { GC_DECLARE_ALLOCATOR(WebGLProgram); public: - static GC::Ptr create(JS::Realm& realm, GLuint handle); + static GC::Ref create(JS::Realm& realm, GLuint handle); virtual ~WebGLProgram(); protected: explicit WebGLProgram(JS::Realm&, GLuint handle); + + virtual void initialize(JS::Realm&) override; }; } diff --git a/Libraries/LibWeb/WebGL/WebGLRenderbuffer.cpp b/Libraries/LibWeb/WebGL/WebGLRenderbuffer.cpp index 3d79d1ca20f..dad9d3f52ae 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderbuffer.cpp +++ b/Libraries/LibWeb/WebGL/WebGLRenderbuffer.cpp @@ -1,10 +1,12 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #include +#include #include #include @@ -12,9 +14,9 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLRenderbuffer); -GC::Ptr WebGLRenderbuffer::create(JS::Realm& realm, GLuint handle) +GC::Ref WebGLRenderbuffer::create(JS::Realm& realm, GLuint handle) { - return realm.heap().allocate(realm, handle); + return realm.create(realm, handle); } WebGLRenderbuffer::WebGLRenderbuffer(JS::Realm& realm, GLuint handle) @@ -24,4 +26,10 @@ WebGLRenderbuffer::WebGLRenderbuffer(JS::Realm& realm, GLuint handle) WebGLRenderbuffer::~WebGLRenderbuffer() = default; +void WebGLRenderbuffer::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLRenderbuffer); +} + } diff --git a/Libraries/LibWeb/WebGL/WebGLRenderbuffer.h b/Libraries/LibWeb/WebGL/WebGLRenderbuffer.h index 826c2800f44..ebdfa359b15 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderbuffer.h +++ b/Libraries/LibWeb/WebGL/WebGLRenderbuffer.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2024, Jelle Raaijmakers + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ @@ -15,12 +16,14 @@ class WebGLRenderbuffer final : public WebGLObject { GC_DECLARE_ALLOCATOR(WebGLRenderbuffer); public: - static GC::Ptr create(JS::Realm& realm, GLuint handle); + static GC::Ref create(JS::Realm& realm, GLuint handle); virtual ~WebGLRenderbuffer(); protected: explicit WebGLRenderbuffer(JS::Realm&, GLuint handle); + + virtual void initialize(JS::Realm&) override; }; } diff --git a/Libraries/LibWeb/WebGL/WebGLShader.cpp b/Libraries/LibWeb/WebGL/WebGLShader.cpp index 7293eafe923..0e79bbfe129 100644 --- a/Libraries/LibWeb/WebGL/WebGLShader.cpp +++ b/Libraries/LibWeb/WebGL/WebGLShader.cpp @@ -1,11 +1,13 @@ /* * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #include +#include #include #include @@ -13,9 +15,9 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLShader); -GC::Ptr WebGLShader::create(JS::Realm& realm, GLuint handle) +GC::Ref WebGLShader::create(JS::Realm& realm, GLuint handle) { - return realm.heap().allocate(realm, handle); + return realm.create(realm, handle); } WebGLShader::WebGLShader(JS::Realm& realm, GLuint handle) @@ -25,4 +27,10 @@ WebGLShader::WebGLShader(JS::Realm& realm, GLuint handle) WebGLShader::~WebGLShader() = default; +void WebGLShader::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLShader); +} + } diff --git a/Libraries/LibWeb/WebGL/WebGLShader.h b/Libraries/LibWeb/WebGL/WebGLShader.h index 7af54e66e30..f82bda03b71 100644 --- a/Libraries/LibWeb/WebGL/WebGLShader.h +++ b/Libraries/LibWeb/WebGL/WebGLShader.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ @@ -17,12 +18,14 @@ class WebGLShader final : public WebGLObject { GC_DECLARE_ALLOCATOR(WebGLShader); public: - static GC::Ptr create(JS::Realm& realm, GLuint handle); + static GC::Ref create(JS::Realm& realm, GLuint handle); virtual ~WebGLShader(); protected: explicit WebGLShader(JS::Realm&, GLuint handle); + + virtual void initialize(JS::Realm&) override; }; } diff --git a/Libraries/LibWeb/WebGL/WebGLTexture.cpp b/Libraries/LibWeb/WebGL/WebGLTexture.cpp index 60a5c1cf1ec..6a8a57d0fea 100644 --- a/Libraries/LibWeb/WebGL/WebGLTexture.cpp +++ b/Libraries/LibWeb/WebGL/WebGLTexture.cpp @@ -1,11 +1,13 @@ /* * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #include +#include #include #include @@ -13,9 +15,9 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLTexture); -GC::Ptr WebGLTexture::create(JS::Realm& realm, GLuint handle) +GC::Ref WebGLTexture::create(JS::Realm& realm, GLuint handle) { - return realm.heap().allocate(realm, handle); + return realm.create(realm, handle); } WebGLTexture::WebGLTexture(JS::Realm& realm, GLuint handle) @@ -25,4 +27,10 @@ WebGLTexture::WebGLTexture(JS::Realm& realm, GLuint handle) WebGLTexture::~WebGLTexture() = default; +void WebGLTexture::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLTexture); +} + } diff --git a/Libraries/LibWeb/WebGL/WebGLTexture.h b/Libraries/LibWeb/WebGL/WebGLTexture.h index 7d82eca0cfa..fb2763c199b 100644 --- a/Libraries/LibWeb/WebGL/WebGLTexture.h +++ b/Libraries/LibWeb/WebGL/WebGLTexture.h @@ -1,6 +1,7 @@ /* * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ @@ -17,12 +18,14 @@ class WebGLTexture final : public WebGLObject { GC_DECLARE_ALLOCATOR(WebGLTexture); public: - static GC::Ptr create(JS::Realm& realm, GLuint handle); + static GC::Ref create(JS::Realm& realm, GLuint handle); virtual ~WebGLTexture(); protected: explicit WebGLTexture(JS::Realm&, GLuint handle); + + virtual void initialize(JS::Realm&) override; }; } diff --git a/Libraries/LibWeb/WebGL/WebGLUniformLocation.cpp b/Libraries/LibWeb/WebGL/WebGLUniformLocation.cpp index 437693026aa..48c4dfa8c9d 100644 --- a/Libraries/LibWeb/WebGL/WebGLUniformLocation.cpp +++ b/Libraries/LibWeb/WebGL/WebGLUniformLocation.cpp @@ -1,11 +1,13 @@ /* * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2024, Aliaksandr Kalenik + * Copyright (c) 2024, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #include +#include #include #include @@ -13,16 +15,23 @@ namespace Web::WebGL { GC_DEFINE_ALLOCATOR(WebGLUniformLocation); -GC::Ptr WebGLUniformLocation::create(JS::Realm& realm, GLuint handle) +GC::Ref WebGLUniformLocation::create(JS::Realm& realm, GLuint handle) { - return realm.heap().allocate(realm, handle); + return realm.create(realm, handle); } WebGLUniformLocation::WebGLUniformLocation(JS::Realm& realm, GLuint handle) - : WebGLObject(realm, handle) + : Bindings::PlatformObject(realm) + , m_handle(handle) { } WebGLUniformLocation::~WebGLUniformLocation() = default; +void WebGLUniformLocation::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(WebGLUniformLocation); +} + } diff --git a/Libraries/LibWeb/WebGL/WebGLUniformLocation.h b/Libraries/LibWeb/WebGL/WebGLUniformLocation.h index 7cc28b16309..bf9d7d25035 100644 --- a/Libraries/LibWeb/WebGL/WebGLUniformLocation.h +++ b/Libraries/LibWeb/WebGL/WebGLUniformLocation.h @@ -7,21 +7,28 @@ #pragma once -#include +#include +#include namespace Web::WebGL { -class WebGLUniformLocation final : public WebGLObject { - WEB_PLATFORM_OBJECT(WebGLUniformLocation, WebGLObject); +class WebGLUniformLocation final : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(WebGLUniformLocation, Bindings::PlatformObject); GC_DECLARE_ALLOCATOR(WebGLUniformLocation); public: - static GC::Ptr create(JS::Realm& realm, GLuint handle); + static GC::Ref create(JS::Realm& realm, GLuint handle); virtual ~WebGLUniformLocation(); + GLuint handle() const { return m_handle; } + protected: explicit WebGLUniformLocation(JS::Realm&, GLuint handle); + + virtual void initialize(JS::Realm&) override; + + GLuint m_handle { 0 }; }; }