diff --git a/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.cpp b/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.cpp index bae7b49c5ce..d2d2a42a8ab 100644 --- a/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.cpp +++ b/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.cpp @@ -42,6 +42,12 @@ static void default_source_size(CanvasImageSource const& image, float& source_wi source_height = source->video_height(); } }, + [&source_width, &source_height](GC::Root const& source) { + auto const bitmap = source->bitmap(); + + source_width = bitmap->width(); + source_height = bitmap->height(); + }, [&source_width, &source_height](GC::Root const& source) { if (source->surface()) { source_width = source->surface()->size().width(); diff --git a/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.h b/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.h index 3c20a55f2fc..9077a824e62 100644 --- a/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.h +++ b/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.h @@ -10,13 +10,14 @@ #include #include #include +#include #include 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, GC::Root, GC::Root, GC::Root, GC::Root>; +using CanvasImageSource = Variant, GC::Root, GC::Root, GC::Root, GC::Root, GC::Root>; // https://html.spec.whatwg.org/multipage/canvas.html#canvasdrawimage class CanvasDrawImage { diff --git a/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.idl b/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.idl index df5c3ac36fe..a475376fe33 100644 --- a/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.idl +++ b/Libraries/LibWeb/HTML/Canvas/CanvasDrawImage.idl @@ -1,6 +1,7 @@ #import #import #import +#import #import #import @@ -9,8 +10,8 @@ typedef (HTMLImageElement or // FIXME: We should use HTMLOrSVGImageElement instead of HTMLImageElement HTMLVideoElement or HTMLCanvasElement or - ImageBitmap -// FIXME: OffscreenCanvas + ImageBitmap or + OffscreenCanvas // FIXME: VideoFrame ) CanvasImageSource; diff --git a/Libraries/LibWeb/HTML/CanvasPattern.cpp b/Libraries/LibWeb/HTML/CanvasPattern.cpp index 8227394c87d..439d5d1372f 100644 --- a/Libraries/LibWeb/HTML/CanvasPattern.cpp +++ b/Libraries/LibWeb/HTML/CanvasPattern.cpp @@ -17,6 +17,7 @@ namespace Web::HTML { GC_DEFINE_ALLOCATOR(CanvasPattern); +// https://html.spec.whatwg.org/multipage/canvas.html#dom-canvaspattern-settransform void CanvasPatternPaintStyle::paint(Gfx::IntRect physical_bounding_box, PaintFunction paint) const { // 1. Create an infinite transparent black bitmap. @@ -50,6 +51,7 @@ void CanvasPatternPaintStyle::paint(Gfx::IntRect physical_bounding_box, PaintFun auto bitmap = m_image.visit( [](GC::Root const& source) -> RefPtr { return source->immutable_bitmap(); }, [](GC::Root const& source) -> RefPtr { return source->current_image_bitmap(); }, + [](GC::Root const& source) -> RefPtr { return Gfx::ImmutableBitmap::create(*source->bitmap()); }, [](GC::Root const& source) -> RefPtr { return Gfx::ImmutableBitmap::create_snapshot_from_painting_surface(*source->surface()); }, [](GC::Root const& source) -> RefPtr { return Gfx::ImmutableBitmap::create(*source->bitmap()); }, [](GC::Root const& source) -> RefPtr { return Gfx::ImmutableBitmap::create(*source->bitmap()); }); diff --git a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index 8116ad8d3b0..75aa1760654 100644 --- a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -135,6 +135,7 @@ WebIDL::ExceptionOr CanvasRenderingContext2D::draw_image_internal(CanvasIm [](GC::Root const& source) -> RefPtr { return source->current_image_bitmap(); }, + [](GC::Root const& source) -> RefPtr { return Gfx::ImmutableBitmap::create(*source->bitmap()); }, [](GC::Root const& source) -> RefPtr { auto surface = source->surface(); if (!surface) @@ -737,8 +738,14 @@ WebIDL::ExceptionOr check_usability_of_image(CanvasI return Optional {}; }, + // OffscreenCanvas + [](GC::Root const& offscreen_canvas) -> WebIDL::ExceptionOr> { + // If image has either a horizontal dimension or a vertical dimension equal to zero, then throw an "InvalidStateError" DOMException. + if (offscreen_canvas->width() == 0 || offscreen_canvas->height() == 0) + return WebIDL::InvalidStateError::create(offscreen_canvas->realm(), "OffscreenCanvas width or height is zero"_string); + return Optional {}; + }, // HTMLCanvasElement - // FIXME: OffscreenCanvas [](GC::Root const& canvas_element) -> WebIDL::ExceptionOr> { // If image has either a horizontal dimension or a vertical dimension equal to zero, then throw an "InvalidStateError" DOMException. if (canvas_element->width() == 0 || canvas_element->height() == 0) @@ -778,8 +785,8 @@ bool image_is_not_origin_clean(CanvasImageSource const& image) // FIXME: image's media data is CORS-cross-origin. return false; }, - // HTMLCanvasElement - [](OneOf, GC::Root> auto const&) { + // HTMLCanvasElement, ImageBitmap or OffscreenCanvas + [](OneOf, GC::Root, GC::Root> auto const&) { // FIXME: image's bitmap's origin-clean flag is false. return false; }); diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h index 31e3a0d6f24..56af43d658b 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContextBase.h @@ -6,8 +6,14 @@ #pragma once +#include +#include + namespace Web::WebGL { +// NOTE: This is the Variant created by the IDL wrapper generator, and needs to be updated accordingly. +using TexImageSource = Variant, GC::Root, GC::Root, GC::Root, GC::Root, GC::Root>; + // FIXME: This object should inherit from Bindings::PlatformObject and implement the WebGLRenderingContextBase IDL interface. // We should make WebGL code generator to produce implementation for this interface. class WebGLRenderingContextBase { diff --git a/Libraries/LibWeb/WebGL/WebGLRenderingContextOverloads.idl b/Libraries/LibWeb/WebGL/WebGLRenderingContextOverloads.idl index 9db7865adc8..0d79f5a3e04 100644 --- a/Libraries/LibWeb/WebGL/WebGLRenderingContextOverloads.idl +++ b/Libraries/LibWeb/WebGL/WebGLRenderingContextOverloads.idl @@ -4,8 +4,8 @@ typedef (ImageBitmap or ImageData or HTMLImageElement or HTMLCanvasElement or - HTMLVideoElement - // FIXME: OffscreenCanvas or + HTMLVideoElement or + OffscreenCanvas // FIXME: VideoFrame ) TexImageSource; diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp index 53e27ac0fc0..4b95c1ee53a 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateWebGLRenderingContext.cpp @@ -730,7 +730,7 @@ struct ConvertedTexture { int height { 0 }; }; -static Optional read_and_pixel_convert_texture_image_source(Variant, GC::Root, GC::Root, GC::Root, GC::Root> const& source, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, Optional destination_width = OptionalNone {}, Optional destination_height = OptionalNone {}) +static Optional read_and_pixel_convert_texture_image_source(TexImageSource const& source, WebIDL::UnsignedLong format, WebIDL::UnsignedLong type, Optional destination_width = OptionalNone {}, Optional destination_height = OptionalNone {}) { // FIXME: If this function is called with an ImageData whose data attribute has been neutered, // an INVALID_VALUE error is generated. @@ -753,6 +753,9 @@ static Optional read_and_pixel_convert_texture_image_source(Va surface->read_into_bitmap(*bitmap); return Gfx::ImmutableBitmap::create(*bitmap); }, + [](GC::Root const& source) -> RefPtr { + return Gfx::ImmutableBitmap::create(*source->bitmap()); + }, [](GC::Root const& source) -> RefPtr { return Gfx::ImmutableBitmap::create(*source->bitmap()); },