Bug 933019, part 7 - Remove code for handling Thebes backed gfxContext from various files under layout/. r=Bas
authorJonathan Watt <jwatt@jwatt.org>
Thu, 10 Jul 2014 10:58:07 +0100
changeset 214168 e4d559c6ebb47901f0b7ab40bb69010f3be37cf5
parent 214167 ac38dea88f944a78361f68cefce579af6c7bc0e6
child 214169 b01d4ca9800f94f8b5457855dc2d6fe0104c3b2a
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs933019
milestone33.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 933019, part 7 - Remove code for handling Thebes backed gfxContext from various files under layout/. r=Bas
layout/base/FrameLayerBuilder.cpp
layout/base/nsCSSRendering.cpp
layout/base/nsCSSRenderingBorders.cpp
layout/base/nsCSSRenderingBorders.h
layout/svg/nsSVGPaintServerFrame.cpp
--- a/layout/base/FrameLayerBuilder.cpp
+++ b/layout/base/FrameLayerBuilder.cpp
@@ -3774,17 +3774,16 @@ FrameLayerBuilder::PaintItems(nsTArray<C
 /**
  * Returns true if it is preferred to draw the list of display
  * items separately for each rect in the visible region rather
  * than clipping to a complex region.
  */
 static bool ShouldDrawRectsSeparately(gfxContext* aContext, DrawRegionClip aClip)
 {
   if (!gfxPrefs::LayoutPaintRectsSeparately() ||
-      aContext->IsCairo() ||
       aClip == DrawRegionClip::CLIP_NONE) {
     return false;
   }
 
   DrawTarget *dt = aContext->GetDrawTarget();
   return dt->GetBackendType() == BackendType::DIRECT2D;
 }
 
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -2523,44 +2523,33 @@ nsCSSRendering::PaintGradient(nsPresCont
       stops.AppendElement(ColorStop(firstStop, firstColor));
     }
     stops.AppendElement(ColorStop(firstStop, lastColor));
   }
 
   bool isRepeat = aGradient->mRepeating || forceRepeatToCoverTiles;
 
   // Now set normalized color stops in pattern.
