Bug 615316 - Part 9: Support changing devices for YCbCrImageD3D9. r=jrmuizel a=blocking-betaN
authorBas Schouten <bschouten@mozilla.com>
Mon, 20 Dec 2010 22:37:18 +0000
changeset 59535 6cfc50d8629c0c04ac88bf5e7b5c5dc49e82c9c3
parent 59534 7d05c8f6c4da72ed60a83f08346892d7a3a56ab2
child 59536 2d4b1d635e8dea64617d72a8b94fd5fee31ba5c1
push id17651
push userbschouten@mozilla.com
push dateMon, 20 Dec 2010 22:38:06 +0000
treeherdermozilla-central@2d4b1d635e8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel, blocking-betaN
bugs615316
milestone2.0b9pre
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 615316 - Part 9: Support changing devices for YCbCrImageD3D9. r=jrmuizel a=blocking-betaN
gfx/layers/d3d9/ImageLayerD3D9.cpp
gfx/layers/d3d9/ImageLayerD3D9.h
--- a/gfx/layers/d3d9/ImageLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ImageLayerD3D9.cpp
@@ -138,17 +138,17 @@ already_AddRefed<Image>
 ImageContainerD3D9::CreateImage(const Image::Format *aFormats,
                                PRUint32 aNumFormats)
 {
   if (!aNumFormats) {
     return nsnull;
   }
   nsRefPtr<Image> img;
   if (aFormats[0] == Image::PLANAR_YCBCR) {
-    img = new PlanarYCbCrImageD3D9(static_cast<LayerManagerD3D9*>(mManager));
+    img = new PlanarYCbCrImageD3D9();
   } else if (aFormats[0] == Image::CAIRO_SURFACE) {
     img = new CairoImageD3D9(static_cast<LayerManagerD3D9*>(mManager)->device());
   }
   return img.forget();
 }
 
 void
 ImageContainerD3D9::SetCurrentImage(Image *aImage)
@@ -238,17 +238,17 @@ ImageLayerD3D9::RenderLayer()
 
   if (image->GetFormat() == Image::PLANAR_YCBCR) {
     PlanarYCbCrImageD3D9 *yuvImage =
       static_cast<PlanarYCbCrImageD3D9*>(image.get());
 
     if (!yuvImage->HasData()) {
       return;
     }
-    yuvImage->AllocateTextures();
+    yuvImage->AllocateTextures(device());
 
     device()->SetVertexShaderConstantF(CBvLayerQuad,
                                        ShaderConstantRect(0,
                                                           0,
                                                           yuvImage->mSize.width,
                                                           yuvImage->mSize.height),
                                        1);
 
@@ -321,19 +321,18 @@ ImageLayerD3D9::RenderLayer()
       mD3DManager->SetShaderMode(DeviceManagerD3D9::RGBLAYER);
     }
 
     device()->SetTexture(0, cairoImage->GetOrCreateTexture());
     device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
   }
 }
 
-PlanarYCbCrImageD3D9::PlanarYCbCrImageD3D9(mozilla::layers::LayerManagerD3D9* aManager)
+PlanarYCbCrImageD3D9::PlanarYCbCrImageD3D9()
   : PlanarYCbCrImage(static_cast<ImageD3D9*>(this))
