Get the sync texture's sync handle during compositor initialization, where it can be made to fail gracefully. (bug 1207665 part 3, r=bas) a=sylvestre
☠☠ backed out by 69e3fb393cad ☠ ☠
authorDavid Anderson <danderson@mozilla.com>
Tue, 29 Sep 2015 11:16:16 -0700
changeset 296245 8de4694e5a549bc1068a31d719ed261f62ad6c4a
parent 296244 ba7918bc5551b8ad70be7db9087d0c18ebe9ffb6
child 296246 1ca0650854b4d2c83d8f9c8a59298775b09605c0
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas, sylvestre
bugs1207665
milestone43.0a2
Get the sync texture's sync handle during compositor initialization, where it can be made to fail gracefully. (bug 1207665 part 3, r=bas) a=sylvestre
gfx/layers/d3d11/CompositorD3D11.cpp
--- a/gfx/layers/d3d11/CompositorD3D11.cpp
+++ b/gfx/layers/d3d11/CompositorD3D11.cpp
@@ -42,21 +42,23 @@ static const GUID sDeviceAttachmentsD3D1
 static const GUID sLayerManagerCount =
 { 0x88041664, 0xc835, 0x4aa8, { 0xac, 0xb8, 0x7e, 0xc8, 0x32, 0x35, 0x7e, 0xd8 } };
 
 const FLOAT sBlendFactor[] = { 0, 0, 0, 0 };
 
 struct DeviceAttachmentsD3D11
 {
   DeviceAttachmentsD3D11(ID3D11Device* device)
-   : mDevice(device),
+   : mSyncHandle(0),
+     mDevice(device),
      mInitOkay(true)
   {}
 
   bool CreateShaders();
+  bool InitSyncObject();
 
   typedef EnumeratedArray<MaskType, MaskType::NumMaskTypes, RefPtr<ID3D11VertexShader>>
           VertexShaderArray;
   typedef EnumeratedArray<MaskType, MaskType::NumMaskTypes, RefPtr<ID3D11PixelShader>>
           PixelShaderArray;
 
   RefPtr<ID3D11InputLayout> mInputLayout;
   RefPtr<ID3D11Buffer> mVertexBuffer;
@@ -75,16 +77,17 @@ struct DeviceAttachmentsD3D11
   RefPtr<ID3D11SamplerState> mPointSamplerState;
   RefPtr<ID3D11BlendState> mPremulBlendState;
   RefPtr<ID3D11BlendState> mNonPremulBlendState;
   RefPtr<ID3D11BlendState> mPremulBlendMultiplyState;
   RefPtr<ID3D11BlendState> mPremulBlendScreenState;
   RefPtr<ID3D11BlendState> mComponentBlendState;
   RefPtr<ID3D11BlendState> mDisabledBlendState;
   RefPtr<IDXGIResource> mSyncTexture;
+  HANDLE mSyncHandle;
 
   //
   // VR pieces
   //
   typedef EnumeratedArray<VRHMDType, VRHMDType::NumHMDTypes, RefPtr<ID3D11InputLayout>>
           VRDistortionInputLayoutArray;
   typedef EnumeratedArray<VRHMDType, VRHMDType::NumHMDTypes, RefPtr<ID3D11VertexShader>>
           VRVertexShaderArray;
@@ -355,34 +358,18 @@ CompositorD3D11::Initialize()
       D3D11_COLOR_WRITE_ENABLE_ALL
     };
     blendDesc.RenderTarget[0] = rtBlendDisabled;
     hr = mDevice->CreateBlendState(&blendDesc, byRef(mAttachments->mDisabledBlendState));
     if (FAILED(hr)) {
       return false;
     }
 
