Bug 1019681 - Remove gfxASurface's MovePixels() and FastMovePixels() methods and their overrides. r=Bas
authorJonathan Watt <jwatt@jwatt.org>
Thu, 05 Jun 2014 01:03:07 +0100
changeset 207113 b46b90e776ec11f2ec1afd625fcff945a792a328
parent 207112 849d75bfa0f863e95aa0cc4b8bd16f0aafc0bb89
child 207114 2d9924eaa36c8b47bebb25d7932fa97773825c6f
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs1019681
milestone32.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 1019681 - Remove gfxASurface's MovePixels() and FastMovePixels() methods and their overrides. r=Bas
gfx/thebes/gfxASurface.cpp
gfx/thebes/gfxASurface.h
gfx/thebes/gfxD2DSurface.h
gfx/thebes/gfxImageSurface.cpp
gfx/thebes/gfxImageSurface.h
gfx/thebes/gfxQuartzSurface.h
gfx/thebes/gfxWindowsSurface.h
--- a/gfx/thebes/gfxASurface.cpp
+++ b/gfx/thebes/gfxASurface.cpp
@@ -520,62 +520,16 @@ gfxASurface::BytePerPixelFromFormat(gfxI
         case gfxImageFormat::A8:
             return 1;
         default:
             NS_WARNING("Unknown byte per pixel value for Image format");
     }
     return 0;
 }
 
-void
-gfxASurface::FastMovePixels(const nsIntRect& aSourceRect,
-                            const nsIntPoint& aDestTopLeft)
-{
-    // Used when the backend can internally handle self copies.
-    nsIntRect dest(aDestTopLeft, aSourceRect.Size());
-    
-    nsRefPtr<gfxContext> ctx = new gfxContext(this);
-    ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
-    nsIntPoint srcOrigin = dest.TopLeft() - aSourceRect.TopLeft();
-    ctx->SetSource(this, gfxPoint(srcOrigin.x, srcOrigin.y));
-    ctx->Rectangle(gfxRect(dest.x, dest.y, dest.width, dest.height));
-    ctx->Fill();
-}
-
-void
-gfxASurface::MovePixels(const nsIntRect& aSourceRect,
-                        const nsIntPoint& aDestTopLeft)
-{
-    // Assume the backend can't handle self copying well and allocate
-    // a temporary surface instead.
-    nsRefPtr<gfxASurface> tmp = 
-      CreateSimilarSurface(GetContentType(), 
-                           nsIntSize(aSourceRect.width, aSourceRect.height));
-    // CreateSimilarSurface can return nullptr if the current surface is
-    // in an error state. This isn't good, but its better to carry
-    // on with the error surface instead of crashing.
-    NS_WARN_IF_FALSE(tmp, "Must have temporary surface to move pixels!");
-    if (!tmp) {
-        return;
-    }
-    nsRefPtr<gfxContext> ctx = new gfxContext(tmp);
-    ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
-    ctx->SetSource(this, gfxPoint(-aSourceRect.x, -aSourceRect.y));
-    ctx->Paint();
-
-    ctx = new gfxContext(this);
-    ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
-    ctx->SetSource(tmp, gfxPoint(aDestTopLeft.x, aDestTopLeft.y));
-    ctx->Rectangle(gfxRect(aDestTopLeft.x, 
-                           aDestTopLeft.y, 
-                           aSourceRect.width, 
-                           aSourceRect.height));
-    ctx->Fill();
-}
-
 /** Memory reporting **/
 
 static const char *sDefaultSurfaceDescription =
     "Memory used by gfx surface of the given type.";
 
 struct SurfaceMemoryReporterAttrs {
   const char *path;
   const char *description;
--- a/gfx/thebes/gfxASurface.h
+++ b/gfx/thebes/gfxASurface.h
@@ -205,50 +205,29 @@ public:
 
     const gfxRect& GetOpaqueRect() {
         if (!!mOpaqueRect)
             return *mOpaqueRect;
         return GetEmptyOpaqueRect();
     }
 
     /**
-     * Move the pixels in |aSourceRect| to |aDestTopLeft|.  Like with
-     * memmove(), |aSourceRect| and the rectangle defined by
-     * |aDestTopLeft| are allowed to overlap, and the effect is
-     * equivalent to copying |aSourceRect| to a scratch surface and
-     * then back to |aDestTopLeft|.
-     *
-     * |aSourceRect| and the destination rectangle defined by
-     * |aDestTopLeft| are clipped to this surface's bounds.
-     */
-    virtual void MovePixels(const nsIntRect& aSourceRect,
-                            const nsIntPoint& aDestTopLeft);
-
-    /**
      * Mark the surface as being allowed/not allowed to be used as a source.
      */
     void SetAllowUseAsSource(bool aAllow) { mAllowUseAsSource = aAllow; }
     bool GetAllowUseAsSource() { return mAllowUseAsSource; }
 
     static uint8_t BytesPerPixel(gfxImageFormat aImageFormat);
 
 protected:
     gfxASurface();
 
     static gfxASurface* GetSurfaceWrapper(cairo_surface_t *csurf);
     static void SetSurfaceWrapper(cairo_surface_t *csurf, gfxASurface *asurf);
 
-    /**
-     * An implementation of MovePixels that assumes the backend can
-     * internally handle this operation and doesn't allocate any
-     * temporary surfaces.
-     */
-    void FastMovePixels(const nsIntRect& aSourceRect,
-                        const nsIntPoint& aDestTopLeft);
-
     // NB: Init() *must* be called from within subclass's
     // constructors.  It's unsafe to call it after the ctor finishes;
     // leaks and use-after-frees are possible.
     void Init(cairo_surface_t *surface, bool existingSurface = false);
 
     // out-of-line helper to allow GetOpaqueRect() to be inlined
     // without including gfxRect.h here
     static const gfxRect& GetEmptyOpaqueRect();
--- a/gfx/thebes/gfxD2DSurface.h
+++ b/gfx/thebes/gfxD2DSurface.h
@@ -24,22 +24,16 @@ public:
                   gfxImageFormat imageFormat = gfxImageFormat::RGB24);
 
     gfxD2DSurface(HANDLE handle, gfxContentType aContent);
 
     gfxD2DSurface(ID3D10Texture2D *texture, gfxContentType aContent);
 
     gfxD2DSurface(cairo_surface_t *csurf);
 
