Skip to content

Truly independent web browser

LibWeb: Convert WebGLContextAttributes in Rust

Aliaksandr Kalenik96a5294af4ab
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs
index e4a37eefc1b..6fd7887a9e7 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs
@@ -32,7 +32,7 @@ fn extension_names(names: ak::Span<'_, ak::Span<'_, u8>>) -> Vec<Vec<u8>> {
names.as_slice().iter().map(|name| name.as_slice().to_vec()).collect()
}
-/// Mirrors `Web::WebGL::RustContextAttributes`.
+/// Mirrors `Web::WebGL::ContextAttributes`.
#[derive(Clone, Copy)]
#[repr(C)]
pub struct ContextAttributes {
@@ -283,6 +283,41 @@ pub unsafe extern "C" fn web_webgl_context_restore(
});
}
+/// Converts the options of getContext() to the dictionary, and answers true with the exception that the conversion
+/// threw.
+///
+/// # Safety
+///
+/// `vm` must be the live VM and `value` a live value.
+#[cfg(web_idl_bindings)]
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_webgl_context_attributes_from_value(
+ vm: *mut c_void,
+ value: u64,
+ out_context_attributes: &mut ContextAttributes,
+ out_exception: &mut u64,
+) -> bool {
+ use crate::bindings::conversions::FromJs;
+
+ // SAFETY: The caller passes the live VM and a live value.
+ let (vm, value) = unsafe {
+ (
+ &*vm.cast::<libjs_rust::api::Vm>(),
+ libjs_rust::api::Value::from_raw(value),
+ )
+ };
+ match WebGLContextAttributes::from_js(vm, value) {
+ Ok(context_attributes) => {
+ *out_context_attributes = context_attributes.into();
+ false
+ }
+ Err(throw) => {
+ *out_exception = throw.value().to_raw();
+ true
+ }
+ }
+}
+
/// # Safety
///
/// `vm` must be the live VM, `realm` a live realm, and `type` a raw AK::Utf16String that the call takes over.
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 8e57ee03740..373dc5f1477 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -904,7 +904,6 @@ set(SOURCES
WebDriver/UserPrompt.cpp
WebGL/EventNames.cpp
WebGL/RemoteWebGLTransportFFI.cpp
- WebGL/WebGLContextAttributes.cpp
WebGL/WebGLRenderingContextBase.cpp
WebIDL/AbstractOperations.cpp
WebIDL/AsyncIterator.cpp
diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h
index d3ef21e5e27..5951f13bc5b 100644
--- a/Libraries/LibWeb/Forward.h
+++ b/Libraries/LibWeb/Forward.h
@@ -1220,7 +1220,6 @@ namespace Web::WebGL {
class RemoteWebGLTransport;
class WebGL2RenderingContext;
-struct WebGLContextAttributes;
class WebGLRenderingContext;
class WebGLRenderingContextBase;
diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp
index 95780900db1..0bfa53ace31 100644
--- a/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.cpp
@@ -392,7 +392,7 @@ JS::ThrowCompletionOr<HTMLCanvasElement::HasOrCreatedContext> HTMLCanvasElement:
if (!m_context.has<Empty>())
return m_context.has<GC::Ref<ContextType>>() ? HasOrCreatedContext::Yes : HasOrCreatedContext::No;
- auto context_attributes = TRY(WebGL::convert_value_to_context_attributes_dictionary(vm(), options));
+ auto context_attributes = TRY(WebGL::convert_to_context_attributes(vm(), options));
TRY(throw_if_control_transferred_to_offscreen());
// AD-HOC: Converting the options can run script that creates a context.
if (!m_context.has<Empty>())
diff --git a/Libraries/LibWeb/HTML/HTMLCanvasElement.h b/Libraries/LibWeb/HTML/HTMLCanvasElement.h
index 1385dfad55e..eaa613f55f5 100644
--- a/Libraries/LibWeb/HTML/HTMLCanvasElement.h
+++ b/Libraries/LibWeb/HTML/HTMLCanvasElement.h
@@ -13,7 +13,6 @@
#include <LibWeb/HTML/Canvas/CanvasHost.h>
#include <LibWeb/HTML/Canvas/CanvasSettings.h>
#include <LibWeb/HTML/HTMLElement.h>
-#include <LibWeb/WebGL/WebGLContextAttributes.h>
#include <LibWebCommon/WebIDL/Types.h>
namespace Web::HTML {
@@ -53,7 +52,6 @@ public:
Yes,
};
HasOrCreatedContext create_2d_context(CanvasRenderingContext2DSettings);
- HasOrCreatedContext create_webgl_context(WebGL::WebGLContextAttributes);
RenderingContext const& context() const { return m_context; }
WebIDL::UnsignedLong width() const;
diff --git a/Libraries/LibWeb/HTML/OffscreenCanvas.cpp b/Libraries/LibWeb/HTML/OffscreenCanvas.cpp
index 72717f30e12..6dc02b611f3 100644
--- a/Libraries/LibWeb/HTML/OffscreenCanvas.cpp
+++ b/Libraries/LibWeb/HTML/OffscreenCanvas.cpp
@@ -35,7 +35,6 @@
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/Platform/FontPlugin.h>
#include <LibWeb/WebGL/WebGL2RenderingContext.h>
-#include <LibWeb/WebGL/WebGLContextAttributes.h>
#include <LibWeb/WebGL/WebGLRenderingContext.h>
#include <LibWeb/WebIDL/DOMException.h>
#include <LibWeb/WebIDL/ExceptionOrUtils.h>
@@ -382,7 +381,7 @@ JS::ThrowCompletionOr<OffscreenCanvas::HasOrCreatedContext> OffscreenCanvas::cre
if (!m_context.has<Empty>())
return m_context.has<GC::Ref<ContextType>>() ? HasOrCreatedContext::Yes : HasOrCreatedContext::No;
- auto context_attributes = TRY(WebGL::convert_value_to_context_attributes_dictionary(vm(), options));
+ auto context_attributes = TRY(WebGL::convert_to_context_attributes(vm(), options));
TRY(throw_if_detached());
// AD-HOC: Converting the options can run script that creates a context.
if (!m_context.has<Empty>())
diff --git a/Libraries/LibWeb/WebGL/WebGL2RenderingContext.h b/Libraries/LibWeb/WebGL/WebGL2RenderingContext.h
index 80ed4226dfe..73e7c340d37 100644
--- a/Libraries/LibWeb/WebGL/WebGL2RenderingContext.h
+++ b/Libraries/LibWeb/WebGL/WebGL2RenderingContext.h
@@ -18,7 +18,7 @@ class WEB_API WebGL2RenderingContext final : public WebGLRenderingContextBase {
WEB_RUST_INTERFACE(WebGL2RenderingContext, web_gl2_rendering_context)
public:
- static GC::Ptr<WebGL2RenderingContext> create(JS::Realm&, CanvasOwner, WebGLContextAttributes const&);
+ static GC::Ptr<WebGL2RenderingContext> create(JS::Realm&, CanvasOwner, ContextAttributes const&);
};
}
diff --git a/Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp b/Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp
deleted file mode 100644
index 50e14614a87..00000000000
--- a/Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (c) 2022, Luke Wilde <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibJS/Runtime/Completion.h>
-#include <LibJS/Runtime/GlobalObject.h>
-#include <LibJS/Runtime/ValueInlines.h>
-#include <LibWeb/WebGL/WebGLContextAttributes.h>
-
-namespace Web::WebGL {
-
-JS::ThrowCompletionOr<WebGLContextAttributes> convert_value_to_context_attributes_dictionary(JS::VM& vm, JS::Value value)
-{
- // NOTE: This code was generated by the IDL code generator and then cleaned up.
- if (!value.is_nullish() && !value.is_object())
- return vm.throw_completion<JS::TypeError>(JS::ErrorType::NotAnObjectOfType, "WebGLContextAttributes");
-
- WebGLContextAttributes context_attributes {};
-
- JS::Value alpha;
- if (value.is_nullish())
- alpha = JS::js_undefined();
- else
- alpha = TRY(value.as_object().get("alpha"_utf16_fly_string));
-
- bool alpha_value;
- if (!alpha.is_undefined())
- alpha_value = alpha.to_boolean();
- else
- alpha_value = true;
-
- context_attributes.alpha = alpha_value;
-
- JS::Value antialias;
- if (value.is_nullish())
- antialias = JS::js_undefined();
- else
- antialias = TRY(value.as_object().get("antialias"_utf16_fly_string));
-
- bool antialias_value;
- if (!antialias.is_undefined())
- antialias_value = antialias.to_boolean();
- else
- antialias_value = true;
-
- context_attributes.antialias = antialias_value;
-
- JS::Value depth;
- if (value.is_nullish())
- depth = JS::js_undefined();
- else
- depth = TRY(value.as_object().get("depth"_utf16_fly_string));
-
- bool depth_value;
- if (!depth.is_undefined())
- depth_value = depth.to_boolean();
- else
- depth_value = true;
-
- context_attributes.depth = depth_value;
-
- JS::Value desynchronized;
- if (value.is_nullish())
- desynchronized = JS::js_undefined();
- else
- desynchronized = TRY(value.as_object().get("desynchronized"_utf16_fly_string));
-
- bool desynchronized_value;
-
- if (!desynchronized.is_undefined())
- desynchronized_value = desynchronized.to_boolean();
- else
- desynchronized_value = false;
-
- context_attributes.desynchronized = desynchronized_value;
-
- JS::Value fail_if_major_performance_caveat;
- if (value.is_nullish())
- fail_if_major_performance_caveat = JS::js_undefined();
- else
- fail_if_major_performance_caveat = TRY(value.as_object().get("failIfMajorPerformanceCaveat"_utf16_fly_string));
-
- bool fail_if_major_performance_caveat_value;
- if (!fail_if_major_performance_caveat.is_undefined())
- fail_if_major_performance_caveat_value = fail_if_major_performance_caveat.to_boolean();
- else
- fail_if_major_performance_caveat_value = false;
-
- context_attributes.fail_if_major_performance_caveat = fail_if_major_performance_caveat_value;
-
- JS::Value power_preference;
- if (value.is_nullish())
- power_preference = JS::js_undefined();
- else
- power_preference = TRY(value.as_object().get("powerPreference"_utf16_fly_string));
-
- Bindings::WebGLPowerPreference power_preference_value { Bindings::WebGLPowerPreference::Default };
-
- if (!power_preference.is_undefined()) {
- auto power_preference_string = TRY(power_preference.to_utf16_string(vm));
-
- if (power_preference_string == "high-performance"sv)
- power_preference_value = Bindings::WebGLPowerPreference::HighPerformance;
- else if (power_preference_string == "low-power"sv)
- power_preference_value = Bindings::WebGLPowerPreference::LowPower;
- else if (power_preference_string == "default"sv)
- power_preference_value = Bindings::WebGLPowerPreference::Default;
- else
- return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidEnumerationValue, power_preference_string, "WebGLPowerPreference");
- }
-
- context_attributes.power_preference = power_preference_value;
-
- JS::Value premultiplied_alpha;
- if (value.is_nullish())
- premultiplied_alpha = JS::js_undefined();
- else
- premultiplied_alpha = TRY(value.as_object().get("premultipliedAlpha"_utf16_fly_string));
-
- bool premultiplied_alpha_value;
-
- if (!premultiplied_alpha.is_undefined())
- premultiplied_alpha_value = premultiplied_alpha.to_boolean();
- else
- premultiplied_alpha_value = true;
-
- context_attributes.premultiplied_alpha = premultiplied_alpha_value;
-
- JS::Value preserve_drawing_buffer;
- if (value.is_nullish())
- preserve_drawing_buffer = JS::js_undefined();
- else
- preserve_drawing_buffer = TRY(value.as_object().get("preserveDrawingBuffer"_utf16_fly_string));
-
- bool preserve_drawing_buffer_value;
- if (!preserve_drawing_buffer.is_undefined())
- preserve_drawing_buffer_value = preserve_drawing_buffer.to_boolean();
- else
- preserve_drawing_buffer_value = false;
-
- context_attributes.preserve_drawing_buffer = preserve_drawing_buffer_value;
-
- JS::Value stencil;
- if (value.is_nullish())
- stencil = JS::js_undefined();
- else
- stencil = TRY(value.as_object().get("stencil"_utf16_fly_string));
-
- bool stencil_value;
-
- if (!stencil.is_undefined())
- stencil_value = stencil.to_boolean();
- else
- stencil_value = false;
-
- context_attributes.stencil = stencil_value;
-
- return context_attributes;
-}
-
-}
diff --git a/Libraries/LibWeb/WebGL/WebGLContextAttributes.h b/Libraries/LibWeb/WebGL/WebGLContextAttributes.h
deleted file mode 100644
index cef22310561..00000000000
--- a/Libraries/LibWeb/WebGL/WebGLContextAttributes.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (c) 2022, Luke Wilde <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibJS/Forward.h>
-#include <LibWeb/Bindings/WebGLRenderingContext.h>
-
-namespace Web::WebGL {
-
-// https://www.khronos.org/registry/webgl/specs/latest/1.0/#WEBGLCONTEXTATTRIBUTES
-struct WebGLContextAttributes {
- bool alpha { true };
- bool depth { true };
- bool stencil { false };
- bool antialias { true };
- bool premultiplied_alpha { true };
- bool preserve_drawing_buffer { false };
- Bindings::WebGLPowerPreference power_preference { Bindings::WebGLPowerPreference::Default };
- bool fail_if_major_performance_caveat { false };
- bool desynchronized { false };
-};
-
-JS::ThrowCompletionOr<WebGLContextAttributes> convert_value_to_context_attributes_dictionary(JS::VM&, JS::Value value);
-
-}
diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContext.h b/Libraries/LibWeb/WebGL/WebGLRenderingContext.h
index 207c9bbb4b6..95f2c3ce8d7 100644
--- a/Libraries/LibWeb/WebGL/WebGLRenderingContext.h
+++ b/Libraries/LibWeb/WebGL/WebGLRenderingContext.h
@@ -17,7 +17,7 @@ class WEB_API WebGLRenderingContext final : public WebGLRenderingContextBase {
WEB_RUST_INTERFACE(WebGLRenderingContext, web_gl_rendering_context)
public:
- static GC::Ptr<WebGLRenderingContext> create(JS::Realm&, CanvasOwner, WebGLContextAttributes const&);
+ static GC::Ptr<WebGLRenderingContext> create(JS::Realm&, CanvasOwner, ContextAttributes const&);
};
}
diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp
index aebcccf8c10..71374cea6c4 100644
--- a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp
+++ b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp
@@ -31,7 +31,6 @@
#include <LibWeb/WebGL/EventNames.h>
#include <LibWeb/WebGL/RemoteWebGLTransport.h>
#include <LibWeb/WebGL/WebGL2RenderingContext.h>
-#include <LibWeb/WebGL/WebGLContextAttributes.h>
#include <LibWeb/WebGL/WebGLRenderingContext.h>
#include <LibWeb/WebGL/WebGLRenderingContextBase.h>
@@ -39,20 +38,6 @@ namespace Web::WebGL {
namespace {
-// `ContextAttributes` of Bindings/Rust/src/web_gl/exports.rs.
-struct RustContextAttributes {
- bool alpha { true };
- bool depth { true };
- bool stencil { false };
- bool antialias { true };
- bool premultiplied_alpha { true };
- bool preserve_drawing_buffer { false };
- // 0 is "default", 1 is "low-power" and 2 is "high-performance".
- u8 power_preference { 0 };
- bool fail_if_major_performance_caveat { false };
- bool desynchronized { false };
-};
-
// `ContextCreationArguments` of Bindings/Rust/src/web_gl/exports.rs.
struct ContextCreationArguments {
void* transport { nullptr };
@@ -61,7 +46,7 @@ struct ContextCreationArguments {
void* canvas { nullptr };
void* canvas_host { nullptr };
bool canvas_is_offscreen { false };
- RustContextAttributes context_attributes;
+ ContextAttributes context_attributes;
ReadonlySpan<ReadonlyBytes> supported_extensions;
};
@@ -97,9 +82,10 @@ void* web_webgl_context_read_back_drawing_buffer(void* context, i32 x, i32 y, i3
bool web_webgl_context_mark_lost(void* context);
void web_webgl_context_set_restore_requested(void* context, bool requested);
bool web_webgl_context_wants_restoring(void* context);
-void web_webgl_context_actual_context_parameters(void* context, RustContextAttributes* out_context_attributes);
+void web_webgl_context_actual_context_parameters(void* context, ContextAttributes* out_context_attributes);
void web_webgl_context_restore(void* context, void* transport, ReadonlySpan<ReadonlyBytes> supported_extensions);
void* web_webgl_context_event_create(JSVM*, void* realm, FlatPtr type);
+bool web_webgl_context_attributes_from_value(JSVM*, JSValue, ContextAttributes* out_context_attributes, JSValue* out_exception);
// What the Rust implementation asks of LibWeb, declared in Bindings/Rust/src/web_gl/canvas.rs.
void web_webgl_canvas_did_change_content(void* canvas_host);
@@ -117,31 +103,13 @@ static void* cell_of(WebGLRenderingContextBase const& context)
return const_cast<WebGLRenderingContextBase*>(&context);
}
-static RustContextAttributes to_rust_context_attributes(WebGLContextAttributes const& context_attributes)
+JS::ThrowCompletionOr<ContextAttributes> convert_to_context_attributes(JS::VM& vm, JS::Value value)
{
- u8 power_preference = 0;
- switch (context_attributes.power_preference) {
- case Bindings::WebGLPowerPreference::Default:
- power_preference = 0;
- break;
- case Bindings::WebGLPowerPreference::LowPower:
- power_preference = 1;
- break;
- case Bindings::WebGLPowerPreference::HighPerformance:
- power_preference = 2;
- break;
- }
- return {
- .alpha = context_attributes.alpha,
- .depth = context_attributes.depth,
- .stencil = context_attributes.stencil,
- .antialias = context_attributes.antialias,
- .premultiplied_alpha = context_attributes.premultiplied_alpha,
- .preserve_drawing_buffer = context_attributes.preserve_drawing_buffer,
- .power_preference = power_preference,
- .fail_if_major_performance_caveat = context_attributes.fail_if_major_performance_caveat,
- .desynchronized = context_attributes.desynchronized,
- };
+ ContextAttributes context_attributes;
+ JSValue exception {};
+ if (web_webgl_context_attributes_from_value(JS::HostABI::vm_to_abi(vm), JS::HostABI::value_to_abi(value), &context_attributes, &exception))
+ return JS::throw_completion(JS::HostABI::value_from_abi(exception));
+ return context_attributes;
}
HTML::CanvasHost& canvas_host_for(CanvasOwner const& canvas)
@@ -216,7 +184,7 @@ Optional<RemoteWebGLContext> create_remote_webgl_context(HTML::CanvasHost& canva
}
-WebGLRenderingContextBase* WebGLRenderingContextBase::create(JS::Realm& realm, CanvasOwner canvas, WebGLContextAttributes const& context_attributes, WebGLVersion webgl_version)
+WebGLRenderingContextBase* WebGLRenderingContextBase::create(JS::Realm& realm, CanvasOwner canvas, ContextAttributes const& context_attributes, WebGLVersion webgl_version)
{
// We should be coming here from getContext being called on a wrapped <canvas> element or OffscreenCanvas.
auto& canvas_host = canvas_host_for(canvas);
@@ -234,18 +202,18 @@ WebGLRenderingContextBase* WebGLRenderingContextBase::create(JS::Realm& realm, C
.canvas = canvas.visit([](auto const& canvas) -> void* { return static_cast<GC::Cell*>(canvas.ptr()); }),
.canvas_host = &canvas_host,
.canvas_is_offscreen = canvas.has<GC::Ref<HTML::OffscreenCanvas>>(),
- .context_attributes = to_rust_context_attributes(context_attributes),
+ .context_attributes = context_attributes,
.supported_extensions = supported_extensions.span(),
};
return static_cast<WebGLRenderingContextBase*>(web_webgl_context_create(JS::HostABI::vm_to_abi(realm.vm()), &arguments));
}
-GC::Ptr<WebGLRenderingContext> WebGLRenderingContext::create(JS::Realm& realm, CanvasOwner canvas, WebGLContextAttributes const& context_attributes)
+GC::Ptr<WebGLRenderingContext> WebGLRenderingContext::create(JS::Realm& realm, CanvasOwner canvas, ContextAttributes const& context_attributes)
{
return static_cast<WebGLRenderingContext*>(WebGLRenderingContextBase::create(realm, canvas, context_attributes, WebGLVersion::WebGL1));
}
-GC::Ptr<WebGL2RenderingContext> WebGL2RenderingContext::create(JS::Realm& realm, CanvasOwner canvas, WebGLContextAttributes const& context_attributes)
+GC::Ptr<WebGL2RenderingContext> WebGL2RenderingContext::create(JS::Realm& realm, CanvasOwner canvas, ContextAttributes const& context_attributes)
{
return static_cast<WebGL2RenderingContext*>(WebGLRenderingContextBase::create(realm, canvas, context_attributes, WebGLVersion::WebGL2));
}
@@ -310,7 +278,7 @@ void WebGLRenderingContextBase::restore_context_after_compositor_reconnect()
// A fresh host context starts with no GL objects; per the spec the page re-creates them
// in its webglcontextrestored handler.
- RustContextAttributes actual_context_parameters;
+ ContextAttributes actual_context_parameters;
web_webgl_context_actual_context_parameters(this, &actual_context_parameters);
auto webgl_version = web_webgl_context_is_webgl2(this) ? WebGLVersion::WebGL2 : WebGLVersion::WebGL1;
auto remote = create_remote_webgl_context(canvas_host(), webgl_version, actual_context_parameters.depth, actual_context_parameters.stencil, actual_context_parameters.antialias);
diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h
index 689bab1be2a..ea4bf2a8878 100644
--- a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h
+++ b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h
@@ -26,6 +26,23 @@ namespace Web::WebGL {
using CanvasOwner = Variant<GC::Ref<HTML::HTMLCanvasElement>, GC::Ref<HTML::OffscreenCanvas>>;
HTML::CanvasHost& canvas_host_for(CanvasOwner const&);
+// https://registry.khronos.org/webgl/specs/latest/1.0/#WEBGLCONTEXTATTRIBUTES
+// `ContextAttributes` of Bindings/Rust/src/web_gl/exports.rs.
+struct ContextAttributes {
+ bool alpha { true };
+ bool depth { true };
+ bool stencil { false };
+ bool antialias { true };
+ bool premultiplied_alpha { true };
+ bool preserve_drawing_buffer { false };
+ // 0 is "default", 1 is "low-power" and 2 is "high-performance".
+ u8 power_preference { 0 };
+ bool fail_if_major_performance_caveat { false };
+ bool desynchronized { false };
+};
+
+JS::ThrowCompletionOr<ContextAttributes> convert_to_context_attributes(JS::VM&, JS::Value);
+
// The C++ side of a WebGLRenderingContext or a WebGL2RenderingContext, which are implemented in Rust
// (Libraries/LibWeb/Bindings/Rust/src/web_gl): what the rest of LibWeb calls, and what the Rust code calls back.
class WEB_API WebGLRenderingContextBase : public Bindings::RustInterfaceCell {
@@ -52,7 +69,7 @@ public:
void restore_context_after_compositor_reconnect();
protected:
- static WebGLRenderingContextBase* create(JS::Realm&, CanvasOwner, WebGLContextAttributes const&, WebGLVersion);
+ static WebGLRenderingContextBase* create(JS::Realm&, CanvasOwner, ContextAttributes const&, WebGLVersion);
};
}
diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl
index a7cf9d62a50..a4430467ea2 100644
--- a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl
+++ b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl
@@ -1,3 +1,4 @@
+[ImplementedIn=Rust]
dictionary WebGLContextAttributes {
boolean alpha = true;
boolean depth = true;