-    if (!gfxWindowsPlatform::GetPlatform()->IsWARP()) {
-      // It's okay to do this on Windows 8. But for now we'll just bail
-      // whenever we're using WARP.
-      CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, 1, 1, 1, 1,
-                                 D3D11_BIND_SHADER_RESOURCE |
-                                 D3D11_BIND_RENDER_TARGET);
-      desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
-
-      RefPtr<ID3D11Texture2D> texture;
-      hr = mDevice->CreateTexture2D(&desc, nullptr, byRef(texture));
-      if (FAILED(hr)) {
-        return false;
-      }
-
-      hr = texture->QueryInterface((IDXGIResource**)byRef(mAttachments->mSyncTexture));
-      if (FAILED(hr)) {
-        return false;
-      }
+    if (!mAttachments->InitSyncObject()) {
+      return false;
     }
     
     //
     // VR additions
     //
     D3D11_INPUT_ELEMENT_DESC vrlayout[] =
     {
       { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT,       0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
@@ -469,24 +456,17 @@ CompositorD3D11::CreateDataTextureSource
 
 TextureFactoryIdentifier
 CompositorD3D11::GetTextureFactoryIdentifier()
 {
   TextureFactoryIdentifier ident;
   ident.mMaxTextureSize = GetMaxTextureSize();
   ident.mParentProcessId = XRE_GetProcessType();
   ident.mParentBackend = LayersBackend::LAYERS_D3D11;
-  if (mAttachments->mSyncTexture) {
-    HRESULT hr = mAttachments->mSyncTexture->GetSharedHandle(&ident.mSyncHandle);
-    if (FAILED(hr) || !ident.mSyncHandle) {
-      gfxCriticalError() << "Failed to get SharedHandle for sync texture. Result: "
-                         << hexa(hr);
-      MOZ_CRASH();
-    }
-  }
+  ident.mSyncHandle = mAttachments->mSyncHandle;
   ident.mSupportedBlendModes += gfx::CompositionOp::OP_SCREEN;
   ident.mSupportedBlendModes += gfx::CompositionOp::OP_MULTIPLY;
   return ident;
 }
 
 bool
 CompositorD3D11::CanUseCanvasLayerForSize(const gfx::IntSize& aSize)
 {
@@ -1343,16 +1323,52 @@ CompositorD3D11::UpdateRenderTarget()
     return;
   }
 
   mDefaultRT = new CompositingRenderTargetD3D11(backBuf, IntPoint(0, 0));
   mDefaultRT->SetSize(mSize);
 }
 
 bool
+DeviceAttachmentsD3D11::InitSyncObject()
+{
+  // Sync object is not supported on WARP.
+  if (gfxWindowsPlatform::GetPlatform()->IsWARP()) {
+    return true;
+  }
+
+  // It's okay to do this on Windows 8. But for now we'll just bail
+  // whenever we're using WARP.
+  CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, 1, 1, 1, 1,
+                             D3D11_BIND_SHADER_RESOURCE |
+                             D3D11_BIND_RENDER_TARGET);
+  desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
+
+  RefPtr<ID3D11Texture2D> texture;
+  HRESULT hr = mDevice->CreateTexture2D(&desc, nullptr, byRef(texture));
+  if (FAILED(hr)) {
+    return false;
+  }
+
+  hr = texture->QueryInterface((IDXGIResource**)byRef(mSyncTexture));
+  if (FAILED(hr)) {
+    return false;
+  }
+
+  hr = mSyncTexture->GetSharedHandle(&mSyncHandle);
+  if (FAILED(hr) || !mSyncHandle) {
+    gfxCriticalError() << "Failed to get SharedHandle for sync texture. Result: "
+                       << hexa(hr);
+    MOZ_CRASH();
+  }
+
+  return true;
+}
+
+bool
 DeviceAttachmentsD3D11::CreateShaders()
 {
   InitVertexShader(sLayerQuadVS, mVSQuadShader, MaskType::MaskNone);
   InitVertexShader(sLayerQuadMaskVS, mVSQuadShader, MaskType::Mask2d);
   InitVertexShader(sLayerQuadMask3DVS, mVSQuadShader, MaskType::Mask3d);
 
   InitPixelShader(sSolidColorShader, mSolidColorShader, MaskType::MaskNone);
   InitPixelShader(sSolidColorShaderMask, mSolidColorShader, MaskType::Mask2d);