Bug 1089364 - Add some missing D3D11 error checks. r=Bas
authorNicolas Silva <nsilva@mozilla.com>
Mon, 27 Oct 2014 13:52:17 +0100
changeset 213001 c30b79646349e2efdbff534864370aadb49cb8fb
parent 213000 459d3080fdf8948c5d6e6419e1f2c8a34e6270cb
child 213002 233974607185bbc7449bd9d50b38c5ae88ce8760
push id27738
push usercbook@mozilla.com
push dateThu, 30 Oct 2014 13:46:07 +0000
treeherdermozilla-central@1aa1b23d799e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs1089364
milestone36.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 1089364 - Add some missing D3D11 error checks. r=Bas
gfx/layers/d3d11/CompositorD3D11.cpp
gfx/layers/d3d11/CompositorD3D11.h
--- a/gfx/layers/d3d11/CompositorD3D11.cpp
+++ b/gfx/layers/d3d11/CompositorD3D11.cpp
@@ -917,35 +917,42 @@ CompositorD3D11::EnsureSize()
 
   mSize = rect.Size();
 }
 
 void
 CompositorD3D11::VerifyBufferSize()
 {
   DXGI_SWAP_CHAIN_DESC swapDesc;
-  mSwapChain->GetDesc(&swapDesc);
+  HRESULT hr;
+
+  hr = mSwapChain->GetDesc(&swapDesc);
+  if (Failed(hr)) {
+    return;
+  }
 
   if ((swapDesc.BufferDesc.Width == mSize.width &&
        swapDesc.BufferDesc.Height == mSize.height) ||
       mSize.width == 0 || mSize.height == 0) {
     return;
   }
 
   mDefaultRT = nullptr;
 
   if (IsRunningInWindowsMetro()) {
-    mSwapChain->ResizeBuffers(2, mSize.width, mSize.height,
-                              DXGI_FORMAT_B8G8R8A8_UNORM,
-                              0);
+    hr = mSwapChain->ResizeBuffers(2, mSize.width, mSize.height,
+                                   DXGI_FORMAT_B8G8R8A8_UNORM,
+                                   0);
+    HandleError(hr);
     mDisableSequenceForNextFrame = true;
   } else {
-    mSwapChain->ResizeBuffers(1, mSize.width, mSize.height,
-                              DXGI_FORMAT_B8G8R8A8_UNORM,
-                              0);
+    hr = mSwapChain->ResizeBuffers(1, mSize.width, mSize.height,
+                                   DXGI_FORMAT_B8G8R8A8_UNORM,
+                                   0);
+    HandleError(hr);
   }
 }
 
 void
 CompositorD3D11::UpdateRenderTarget()
 {
   EnsureSize();
   VerifyBufferSize();
@@ -1071,50 +1078,64 @@ CompositorD3D11::SetSamplerForFilter(Fil
 
   mContext->PSSetSamplers(0, 1, &sampler);
 }
 
 void
 CompositorD3D11::PaintToTarget()
 {
   nsRefPtr<ID3D11Texture2D> backBuf;
+  HRESULT hr;
 
-  mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)backBuf.StartAssignment());
+  hr = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)backBuf.StartAssignment());
+  if (Failed(hr)) {
+    return;
+  }
 
   D3D11_TEXTURE2D_DESC bbDesc;
   backBuf->GetDesc(&bbDesc);
 
   CD3D11_TEXTURE2D_DESC softDesc(bbDesc.Format, bbDesc.Width, bbDesc.Height);
   softDesc.MipLevels = 1;
   softDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
   softDesc.Usage = D3D11_USAGE_STAGING;
   softDesc.BindFlags = 0;
 
   nsRefPtr<ID3D11Texture2D> readTexture;
 
-  HRESULT hr = mDevice->CreateTexture2D(&softDesc, nullptr, getter_AddRefs(readTexture));
+  hr = mDevice->CreateTexture2D(&softDesc, nullptr, getter_AddRefs(readTexture));
+  if (Failed(hr)) {
+    return;
+  }
   mContext->CopyResource(readTexture, backBuf);
 
   D3D11_MAPPED_SUBRESOURCE map;
-  mContext->Map(readTexture, 0, D3D11_MAP_READ, 0, &map);
+  hr = mContext->Map(readTexture, 0, D3D11_MAP_READ, 0, &map);
+  if (Failed(hr)) {
+    return;
+  }
   RefPtr<DataSourceSurface> sourceSurface =
     Factory::CreateWrappingDataSourceSurface((uint8_t*)map.pData,
                                              map.RowPitch,
                                              IntSize(bbDesc.Width, bbDesc.Height),
                                              SurfaceFormat::B8G8R8A8);
   mTarget->CopySurface(sourceSurface,
                        IntRect(0, 0, bbDesc.Width, bbDesc.Height),
                        IntPoint(-mTargetBounds.x, -mTargetBounds.y));
+
   mTarget->Flush();
   mContext->Unmap(readTexture, 0);
 }
 
 void
 CompositorD3D11::HandleError(HRESULT hr, Severity aSeverity)
 {
+  if (SUCCEEDED(hr)) {
+    return;
+  }
   // XXX - It would be nice to use gfxCriticalError, but it needs to
   // be made to work off the main thread first.
   MOZ_ASSERT(aSeverity != DebugAssert);
 
   if (aSeverity == Critical) {
     MOZ_CRASH("Unrecoverable D3D11 error");
   }
 
@@ -1130,23 +1151,21 @@ CompositorD3D11::HandleError(HRESULT hr,
   if (aSeverity == Recoverable) {
     NS_WARNING("Encountered a recoverable D3D11 error");
   }
 }
 
 bool
 CompositorD3D11::Failed(HRESULT hr, Severity aSeverity)
 {
-  if (FAILED(hr)) {
-    HandleError(hr, aSeverity);
-    return true;
-  }
-  return false;
+  HandleError(hr, aSeverity);
+  return FAILED(hr);
 }
 
 bool
 CompositorD3D11::Succeeded(HRESULT hr, Severity aSeverity)
 {
-  return !Failed(hr, aSeverity);
+  HandleError(hr, aSeverity);
+  return SUCCEEDED(hr);
 }
 
 }
 }
--- a/gfx/layers/d3d11/CompositorD3D11.h
+++ b/gfx/layers/d3d11/CompositorD3D11.h
@@ -144,17 +144,17 @@ public:
 
 private:
   enum Severity {
     Recoverable,
     DebugAssert,
     Critical,
   };
 
-  void HandleError(HRESULT hr, Severity aSeverity);
+  void HandleError(HRESULT hr, Severity aSeverity = DebugAssert);
   bool Failed(HRESULT hr, Severity aSeverity = DebugAssert);
   bool Succeeded(HRESULT hr, Severity aSeverity = DebugAssert);
 
   // ensure mSize is up to date with respect to mWidget
   void EnsureSize();
   void VerifyBufferSize();
   void UpdateRenderTarget();
   bool CreateShaders();