drawBitmap* cleanup

https://codereview.chromium.org/19977003/



git-svn-id: http://skia.googlecode.com/svn/trunk@10342 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 0a4b779..d22859f 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -705,9 +705,9 @@
      *  bitmap is the "center", then the center-rect should be [2, 2, 3, 3].
      *
      *  If the dst is >= the bitmap size, then...
-     *  - The 4 corners are not stretch at all.
-     *  - The sides are stretch in only one axis.
-     *  - The center is stretch in both axes.
+     *  - The 4 corners are not stretched at all.
+     *  - The sides are stretched in only one axis.
+     *  - The center is stretched in both axes.
      * Else, for each axis where dst < bitmap,
      *  - The corners shrink proportionally
      *  - The sides (along the shrink axis) and center are not drawn
@@ -1002,10 +1002,6 @@
     // is not released or deleted by the caller.
     virtual SkCanvas* canvasForDrawIter();
 
-    // all of the drawBitmap variants call this guy
-    void commonDrawBitmap(const SkBitmap&, const SkIRect*, const SkMatrix&,
-                          const SkPaint& paint);
-
     // Clip rectangle bounds. Called internally by saveLayer.
     // returns false if the entire rectangle is entirely clipped out
     bool clipRectBounds(const SkRect* bounds, SaveFlags flags,
@@ -1067,8 +1063,7 @@
 
     // internal methods are not virtual, so they can safely be called by other
     // canvas apis, without confusing subclasses (like SkPictureRecording)
-    void internalDrawBitmap(const SkBitmap&, const SkIRect*, const SkMatrix& m,
-                                  const SkPaint* paint);
+    void internalDrawBitmap(const SkBitmap&, const SkMatrix& m, const SkPaint* paint);
     void internalDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
                                 const SkRect& dst, const SkPaint* paint);
     void internalDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index 162d882..f39e5dd 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -277,7 +277,6 @@
                           const SkMatrix* prePathMatrix = NULL,
                           bool pathIsMutable = false);
     virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
-                            const SkIRect* srcRectOrNull,
                             const SkMatrix& matrix, const SkPaint& paint);
     virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
                             int x, int y, const SkPaint& paint);
diff --git a/include/device/xps/SkXPSDevice.h b/include/device/xps/SkXPSDevice.h
index 8ed3180..dab8d1f 100644
--- a/include/device/xps/SkXPSDevice.h
+++ b/include/device/xps/SkXPSDevice.h
@@ -95,7 +95,6 @@
     virtual void drawBitmap(
         const SkDraw&,
         const SkBitmap& bitmap,
-        const SkIRect* srcRectOrNull,
         const SkMatrix& matrix,
         const SkPaint& paint) SK_OVERRIDE;
 
diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h
index b0b1559..32f8749 100644
--- a/include/gpu/SkGpuDevice.h
+++ b/include/gpu/SkGpuDevice.h
@@ -81,7 +81,6 @@
                           const SkPaint& paint, const SkMatrix* prePathMatrix,
                           bool pathIsMutable) SK_OVERRIDE;
     virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
-                            const SkIRect* srcRectOrNull,
                             const SkMatrix&, const SkPaint&) SK_OVERRIDE;
     virtual void drawBitmapRect(const SkDraw&, const SkBitmap&,
                                 const SkRect* srcOrNull, const SkRect& dst,
diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h
index 6c5e457..cb17134 100644
--- a/include/pdf/SkPDFDevice.h
+++ b/include/pdf/SkPDFDevice.h
@@ -90,7 +90,6 @@
                                 const SkRect* src, const SkRect& dst,
                                 const SkPaint& paint) SK_OVERRIDE;
     virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
-                            const SkIRect* srcRectOrNull,
                             const SkMatrix& matrix, const SkPaint&) SK_OVERRIDE;
     virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap, int x, int y,
                             const SkPaint& paint) SK_OVERRIDE;
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index e80504c..5a9a56b 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -955,7 +955,7 @@
     return  bitmap.width() <= 0 || bitmap.height() <= 0;
 }
 
