From 96f961a570a9a7fa2738b256b09fc969890b45b7 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 12 Jul 2012 05:51:57 -0700 Subject: [PATCH] Bug 765734, part 2: Migrate ImageLayers to SurfaceDescriptor. r=mattwoodrow,roc --HG-- extra : rebase_source : 19fc8b0ae4cfffdf9a098911deac3b48c2f5d768 --- gfx/layers/basic/BasicImageLayer.cpp | 66 ++++++++++++++++---------- gfx/layers/basic/BasicLayerManager.cpp | 10 ++-- gfx/layers/basic/BasicLayers.h | 8 ++-- gfx/layers/d3d9/ImageLayerD3D9.cpp | 15 +++--- gfx/layers/ipc/PLayers.ipdl | 6 +-- gfx/layers/opengl/ImageLayerOGL.cpp | 28 ++++++----- 6 files changed, 77 insertions(+), 56 deletions(-) diff --git a/gfx/layers/basic/BasicImageLayer.cpp b/gfx/layers/basic/BasicImageLayer.cpp index df4e3a5bdb04..6ecc75ebc9c9 100644 --- a/gfx/layers/basic/BasicImageLayer.cpp +++ b/gfx/layers/basic/BasicImageLayer.cpp @@ -196,9 +196,9 @@ public: mBackBuffer = aBuffer; } - virtual void SetBackBufferYUVImage(gfxSharedImageSurface* aYBuffer, - gfxSharedImageSurface* aUBuffer, - gfxSharedImageSurface* aVBuffer) + virtual void SetBackBufferYUVImage(const SurfaceDescriptor& aYBuffer, + const SurfaceDescriptor& aUBuffer, + const SurfaceDescriptor& aVBuffer) { mBackBufferY = aYBuffer; mBackBufferU = aUBuffer; @@ -207,7 +207,9 @@ public: virtual void Disconnect() { - mBackBufferY = mBackBufferU = mBackBufferV = nsnull; + mBackBufferY = SurfaceDescriptor(); + mBackBufferU = SurfaceDescriptor(); + mBackBufferV = SurfaceDescriptor(); mBackBuffer = SurfaceDescriptor(); BasicShadowableLayer::Disconnect(); } @@ -217,11 +219,11 @@ public: if (IsSurfaceDescriptorValid(mBackBuffer)) { BasicManager()->ShadowLayerForwarder::DestroySharedSurface(&mBackBuffer); } - if (mBackBufferY) { - BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackBufferY); - BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackBufferU); - BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackBufferV); - } + if (IsSurfaceDescriptorValid(mBackBufferY)) { + BasicManager()->ShadowLayerForwarder::DestroySharedSurface(&mBackBufferY); + BasicManager()->ShadowLayerForwarder::DestroySharedSurface(&mBackBufferU); + BasicManager()->ShadowLayerForwarder::DestroySharedSurface(&mBackBufferV); +} } private: @@ -234,9 +236,9 @@ private: // for RGB images only mBackSurface is used. SurfaceDescriptor mBackBuffer; bool mBufferIsOpaque; - nsRefPtr mBackBufferY; - nsRefPtr mBackBufferU; - nsRefPtr mBackBufferV; + SurfaceDescriptor mBackBufferY; + SurfaceDescriptor mBackBufferU; + SurfaceDescriptor mBackBufferV; gfxIntSize mCbCrSize; }; @@ -271,38 +273,52 @@ BasicShadowableImageLayer::Paint(gfxContext* aContext, Layer* aMaskLayer) const PlanarYCbCrImage::Data *data = YCbCrImage->GetData(); NS_ASSERTION(data, "Must be able to retrieve yuv data from image!"); - if (mSize != data->mYSize || mCbCrSize != data->mCbCrSize || !mBackBufferY) { + if (mSize != data->mYSize || mCbCrSize != data->mCbCrSize || !IsSurfaceDescriptorValid(mBackBufferY)) { DestroyBackBuffer(); mSize = data->mYSize; mCbCrSize = data->mCbCrSize; - if (!BasicManager()->AllocBuffer(mSize, gfxASurface::CONTENT_ALPHA, - getter_AddRefs(mBackBufferY)) || - !BasicManager()->AllocBuffer(mCbCrSize, gfxASurface::CONTENT_ALPHA, - getter_AddRefs(mBackBufferU)) || - !BasicManager()->AllocBuffer(mCbCrSize, gfxASurface::CONTENT_ALPHA, - getter_AddRefs(mBackBufferV))) { + // We either allocate all three planes or none. + if (!BasicManager()->AllocBufferWithCaps(mSize, + gfxASurface::CONTENT_ALPHA, + MAP_AS_IMAGE_SURFACE, + &mBackBufferY) || + !BasicManager()->AllocBufferWithCaps(mCbCrSize, + gfxASurface::CONTENT_ALPHA, + MAP_AS_IMAGE_SURFACE, + &mBackBufferU) || + !BasicManager()->AllocBufferWithCaps(mCbCrSize, + gfxASurface::CONTENT_ALPHA, + MAP_AS_IMAGE_SURFACE, + &mBackBufferV)) { NS_RUNTIMEABORT("creating ImageLayer 'front buffer' failed!"); } } + nsRefPtr dyas = BasicManager()->OpenDescriptor(mBackBufferY); + nsRefPtr dy = dyas->GetAsImageSurface(); + for (int i = 0; i < data->mYSize.height; i++) { - memcpy(mBackBufferY->Data() + i * mBackBufferY->Stride(), + memcpy(dy->Data() + i * dy->Stride(), data->mYChannel + i * data->mYStride, data->mYSize.width); } + + nsRefPtr duas = BasicManager()->OpenDescriptor(mBackBufferU); + nsRefPtr du = duas->GetAsImageSurface(); + nsRefPtr dvas = BasicManager()->OpenDescriptor(mBackBufferV); + nsRefPtr dv = dvas->GetAsImageSurface(); + for (int i = 0; i < data->mCbCrSize.height; i++) { - memcpy(mBackBufferU->Data() + i * mBackBufferU->Stride(), + memcpy(du->Data() + i * du->Stride(), data->mCbChannel + i * data->mCbCrStride, data->mCbCrSize.width); - memcpy(mBackBufferV->Data() + i * mBackBufferV->Stride(), + memcpy(dv->Data() + i * dv->Stride(), data->mCrChannel + i * data->mCbCrStride, data->mCbCrSize.width); } - YUVImage yuv(mBackBufferY->GetShmem(), - mBackBufferU->GetShmem(), - mBackBufferV->GetShmem(), + YUVImage yuv(mBackBufferY, mBackBufferU, mBackBufferV, data->GetPictureRect()); BasicManager()->PaintedImage(BasicManager()->Hold(this), diff --git a/gfx/layers/basic/BasicLayerManager.cpp b/gfx/layers/basic/BasicLayerManager.cpp index 493506746d45..0cf61618b9d3 100644 --- a/gfx/layers/basic/BasicLayerManager.cpp +++ b/gfx/layers/basic/BasicLayerManager.cpp @@ -839,7 +839,6 @@ BasicLayerManager::PaintLayer(gfxContext* aTarget, gfxUtils::ClipToRegion(aTarget, aLayer->GetEffectiveVisibleRegion()); } AutoSetOperator setOperator(aTarget, container->GetOperator()); - gfxMatrix temp = aTarget->CurrentMatrix(); PaintWithMask(aTarget, aLayer->GetEffectiveOpacity(), HasShadowManager() ? nsnull : aLayer->GetMaskLayer()); } @@ -1048,13 +1047,12 @@ BasicShadowLayerManager::ForwardTransaction() layer->SetBackBuffer(newBack.get_SurfaceDescriptor()); } else if (newBack.type() == SharedImage::TYUVImage) { const YUVImage& yuv = newBack.get_YUVImage(); - nsRefPtr YSurf = gfxSharedImageSurface::Open(yuv.Ydata()); - nsRefPtr USurf = gfxSharedImageSurface::Open(yuv.Udata()); - nsRefPtr VSurf = gfxSharedImageSurface::Open(yuv.Vdata()); - layer->SetBackBufferYUVImage(YSurf, USurf, VSurf); + layer->SetBackBufferYUVImage(yuv.Ydata(), yuv.Udata(), yuv.Vdata()); } else { layer->SetBackBuffer(SurfaceDescriptor()); - layer->SetBackBufferYUVImage(nsnull, nsnull, nsnull); + layer->SetBackBufferYUVImage(SurfaceDescriptor(), + SurfaceDescriptor(), + SurfaceDescriptor()); } break; diff --git a/gfx/layers/basic/BasicLayers.h b/gfx/layers/basic/BasicLayers.h index 1649559d3f1f..da51e897b1e9 100644 --- a/gfx/layers/basic/BasicLayers.h +++ b/gfx/layers/basic/BasicLayers.h @@ -279,11 +279,11 @@ public: NS_RUNTIMEABORT("if this default impl is called, |aBuffer| leaks"); } - virtual void SetBackBufferYUVImage(gfxSharedImageSurface* aYBuffer, - gfxSharedImageSurface* aUBuffer, - gfxSharedImageSurface* aVBuffer) + virtual void SetBackBufferYUVImage(const SurfaceDescriptor& aYBuffer, + const SurfaceDescriptor& aUBuffer, + const SurfaceDescriptor& aVBuffer) { - NS_RUNTIMEABORT("if this default impl is called, |aBuffer| leaks"); + NS_RUNTIMEABORT("if this default impl is called, the buffers leak"); } virtual void Disconnect() diff --git a/gfx/layers/d3d9/ImageLayerD3D9.cpp b/gfx/layers/d3d9/ImageLayerD3D9.cpp index 6e087d13b727..e3f1216884c9 100644 --- a/gfx/layers/d3d9/ImageLayerD3D9.cpp +++ b/gfx/layers/d3d9/ImageLayerD3D9.cpp @@ -558,12 +558,15 @@ ShadowImageLayerD3D9::Swap(const SharedImage& aNewFront, } else { const YUVImage& yuv = aNewFront.get_YUVImage(); - nsRefPtr surfY = - gfxSharedImageSurface::Open(yuv.Ydata()); - nsRefPtr surfU = - gfxSharedImageSurface::Open(yuv.Udata()); - nsRefPtr surfV = - gfxSharedImageSurface::Open(yuv.Vdata()); + nsRefPtr asurfY = + ShadowLayerForwarder::OpenDescriptor(yuv.Ydata()); + nsRefPtr surfY = asurfY->GetAsImageSurface(); + nsRefPtr asurfU = + ShadowLayerForwarder::OpenDescriptor(yuv.Udata()); + nsRefPtr surfU = asurfU->GetAsImageSurface(); + nsRefPtr asurfV = + ShadowLayerForwarder::OpenDescriptor(yuv.Vdata()); + nsRefPtr surfV = asurfV->GetAsImageSurface(); PlanarYCbCrImage::Data data; data.mYChannel = surfY->Data(); diff --git a/gfx/layers/ipc/PLayers.ipdl b/gfx/layers/ipc/PLayers.ipdl index 365094f31bba..6467512eb19b 100644 --- a/gfx/layers/ipc/PLayers.ipdl +++ b/gfx/layers/ipc/PLayers.ipdl @@ -53,9 +53,9 @@ union SurfaceDescriptor { }; struct YUVImage { - Shmem Ydata; - Shmem Udata; - Shmem Vdata; + SurfaceDescriptor Ydata; + SurfaceDescriptor Udata; + SurfaceDescriptor Vdata; nsIntRect picture; }; diff --git a/gfx/layers/opengl/ImageLayerOGL.cpp b/gfx/layers/opengl/ImageLayerOGL.cpp index 176bc2e2acfe..e127f4073e5e 100644 --- a/gfx/layers/opengl/ImageLayerOGL.cpp +++ b/gfx/layers/opengl/ImageLayerOGL.cpp @@ -674,12 +674,12 @@ ShadowImageLayerOGL::Init(const SharedImage& aFront) } else { YUVImage yuv = aFront.get_YUVImage(); - nsRefPtr surfY = - gfxSharedImageSurface::Open(yuv.Ydata()); - nsRefPtr surfU = - gfxSharedImageSurface::Open(yuv.Udata()); - nsRefPtr surfV = - gfxSharedImageSurface::Open(yuv.Vdata()); + nsRefPtr asurfY = + ShadowLayerForwarder::OpenDescriptor(yuv.Ydata()); + nsRefPtr surfY = asurfY->GetAsImageSurface(); + nsRefPtr asurfU = + ShadowLayerForwarder::OpenDescriptor(yuv.Udata()); + nsRefPtr surfU = asurfU->GetAsImageSurface(); mSize = surfY->GetSize(); mCbCrSize = surfU->GetSize(); @@ -723,12 +723,16 @@ ShadowImageLayerOGL::Swap(const SharedImage& aNewFront, } else { const YUVImage& yuv = aNewFront.get_YUVImage(); - nsRefPtr surfY = - gfxSharedImageSurface::Open(yuv.Ydata()); - nsRefPtr surfU = - gfxSharedImageSurface::Open(yuv.Udata()); - nsRefPtr surfV = - gfxSharedImageSurface::Open(yuv.Vdata()); + nsRefPtr asurfY = + ShadowLayerForwarder::OpenDescriptor(yuv.Ydata()); + nsRefPtr surfY = asurfY->GetAsImageSurface(); + nsRefPtr asurfU = + ShadowLayerForwarder::OpenDescriptor(yuv.Udata()); + nsRefPtr surfU = asurfU->GetAsImageSurface(); + // XXX do we really need to open this? + nsRefPtr asurfV = + ShadowLayerForwarder::OpenDescriptor(yuv.Vdata()); + nsRefPtr surfV = asurfV->GetAsImageSurface(); mPictureRect = yuv.picture(); gfxIntSize size = surfY->GetSize();