Bug 1170143 - Add some error checks around the creation of dxgi ycbcr video frames. r=Bas
authorNicolas Silva <nsilva@mozilla.com>
Fri, 05 Jun 2015 16:19:11 +0200
changeset 247408 17467c9adf1b
parent 247407 0dca3f73814c
child 247409 915d4854e649
push id28864
push userkwierso@gmail.com
push date2015-06-05 21:49 +0000
treeherdermozilla-central@97a39c939c51 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs1170143
milestone41.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 1170143 - Add some error checks around the creation of dxgi ycbcr video frames. r=Bas
gfx/layers/IMFYCbCrImage.cpp
gfx/layers/d3d11/TextureD3D11.cpp
--- a/gfx/layers/IMFYCbCrImage.cpp
+++ b/gfx/layers/IMFYCbCrImage.cpp
@@ -93,29 +93,41 @@ InitTextures(IDirect3DDevice9* aDevice,
   if (!aLockedRect.pBits) {
     NS_WARNING("Could not lock surface");
     return nullptr;
   }
 
   return result.forget();
 }
 
-static void
+static bool
 FinishTextures(IDirect3DDevice9* aDevice,
                IDirect3DTexture9* aTexture,
                IDirect3DSurface9* aSurface)
 {
   if (!aDevice) {
     return;
   }
 
-  aSurface->UnlockRect();
+  HRESULT hr = aSurface->UnlockRect();
+  if (FAILED(hr)) {
+    return false;
+  }
+
   nsRefPtr<IDirect3DSurface9> dstSurface;
-  aTexture->GetSurfaceLevel(0, getter_AddRefs(dstSurface));
-  aDevice->UpdateSurface(aSurface, nullptr, dstSurface, nullptr);
+  hr = aTexture->GetSurfaceLevel(0, getter_AddRefs(dstSurface));
+  if (FAILED(hr)) {
+    return false;
+  }
+
+  hr = aDevice->UpdateSurface(aSurface, nullptr, dstSurface, nullptr);
+  if (FAILED(hr)) {
+    return false;
+  }
+  return true;
 }
 
 static bool UploadData(IDirect3DDevice9* aDevice,
                        RefPtr<IDirect3DTexture9>& aTexture,
                        HANDLE& aHandle,
                        uint8_t* aSrc,
                        const gfx::IntSize& aSrcSize,
                        int32_t aSrcStride)
@@ -132,18 +144,17 @@ static bool UploadData(IDirect3DDevice9*
   } else {
     for (int i = 0; i < aSrcSize.height; i++) {
       memcpy((uint8_t*)rect.pBits + i * rect.Pitch,
              aSrc + i * aSrcStride,
              aSrcSize.width);
     }
   }
 
-  FinishTextures(aDevice, aTexture, surf);
-  return true;
+  return FinishTextures(aDevice, aTexture, surf);
 }
 
 TextureClient*
 IMFYCbCrImage::GetD3D9TextureClient(CompositableClient* aClient)
 {
   IDirect3DDevice9* device = gfxWindowsPlatform::GetPlatform()->GetD3D9Device();
 
   RefPtr<IDirect3DTexture9> textureY;
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -559,16 +559,21 @@ DXGIYCbCrTextureClient::Create(ISurfaceA
                                IUnknown* aTextureCr,
                                HANDLE aHandleY,
                                HANDLE aHandleCb,
                                HANDLE aHandleCr,
                                const gfx::IntSize& aSize,
                                const gfx::IntSize& aSizeY,
                                const gfx::IntSize& aSizeCbCr)
 {
+  if (!aHandleY || !aHandleCb || !aHandleCr ||
+      !aTextureY, || !aTextureCb || !aTextureCr) {
+    return nullptr;
+  }
+
   RefPtr<DXGIYCbCrTextureClient> texture =
     new DXGIYCbCrTextureClient(aAllocator, aFlags);
   texture->mHandles[0] = aHandleY;
   texture->mHandles[1] = aHandleCb;
   texture->mHandles[2] = aHandleCr;
   texture->mHoldRefs[0] = aTextureY;
   texture->mHoldRefs[1] = aTextureCb;
   texture->mHoldRefs[2] = aTextureCr;