mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 09:45:06 +02:00
LibGfx: Cache GPU textures for bitmap-backed ImmutableBitmaps
Previously, bitmap-backed images were stored as raster SkImages and re-uploaded to the GPU every frame. This caused significant overhead in createProxyFromBitmap, uploadToTexture, and memmove. Now, ensure_sk_image() converts raster SkImages to GPU textures using SkImages::TextureFromImage() on first use. The texture is cached and reused for subsequent frames. - Mipmaps disabled (kNo) to reduce upload time and memory - Budgeted (kYes) to let Skia manage GPU memory and evict under pressure - Falls back to raster rendering if no GPU context available
This commit is contained in:
committed by
Alexander Kalenik
parent
534c4c3736
commit
a1d538ae58
Notes:
github-actions[bot]
2026-02-06 11:09:12 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/a1d538ae585 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7610
@@ -298,24 +298,35 @@ static sk_sp<SkColorSpace> color_space_from_cicp(Media::CodingIndependentCodePoi
|
||||
|
||||
bool ImmutableBitmap::ensure_sk_image(SkiaBackendContext& context) const
|
||||
{
|
||||
if (m_impl->sk_image) {
|
||||
if (m_impl->context)
|
||||
VERIFY(m_impl->context.ptr() == &context);
|
||||
|
||||
if (m_impl->context) {
|
||||
VERIFY(m_impl->context.ptr() == &context);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Bitmap-backed ImmutableBitmaps must have an sk_image already.
|
||||
VERIFY(m_impl->yuv_data != nullptr);
|
||||
|
||||
context.lock();
|
||||
ScopeGuard unlock_guard = [&context] {
|
||||
context.unlock();
|
||||
};
|
||||
|
||||
auto* gr_context = context.sk_context();
|
||||
|
||||
// Bitmap-backed: try to upload raster image to GPU texture
|
||||
if (m_impl->sk_image) {
|
||||
if (!gr_context)
|
||||
return true; // No GPU, but raster image is still usable
|
||||
auto gpu_image = SkImages::TextureFromImage(gr_context, m_impl->sk_image.get(), skgpu::Mipmapped::kNo, skgpu::Budgeted::kYes);
|
||||
if (gpu_image) {
|
||||
m_impl->context = context;
|
||||
m_impl->sk_image = move(gpu_image);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// YUV-backed: GPU is required to decode YUV to RGB
|
||||
VERIFY(m_impl->yuv_data);
|
||||
|
||||
if (!gr_context)
|
||||
return false;
|
||||
return false; // No GPU, cannot create image from YUV data
|
||||
|
||||
auto const& pixmaps = m_impl->yuv_data->skia_yuva_pixmaps();
|
||||
auto color_space = color_space_from_cicp(m_impl->yuv_data->cicp());
|
||||
|
||||
Reference in New Issue
Block a user