Bug 1176570 - Make sure all shared texture handles are opened correctly before attempting to use them. r=jrmuizel
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 26 Jun 2015 14:07:57 -0700
changeset 250349 22bc3c64183865a51c1a0ae2814eca1c41ec3578
parent 250348 4c72e43c5ec2e3d8341c9d6412eeef5aa2fdff06
child 250350 198da127cf26f2ae90c3ce33d6d47b034690d9ff
push id61526
push usermwoodrow@mozilla.com
push dateFri, 26 Jun 2015 21:08:10 +0000
treeherdermozilla-inbound@22bc3c641838 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1176570
milestone41.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 1176570 - Make sure all shared texture handles are opened correctly before attempting to use them. r=jrmuizel
gfx/layers/d3d11/TextureD3D11.cpp
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -712,40 +712,46 @@ DXGIYCbCrTextureHostD3D11::DXGIYCbCrText
 
 bool
 DXGIYCbCrTextureHostD3D11::OpenSharedHandle()
 {
   if (!GetDevice()) {
     return false;
   }
 
+  RefPtr<ID3D11Texture2D> textures[3];
+
   HRESULT hr = GetDevice()->OpenSharedResource((HANDLE)mHandles[0],
                                                __uuidof(ID3D11Texture2D),
-                                               (void**)(ID3D11Texture2D**)byRef(mTextures[0]));
+                                               (void**)(ID3D11Texture2D**)byRef(textures[0]));
   if (FAILED(hr)) {
     NS_WARNING("Failed to open shared texture for Y Plane");
     return false;
   }
 
   hr = GetDevice()->OpenSharedResource((HANDLE)mHandles[1],
                                        __uuidof(ID3D11Texture2D),
-                                       (void**)(ID3D11Texture2D**)byRef(mTextures[1]));
+                                       (void**)(ID3D11Texture2D**)byRef(textures[1]));
   if (FAILED(hr)) {
     NS_WARNING("Failed to open shared texture for Cb Plane");
     return false;
   }
 
   hr = GetDevice()->OpenSharedResource((HANDLE)mHandles[2],
                                        __uuidof(ID3D11Texture2D),
-                                       (void**)(ID3D11Texture2D**)byRef(mTextures[2]));
+                                       (void**)(ID3D11Texture2D**)byRef(textures[2]));
   if (FAILED(hr)) {
     NS_WARNING("Failed to open shared texture for Cr Plane");
     return false;
   }
 
+  mTextures[0] = textures[0].forget();
+  mTextures[1] = textures[1].forget();
+  mTextures[2] = textures[2].forget();
+
   return true;
 }
 
 ID3D11Device*
 DXGIYCbCrTextureHostD3D11::GetDevice()
 {
   return gfxWindowsPlatform::GetPlatform()->GetD3D11Device();
 }
@@ -764,16 +770,18 @@ DXGIYCbCrTextureHostD3D11::Lock()
     NS_WARNING("trying to lock a TextureHost without a D3D device");
     return false;
   }
   if (!mTextureSources[0]) {
     if (!mTextures[0] && !OpenSharedHandle()) {
       return false;
     }
 
+    MOZ_ASSERT(mTextures[1] && mTextures[2]);
+
     mTextureSources[0] = new DataTextureSourceD3D11(SurfaceFormat::A8, mCompositor, mTextures[0]);
     mTextureSources[1] = new DataTextureSourceD3D11(SurfaceFormat::A8, mCompositor, mTextures[1]);
     mTextureSources[2] = new DataTextureSourceD3D11(SurfaceFormat::A8, mCompositor, mTextures[2]);
     mTextureSources[0]->SetNextSibling(mTextureSources[1]);
     mTextureSources[1]->SetNextSibling(mTextureSources[2]);
   }
 
   mIsLocked = LockD3DTexture(mTextureSources[0]->GetD3D11Texture()) &&