-void SkCanvas::internalDrawBitmap(const SkBitmap& bitmap, const SkIRect* srcRect,
+void SkCanvas::internalDrawBitmap(const SkBitmap& bitmap,
                                 const SkMatrix& matrix, const SkPaint* paint) {
     if (reject_bitmap(bitmap)) {
         return;
@@ -965,7 +965,17 @@
     if (NULL == paint) {
         paint = lazy.init();
     }
-    this->commonDrawBitmap(bitmap, srcRect, matrix, *paint);
+
+    SkDEBUGCODE(bitmap.validate();)
+    CHECK_LOCKCOUNT_BALANCE(bitmap);
+
+    LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type)
+
+    while (iter.next()) {
+        iter.fDevice->drawBitmap(iter, bitmap, matrix, looper.paint());
+    }
+
+    LOOPER_END
 }
 
 void SkCanvas::internalDrawDevice(SkDevice* srcDev, int x, int y,
@@ -1733,7 +1743,7 @@
 
     SkMatrix matrix;
     matrix.setTranslate(x, y);
-    this->internalDrawBitmap(bitmap, NULL, matrix, paint);
+    this->internalDrawBitmap(bitmap, matrix, paint);
 }
 
 // this one is non-virtual, so it can be called safely by other canvas apis
@@ -1779,21 +1789,7 @@
 void SkCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& matrix,
                                 const SkPaint* paint) {
     SkDEBUGCODE(bitmap.validate();)
-    this->internalDrawBitmap(bitmap, NULL, matrix, paint);
-}
-
-void SkCanvas::commonDrawBitmap(const SkBitmap& bitmap, const SkIRect* srcRect,
-                                const SkMatrix& matrix, const SkPaint& paint) {
-    SkDEBUGCODE(bitmap.validate();)
-    CHECK_LOCKCOUNT_BALANCE(bitmap);
-
-    LOOPER_BEGIN(paint, SkDrawFilter::kBitmap_Type)
-
-    while (iter.next()) {
-        iter.fDevice->drawBitmap(iter, bitmap, srcRect, matrix, looper.paint());
-    }
-
-    LOOPER_END
+    this->internalDrawBitmap(bitmap, matrix, paint);
 }
 
 void SkCanvas::internalDrawBitmapNine(const SkBitmap& bitmap,
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 1de5b4e..408cda2 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -371,18 +371,8 @@
 }
 
 void SkDevice::drawBitmap(const SkDraw& draw, const SkBitmap& bitmap,
-                          const SkIRect* srcRect,
                           const SkMatrix& matrix, const SkPaint& paint) {
-    SkBitmap        tmp;    // storage if we need a subset of bitmap
-    const SkBitmap* bitmapPtr = &bitmap;
-
-    if (srcRect) {
-        if (!bitmap.extractSubset(&tmp, *srcRect)) {
-            return;     // extraction failed
-        }
-        bitmapPtr = &tmp;
-    }
-    draw.drawBitmap(*bitmapPtr, matrix, paint);
+    draw.drawBitmap(bitmap, matrix, paint);
 }
 
 void SkDevice::drawBitmapRect(const SkDraw& draw, const SkBitmap& bitmap,
@@ -449,7 +439,7 @@
         // We can go faster by just calling drawBitmap, which will concat the
         // matrix with the CTM, and try to call drawSprite if it can. If not,
         // it will make a shader and call drawRect, as we do below.
-        this->drawBitmap(draw, *bitmapPtr, NULL, matrix, paint);
+        this->drawBitmap(draw, *bitmapPtr, matrix, paint);
         return;
     }
 
