Bug 1806096 - Added check for front TextureClient lost by PersistentBufferProviderShared::SetKnowsCompositor() r=gfx-reviewers,lsalzman

Device reset could cause front TextureClient lost in PersistentBufferProviderShared::SetKnowsCompositor(). In this case, ShareableCanvasRenderer::UpdateCompositableClient() does not have TextureClient for compositor.

Differential Revision: https://phabricator.services.mozilla.com/D176748
This commit is contained in:
sotaro 2023-04-28 07:13:54 +00:00
parent c98e22e73d
commit c2f99c7e0e
3 changed files with 21 additions and 7 deletions

View File

@ -228,8 +228,9 @@ PersistentBufferProviderShared::~PersistentBufferProviderShared() {
}
bool PersistentBufferProviderShared::SetKnowsCompositor(
KnowsCompositor* aKnowsCompositor) {
KnowsCompositor* aKnowsCompositor, bool& aOutLostFrontTexture) {
MOZ_ASSERT(aKnowsCompositor);
MOZ_ASSERT(!aOutLostFrontTexture);
if (!aKnowsCompositor) {
return false;
}
@ -257,7 +258,9 @@ bool PersistentBufferProviderShared::SetKnowsCompositor(
// Get rid of everything else
Destroy();
if (prevTexture && prevTexture->IsValid()) {
if (prevTexture && !prevTexture->IsValid()) {
aOutLostFrontTexture = true;
} else if (prevTexture && prevTexture->IsValid()) {
RefPtr<TextureClient> newTexture =
CreateTexture(aKnowsCompositor, mFormat, mSize, mWillReadFrequently);

View File

@ -81,7 +81,8 @@ class PersistentBufferProvider : public RefCounted<PersistentBufferProvider>,
virtual void OnShutdown() {}
virtual bool SetKnowsCompositor(KnowsCompositor* aKnowsCompositor) {
virtual bool SetKnowsCompositor(KnowsCompositor* aKnowsCompositor,
bool& aOutLostFrontTexture) {
return true;
}
@ -207,7 +208,8 @@ class PersistentBufferProviderShared : public PersistentBufferProvider,
void OnShutdown() override { Destroy(); }
bool SetKnowsCompositor(KnowsCompositor* aKnowsCompositor) override;
bool SetKnowsCompositor(KnowsCompositor* aKnowsCompositor,
bool& aOutLostFrontTexture) override;
void ClearCachedResources() override;

View File

@ -120,15 +120,19 @@ void ShareableCanvasRenderer::UpdateCompositableClient() {
// -
const auto fnGetExistingTc =
[&](const Maybe<SurfaceDescriptor>& aDesc) -> RefPtr<TextureClient> {
[&](const Maybe<SurfaceDescriptor>& aDesc,
bool& aOutLostFrontTexture) -> RefPtr<TextureClient> {
if (aDesc) {
return GetFrontBufferFromDesc(*aDesc, flags);
}
if (provider) {
if (!provider->SetKnowsCompositor(forwarder)) {
if (!provider->SetKnowsCompositor(forwarder, aOutLostFrontTexture)) {
gfxCriticalNote << "BufferProvider::SetForwarder failed";
return nullptr;
}
if (aOutLostFrontTexture) {
return nullptr;
}
return provider->GetTextureClient();
}
@ -196,7 +200,12 @@ void ShareableCanvasRenderer::UpdateCompositableClient() {
EnsurePipeline();
// Let's see if we can get a no-copy TextureClient from the canvas.
auto tc = fnGetExistingTc(desc);
bool lostFrontTexture = false;
auto tc = fnGetExistingTc(desc, lostFrontTexture);
if (lostFrontTexture) {
// Device reset could cause this.
return;
}
if (!tc) {
// Otherwise, snapshot the surface and copy into a TexClient.
tc = fnMakeTcFromSnapshot();