-  if (!ctx->IsCairo()) {
-    // Offscreen gradient surface cache (not a tile):
-    // On some backends (e.g. D2D), the GradientStops object holds an offscreen surface
-    // which is a lookup table used to evaluate the gradient. This surface can use
-    // much memory (ram and/or GPU ram) and can be expensive to create. So we cache it.
-    // The cache key correlates 1:1 with the arguments for CreateGradientStops (also the implied backend type)
-    // Note that GradientStop is a simple struct with a stop value (while GradientStops has the surface).
-    nsTArray<gfx::GradientStop> rawStops(stops.Length());
-    rawStops.SetLength(stops.Length());
-    for(uint32_t i = 0; i < stops.Length(); i++) {
-      rawStops[i].color = gfx::Color(stops[i].mColor.r, stops[i].mColor.g, stops[i].mColor.b, stops[i].mColor.a);
-      rawStops[i].offset = stopScale * (stops[i].mPosition - stopOrigin);
-    }
-    mozilla::RefPtr<mozilla::gfx::GradientStops> gs =
-      gfxGradientCache::GetOrCreateGradientStops(ctx->GetDrawTarget(),
-                                                 rawStops,
-                                                 isRepeat ? gfx::ExtendMode::REPEAT : gfx::ExtendMode::CLAMP);
-    gradientPattern->SetColorStops(gs);
-  } else {
-    for (uint32_t i = 0; i < stops.Length(); i++) {
-      double pos = stopScale*(stops[i].mPosition - stopOrigin);
-      gradientPattern->AddColorStop(pos, stops[i].mColor);
-    }
-    // Set repeat mode. Default cairo extend mode is PAD.
-    if (isRepeat) {
-      gradientPattern->SetExtend(gfxPattern::EXTEND_REPEAT);
-    }
+  // Offscreen gradient surface cache (not a tile):
+  // On some backends (e.g. D2D), the GradientStops object holds an offscreen surface
+  // which is a lookup table used to evaluate the gradient. This surface can use
+  // much memory (ram and/or GPU ram) and can be expensive to create. So we cache it.
+  // The cache key correlates 1:1 with the arguments for CreateGradientStops (also the implied backend type)
+  // Note that GradientStop is a simple struct with a stop value (while GradientStops has the surface).
+  nsTArray<gfx::GradientStop> rawStops(stops.Length());
+  rawStops.SetLength(stops.Length());
+  for(uint32_t i = 0; i < stops.Length(); i++) {
+    rawStops[i].color = gfx::Color(stops[i].mColor.r, stops[i].mColor.g, stops[i].mColor.b, stops[i].mColor.a);
+    rawStops[i].offset = stopScale * (stops[i].mPosition - stopOrigin);
   }
+  mozilla::RefPtr<mozilla::gfx::GradientStops> gs =
+    gfxGradientCache::GetOrCreateGradientStops(ctx->GetDrawTarget(),
+                                               rawStops,
+                                               isRepeat ? gfx::ExtendMode::REPEAT : gfx::ExtendMode::CLAMP);
+  gradientPattern->SetColorStops(gs);
 
   // Paint gradient tiles. This isn't terribly efficient, but doing it this
   // way is simple and sure to get pixel-snapping right. We could speed things
   // up by drawing tiles into temporary surfaces and copying those to the
   // destination, but after pixel-snapping tiles may not all be the same size.
   nsRect dirty;
   if (!dirty.IntersectRect(aDirtyRect, aFillArea))
     return;
--- a/layout/base/nsCSSRenderingBorders.cpp
+++ b/layout/base/nsCSSRenderingBorders.cpp
@@ -1063,31 +1063,19 @@ nsCSSBorderRenderer::CreateCornerGradien
     mBorderWidths[cornerHeight[aCorner]] * gradientCoeff[aCorner].a;
   pat1.y = cornerOrigin.y +
     mBorderWidths[cornerWidth[aCorner]]  * gradientCoeff[aCorner].b;
   pat2.x = cornerOrigin.x -
     mBorderWidths[cornerHeight[aCorner]] * gradientCoeff[aCorner].a;
   pat2.y = cornerOrigin.y -
     mBorderWidths[cornerWidth[aCorner]]  * gradientCoeff[aCorner].b;
 
-  float gradientOffset;
-  
-  if (mContext->IsCairo() &&
-      (mContext->OriginalSurface()->GetType() == gfxSurfaceType::D2D ||
-       mContext->OriginalSurface()->GetType() == gfxSurfaceType::Quartz))
-  {
-    // On quarz this doesn't do exactly the right thing, but it does do what
-    // most other browsers do and doing the 'right' thing seems to be
-    // hard with the quartz cairo backend.
-    gradientOffset = 0;
-  } else {
-    // When cairo/Azure does the gradient drawing this gives us pretty nice behavior!
-    gradientOffset = 0.25 / sqrt(pow(mBorderWidths[cornerHeight[aCorner]], 2) +
-                                 pow(mBorderWidths[cornerHeight[aCorner]], 2));
-  }
+  float gradientOffset =
+    0.25 / sqrt(pow(mBorderWidths[cornerHeight[aCorner]], 2) +
+                pow(mBorderWidths[cornerHeight[aCorner]], 2));
 
   nsRefPtr<gfxPattern> pattern = new gfxPattern(pat1.x, pat1.y, pat2.x, pat2.y);
   pattern->AddColorStop(0.5 - gradientOffset, gfxRGBA(aFirstColor));
   pattern->AddColorStop(0.5 + gradientOffset, gfxRGBA(aSecondColor));
 
   return pattern.forget();
 }
 
