Fixed bug in drawing of large bitmaps

https://codereview.appspot.com/6595047/



git-svn-id: http://skia.googlecode.com/svn/trunk@5745 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/bitmaprect.cpp b/gm/bitmaprect.cpp
index ee95e45..c438776 100644
--- a/gm/bitmaprect.cpp
+++ b/gm/bitmaprect.cpp
@@ -206,13 +206,23 @@
         SkBitmap bitmap;
         make_big_bitmap(&bitmap);
 
-        SkRect srcR = { 0.0f, 0.0f, 4096.0f, 2040.0f };
-        SkRect dstR = { 10.1f, 10.1f, 629.9f, 469.9f };
+        SkRect srcR1 = { 0.0f, 0.0f, 4096.0f, 2040.0f };
+        SkRect dstR1 = { 10.1f, 10.1f, 629.9f, 400.9f };
+
+        SkRect srcR2 = { 4085.0f, 10.0f, 4087.0f, 12.0f };
+        SkRect dstR2 = { 10, 410, 30, 430 };
 
         if (!fUseIRect) {
-            canvas->drawBitmapRectToRect(bitmap, &srcR, dstR, &paint);
+            canvas->drawBitmapRectToRect(bitmap, &srcR1, dstR1, &paint);
+            canvas->drawBitmapRectToRect(bitmap, &srcR2, dstR2, &paint);
         } else {
-            canvas->drawBitmapRect(bitmap, NULL, dstR, &paint);
+            SkIRect iSrcR1, iSrcR2;
+
+            srcR1.roundOut(&iSrcR1);
+            srcR2.roundOut(&iSrcR2);
+
+            canvas->drawBitmapRect(bitmap, &iSrcR1, dstR1, &paint);
+            canvas->drawBitmapRect(bitmap, &iSrcR2, dstR2, &paint);
         }
     }
 
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 5b210b2..528f850 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1331,9 +1331,6 @@
 
     int tileSize = determine_tile_size(bitmap, srcRect, maxTextureSize);
 
-    // undo the translate done by SkCanvas
-    SkScalar DX = SkMaxScalar(0, srcRect.fLeft);
-    SkScalar DY = SkMaxScalar(0, srcRect.fTop);
     // compute clip bounds in local coordinates
     SkRect clipRect;
     {
@@ -1344,8 +1341,6 @@
             return;
         }
         inverse.mapRect(&clipRect);
-        // apply the canvas' translate to our local clip
-        clipRect.offset(DX, DY);
     }
 
     int nx = bitmap.width() / tileSize;
@@ -1372,13 +1367,10 @@
             if (bitmap.extractSubset(&tmpB, iTileR)) {
                 // now offset it to make it "local" to our tmp bitmap
                 tileR.offset(SkIntToScalar(-iTileR.fLeft), SkIntToScalar(-iTileR.fTop));
-
                 SkMatrix tmpM(m);
-                {
-                    SkScalar dx = iTileR.fLeft - DX + SkMaxScalar(0, tileR.fLeft);
-                    SkScalar dy = iTileR.fTop  - DY + SkMaxScalar(0, tileR.fTop);
-                    tmpM.preTranslate(dx, dy);
-                }
+                tmpM.preTranslate(SkIntToScalar(iTileR.fLeft), 
+                                  SkIntToScalar(iTileR.fTop));
+
                 this->internalDrawBitmap(draw, tmpB, tileR, tmpM, params, grPaint);
             }
         }