-    void MovePixels(const nsIntRect& aSourceRect,
-                    const nsIntPoint& aDestTopLeft)
-    {
-        FastMovePixels(aSourceRect, aDestTopLeft);
-    }
-
     virtual ~gfxD2DSurface();
 
     void Present();
     void Scroll(const nsIntPoint &aDelta, const nsIntRect &aClip);
 
     virtual const gfxIntSize GetSize() const;
 
     ID3D10Texture2D *GetTexture();
--- a/gfx/thebes/gfxImageSurface.cpp
+++ b/gfx/thebes/gfxImageSurface.cpp
@@ -366,75 +366,8 @@ gfxSubimageSurface::gfxSubimageSurface(g
 }
 
 already_AddRefed<gfxImageSurface>
 gfxImageSurface::GetAsImageSurface()
 {
   nsRefPtr<gfxImageSurface> surface = this;
   return surface.forget();
 }
-
-void
-gfxImageSurface::MovePixels(const nsIntRect& aSourceRect,
-                            const nsIntPoint& aDestTopLeft)
-{
-    const nsIntRect bounds(0, 0, mSize.width, mSize.height);
-    nsIntPoint offset = aDestTopLeft - aSourceRect.TopLeft(); 
-    nsIntRect clippedSource = aSourceRect;
-    clippedSource.IntersectRect(clippedSource, bounds);
-    nsIntRect clippedDest = clippedSource + offset;
-    clippedDest.IntersectRect(clippedDest, bounds);
-    const nsIntRect dest = clippedDest;
-    const nsIntRect source = dest - offset;
-    // NB: this relies on IntersectRect() and operator+/- preserving
-    // x/y for empty rectangles
-    NS_ABORT_IF_FALSE(bounds.Contains(dest) && bounds.Contains(source) &&
-                      aSourceRect.Contains(source) &&
-                      nsIntRect(aDestTopLeft, aSourceRect.Size()).Contains(dest) &&
-                      source.Size() == dest.Size() &&
-                      offset == (dest.TopLeft() - source.TopLeft()),
-                      "Messed up clipping, crash or corruption will follow");
-    if (source.IsEmpty() || source.IsEqualInterior(dest)) {
-        return;
-    }
-
-    long naturalStride = ComputeStride(mSize, mFormat);
-    if (mStride == naturalStride && dest.width == bounds.width) {
-        // Fast path: this is a vertical shift of some rows in a
-        // "normal" image surface.  We can directly memmove and
-        // hopefully stay in SIMD land.
-        unsigned char* dst = mData + dest.y * mStride;
-        const unsigned char* src = mData + source.y * mStride;
-        size_t nBytes = dest.height * mStride;
-        memmove(dst, src, nBytes);
-        return;
-    }
-
-    // Slow(er) path: have to move row-by-row.
-    const int32_t bpp = BytePerPixelFromFormat(mFormat);
-    const size_t nRowBytes = dest.width * bpp;
-    // dstRow points at the first pixel within the current destination
-    // row, and similarly for srcRow.  endSrcRow is one row beyond the
-    // last row we need to copy.  stride is either +mStride or
-    // -mStride, depending on which direction we're copying.
-    unsigned char* dstRow;
-    unsigned char* srcRow;
-    unsigned char* endSrcRow;   // NB: this may point outside the image
-    long stride;
-    if (dest.y > source.y) {
-        // We're copying down from source to dest, so walk backwards
-        // starting from the last rows to avoid stomping pixels we
-        // need.
-        stride = -mStride;
-        dstRow = mData + dest.x * bpp + (dest.YMost() - 1) * mStride;
-        srcRow = mData + source.x * bpp + (source.YMost() - 1) * mStride;
-        endSrcRow = mData + source.x * bpp + (source.y - 1) * mStride;
-    } else {
-        stride = mStride;
-        dstRow = mData + dest.x * bpp + dest.y * mStride;
-        srcRow = mData + source.x * bpp + source.y * mStride;
-        endSrcRow = mData + source.x * bpp + source.YMost() * mStride;
-    }
-
-    for (; srcRow != endSrcRow; dstRow += stride, srcRow += stride) {
-        memmove(dstRow, srcRow, nRowBytes);
-    }
-}
--- a/gfx/thebes/gfxImageSurface.h
+++ b/gfx/thebes/gfxImageSurface.h
@@ -119,19 +119,16 @@ public:
     /* return new Subimage with pointing to original image starting from aRect.pos
      * and size of aRect.size. New subimage keeping current image reference
      */
     already_AddRefed<gfxSubimageSurface> GetSubimage(const gfxRect& aRect);
 
     virtual already_AddRefed<gfxImageSurface> GetAsImageSurface();
 
     /** See gfxASurface.h. */