@@ -1184,164 +1172,16 @@ nsCSSBorderRenderer::DrawSingleWidthSoli
     mContext->LineTo(secondCorner);
     mContext->Stroke();
   }
 }
 
 void
 nsCSSBorderRenderer::DrawNoCompositeColorSolidBorder()
 {
-  const gfxFloat alpha = 0.55191497064665766025;
-
-  const twoFloats cornerMults[4] = { { -1,  0 },
-                                      {  0, -1 },
-                                      { +1,  0 },
-                                      {  0, +1 } };
-
-  const twoFloats centerAdjusts[4] = { { 0, +0.5 },
-                                        { -0.5, 0 },
-                                        { 0, -0.5 },
-                                        { +0.5, 0 } };
-
-  gfxPoint pc, pci, p0, p1, p2, p3, pd, p3i;
-
-  gfxCornerSizes innerRadii;
-  ComputeInnerRadii(mBorderRadii, mBorderWidths, &innerRadii);
-
-  gfxRect strokeRect = mOuterRect;
-  strokeRect.Deflate(gfxMargin(mBorderWidths[0] / 2.0, mBorderWidths[1] / 2.0,
-                               mBorderWidths[2] / 2.0, mBorderWidths[3] / 2.0));
-
-  NS_FOR_CSS_CORNERS(i) {
-      // the corner index -- either 1 2 3 0 (cw) or 0 3 2 1 (ccw)
-    mozilla::css::Corner c = mozilla::css::Corner((i+1) % 4);
-    mozilla::css::Corner prevCorner = mozilla::css::Corner(i);
-
-    // i+2 and i+3 respectively.  These are used to index into the corner
-    // multiplier table, and were deduced by calculating out the long form
-    // of each corner and finding a pattern in the signs and values.
-    int i1 = (i+1) % 4;
-    int i2 = (i+2) % 4;
-    int i3 = (i+3) % 4;
-
-    pc = mOuterRect.AtCorner(c);
-    pci = mInnerRect.AtCorner(c);
-    mContext->SetLineWidth(mBorderWidths[i]);
-
-    nscolor firstColor, secondColor;
-    if (IsVisible(mBorderStyles[i]) && IsVisible(mBorderStyles[i1])) {
-      firstColor = mBorderColors[i];
-      secondColor = mBorderColors[i1];
-    } else if (IsVisible(mBorderStyles[i])) {
-      firstColor = mBorderColors[i];
-      secondColor = mBorderColors[i];
-    } else {
-      firstColor = mBorderColors[i1];
-      secondColor = mBorderColors[i1];
-    }
-
-    mContext->NewPath();
-
-    gfxPoint strokeStart, strokeEnd;
-
-    strokeStart.x = mOuterRect.AtCorner(prevCorner).x +
-      mBorderCornerDimensions[prevCorner].width * cornerMults[i2].a;
-    strokeStart.y = mOuterRect.AtCorner(prevCorner).y +
-      mBorderCornerDimensions[prevCorner].height * cornerMults[i2].b;
-
-    strokeEnd.x = pc.x + mBorderCornerDimensions[c].width * cornerMults[i].a;
-    strokeEnd.y = pc.y + mBorderCornerDimensions[c].height * cornerMults[i].b;
-
-    strokeStart.x += centerAdjusts[i].a * mBorderWidths[i];
-    strokeStart.y += centerAdjusts[i].b * mBorderWidths[i];
-    strokeEnd.x += centerAdjusts[i].a * mBorderWidths[i];
-    strokeEnd.y += centerAdjusts[i].b * mBorderWidths[i];
-
-    mContext->MoveTo(strokeStart);
-    mContext->LineTo(strokeEnd);
-    mContext->SetColor(gfxRGBA(mBorderColors[i]));
-    mContext->Stroke();
-
-    if (firstColor != secondColor) {
-      nsRefPtr<gfxPattern> pattern =
-        CreateCornerGradient(c, firstColor, secondColor);
-      mContext->SetPattern(pattern);
-    } else {
-      mContext->SetColor(firstColor);
-    }     
-    
-    if (mBorderRadii[c].width > 0 && mBorderRadii[c].height > 0) {
-      p0.x = pc.x + cornerMults[i].a * mBorderRadii[c].width;
-      p0.y = pc.y + cornerMults[i].b * mBorderRadii[c].height;
-
-      p3.x = pc.x + cornerMults[i3].a * mBorderRadii[c].width;
-      p3.y = pc.y + cornerMults[i3].b * mBorderRadii[c].height;
-
-      p1.x = p0.x + alpha * cornerMults[i2].a * mBorderRadii[c].width;
-      p1.y = p0.y + alpha * cornerMults[i2].b * mBorderRadii[c].height;
-
-      p2.x = p3.x - alpha * cornerMults[i3].a * mBorderRadii[c].width;
-      p2.y = p3.y - alpha * cornerMults[i3].b * mBorderRadii[c].height;
-
-      mContext->NewPath();
-            
-      gfxPoint cornerStart;
-      cornerStart.x = pc.x + cornerMults[i].a * mBorderCornerDimensions[c].width;
-      cornerStart.y = pc.y + cornerMults[i].b * mBorderCornerDimensions[c].height;
-
-      mContext->MoveTo(cornerStart);
-      mContext->LineTo(p0);
-
-      mContext->CurveTo(p1, p2, p3);
-            
-      gfxPoint outerCornerEnd;
-      outerCornerEnd.x = pc.x + cornerMults[i3].a * mBorderCornerDimensions[c].width;
-      outerCornerEnd.y = pc.y + cornerMults[i3].b * mBorderCornerDimensions[c].height;
-
-      mContext->LineTo(outerCornerEnd);
-
-      p0.x = pci.x + cornerMults[i].a * innerRadii[c].width;
-      p0.y = pci.y + cornerMults[i].b * innerRadii[c].height;
-
-      p3i.x = pci.x + cornerMults[i3].a * innerRadii[c].width;
-      p3i.y = pci.y + cornerMults[i3].b * innerRadii[c].height;
-
-      p1.x = p0.x + alpha * cornerMults[i2].a * innerRadii[c].width;
-      p1.y = p0.y + alpha * cornerMults[i2].b * innerRadii[c].height;
-
-      p2.x = p3i.x - alpha * cornerMults[i3].a * innerRadii[c].width;
-      p2.y = p3i.y - alpha * cornerMults[i3].b * innerRadii[c].height;
-      mContext->LineTo(p3i);
-      mContext->CurveTo(p2, p1, p0);
-      mContext->ClosePath();
-      mContext->Fill();
-    } else {
-      gfxPoint c1, c2, c3, c4;
-
-      c1.x = pc.x + cornerMults[i].a * mBorderCornerDimensions[c].width;
-      c1.y = pc.y + cornerMults[i].b * mBorderCornerDimensions[c].height;
-      c2 = pc;
-      c3.x = pc.x + cornerMults[i3].a * mBorderCornerDimensions[c].width;
-      c3.y = pc.y + cornerMults[i3].b * mBorderCornerDimensions[c].height;
-
-      mContext->NewPath();
-      mContext->MoveTo(c1);
-      mContext->LineTo(c2);
-      mContext->LineTo(c3);
-      mContext->LineTo(pci);
-      mContext->ClosePath();
-
-      mContext->Fill();
-    }
-  }
-}
-
-void
-nsCSSBorderRenderer::DrawNoCompositeColorSolidBorderAzure()
-{
   DrawTarget *dt = mContext->GetDrawTarget();
 
   const gfxFloat alpha = 0.55191497064665766025;
 
   const twoFloats cornerMults[4] = { { -1,  0 },
                                      {  0, -1 },
                                      { +1,  0 },
                                      {  0, +1 } };
@@ -1709,21 +1549,17 @@ nsCSSBorderRenderer::DrawBorders()
   {
     DrawSingleWidthSolidBorder();
     return;
   }
 
   if (allBordersSolid && !hasCompositeColors &&
       !mAvoidStroke)
   {
-    if (mContext->IsCairo()) {
-      DrawNoCompositeColorSolidBorder();
-    } else {
-      DrawNoCompositeColorSolidBorderAzure();
-    }
+    DrawNoCompositeColorSolidBorder();
     return;
   }
 
   if (allBordersSolid &&
       allBordersSameWidth &&
       mNoBorderRadius &&
       !mAvoidStroke)
   {
--- a/layout/base/nsCSSRenderingBorders.h
+++ b/layout/base/nsCSSRenderingBorders.h
@@ -198,19 +198,16 @@ struct nsCSSBorderRenderer {
                        mozilla::gfx::Point &aPoint1, mozilla::gfx::Point &aPoint2);
 
   // Draw a solid color border that is uniformly the same width.
   void DrawSingleWidthSolidBorder();
 
   // Draw any border which is solid on all sides and does not use
   // CompositeColors.
   void DrawNoCompositeColorSolidBorder();
-  // Draw any border which is solid on all sides and does not use
-  // CompositeColors. Using Azure.
-  void DrawNoCompositeColorSolidBorderAzure();
 
   // Draw a solid border that has no border radius (i.e. is rectangular) and
   // uses CompositeColors.
   void DrawRectangularCompositeColors();
 
   // draw the entire border
   void DrawBorders ();
 
--- a/layout/svg/nsSVGPaintServerFrame.cpp
+++ b/layout/svg/nsSVGPaintServerFrame.cpp
@@ -19,15 +19,13 @@ nsSVGPaintServerFrame::SetupPaintServer(
                                         float aOpacity)
 {
   nsRefPtr<gfxPattern> pattern =
     GetPaintServerPattern(aSource, aContext->CurrentMatrix(), aFillOrStroke,
                           aOpacity);
   if (!pattern)
     return false;
 
-  if (!aContext->IsCairo()) {
-    pattern->CacheColorStops(aContext->GetDrawTarget());
-  }
+  pattern->CacheColorStops(aContext->GetDrawTarget());
 
   aContext->SetPattern(pattern);
   return true;
 }