LibWeb: Make CanvasImageSource also be an ImageBitmap

This commit is contained in:
Lucas CHOLLET 2024-04-05 09:15:45 -04:00 committed by Andreas Kling
commit 94128fe027
Notes: sideshowbarker 2024-07-17 02:39:10 +09:00
8 changed files with 24 additions and 5 deletions

View file

@ -5,6 +5,7 @@
*/
#include <LibWeb/HTML/Canvas/CanvasDrawImage.h>
#include <LibWeb/HTML/ImageBitmap.h>
namespace Web::HTML {

View file

@ -6,6 +6,7 @@
#pragma once
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/HTMLCanvasElement.h>
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@ -14,7 +15,7 @@ namespace Web::HTML {
// https://html.spec.whatwg.org/multipage/canvas.html#canvasimagesource
// NOTE: This is the Variant created by the IDL wrapper generator, and needs to be updated accordingly.
using CanvasImageSource = Variant<JS::Handle<HTMLImageElement>, JS::Handle<HTMLCanvasElement>>;
using CanvasImageSource = Variant<JS::Handle<HTMLImageElement>, JS::Handle<HTMLCanvasElement>, JS::Handle<ImageBitmap>>;
// https://html.spec.whatwg.org/multipage/canvas.html#canvasdrawimage
class CanvasDrawImage {

View file

@ -1,11 +1,12 @@
#import <HTML/HTMLCanvasElement.idl>
#import <HTML/HTMLImageElement.idl>
#import <HTML/ImageBitmap.idl>
typedef (HTMLImageElement or
// FIXME: We should use HTMLOrSVGImageElement instead of HTMLImageElement
// FIXME: HTMLVideoElement or
HTMLCanvasElement
// FIXME: ImageBitmap
HTMLCanvasElement or
ImageBitmap
// FIXME: OffscreenCanvas
// FIXME: VideoFrame
) CanvasImageSource;

View file

@ -8,6 +8,7 @@
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/CanvasPattern.h>
#include <LibWeb/HTML/CanvasRenderingContext2D.h>
#include <LibWeb/HTML/ImageBitmap.h>
namespace Web::HTML {

View file

@ -16,6 +16,7 @@
#include <LibWeb/HTML/CanvasRenderingContext2D.h>
#include <LibWeb/HTML/HTMLCanvasElement.h>
#include <LibWeb/HTML/HTMLImageElement.h>
#include <LibWeb/HTML/ImageBitmap.h>
#include <LibWeb/HTML/ImageData.h>
#include <LibWeb/HTML/Path2D.h>
#include <LibWeb/HTML/TextMetrics.h>
@ -636,6 +637,14 @@ WebIDL::ExceptionOr<CanvasImageSourceUsability> check_usability_of_image(CanvasI
if (canvas_element->width() == 0 || canvas_element->height() == 0)
return WebIDL::InvalidStateError::create(canvas_element->realm(), "Canvas width or height is zero"_fly_string);
return Optional<CanvasImageSourceUsability> {};
},
// ImageBitmap
// FIXME: VideoFrame
[](JS::Handle<ImageBitmap> const& image_bitmap) -> WebIDL::ExceptionOr<Optional<CanvasImageSourceUsability>> {
if (image_bitmap->is_detached())
return WebIDL::InvalidStateError::create(image_bitmap->realm(), "Image bitmap is detached"_fly_string);
return Optional<CanvasImageSourceUsability> {};
}));
if (usability.has_value())
return usability.release_value();
@ -659,8 +668,7 @@ bool image_is_not_origin_clean(CanvasImageSource const& image)
// image's media data is CORS-cross-origin.
// HTMLCanvasElement
// FIXME: ImageBitmap
[](JS::Handle<HTMLCanvasElement> const&) {
[](OneOf<JS::Handle<HTMLCanvasElement>, JS::Handle<ImageBitmap>> auto const&) {
// FIXME: image's bitmap's origin-clean flag is false.
return false;
});

View file

@ -104,4 +104,9 @@ void ImageBitmap::set_bitmap(RefPtr<Gfx::Bitmap> bitmap)
m_height = m_bitmap->height();
}
Gfx::Bitmap* ImageBitmap::bitmap() const
{
return m_bitmap.ptr();
}
}

View file

@ -50,6 +50,7 @@ public:
// Implementation specific:
void set_bitmap(RefPtr<Gfx::Bitmap>);
Gfx::Bitmap* bitmap() const;
private:
explicit ImageBitmap(JS::Realm&);