Commit c2f99c7e authored by sotaro's avatar sotaro
Browse files

Bug 1806096 - Added check for front TextureClient lost by...

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
parent c98e22e7
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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);

+4 −2
Original line number Diff line number Diff line
@@ -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;

+12 −3
Original line number Diff line number Diff line
@@ -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();