Bug 1300682 - Part 2: Allow using the compositor device for IMFYCbCrImage. r=dvander
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 07 Oct 2016 21:13:32 +1300
changeset 316885 9aec9ca6a65915dfbb370c3e7a5af3bbd1c6ed2e
parent 316884 66adb66eeed57f304d0fc98de490e5714412e2b9
child 316886 0d5d1841286616dabd27d2cb629c46793bcf3ee4
push id82560
push usermwoodrow@mozilla.com
push dateFri, 07 Oct 2016 08:13:28 +0000
treeherdermozilla-inbound@4b28c86a0536 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs1300682
milestone52.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 1300682 - Part 2: Allow using the compositor device for IMFYCbCrImage. r=dvander
gfx/layers/IMFYCbCrImage.cpp
--- a/gfx/layers/IMFYCbCrImage.cpp
+++ b/gfx/layers/IMFYCbCrImage.cpp
@@ -32,28 +32,34 @@ IMFYCbCrImage::~IMFYCbCrImage()
   }
 }
 
 struct AutoLockTexture
 {
   AutoLockTexture(ID3D11Texture2D* aTexture)
   {
     aTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mMutex));
+    if (!mMutex) {
+      return;
+    }
     HRESULT hr = mMutex->AcquireSync(0, 10000);
     if (hr == WAIT_TIMEOUT) {
       MOZ_CRASH("GFX: IMFYCbCrImage timeout");
     }
 
     if (FAILED(hr)) {
       NS_WARNING("Failed to lock the texture");
     }
   }
 
   ~AutoLockTexture()
   {
+    if (!mMutex) {
+      return;
+    }
     HRESULT hr = mMutex->ReleaseSync(0);
     if (FAILED(hr)) {
       NS_WARNING("Failed to unlock the texture");
     }
   }
 
   RefPtr<IDXGIKeyedMutex> mMutex;
 };
@@ -222,16 +228,20 @@ TextureClient*
 IMFYCbCrImage::GetTextureClient(KnowsCompositor* aForwarder)
 {
   if (mTextureClient) {
     return mTextureClient;
   }
 
   RefPtr<ID3D11Device> device =
     gfx::DeviceManagerDx::Get()->GetContentDevice();
+  if (!device) {
+    device =
+      gfx::DeviceManagerDx::Get()->GetCompositorDevice();
+  }
 
   LayersBackend backend = aForwarder->GetCompositorBackendType();
   if (!device || backend != LayersBackend::LAYERS_D3D11) {
     if (backend == LayersBackend::LAYERS_D3D9 ||
         backend == LayersBackend::LAYERS_D3D11) {
       return GetD3D9TextureClient(aForwarder);
     }
     return nullptr;
@@ -240,17 +250,21 @@ IMFYCbCrImage::GetTextureClient(KnowsCom
   if (mData.mYStride < 0 || mData.mCbCrStride < 0) {
     // D3D11 only supports unsigned stride values.
     return nullptr;
   }
 
   CD3D11_TEXTURE2D_DESC newDesc(DXGI_FORMAT_R8_UNORM,
                                 mData.mYSize.width, mData.mYSize.height, 1, 1);
 
-  newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
+  if (device == gfx::DeviceManagerDx::Get()->GetCompositorDevice()) {
+    newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
+  } else {
+    newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
+  }
 
   RefPtr<ID3D11Texture2D> textureY;
   D3D11_SUBRESOURCE_DATA yData = { mData.mYChannel, (UINT)mData.mYStride, 0 };
   HRESULT hr = device->CreateTexture2D(&newDesc, &yData, getter_AddRefs(textureY));
   NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
 
   newDesc.Width = mData.mCbCrSize.width;
   newDesc.Height = mData.mCbCrSize.height;