Bug 570625, part 5: Mostly mechanically switch BasicShadowable/ShadowThebes over to the new SurfaceDescriptor API. r=roc

This commit is contained in:
Chris Jones 2010-09-14 00:23:08 -05:00
Родитель a51fcd62bb
Коммит ebd077db4c
4 изменённых файлов: 98 добавлений и 57 удалений

Просмотреть файл

@ -1242,7 +1242,13 @@ public:
mShadow = aShadow; mShadow = aShadow;
} }
virtual void SetBackBuffer(gfxSharedImageSurface* aBuffer) virtual void SetBackBufferImage(gfxSharedImageSurface* aBuffer)
{
NS_RUNTIMEABORT("if this default impl is called, |aBuffer| leaks");
}
virtual PRBool SupportsSurfaceDescriptor() const { return PR_FALSE; }
virtual void SetBackBuffer(const SurfaceDescriptor& aBuffer)
{ {
NS_RUNTIMEABORT("if this default impl is called, |aBuffer| leaks"); NS_RUNTIMEABORT("if this default impl is called, |aBuffer| leaks");
} }
@ -1329,6 +1335,12 @@ BasicShadowableContainerLayer::RemoveChild(Layer* aChild)
BasicContainerLayer::RemoveChild(aChild); BasicContainerLayer::RemoveChild(aChild);
} }
static PRBool
IsSurfaceDescriptorValid(const SurfaceDescriptor& aSurface)
{
return SurfaceDescriptor::T__None != aSurface.type();
}
class BasicShadowableThebesLayer : public BasicThebesLayer, class BasicShadowableThebesLayer : public BasicThebesLayer,
public BasicShadowableLayer public BasicShadowableLayer
{ {
@ -1342,8 +1354,8 @@ public:
} }
virtual ~BasicShadowableThebesLayer() virtual ~BasicShadowableThebesLayer()
{ {
if (mBackBuffer) if (IsSurfaceDescriptorValid(mBackBuffer))
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackBuffer); BasicManager()->ShadowLayerForwarder::DestroySharedSurface(&mBackBuffer);
MOZ_COUNT_DTOR(BasicShadowableThebesLayer); MOZ_COUNT_DTOR(BasicShadowableThebesLayer);
} }
@ -1356,15 +1368,18 @@ public:
virtual Layer* AsLayer() { return this; } virtual Layer* AsLayer() { return this; }
virtual ShadowableLayer* AsShadowableLayer() { return this; } virtual ShadowableLayer* AsShadowableLayer() { return this; }
virtual void SetBackBuffer(gfxSharedImageSurface* aBuffer) virtual PRBool SupportsSurfaceDescriptor() const { return PR_TRUE; }
virtual void SetBackBuffer(const SurfaceDescriptor& aBuffer)
{ {
mBackBuffer = aBuffer; mBackBuffer = aBuffer;
mBuffer.SetBackingBuffer(aBuffer); nsRefPtr<gfxASurface> backBuffer = BasicManager()->OpenDescriptor(mBackBuffer);
mBuffer.SetBackingBuffer(backBuffer);
} }
virtual void Disconnect() virtual void Disconnect()
{ {
mBackBuffer = nsnull; mBackBuffer = SurfaceDescriptor();
BasicShadowableLayer::Disconnect(); BasicShadowableLayer::Disconnect();
} }
@ -1384,9 +1399,10 @@ private:
NS_OVERRIDE virtual already_AddRefed<gfxASurface> NS_OVERRIDE virtual already_AddRefed<gfxASurface>
CreateBuffer(Buffer::ContentType aType, const nsIntSize& aSize); CreateBuffer(Buffer::ContentType aType, const nsIntSize& aSize);
// We give a ref to this buffer to our ThebesLayerBuffer, and keep // This describes the gfxASurface we hand to mBuffer. We keep a
// this ref here that we can destroy its underlying shmem segment. // copy of the descriptor here so that we can call
nsRefPtr<gfxSharedImageSurface> mBackBuffer; // DestroySharedSurface() on the descriptor.
SurfaceDescriptor mBackBuffer;
nsIntSize mBufferSize; nsIntSize mBufferSize;
}; };
@ -1401,7 +1417,8 @@ BasicShadowableThebesLayer::PaintBuffer(gfxContext* aContext,
aCallback, aCallbackData); aCallback, aCallbackData);
if (HasShadow()) { if (HasShadow()) {
NS_ABORT_IF_FALSE(!!mBackBuffer, "should have a back buffer by now"); NS_ABORT_IF_FALSE(IsSurfaceDescriptorValid(mBackBuffer),
"should have a back buffer by now");
BasicManager()->PaintedThebesBuffer(BasicManager()->Hold(this), BasicManager()->PaintedThebesBuffer(BasicManager()->Hold(this),
mBuffer.BufferRect(), mBuffer.BufferRect(),
@ -1418,21 +1435,18 @@ BasicShadowableThebesLayer::CreateBuffer(Buffer::ContentType aType,
return BasicThebesLayer::CreateBuffer(aType, aSize); return BasicThebesLayer::CreateBuffer(aType, aSize);
} }
if (mBackBuffer) { if (IsSurfaceDescriptorValid(mBackBuffer)) {
BasicManager()->DestroyedThebesBuffer(BasicManager()->Hold(this), BasicManager()->DestroyedThebesBuffer(BasicManager()->Hold(this),
mBackBuffer); mBackBuffer);
mBackBuffer = nsnull; mBackBuffer = SurfaceDescriptor();
} }
gfxASurface::gfxImageFormat format = (aType == gfxASurface::CONTENT_COLOR) ? SurfaceDescriptor tmpFront;
gfxASurface::ImageFormatRGB24 :
gfxASurface::ImageFormatARGB32;
nsRefPtr<gfxSharedImageSurface> tmpFront;
// XXX error handling // XXX error handling
if (!BasicManager()->AllocDoubleBuffer(gfxIntSize(aSize.width, aSize.height), if (!BasicManager()->AllocDoubleBuffer(gfxIntSize(aSize.width, aSize.height),
format, aType,
getter_AddRefs(tmpFront), &tmpFront,
getter_AddRefs(mBackBuffer))) &mBackBuffer))
NS_RUNTIMEABORT("creating ThebesLayer 'back buffer' failed!"); NS_RUNTIMEABORT("creating ThebesLayer 'back buffer' failed!");
mBufferSize = aSize; mBufferSize = aSize;
@ -1442,7 +1456,7 @@ BasicShadowableThebesLayer::CreateBuffer(Buffer::ContentType aType,
// follows // follows
nsIntRect(nsIntPoint(0, 0), aSize), nsIntRect(nsIntPoint(0, 0), aSize),
tmpFront); tmpFront);
return nsRefPtr<gfxASurface>(mBackBuffer).forget(); return BasicManager()->OpenDescriptor(mBackBuffer);
} }
@ -1476,7 +1490,7 @@ public:
virtual Layer* AsLayer() { return this; } virtual Layer* AsLayer() { return this; }
virtual ShadowableLayer* AsShadowableLayer() { return this; } virtual ShadowableLayer* AsShadowableLayer() { return this; }
virtual void SetBackBuffer(gfxSharedImageSurface* aBuffer) virtual void SetBackBufferImage(gfxSharedImageSurface* aBuffer)
{ {
mBackSurface = aBuffer; mBackSurface = aBuffer;
} }
@ -1596,7 +1610,7 @@ public:
virtual Layer* AsLayer() { return this; } virtual Layer* AsLayer() { return this; }
virtual ShadowableLayer* AsShadowableLayer() { return this; } virtual ShadowableLayer* AsShadowableLayer() { return this; }
virtual void SetBackBuffer(gfxSharedImageSurface* aBuffer) virtual void SetBackBufferImage(gfxSharedImageSurface* aBuffer)
{ {
mBackBuffer = aBuffer; mBackBuffer = aBuffer;
} }
@ -1681,8 +1695,8 @@ public:
MOZ_COUNT_DTOR(ShadowThebesLayerBuffer); MOZ_COUNT_DTOR(ShadowThebesLayerBuffer);
} }
already_AddRefed<gfxSharedImageSurface> already_AddRefed<gfxASurface>
Swap(gfxSharedImageSurface* aNewFrontBuffer, const nsIntSize& aBufferDims, Swap(gfxASurface* aNewFrontBuffer, const nsIntSize& aBufferDims,
const nsIntRect& aBufferRect, const nsIntRect& aBufferRect,
const nsIntPoint& aRotation=nsIntPoint(0, 0)) const nsIntPoint& aRotation=nsIntPoint(0, 0))
{ {
@ -1698,7 +1712,7 @@ public:
tmpCtx->DrawSurface(aNewFrontBuffer, tmpCtx->DrawSurface(aNewFrontBuffer,
gfxIntSize(aBufferDims.width, aBufferDims.height)); gfxIntSize(aBufferDims.width, aBufferDims.height));
} }
return static_cast<gfxSharedImageSurface*>(newBackBuffer.forget().get()); return newBackBuffer.forget();
} }
protected: protected:
@ -1731,22 +1745,17 @@ public:
ShadowThebesLayer::Disconnect(); ShadowThebesLayer::Disconnect();
} }
virtual already_AddRefed<gfxSharedImageSurface> virtual SurfaceDescriptor
Swap(gfxSharedImageSurface* aNewFront, Swap(const SurfaceDescriptor& aNewFront,
const nsIntRect& aBufferRect, const nsIntRect& aBufferRect,
const nsIntPoint& aRotation) const nsIntPoint& aRotation);
{
gfxIntSize size = aNewFront->GetSize();
return mFrontBuffer.Swap(aNewFront, nsIntSize(size.width, size.height),
aBufferRect, aRotation);
}
virtual void DestroyFrontBuffer() virtual void DestroyFrontBuffer()
{ {
nsRefPtr<gfxSharedImageSurface> frontBuffer = nsRefPtr<gfxASurface> unused =
mFrontBuffer.Swap(nsnull, nsIntSize(), nsIntRect()); mFrontBuffer.Swap(nsnull, nsIntSize(), nsIntRect());
if (frontBuffer) { if (IsSurfaceDescriptorValid(mFrontBufferDescriptor)) {
BasicManager()->ShadowLayerManager::DestroySharedSurface(frontBuffer); BasicManager()->ShadowLayerManager::DestroySharedSurface(&mFrontBufferDescriptor);
} }
} }
@ -1762,8 +1771,28 @@ private:
} }
ShadowThebesLayerBuffer mFrontBuffer; ShadowThebesLayerBuffer mFrontBuffer;
// Describes the gfxASurface we hand out to |mFrontBuffer|.
SurfaceDescriptor mFrontBufferDescriptor;
}; };
SurfaceDescriptor
BasicShadowThebesLayer::Swap(const SurfaceDescriptor& aNewFront,
const nsIntRect& aBufferRect,
const nsIntPoint& aRotation)
{
SurfaceDescriptor newBackBuffer = mFrontBufferDescriptor;
nsRefPtr<gfxASurface> newFrontBuffer =
BasicManager()->OpenDescriptor(aNewFront);
gfxIntSize size = newFrontBuffer->GetSize();
nsRefPtr<gfxASurface> unused =
mFrontBuffer.Swap(newFrontBuffer, nsIntSize(size.width, size.height),
aBufferRect, aRotation);
mFrontBufferDescriptor = aNewFront;
return newBackBuffer;
}
void void
BasicShadowThebesLayer::Paint(gfxContext* aContext, BasicShadowThebesLayer::Paint(gfxContext* aContext,
LayerManager::DrawThebesLayerCallback aCallback, LayerManager::DrawThebesLayerCallback aCallback,
@ -2124,8 +2153,18 @@ BasicShadowLayerManager::EndTransaction(DrawThebesLayerCallback aCallback,
MOZ_LAYERS_LOG(("[LayersForwarder] BufferSwap")); MOZ_LAYERS_LOG(("[LayersForwarder] BufferSwap"));
const OpBufferSwap& obs = reply.get_OpBufferSwap(); const OpBufferSwap& obs = reply.get_OpBufferSwap();
GetBasicShadowable(obs)->SetBackBuffer( const SurfaceDescriptor& descr = obs.newBackBuffer();
new gfxSharedImageSurface(obs.newBackBuffer())); BasicShadowableLayer* layer = GetBasicShadowable(obs);
if (layer->SupportsSurfaceDescriptor()) {
layer->SetBackBuffer(descr);
} else {
if (SurfaceDescriptor::TShmem != descr.type()) {
NS_RUNTIMEABORT("non-Shmem surface sent to a layer that expected one!");
}
nsRefPtr<gfxASurface> imageSurf = OpenDescriptor(descr);
layer->SetBackBufferImage(
static_cast<gfxSharedImageSurface*>(imageSurf.get()));
}
break; break;
} }

Просмотреть файл

@ -52,7 +52,7 @@
namespace mozilla { namespace mozilla {
namespace layers { namespace layers {
typedef nsTArray<nsRefPtr<gfxSharedImageSurface> > BufferArray; typedef nsTArray<SurfaceDescriptor> BufferArray;
typedef std::vector<Edit> EditVector; typedef std::vector<Edit> EditVector;
typedef std::set<ShadowableLayer*> ShadowableLayerSet; typedef std::set<ShadowableLayer*> ShadowableLayerSet;
@ -74,6 +74,10 @@ public:
mMutants.insert(aLayer); mMutants.insert(aLayer);
} }
void AddBufferToDestroy(gfxSharedImageSurface* aBuffer) void AddBufferToDestroy(gfxSharedImageSurface* aBuffer)
{
return AddBufferToDestroy(aBuffer->GetShmem());
}
void AddBufferToDestroy(const SurfaceDescriptor& aBuffer)
{ {
NS_ABORT_IF_FALSE(!Finished(), "forgot BeginTransaction?"); NS_ABORT_IF_FALSE(!Finished(), "forgot BeginTransaction?");
mDyingBuffers.AppendElement(aBuffer); mDyingBuffers.AppendElement(aBuffer);
@ -168,11 +172,11 @@ ShadowLayerForwarder::CreatedCanvasLayer(ShadowableLayer* aCanvas)
void void
ShadowLayerForwarder::CreatedThebesBuffer(ShadowableLayer* aThebes, ShadowLayerForwarder::CreatedThebesBuffer(ShadowableLayer* aThebes,
nsIntRect aBufferRect, nsIntRect aBufferRect,
gfxSharedImageSurface* aTempFrontBuffer) const SurfaceDescriptor& aTempFrontBuffer)
{ {
mTxn->AddEdit(OpCreateThebesBuffer(NULL, Shadow(aThebes), mTxn->AddEdit(OpCreateThebesBuffer(NULL, Shadow(aThebes),
aBufferRect, aBufferRect,
aTempFrontBuffer->GetShmem())); aTempFrontBuffer));
} }
void void
@ -197,7 +201,7 @@ ShadowLayerForwarder::CreatedCanvasBuffer(ShadowableLayer* aCanvas,
void void
ShadowLayerForwarder::DestroyedThebesBuffer(ShadowableLayer* aThebes, ShadowLayerForwarder::DestroyedThebesBuffer(ShadowableLayer* aThebes,
gfxSharedImageSurface* aBackBufferToDestroy) const SurfaceDescriptor& aBackBufferToDestroy)
{ {
mTxn->AddEdit(OpDestroyThebesFrontBuffer(NULL, Shadow(aThebes))); mTxn->AddEdit(OpDestroyThebesFrontBuffer(NULL, Shadow(aThebes)));
mTxn->AddBufferToDestroy(aBackBufferToDestroy); mTxn->AddBufferToDestroy(aBackBufferToDestroy);
@ -251,10 +255,10 @@ void
ShadowLayerForwarder::PaintedThebesBuffer(ShadowableLayer* aThebes, ShadowLayerForwarder::PaintedThebesBuffer(ShadowableLayer* aThebes,
nsIntRect aBufferRect, nsIntRect aBufferRect,
nsIntPoint aBufferRotation, nsIntPoint aBufferRotation,
gfxSharedImageSurface* aNewFrontBuffer) const SurfaceDescriptor& aNewFrontBuffer)
{ {
mTxn->AddEdit(OpPaintThebesBuffer(NULL, Shadow(aThebes), mTxn->AddEdit(OpPaintThebesBuffer(NULL, Shadow(aThebes),
ThebesBuffer(aNewFrontBuffer->GetShmem(), ThebesBuffer(aNewFrontBuffer,
aBufferRect, aBufferRect,
aBufferRotation))); aBufferRotation)));
} }
@ -290,7 +294,7 @@ ShadowLayerForwarder::EndTransaction(nsTArray<EditReply>* aReplies)
MOZ_LAYERS_LOG(("[LayersForwarder] destroying buffers...")); MOZ_LAYERS_LOG(("[LayersForwarder] destroying buffers..."));
for (PRUint32 i = 0; i < mTxn->mDyingBuffers.Length(); ++i) { for (PRUint32 i = 0; i < mTxn->mDyingBuffers.Length(); ++i) {
DestroySharedSurface(mTxn->mDyingBuffers[i]); DestroySharedSurface(&mTxn->mDyingBuffers[i]);
} }
MOZ_LAYERS_LOG(("[LayersForwarder] building transaction...")); MOZ_LAYERS_LOG(("[LayersForwarder] building transaction..."));

Просмотреть файл

@ -149,7 +149,7 @@ public:
*/ */
void CreatedThebesBuffer(ShadowableLayer* aThebes, void CreatedThebesBuffer(ShadowableLayer* aThebes,
nsIntRect aBufferRect, nsIntRect aBufferRect,
gfxSharedImageSurface* aInitialFrontBuffer); const SurfaceDescriptor& aInitialFrontBuffer);
/** /**
* For the next two methods, |aSize| is the size of * For the next two methods, |aSize| is the size of
* |aInitialFrontSurface|. * |aInitialFrontSurface|.
@ -170,7 +170,7 @@ public:
* resize, e.g. * resize, e.g.
*/ */
void DestroyedThebesBuffer(ShadowableLayer* aThebes, void DestroyedThebesBuffer(ShadowableLayer* aThebes,
gfxSharedImageSurface* aBackBufferToDestroy); const SurfaceDescriptor& aBackBufferToDestroy);
void DestroyedImageBuffer(ShadowableLayer* aImage); void DestroyedImageBuffer(ShadowableLayer* aImage);
void DestroyedCanvasBuffer(ShadowableLayer* aCanvas); void DestroyedCanvasBuffer(ShadowableLayer* aCanvas);
@ -209,7 +209,7 @@ public:
void PaintedThebesBuffer(ShadowableLayer* aThebes, void PaintedThebesBuffer(ShadowableLayer* aThebes,
nsIntRect aBufferRect, nsIntRect aBufferRect,
nsIntPoint aBufferRotation, nsIntPoint aBufferRotation,
gfxSharedImageSurface* aNewFrontBuffer); const SurfaceDescriptor& aNewFrontBuffer);
/** /**
* NB: this initial implementation only forwards RGBA data for * NB: this initial implementation only forwards RGBA data for
* ImageLayers. This is slow, and will be optimized. * ImageLayers. This is slow, and will be optimized.
@ -436,8 +436,8 @@ public:
* will tell! (Maybe possible to choose between both depending on * will tell! (Maybe possible to choose between both depending on
* size of blit vs. expense of re-fill?) * size of blit vs. expense of re-fill?)
*/ */
virtual already_AddRefed<gfxSharedImageSurface> virtual SurfaceDescriptor
Swap(gfxSharedImageSurface* aNewFront, Swap(const SurfaceDescriptor& aNewFront,
const nsIntRect& aBufferRect, const nsIntRect& aBufferRect,
const nsIntPoint& aRotation) = 0; const nsIntPoint& aRotation) = 0;

Просмотреть файл

@ -189,7 +189,7 @@ ShadowLayersParent::RecvUpdate(const nsTArray<Edit>& cset,
ShadowThebesLayer* thebes = static_cast<ShadowThebesLayer*>( ShadowThebesLayer* thebes = static_cast<ShadowThebesLayer*>(
AsShadowLayer(otb)->AsLayer()); AsShadowLayer(otb)->AsLayer());
unused << thebes->Swap(new gfxSharedImageSurface(otb.initialFront()), unused << thebes->Swap(otb.initialFront(),
otb.bufferRect(), otb.bufferRect(),
nsIntPoint(0, 0)); nsIntPoint(0, 0));
@ -368,14 +368,12 @@ ShadowLayersParent::RecvUpdate(const nsTArray<Edit>& cset,
static_cast<ShadowThebesLayer*>(shadow->AsLayer()); static_cast<ShadowThebesLayer*>(shadow->AsLayer());
const ThebesBuffer& newFront = op.newFrontBuffer(); const ThebesBuffer& newFront = op.newFrontBuffer();
nsRefPtr<gfxSharedImageSurface> newBack = SurfaceDescriptor newBack = thebes->Swap(newFront.buffer(),
thebes->Swap(new gfxSharedImageSurface(newFront.buffer()),
newFront.rect(), newFront.rect(),
newFront.rotation()); newFront.rotation());
// XXX figure me out // XXX figure me out
replyv.push_back(OpBufferSwap(shadow, NULL, replyv.push_back(OpBufferSwap(shadow, NULL, newBack));
newBack->GetShmem()));
break; break;
} }
case Edit::TOpPaintCanvas: { case Edit::TOpPaintCanvas: {