Bug 1568419 - Handle a case that NumSubTextures() returns 0 in AsyncImagePipelineManager::UpdateImageKeys() r=nical, a=RyanVM
authorsotaro <sotaro.ikeda.g@gmail.com>
Wed, 24 Jul 2019 13:33:57 +0000
changeset 544780 03ecebbe614d362db589181059186b165265956b
parent 544779 1eee7ed3de831a92e58f0328b6c3f817ca0c4d13
child 544781 d65aa43e6960433cc6eacb88887c3184079cd66f
push id2131
push userffxbld-merge
push dateMon, 26 Aug 2019 18:30:20 +0000
treeherdermozilla-release@b19ffb3ca153 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical, RyanVM
bugs1568419
milestone69.0
Bug 1568419 - Handle a case that NumSubTextures() returns 0 in AsyncImagePipelineManager::UpdateImageKeys() r=nical, a=RyanVM GPUVideoTextureHost::NumSubTextures() returns 0 when wrapped TextureHost does not exist. In this case, we do not have a content of GPUVideoTextureHost for WR render. And EnsureWrappedTextureHost() calling is added in GPUVideoTextureHost::NumSubTextures(), since GPUVideoTextureHost is not explicit about when a wrapped TextureHost is created. Differential Revision: https://phabricator.services.mozilla.com/D39137
gfx/layers/composite/GPUVideoTextureHost.cpp
gfx/layers/composite/GPUVideoTextureHost.h
gfx/layers/composite/TextureHost.cpp
gfx/layers/composite/TextureHost.h
gfx/layers/d3d11/TextureD3D11.cpp
gfx/layers/d3d11/TextureD3D11.h
gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
gfx/layers/wr/AsyncImagePipelineManager.cpp
gfx/layers/wr/WebRenderTextureHost.cpp
gfx/layers/wr/WebRenderTextureHost.h
--- a/gfx/layers/composite/GPUVideoTextureHost.cpp
+++ b/gfx/layers/composite/GPUVideoTextureHost.cpp
@@ -113,22 +113,22 @@ void GPUVideoTextureHost::CreateRenderTe
   MOZ_ASSERT(EnsureWrappedTextureHost());
   if (!EnsureWrappedTextureHost()) {
     return;
   }
 
   EnsureWrappedTextureHost()->CreateRenderTexture(aExternalImageId);
 }
 
