Bug 1490415 - prevent creating a GPUVideoTextureHost with a null wrapped texture; r=sotaro
authorAlex Gaynor <agaynor@mozilla.com>
Wed, 12 Sep 2018 00:17:10 +0000
changeset 435968 a66a85285cb09523916bc95e30a42056b798e935
parent 435967 82ec584ba21dc00124c94aed3807cc0342f5aa42
child 435969 8675ff71202cb14c8ff3d7138d8166ff5870b5cb
push id107758
push userdluca@mozilla.com
push dateWed, 12 Sep 2018 18:37:29 +0000
treeherdermozilla-inbound@e6d4af6ebdd5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1490415
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1490415 - prevent creating a GPUVideoTextureHost with a null wrapped texture; r=sotaro Differential Revision: https://phabricator.services.mozilla.com/D5563
gfx/layers/composite/GPUVideoTextureHost.cpp
gfx/layers/composite/GPUVideoTextureHost.h
gfx/layers/composite/TextureHost.cpp
--- a/gfx/layers/composite/GPUVideoTextureHost.cpp
+++ b/gfx/layers/composite/GPUVideoTextureHost.cpp
@@ -8,28 +8,41 @@
 #include "mozilla/dom/VideoDecoderManagerParent.h"
 #include "ImageContainer.h"
 #include "mozilla/layers/VideoBridgeParent.h"
 
 namespace mozilla {
 namespace layers {
 
 GPUVideoTextureHost::GPUVideoTextureHost(TextureFlags aFlags,
-                                         const SurfaceDescriptorGPUVideo& aDescriptor)
+                                         TextureHost* aWrappedTextureHost)
   : TextureHost(aFlags)
+  , mWrappedTextureHost(aWrappedTextureHost)
 {
   MOZ_COUNT_CTOR(GPUVideoTextureHost);
-  mWrappedTextureHost = VideoBridgeParent::GetSingleton()->LookupTexture(aDescriptor.handle());
 }
 
 GPUVideoTextureHost::~GPUVideoTextureHost()
 {
   MOZ_COUNT_DTOR(GPUVideoTextureHost);
 }
 
+GPUVideoTextureHost*
+GPUVideoTextureHost::CreateFromDescriptor(
+  TextureFlags aFlags,
+  const SurfaceDescriptorGPUVideo& aDescriptor)
+{
+  TextureHost* wrappedTextureHost =
+    VideoBridgeParent::GetSingleton()->LookupTexture(aDescriptor.handle());
+  if (!wrappedTextureHost) {
+    return nullptr;
+  }
+  return new GPUVideoTextureHost(aFlags, wrappedTextureHost);
+}
+
 bool
 GPUVideoTextureHost::Lock()
 {
   if (!mWrappedTextureHost) {
     return false;
   }
   return mWrappedTextureHost->Lock();
 }
--- a/gfx/layers/composite/GPUVideoTextureHost.h
+++ b/gfx/layers/composite/GPUVideoTextureHost.h
@@ -10,18 +10,20 @@
 #include "mozilla/layers/TextureHost.h"
 
 namespace mozilla {
 namespace layers {
 
 class GPUVideoTextureHost : public TextureHost
 {
 public:
- GPUVideoTextureHost(TextureFlags aFlags,
-                     const SurfaceDescriptorGPUVideo& aDescriptor);
+  static GPUVideoTextureHost* CreateFromDescriptor(
+    TextureFlags aFlags,
+    const SurfaceDescriptorGPUVideo& aDescriptor);
+
   virtual ~GPUVideoTextureHost();
 
   virtual void DeallocateDeviceData() override {}
 
   virtual void SetTextureSourceProvider(TextureSourceProvider* aProvider) override;
 
   virtual bool Lock() override;
 
@@ -60,15 +62,17 @@ public:
                                 const wr::LayoutRect& aBounds,
                                 const wr::LayoutRect& aClip,
                                 wr::ImageRendering aFilter,
                                 const Range<wr::ImageKey>& aImageKeys) override;
 
   virtual bool SupportsWrNativeTexture() override;
 
 protected:
+  GPUVideoTextureHost(TextureFlags aFlags, TextureHost* aWrappedTextureHost);
+
   RefPtr<TextureHost> mWrappedTextureHost;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif // MOZILLA_GFX_GPUVIDEOTEXTUREHOST_H
--- a/gfx/layers/composite/TextureHost.cpp
+++ b/gfx/layers/composite/TextureHost.cpp
@@ -331,17 +331,18 @@ CreateBackendIndependentTextureHost(cons
         }
         default:
           gfxCriticalError() << "Failed texture host for backend " << (int)data.type();
           MOZ_CRASH("GFX: No texture host for backend");
       }
       break;
     }
     case SurfaceDescriptor::TSurfaceDescriptorGPUVideo: {
-      result = new GPUVideoTextureHost(aFlags, aDesc.get_SurfaceDescriptorGPUVideo());
+      result = GPUVideoTextureHost::CreateFromDescriptor(
+        aFlags, aDesc.get_SurfaceDescriptorGPUVideo());
       break;
     }
 #ifdef XP_WIN
     case SurfaceDescriptor::TSurfaceDescriptorDIB: {
       if (!aDeallocator->IsSameProcess()) {
         NS_ERROR("A client process is trying to peek at our address space using a DIBTexture!");
         return nullptr;
       }