Bug 989858 - Part 6: Rename DeprecatedPaint and stop passing a gfxContext in. r=roc
authorMatt Woodrow <mwoodrow@mozilla.com>
Tue, 01 Apr 2014 12:02:10 +0800
changeset 176458 f94c69dfca918100c56efdd0ccc8e82c3e8ff80b
parent 176457 ad933a27ebb51643104a7a103e8be5b0dd54e340
child 176459 f9d6b3557b322d3cfeb1b55f6832ef686d0690e1
push id26524
push userryanvm@gmail.com
push dateTue, 01 Apr 2014 20:44:18 +0000
treeherdermozilla-central@0ff6afce0133 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs989858
milestone31.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 989858 - Part 6: Rename DeprecatedPaint and stop passing a gfxContext in. r=roc
gfx/2d/BasePoint.h
gfx/2d/PathHelpers.h
gfx/layers/basic/BasicCanvasLayer.cpp
gfx/layers/basic/BasicCanvasLayer.h
gfx/layers/basic/BasicColorLayer.cpp
gfx/layers/basic/BasicImageLayer.cpp
gfx/layers/basic/BasicImplData.h
gfx/layers/basic/BasicLayerManager.cpp
gfx/thebes/gfxPoint.h
--- a/gfx/2d/BasePoint.h
+++ b/gfx/2d/BasePoint.h
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_BASEPOINT_H_
 #define MOZILLA_GFX_BASEPOINT_H_
 
