Bug 1201937 - push transform onto cairo context when evaluating path bounds. r=eihrul

This commit is contained in:
Lee Salzman 2015-09-21 13:33:06 -04:00
Родитель f95c3d69ad
Коммит 36f6069f0c
3 изменённых файлов: 24 добавлений и 8 удалений

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

@ -265,6 +265,13 @@ public:
return !(*this == other); return !(*this == other);
} }
bool ExactlyEquals(const Matrix& o) const
{
return _11 == o._11 && _12 == o._12 &&
_21 == o._21 && _22 == o._22 &&
_31 == o._31 && _32 == o._32;
}
/* Verifies that the matrix contains no Infs or NaNs. */ /* Verifies that the matrix contains no Infs or NaNs. */
bool IsFinite() const bool IsFinite() const
{ {

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

@ -188,7 +188,7 @@ PathCairo::ContainsPoint(const Point &aPoint, const Matrix &aTransform) const
inverse.Invert(); inverse.Invert();
Point transformed = inverse * aPoint; Point transformed = inverse * aPoint;
EnsureContainingContext(); EnsureContainingContext(aTransform);
return cairo_in_fill(mContainingContext, transformed.x, transformed.y); return cairo_in_fill(mContainingContext, transformed.x, transformed.y);
} }
@ -202,7 +202,7 @@ PathCairo::StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
inverse.Invert(); inverse.Invert();
Point transformed = inverse * aPoint; Point transformed = inverse * aPoint;
EnsureContainingContext(); EnsureContainingContext(aTransform);
SetCairoStrokeOptions(mContainingContext, aStrokeOptions); SetCairoStrokeOptions(mContainingContext, aStrokeOptions);
@ -212,7 +212,7 @@ PathCairo::StrokeContainsPoint(const StrokeOptions &aStrokeOptions,
Rect Rect
PathCairo::GetBounds(const Matrix &aTransform) const PathCairo::GetBounds(const Matrix &aTransform) const
{ {
EnsureContainingContext(); EnsureContainingContext(aTransform);
double x1, y1, x2, y2; double x1, y1, x2, y2;
@ -225,7 +225,7 @@ Rect
PathCairo::GetStrokedBounds(const StrokeOptions &aStrokeOptions, PathCairo::GetStrokedBounds(const StrokeOptions &aStrokeOptions,
const Matrix &aTransform) const const Matrix &aTransform) const
{ {
EnsureContainingContext(); EnsureContainingContext(aTransform);
double x1, y1, x2, y2; double x1, y1, x2, y2;
@ -266,13 +266,21 @@ PathCairo::StreamToSink(PathSink *aSink) const
} }
void void
PathCairo::EnsureContainingContext() const PathCairo::EnsureContainingContext(const Matrix &aTransform) const
{ {
if (mContainingContext) { if (mContainingContext) {
if (mContainingTransform.ExactlyEquals(aTransform)) {
return; return;
} }
} else {
mContainingContext = cairo_create(DrawTargetCairo::GetDummySurface()); mContainingContext = cairo_create(DrawTargetCairo::GetDummySurface());
}
mContainingTransform = aTransform;
cairo_matrix_t mat;
GfxMatrixToCairoMatrix(mContainingTransform, mat);
cairo_set_matrix(mContainingContext, &mat);
SetPathOnContext(mContainingContext); SetPathOnContext(mContainingContext);
} }

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

@ -80,11 +80,12 @@ public:
void AppendPathToBuilder(PathBuilderCairo *aBuilder, const Matrix *aTransform = nullptr) const; void AppendPathToBuilder(PathBuilderCairo *aBuilder, const Matrix *aTransform = nullptr) const;
private: private:
void EnsureContainingContext() const; void EnsureContainingContext(const Matrix &aTransform) const;
FillRule mFillRule; FillRule mFillRule;
std::vector<cairo_path_data_t> mPathData; std::vector<cairo_path_data_t> mPathData;
mutable cairo_t *mContainingContext; mutable cairo_t *mContainingContext;
mutable Matrix mContainingTransform;
Point mCurrentPoint; Point mCurrentPoint;
}; };