Bug 571507 - Add checks for texture creation failure to ContainerLayerD3D* - r=bas.schouten
authorJeff Gilbert <jgilbert@mozilla.com>
Thu, 03 Nov 2011 12:10:10 -0700
changeset 79709 a56d922453c736da7b5a27b10857a18dec741f33
parent 79708 57d804eae9a0edc732ed45bc95c69b92f8ef6a45
child 79710 765f5b79fedfa8b7cd239ac170e071b62986ae9b
push id21421
push userbmo@edmorley.co.uk
push dateFri, 04 Nov 2011 09:04:27 +0000
treeherdermozilla-central@e6893e6c883f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas.schouten
bugs571507
milestone10.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 571507 - Add checks for texture creation failure to ContainerLayerD3D* - r=bas.schouten
gfx/layers/d3d10/ImageLayerD3D10.cpp
gfx/layers/d3d10/LayerManagerD3D10.cpp
gfx/layers/d3d10/ThebesLayerD3D10.cpp
gfx/layers/d3d9/CanvasLayerD3D9.cpp
gfx/layers/d3d9/ContainerLayerD3D9.cpp
gfx/layers/d3d9/ImageLayerD3D9.cpp
gfx/layers/d3d9/ShadowBufferD3D9.cpp
gfx/layers/d3d9/ThebesLayerD3D9.cpp
--- a/gfx/layers/d3d10/ImageLayerD3D10.cpp
+++ b/gfx/layers/d3d10/ImageLayerD3D10.cpp
@@ -404,19 +404,28 @@ PlanarYCbCrImageD3D10::AllocateTextures(
 
   dataY.pSysMem = mData.mYChannel;
   dataY.SysMemPitch = mData.mYStride;
   dataCb.pSysMem = mData.mCbChannel;
   dataCb.SysMemPitch = mData.mCbCrStride;
   dataCr.pSysMem = mData.mCrChannel;
   dataCr.SysMemPitch = mData.mCbCrStride;
 
-  mDevice->CreateTexture2D(&descY, &dataY, getter_AddRefs(mYTexture));
-  mDevice->CreateTexture2D(&descCbCr, &dataCb, getter_AddRefs(mCbTexture));
-  mDevice->CreateTexture2D(&descCbCr, &dataCr, getter_AddRefs(mCrTexture));
+  HRESULT hr = mDevice->CreateTexture2D(&descY, &dataY, getter_AddRefs(mYTexture));
+  if (!FAILED(hr)) {
+      hr = mDevice->CreateTexture2D(&descCbCr, &dataCb, getter_AddRefs(mCbTexture));
+  }
+  if (!FAILED(hr)) {
+      hr = mDevice->CreateTexture2D(&descCbCr, &dataCr, getter_AddRefs(mCrTexture));
+  }
+  if (FAILED(hr)) {
+    LayerManagerD3D10::ReportFailure(NS_LITERAL_CSTRING("PlanarYCbCrImageD3D10::AllocateTextures(): Failed to create texture"),
+                                     hr);
+    return;
+  }
   mDevice->CreateShaderResourceView(mYTexture, NULL, getter_AddRefs(mYView));
   mDevice->CreateShaderResourceView(mCbTexture, NULL, getter_AddRefs(mCbView));
   mDevice->CreateShaderResourceView(mCrTexture, NULL, getter_AddRefs(mCrView));
 }
 
 already_AddRefed<gfxASurface>
 PlanarYCbCrImageD3D10::GetAsSurface()
 {
@@ -482,17 +491,22 @@ CairoImageD3D10::GetAsSurface()
   // drawing with Direct2D because it is immutable and cannot be bound as a
   // render target.
   D3D10_TEXTURE2D_DESC texDesc;
   mTexture->GetDesc(&texDesc);
   texDesc.Usage = D3D10_USAGE_DEFAULT;
   texDesc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
   texDesc.MiscFlags = D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
 
-  mDevice->CreateTexture2D(&texDesc, NULL, getter_AddRefs(surfTexture));
+  HRESULT hr = mDevice->CreateTexture2D(&texDesc, NULL, getter_AddRefs(surfTexture));
+  if (FAILED(hr)) {
+    LayerManagerD3D10::ReportFailure(NS_LITERAL_CSTRING("CairoImageD3D10::GetAsSurface(): Failed to create texture"),
+                                     hr);
+    return nsnull;
+  }
 
   mDevice->CopyResource(surfTexture, mTexture);
 
   nsRefPtr<gfxASurface> surf =
     new gfxD2DSurface(surfTexture, mHasAlpha ? gfxASurface::CONTENT_COLOR_ALPHA :
                                                gfxASurface::CONTENT_COLOR);
   return surf.forget();
 }
