From f8e8d3bb7a021b5055d54db6987ef549c2d48fee Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Wed, 21 Aug 2013 11:57:57 +1200 Subject: [PATCH] Bug 907011 - Implement pattern matrices for the Cairo Azure backend. r=Bas --- gfx/2d/DrawTargetCairo.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/gfx/2d/DrawTargetCairo.cpp b/gfx/2d/DrawTargetCairo.cpp index ecf8f455e4a3..1da678036709 100644 --- a/gfx/2d/DrawTargetCairo.cpp +++ b/gfx/2d/DrawTargetCairo.cpp @@ -255,6 +255,7 @@ static cairo_pattern_t* GfxPatternToCairoPattern(const Pattern& aPattern, Float aAlpha) { cairo_pattern_t* pat; + const Matrix* matrix = nullptr; switch (aPattern.GetType()) { @@ -272,14 +273,7 @@ GfxPatternToCairoPattern(const Pattern& aPattern, Float aAlpha) pat = cairo_pattern_create_for_surface(surf); - // The pattern matrix is a matrix that transforms the pattern into user - // space. Cairo takes a matrix that converts from user space to pattern - // space. Cairo therefore needs the inverse. - - cairo_matrix_t mat; - GfxMatrixToCairoMatrix(pattern.mMatrix, mat); - cairo_matrix_invert(&mat); - cairo_pattern_set_matrix(pat, &mat); + matrix = &pattern.mMatrix; cairo_pattern_set_filter(pat, GfxFilterToCairoFilter(pattern.mFilter)); cairo_pattern_set_extend(pat, GfxExtendToCairoExtend(pattern.mExtendMode)); @@ -299,6 +293,8 @@ GfxPatternToCairoPattern(const Pattern& aPattern, Float aAlpha) GradientStopsCairo* cairoStops = static_cast(pattern.mStops.get()); cairo_pattern_set_extend(pat, GfxExtendToCairoExtend(cairoStops->GetExtendMode())); + matrix = &pattern.mMatrix; + const std::vector& stops = cairoStops->GetStops(); for (size_t i = 0; i < stops.size(); ++i) { const GradientStop& stop = stops[i]; @@ -320,6 +316,8 @@ GfxPatternToCairoPattern(const Pattern& aPattern, Float aAlpha) GradientStopsCairo* cairoStops = static_cast(pattern.mStops.get()); cairo_pattern_set_extend(pat, GfxExtendToCairoExtend(cairoStops->GetExtendMode())); + matrix = &pattern.mMatrix; + const std::vector& stops = cairoStops->GetStops(); for (size_t i = 0; i < stops.size(); ++i) { const GradientStop& stop = stops[i]; @@ -337,6 +335,16 @@ GfxPatternToCairoPattern(const Pattern& aPattern, Float aAlpha) } } + // The pattern matrix is a matrix that transforms the pattern into user + // space. Cairo takes a matrix that converts from user space to pattern + // space. Cairo therefore needs the inverse. + if (matrix) { + cairo_matrix_t mat; + GfxMatrixToCairoMatrix(*matrix, mat); + cairo_matrix_invert(&mat); + cairo_pattern_set_matrix(pat, &mat); + } + return pat; }