@@ -165,25 +165,29 @@ Optional<WebGLRenderingContextBase::ConvertedTexture> WebGLRenderingContextBase:
165165
166166 auto buffer = MUST (ByteBuffer::create_zeroed (buffer_pitch.value () * height));
167167
168- auto skia_format = opengl_format_and_type_to_skia_color_type (format, type);
169-
170- // FIXME: Respect UNPACK_PREMULTIPLY_ALPHA_WEBGL
171- // FIXME: Respect unpackColorSpace
172- auto color_space = SkColorSpace::MakeSRGB ();
173- auto image_info = SkImageInfo::Make (width, height, skia_format, SkAlphaType::kPremul_SkAlphaType , color_space);
174- auto surface = SkSurfaces::WrapPixels (image_info, buffer.data (), buffer_pitch.value ());
175- auto surface_canvas = surface->getCanvas ();
176- auto dst_rect = Gfx::to_skia_rect (Gfx::Rect { 0 , 0 , width, height });
177-
178- // The first pixel transferred from the source to the WebGL implementation corresponds to the upper left corner of
179- // the source. This behavior is modified by the UNPACK_FLIP_Y_WEBGL pixel storage parameter, except for ImageBitmap
180- // arguments, as described in the abovementioned section.
181- if (m_unpack_flip_y && !source.has <GC::Root<HTML::ImageBitmap>>()) {
182- surface_canvas->translate (0 , dst_rect.height ());
183- surface_canvas->scale (1 , -1 );
184- }
168+ if (width > 0 && height > 0 ) {
169+ // FIXME: Respect UNPACK_PREMULTIPLY_ALPHA_WEBGL
170+ // FIXME: Respect unpackColorSpace
171+ auto skia_format = opengl_format_and_type_to_skia_color_type (format, type);
172+ auto color_space = SkColorSpace::MakeSRGB ();
173+ auto image_info = SkImageInfo::Make (width, height, skia_format, SkAlphaType::kPremul_SkAlphaType , color_space);
174+ auto surface = SkSurfaces::WrapPixels (image_info, buffer.data (), buffer_pitch.value ());
175+ VERIFY (surface);
176+ auto surface_canvas = surface->getCanvas ();
177+ auto dst_rect = Gfx::to_skia_rect (Gfx::Rect { 0 , 0 , width, height });
178+
179+ // The first pixel transferred from the source to the WebGL implementation corresponds to the upper left corner of
180+ // the source. This behavior is modified by the UNPACK_FLIP_Y_WEBGL pixel storage parameter, except for ImageBitmap
181+ // arguments, as described in the abovementioned section.
182+ if (m_unpack_flip_y && !source.has <GC::Root<HTML::ImageBitmap>>()) {
183+ surface_canvas->translate (0 , dst_rect.height ());
184+ surface_canvas->scale (1 , -1 );
185+ }
185186
186- surface_canvas->drawImageRect (bitmap->sk_image (), dst_rect, Gfx::to_skia_sampling_options (Gfx::ScalingMode::NearestNeighbor));
187+ surface_canvas->drawImageRect (bitmap->sk_image (), dst_rect, Gfx::to_skia_sampling_options (Gfx::ScalingMode::NearestNeighbor));
188+ } else {
189+ VERIFY (buffer.is_empty ());
190+ }
187191
188192 return ConvertedTexture {
189193 .buffer = move (buffer),
0 commit comments