diff --git a/src/device/xps/SkXPSDevice.cpp b/src/device/xps/SkXPSDevice.cpp
index 30e81bf..442a51f 100644
--- a/src/device/xps/SkXPSDevice.cpp
+++ b/src/device/xps/SkXPSDevice.cpp
@@ -1949,25 +1949,13 @@
 }
 
 void SkXPSDevice::drawBitmap(const SkDraw& d, const SkBitmap& bitmap,
-                             const SkIRect* srcRectOrNull,
                              const SkMatrix& matrix, const SkPaint& paint) {
     if (d.fClip->isEmpty()) {
         return;
     }
 
     SkIRect srcRect;
-    SkBitmap tmp;
-    const SkBitmap* bitmapPtr = &bitmap;
-    if (NULL == srcRectOrNull) {
-        srcRect.set(0, 0, bitmap.width(), bitmap.height());
-        bitmapPtr = &bitmap;
-    } else {
-        srcRect = *srcRectOrNull;
-        if (!bitmap.extractSubset(&tmp, srcRect)) {
-            return; // extraction failed
-        }
-        bitmapPtr = &tmp;
-    }
+    srcRect.set(0, 0, bitmap.width(), bitmap.height());
 
     //Create the new shaded path.
     SkTScopedComPtr<IXpsOMPath> shadedPath;
@@ -2007,7 +1995,7 @@
             SkShader::kClamp_TileMode,
         };
         SkTScopedComPtr<IXpsOMTileBrush> xpsImageBrush;