--- a/gfx/layers/d3d10/LayerManagerD3D10.cpp
+++ b/gfx/layers/d3d10/LayerManagerD3D10.cpp
@@ -600,17 +600,16 @@ LayerManagerD3D10::UpdateRenderTarget()
 }
 
 void
 LayerManagerD3D10::VerifyBufferSize()
 {
   nsIntRect rect;
   mWidget->GetClientBounds(rect);
 
-  HRESULT hr;
   if (mSwapChain) {
     DXGI_SWAP_CHAIN_DESC swapDesc;
     mSwapChain->GetDesc(&swapDesc);
 
     if (swapDesc.BufferDesc.Width == rect.width &&
         swapDesc.BufferDesc.Height == rect.height) {
       return;
     }
@@ -638,21 +637,21 @@ LayerManagerD3D10::VerifyBufferSize()
     }
 
     CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM,
                                rect.width, rect.height, 1, 1);
     desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
     desc.MiscFlags = D3D10_RESOURCE_MISC_SHARED
                      // FIXME/bug 662109: synchronize using KeyedMutex
                      /*D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX*/;
-    hr = device()->CreateTexture2D(&desc, nsnull, getter_AddRefs(mBackBuffer));
+    HRESULT hr = device()->CreateTexture2D(&desc, nsnull, getter_AddRefs(mBackBuffer));
     if (FAILED(hr)) {
-        ReportFailure(nsDependentCString("Failed to create shared texture"),
-                      hr);
-        NS_RUNTIMEABORT("Failed to create back buffer");
+      ReportFailure(NS_LITERAL_CSTRING("LayerManagerD3D10::VerifyBufferSize(): Failed to create shared texture"),
+                    hr);
+      NS_RUNTIMEABORT("Failed to create back buffer");
     }
 
     // XXX resize texture?
     mRTView = nsnull;
   }
 }
 
 void
@@ -794,17 +793,22 @@ LayerManagerD3D10::PaintToTarget()
   CD3D10_TEXTURE2D_DESC softDesc(bbDesc.Format, bbDesc.Width, bbDesc.Height);
   softDesc.MipLevels = 1;
   softDesc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
   softDesc.Usage = D3D10_USAGE_STAGING;
   softDesc.BindFlags = 0;
 
   nsRefPtr<ID3D10Texture2D> readTexture;
 
