Bug 784573 - Create a RAII helper for temporary cairo matrices. r=joe

This commit is contained in:
Anthony Jones 2012-09-03 17:47:09 -04:00
parent 0ebc307776
commit a362c2be73

View File

@ -207,6 +207,32 @@ GfxFillRuleToCairoFillRule(FillRule rule)
return CAIRO_FILL_RULE_WINDING;
}
// RAII class for temporarily changing the cairo matrix transform. It will use
// the given matrix transform while it is in scope. When it goes out of scope
// it will put the cairo context back the way it was.
class CairoTempMatrix
{
public:
CairoTempMatrix(cairo_t* aCtx, const Matrix& aMatrix)
: mCtx(aCtx)
{
cairo_get_matrix(aCtx, &mSaveMatrix);
cairo_matrix_t matrix;
GfxMatrixToCairoMatrix(aMatrix, matrix);
cairo_set_matrix(aCtx, &matrix);
}
~CairoTempMatrix()
{
cairo_get_matrix(mCtx, &mSaveMatrix);
}
private:
cairo_t* mCtx;
cairo_matrix_t mSaveMatrix;
};
}
}