From 855109b02862ed5680500de105147bf6e79adc45 Mon Sep 17 00:00:00 2001 From: Jeremy Andrews Date: Mon, 23 Oct 2023 22:36:00 -0500 Subject: Issue #2357 - Paused WebM videos w/alpha are 100% transparent if HA is disabled. Mozilla found a bug in their initial implementation, causing paused WebM videos with alpha to become totally transparent if hardware acceleration is disabled. Straight port of the Firefox 54 fix. Ref: BZ 1332952 --- gfx/layers/ipc/SharedRGBImage.cpp | 27 ++++++++++++++++++++++++++- gfx/layers/ipc/SharedRGBImage.h | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gfx/layers/ipc/SharedRGBImage.cpp b/gfx/layers/ipc/SharedRGBImage.cpp index bb3bb968cd..2db2ef105a 100644 --- a/gfx/layers/ipc/SharedRGBImage.cpp +++ b/gfx/layers/ipc/SharedRGBImage.cpp @@ -106,7 +106,32 @@ SharedRGBImage::GetTextureClient(KnowsCompositor* aForwarder) already_AddRefed SharedRGBImage::GetAsSourceSurface() { - return nullptr; + NS_ASSERTION(NS_IsMainThread(), "Must be main thread"); + + if (mSourceSurface) { + RefPtr surface(mSourceSurface); + return surface.forget(); + } + + RefPtr surface; + { + // We are 'borrowing' the DrawTarget and retaining a permanent reference to + // the underlying data (via the surface). It is in this instance since we + // know that the TextureClient is always wrapping a BufferTextureData and + // therefore it won't go away underneath us. + BufferTextureData* decoded_buffer = + mTextureClient->GetInternalData()->AsBufferTextureData(); + RefPtr drawTarget = decoded_buffer->BorrowDrawTarget(); + + if (!drawTarget) { + return nullptr; + } + + surface = drawTarget->Snapshot(); + } + + mSourceSurface = surface; + return surface.forget(); } } // namespace layers diff --git a/gfx/layers/ipc/SharedRGBImage.h b/gfx/layers/ipc/SharedRGBImage.h index 2c6009c19c..7122b27bc4 100644 --- a/gfx/layers/ipc/SharedRGBImage.h +++ b/gfx/layers/ipc/SharedRGBImage.h @@ -51,6 +51,7 @@ private: gfx::IntSize mSize; RefPtr mCompositable; RefPtr mTextureClient; + nsCountedRef mSourceSurface; }; } // namespace layers -- cgit v1.2.3