-  device()->CreateTexture2D(&softDesc, NULL, getter_AddRefs(readTexture));
+  HRESULT hr = device()->CreateTexture2D(&softDesc, NULL, getter_AddRefs(readTexture));
+  if (FAILED(hr)) {
+    ReportFailure(NS_LITERAL_CSTRING("LayerManagerD3D10::PaintToTarget(): Failed to create texture"),
+                  hr);
+    return;
+  }
 
   device()->CopyResource(readTexture, backBuf);
 
   D3D10_MAPPED_TEXTURE2D map;
   readTexture->Map(0, D3D10_MAP_READ, 0, &map);
 
   nsRefPtr<gfxImageSurface> tmpSurface =
     new gfxImageSurface((unsigned char*)map.pData,
--- a/gfx/layers/d3d10/ThebesLayerD3D10.cpp
+++ b/gfx/layers/d3d10/ThebesLayerD3D10.cpp
@@ -282,17 +282,23 @@ ThebesLayerD3D10::Validate(ReadbackProce
 
     if (readbackUpdates.Length() > 0) {
       CD3D10_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM,
                                  newTextureRect.width, newTextureRect.height,
                                  1, 1, 0, D3D10_USAGE_STAGING,
                                  D3D10_CPU_ACCESS_READ);
 
       nsRefPtr<ID3D10Texture2D> readbackTexture;
-      device()->CreateTexture2D(&desc, NULL, getter_AddRefs(readbackTexture));
+      HRESULT hr = device()->CreateTexture2D(&desc, NULL, getter_AddRefs(readbackTexture));
+      if (FAILED(hr)) {
+        LayerManagerD3D10::ReportFailure(NS_LITERAL_CSTRING("ThebesLayerD3D10::Validate(): Failed to create texture"),
+                                         hr);
+        return;
+      }
+
       device()->CopyResource(readbackTexture, mTexture);
 
       for (PRUint32 i = 0; i < readbackUpdates.Length(); i++) {
         mD3DManager->readbackManager()->PostTask(readbackTexture,
                                                  &readbackUpdates[i],
                                                  gfxPoint(newTextureRect.x, newTextureRect.y));
       }
     }
--- a/gfx/layers/d3d9/CanvasLayerD3D9.cpp
+++ b/gfx/layers/d3d9/CanvasLayerD3D9.cpp
@@ -273,26 +273,32 @@ CanvasLayerD3D9::LayerManagerDestroyed()
 {
   mD3DManager->deviceManager()->mLayersWithResources.RemoveElement(this);
   mD3DManager = nsnull;
 }
 
 void
 CanvasLayerD3D9::CreateTexture()
 {
+  HRESULT hr;
   if (mD3DManager->deviceManager()->HasDynamicTextures()) {
-    device()->CreateTexture(mBounds.width, mBounds.height, 1, D3DUSAGE_DYNAMIC,
-                            D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
-                            getter_AddRefs(mTexture), NULL);    
+    hr = device()->CreateTexture(mBounds.width, mBounds.height, 1, D3DUSAGE_DYNAMIC,
+                                 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
+                                 getter_AddRefs(mTexture), NULL);
   } else {
     // D3DPOOL_MANAGED is fine here since we require Dynamic Textures for D3D9Ex
     // devices.
-    device()->CreateTexture(mBounds.width, mBounds.height, 1, 0,
-                            D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,
-                            getter_AddRefs(mTexture), NULL);
+    hr = device()->CreateTexture(mBounds.width, mBounds.height, 1, 0,
+                                 D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,
+                                 getter_AddRefs(mTexture), NULL);
+  }
+  if (FAILED(hr)) {
+    mD3DManager->ReportFailure(NS_LITERAL_CSTRING("CanvasLayerD3D9::CreateTexture() failed"),
+                                 hr);
+    return;
   }
 }
 
 ShadowCanvasLayerD3D9::ShadowCanvasLayerD3D9(LayerManagerD3D9* aManager)
   : ShadowCanvasLayer(aManager, nsnull)
   , LayerD3D9(aManager)
   , mNeedsYFlip(false)
 {
--- a/gfx/layers/d3d9/ContainerLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ContainerLayerD3D9.cpp
@@ -175,20 +175,26 @@ ContainerRender(Container* aContainer,
   readback.BuildUpdates(aContainer);
 
   nsIntRect visibleRect = aContainer->GetEffectiveVisibleRegion().GetBounds();
   bool useIntermediate = aContainer->UseIntermediateSurface();
 
   aContainer->mSupportsComponentAlphaChildren = false;
   if (useIntermediate) {
     aManager->device()->GetRenderTarget(0, getter_AddRefs(previousRenderTarget));
-    aManager->device()->CreateTexture(visibleRect.width, visibleRect.height, 1,
-                            D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
-                            D3DPOOL_DEFAULT, getter_AddRefs(renderTexture),
-                            NULL);
+    HRESULT hr = aManager->device()->CreateTexture(visibleRect.width, visibleRect.height, 1,
+                                                   D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
+                                                   D3DPOOL_DEFAULT, getter_AddRefs(renderTexture),
+                                                   NULL);
+    if (FAILED(hr)) {
+      aManager->ReportFailure(NS_LITERAL_CSTRING("ContainerLayerD3D9::ContainerRender(): Failed to create texture"),
+                              hr);
+      return;
+    }
+
     nsRefPtr<IDirect3DSurface9> renderSurface;
     renderTexture->GetSurfaceLevel(0, getter_AddRefs(renderSurface));
     aManager->device()->SetRenderTarget(0, renderSurface);
 
     if (aContainer->mVisibleRegion.GetNumRects() == 1 && 
         (aContainer->GetContentFlags() & aContainer->CONTENT_OPAQUE)) {
       // don't need a background, we're going to paint all opaque stuff
       aContainer->mSupportsComponentAlphaChildren = true;
--- a/gfx/layers/d3d9/ImageLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ImageLayerD3D9.cpp
@@ -431,50 +431,80 @@ PlanarYCbCrImageD3D9::AllocateTextures(I
 
   if (isD3D9Ex) {
     nsRefPtr<IDirect3DTexture9> tmpYTexture;
     nsRefPtr<IDirect3DTexture9> tmpCbTexture;
     nsRefPtr<IDirect3DTexture9> tmpCrTexture;
     // D3D9Ex does not support the managed pool, could use dynamic textures
     // here. But since an Image is immutable static textures are probably a
     // better idea.
-    aDevice->CreateTexture(mData.mYSize.width, mData.mYSize.height,
-                            1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
-                            getter_AddRefs(mYTexture), NULL);
-    aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
-                            1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
-                            getter_AddRefs(mCbTexture), NULL);
-    aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
-                            1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
-                            getter_AddRefs(mCrTexture), NULL);
-    aDevice->CreateTexture(mData.mYSize.width, mData.mYSize.height,
-                            1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
-                            getter_AddRefs(tmpYTexture), NULL);
-    aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
-                            1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
-                            getter_AddRefs(tmpCbTexture), NULL);
-    aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
-                            1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
-                            getter_AddRefs(tmpCrTexture), NULL);
+
+    HRESULT hr;
+    hr = aDevice->CreateTexture(mData.mYSize.width, mData.mYSize.height,
+                                1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
+                                getter_AddRefs(mYTexture), NULL);
+    if (!FAILED(hr)) {
+      hr = aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
+                                  1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
+                                  getter_AddRefs(mCbTexture), NULL);
+    }
+    if (!FAILED(hr)) {
+      hr = aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
+                                  1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
+                                  getter_AddRefs(mCrTexture), NULL);
+    }
+    if (!FAILED(hr)) {
+      hr = aDevice->CreateTexture(mData.mYSize.width, mData.mYSize.height,
+                                  1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
+                                  getter_AddRefs(tmpYTexture), NULL);
+    }
+    if (!FAILED(hr)) {
+      hr = aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
+                                  1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
+                                  getter_AddRefs(tmpCbTexture), NULL);
+    }
+    if (!FAILED(hr)) {
+      hr = aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
+                                  1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
+                                  getter_AddRefs(tmpCrTexture), NULL);
+    }
+
+    if (FAILED(hr)) {
+      mManager->ReportFailure(NS_LITERAL_CSTRING("PlanarYCbCrImageD3D9::AllocateTextures(): Failed to create texture (isD3D9Ex)"),
+                              hr);
+      return;
+    }
+
     tmpYTexture->GetSurfaceLevel(0, getter_AddRefs(tmpSurfaceY));
     tmpCbTexture->GetSurfaceLevel(0, getter_AddRefs(tmpSurfaceCb));
     tmpCrTexture->GetSurfaceLevel(0, getter_AddRefs(tmpSurfaceCr));
     tmpSurfaceY->LockRect(&lockrectY, NULL, 0);
     tmpSurfaceCb->LockRect(&lockrectCb, NULL, 0);
     tmpSurfaceCr->LockRect(&lockrectCr, NULL, 0);
   } else {
-    aDevice->CreateTexture(mData.mYSize.width, mData.mYSize.height,
-                            1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
-                            getter_AddRefs(mYTexture), NULL);
-    aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
-                            1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
-                            getter_AddRefs(mCbTexture), NULL);
-    aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
-                            1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
-                            getter_AddRefs(mCrTexture), NULL);
+    HRESULT hr;
+    hr = aDevice->CreateTexture(mData.mYSize.width, mData.mYSize.height,
+                                1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
+                                getter_AddRefs(mYTexture), NULL);
+    if (!FAILED(hr)) {
+      aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
+                             1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
+                             getter_AddRefs(mCbTexture), NULL);
+    }
+    if (!FAILED(hr)) {
+      aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
+                             1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
+                             getter_AddRefs(mCrTexture), NULL);
+    }
+
+    if (FAILED(hr)) {
+      mManager->ReportFailure(NS_LITERAL_CSTRING("PlanarYCbCrImageD3D9::AllocateTextures(): Failed to create texture (!isD3D9Ex)"),
+                              hr);
+      return;
+    }
 
     /* lock the entire texture */
     mYTexture->LockRect(0, &lockrectY, NULL, 0);
     mCbTexture->LockRect(0, &lockrectCb, NULL, 0);
     mCrTexture->LockRect(0, &lockrectCr, NULL, 0);
   }
 
   src  = mData.mYChannel;
