Skip to content

Truly independent web browser

LibCompositing+LibWeb: Check WebGL texture image sizes in Rust

Aliaksandr Kalenikc322cad0bdc2
diff --git a/Libraries/LibCompositing/WebGL/TextureUpload.cpp b/Libraries/LibCompositing/WebGL/TextureUpload.cpp
index 26d32041d8a..4e570081e75 100644
--- a/Libraries/LibCompositing/WebGL/TextureUpload.cpp
+++ b/Libraries/LibCompositing/WebGL/TextureUpload.cpp
@@ -6,7 +6,6 @@
#include <GLES3/gl3.h>
-#include <AK/Checked.h>
#include <AK/Debug.h>
#include <LibCompositing/WebGL/TextureUpload.h>
@@ -70,133 +69,4 @@ Optional<Gfx::ExportFormat> texture_export_format(GLenum format, GLenum type)
return {};
}
-static Optional<size_t> component_count_for_format(GLenum format)
-{
- switch (format) {
- case GL_ALPHA:
- case GL_LUMINANCE:
- case GL_RED:
- case GL_RED_INTEGER:
- case GL_DEPTH_COMPONENT:
- return 1;
- case GL_LUMINANCE_ALPHA:
- case GL_RG:
- case GL_RG_INTEGER:
- return 2;
- case GL_RGB:
- case GL_RGB_INTEGER:
- return 3;
- case GL_RGBA:
- case GL_RGBA_INTEGER:
- return 4;
- default:
- return {};
- }
-}
-
-static Optional<size_t> bytes_per_pixel(GLenum format, GLenum type)
-{
- switch (type) {
- case GL_UNSIGNED_SHORT_5_6_5:
- case GL_UNSIGNED_SHORT_4_4_4_4:
- case GL_UNSIGNED_SHORT_5_5_5_1:
- return 2;
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- case GL_UNSIGNED_INT_10F_11F_11F_REV:
- case GL_UNSIGNED_INT_5_9_9_9_REV:
- case GL_UNSIGNED_INT_24_8:
- return 4;
- case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
- return 8;
- default:
- break;
- }
-
- auto component_count = component_count_for_format(format);
- if (!component_count.has_value())
- return {};
-
- size_t component_size;
- switch (type) {
- case GL_BYTE:
- case GL_UNSIGNED_BYTE:
- component_size = 1;
- break;
- case GL_SHORT:
- case GL_UNSIGNED_SHORT:
- case GL_HALF_FLOAT:
- component_size = 2;
- break;
- case GL_INT:
- case GL_UNSIGNED_INT:
- case GL_FLOAT:
- component_size = 4;
- break;
- default:
- return {};
- }
-
- return *component_count * component_size;
-}
-
-bool is_valid_2d_pixel_unpack_state(GLsizei width, PixelUnpackState const& unpack_state)
-{
- if (width < 0)
- return true;
-
- auto data_store_width = unpack_state.row_length == 0 ? static_cast<size_t>(width) : unpack_state.row_length;
- Checked<size_t> unpacked_row_end = unpack_state.skip_pixels;
- unpacked_row_end += static_cast<size_t>(width);
- return !unpacked_row_end.has_overflow() && unpacked_row_end.value() <= data_store_width;
-}
-
-Optional<size_t> required_2d_texture_data_size(GLsizei width, GLsizei height, GLenum format, GLenum type, PixelUnpackState const& unpack_state)
-{
- if (width < 0 || height < 0)
- return {};
- if (!is_valid_2d_pixel_unpack_state(width, unpack_state))
- return {};
- if (width == 0 || height == 0)
- return 0;
-
- auto pixel_size = bytes_per_pixel(format, type);
- if (!pixel_size.has_value())
- return {};
-
- if (unpack_state.alignment != 1 && unpack_state.alignment != 2 && unpack_state.alignment != 4 && unpack_state.alignment != 8)
- return {};
-
- Checked<size_t> row_byte_length = unpack_state.row_length == 0 ? static_cast<size_t>(width) : unpack_state.row_length;
- row_byte_length *= *pixel_size;
- row_byte_length += unpack_state.alignment - 1;
- if (row_byte_length.has_overflow())
- return {};
-
- row_byte_length = row_byte_length.value() / unpack_state.alignment * unpack_state.alignment;
-
- Checked<size_t> skipped_rows_size = unpack_state.skip_rows;
- skipped_rows_size *= row_byte_length.value();
-
- Checked<size_t> skipped_pixels_size = unpack_state.skip_pixels;
- skipped_pixels_size *= *pixel_size;
-
- Checked<size_t> remaining_rows_size = static_cast<size_t>(height) - 1;
- remaining_rows_size *= row_byte_length.value();
-
- Checked<size_t> final_row_size = static_cast<size_t>(width);
- final_row_size *= *pixel_size;
-
- if (skipped_rows_size.has_overflow() || skipped_pixels_size.has_overflow() || remaining_rows_size.has_overflow() || final_row_size.has_overflow())
- return {};
-
- Checked<size_t> required_size = skipped_rows_size.value();
- required_size += skipped_pixels_size.value();
- required_size += remaining_rows_size.value();
- required_size += final_row_size.value();
- if (required_size.has_overflow())
- return {};
-
- return required_size.value();
-}
-
}
diff --git a/Libraries/LibCompositing/WebGL/TextureUpload.h b/Libraries/LibCompositing/WebGL/TextureUpload.h
index ad9757cc109..00f40ed2ba0 100644
--- a/Libraries/LibCompositing/WebGL/TextureUpload.h
+++ b/Libraries/LibCompositing/WebGL/TextureUpload.h
@@ -14,7 +14,5 @@
namespace Compositing::WebGL {
COMPOSITING_API Optional<Gfx::ExportFormat> texture_export_format(GLenum format, GLenum type);
-COMPOSITING_API bool is_valid_2d_pixel_unpack_state(GLsizei width, PixelUnpackState const&);
-COMPOSITING_API Optional<size_t> required_2d_texture_data_size(GLsizei width, GLsizei height, GLenum format, GLenum type, PixelUnpackState const&);
}
diff --git a/Libraries/LibCompositing/WebGL/Types.h b/Libraries/LibCompositing/WebGL/Types.h
index 47b82c377bc..8a676696aa2 100644
--- a/Libraries/LibCompositing/WebGL/Types.h
+++ b/Libraries/LibCompositing/WebGL/Types.h
@@ -42,11 +42,4 @@ struct ReadPixelsResult {
GLsizei rows { 0 };
};
-struct PixelUnpackState {
- size_t alignment { 4 };
- size_t row_length { 0 };
- size_t skip_pixels { 0 };
- size_t skip_rows { 0 };
-};
-
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/buffer_source.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/buffer_source.rs
index dac325adcb8..b68648a5760 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/buffer_source.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/buffer_source.rs
@@ -16,8 +16,7 @@ use super::byte_ranges::{
list_range, offset_in_buffer_of_checked_write, sequence_list_tail, typed_array_list_range, typed_array_list_tail,
upload_range, upload_range_of_2d_texture,
};
-use super::canvas::{is_valid_2d_pixel_unpack_state, required_2d_texture_data_size};
-use super::pixel_unpacking::ImageUnpackConversion;
+use super::pixel_unpacking::{ImageUnpackConversion, is_valid_2d_pixel_unpack_state, required_2d_texture_data_size};
use super::proxy::recorder::{PlainNumber, bytes_of};
use super::state::ContextState;
use super::types::Float32List;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/canvas.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/canvas.rs
index 483f43a9b98..4d162bfadee 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/canvas.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/canvas.rs
@@ -15,7 +15,6 @@ use libgfx_rust::image_frame::ImageFrameHandle;
use libjs_rust::api::{Gc, Object, Realm};
use super::host::Frame;
-use super::pixel_unpacking::PixelUnpackState;
use crate::bindings::conversions::CppInterface;
/// The sources of texture images that are implemented in C++, in the order of the C++ enum of the same name.
@@ -39,15 +38,6 @@ unsafe extern "C" {
fn web_webgl_canvas_wrapper(canvas: *mut c_void, canvas_is_offscreen: bool, realm: *mut c_void) -> *mut c_void;
fn web_webgl_canvas_relevant_realm(canvas_host: *mut c_void) -> *mut c_void;
safe fn web_webgl_expose_experimental_interfaces() -> bool;
- safe fn web_webgl_is_valid_2d_pixel_unpack_state(width: i32, unpack_state: &PixelUnpackState) -> bool;
- safe fn web_webgl_required_2d_texture_data_size(
- width: i32,
- height: i32,
- format: u32,
- r#type: u32,
- unpack_state: &PixelUnpackState,
- out_size: &mut usize,
- ) -> bool;
fn web_webgl_read_tex_image_source(
source_wrapper: *mut c_void,
source_kind: TexImageSourceKind,
@@ -111,21 +101,6 @@ pub(crate) fn expose_experimental_interfaces() -> bool {
web_webgl_expose_experimental_interfaces()
}
-pub(crate) fn is_valid_2d_pixel_unpack_state(width: i32, unpack_state: &PixelUnpackState) -> bool {
- web_webgl_is_valid_2d_pixel_unpack_state(width, unpack_state)
-}
-
-pub(crate) fn required_2d_texture_data_size(
- width: i32,
- height: i32,
- format: u32,
- r#type: u32,
- unpack_state: &PixelUnpackState,
-) -> Option<usize> {
- let mut size = 0;
- web_webgl_required_2d_texture_data_size(width, height, format, r#type, unpack_state, &mut size).then_some(size)
-}
-
pub(crate) enum TexImageSourceFrame {
Frame(Frame),
/// The source has no image, or no image is uploaded with this format and type.
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/pixel_unpacking.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/pixel_unpacking.rs
index f578bca9df3..dae46b9f63f 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/pixel_unpacking.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/pixel_unpacking.rs
@@ -18,9 +18,7 @@ use super::constants::{
GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_SHORT_5_6_5,
};
-/// Mirrors `Compositing::WebGL::PixelUnpackState`.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-#[repr(C)]
pub(crate) struct PixelUnpackState {
pub(crate) alignment: usize,
pub(crate) row_length: usize,
@@ -39,6 +37,60 @@ impl Default for PixelUnpackState {
}
}
+/// Whether the pixels of a row of a 2D image that is `width` pixels wide lie inside the row of client memory that they
+/// are unpacked from. A negative width is left for the operation to reject.
+pub(crate) fn is_valid_2d_pixel_unpack_state(width: i32, unpack_state: &PixelUnpackState) -> bool {
+ let Ok(width) = usize::try_from(width) else {
+ return true;
+ };
+ let data_store_width = if unpack_state.row_length == 0 {
+ width
+ } else {
+ unpack_state.row_length
+ };
+ unpack_state
+ .skip_pixels
+ .checked_add(width)
+ .is_some_and(|unpacked_row_end| unpacked_row_end <= data_store_width)
+}
+
+/// How many bytes of client memory a 2D image is unpacked from, counted from the start of that memory.
+pub(crate) fn required_2d_texture_data_size(
+ width: i32,
+ height: i32,
+ format: u32,
+ r#type: u32,
+ unpack_state: &PixelUnpackState,
+) -> Option<usize> {
+ if !is_valid_2d_pixel_unpack_state(width, unpack_state) {
+ return None;
+ }
+ let width = usize::try_from(width).ok()?;
+ let height = usize::try_from(height).ok()?;
+ if width == 0 || height == 0 {
+ return Some(0);
+ }
+ let pixel_size = texel_layout(format, r#type)?.bytes_per_pixel;
+ let alignment = unpack_state.alignment;
+ if !matches!(alignment, 1 | 2 | 4 | 8) {
+ return None;
+ }
+ let pixels_per_row = if unpack_state.row_length == 0 {
+ width
+ } else {
+ unpack_state.row_length
+ };
+ let row_byte_length = pixels_per_row.checked_mul(pixel_size)?.checked_add(alignment - 1)? / alignment * alignment;
+ let skipped_rows_size = unpack_state.skip_rows.checked_mul(row_byte_length)?;
+ let skipped_pixels_size = unpack_state.skip_pixels.checked_mul(pixel_size)?;
+ let remaining_rows_size = (height - 1).checked_mul(row_byte_length)?;
+ let final_row_size = width.checked_mul(pixel_size)?;
+ skipped_rows_size
+ .checked_add(skipped_pixels_size)?
+ .checked_add(remaining_rows_size)?
+ .checked_add(final_row_size)
+}
+
/// https://registry.khronos.org/webgl/specs/latest/1.0/#PIXEL_STORAGE_PARAMETERS
///
/// A 2D image that texImage2D or texSubImage2D unpacks from an ArrayBufferView, and how it is flipped and
@@ -863,4 +915,75 @@ mod tests {
assert_eq!(bytes_per_pixel(GL_RGBA, 0x1234), None);
assert_eq!(bytes_per_pixel(0x1234, GL_UNSIGNED_BYTE), None);
}
+
+ #[test]
+ fn the_size_of_an_image_follows_from_its_dimensions() {
+ let default = PixelUnpackState::default();
+ assert_eq!(
+ required_2d_texture_data_size(16, 16, GL_RGB, GL_UNSIGNED_BYTE, &default),
+ Some(768)
+ );
+ assert_eq!(
+ required_2d_texture_data_size(3, 2, GL_RGB, GL_UNSIGNED_BYTE, &default),
+ Some(21)
+ );
+ assert_eq!(
+ required_2d_texture_data_size(5, 2, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, &default),
+ Some(22)
+ );
+ }
+
+ #[test]
+ fn the_size_of_an_image_includes_what_the_unpack_state_skips() {
+ let unpack_state = PixelUnpackState {
+ alignment: 8,
+ row_length: 10,
+ skip_pixels: 2,
+ skip_rows: 3,
+ };
+ assert_eq!(
+ required_2d_texture_data_size(4, 2, GL_RGBA, GL_UNSIGNED_BYTE, &unpack_state),
+ Some(184)
+ );
+ }
+
+ #[test]
+ fn an_image_whose_rows_overlap_has_no_size() {
+ let unpack_state = PixelUnpackState {
+ row_length: 8,
+ skip_pixels: 5,
+ ..PixelUnpackState::default()
+ };
+ assert!(!is_valid_2d_pixel_unpack_state(4, &unpack_state));
+ assert_eq!(
+ required_2d_texture_data_size(4, 2, GL_RGBA, GL_UNSIGNED_BYTE, &unpack_state),
+ None
+ );
+ }
+
+ #[test]
+ fn an_image_whose_size_overflows_has_none() {
+ for unpack_state in [
+ PixelUnpackState {
+ row_length: usize::MAX,
+ skip_pixels: usize::MAX,
+ ..PixelUnpackState::default()
+ },
+ PixelUnpackState {
+ skip_rows: usize::MAX,
+ ..PixelUnpackState::default()
+ },
+ PixelUnpackState {
+ row_length: 2,
+ skip_pixels: 1,
+ skip_rows: usize::MAX / 8,
+ ..PixelUnpackState::default()
+ },
+ ] {
+ assert_eq!(
+ required_2d_texture_data_size(1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &unpack_state),
+ None
+ );
+ }
+ }
}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl2_rendering_context_overloads.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl2_rendering_context_overloads.rs
index 9a43c967eb1..ac72305b399 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl2_rendering_context_overloads.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl2_rendering_context_overloads.rs
@@ -9,8 +9,8 @@
//! The operations of a WebGL 2 context that it has more overloads of than a WebGL 1 context.
use super::buffer_source::{destination_bytes, list_bytes, source_bytes, write_checked};
-use super::canvas::is_valid_2d_pixel_unpack_state;
use super::constants::{GL_INVALID_ENUM, GL_INVALID_OPERATION, GL_INVALID_VALUE, GL_OUT_OF_MEMORY};
+use super::pixel_unpacking::is_valid_2d_pixel_unpack_state;
use super::state::{RenderingContext, WebGL2};
use super::types::Float32List;
use super::web_gl_rendering_context_overloads::{Int32List, TexImageSource};
diff --git a/Libraries/LibWeb/WebGL/Types.h b/Libraries/LibWeb/WebGL/Types.h
index 0daa6d2dbfb..c99394b41b8 100644
--- a/Libraries/LibWeb/WebGL/Types.h
+++ b/Libraries/LibWeb/WebGL/Types.h
@@ -27,11 +27,8 @@ using Compositing::WebGL::GLintptr;
using Compositing::WebGL::GLsizei;
using Compositing::WebGL::GLsyncInternal;
using Compositing::WebGL::GLuint;
-using Compositing::WebGL::is_valid_2d_pixel_unpack_state;
using Compositing::WebGL::max_webgl_drawing_buffer_dimension;
-using Compositing::WebGL::PixelUnpackState;
using Compositing::WebGL::ReadPixelsResult;
-using Compositing::WebGL::required_2d_texture_data_size;
using Compositing::WebGL::texture_export_format;
using Compositing::WebGL::WebGLCommandHeader;
using Compositing::WebGL::WebGLCommandList;
diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp
index 3a05e64cd46..aebcccf8c10 100644
--- a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp
+++ b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.cpp
@@ -80,17 +80,6 @@ enum class TexImageSourceResult : u8 {
InvalidValue,
};
-// NB: `PixelUnpackState` of Bindings/Rust/src/web_gl/canvas.rs is four `usize`s in this order, with these defaults.
-static_assert(sizeof(PixelUnpackState) == 4 * sizeof(size_t));
-static_assert(offsetof(PixelUnpackState, alignment) == 0);
-static_assert(offsetof(PixelUnpackState, row_length) == sizeof(size_t));
-static_assert(offsetof(PixelUnpackState, skip_pixels) == 2 * sizeof(size_t));
-static_assert(offsetof(PixelUnpackState, skip_rows) == 3 * sizeof(size_t));
-static_assert(PixelUnpackState {}.alignment == 4);
-static_assert(PixelUnpackState {}.row_length == 0);
-static_assert(PixelUnpackState {}.skip_pixels == 0);
-static_assert(PixelUnpackState {}.skip_rows == 0);
-
}
extern "C" {
@@ -118,8 +107,6 @@ void web_webgl_canvas_bitmap_size(void* canvas_host, i32* out_width, i32* out_he
void* web_webgl_canvas_wrapper(void* canvas, bool canvas_is_offscreen, void* realm);
void* web_webgl_canvas_relevant_realm(void* canvas_host);
bool web_webgl_expose_experimental_interfaces();
-bool web_webgl_is_valid_2d_pixel_unpack_state(i32 width, PixelUnpackState const* unpack_state);
-bool web_webgl_required_2d_texture_data_size(i32 width, i32 height, u32 format, u32 type, PixelUnpackState const* unpack_state, size_t* out_size);
TexImageSourceResult web_webgl_read_tex_image_source(void* source_wrapper, TexImageSourceKind, u32 format, u32 type, void** out_frame);
TexImageSourceResult web_webgl_read_tex_image_frame(Gfx::DecodedImageFrame const* image_frame, u32 format, u32 type, void** out_frame);
TexImageSourceResult web_webgl_read_tex_image_pixels(u8 const* pixels, u32 width, u32 height, u32 format, u32 type, void** out_frame);
@@ -370,20 +357,6 @@ bool web_webgl_expose_experimental_interfaces()
return HTML::WindowOrWorkerGlobalScopeMixin::expose_experimental_interfaces();
}
-bool web_webgl_is_valid_2d_pixel_unpack_state(i32 width, PixelUnpackState const* unpack_state)
-{
- return is_valid_2d_pixel_unpack_state(width, *unpack_state);
-}
-
-bool web_webgl_required_2d_texture_data_size(i32 width, i32 height, u32 format, u32 type, PixelUnpackState const* unpack_state, size_t* out_size)
-{
- auto size = required_2d_texture_data_size(width, height, format, type, *unpack_state);
- if (!size.has_value())
- return false;
- *out_size = *size;
- return true;
-}
-
// The frame that a texture image source uploads, which the recorder takes over, if this format and type upload one.
static TexImageSourceResult tex_image_source_frame(Optional<Compositing::WebGL::ImageSourceFrame> frame, u32 format, u32 type, void** out_frame)
{
diff --git a/Tests/LibCompositing/CMakeLists.txt b/Tests/LibCompositing/CMakeLists.txt
index cb95c2a5b82..cdb5399ce4c 100644
--- a/Tests/LibCompositing/CMakeLists.txt
+++ b/Tests/LibCompositing/CMakeLists.txt
@@ -5,7 +5,6 @@ set(TEST_SOURCES
TestPausedDebuggerOverlay.cpp
TestPictureInPictureControls.cpp
TestScrollRequest.cpp
- TestTextureUpload.cpp
TestUIOverlays.cpp
TestVideoFrameHold.cpp
)
diff --git a/Tests/LibCompositing/TestTextureUpload.cpp b/Tests/LibCompositing/TestTextureUpload.cpp
deleted file mode 100644
index f60e61a5eeb..00000000000
--- a/Tests/LibCompositing/TestTextureUpload.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 2026-present, the Ladybird developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <AK/NumericLimits.h>
-#include <LibCompositing/WebGL/TextureUpload.h>
-#include <LibTest/TestCase.h>
-
-static constexpr Compositing::WebGL::GLenum UNSIGNED_BYTE = 0x1401;
-static constexpr Compositing::WebGL::GLenum RGB = 0x1907;
-static constexpr Compositing::WebGL::GLenum RGBA = 0x1908;
-static constexpr Compositing::WebGL::GLenum UNSIGNED_SHORT_5_6_5 = 0x8363;
-
-TEST_CASE(required_2d_texture_data_size_uses_dimensions)
-{
- auto size = Compositing::WebGL::required_2d_texture_data_size(16, 16, RGB, UNSIGNED_BYTE, {});
- EXPECT(size.has_value());
- EXPECT_EQ(*size, 768u);
-}
-
-TEST_CASE(required_2d_texture_data_size_includes_row_alignment)
-{
- auto size = Compositing::WebGL::required_2d_texture_data_size(3, 2, RGB, UNSIGNED_BYTE, {});
- EXPECT(size.has_value());
- EXPECT_EQ(*size, 21u);
-}
-
-TEST_CASE(required_2d_texture_data_size_includes_unpack_state)
-{
- Compositing::WebGL::PixelUnpackState unpack_state {
- .alignment = 8,
- .row_length = 10,
- .skip_pixels = 2,
- .skip_rows = 3,
- };
- auto size = Compositing::WebGL::required_2d_texture_data_size(4, 2, RGBA, UNSIGNED_BYTE, unpack_state);
- EXPECT(size.has_value());
- EXPECT_EQ(*size, 184u);
-}
-
-TEST_CASE(required_2d_texture_data_size_handles_packed_types)
-{
- auto size = Compositing::WebGL::required_2d_texture_data_size(5, 2, RGB, UNSIGNED_SHORT_5_6_5, {});
- EXPECT(size.has_value());
- EXPECT_EQ(*size, 22u);
-}
-
-TEST_CASE(required_2d_texture_data_size_rejects_overlapping_rows)
-{
- Compositing::WebGL::PixelUnpackState unpack_state {
- .row_length = 8,
- .skip_pixels = 5,
- };
- auto size = Compositing::WebGL::required_2d_texture_data_size(4, 2, RGBA, UNSIGNED_BYTE, unpack_state);
- EXPECT(!size.has_value());
-}
-
-TEST_CASE(required_2d_texture_data_size_rejects_skip_overflow)
-{
- Compositing::WebGL::PixelUnpackState unpack_state {
- .row_length = NumericLimits<size_t>::max(),
- .skip_pixels = NumericLimits<size_t>::max(),
- };
- auto size = Compositing::WebGL::required_2d_texture_data_size(1, 1, RGBA, UNSIGNED_BYTE, unpack_state);
- EXPECT(!size.has_value());
-}
-
-TEST_CASE(required_2d_texture_data_size_rejects_skipped_rows_size_overflow)
-{
- Compositing::WebGL::PixelUnpackState unpack_state {
- .skip_rows = NumericLimits<size_t>::max(),
- };
- auto size = Compositing::WebGL::required_2d_texture_data_size(1, 1, RGBA, UNSIGNED_BYTE, unpack_state);
- EXPECT(!size.has_value());
-}
-
-TEST_CASE(required_2d_texture_data_size_rejects_required_size_overflow)
-{
- Compositing::WebGL::PixelUnpackState unpack_state {
- .row_length = 2,
- .skip_pixels = 1,
- .skip_rows = NumericLimits<size_t>::max() / 8,
- };
- auto size = Compositing::WebGL::required_2d_texture_data_size(1, 1, RGBA, UNSIGNED_BYTE, unpack_state);
- EXPECT(!size.has_value());
-}