Bug 1287653 - Minor fixes in D3D11Checks. - r=mattwoodrow draft
authorJeff Gilbert <jgilbert@mozilla.com>
Sun, 17 Jul 2016 13:54:23 -0700
changeset 394103 819c5fc600a83b538970155f4666bd5a1dc55d5d
parent 394102 7ef8197633aa58ad428995ea09c5cd8ee79a558c
child 394104 b7e766981970a4c0ca88d535ec91c8d7789495c9
push id24492
push userbmo:jgilbert@mozilla.com
push dateFri, 29 Jul 2016 03:02:43 +0000
reviewersmattwoodrow
bugs1287653
milestone50.0a1
Bug 1287653 - Minor fixes in D3D11Checks. - r=mattwoodrow MozReview-Commit-ID: l8VkUewdhA
gfx/thebes/D3D11Checks.cpp
--- a/gfx/thebes/D3D11Checks.cpp
+++ b/gfx/thebes/D3D11Checks.cpp
@@ -85,34 +85,34 @@ D3D11Checks::DoesRenderTargetViewNeedRec
     deviceContext->ClearRenderTargetView(offscreenRTView, color2);
     D3D11_TEXTURE2D_DESC desc;
 
     offscreenTexture->GetDesc(&desc);
     desc.Usage = D3D11_USAGE_STAGING;
     desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
     desc.MiscFlags = 0;
     desc.BindFlags = 0;
-    ID3D11Texture2D* cpuTexture;
-    hr = aDevice->CreateTexture2D(&desc, NULL, &cpuTexture);
+    RefPtr<ID3D11Texture2D> cpuTexture;
+    hr = aDevice->CreateTexture2D(&desc, NULL, getter_AddRefs(cpuTexture));
     if (FAILED(hr)) {
         gfxCriticalNote << "DoesRecreatingCreateCPUTextureFailed";
         return false;
     }
 
     deviceContext->CopyResource(cpuTexture, offscreenTexture);
 
     D3D11_MAPPED_SUBRESOURCE mapped;
     hr = deviceContext->Map(cpuTexture, 0, D3D11_MAP_READ, 0, &mapped);
     if (FAILED(hr)) {
         gfxCriticalNote << "DoesRecreatingMapFailed " << hexa(hr);
         return false;
     }
     int resultColor = *(int*)mapped.pData;
     deviceContext->Unmap(cpuTexture, 0);
-    cpuTexture->Release();
+    cpuTexture = nullptr;
 
     // XXX on some drivers resultColor will not have changed to
     // match the clear
     if (resultColor != 0xffffff00) {
         gfxCriticalNote << "RenderTargetViewNeedsRecreating";
         result = true;
     }
 
@@ -306,29 +306,30 @@ DoesTextureSharingWorkInternal(ID3D11Dev
     gfxCriticalError() << "DoesD3D11TextureSharingWork_AcquireSyncTimeout";
     // only wait for 30 seconds
     return false;
   }
 
   // Copy to the cpu texture so that we can readback
   deviceContext->CopyResource(cpuTexture, sharedTexture);
 
+  // We only need to hold on to the mutex during the copy.
+  sharedMutex->ReleaseSync(0);
+
   D3D11_MAPPED_SUBRESOURCE mapped;
-  int resultColor = 0;
+  uint32_t resultColor = 0;
   if (SUCCEEDED(deviceContext->Map(cpuTexture, 0, D3D11_MAP_READ, 0, &mapped))) {
     // read the texture
-    resultColor = *(int*)mapped.pData;
+    resultColor = *(uint32_t*)mapped.pData;
     deviceContext->Unmap(cpuTexture, 0);
   } else {
     gfxCriticalError() << "DoesD3D11TextureSharingWork_MapFailed";
     return false;
   }
 
-  sharedMutex->ReleaseSync(0);
-
   // check that the color we put in is the color we get out
   if (resultColor != color[0]) {
     // Shared surfaces seem to be broken on dual AMD & Intel HW when using the
     // AMD GPU
     gfxCriticalNote << "DoesD3D11TextureSharingWork_ColorMismatch";
     return false;
   }