Bug 1085533, part 2 - Port nsDisplayNotation::Paint to Moz2D. r=mattwoodrow
authorJonathan Watt <jwatt@jwatt.org>
Fri, 24 Oct 2014 08:26:28 +0100
changeset 212082 15f6514447d6369b5b8f6818491e93e50f9d2c43
parent 212081 6decbde116bc7f899ae63c0dbf503895da1b88f6
child 212083 e413f8f8c235f6dfc8dd5fb00190012c103b22f4
push id27697
push usercbook@mozilla.com
push dateFri, 24 Oct 2014 13:48:53 +0000
treeherdermozilla-central@de805196bbc4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1085533
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1085533, part 2 - Port nsDisplayNotation::Paint to Moz2D. r=mattwoodrow
layout/mathml/nsMathMLmencloseFrame.cpp
layout/reftests/mathml/reftest.list
--- a/layout/mathml/nsMathMLmencloseFrame.cpp
+++ b/layout/mathml/nsMathMLmencloseFrame.cpp
@@ -762,111 +762,97 @@ private:
   nsRect             mRect;
   nscoord            mThickness;
   nsMencloseNotation mType;
 };
 
 void nsDisplayNotation::Paint(nsDisplayListBuilder* aBuilder,
                               nsRenderingContext* aCtx)
 {
-  // get the gfxRect
+  DrawTarget& aDrawTarget = *aCtx->GetDrawTarget();
   nsPresContext* presContext = mFrame->PresContext();
-  gfxRect rect = presContext->AppUnitsToGfxUnits(mRect + ToReferenceFrame());
+
+  Float strokeWidth = presContext->AppUnitsToGfxUnits(mThickness);
 
-  // paint the frame with the current text color
+  Rect rect = NSRectToRect(mRect + ToReferenceFrame(),
+                           presContext->AppUnitsPerDevPixel());
+  rect.Deflate(strokeWidth / 2.f);
+
   ColorPattern color(ToDeviceColor(
                        mFrame->GetVisitedDependentColor(eCSSProperty_color)));
-  aCtx->ThebesContext()->SetColor(
-          mFrame->GetVisitedDependentColor(eCSSProperty_color));
 
-  DrawTarget* drawTarget = aCtx->GetDrawTarget();
-
-  // change line width to mThickness
-  gfxContext *gfxCtx = aCtx->ThebesContext();
-  gfxFloat e = presContext->AppUnitsToGfxUnits(mThickness);
-  gfxCtx->Save();
-  gfxCtx->SetLineWidth(e);
-
-  rect.Deflate(e / 2.0);
+  StrokeOptions strokeOptions(strokeWidth);
 
   switch(mType)
   {
     case NOTATION_CIRCLE: {
-      RefPtr<PathBuilder> builder = drawTarget->CreatePathBuilder();
-      AppendEllipseToPath(builder, ToPoint(rect.Center()), ToSize(rect.Size()));
-      RefPtr<Path> ellipse = builder->Finish();
-      drawTarget->Stroke(ellipse, color);
-      break;
+      RefPtr<Path> ellipse =
+        MakePathForEllipse(aDrawTarget, rect.Center(), rect.Size());
+      aDrawTarget.Stroke(ellipse, color, strokeOptions);
+      return;
     }
-
-    case NOTATION_ROUNDEDBOX:
-      gfxCtx->NewPath();
-      gfxCtx->RoundedRectangle(rect, gfxCornerSizes(3 * e), true);
-      gfxCtx->Stroke();
-      break;
-
-    case NOTATION_UPDIAGONALSTRIKE:
-      gfxCtx->NewPath();
-      gfxCtx->Line(rect.BottomLeft(), rect.TopRight());
-      gfxCtx->Stroke();
-      break;
-
-    case NOTATION_DOWNDIAGONALSTRIKE:
-      gfxCtx->NewPath();
-      gfxCtx->Line(rect.TopLeft(), rect.BottomRight());
-      gfxCtx->Stroke();
-      break;
-
+    case NOTATION_ROUNDEDBOX: {
+      Float radius = 3 * strokeWidth;
+      Size cornerRadii(radius, radius);
+      Size radii[] = { cornerRadii, cornerRadii, cornerRadii, cornerRadii };
+      RefPtr<Path> roundedRect =
+        MakePathForRoundedRect(aDrawTarget, rect, radii, true);
+      aDrawTarget.Stroke(roundedRect, color, strokeOptions);
+      return;
+    }
+    case NOTATION_UPDIAGONALSTRIKE: {
+      aDrawTarget.StrokeLine(rect.BottomLeft(), rect.TopRight(),
+                             color, strokeOptions);
+      return;
+    }
+    case NOTATION_DOWNDIAGONALSTRIKE: {
+      aDrawTarget.StrokeLine(rect.TopLeft(), rect.BottomRight(),
+                             color, strokeOptions);
+      return;
+    }
     case NOTATION_UPDIAGONALARROW: {
       // Compute some parameters to draw the updiagonalarrow. The values below
       // are taken from MathJax's HTML-CSS output.
-      gfxFloat W = rect.Width(); gfxFloat H = rect.Height();
-      gfxFloat l = sqrt(W*W + H*H);
-      gfxFloat f = gfxFloat(kArrowHeadSize) * e / l;
-      gfxFloat w = W * f; gfxFloat h = H * f;
+      Float W = rect.Width(); gfxFloat H = rect.Height();
+      Float l = sqrt(W*W + H*H);
+      Float f = Float(kArrowHeadSize) * strokeWidth / l;
+      Float w = W * f; gfxFloat h = H * f;
 
       // Draw the arrow shaft
-      gfxCtx->NewPath();
-      gfxCtx->Line(rect.BottomLeft(), rect.TopRight() + gfxPoint(-.7*w, .7*h));
-      gfxCtx->Stroke();
+      aDrawTarget.StrokeLine(rect.BottomLeft(),
+                             rect.TopRight() + Point(-.7*w, .7*h),
+                             color, strokeOptions);
 
       // Draw the arrow head
-      gfxCtx->NewPath();
-      gfxPoint p[] = {
-        rect.TopRight(),
-        rect.TopRight() + gfxPoint(-w -.4*h, std::max(-e / 2.0, h - .4*w)),
-        rect.TopRight() + gfxPoint(-.7*w, .7*h),
-        rect.TopRight() + gfxPoint(std::min(e / 2.0, -w + .4*h), h + .4*w),
-        rect.TopRight()
-      };
-      gfxCtx->Polygon(p, MOZ_ARRAY_LENGTH(p));
-      gfxCtx->Fill();
+      RefPtr<PathBuilder> builder = aDrawTarget.CreatePathBuilder();
+      builder->MoveTo(rect.TopRight());
+      builder->LineTo(rect.TopRight() + Point(-w -.4*h, std::max(-strokeWidth / 2.0, h - .4*w)));
+      builder->LineTo(rect.TopRight() + Point(-.7*w, .7*h));
+      builder->LineTo(rect.TopRight() + Point(std::min(strokeWidth / 2.0, -w + .4*h), h + .4*w));
+      builder->Close();
+      RefPtr<Path> path = builder->Finish();
+      aDrawTarget.Fill(path, color);
+      return;
     }
-      break;
-
     case NOTATION_PHASORANGLE: {
       // Compute some parameters to draw the angled line,
       // that uses a slope of 2 (angle = tan^-1(2)).
       // H = w * tan(angle) = w * 2
-      gfxFloat w = gfxFloat(kPhasorangleWidth) * e;
-      gfxFloat H = 2 * w;
+      Float w = Float(kPhasorangleWidth) * strokeWidth;
+      Float H = 2 * w;
 
       // Draw the angled line
-      gfxCtx->NewPath();
-      gfxCtx->Line(rect.BottomLeft(), rect.BottomLeft() + gfxPoint(w, -H));
-      gfxCtx->Stroke();
-      break;
+      aDrawTarget.StrokeLine(rect.BottomLeft(),
+                             rect.BottomLeft() + Point(w, -H),
+                             color, strokeOptions);
+      return;
     }
-
     default:
       NS_NOTREACHED("This notation can not be drawn using nsDisplayNotation");
-      break;
   }
-
-  gfxCtx->Restore();
 }
 
 void
 nsMathMLmencloseFrame::DisplayNotation(nsDisplayListBuilder* aBuilder,
                                        nsIFrame* aFrame, const nsRect& aRect,
                                        const nsDisplayListSet& aLists,
                                        nscoord aThickness,
                                        nsMencloseNotation aType)