+#include <cmath>
 #include "mozilla/Attributes.h"
 
 namespace mozilla {
 namespace gfx {
 
 /**
  * Do not use this class directly. Subclass it, pass that subclass as the
  * Sub parameter, and only use that subclass. This allows methods to safely
@@ -59,14 +60,24 @@ struct BasePoint {
   }
   Sub operator/(T aScale) const {
     return Sub(x / aScale, y / aScale);
   }
 
   Sub operator-() const {
     return Sub(-x, -y);
   }
+
+  // Round() is *not* rounding to nearest integer if the values are negative.
+  // They are always rounding as floor(n + 0.5).
+  // See https://bugzilla.mozilla.org/show_bug.cgi?id=410748#c14
+  Sub& Round() {
+    x = static_cast<T>(floor(x + 0.5));
+    y = static_cast<T>(floor(y + 0.5));
+    return *static_cast<Sub*>(this);
+  }
+
 };
 
 }
 }
 
 #endif /* MOZILLA_GFX_BASEPOINT_H_ */
--- a/gfx/2d/PathHelpers.h
+++ b/gfx/2d/PathHelpers.h
@@ -106,12 +106,38 @@ GFX2D_API void AppendRoundedRectToPath(P
  *
  * The ellipse extends aDimensions.width / 2.0 in the horizontal direction
  * from aCenter, and aDimensions.height / 2.0 in the vertical direction.
  */
 GFX2D_API void AppendEllipseToPath(PathBuilder* aPathBuilder,
                                    const Point& aCenter,
                                    const Size& aDimensions);
 
+static inline bool
+UserToDevicePixelSnapped(Rect& aRect, const Matrix& aTransform)
+{
+  Point p1 = aTransform * aRect.TopLeft();
+  Point p2 = aTransform * aRect.TopRight();
+  Point p3 = aTransform * aRect.BottomRight();
+
+  // Check that the rectangle is axis-aligned. For an axis-aligned rectangle,
+  // two opposite corners define the entire rectangle. So check if
+  // the axis-aligned rectangle with opposite corners p1 and p3
+  // define an axis-aligned rectangle whose other corners are p2 and p4.
+  // We actually only need to check one of p2 and p4, since an affine
+  // transform maps parallelograms to parallelograms.
+  if (p2 == Point(p1.x, p3.y) || p2 == Point(p3.x, p1.y)) {
+      p1.Round();
+      p3.Round();
+
+      aRect.MoveTo(Point(std::min(p1.x, p3.x), std::min(p1.y, p3.y)));
+      aRect.SizeTo(Size(std::max(p1.x, p3.x) - aRect.X(),
+                        std::max(p1.y, p3.y) - aRect.Y()));
+      return true;
+  }
+
+  return false;
+}
+
 } // namespace gfx
 } // namespace mozilla
 
 #endif /* MOZILLA_GFX_PATHHELPERS_H_ */
--- a/gfx/layers/basic/BasicCanvasLayer.cpp
+++ b/gfx/layers/basic/BasicCanvasLayer.cpp
@@ -16,40 +16,42 @@ class gfxContext;
 
 using namespace mozilla::gfx;
 using namespace mozilla::gl;
 
 namespace mozilla {
 namespace layers {
 
 void
-BasicCanvasLayer::DeprecatedPaint(gfxContext* aContext, Layer* aMaskLayer)
+BasicCanvasLayer::Paint(DrawTarget* aDT, Layer* aMaskLayer)
 {
   if (IsHidden())
     return;
 
   FirePreTransactionCallback();
   UpdateTarget();
   FireDidTransactionCallback();
 
-  gfxMatrix m;
+  Matrix m;
   if (mNeedsYFlip) {
-    m = aContext->CurrentMatrix();
-    aContext->Translate(gfxPoint(0.0, mBounds.height));
-    aContext->Scale(1.0, -1.0);
+    m = aDT->GetTransform();
+    Matrix newTransform = m;
+    newTransform.Translate(0.0f, mBounds.height);
+    newTransform.Scale(1.0f, -1.0f);
+    aDT->SetTransform(newTransform);
   }
 
-  FillRectWithMask(aContext->GetDrawTarget(),
+  FillRectWithMask(aDT,
                    Rect(0, 0, mBounds.width, mBounds.height),
                    mSurface, ToFilter(mFilter),
                    DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)),
                    aMaskLayer);
 
   if (mNeedsYFlip) {
-    aContext->SetMatrix(m);
+    aDT->SetTransform(m);
   }
 }
 
 already_AddRefed<CanvasLayer>
 BasicLayerManager::CreateCanvasLayer()
 {
   NS_ASSERTION(InConstruction(), "Only allowed in construction phase");
   nsRefPtr<CanvasLayer> layer = new BasicCanvasLayer(this);
--- a/gfx/layers/basic/BasicCanvasLayer.h
+++ b/gfx/layers/basic/BasicCanvasLayer.h
@@ -29,17 +29,17 @@ public:
   
   virtual void SetVisibleRegion(const nsIntRegion& aRegion)
   {
     NS_ASSERTION(BasicManager()->InConstruction(),
                  "Can only set properties in construction phase");
     CanvasLayer::SetVisibleRegion(aRegion);
   }
   
-  virtual void DeprecatedPaint(gfxContext* aContext, Layer* aMaskLayer) MOZ_OVERRIDE;
+  virtual void Paint(gfx::DrawTarget* aDT, Layer* aMaskLayer) MOZ_OVERRIDE;
  
 protected:
   BasicLayerManager* BasicManager()
   {
     return static_cast<BasicLayerManager*>(mManager);
   }
 };
 
--- a/gfx/layers/basic/BasicColorLayer.cpp
+++ b/gfx/layers/basic/BasicColorLayer.cpp
@@ -12,16 +12,17 @@
 #include "gfx2DGlue.h"
 #include "mozilla/mozalloc.h"           // for operator new
 #include "nsAutoPtr.h"                  // for nsRefPtr
 #include "nsCOMPtr.h"                   // for already_AddRefed
 #include "nsDebug.h"                    // for NS_ASSERTION
 #include "nsISupportsImpl.h"            // for Layer::AddRef, etc
 #include "nsRect.h"                     // for nsIntRect
 #include "nsRegion.h"                   // for nsIntRegion
+#include "mozilla/gfx/PathHelpers.h"
 
 using namespace mozilla::gfx;
 
 namespace mozilla {
 namespace layers {
 
 class BasicColorLayer : public ColorLayer, public BasicImplData {
 public:
@@ -38,32 +39,30 @@ public:
 
   virtual void SetVisibleRegion(const nsIntRegion& aRegion)
   {
     NS_ASSERTION(BasicManager()->InConstruction(),
                  "Can only set properties in construction phase");
     ColorLayer::SetVisibleRegion(aRegion);
   }
 
-  virtual void DeprecatedPaint(gfxContext* aContext, Layer* aMaskLayer) MOZ_OVERRIDE
+  virtual void Paint(DrawTarget* aDT, Layer* aMaskLayer) MOZ_OVERRIDE
   {
     if (IsHidden()) {
       return;
     }
 
-    gfxRect snapped(mBounds.x, mBounds.y, mBounds.width, mBounds.height);
-    if (aContext->UserToDevicePixelSnapped(snapped, true)) {
-      gfxMatrix mat = aContext->CurrentMatrix();
+    Rect snapped(mBounds.x, mBounds.y, mBounds.width, mBounds.height);
+    if (UserToDevicePixelSnapped(snapped, aDT->GetTransform())) {
+      Matrix mat = aDT->GetTransform();
       mat.Invert();
       snapped = mat.TransformBounds(snapped);
     }
 
-    FillRectWithMask(aContext->GetDrawTarget(),
-                     Rect(snapped.x, snapped.y, snapped.width, snapped.height),
-                     ToColor(mColor),
+    FillRectWithMask(aDT, snapped, ToColor(mColor),
                      DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)),
                      aMaskLayer);
   }
 
 protected:
   BasicLayerManager* BasicManager()
   {
     return static_cast<BasicLayerManager*>(mManager);
--- a/gfx/layers/basic/BasicImageLayer.cpp
+++ b/gfx/layers/basic/BasicImageLayer.cpp
@@ -46,17 +46,17 @@ public:
 
   virtual void SetVisibleRegion(const nsIntRegion& aRegion)
   {
     NS_ASSERTION(BasicManager()->InConstruction(),
                  "Can only set properties in construction phase");
     ImageLayer::SetVisibleRegion(aRegion);
   }
 
-  virtual void DeprecatedPaint(gfxContext* aContext, Layer* aMaskLayer) MOZ_OVERRIDE;
+  virtual void Paint(DrawTarget* aDT, Layer* aMaskLayer) MOZ_OVERRIDE;
 
   virtual bool GetAsSurface(gfxASurface** aSurface,
                             SurfaceDescriptor* aDescriptor);
   virtual TemporaryRef<SourceSurface> GetAsSourceSurface() MOZ_OVERRIDE;
 
 protected:
   BasicLayerManager* BasicManager()
   {
@@ -68,36 +68,34 @@ protected:
   GetAndPaintCurrentImage(DrawTarget* aTarget,
                           float aOpacity,
                           SourceSurface* aMaskSurface);
 
   gfx::IntSize mSize;
 };
 
 void
-BasicImageLayer::DeprecatedPaint(gfxContext* aContext, Layer* aMaskLayer)
+BasicImageLayer::Paint(DrawTarget* aDT, Layer* aMaskLayer)
 {
   if (IsHidden() || !mContainer) {
     return;
   }
 
   mContainer->SetImageFactory(mManager->IsCompositingCheap() ? nullptr : BasicManager()->GetImageFactory());
 
   RefPtr<gfx::SourceSurface> surface;
   AutoLockImage autoLock(mContainer, &surface);
   Image *image = autoLock.GetImage();
   gfx::IntSize size = mSize = autoLock.GetSize();
 
   if (!surface || !surface->IsValid()) {
     return;
   }
 
-  FillRectWithMask(aContext->GetDrawTarget(),
-                   Rect(0, 0, size.width, size.height),
-                   surface, ToFilter(mFilter),
+  FillRectWithMask(aDT, Rect(0, 0, size.width, size.height), surface, ToFilter(mFilter),
                    DrawOptions(GetEffectiveOpacity(), GetEffectiveOperator(this)),
                    aMaskLayer);
 
   GetContainer()->NotifyPaintedImage(image);
 }
 
 void
 BasicImageLayer::GetAndPaintCurrentImage(DrawTarget* aTarget,
--- a/gfx/layers/basic/BasicImplData.h
+++ b/gfx/layers/basic/BasicImplData.h
@@ -56,17 +56,17 @@ public:
   }
 
   /**
    * Layers that paint themselves, such as ImageLayers, should paint
    * in response to this method call. aContext will already have been
    * set up to account for all the properties of the layer (transform,
    * opacity, etc).
    */
-  virtual void DeprecatedPaint(gfxContext* aContext, Layer* aMaskLayer) {}
+  virtual void Paint(gfx::DrawTarget* aDT, Layer* aMaskLayer) {}
 
   /**
    * Like Paint() but called for ThebesLayers with the additional parameters
    * they need.
    * If mClipToVisibleRegion is set, then the layer must clip to its
    * effective visible region (snapped or unsnapped, it doesn't matter).
    */
   virtual void PaintThebes(gfxContext* aContext,
--- a/gfx/layers/basic/BasicLayerManager.cpp
+++ b/gfx/layers/basic/BasicLayerManager.cpp
@@ -829,17 +829,18 @@ BasicLayerManager::PaintSelfOrChildren(P
   /* Only paint ourself, or our children - This optimization relies on this! */
   Layer* child = aPaintContext.mLayer->GetFirstChild();
   if (!child) {
     if (aPaintContext.mLayer->AsThebesLayer()) {
       data->PaintThebes(aGroupTarget, aPaintContext.mLayer->GetMaskLayer(),
           aPaintContext.mCallback, aPaintContext.mCallbackData,
           aPaintContext.mReadback);
     } else {
-      data->DeprecatedPaint(aGroupTarget, aPaintContext.mLayer->GetMaskLayer());
+      data->Paint(aGroupTarget->GetDrawTarget(),
+                  aPaintContext.mLayer->GetMaskLayer());
     }
   } else {
     ReadbackProcessor readback;
     ContainerLayer* container =
         static_cast<ContainerLayer*>(aPaintContext.mLayer);
     if (IsRetained()) {
       readback.BuildUpdates(container);
     }
--- a/gfx/thebes/gfxPoint.h
+++ b/gfx/thebes/gfxPoint.h
@@ -24,25 +24,16 @@ struct gfxSize : public mozilla::gfx::Ba
 
 struct gfxPoint : public mozilla::gfx::BasePoint<gfxFloat, gfxPoint> {
     typedef mozilla::gfx::BasePoint<gfxFloat, gfxPoint> Super;
 
     gfxPoint() : Super() {}
     gfxPoint(gfxFloat aX, gfxFloat aY) : Super(aX, aY) {}
     gfxPoint(const nsIntPoint& aPoint) : Super(aPoint.x, aPoint.y) {}
 
-    // Round() is *not* rounding to nearest integer if the values are negative.
-    // They are always rounding as floor(n + 0.5).
-    // See https://bugzilla.mozilla.org/show_bug.cgi?id=410748#c14
-    gfxPoint& Round() {
-        x = floor(x + 0.5);
-        y = floor(y + 0.5);
-        return *this;
-    }
-
     bool WithinEpsilonOf(const gfxPoint& aPoint, gfxFloat aEpsilon) {
         return fabs(aPoint.x - x) < aEpsilon && fabs(aPoint.y - y) < aEpsilon;
     }
 };
 
 inline gfxPoint
 operator*(const gfxPoint& aPoint, const gfxSize& aSize)
 {