Bug 764125; Fix a bug where a path with a transform is re-used. r=Bas

This commit is contained in:
Nicholas Cameron 2012-07-24 22:18:38 +12:00
parent d157fedf81
commit 5aadfa70b7
2 changed files with 27 additions and 5 deletions

View File

@ -44,6 +44,28 @@ CairoPathContext::~CairoPathContext()
cairo_destroy(mContext);
}
void
CairoPathContext::ObserveTarget(DrawTargetCairo* aDrawTarget)
{
if (!aDrawTarget) {
return;
}
if (mDrawTarget) {
mDrawTarget->SetPathObserver(NULL);
}
mDrawTarget = aDrawTarget;
// If there is a transform on the path, then we must have a separate context
// from the draw target, so we cannot be its observer
if (!mTransform.IsIdentity()) {
ForgetDrawTarget();
return;
}
mDrawTarget->SetPathObserver(this);
}
void
CairoPathContext::DuplicateContextAndPath(const Matrix& aMatrix /* = Matrix() */)
{
@ -320,11 +342,7 @@ PathCairo::CopyPathTo(cairo_t* aContext, DrawTargetCairo* aDrawTarget)
// Since aDrawTarget wants us to be the current path on its context, we
// should also listen to it for updates to that path (as an optimization).
// The easiest way to do this is to just recreate mPathContext, since it
// registers with aDrawTarget for updates.
mPathContext = new CairoPathContext(aContext, aDrawTarget,
mPathContext->GetFillRule(),
mPathContext->GetTransform());
mPathContext->ObserveTarget(aDrawTarget);
}
}

View File

@ -68,6 +68,10 @@ public:
// Returns true if this CairoPathContext represents path.
bool ContainsPath(const Path* path);
// add ourselves as an observer of aDrawTarget, if possible
// if we succeed, then mDrawTarget is set to aDrawTarget
void ObserveTarget(DrawTargetCairo* aDrawTarget);
cairo_t* GetContext() const { return mContext; }
DrawTargetCairo* GetDrawTarget() const { return mDrawTarget; }
Matrix GetTransform() const { return mTransform; }