--- a/gfx/layers/d3d9/ShadowBufferD3D9.cpp
+++ b/gfx/layers/d3d9/ShadowBufferD3D9.cpp
@@ -48,20 +48,25 @@ namespace layers {
 void 
 ShadowBufferD3D9::Upload(gfxASurface* aUpdate, 
                          const nsIntRect& aVisibleRect)
 {
 
   gfxIntSize size = aUpdate->GetSize();
 
   if (GetSize() != nsIntSize(size.width, size.height)) {
-    mLayer->device()->CreateTexture(size.width, size.height, 1,
-                          D3DUSAGE_DYNAMIC,
-                          D3DFMT_A8R8G8B8,
-                          D3DPOOL_DEFAULT, getter_AddRefs(mTexture), NULL);
+    HRESULT hr = mLayer->device()->CreateTexture(size.width, size.height, 1,
+                                                 D3DUSAGE_DYNAMIC,
+                                                 D3DFMT_A8R8G8B8,
+                                                 D3DPOOL_DEFAULT, getter_AddRefs(mTexture), NULL);
+    if (FAILED(hr)) {
+      mLayer->ReportFailure(NS_LITERAL_CSTRING("ShadowBufferD3D9::Upload(): Failed to create texture"),
+                            hr);
+      return;
+    }
 
     mTextureRect = aVisibleRect;
   }
 
   LockTextureRectD3D9 textureLock(mTexture);
   if (!textureLock.HasLock()) {
     NS_WARNING("Failed to lock ShadowBufferD3D9 texture.");
     return;
--- a/gfx/layers/d3d9/ThebesLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ThebesLayerD3D9.cpp
@@ -595,25 +595,36 @@ ThebesLayerD3D9::CreateNewTextures(const
 {
   if (aSize.width == 0 || aSize.height == 0) {
     // Nothing to do.
     return;
   }
 
   mTexture = nsnull;
   mTextureOnWhite = nsnull;
-  device()->CreateTexture(aSize.width, aSize.height, 1,
-                          D3DUSAGE_RENDERTARGET,
-                          aMode != SURFACE_SINGLE_CHANNEL_ALPHA ? D3DFMT_X8R8G8B8 : D3DFMT_A8R8G8B8,
-                          D3DPOOL_DEFAULT, getter_AddRefs(mTexture), NULL);
+  HRESULT hr = device()->CreateTexture(aSize.width, aSize.height, 1,
+                                       D3DUSAGE_RENDERTARGET,
+                                       aMode != SURFACE_SINGLE_CHANNEL_ALPHA ? D3DFMT_X8R8G8B8 : D3DFMT_A8R8G8B8,
+                                       D3DPOOL_DEFAULT, getter_AddRefs(mTexture), NULL);
+  if (FAILED(hr)) {
+    ReportFailure(NS_LITERAL_CSTRING("ThebesLayerD3D9::CreateNewTextures(): Failed to create texture"),
+                  hr);
+    return;
+  }
+
   if (aMode == SURFACE_COMPONENT_ALPHA) {
-    device()->CreateTexture(aSize.width, aSize.height, 1,
-                            D3DUSAGE_RENDERTARGET,
-                            D3DFMT_X8R8G8B8,
-                            D3DPOOL_DEFAULT, getter_AddRefs(mTextureOnWhite), NULL);
+    hr = device()->CreateTexture(aSize.width, aSize.height, 1,
+                                 D3DUSAGE_RENDERTARGET,
+                                 D3DFMT_X8R8G8B8,
+                                 D3DPOOL_DEFAULT, getter_AddRefs(mTextureOnWhite), NULL);
+    if (FAILED(hr)) {
+      ReportFailure(NS_LITERAL_CSTRING("ThebesLayerD3D9::CreateNewTextures(): Failed to create texture (2)"),
+                    hr);
+      return;
+    }
   }
 }
 
 ShadowThebesLayerD3D9::ShadowThebesLayerD3D9(LayerManagerD3D9 *aManager)
   : ShadowThebesLayer(aManager, nsnull)
   , LayerD3D9(aManager)
 {
   mImplData = static_cast<LayerD3D9*>(this);