Glop support for custom textured UVs, simplify drawBitmap(src,dst)

Front load the scaling-to-support-shaders to record time.

Change-Id: I861c82d9d16d3c5e063cf87230127eed0b3f9b54
diff --git a/libs/hwui/DisplayListRenderer.cpp b/libs/hwui/DisplayListRenderer.cpp
index 23181bc..2a673f4 100644
--- a/libs/hwui/DisplayListRenderer.cpp
+++ b/libs/hwui/DisplayListRenderer.cpp
@@ -258,7 +258,8 @@
         float srcRight, float srcBottom, float dstLeft, float dstTop,
         float dstRight, float dstBottom, const SkPaint* paint) {
     if (srcLeft == 0 && srcTop == 0
-            && srcRight == bitmap.width() && srcBottom == bitmap.height()
+            && srcRight == bitmap.width()
+            && srcBottom == bitmap.height()
             && (srcBottom - srcTop == dstBottom - dstTop)
             && (srcRight - srcLeft == dstRight - dstLeft)) {
         // transform simple rect to rect drawing case into position bitmap ops, since they merge
@@ -269,6 +270,30 @@
     } else {
         paint = refPaint(paint);
 
+        if (paint && paint->getShader()) {
+            float scaleX = (dstRight - dstLeft) / (srcRight - srcLeft);
+            float scaleY = (dstBottom - dstTop) / (srcBottom - srcTop);
+            if (!MathUtils::areEqual(scaleX, 1.0f) || !MathUtils::areEqual(scaleY, 1.0f)) {
+                // Apply the scale transform on the canvas, so that the shader
+                // effectively calculates positions relative to src rect space
+
+                save(SkCanvas::kMatrix_SaveFlag);
+                translate(dstLeft, dstTop);
+                scale(scaleX, scaleY);
+
+                dstLeft = 0.0f;
+                dstTop = 0.0f;
+                dstRight = srcRight - srcLeft;
+                dstBottom = srcBottom - srcTop;
+
+                addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(&bitmap),
+                        srcLeft, srcTop, srcRight, srcBottom,
+                        dstLeft, dstTop, dstRight, dstBottom, paint));
+                restore();
+                return;
+            }
+        }
+
         addDrawOp(new (alloc()) DrawBitmapRectOp(refBitmap(&bitmap),
                 srcLeft, srcTop, srcRight, srcBottom,
                 dstLeft, dstTop, dstRight, dstBottom, paint));