Skip to content

Commit

Permalink
[gpu] Re-upload textures when a the internal Surface bitmap changes
Browse files Browse the repository at this point in the history
We can use the internal SkBitmap generation ID in the SkiaSurface to
know if the uploaded texture is already outdated and we have to
re-upload it to the GPU.
  • Loading branch information
dacap committed Jun 17, 2024
1 parent 968f0e4 commit feba52e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions os/skia/skia_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,10 @@ const SkImage* SkiaSurface::getOrCreateTextureImage() const
if (!win || !win->sk_grCtx())
return nullptr;

// Invalidate the cached texture if the bitmap pixels were modified.
if (m_cachedGen && m_cachedGen != m_bitmap.getGenerationID())
m_image.reset();

if (m_image && m_image->isValid(win->sk_grCtx()))
return m_image.get();
if (uploadBitmapAsTexture() &&
Expand Down Expand Up @@ -828,6 +832,9 @@ bool SkiaSurface::uploadBitmapAsTexture() const
ii.alphaType(),
nullptr);

if (m_image)
m_cachedGen = m_bitmap.getGenerationID();

return (m_image != nullptr);
}

Expand Down
2 changes: 2 additions & 0 deletions os/skia/skia_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class SkiaSurface final : public Surface {

SkBitmap m_bitmap;
#if SK_SUPPORT_GPU
// Cached m_bitmap generation in the GPU texture.
mutable uint32_t m_cachedGen = 0;
mutable sk_sp<SkImage> m_image;
#endif
sk_sp<SkSurface> m_surface;
Expand Down

0 comments on commit feba52e

Please sign in to comment.