From c817eb8d2b7911b88abde75551b8106590f78608 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Thu, 5 Dec 2024 02:59:00 +0100 Subject: [PATCH] LibWeb/WebGL: Implement getContextAttributes() --- Libraries/LibWeb/WebGL/Types.idl | 5 ----- Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp | 8 ++++---- Libraries/LibWeb/WebGL/WebGLContextAttributes.h | 9 ++------- Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp | 7 +++++++ Libraries/LibWeb/WebGL/WebGLRenderingContext.h | 1 + Libraries/LibWeb/WebGL/WebGLRenderingContext.idl | 6 ++++++ Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl | 2 +- .../LibWeb/GenerateWebGLRenderingContext.cpp | 2 +- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Libraries/LibWeb/WebGL/Types.idl b/Libraries/LibWeb/WebGL/Types.idl index 251f3bbce8a..9dbb3e229b5 100644 --- a/Libraries/LibWeb/WebGL/Types.idl +++ b/Libraries/LibWeb/WebGL/Types.idl @@ -10,8 +10,3 @@ typedef long long GLsizeiptr; typedef unrestricted float GLfloat; typedef unrestricted float GLclampf; -enum WebGLPowerPreference { - "default", - "low-power", - "high-performance" -}; diff --git a/Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp b/Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp index b83be8c7d98..8837d55e092 100644 --- a/Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp +++ b/Libraries/LibWeb/WebGL/WebGLContextAttributes.cpp @@ -96,17 +96,17 @@ JS::ThrowCompletionOr convert_value_to_context_attribute else power_preference = TRY(value.as_object().get("powerPreference")); - WebGLPowerPreference power_preference_value { WebGLPowerPreference::Default }; + Bindings::WebGLPowerPreference power_preference_value { Bindings::WebGLPowerPreference::Default }; if (!power_preference.is_undefined()) { auto power_preference_string = TRY(power_preference.to_string(vm)); if (power_preference_string == "high-performance"sv) - power_preference_value = WebGLPowerPreference::HighPerformance; + power_preference_value = Bindings::WebGLPowerPreference::HighPerformance; else if (power_preference_string == "low-power"sv) - power_preference_value = WebGLPowerPreference::LowPower; + power_preference_value = Bindings::WebGLPowerPreference::LowPower; else if (power_preference_string == "default"sv) - power_preference_value = WebGLPowerPreference::Default; + power_preference_value = Bindings::WebGLPowerPreference::Default; else return vm.throw_completion(JS::ErrorType::InvalidEnumerationValue, power_preference_string, "WebGLPowerPreference"); } diff --git a/Libraries/LibWeb/WebGL/WebGLContextAttributes.h b/Libraries/LibWeb/WebGL/WebGLContextAttributes.h index 196d1798fba..7802ab70325 100644 --- a/Libraries/LibWeb/WebGL/WebGLContextAttributes.h +++ b/Libraries/LibWeb/WebGL/WebGLContextAttributes.h @@ -7,15 +7,10 @@ #pragma once #include +#include namespace Web::WebGL { -enum class WebGLPowerPreference { - Default, - LowPower, - HighPerformance, -}; - // https://www.khronos.org/registry/webgl/specs/latest/1.0/#WEBGLCONTEXTATTRIBUTES struct WebGLContextAttributes { bool alpha { true }; @@ -24,7 +19,7 @@ struct WebGLContextAttributes { bool antialias { true }; bool premultiplied_alpha { true }; bool preserve_drawing_buffer { false }; - WebGLPowerPreference power_preference { WebGLPowerPreference::Default }; + Bindings::WebGLPowerPreference power_preference { Bindings::WebGLPowerPreference::Default }; bool fail_if_major_performance_caveat { false }; bool desynchronized { false }; }; diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp b/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp index be56135d4d9..a61e71d5c21 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContext.cpp @@ -131,6 +131,13 @@ bool WebGLRenderingContext::is_context_lost() const return m_context_lost; } +Optional WebGLRenderingContext::get_context_attributes() +{ + if (is_context_lost()) + return {}; + return m_actual_context_parameters; +} + void WebGLRenderingContext::set_size(Gfx::IntSize const& size) { context().set_size(size); diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContext.h b/Libraries/LibWeb/WebGL/WebGLRenderingContext.h index c0482d736da..5f02b10fdfc 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContext.h +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContext.h @@ -32,6 +32,7 @@ public: GC::Ref canvas_for_binding() const; bool is_context_lost() const; + Optional get_context_attributes(); RefPtr surface(); void allocate_painting_surface_if_needed(); diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContext.idl b/Libraries/LibWeb/WebGL/WebGLRenderingContext.idl index f5cc645ae82..a233cec6c52 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContext.idl +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContext.idl @@ -8,3 +8,9 @@ interface WebGLRenderingContext { WebGLRenderingContext includes WebGLRenderingContextBase; WebGLRenderingContext includes WebGLRenderingContextOverloads; + +enum WebGLPowerPreference { + "default", + "low-power", + "high-performance" +}; diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl index c8c55cbb80c..3939c58e746 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.idl @@ -38,7 +38,7 @@ interface mixin WebGLRenderingContextBase { [FIXME] attribute PredefinedColorSpace drawingBufferColorSpace; [FIXME] attribute PredefinedColorSpace unpackColorSpace; - [FIXME] WebGLContextAttributes? getContextAttributes(); + WebGLContextAttributes? getContextAttributes(); [FIXME] boolean isContextLost(); sequence? getSupportedExtensions(); diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp index 8004fe7ed00..1317bedba9c 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp @@ -345,7 +345,7 @@ public: continue; } - if (function.name == "getSupportedExtensions"sv || function.name == "getExtension"sv) { + if (function.name == "getSupportedExtensions"sv || function.name == "getExtension"sv || function.name == "getContextAttributes"sv) { // Implemented in WebGLRenderingContext continue; }