Truly independent web browser
LibWeb: Report a drawing buffer at least 1×1 for a WebGL canvas
sideshowbarkera72b0d371e87
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rsindex 06f7b91945e..0153c18174c 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs@@ -16,8 +16,8 @@ use super::fingerprint::verify_that_rust_and_cpp_agree_on_layouts_and_constants;use super::host::CppTransport;use super::proxy::recorder::Proxy;use super::state::{- ContextParameters, ContextRef, ContextState, MAX_WEBGL_DRAWING_BUFFER_DIMENSION, RenderingContext, WebGL1, WebGL2,- WebGLVersion,+ ContextParameters, ContextRef, ContextState, RenderingContext, WebGL1, WebGL2, WebGLVersion,+ drawing_buffer_dimension,};use super::web_gl_rendering_context::WebGLPowerPreference;use super::web_gl_rendering_context_base::WebGLContextAttributes;@@ -200,10 +200,9 @@ pub extern "C" fn web_webgl_context_canvas_id(context: &ContextCell, out_canvas_#[unsafe(no_mangle)]pub extern "C" fn web_webgl_context_set_size(context: &ContextCell, width: i32, height: i32) {with_context(context, |context| {- context.proxy.set_size(- width.clamp(1, MAX_WEBGL_DRAWING_BUFFER_DIMENSION),- height.clamp(1, MAX_WEBGL_DRAWING_BUFFER_DIMENSION),- );+ context+ .proxy+ .set_size(drawing_buffer_dimension(width), drawing_buffer_dimension(height));});}diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/state.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/state.rsindex ecfc03a50a7..c2215702f69 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/state.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/state.rs@@ -44,6 +44,13 @@ use crate::canvas_2d::canvas::CanvasImageSourceKind;pub(crate) const MAX_WEBGL_DRAWING_BUFFER_DIMENSION: i32 = 16384;+/// The width or height of the drawing buffer for a canvas of this width or height.+// https://registry.khronos.org/webgl/specs/latest/1.0/#THE_DRAWING_BUFFER+// A 0x0 canvas yields a 1x1 drawing buffer, and a canvas larger than the implementation supports yields a smaller one.+pub(crate) fn drawing_buffer_dimension(canvas_dimension: i32) -> i32 {+ canvas_dimension.clamp(1, MAX_WEBGL_DRAWING_BUFFER_DIMENSION)+}+#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) enum WebGLVersion {WebGL1,diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_rendering_context_base.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_rendering_context_base.rsindex 7add76eed73..f1fd1955d1e 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_rendering_context_base.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_rendering_context_base.rs@@ -25,9 +25,7 @@ use super::constants::{GL_UNPACK_SKIP_ROWS, GL_VERTEX_ATTRIB_ARRAY_POINTER, GL_VERTEX_SHADER,};use super::gl_string::{utf8_bytes, utf16_string_from_gl_string};-use super::state::{- Binding, ContextState, MAX_WEBGL_DRAWING_BUFFER_DIMENSION, RenderingContext, Version, WebGLVersion,-};+use super::state::{Binding, ContextState, RenderingContext, Version, WebGLVersion, drawing_buffer_dimension};use super::types::Float32List;use super::web_gl_active_info::WebGLActiveInfo;use super::web_gl_buffer::WebGLBuffer;@@ -124,12 +122,12 @@ impl<V: Version> RenderingContext<V> {pub(crate) fn drawing_buffer_width(&self, _: &mut CallContext) -> WebIdlResult<i32> {let (width, _) = ContextState::canvas(self).bitmap_size();- Ok(width.min(MAX_WEBGL_DRAWING_BUFFER_DIMENSION))+ Ok(drawing_buffer_dimension(width))}pub(crate) fn drawing_buffer_height(&self, _: &mut CallContext) -> WebIdlResult<i32> {let (_, height) = ContextState::canvas(self).bitmap_size();- Ok(height.min(MAX_WEBGL_DRAWING_BUFFER_DIMENSION))+ Ok(drawing_buffer_dimension(height))}pub(crate) fn get_context_attributes(&self, _: &mut CallContext) -> WebIdlResult<Option<WebGLContextAttributes>> {diff --git a/Tests/LibWeb/Text/expected/WebGL/drawing-buffer-at-least-one-pixel.txt b/Tests/LibWeb/Text/expected/WebGL/drawing-buffer-at-least-one-pixel.txtnew file mode 100644index 00000000000..aa78c518fbe--- /dev/null+++ b/Tests/LibWeb/Text/expected/WebGL/drawing-buffer-at-least-one-pixel.txt@@ -0,0 +1,8 @@+webgl canvas 300x150: drawing buffer 300x150+webgl canvas 1956x0: drawing buffer 1956x1+webgl canvas 0x0: drawing buffer 1x1+webgl framebuffer as large as a 1956x0 canvas's drawing buffer is complete: true+webgl2 canvas 300x150: drawing buffer 300x150+webgl2 canvas 1956x0: drawing buffer 1956x1+webgl2 canvas 0x0: drawing buffer 1x1+webgl2 framebuffer as large as a 1956x0 canvas's drawing buffer is complete: truediff --git a/Tests/LibWeb/Text/input/WebGL/drawing-buffer-at-least-one-pixel.html b/Tests/LibWeb/Text/input/WebGL/drawing-buffer-at-least-one-pixel.htmlnew file mode 100644index 00000000000..0e367f79818--- /dev/null+++ b/Tests/LibWeb/Text/input/WebGL/drawing-buffer-at-least-one-pixel.html@@ -0,0 +1,29 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ // A canvas width or height under 1 gives a drawing buffer 1 pixel in that dimension, so a framebuffer as large as+ // the drawing buffer is complete.+ test(() => {+ for (const type of ["webgl", "webgl2"]) {+ for (const [width, height] of [[300, 150], [1956, 0], [0, 0]]) {+ const canvas = document.createElement("canvas");+ canvas.width = width;+ canvas.height = height;+ const gl = canvas.getContext(type);+ println(`${type} canvas ${width}x${height}: drawing buffer ${gl.drawingBufferWidth}x${gl.drawingBufferHeight}`);+ }++ const canvas = document.createElement("canvas");+ canvas.width = 1956;+ canvas.height = 0;+ const gl = canvas.getContext(type);+ const texture = gl.createTexture();+ gl.bindTexture(gl.TEXTURE_2D, texture);+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.drawingBufferWidth, gl.drawingBufferHeight, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);+ gl.bindFramebuffer(gl.FRAMEBUFFER, gl.createFramebuffer());+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);+ const complete = gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE;+ println(`${type} framebuffer as large as a 1956x0 canvas's drawing buffer is complete: ${complete}`);+ }+ });+</script>