LibWeb: Implement createImageBitmap() with an ImageBitmap source

This commit is contained in:
ayeteadoe 2025-10-25 18:29:56 -07:00 committed by Jelle Raaijmakers
parent d733bf54cc
commit 5abb5d555a
3 changed files with 29 additions and 15 deletions

View File

@ -416,11 +416,25 @@ GC::Ref<WebIDL::Promise> WindowOrWorkerGlobalScopeMixin::create_image_bitmap_imp
}));
},
// -> ImageBitmap
[&](GC::Root<ImageBitmap> const&) {
dbgln("(STUBBED) createImageBitmap() for ImageBitmap");
auto const error = JS::Error::create(realm, "Not Implemented: createImageBitmap() for ImageBitmap"sv);
TemporaryExecutionContext const context { relevant_realm(p->promise()), TemporaryExecutionContext::CallbacksEnabled::Yes };
WebIDL::reject_promise(realm, *p, error);
[&](GC::Root<ImageBitmap> const& source_image_bitmap) {
// 1. Set imageBitmap's bitmap data to a copy of image's bitmap data, cropped to the source rectangle with formatting.
auto cropped_bitmap_or_error = crop_to_the_source_rectangle_with_formatting(source_image_bitmap->bitmap(), sx, sy, sw, sh, options);
// AD-HOC: Reject promise with an "InvalidStateError" DOMException on allocation failure
// Spec issue: https://github.com/whatwg/html/issues/3323
if (cropped_bitmap_or_error.is_error()) {
WebIDL::reject_promise(realm, *p, WebIDL::InvalidStateError::create(image_bitmap->realm(), "Image size is invalid"_utf16));
return;
}
image_bitmap->set_bitmap(cropped_bitmap_or_error.release_value());
// FIXME: 2. Set the origin-clean flag of imageBitmap's bitmap to the same value as the origin-clean flag of image's bitmap.
// 3. Queue a global task, using the bitmap task source, to resolve promise with imageBitmap.
queue_global_task(Task::Source::BitmapTask, image_bitmap, GC::create_function(realm.heap(), [p, image_bitmap] {
auto& realm = relevant_realm(image_bitmap);
TemporaryExecutionContext const context { realm, TemporaryExecutionContext::CallbacksEnabled::Yes };
WebIDL::resolve_promise(realm, *p, image_bitmap);
}));
},
[&](GC::Root<OffscreenCanvas> const&) {
dbgln("(STUBBED) createImageBitmap() for OffscreenCanvas");

View File

@ -2,8 +2,8 @@ Harness status: OK
Found 55 tests
35 Pass
20 Fail
40 Pass
15 Fail
Pass createImageBitmap from an HTMLCanvasElement, and drawImage on the created ImageBitmap
Pass createImageBitmap from an HTMLCanvasElement scaled down, and drawImage on the created ImageBitmap
Pass createImageBitmap from an HTMLCanvasElement scaled up, and drawImage on the created ImageBitmap
@ -49,11 +49,11 @@ Pass createImageBitmap from an ImageData scaled down, and drawImage on the creat
Pass createImageBitmap from an ImageData scaled up, and drawImage on the created ImageBitmap
Pass createImageBitmap from an ImageData resized, and drawImage on the created ImageBitmap
Pass createImageBitmap from an ImageData with negative sw/sh, and drawImage on the created ImageBitmap
Fail createImageBitmap from an ImageBitmap, and drawImage on the created ImageBitmap
Fail createImageBitmap from an ImageBitmap scaled down, and drawImage on the created ImageBitmap
Fail createImageBitmap from an ImageBitmap scaled up, and drawImage on the created ImageBitmap
Fail createImageBitmap from an ImageBitmap resized, and drawImage on the created ImageBitmap
Fail createImageBitmap from an ImageBitmap with negative sw/sh, and drawImage on the created ImageBitmap
Pass createImageBitmap from an ImageBitmap, and drawImage on the created ImageBitmap
Pass createImageBitmap from an ImageBitmap scaled down, and drawImage on the created ImageBitmap
Pass createImageBitmap from an ImageBitmap scaled up, and drawImage on the created ImageBitmap
Pass createImageBitmap from an ImageBitmap resized, and drawImage on the created ImageBitmap
Pass createImageBitmap from an ImageBitmap with negative sw/sh, and drawImage on the created ImageBitmap
Pass createImageBitmap from a Blob, and drawImage on the created ImageBitmap
Pass createImageBitmap from a Blob scaled down, and drawImage on the created ImageBitmap
Pass createImageBitmap from a Blob scaled up, and drawImage on the created ImageBitmap

View File

@ -2,8 +2,8 @@ Harness status: OK
Found 93 tests
87 Pass
6 Fail
88 Pass
5 Fail
Pass createImageBitmap with an HTMLCanvasElement source and sw set to 0
Pass createImageBitmap with an HTMLCanvasElement source and sh set to 0
Pass createImageBitmap with an HTMLCanvasElement source and oversized (unallocatable) crop region
@ -69,7 +69,7 @@ Pass createImageBitmap with an ImageData source and a value between 0 and 1 in r
Pass createImageBitmap with an ImageData source and a value between 0 and 1 in resizeHeight
Pass createImageBitmap with an ImageBitmap source and sw set to 0
Pass createImageBitmap with an ImageBitmap source and sh set to 0
Fail createImageBitmap with an ImageBitmap source and oversized (unallocatable) crop region
Pass createImageBitmap with an ImageBitmap source and oversized (unallocatable) crop region
Pass createImageBitmap with an ImageBitmap source and a value of 0 int resizeWidth
Pass createImageBitmap with an ImageBitmap source and a value of 0 in resizeHeight
Pass createImageBitmap with an ImageBitmap source and a value between 0 and 1 in resizeWidth