-    virtual void MovePixels(const nsIntRect& aSourceRect,
-                            const nsIntPoint& aDestTopLeft) MOZ_OVERRIDE;
-
     static long ComputeStride(const gfxIntSize&, gfxImageFormat);
 
     virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
         MOZ_OVERRIDE;
     virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
         MOZ_OVERRIDE;
     virtual bool SizeOfIsMeasured() const MOZ_OVERRIDE;
 
--- a/gfx/thebes/gfxQuartzSurface.h
+++ b/gfx/thebes/gfxQuartzSurface.h
@@ -34,22 +34,16 @@ public:
     CGContextRef GetCGContext() { return mCGContext; }
 
     CGContextRef GetCGContextWithClip(gfxContext *ctx);
 
     virtual int32_t GetDefaultContextFlags() const;
 
     already_AddRefed<gfxImageSurface> GetAsImageSurface();
 
-    void MovePixels(const nsIntRect& aSourceRect,
-                    const nsIntPoint& aDestTopLeft)
-    {
-        FastMovePixels(aSourceRect, aDestTopLeft);
-    }
-
 protected:
     void MakeInvalid();
 
     CGContextRef mCGContext;
     gfxSize      mSize;
     bool mForPrinting;
 };
 
--- a/gfx/thebes/gfxWindowsSurface.h
+++ b/gfx/thebes/gfxWindowsSurface.h
@@ -62,22 +62,16 @@ public:
     nsresult AbortPrinting();
     nsresult BeginPage();
     nsresult EndPage();
 
     virtual int32_t GetDefaultContextFlags() const;
 
     const gfxIntSize GetSize() const;
 
-    void MovePixels(const nsIntRect& aSourceRect,
-                    const nsIntPoint& aDestTopLeft)
-    {
-        FastMovePixels(aSourceRect, aDestTopLeft);
-    }
-
     // The memory used by this surface lives in this process's address space,
     // but not in the heap.
     virtual gfxMemoryLocation GetMemoryLocation() const;
 
 private:
     void MakeInvalid(gfxIntSize& size);
 
     bool mOwnsDC;