Merge "Fix texture coordinates for sub-bitmap rendering."
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 8cf325b..8e9e8be 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -1369,10 +1369,10 @@
     const float width = texture->width;
     const float height = texture->height;
 
-    const float u1 = srcLeft / width;
-    const float v1 = srcTop / height;
-    const float u2 = srcRight / width;
-    const float v2 = srcBottom / height;
+    const float u1 = (srcLeft + 0.5f) / width;
+    const float v1 = (srcTop + 0.5f)  / height;
+    const float u2 = (srcRight - 0.5f) / width;
+    const float v2 = (srcBottom - 0.5f) / height;
 
     mCaches.unbindMeshBuffer();
     resetDrawTextureTexCoords(u1, v1, u2, v2);
diff --git a/tests/HwAccelerationTest/res/drawable-hdpi/patch.9.png b/tests/HwAccelerationTest/res/drawable-hdpi/patch.9.png
new file mode 100644
index 0000000..e3b3639
--- /dev/null
+++ b/tests/HwAccelerationTest/res/drawable-hdpi/patch.9.png
Binary files differ
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ThinPatchesActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ThinPatchesActivity.java
index 4f605fa..cfad6da 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ThinPatchesActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ThinPatchesActivity.java
@@ -18,7 +18,10 @@
 
 import android.app.Activity;
 import android.content.res.Resources;
+import android.graphics.Bitmap;
 import android.graphics.Canvas;
+import android.graphics.Rect;
+import android.graphics.RectF;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.view.View;
@@ -42,6 +45,7 @@
 
     private class PatchView extends View {
         private Drawable mPatch1, mPatch2;
+        private Bitmap mTexture;
 
         public PatchView(Activity activity) {
             super(activity);
@@ -49,6 +53,20 @@
             final Resources resources = activity.getResources();
             mPatch1 = resources.getDrawable(R.drawable.patch);
             mPatch2 = resources.getDrawable(R.drawable.btn_toggle_on);
+
+            mTexture = Bitmap.createBitmap(4, 3, Bitmap.Config.ARGB_8888);
+            mTexture.setPixel(0, 0, 0xffff0000);
+            mTexture.setPixel(1, 0, 0xffffffff);
+            mTexture.setPixel(2, 0, 0xff000000);
+            mTexture.setPixel(3, 0, 0xffff0000);
+            mTexture.setPixel(0, 1, 0xffff0000);
+            mTexture.setPixel(1, 1, 0xff000000);
+            mTexture.setPixel(2, 1, 0xffffffff);
+            mTexture.setPixel(3, 1, 0xffff0000);
+            mTexture.setPixel(0, 2, 0xffff0000);
+            mTexture.setPixel(1, 2, 0xffff0000);
+            mTexture.setPixel(2, 2, 0xffff0000);
+            mTexture.setPixel(3, 2, 0xffff0000);
         }
 
         @Override
@@ -62,10 +80,17 @@
             mPatch1.setBounds(left, top, left + width, top + height);
             mPatch1.draw(canvas);
 
+            canvas.save();
             canvas.translate(0.0f, height + 20.0f);
             
             mPatch2.setBounds(left, top, left + width, top + height);
             mPatch2.draw(canvas);
+
+            canvas.restore();
+
+//            Rect src = new Rect(1, 0, 3, 2);
+//            RectF dst = new RectF(0, 0, getWidth(), getHeight());
+//            canvas.drawBitmap(mTexture, src, dst, null);
         }
     }
 }