Bug 567966: Part 1: Properly handle siblings and children. Also fix missing release on container destructor. r=vlad

This commit is contained in:
Bas Schouten 2010-05-25 09:37:19 +02:00
parent 2409b23285
commit 44402345e3
5 changed files with 51 additions and 36 deletions

View File

@ -47,6 +47,18 @@ ContainerLayerD3D9::ContainerLayerD3D9(LayerManagerD3D9 *aManager)
mImplData = static_cast<LayerD3D9*>(this); mImplData = static_cast<LayerD3D9*>(this);
} }
ContainerLayerD3D9::~ContainerLayerD3D9()
{
while (mFirstChild) {
Layer* next = mFirstChild->GetNextSibling();
mFirstChild->SetNextSibling(nsnull);
mFirstChild->SetPrevSibling(nsnull);
mFirstChild->SetParent(nsnull);
NS_RELEASE(mFirstChild);
mFirstChild = next;
}
}
const nsIntRect& const nsIntRect&
ContainerLayerD3D9::GetVisibleRect() ContainerLayerD3D9::GetVisibleRect()
{ {
@ -62,21 +74,28 @@ ContainerLayerD3D9::SetVisibleRegion(const nsIntRegion &aRegion)
void void
ContainerLayerD3D9::InsertAfter(Layer* aChild, Layer* aAfter) ContainerLayerD3D9::InsertAfter(Layer* aChild, Layer* aAfter)
{ {
LayerD3D9 *newChild = static_cast<LayerD3D9*>(aChild->ImplData());
aChild->SetParent(this); aChild->SetParent(this);
if (!aAfter) { if (!aAfter) {
LayerD3D9 *oldFirstChild = GetFirstChildD3D9(); Layer *oldFirstChild = GetFirstChild();
mFirstChild = newChild->GetLayer(); mFirstChild = aChild;
newChild->SetNextSibling(oldFirstChild); aChild->SetNextSibling(oldFirstChild);
aChild->SetPrevSibling(nsnull);
if (oldFirstChild) {
oldFirstChild->SetPrevSibling(aChild);
}
NS_ADDREF(aChild); NS_ADDREF(aChild);
return; return;
} }
for (LayerD3D9 *child = GetFirstChildD3D9(); for (Layer *child = GetFirstChild();
child; child = child->GetNextSibling()) { child; child = child->GetNextSibling()) {
if (aAfter == child->GetLayer()) { if (aAfter == child) {
LayerD3D9 *oldNextSibling = child->GetNextSibling(); Layer *oldNextSibling = child->GetNextSibling();
child->SetNextSibling(newChild); child->SetNextSibling(aChild);
child->GetNextSibling()->SetNextSibling(oldNextSibling); aChild->SetNextSibling(oldNextSibling);
if (oldNextSibling) {
oldNextSibling->SetPrevSibling(aChild);
}
aChild->SetPrevSibling(child);
NS_ADDREF(aChild); NS_ADDREF(aChild);
return; return;
} }
@ -88,19 +107,26 @@ void
ContainerLayerD3D9::RemoveChild(Layer *aChild) ContainerLayerD3D9::RemoveChild(Layer *aChild)
{ {
if (GetFirstChild() == aChild) { if (GetFirstChild() == aChild) {
mFirstChild = GetFirstChildD3D9()->GetNextSibling() ? mFirstChild = GetFirstChild()->GetNextSibling() ?
GetFirstChildD3D9()->GetNextSibling()->GetLayer() : nsnull; GetFirstChild()->GetNextSibling() : nsnull;
if (mFirstChild) {
mFirstChild->SetPrevSibling(nsnull);
}
NS_RELEASE(aChild); NS_RELEASE(aChild);
return; return;
} }
LayerD3D9 *lastChild = NULL; Layer *lastChild = nsnull;
for (LayerD3D9 *child = GetFirstChildD3D9(); child; for (Layer *child = GetFirstChild(); child;
child = child->GetNextSibling()) { child = child->GetNextSibling()) {
if (child->GetLayer() == aChild) { if (child == aChild) {
// We're sure this is not our first child. So lastChild != NULL. // We're sure this is not our first child. So lastChild != NULL.
lastChild->SetNextSibling(child->GetNextSibling()); lastChild->SetNextSibling(child->GetNextSibling());
child->SetNextSibling(NULL); if (child->GetNextSibling()) {
child->GetLayer()->SetParent(NULL); child->GetNextSibling()->SetPrevSibling(lastChild);
}
child->SetNextSibling(nsnull);
child->SetPrevSibling(nsnull);
child->SetParent(nsnull);
NS_RELEASE(aChild); NS_RELEASE(aChild);
return; return;
} }
@ -210,7 +236,10 @@ ContainerLayerD3D9::RenderLayer()
device()->SetScissorRect(&r); device()->SetScissorRect(&r);
layerToRender->RenderLayer(); layerToRender->RenderLayer();
layerToRender = layerToRender->GetNextSibling(); Layer *nextSibling = layerToRender->GetLayer()->GetNextSibling();
layerToRender = nextSibling ? static_cast<LayerD3D9*>(nextSibling->
ImplData())
: nsnull;
} }
if (useIntermediate) { if (useIntermediate) {

View File

@ -45,10 +45,11 @@ namespace mozilla {
namespace layers { namespace layers {
class ContainerLayerD3D9 : public ContainerLayer, class ContainerLayerD3D9 : public ContainerLayer,
public LayerD3D9 public LayerD3D9
{ {
public: public:
ContainerLayerD3D9(LayerManagerD3D9 *aManager); ContainerLayerD3D9(LayerManagerD3D9 *aManager);
~ContainerLayerD3D9();
const nsIntRect &GetVisibleRect(); const nsIntRect &GetVisibleRect();

View File

@ -100,6 +100,7 @@ class THEBES_API PlanarYCbCrImageD3D9 : public PlanarYCbCrImage,
{ {
public: public:
PlanarYCbCrImageD3D9(LayerManagerD3D9 *aManager); PlanarYCbCrImageD3D9(LayerManagerD3D9 *aManager);
~PlanarYCbCrImageD3D9() {}
virtual void SetData(const Data &aData); virtual void SetData(const Data &aData);

View File

@ -558,21 +558,8 @@ LayerManagerD3D9::VerifyCaps()
LayerD3D9::LayerD3D9(LayerManagerD3D9 *aManager) LayerD3D9::LayerD3D9(LayerManagerD3D9 *aManager)
: mD3DManager(aManager) : mD3DManager(aManager)
, mNextSibling(NULL)
{ {
} }
LayerD3D9*
LayerD3D9::GetNextSibling()
{
return mNextSibling;
}
void
LayerD3D9::SetNextSibling(LayerD3D9 *aNextSibling)
{
mNextSibling = aNextSibling;
}
} /* namespace layers */ } /* namespace layers */
} /* namespace mozilla */ } /* namespace mozilla */

View File

@ -217,10 +217,8 @@ public:
virtual LayerType GetType() = 0; virtual LayerType GetType() = 0;
LayerD3D9 *GetNextSibling();
virtual LayerD3D9 *GetFirstChildD3D9() { return nsnull; } virtual LayerD3D9 *GetFirstChildD3D9() { return nsnull; }
void SetNextSibling(LayerD3D9 *aParent);
void SetFirstChild(LayerD3D9 *aParent); void SetFirstChild(LayerD3D9 *aParent);
virtual Layer* GetLayer() = 0; virtual Layer* GetLayer() = 0;
@ -230,7 +228,6 @@ public:
IDirect3DDevice9 *device() const { return mD3DManager->device(); } IDirect3DDevice9 *device() const { return mD3DManager->device(); }
protected: protected:
LayerManagerD3D9 *mD3DManager; LayerManagerD3D9 *mD3DManager;
LayerD3D9 *mNextSibling;
}; };
} /* layers */ } /* layers */