--- a/layout/reftests/mathml/reftest.list
+++ b/layout/reftests/mathml/reftest.list
@@ -236,44 +236,44 @@ fails-if(B2G||Android||OSX==10.6) == men
 == menclose-3-invalid.html menclose-3-invalid-ref.html
 == menclose-3-multiple.html menclose-3-multiple-ref.html
 == menclose-3-unknown.html menclose-3-unknown.html
 == menclose-4.html data:text/html,<body>Pass
 == menclose-5-actuarial.html menclose-5-actuarial-ref.html
 == menclose-5-bottom.html menclose-5-bottom-ref.html
 == menclose-5-box.html menclose-5-box-ref.html
 fuzzy-if(OSX,1,100) == menclose-5-circle.html menclose-5-circle-ref.html
-== menclose-5-downdiagonalstrike.html menclose-5-downdiagonalstrike-ref.html
+fuzzy-if(d2d&&!contentSameGfxBackendAsCanvas,7,1) == menclose-5-downdiagonalstrike.html menclose-5-downdiagonalstrike-ref.html
 == menclose-5-horizontalstrike.html menclose-5-horizontalstrike-ref.html
 == menclose-5-left.html menclose-5-left-ref.html
 == menclose-5-longdiv.html menclose-5-longdiv-ref.html
 == menclose-5-madruwb.html menclose-5-madruwb-ref.html
 == menclose-5-radical.html menclose-5-radical-ref.html
 == menclose-5-right.html menclose-5-right-ref.html
 == menclose-5-roundedbox.html menclose-5-roundedbox-ref.html
 == menclose-5-top.html menclose-5-top-ref.html
 == menclose-5-updiagonalarrow.html menclose-5-updiagonalarrow-ref.html