-  , mManager(aManager)
   , mHasData(PR_FALSE)
 {
 }
 
 void
 PlanarYCbCrImageD3D9::SetData(const PlanarYCbCrImage::Data &aData)
 {
   // XXX - For D3D9Ex we really should just copy to systemmem surfaces here.
@@ -405,69 +404,73 @@ PlanarYCbCrImageD3D9::SetData(const Plan
   // Fix picture rect to be correct
   mData.mPicX = mData.mPicY = 0;
   mSize = aData.mPicSize;
 
   mHasData = PR_TRUE;
 }
 
 void
-PlanarYCbCrImageD3D9::AllocateTextures()
+PlanarYCbCrImageD3D9::AllocateTextures(IDirect3DDevice9 *aDevice)
 {
-
-
   D3DLOCKED_RECT lockrectY;
   D3DLOCKED_RECT lockrectCb;
   D3DLOCKED_RECT lockrectCr;
   PRUint8* src;
   PRUint8* dest;
 
   nsRefPtr<IDirect3DSurface9> tmpSurfaceY;
   nsRefPtr<IDirect3DSurface9> tmpSurfaceCb;
   nsRefPtr<IDirect3DSurface9> tmpSurfaceCr;
 
-  if (mManager->deviceManager()->IsD3D9Ex()) {
+  nsRefPtr<IDirect3DDevice9Ex> deviceEx;
+  aDevice->QueryInterface(__uuidof(IDirect3DDevice9Ex),
+                          getter_AddRefs(deviceEx));
+
+  bool isD3D9Ex = deviceEx;
+
+  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.
-    mManager->device()->CreateTexture(mData.mYSize.width, mData.mYSize.height,
+    aDevice->CreateTexture(mData.mYSize.width, mData.mYSize.height,
                             1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
                             getter_AddRefs(mYTexture), NULL);
-    mManager->device()->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
+    aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
                             1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
                             getter_AddRefs(mCbTexture), NULL);
-    mManager->device()->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
+    aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
                             1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
                             getter_AddRefs(mCrTexture), NULL);
-    mManager->device()->CreateTexture(mData.mYSize.width, mData.mYSize.height,
+    aDevice->CreateTexture(mData.mYSize.width, mData.mYSize.height,
                             1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
                             getter_AddRefs(tmpYTexture), NULL);
-    mManager->device()->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
+    aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
                             1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
                             getter_AddRefs(tmpCbTexture), NULL);
-    mManager->device()->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
+    aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
                             1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
                             getter_AddRefs(tmpCrTexture), NULL);
     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 {
-    mManager->device()->CreateTexture(mData.mYSize.width, mData.mYSize.height,
+    aDevice->CreateTexture(mData.mYSize.width, mData.mYSize.height,
                             1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
                             getter_AddRefs(mYTexture), NULL);
-    mManager->device()->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
+    aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
                             1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
                             getter_AddRefs(mCbTexture), NULL);
-    mManager->device()->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
+    aDevice->CreateTexture(mData.mCbCrSize.width, mData.mCbCrSize.height,
                             1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
                             getter_AddRefs(mCrTexture), NULL);
 
     /* lock the entire texture */
     mYTexture->LockRect(0, &lockrectY, NULL, 0);
     mCbTexture->LockRect(0, &lockrectCb, NULL, 0);
     mCrTexture->LockRect(0, &lockrectCr, NULL, 0);
   }
@@ -500,27 +503,27 @@ PlanarYCbCrImageD3D9::AllocateTextures()
 
   // copy over data
   for (int h=0; h<mData.mCbCrSize.height; h++) {
     memcpy(dest, src, mData.mCbCrSize.width);
     dest += lockrectCr.Pitch;
     src += mData.mCbCrStride;
   }
 
-  if (mManager->deviceManager()->IsD3D9Ex()) {
+  if (isD3D9Ex) {
     tmpSurfaceY->UnlockRect();
     tmpSurfaceCb->UnlockRect();
     tmpSurfaceCr->UnlockRect();
     nsRefPtr<IDirect3DSurface9> dstSurface;
     mYTexture->GetSurfaceLevel(0, getter_AddRefs(dstSurface));
-    mManager->device()->UpdateSurface(tmpSurfaceY, NULL, dstSurface, NULL);
+    aDevice->UpdateSurface(tmpSurfaceY, NULL, dstSurface, NULL);
     mCbTexture->GetSurfaceLevel(0, getter_AddRefs(dstSurface));
-    mManager->device()->UpdateSurface(tmpSurfaceCb, NULL, dstSurface, NULL);
+    aDevice->UpdateSurface(tmpSurfaceCb, NULL, dstSurface, NULL);
     mCrTexture->GetSurfaceLevel(0, getter_AddRefs(dstSurface));
-    mManager->device()->UpdateSurface(tmpSurfaceCr, NULL, dstSurface, NULL);
+    aDevice->UpdateSurface(tmpSurfaceCr, NULL, dstSurface, NULL);
   } else {
     mYTexture->UnlockRect(0);
     mCbTexture->UnlockRect(0);
     mCrTexture->UnlockRect(0);
   }
 }
 
 void
--- a/gfx/layers/d3d9/ImageLayerD3D9.h
+++ b/gfx/layers/d3d9/ImageLayerD3D9.h
@@ -95,26 +95,26 @@ class THEBES_API ImageD3D9
 public:
   virtual already_AddRefed<gfxASurface> GetAsSurface() = 0;
 };
 
 class THEBES_API PlanarYCbCrImageD3D9 : public PlanarYCbCrImage,
                                         public ImageD3D9
 {
 public:
-  PlanarYCbCrImageD3D9(LayerManagerD3D9 *aManager);
+  PlanarYCbCrImageD3D9();
   ~PlanarYCbCrImageD3D9() {}
 
   virtual void SetData(const Data &aData);
 
   /*
    * Upload the data from out mData into our textures. For now we use this to
    * make sure the textures are created and filled on the main thread.
    */
-  void AllocateTextures();
+  void AllocateTextures(IDirect3DDevice9 *aDevice);
   /*
    * XXX
    * Free the textures, we call this from the main thread when we're done
    * drawing this frame. We cannot free this from the constructor since it may
    * be destroyed off the main-thread and might not be able to properly clean
    * up its textures
    */
   void FreeTextures();