LibWeb/WebGL: Implement getContextAttributes()

This commit is contained in:
Aliaksandr Kalenik 2024-12-05 02:59:00 +01:00 committed by Andreas Kling
commit c817eb8d2b
Notes: github-actions[bot] 2024-12-05 08:57:56 +00:00
8 changed files with 22 additions and 18 deletions

View file

@ -10,8 +10,3 @@ typedef long long GLsizeiptr;
typedef unrestricted float GLfloat; typedef unrestricted float GLfloat;
typedef unrestricted float GLclampf; typedef unrestricted float GLclampf;
enum WebGLPowerPreference {
"default",
"low-power",
"high-performance"
};

View file

@ -96,17 +96,17 @@ JS::ThrowCompletionOr<WebGLContextAttributes> convert_value_to_context_attribute
else else
power_preference = TRY(value.as_object().get("powerPreference")); 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()) { if (!power_preference.is_undefined()) {
auto power_preference_string = TRY(power_preference.to_string(vm)); auto power_preference_string = TRY(power_preference.to_string(vm));
if (power_preference_string == "high-performance"sv) 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) 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) else if (power_preference_string == "default"sv)
power_preference_value = WebGLPowerPreference::Default; power_preference_value = Bindings::WebGLPowerPreference::Default;
else else
return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidEnumerationValue, power_preference_string, "WebGLPowerPreference"); return vm.throw_completion<JS::TypeError>(JS::ErrorType::InvalidEnumerationValue, power_preference_string, "WebGLPowerPreference");
} }

View file

@ -7,15 +7,10 @@
#pragma once #pragma once
#include <LibJS/Forward.h> #include <LibJS/Forward.h>
#include <LibWeb/Bindings/WebGLRenderingContextPrototype.h>
namespace Web::WebGL { namespace Web::WebGL {
enum class WebGLPowerPreference {
Default,
LowPower,
HighPerformance,
};
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#WEBGLCONTEXTATTRIBUTES // https://www.khronos.org/registry/webgl/specs/latest/1.0/#WEBGLCONTEXTATTRIBUTES
struct WebGLContextAttributes { struct WebGLContextAttributes {
bool alpha { true }; bool alpha { true };
@ -24,7 +19,7 @@ struct WebGLContextAttributes {
bool antialias { true }; bool antialias { true };
bool premultiplied_alpha { true }; bool premultiplied_alpha { true };
bool preserve_drawing_buffer { false }; 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 fail_if_major_performance_caveat { false };
bool desynchronized { false }; bool desynchronized { false };
}; };

View file

@ -131,6 +131,13 @@ bool WebGLRenderingContext::is_context_lost() const
return m_context_lost; return m_context_lost;
} }
Optional<WebGLContextAttributes> WebGLRenderingContext::get_context_attributes()
{
if (is_context_lost())
return {};
return m_actual_context_parameters;
}
void WebGLRenderingContext::set_size(Gfx::IntSize const& size) void WebGLRenderingContext::set_size(Gfx::IntSize const& size)
{ {
context().set_size(size); context().set_size(size);

View file

@ -32,6 +32,7 @@ public:
GC::Ref<HTML::HTMLCanvasElement> canvas_for_binding() const; GC::Ref<HTML::HTMLCanvasElement> canvas_for_binding() const;
bool is_context_lost() const; bool is_context_lost() const;
Optional<WebGLContextAttributes> get_context_attributes();
RefPtr<Gfx::PaintingSurface> surface(); RefPtr<Gfx::PaintingSurface> surface();
void allocate_painting_surface_if_needed(); void allocate_painting_surface_if_needed();

View file

@ -8,3 +8,9 @@ interface WebGLRenderingContext {
WebGLRenderingContext includes WebGLRenderingContextBase; WebGLRenderingContext includes WebGLRenderingContextBase;
WebGLRenderingContext includes WebGLRenderingContextOverloads; WebGLRenderingContext includes WebGLRenderingContextOverloads;
enum WebGLPowerPreference {
"default",
"low-power",
"high-performance"
};

View file

@ -38,7 +38,7 @@ interface mixin WebGLRenderingContextBase {
[FIXME] attribute PredefinedColorSpace drawingBufferColorSpace; [FIXME] attribute PredefinedColorSpace drawingBufferColorSpace;
[FIXME] attribute PredefinedColorSpace unpackColorSpace; [FIXME] attribute PredefinedColorSpace unpackColorSpace;
[FIXME] WebGLContextAttributes? getContextAttributes(); WebGLContextAttributes? getContextAttributes();
[FIXME] boolean isContextLost(); [FIXME] boolean isContextLost();
sequence<DOMString>? getSupportedExtensions(); sequence<DOMString>? getSupportedExtensions();

View file

@ -345,7 +345,7 @@ public:
continue; 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 // Implemented in WebGLRenderingContext
continue; continue;
} }