Bug 821475 - Moz2D: Remove flip when drawing gradient. r=mstange, a=lsblakk
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Sat, 15 Feb 2014 18:21:43 -0500
changeset 176320 d47ccac51df00d378c750bf15ef7615b7ccfad99
parent 176319 533e8bcf1404be7c8bef2ff571f371f0e990a29f
child 176321 7ca0fa1af120aab26bfc30428aec82b5ae06a3f9
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, lsblakk
bugs821475
milestone28.0
Bug 821475 - Moz2D: Remove flip when drawing gradient. r=mstange, a=lsblakk We muck with the matrix before we draw the text. We need to set it back after.
content/canvas/test/mochitest.ini
content/canvas/test/test_2d.fillText.gradient.html
gfx/2d/DrawTargetCG.cpp
--- a/content/canvas/test/mochitest.ini
+++ b/content/canvas/test/mochitest.ini
@@ -101,8 +101,9 @@ support-files =
 [test_mozDashOffset.html]
 [test_mozGetAsFile.html]
 [test_strokeText_throw.html]
 [test_toBlob.html]
 [test_toDataURL_alpha.html]
 [test_toDataURL_lowercase_ascii.html]
 [test_toDataURL_parameters.html]
 [test_windingRuleUndefined.html]
+[test_2d.fillText.gradient.html]
new file mode 100644
--- /dev/null
+++ b/content/canvas/test/test_2d.fillText.gradient.html
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<title>Canvas test: 2d.composite.canvas.xor</title>
+<script src="/MochiKit/MochiKit.js"></script>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css">
+<body>
+<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
+<script>
+function isPixel(ctx, x,y, r,g,b,a, pos, colour, d) {
+    var pixel = ctx.getImageData(x, y, 1, 1);
+    var pr = pixel.data[0],
+        pg = pixel.data[1],
+        pb = pixel.data[2],
+        pa = pixel.data[3];
+    ok(r-d <= pr && pr <= r+d &&
+       g-d <= pg && pg <= g+d &&
+       b-d <= pb && pb <= b+d &&
+       a-d <= pa && pa <= a+d,
+       "pixel "+pos+" is "+pr+","+pg+","+pb+","+pa+"; expected "+colour+" +/- "+d);
+}
+
+SimpleTest.waitForExplicitFinish();
+addLoadEvent(function () {
+
+var canvas = document.getElementById('c');
+var ctx = canvas.getContext('2d');
+                                var text                = "I";
+                                var colorTop    = 'rgba(255,0,0,1)';
+                                var colorBottom = 'rgba(0,255,0,1)';
+                                var inset               = 10;
+                                var grad                = ctx.createLinearGradient(inset, inset, inset, inset + 30);
+                                
+                                // add color stops
+                                grad.addColorStop(0, colorTop);
+                                grad.addColorStop(1, colorBottom);
+                                
+                                ctx.fillStyle               = grad;
+                                ctx.textBaseline    = 'top';
+                                ctx.font                    = '110px sans-serif'
+                                ctx.fillText(text, -10, -20);
+                                ctx.fillText(text, -8, -20);
+                                ctx.fillText(text, -6, -20);
+                                ctx.fillText(text, -4, -20);
+                                ctx.fillText(text, -2, -20);
+                                ctx.fillText(text, 0, -20);
+                                ctx.fillText(text, 2, -20);
+                                ctx.fillText(text, 4, -20);
+                                ctx.fillText(text, 6, -20);
+
+                                isPixel(ctx, 15,0, 255,0,0,255, "15,0", "255,0,0,255", 5);
+                                isPixel(ctx, 15,49, 0,255,0,255, "15,49", "0,255,0,255", 5);
+SimpleTest.finish();
+
+});
+</script>
+
--- a/gfx/2d/DrawTargetCG.cpp
+++ b/gfx/2d/DrawTargetCG.cpp
@@ -1114,18 +1114,17 @@ DrawTargetCG::FillGlyphs(ScaledFont *aFo
 
   //XXX: we should use a stack vector here when we have a class like that
   std::vector<CGGlyph> glyphs;
   std::vector<CGPoint> positions;
   glyphs.resize(aBuffer.mNumGlyphs);
   positions.resize(aBuffer.mNumGlyphs);
 
   // Handle the flip
-  CGAffineTransform matrix = CGAffineTransformMakeScale(1, -1);
-  CGContextConcatCTM(cg, matrix);
+  CGContextScaleCTM(cg, 1, -1);
   // CGContextSetTextMatrix works differently with kCGTextClip && kCGTextFill
   // It seems that it transforms the positions with TextFill and not with TextClip
   // Therefore we'll avoid it. See also:
   // http://cgit.freedesktop.org/cairo/commit/?id=9c0d761bfcdd28d52c83d74f46dd3c709ae0fa69
 
   for (unsigned int i = 0; i < aBuffer.mNumGlyphs; i++) {
     glyphs[i] = aBuffer.mGlyphs[i].mIndex;
     // XXX: CGPointMake might not be inlined
@@ -1151,16 +1150,17 @@ DrawTargetCG::FillGlyphs(ScaledFont *aFo
       extents = ComputeGlyphsExtents(bboxes, &positions.front(), aBuffer.mNumGlyphs, macFont->mSize);
 
       CGContextSetFont(cg, macFont->mFont);
       CGContextSetFontSize(cg, macFont->mSize);
       CGContextShowGlyphsAtPositions(cg, &glyphs.front(), &positions.front(),
                                      aBuffer.mNumGlyphs);
       delete bboxes;
     }
+    CGContextScaleCTM(cg, 1, -1);
     DrawGradient(cg, aPattern, extents);
   } else {
     //XXX: with CoreGraphics we can stroke text directly instead of going
     // through GetPath. It would be nice to add support for using that
     CGContextSetTextDrawingMode(cg, kCGTextFill);
     SetFillFromPattern(cg, mColorSpace, aPattern);
     if (ScaledFontMac::CTFontDrawGlyphsPtr != nullptr) {
       ScaledFontMac::CTFontDrawGlyphsPtr(macFont->mCTFont, &glyphs.front(),