LibGfx+LibWeb: Cache SkImage in ImmutableBitmap

By caching the SkImage that is reused across repaints, we allow Skia t
optimize GPU texture caching.

ImmutableBitmap is chosen to own the SkImage because it guarantees that
the underlying pixels cannot be modified. This is not the case for
Gfx::Bitmap, where invalidating the SkImage would be challenging since
it exposes pointers to underlying data through methods like scanline().
This commit is contained in:
Aliaksandr Kalenik
2024-11-09 05:48:17 +01:00
committed by Alexander Kalenik
parent 460803d2da
commit 698bca686e
20 changed files with 186 additions and 118 deletions

View File

@@ -269,7 +269,9 @@ String HTMLCanvasElement::to_data_url(StringView type, Optional<double> quality)
// 3. Let file be a serialization of this canvas element's bitmap as a file, passing type and quality if given.
auto snapshot = m_surface->create_snapshot();
auto file = serialize_bitmap(snapshot->bitmap(), type, move(quality));
auto bitmap = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, m_surface->size()));
m_surface->read_into_bitmap(*bitmap);
auto file = serialize_bitmap(bitmap, type, move(quality));
// 4. If file is null then return "data:,".
if (file.is_error()) {
@@ -301,8 +303,8 @@ WebIDL::ExceptionOr<void> HTMLCanvasElement::to_blob(JS::NonnullGCPtr<WebIDL::Ca
// 3. If this canvas element's bitmap has pixels (i.e., neither its horizontal dimension nor its vertical dimension is zero),
// then set result to a copy of this canvas element's bitmap.
if (m_surface) {
auto snapshot = m_surface->create_snapshot();
bitmap_result = snapshot->bitmap();
bitmap_result = MUST(Gfx::Bitmap::create(Gfx::BitmapFormat::BGRA8888, Gfx::AlphaType::Premultiplied, m_surface->size()));
m_surface->read_into_bitmap(*bitmap_result);
}
// 4. Run these steps in parallel: