1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:27:44 +00:00

LibGfx+LibWeb: Add ImmutableBitmap for images bitmap caching in painter

Before this change, we used Gfx::Bitmap to represent both decoded
images that are not going to be mutated and bitmaps corresponding
to canvases that could be mutated.

This change introduces a wrapper for bitmaps that are not going to be
mutated, so the painter could do caching: texture caching in the case
of GPU painter and potentially scaled bitmap caching in the case of CPU
painter.
This commit is contained in:
Aliaksandr Kalenik 2023-11-24 14:45:45 +01:00 committed by Andreas Kling
parent abcf71a8ca
commit f4a5c136c3
24 changed files with 146 additions and 35 deletions

View file

@ -101,8 +101,9 @@ SVGDecodedImageData::SVGDecodedImageData(NonnullOwnPtr<Page> page, NonnullOwnPtr
SVGDecodedImageData::~SVGDecodedImageData() = default;
void SVGDecodedImageData::render(Gfx::IntSize size) const
RefPtr<Gfx::Bitmap> SVGDecodedImageData::render(Gfx::IntSize size) const
{
auto bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size).release_value_but_fixme_should_propagate_errors();
VERIFY(m_document->navigable());
m_document->navigable()->set_viewport_rect({ 0, 0, size.width(), size.height() });
m_document->update_layout();
@ -112,21 +113,22 @@ void SVGDecodedImageData::render(Gfx::IntSize size) const
m_document->paintable()->paint_all_phases(context);
Painting::PaintingCommandExecutorCPU executor { *m_bitmap };
Painting::PaintingCommandExecutorCPU executor { *bitmap };
recording_painter.execute(executor);
return bitmap;
}
RefPtr<Gfx::Bitmap const> SVGDecodedImageData::bitmap(size_t, Gfx::IntSize size) const
RefPtr<Gfx::ImmutableBitmap> SVGDecodedImageData::bitmap(size_t, Gfx::IntSize size) const
{
if (size.is_empty())
return nullptr;
if (m_bitmap && m_bitmap->size() == size)
return m_bitmap;
if (m_immutable_bitmap && m_immutable_bitmap->size() == size)
return m_immutable_bitmap;
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, size).release_value_but_fixme_should_propagate_errors();
render(size);
return m_bitmap;
m_immutable_bitmap = Gfx::ImmutableBitmap::create(*render(size));
return m_immutable_bitmap;
}
Optional<CSSPixels> SVGDecodedImageData::intrinsic_width() const