-== menclose-5-updiagonalstrike.html menclose-5-updiagonalstrike-ref.html
+fuzzy-if(d2d&&!contentSameGfxBackendAsCanvas,7,1) == menclose-5-updiagonalstrike.html menclose-5-updiagonalstrike-ref.html
 == menclose-5-verticalstrike.html menclose-5-verticalstrike-ref.html
 == menclose-5-phasorangle.html menclose-5-phasorangle-ref.html
 == menclose-6-actuarial.html menclose-6-ref.html
 == menclose-6-bottom.html menclose-6-ref.html
 == menclose-6-box.html menclose-6-ref.html
 == menclose-6-circle.html menclose-6-ref.html
-== menclose-6-downdiagonalstrike.html menclose-6-ref.html
+fuzzy-if(d2d&&!contentSameGfxBackendAsCanvas,7,1) == menclose-6-downdiagonalstrike.html menclose-6-ref.html
 == menclose-6-horizontalstrike.html menclose-6-ref.html
 == menclose-6-left.html menclose-6-ref.html
 == menclose-6-longdiv.html menclose-6-ref.html
 == menclose-6-madruwb.html menclose-6-ref.html
 == menclose-6-radical.html menclose-6-ref.html
 == menclose-6-right.html menclose-6-ref.html
 == menclose-6-roundedbox.html menclose-6-ref.html
 == menclose-6-top.html menclose-6-ref.html
 == menclose-6-updiagonalarrow.html menclose-6-ref.html
-== menclose-6-updiagonalstrike.html menclose-6-ref.html
+fuzzy-if(d2d&&!contentSameGfxBackendAsCanvas,7,1) == menclose-6-updiagonalstrike.html menclose-6-ref.html
 == menclose-6-verticalstrike.html menclose-6-ref.html
 == menclose-6-phasorangle.html menclose-6-ref.html
 == mmultiscript-align.html mmultiscript-align-ref.html
 fails-if(winWidget&&!/^Windows\x20NT\x205\.1/.test(http.oscpu)) == subscript-italic-correction.html subscript-italic-correction-ref.html # Windows versions with Cambria Math, bug 961482
 fails-if(B2G||Android||/^Windows\x20NT\x205\.1/.test(http.oscpu)||OSX==10.6) == mathvariant-1a.html mathvariant-1a-ref.html # Bug 1010679
 fails-if(B2G||Android||/^Windows\x20NT\x205\.1/.test(http.oscpu)||OSX==10.6) == mathvariant-1b.html mathvariant-1b-ref.html # Bug 1010679
 fails-if(B2G||Android||/^Windows\x20NT\x205\.1/.test(http.oscpu)||OSX==10.6) == mathvariant-1c.html mathvariant-1c-ref.html # Bug 1010679
 == mathvariant-1d.html mathvariant-1d-ref.html