@@ -331,27 +331,12 @@ String HTMLCanvasElement::to_data_url(StringView type, JS::Value js_quality)
331
331
// https://html.spec.whatwg.org/multipage/canvas.html#dom-canvas-toblob
332
332
WebIDL::ExceptionOr<void > HTMLCanvasElement::to_blob (GC::Ref<WebIDL::CallbackType> callback, StringView type, JS::Value js_quality)
333
333
{
334
- // It is possible the canvas doesn't have a associated bitmap so create one
335
- allocate_painting_surface_if_needed ();
336
- auto surface = this ->surface ();
337
- auto size = bitmap_size_for_canvas ();
338
- if (!surface && !size.is_empty ()) {
339
- // If the context is not initialized yet, we need to allocate transparent surface for serialization
340
- auto skia_backend_context = navigable ()->traversable_navigable ()->skia_backend_context ();
341
- surface = Gfx::PaintingSurface::create_with_size (skia_backend_context, size, Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied);
342
- }
343
-
344
334
// FIXME: 1. If this canvas element's bitmap's origin-clean flag is set to false, then throw a "SecurityError" DOMException.
345
335
346
336
// 2. Let result be null.
347
- RefPtr<Gfx::Bitmap> bitmap_result;
348
-
349
337
// 3. If this canvas element's bitmap has pixels (i.e., neither its horizontal dimension nor its vertical dimension is zero),
350
338
// then set result to a copy of this canvas element's bitmap.
351
- if (surface) {
352
- bitmap_result = MUST (Gfx::Bitmap::create (Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, surface->size ()));
353
- surface->read_into_bitmap (*bitmap_result);
354
- }
339
+ auto bitmap_result = get_bitmap_from_surface ();
355
340
356
341
Optional<double > quality = js_quality.is_number () ? js_quality.as_double () : Optional<double >();
357
342
@@ -383,6 +368,26 @@ WebIDL::ExceptionOr<void> HTMLCanvasElement::to_blob(GC::Ref<WebIDL::CallbackTyp
383
368
return {};
384
369
}
385
370
371
+ RefPtr<Gfx::Bitmap> HTMLCanvasElement::get_bitmap_from_surface ()
372
+ {
373
+ // It is possible the canvas doesn't have an associated bitmap so create one
374
+ allocate_painting_surface_if_needed ();
375
+ auto surface = this ->surface ();
376
+ if (auto const size = bitmap_size_for_canvas (); !surface && !size.is_empty ()) {
377
+ // If the context is not initialized yet, we need to allocate transparent surface for serialization
378
+ auto const skia_backend_context = navigable ()->traversable_navigable ()->skia_backend_context ();
379
+ surface = Gfx::PaintingSurface::create_with_size (skia_backend_context, size, Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied);
380
+ }
381
+
382
+ RefPtr<Gfx::Bitmap> bitmap;
383
+ if (surface) {
384
+ bitmap = MUST (Gfx::Bitmap::create (Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, surface->size ()));
385
+ surface->read_into_bitmap (*bitmap);
386
+ }
387
+
388
+ return bitmap;
389
+ }
390
+
386
391
void HTMLCanvasElement::present ()
387
392
{
388
393
if (auto surface = this ->surface ())
0 commit comments