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:
Aliaksandr Kalenik
2026-01-24 20:08:00 +01:00
committed by Alexander Kalenik
parent 534c4c3736
commit a1d538ae58
Notes: github-actions[bot] 2026-02-06 11:09:12 +00:00

View File

@@ -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());