Bug 1083533 - Port the code that uses nsRenderingContext::SetClip() to Moz2D. r=mattwoodrow
authorJonathan Watt <jwatt@jwatt.org>
Fri, 17 Oct 2014 12:53:16 +0100
changeset 211027 1d96887e4712ae6ce6d1e5eb5b2cb7ec45842750
parent 211026 f7f5057765f9deb55a635bb85a0be8a4d2495a90
child 211028 197317c196cf68d98b83349027b20afbffe869a3
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersmattwoodrow
bugs1083533
milestone36.0a1
Bug 1083533 - Port the code that uses nsRenderingContext::SetClip() to Moz2D. r=mattwoodrow
gfx/src/nsRenderingContext.cpp
gfx/src/nsRenderingContext.h
layout/base/nsPresShell.cpp
--- a/gfx/src/nsRenderingContext.cpp
+++ b/gfx/src/nsRenderingContext.cpp
@@ -98,41 +98,16 @@ nsRenderingContext::IntersectClip(const 
     } else {
         mThebes->Rectangle(clipRect);
     }
 
     mThebes->Clip();
 }
 
 void
-nsRenderingContext::SetClip(const nsIntRegion& aRegion)
-{
-    // Region is in device coords, no transformation.  This should
-    // only be called when there is no transform in place, when we we
-    // just start painting a widget. The region is set by the platform
-    // paint routine.  Therefore, there is no option to intersect with
-    // an existing clip.
-
-    gfxMatrix mat = mThebes->CurrentMatrix();
-    mThebes->SetMatrix(gfxMatrix());
-
-    mThebes->ResetClip();
-
-    mThebes->NewPath();
-    nsIntRegionRectIterator iter(aRegion);
-    const nsIntRect* rect;
-    while ((rect = iter.Next())) {
-        mThebes->Rectangle(gfxRect(rect->x, rect->y, rect->width, rect->height),
-                           true);
-    }
-    mThebes->Clip();
-    mThebes->SetMatrix(mat);
-}
-
-void
 nsRenderingContext::SetColor(nscolor aColor)
 {
     /* This sets the color assuming the sRGB color space, since that's
      * what all CSS colors are defined to be in by the spec.
      */
     mThebes->SetColor(gfxRGBA(aColor));
 }
 
--- a/gfx/src/nsRenderingContext.h
+++ b/gfx/src/nsRenderingContext.h
@@ -40,17 +40,16 @@ public:
     // These accessors will never return null.
     gfxContext *ThebesContext() { return mThebes; }
     DrawTarget *GetDrawTarget() { return mThebes->GetDrawTarget(); }
     nsDeviceContext *DeviceContext() { return mDeviceContext; }
 
     // Graphics state
 
     void IntersectClip(const nsRect& aRect);
-    void SetClip(const nsIntRegion& aRegion);
     void SetColor(nscolor aColor);
 
     // Shapes
 
     void DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt);
     void DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
     void DrawRect(const nsRect& aRect);
     void DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -5109,26 +5109,31 @@ PresShell::PaintRangePaintInfo(nsTArray<
    gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget(
                                  IntSize(pixelArea.width, pixelArea.height),
                                  SurfaceFormat::B8G8R8A8);
   if (!dt) {
     return nullptr;
   }
 
   nsRefPtr<gfxContext> ctx = new gfxContext(dt);
-  nsRefPtr<nsRenderingContext> rc = new nsRenderingContext();
-  rc->Init(deviceContext, ctx);
 
   if (aRegion) {
     // Convert aRegion from CSS pixels to dev pixels
     nsIntRegion region =
       aRegion->ToAppUnits(nsPresContext::AppUnitsPerCSSPixel())
         .ToOutsidePixels(pc->AppUnitsPerDevPixel());
-    rc->SetClip(region);
-  }
+    nsIntRegionRectIterator iter(region);
+    const nsIntRect* rect;
+    while ((rect = iter.Next())) {
+      ctx->Clip(gfxRect(rect->x, rect->y, rect->width, rect->height));
+    }
+  }
+
+  nsRefPtr<nsRenderingContext> rc = new nsRenderingContext();
+  rc->Init(deviceContext, ctx);
 
   gfxMatrix initialTM = ctx->CurrentMatrix();
 
   if (resize)
     initialTM.Scale(scale, scale);
 
   // translate so that points are relative to the surface area
   gfxPoint surfaceOffset =