Backed out changeset b37bdb032fe7

This commit is contained in:
Robert O'Callahan
2010-05-24 10:53:05 +12:00
parent 878449cec1
commit b0069a62d7
22 changed files with 912 additions and 854 deletions

View File

@@ -94,9 +94,7 @@ public:
* set up to account for all the properties of the layer (transform,
* opacity, etc).
*/
virtual void Paint(gfxContext* aContext,
LayerManager::DrawThebesLayerCallback aCallback,
void* aCallbackData) {}
virtual void Paint(gfxContext* aContext) {}
protected:
nsIntRegion mVisibleRegion;
@@ -242,9 +240,8 @@ public:
"Can only set properties in construction phase");
}
virtual void Paint(gfxContext* aContext,
LayerManager::DrawThebesLayerCallback aCallback,
void* aCallbackData);
virtual gfxContext* BeginDrawing(nsIntRegion* aRegionToDraw);
virtual void EndDrawing();
protected:
BasicLayerManager* BasicManager()
@@ -253,17 +250,30 @@ protected:
}
};
void
BasicThebesLayer::Paint(gfxContext* aContext,
LayerManager::DrawThebesLayerCallback aCallback,
void* aCallbackData)
gfxContext*
BasicThebesLayer::BeginDrawing(nsIntRegion* aRegionToDraw)
{
NS_ASSERTION(BasicManager()->IsBeforeInTree(BasicManager()->GetLastPainted(), this),
"Painting layers out of order");
NS_ASSERTION(BasicManager()->InDrawing(),
"Can only draw in drawing phase");
gfxContext* target = BasicManager()->GetTarget();
NS_ASSERTION(target, "We shouldn't be called if there's no target");
if (!target)
return nsnull;
aCallback(this, target, mVisibleRegion, aCallbackData);
BasicManager()->AdvancePaintingTo(this);
*aRegionToDraw = mVisibleRegion;
return target;
}
void
BasicThebesLayer::EndDrawing()
{
NS_ASSERTION(BasicManager()->InDrawing(),
"Can only draw in drawing phase");
NS_ASSERTION(BasicManager()->GetLastPainted() == this,
"Not currently drawing this layer");
}
class BasicImageLayer : public ImageLayer, BasicImplData {
@@ -285,9 +295,7 @@ public:
mVisibleRegion = aRegion;
}
virtual void Paint(gfxContext* aContext,
LayerManager::DrawThebesLayerCallback aCallback,
void* aCallbackData);
virtual void Paint(gfxContext* aContext);
protected:
BasicLayerManager* BasicManager()
@@ -297,9 +305,7 @@ protected:
};
void
BasicImageLayer::Paint(gfxContext* aContext,
LayerManager::DrawThebesLayerCallback aCallback,
void* aCallbackData)
BasicImageLayer::Paint(gfxContext* aContext)
{
if (!mContainer)
return;
@@ -359,9 +365,7 @@ public:
mVisibleRegion = aRegion;
}
virtual void Paint(gfxContext* aContext,
LayerManager::DrawThebesLayerCallback aCallback,
void* aCallbackData);
virtual void Paint(gfxContext* aContext);
protected:
BasicLayerManager* BasicManager()
@@ -371,9 +375,7 @@ protected:
};
void
BasicColorLayer::Paint(gfxContext* aContext,
LayerManager::DrawThebesLayerCallback aCallback,
void* aCallbackData)
BasicColorLayer::Paint(gfxContext* aContext)
{
aContext->SetColor(mColor);
aContext->Paint();
@@ -395,9 +397,7 @@ public:
virtual void Initialize(const Data& aData);
virtual void Updated(const nsIntRect& aRect);
virtual void Paint(gfxContext* aContext,
LayerManager::DrawThebesLayerCallback aCallback,
void* aCallbackData);
virtual void Paint(gfxContext* aContext);
protected:
nsRefPtr<gfxASurface> mSurface;
@@ -484,9 +484,7 @@ BasicCanvasLayer::Updated(const nsIntRect& aRect)
}
void
BasicCanvasLayer::Paint(gfxContext* aContext,
LayerManager::DrawThebesLayerCallback aCallback,
void* aCallbackData)
BasicCanvasLayer::Paint(gfxContext* aContext)
{
nsRefPtr<gfxPattern> pat = new gfxPattern(mSurface);
@@ -513,7 +511,7 @@ BasicCanvasLayer::Paint(gfxContext* aContext,
}
BasicLayerManager::BasicLayerManager(gfxContext* aContext) :
mDefaultTarget(aContext)
mDefaultTarget(aContext), mLastPainted(nsnull)
#ifdef DEBUG
, mPhase(PHASE_NONE)
#endif
@@ -556,23 +554,24 @@ BasicLayerManager::BeginTransactionWithTarget(gfxContext* aTarget)
}
void
BasicLayerManager::EndTransaction(DrawThebesLayerCallback aCallback,
void* aCallbackData)
BasicLayerManager::EndConstruction()
{
NS_ASSERTION(mRoot, "Root not set");
NS_ASSERTION(mPhase == PHASE_CONSTRUCTION, "Should be in construction phase");
#ifdef DEBUG
mPhase = PHASE_DRAWING;
#endif
}
if (mTarget) {
PaintLayer(mRoot, aCallback, aCallbackData);
mTarget = nsnull;
}
void
BasicLayerManager::EndTransaction()
{
NS_ASSERTION(mPhase == PHASE_DRAWING, "Should be in drawing phase");
#ifdef DEBUG
mPhase = PHASE_NONE;
#endif
AdvancePaintingTo(nsnull);
mTarget = nsnull;
// No retained layers supported for now
mRoot = nsnull;
}
@@ -626,14 +625,10 @@ UseOpaqueSurface(Layer* aLayer)
}
void
BasicLayerManager::PaintLayer(Layer* aLayer,
DrawThebesLayerCallback aCallback,
void* aCallbackData)
BasicLayerManager::BeginPaintingLayer(Layer* aLayer)
{
PRBool needsGroup = NeedsGroup(aLayer);
PRBool needsSaveRestore = needsGroup || NeedsState(aLayer);
if (needsSaveRestore) {
if ((needsGroup || NeedsState(aLayer)) && mTarget) {
mTarget->Save();
if (aLayer->GetClipRect()) {
@@ -672,22 +667,66 @@ BasicLayerManager::PaintLayer(Layer* aLayer,
}
}
ToData(aLayer)->Paint(mTarget, aCallback, aCallbackData);
for (Layer* child = aLayer->GetFirstChild(); child;
child = child->GetNextSibling()) {
PaintLayer(child, aCallback, aCallbackData);
}
mLastPainted = aLayer;
if (needsSaveRestore) {
// For layers that paint themselves (e.g., BasicImageLayer), paint
// them now.
ToData(aLayer)->Paint(mTarget);
}
void
BasicLayerManager::EndPaintingLayer()
{
PRBool needsGroup = NeedsGroup(mLastPainted);
if ((needsGroup || NeedsState(mLastPainted)) && mTarget) {
if (needsGroup) {
mTarget->PopGroupToSource();
mTarget->Paint(aLayer->GetOpacity());
mTarget->Paint(mLastPainted->GetOpacity());
}
mTarget->Restore();
}
}
void
BasicLayerManager::AdvancePaintingTo(BasicThebesLayer* aLayer)
{
NS_ASSERTION(!aLayer || IsBeforeInTree(mLastPainted, aLayer),
"Painting layers out of order");
// Traverse the layer tree from mLastPainted to aLayer, calling
// BeginPaintingLayer and EndPaintingLayer as we enter or exit layers.
do {
Layer* firstChild;
Layer* nextSibling;
// Advance mLastPainted one step through the tree in preorder
if (!mLastPainted) {
// This is the first AdvancePaintingTo call. Start at the root.
BeginPaintingLayer(mRoot);
} else if ((firstChild = mLastPainted->GetFirstChild()) != nsnull) {
// Descend into our first child, if there is one.
BeginPaintingLayer(firstChild);
} else if ((nextSibling = mLastPainted->GetNextSibling()) != nsnull) {
// There are no children to descend into. Leave this layer and
// advance to our next sibling, if there is one.
EndPaintingLayer();
BeginPaintingLayer(nextSibling);
} else {
// There are no children to descend into and we have no next sibling.
// Exit layers until we find a layer which has a next sibling
// (or we exit the root).
do {
EndPaintingLayer();
mLastPainted = mLastPainted->GetParent();
} while (mLastPainted && !mLastPainted->GetNextSibling());
if (mLastPainted) {
EndPaintingLayer();
BeginPaintingLayer(mLastPainted->GetNextSibling());
}
}
} while (mLastPainted != aLayer);
}
already_AddRefed<ThebesLayer>
BasicLayerManager::CreateThebesLayer()
{
@@ -728,5 +767,54 @@ BasicLayerManager::CreateCanvasLayer()
return layer.forget();
}
#ifdef DEBUG
static void
AppendAncestors(Layer* aLayer, nsTArray<Layer*>* aAncestors)
{
while (aLayer) {
aAncestors->AppendElement(aLayer);
aLayer = aLayer->GetParent();
}
}
PRBool
BasicLayerManager::IsBeforeInTree(Layer* aBefore, Layer* aLayer)
{
if (!aBefore) {
return PR_TRUE;
}
nsAutoTArray<Layer*,8> beforeAncestors, afterAncestors;
AppendAncestors(aBefore, &beforeAncestors);
AppendAncestors(aLayer, &afterAncestors);
PRInt32 beforeIndex = beforeAncestors.Length() - 1;
PRInt32 afterIndex = afterAncestors.Length() - 1;
NS_ASSERTION(beforeAncestors[beforeIndex] == mRoot, "aBefore not in tree?");
NS_ASSERTION(afterAncestors[afterIndex] == mRoot, "aLayer not in tree?");
--beforeIndex;
--afterIndex;
while (beforeIndex >= 0 && afterIndex >= 0) {
if (beforeAncestors[beforeIndex] != afterAncestors[afterIndex]) {
BasicContainerLayer* parent =
static_cast<BasicContainerLayer*>(beforeAncestors[beforeIndex + 1]);
for (Layer* child = parent->GetFirstChild();
child != afterAncestors[afterIndex];
child = child->GetNextSibling()) {
if (child == beforeAncestors[beforeIndex]) {
return PR_TRUE;
}
}
return PR_FALSE;
}
--beforeIndex;
--afterIndex;
}
if (afterIndex > 0) {
// aBefore is an ancestor of aLayer, so it's before aLayer in preorder
return PR_TRUE;
}
return PR_FALSE;
}
#endif
}
}