-uint32_t GPUVideoTextureHost::NumSubTextures() const {
-  MOZ_ASSERT(mWrappedTextureHost);
-  if (!mWrappedTextureHost) {
+uint32_t GPUVideoTextureHost::NumSubTextures() {
+  MOZ_ASSERT(EnsureWrappedTextureHost());
+  if (!EnsureWrappedTextureHost()) {
     return 0;
   }
-  return mWrappedTextureHost->NumSubTextures();
+  return EnsureWrappedTextureHost()->NumSubTextures();
 }
 
 void GPUVideoTextureHost::PushResourceUpdates(
     wr::TransactionBuilder& aResources, ResourceUpdateOp aOp,
     const Range<wr::ImageKey>& aImageKeys, const wr::ExternalImageId& aExtID) {
   MOZ_ASSERT(EnsureWrappedTextureHost());
   if (!EnsureWrappedTextureHost()) {
     return;
--- a/gfx/layers/composite/GPUVideoTextureHost.h
+++ b/gfx/layers/composite/GPUVideoTextureHost.h
@@ -45,17 +45,17 @@ class GPUVideoTextureHost : public Textu
   const char* Name() override { return "GPUVideoTextureHost"; }
 #endif
 
   bool HasIntermediateBuffer() const override;
 
   void CreateRenderTexture(
       const wr::ExternalImageId& aExternalImageId) override;
 
-  uint32_t NumSubTextures() const override;
+  uint32_t NumSubTextures() override;
 
   void PushResourceUpdates(wr::TransactionBuilder& aResources,
                            ResourceUpdateOp aOp,
                            const Range<wr::ImageKey>& aImageKeys,
                            const wr::ExternalImageId& aExtID) override;
 
   void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
                         const wr::LayoutRect& aBounds,
--- a/gfx/layers/composite/TextureHost.cpp
+++ b/gfx/layers/composite/TextureHost.cpp
@@ -565,17 +565,17 @@ void BufferTextureHost::CreateRenderText
     const wr::ExternalImageId& aExternalImageId) {
   RefPtr<wr::RenderTextureHost> texture =
       new wr::RenderBufferTextureHost(GetBuffer(), GetBufferDescriptor());
 
   wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId),
                                                  texture.forget());
 }
 
-uint32_t BufferTextureHost::NumSubTextures() const {
+uint32_t BufferTextureHost::NumSubTextures() {
   if (GetFormat() == gfx::SurfaceFormat::YUV) {
     return 3;
   }
 
   return 1;
 }
 
 void BufferTextureHost::PushResourceUpdates(
--- a/gfx/layers/composite/TextureHost.h
+++ b/gfx/layers/composite/TextureHost.h
@@ -637,17 +637,17 @@ class TextureHost : public AtomicRefCoun
       const wr::ExternalImageId& aExternalImageId) {
     MOZ_RELEASE_ASSERT(
         false,
         "No CreateRenderTexture() implementation for this TextureHost type.");
   }
 
   /// Returns the number of actual textures that will be used to render this.
   /// For example in a lot of YUV cases it will be 3
-  virtual uint32_t NumSubTextures() const { return 1; }
+  virtual uint32_t NumSubTextures() { return 1; }
 
   enum ResourceUpdateOp {
     ADD_IMAGE,
     UPDATE_IMAGE,
   };
 
   // Add all necessary TextureHost informations to the resource update queue.
   virtual void PushResourceUpdates(wr::TransactionBuilder& aResources,
@@ -774,17 +774,17 @@ class BufferTextureHost : public Texture
 
   BufferTextureHost* AsBufferTextureHost() override { return this; }
 
   const BufferDescriptor& GetBufferDescriptor() const { return mDescriptor; }
 
   void CreateRenderTexture(
       const wr::ExternalImageId& aExternalImageId) override;
 
-  uint32_t NumSubTextures() const override;
+  uint32_t NumSubTextures() override;
 
   void PushResourceUpdates(wr::TransactionBuilder& aResources,
                            ResourceUpdateOp aOp,
                            const Range<wr::ImageKey>& aImageKeys,
                            const wr::ExternalImageId& aExtID) override;
 
   void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
                         const wr::LayoutRect& aBounds,
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -978,17 +978,17 @@ void DXGITextureHostD3D11::CreateRenderT
     const wr::ExternalImageId& aExternalImageId) {
   RefPtr<wr::RenderTextureHost> texture =
       new wr::RenderDXGITextureHostOGL(mHandle, mFormat, mSize);
 
   wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId),
                                                  texture.forget());
 }
 
-uint32_t DXGITextureHostD3D11::NumSubTextures() const {
+uint32_t DXGITextureHostD3D11::NumSubTextures() {
   switch (GetFormat()) {
     case gfx::SurfaceFormat::R8G8B8X8:
     case gfx::SurfaceFormat::R8G8B8A8:
     case gfx::SurfaceFormat::B8G8R8A8:
     case gfx::SurfaceFormat::B8G8R8X8: {
       return 1;
     }
     case gfx::SurfaceFormat::NV12:
@@ -1238,17 +1238,17 @@ void DXGIYCbCrTextureHostD3D11::CreateRe
     const wr::ExternalImageId& aExternalImageId) {
   RefPtr<wr::RenderTextureHost> texture =
       new wr::RenderDXGIYCbCrTextureHostOGL(mHandles, mSize, mSizeCbCr);
 
   wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId),
                                                  texture.forget());
 }
 
