diff options
author | Andreas Kling <kling@serenityos.org> | 2023-05-20 16:40:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-21 07:44:29 +0200 |
commit | e63f68661f8d31bf195f801b3f82ad57da1e8237 (patch) | |
tree | 870b2e98e443bc34b5a528543e2c3594cd22c513 /Userland/Libraries/LibWeb | |
parent | 6f46bff4dfe43f78ac1906587b3f1106f31765e5 (diff) | |
download | serenity-e63f68661f8d31bf195f801b3f82ad57da1e8237.zip |
LibWeb: Have ImageProvider bitmap getter take optional size argument
This allows the painting subsystem to request a bitmap with the exact
size needed for painting, instead of being limited to "just give me a
bitmap" (which was perfectly enough for raster images, but not for
vector graphics).
Diffstat (limited to 'Userland/Libraries/LibWeb')
11 files changed, 15 insertions, 14 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/AnimatedBitmapDecodedImageData.cpp b/Userland/Libraries/LibWeb/HTML/AnimatedBitmapDecodedImageData.cpp index 06805f789c..5b5c24cb5d 100644 --- a/Userland/Libraries/LibWeb/HTML/AnimatedBitmapDecodedImageData.cpp +++ b/Userland/Libraries/LibWeb/HTML/AnimatedBitmapDecodedImageData.cpp @@ -23,7 +23,7 @@ AnimatedBitmapDecodedImageData::AnimatedBitmapDecodedImageData(Vector<Frame>&& f AnimatedBitmapDecodedImageData::~AnimatedBitmapDecodedImageData() = default; -RefPtr<Gfx::Bitmap const> AnimatedBitmapDecodedImageData::bitmap(size_t frame_index) const +RefPtr<Gfx::Bitmap const> AnimatedBitmapDecodedImageData::bitmap(size_t frame_index, Gfx::IntSize) const { if (frame_index >= m_frames.size()) return nullptr; diff --git a/Userland/Libraries/LibWeb/HTML/AnimatedBitmapDecodedImageData.h b/Userland/Libraries/LibWeb/HTML/AnimatedBitmapDecodedImageData.h index 0d24dbd36e..9f7ca8fc31 100644 --- a/Userland/Libraries/LibWeb/HTML/AnimatedBitmapDecodedImageData.h +++ b/Userland/Libraries/LibWeb/HTML/AnimatedBitmapDecodedImageData.h @@ -20,7 +20,7 @@ public: static ErrorOr<NonnullRefPtr<AnimatedBitmapDecodedImageData>> create(Vector<Frame>&&, size_t loop_count, bool animated); virtual ~AnimatedBitmapDecodedImageData() override; - virtual RefPtr<Gfx::Bitmap const> bitmap(size_t frame_index) const override; + virtual RefPtr<Gfx::Bitmap const> bitmap(size_t frame_index, Gfx::IntSize = {}) const override; virtual int frame_duration(size_t frame_index) const override; virtual size_t frame_count() const override { return m_frames.size(); } diff --git a/Userland/Libraries/LibWeb/HTML/DecodedImageData.h b/Userland/Libraries/LibWeb/HTML/DecodedImageData.h index 100722767a..f96b60342e 100644 --- a/Userland/Libraries/LibWeb/HTML/DecodedImageData.h +++ b/Userland/Libraries/LibWeb/HTML/DecodedImageData.h @@ -7,7 +7,7 @@ #pragma once #include <AK/RefCounted.h> -#include <LibGfx/Forward.h> +#include <LibGfx/Size.h> #include <LibJS/Heap/Cell.h> #include <LibWeb/PixelUnits.h> @@ -18,7 +18,7 @@ class DecodedImageData : public RefCounted<DecodedImageData> { public: virtual ~DecodedImageData(); - virtual RefPtr<Gfx::Bitmap const> bitmap(size_t frame_index) const = 0; + virtual RefPtr<Gfx::Bitmap const> bitmap(size_t frame_index, Gfx::IntSize = {}) const = 0; virtual int frame_duration(size_t frame_index) const = 0; virtual size_t frame_count() const = 0; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp index 3abb9a292a..56537cd7ed 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -132,10 +132,10 @@ Optional<float> HTMLImageElement::intrinsic_aspect_ratio() const return {}; } -RefPtr<Gfx::Bitmap const> HTMLImageElement::current_image_bitmap() const +RefPtr<Gfx::Bitmap const> HTMLImageElement::current_image_bitmap(Gfx::IntSize size) const { if (auto data = m_current_request->image_data()) - return data->bitmap(m_current_frame_index); + return data->bitmap(m_current_frame_index, size); return nullptr; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h index abb5d1f77b..1086d4c598 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.h @@ -81,7 +81,7 @@ public: virtual Optional<CSSPixels> intrinsic_width() const override; virtual Optional<CSSPixels> intrinsic_height() const override; virtual Optional<float> intrinsic_aspect_ratio() const override; - virtual RefPtr<Gfx::Bitmap const> current_image_bitmap() const override; + virtual RefPtr<Gfx::Bitmap const> current_image_bitmap(Gfx::IntSize = {}) const override; virtual void set_visible_in_viewport(bool) override; private: diff --git a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp index 4c25726b0d..edb4858dd4 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.cpp @@ -371,7 +371,7 @@ Optional<float> HTMLObjectElement::intrinsic_aspect_ratio() const return {}; } -RefPtr<Gfx::Bitmap const> HTMLObjectElement::current_image_bitmap() const +RefPtr<Gfx::Bitmap const> HTMLObjectElement::current_image_bitmap(Gfx::IntSize) const { if (m_image_loader.has_value()) return m_image_loader->bitmap(m_image_loader->current_frame_index()); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h index d728f4cc72..15ab8074f1 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLObjectElement.h @@ -73,7 +73,7 @@ private: virtual Optional<CSSPixels> intrinsic_width() const override; virtual Optional<CSSPixels> intrinsic_height() const override; virtual Optional<float> intrinsic_aspect_ratio() const override; - virtual RefPtr<Gfx::Bitmap const> current_image_bitmap() const override; + virtual RefPtr<Gfx::Bitmap const> current_image_bitmap(Gfx::IntSize = {}) const override; virtual void set_visible_in_viewport(bool) override; Representation m_representation { Representation::Unknown }; diff --git a/Userland/Libraries/LibWeb/Layout/ImageProvider.h b/Userland/Libraries/LibWeb/Layout/ImageProvider.h index 1a45c3de8b..8d1455d698 100644 --- a/Userland/Libraries/LibWeb/Layout/ImageProvider.h +++ b/Userland/Libraries/LibWeb/Layout/ImageProvider.h @@ -6,6 +6,7 @@ #pragma once +#include <LibGfx/Size.h> #include <LibWeb/PixelUnits.h> namespace Web::Layout { @@ -18,7 +19,7 @@ public: virtual Optional<CSSPixels> intrinsic_height() const = 0; virtual Optional<float> intrinsic_aspect_ratio() const = 0; - virtual RefPtr<Gfx::Bitmap const> current_image_bitmap() const = 0; + virtual RefPtr<Gfx::Bitmap const> current_image_bitmap(Gfx::IntSize) const = 0; virtual void set_visible_in_viewport(bool) = 0; }; diff --git a/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp b/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp index 4c8ca279d0..7629c51961 100644 --- a/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp +++ b/Userland/Libraries/LibWeb/Painting/ImagePaintable.cpp @@ -52,6 +52,7 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const PaintableBox::paint(context, phase); if (phase == PaintPhase::Foreground) { + auto image_rect = context.rounded_device_rect(absolute_rect()); if (layout_box().renders_as_alt_text()) { auto& image_element = verify_cast<HTML::HTMLImageElement>(*dom_node()); auto enclosing_rect = context.enclosing_device_rect(absolute_rect()).to_type<int>(); @@ -61,8 +62,7 @@ void ImagePaintable::paint(PaintContext& context, PaintPhase phase) const if (alt.is_empty()) alt = image_element.src(); context.painter().draw_text(enclosing_rect, alt, Gfx::TextAlignment::Center, computed_values().color(), Gfx::TextElision::Right); - } else if (auto bitmap = layout_box().image_provider().current_image_bitmap()) { - auto image_rect = context.rounded_device_rect(absolute_rect()); + } else if (auto bitmap = layout_box().image_provider().current_image_bitmap(image_rect.size().to_type<int>())) { ScopedCornerRadiusClip corner_clip { context, context.painter(), image_rect, normalized_border_radii_data(ShrinkRadiiForBorders::Yes) }; auto scaling_mode = to_gfx_scaling_mode(computed_values().image_rendering(), bitmap->rect(), image_rect.to_type<int>()); context.painter().draw_scaled_bitmap(image_rect.to_type<int>(), *bitmap, bitmap->rect(), 1.f, scaling_mode); diff --git a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp index d6192cb9ef..bda9e99561 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.cpp @@ -20,7 +20,7 @@ SVGDecodedImageData::SVGDecodedImageData() SVGDecodedImageData::~SVGDecodedImageData() = default; -RefPtr<Gfx::Bitmap const> SVGDecodedImageData::bitmap(size_t) const +RefPtr<Gfx::Bitmap const> SVGDecodedImageData::bitmap(size_t, Gfx::IntSize) const { return nullptr; } diff --git a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.h b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.h index f8a5b05809..1adc482684 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.h +++ b/Userland/Libraries/LibWeb/SVG/SVGDecodedImageData.h @@ -15,7 +15,7 @@ public: static ErrorOr<NonnullRefPtr<SVGDecodedImageData>> create(ByteBuffer encoded_svg); virtual ~SVGDecodedImageData() override; - virtual RefPtr<Gfx::Bitmap const> bitmap(size_t frame_index) const override; + virtual RefPtr<Gfx::Bitmap const> bitmap(size_t frame_index, Gfx::IntSize) const override; virtual Optional<CSSPixels> intrinsic_width() const override; virtual Optional<CSSPixels> intrinsic_height() const override; |