LibWeb/WebGL: Don't attempt to do texture transforms on an empty texture

Skia will not give us a surface if the width or height is zero.
This commit is contained in:
Luke Wilde 2025-10-28 16:03:13 +00:00 committed by Jelle Raaijmakers
parent b0e02af040
commit 3ca4ff6037

View File

@ -165,26 +165,30 @@ Optional<WebGLRenderingContextBase::ConvertedTexture> WebGLRenderingContextBase:
auto buffer = MUST(ByteBuffer::create_zeroed(buffer_pitch.value() * height)); auto buffer = MUST(ByteBuffer::create_zeroed(buffer_pitch.value() * height));
auto skia_format = opengl_format_and_type_to_skia_color_type(format, type); if (width > 0 && height > 0) {
// FIXME: Respect UNPACK_PREMULTIPLY_ALPHA_WEBGL
// FIXME: Respect unpackColorSpace
auto skia_format = opengl_format_and_type_to_skia_color_type(format, type);
auto color_space = SkColorSpace::MakeSRGB();
auto image_info = SkImageInfo::Make(width, height, skia_format, SkAlphaType::kPremul_SkAlphaType, color_space);
auto surface = SkSurfaces::WrapPixels(image_info, buffer.data(), buffer_pitch.value());
VERIFY(surface);
auto surface_canvas = surface->getCanvas();
auto dst_rect = Gfx::to_skia_rect(Gfx::Rect { 0, 0, width, height });
// FIXME: Respect UNPACK_PREMULTIPLY_ALPHA_WEBGL // The first pixel transferred from the source to the WebGL implementation corresponds to the upper left corner of
// FIXME: Respect unpackColorSpace // the source. This behavior is modified by the UNPACK_FLIP_Y_WEBGL pixel storage parameter, except for ImageBitmap
auto color_space = SkColorSpace::MakeSRGB(); // arguments, as described in the abovementioned section.
auto image_info = SkImageInfo::Make(width, height, skia_format, SkAlphaType::kPremul_SkAlphaType, color_space); if (m_unpack_flip_y && !source.has<GC::Root<HTML::ImageBitmap>>()) {
auto surface = SkSurfaces::WrapPixels(image_info, buffer.data(), buffer_pitch.value()); surface_canvas->translate(0, dst_rect.height());
auto surface_canvas = surface->getCanvas(); surface_canvas->scale(1, -1);
auto dst_rect = Gfx::to_skia_rect(Gfx::Rect { 0, 0, width, height }); }
// The first pixel transferred from the source to the WebGL implementation corresponds to the upper left corner of surface_canvas->drawImageRect(bitmap->sk_image(), dst_rect, Gfx::to_skia_sampling_options(Gfx::ScalingMode::NearestNeighbor));
// the source. This behavior is modified by the UNPACK_FLIP_Y_WEBGL pixel storage parameter, except for ImageBitmap } else {
// arguments, as described in the abovementioned section. VERIFY(buffer.is_empty());
if (m_unpack_flip_y && !source.has<GC::Root<HTML::ImageBitmap>>()) {
surface_canvas->translate(0, dst_rect.height());
surface_canvas->scale(1, -1);
} }
surface_canvas->drawImageRect(bitmap->sk_image(), dst_rect, Gfx::to_skia_sampling_options(Gfx::ScalingMode::NearestNeighbor));
return ConvertedTexture { return ConvertedTexture {
.buffer = move(buffer), .buffer = move(buffer),
.width = width, .width = width,