-uint32_t DXGIYCbCrTextureHostD3D11::NumSubTextures() const {
+uint32_t DXGIYCbCrTextureHostD3D11::NumSubTextures() {
   // ycbcr use 3 sub textures.
   return 3;
 }
 
 void DXGIYCbCrTextureHostD3D11::PushResourceUpdates(
     wr::TransactionBuilder& aResources, ResourceUpdateOp aOp,
     const Range<wr::ImageKey>& aImageKeys, const wr::ExternalImageId& aExtID) {
   if (!gfx::gfxVars::UseWebRenderANGLE()) {
--- a/gfx/layers/d3d11/TextureD3D11.h
+++ b/gfx/layers/d3d11/TextureD3D11.h
@@ -337,17 +337,17 @@ class DXGITextureHostD3D11 : public Text
     return mYUVColorSpace;
   }
 
   already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override;
 
   void CreateRenderTexture(
       const wr::ExternalImageId& aExternalImageId) override;
 
-  uint32_t NumSubTextures() const override;
+  uint32_t NumSubTextures() override;
 
   void PushResourceUpdates(wr::TransactionBuilder& aResources,
                            ResourceUpdateOp aOp,
                            const Range<wr::ImageKey>& aImageKeys,
                            const wr::ExternalImageId& aExtID) override;
 
   void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
                         const wr::LayoutRect& aBounds,
@@ -406,17 +406,17 @@ class DXGIYCbCrTextureHostD3D11 : public
 
   already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override {
     return nullptr;
   }
 
   void CreateRenderTexture(
       const wr::ExternalImageId& aExternalImageId) override;
 
-  uint32_t NumSubTextures() const override;
+  uint32_t NumSubTextures() override;
 
   void PushResourceUpdates(wr::TransactionBuilder& aResources,
                            ResourceUpdateOp aOp,
                            const Range<wr::ImageKey>& aImageKeys,
                            const wr::ExternalImageId& aExtID) override;
 
   void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
                         const wr::LayoutRect& aBounds,
--- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
+++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.cpp
@@ -126,17 +126,17 @@ void MacIOSurfaceTextureHostOGL::CreateR
     const wr::ExternalImageId& aExternalImageId) {
   RefPtr<wr::RenderTextureHost> texture =
       new wr::RenderMacIOSurfaceTextureHostOGL(GetMacIOSurface());
 
   wr::RenderThread::Get()->RegisterExternalImage(wr::AsUint64(aExternalImageId),
                                                  texture.forget());
 }
 
-uint32_t MacIOSurfaceTextureHostOGL::NumSubTextures() const {
+uint32_t MacIOSurfaceTextureHostOGL::NumSubTextures() {
   switch (GetFormat()) {
     case gfx::SurfaceFormat::R8G8B8X8:
     case gfx::SurfaceFormat::R8G8B8A8:
     case gfx::SurfaceFormat::B8G8R8A8:
     case gfx::SurfaceFormat::B8G8R8X8:
     case gfx::SurfaceFormat::YUV422: {
       return 1;
     }
--- a/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
+++ b/gfx/layers/opengl/MacIOSurfaceTextureHostOGL.h
@@ -61,17 +61,17 @@ class MacIOSurfaceTextureHostOGL : publi
     return this;
   }
 
   MacIOSurface* GetMacIOSurface() override { return mSurface; }
 
   void CreateRenderTexture(
       const wr::ExternalImageId& aExternalImageId) override;
 
-  uint32_t NumSubTextures() const override;
+  uint32_t NumSubTextures() override;
 
   void PushResourceUpdates(wr::TransactionBuilder& aResources,
                            ResourceUpdateOp aOp,
                            const Range<wr::ImageKey>& aImageKeys,
                            const wr::ExternalImageId& aExtID) override;
 
   void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
                         const wr::LayoutRect& aBounds,
--- a/gfx/layers/wr/AsyncImagePipelineManager.cpp
+++ b/gfx/layers/wr/AsyncImagePipelineManager.cpp
@@ -221,18 +221,19 @@ Maybe<TextureHost::ResourceUpdateOp> Asy
     // The texture has not changed, just reuse previous ImageKeys.
     aKeys = aPipeline->mKeys;
     if (aPipeline->mWrTextureWrapper) {
       HoldExternalImage(aPipelineId, aEpoch, aPipeline->mWrTextureWrapper);
     }
     return Nothing();
   }
 
-  if (!texture) {
-    // We don't have a new texture, there isn't much we can do.
+  if (!texture || texture->NumSubTextures() == 0) {
+    // We don't have a new texture or texture does not have SubTextures, there
+    // isn't much we can do.
     aKeys = aPipeline->mKeys;
     if (aPipeline->mWrTextureWrapper) {
       HoldExternalImage(aPipelineId, aEpoch, aPipeline->mWrTextureWrapper);
     }
     return Nothing();
   }
 
   aPipeline->mCurrentTexture = texture;
@@ -252,16 +253,17 @@ Maybe<TextureHost::ResourceUpdateOp> Asy
   bool useWrTextureWrapper =
       useExternalImage && wrTexture && wrTexture->SupportsWrNativeTexture();
   // XXX Re-enable fast path for async native texture updates(Bug 1559294)
   useWrTextureWrapper = false;
 
   // The non-external image code path falls back to converting the texture into
   // an rgb image.
   auto numKeys = useExternalImage ? texture->NumSubTextures() : 1;
+  MOZ_ASSERT(numKeys > 0);
 
   // If we already had a texture and the format hasn't changed, better to reuse
   // the image keys than create new ones.
   bool canUpdate = !!previousTexture &&
                    previousTexture->GetSize() == texture->GetSize() &&
                    previousTexture->GetFormat() == texture->GetFormat() &&
                    previousTexture->NeedsYFlip() == texture->NeedsYFlip() &&
                    aPipeline->mKeys.Length() == numKeys;
--- a/gfx/layers/wr/WebRenderTextureHost.cpp
+++ b/gfx/layers/wr/WebRenderTextureHost.cpp
@@ -196,17 +196,17 @@ int32_t WebRenderTextureHost::GetRGBStri
   return ImageDataSerializer::ComputeRGBStride(format, GetSize().width);
 }
 
 bool WebRenderTextureHost::HasIntermediateBuffer() const {
   MOZ_ASSERT(mWrappedTextureHost);
   return mWrappedTextureHost->HasIntermediateBuffer();
 }
 
-uint32_t WebRenderTextureHost::NumSubTextures() const {
+uint32_t WebRenderTextureHost::NumSubTextures() {
   MOZ_ASSERT(mWrappedTextureHost);
   return mWrappedTextureHost->NumSubTextures();
 }
 
 void WebRenderTextureHost::PushResourceUpdates(
     wr::TransactionBuilder& aResources, ResourceUpdateOp aOp,
     const Range<wr::ImageKey>& aImageKeys, const wr::ExternalImageId& aExtID) {
   MOZ_ASSERT(mWrappedTextureHost);
--- a/gfx/layers/wr/WebRenderTextureHost.h
+++ b/gfx/layers/wr/WebRenderTextureHost.h
@@ -64,17 +64,17 @@ class WebRenderTextureHost : public Text
   virtual void PrepareForUse() override;
 
   wr::ExternalImageId GetExternalImageKey() { return mExternalImageId; }
 
   int32_t GetRGBStride();
 
   bool HasIntermediateBuffer() const override;
 
-  uint32_t NumSubTextures() const override;
+  uint32_t NumSubTextures() override;
 
   void PushResourceUpdates(wr::TransactionBuilder& aResources,
                            ResourceUpdateOp aOp,
                            const Range<wr::ImageKey>& aImageKeys,
                            const wr::ExternalImageId& aExtID) override;
 
   void PushDisplayItems(wr::DisplayListBuilder& aBuilder,
                         const wr::LayoutRect& aBounds,