-        HRV(this->createXpsImageBrush(*bitmapPtr,
+        HRV(this->createXpsImageBrush(bitmap,
                                       transform,
                                       xy,
                                       paint.getAlpha(),
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 4456f51..000efee 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1078,21 +1078,10 @@
 
 void SkGpuDevice::drawBitmap(const SkDraw& draw,
                              const SkBitmap& bitmap,
-                             const SkIRect* srcRectPtr,
                              const SkMatrix& m,
                              const SkPaint& paint) {
-
-    SkRect  tmp;
-    SkRect* tmpPtr = NULL;
-
-    // convert from SkIRect to SkRect
-    if (NULL != srcRectPtr) {
-        tmp.set(*srcRectPtr);
-        tmpPtr = &tmp;
-    }
-
     // We cannot call drawBitmapRect here since 'm' could be anything
-    this->drawBitmapCommon(draw, bitmap, tmpPtr, m, paint);
+    this->drawBitmapCommon(draw, bitmap, NULL, m, paint);
 }
 
 void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
@@ -1216,9 +1205,8 @@
     }
 }
 
-namespace {
-
-bool hasAlignedSamples(const SkRect& srcRect, const SkRect& transformedRect) {
+static bool has_aligned_samples(const SkRect& srcRect, 
+                                const SkRect& transformedRect) {
     // detect pixel disalignment
     if (SkScalarAbs(SkScalarRoundToScalar(transformedRect.left()) -
             transformedRect.left()) < COLOR_BLEED_TOLERANCE &&
@@ -1233,11 +1221,12 @@
     return false;
 }
 
-bool mayColorBleed(const SkRect& srcRect, const SkRect& transformedRect,
-                   const SkMatrix& m) {
-    // Only gets called if hasAlignedSamples returned false.
+static bool may_color_bleed(const SkRect& srcRect, 
+                            const SkRect& transformedRect,
+                            const SkMatrix& m) {
+    // Only gets called if has_aligned_samples returned false.
     // So we can assume that sampling is axis aligned but not texel aligned.
-    GrAssert(!hasAlignedSamples(srcRect, transformedRect));
+    GrAssert(!has_aligned_samples(srcRect, transformedRect));
     SkRect innerSrcRect(srcRect), innerTransformedRect,
         outerTransformedRect(transformedRect);
     innerSrcRect.inset(SK_ScalarHalf, SK_ScalarHalf);
@@ -1257,7 +1246,6 @@
     return inner != outer;
 }
 
-} // unnamed namespace
 
 /*
  *  This is called by drawBitmap(), which has to handle images that may be too
@@ -1294,20 +1282,19 @@
         // Need texture domain if drawing a sub rect.
         needsTextureDomain = srcRect.width() < bitmap.width() ||
                              srcRect.height() < bitmap.height();
-        if (m.rectStaysRect() && fContext->getMatrix().rectStaysRect()) {
+        if (needsTextureDomain && m.rectStaysRect() && fContext->getMatrix().rectStaysRect()) {
             // sampling is axis-aligned
             SkRect transformedRect;
             SkMatrix srcToDeviceMatrix(m);
             srcToDeviceMatrix.postConcat(fContext->getMatrix());
             srcToDeviceMatrix.mapRect(&transformedRect, srcRect);
 
-            if (hasAlignedSamples(srcRect, transformedRect)) {
+            if (has_aligned_samples(srcRect, transformedRect)) {
                 // We could also turn off filtering here (but we already did a cache lookup with
                 // params).
                 needsTextureDomain = false;
             } else {
-                needsTextureDomain = needsTextureDomain &&
-                    mayColorBleed(srcRect, transformedRect, m);
+                needsTextureDomain = may_color_bleed(srcRect, transformedRect, m);
             }
         }
     }
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index f7077a9..387bfe8 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -908,20 +908,18 @@
             matrix.preTranslate(dx, dy);
         }
     }
-    this->drawBitmap(draw, *bitmapPtr, NULL, matrix, paint);
+    this->drawBitmap(draw, *bitmapPtr, matrix, paint);
 }
 
 void SkPDFDevice::drawBitmap(const SkDraw& d, const SkBitmap& bitmap,
-                             const SkIRect* srcRect, const SkMatrix& matrix,
-                             const SkPaint& paint) {
+                             const SkMatrix& matrix, const SkPaint& paint) {
     if (d.fClip->isEmpty()) {
         return;
     }
 
     SkMatrix transform = matrix;
     transform.postConcat(*d.fMatrix);
-    internalDrawBitmap(transform, d.fClipStack, *d.fClip, bitmap, srcRect,
-                       paint);
+    this->internalDrawBitmap(transform, d.fClipStack, *d.fClip, bitmap, NULL, paint);
 }
 
 void SkPDFDevice::drawSprite(const SkDraw& d, const SkBitmap& bitmap,
@@ -932,7 +930,7 @@
 
     SkMatrix matrix;
     matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y));
-    internalDrawBitmap(matrix, d.fClipStack, *d.fClip, bitmap, NULL, paint);
+    this->internalDrawBitmap(matrix, d.fClipStack, *d.fClip, bitmap, NULL, paint);
 }
 
 void SkPDFDevice::drawText(const SkDraw& d, const void* text, size_t len,
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index 68d0602..6dce383 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -203,7 +203,6 @@
                             bool pathIsMutable = false) SK_OVERRIDE
         {SkASSERT(0);}
     virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
-                            const SkIRect* srcRectOrNull,
                             const SkMatrix& matrix, const SkPaint& paint) SK_OVERRIDE
         {SkASSERT(0);}
     virtual void drawSprite(const SkDraw&, const SkBitmap& bitmap,
diff --git a/src/utils/SkPictureUtils.cpp b/src/utils/SkPictureUtils.cpp
index 5ef9e48..36b62e5 100644
--- a/src/utils/SkPictureUtils.cpp
+++ b/src/utils/SkPictureUtils.cpp
@@ -103,7 +103,6 @@
         this->addBitmapFromPaint(paint);
     }
     virtual void drawBitmap(const SkDraw&, const SkBitmap& bitmap,
-                            const SkIRect* srcRectOrNull,
                             const SkMatrix&, const SkPaint&) SK_OVERRIDE {
         this->addBitmap(bitmap);
     }
diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp
index 9d3872e..1289c03 100644
--- a/tests/DeferredCanvasTest.cpp
+++ b/tests/DeferredCanvasTest.cpp
@@ -243,7 +243,6 @@
         fDrawBitmapCallCount = 0;
     }
     virtual void drawBitmap(const SkDraw&, const SkBitmap&,
-                            const SkIRect*,
                             const SkMatrix&, const SkPaint&) SK_OVERRIDE {
         fDrawBitmapCallCount++;
     }