Null-check D3D10 devices in a few places. (bug 1225645, r=bas)
authorDavid Anderson <danderson@mozilla.com>
Thu, 19 Nov 2015 15:04:46 -0800
changeset 273442 7683624ba8265f0ea4ebb3aad1745cd978d6b57d
parent 273441 88359067c6e266fed5908c9f610a52782036b877
child 273443 50b8122fd926f7808d44594ba8f2742990c37112
push id29702
push usercbook@mozilla.com
push dateFri, 20 Nov 2015 12:13:22 +0000
treeherdermozilla-central@ec628289d8b4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs1225645
milestone45.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
Null-check D3D10 devices in a few places. (bug 1225645, r=bas)
gfx/2d/DrawTargetD2D.cpp
gfx/2d/SourceSurfaceD2DTarget.cpp
gfx/layers/d3d11/TextureD3D11.cpp
--- a/gfx/2d/DrawTargetD2D.cpp
+++ b/gfx/2d/DrawTargetD2D.cpp
@@ -467,16 +467,19 @@ DrawTargetD2D::DrawSurfaceWithShadow(Sou
 
   AutoSaveRestoreClippedOut restoreClippedOut(this);
 
   if (!IsOperatorBoundByMask(aOperator)) {
     restoreClippedOut.Save();
   }
 
   srView = static_cast<SourceSurfaceD2DTarget*>(aSurface)->GetSRView();
+  if (!srView) {
+    return;
+  }
 
   EnsureViews();
 
   if (!mTempRTView) {
     // This view is only needed in this path.
     HRESULT hr = mDevice->CreateRenderTargetView(mTempTexture, nullptr, getter_AddRefs(mTempRTView));
 
     if (FAILED(hr)) {
@@ -754,16 +757,21 @@ DrawTargetD2D::DrawSurfaceWithShadow(Sou
     mPrivateData->mEffect->GetTechniqueByName("SampleTextureWithShadow")->
       GetPassByIndex(1)->Apply(0);
   }
 
   mDevice->OMSetBlendState(GetBlendStateForOperator(aOperator), nullptr, 0xffffffff);
 
   mDevice->Draw(4, 0);
 
+  srView = static_cast<SourceSurfaceD2DTarget*>(aSurface)->GetSRView();
+  if (!srView) {
+    return;
+  }
+
   mPrivateData->mEffect->GetVariableByName("QuadDesc")->AsVector()->
     SetFloatVector(ShaderConstantRectD3D10(-1.0f + ((aDest.x / mSize.width) * 2.0f),
                                            1.0f - (aDest.y / mSize.height * 2.0f),
                                            (Float(aSurface->GetSize().width) / mSize.width) * 2.0f,
                                            (-Float(aSurface->GetSize().height) / mSize.height) * 2.0f));
   mPrivateData->mEffect->GetVariableByName("tex")->AsShaderResource()->SetResource(static_cast<SourceSurfaceD2DTarget*>(aSurface)->GetSRView());
   mPrivateData->mEffect->GetVariableByName("TexCoords")->AsVector()->
     SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
--- a/gfx/2d/SourceSurfaceD2DTarget.cpp
+++ b/gfx/2d/SourceSurfaceD2DTarget.cpp
@@ -91,16 +91,21 @@ SourceSurfaceD2DTarget::GetNativeSurface
 
 ID3D10ShaderResourceView*
 SourceSurfaceD2DTarget::GetSRView()
 {
   if (mSRView) {
     return mSRView;
   }
 
+  if (!Factory::GetDirect3D10Device()) {
+    gfxCriticalError() << "Invalid D3D10 device in D2D target surface";
+    return nullptr;
+  }
+
   HRESULT hr = Factory::GetDirect3D10Device()->CreateShaderResourceView(mTexture, nullptr, getter_AddRefs(mSRView));
 
   if (FAILED(hr)) {
     gfxWarning() << "Failed to create ShaderResourceView. Code: " << hexa(hr);
   }
 
   return mSRView;
 }
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -365,16 +365,19 @@ TextureClientD3D11::Unlock()
     // outside world between Lock() and Unlock(). This assertion checks that no outside
     // reference remains by the time Unlock() is called.
     MOZ_ASSERT(mDrawTarget->refCount() == 1);
     mDrawTarget->Flush();
   }
 
   if (NS_IsMainThread() && mReadbackSink && mTexture10) {
     ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
+    if (!device) {
+      return;
+    }
 
     D3D10_TEXTURE2D_DESC desc;
     mTexture10->GetDesc(&desc);
     desc.BindFlags = 0;
     desc.Usage = D3D10_USAGE_STAGING;
     desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
     desc.MiscFlags = 0;
 
@@ -583,16 +586,19 @@ TextureClientD3D11::AllocateForSurface(g
   bool haveD3d11Backend = (backend == BackendType::DIRECT2D1_1) || !NS_IsMainThread();
 
   if (haveD3d11Backend) {
     if (!AllocateD3D11Surface(d3d11device, aSize)) {
       return false;
     }
   } else {
     ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
+    if (!device) {
+      return false;
+    }
 
     CD3D10_TEXTURE2D_DESC newDesc(DXGI_FORMAT_B8G8R8A8_UNORM,
       aSize.width, aSize.height, 1, 1,
       D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE);
 
     newDesc.MiscFlags = D3D10_RESOURCE_MISC_SHARED;
 
     hr = device->CreateTexture2D(&newDesc, nullptr, getter_AddRefs(mTexture10));
@@ -1230,16 +1236,19 @@ SyncObjectD3D11::RegisterTexture(ID3D10T
 
 void
 SyncObjectD3D11::FinalizeFrame()
 {
   HRESULT hr;
 
   if (!mD3D10Texture && mD3D10SyncedTextures.size()) {
     ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
+    if (!device) {
+      return;
+    }
 
     hr = device->OpenSharedResource(mHandle, __uuidof(ID3D10Texture2D), (void**)(ID3D10Texture2D**)getter_AddRefs(mD3D10Texture));
     
     if (FAILED(hr) || !mD3D10Texture) {
       gfxCriticalError() << "Failed to D3D10 OpenSharedResource for frame finalization: " << hexa(hr);
 
       if (gfxWindowsPlatform::GetPlatform()->DidRenderingDeviceReset()) {
         return;
@@ -1300,16 +1309,19 @@ SyncObjectD3D11::FinalizeFrame()
       gfxDevCrash(LogReason::D3D10SyncLock) << "Timeout on the D3D10 sync lock";
     }
 
     D3D10_BOX box;
     box.front = box.top = box.left = 0;
     box.back = box.bottom = box.right = 1;
 
     ID3D10Device* device = gfxWindowsPlatform::GetPlatform()->GetD3D10Device();
+    if (!device) {
+      return;
+    }
 
     for (auto iter = mD3D10SyncedTextures.begin(); iter != mD3D10SyncedTextures.end(); iter++) {
       device->CopySubresourceRegion(mD3D10Texture, 0, 0, 0, 0, *iter, 0, &box);
     }
 
     mutex->ReleaseSync(0);
 
     mD3D10SyncedTextures.clear();