From 322bc57a338ec650347084ef379860c19b29d1b4 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Tue, 20 Mar 2018 13:37:04 -0400 Subject: [PATCH] detect api version, and start respecting offsets Test: make Bug: 36471624 Change-Id: Ica10c557bf35e8d707fabbafab49d22109916fd3 --- core/jni/android_graphics_Canvas.cpp | 11 ++++++++++- graphics/java/android/graphics/Canvas.java | 4 ++++ libs/hwui/hwui/Canvas.h | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp index 0017f6cd8a417..c9bfa137c7ac0 100644 --- a/core/jni/android_graphics_Canvas.cpp +++ b/core/jni/android_graphics_Canvas.cpp @@ -18,6 +18,7 @@ #include "GraphicsJNI.h" #include "core_jni_helpers.h" +#include #include #include #include @@ -467,6 +468,13 @@ static void drawBitmapArray(JNIEnv* env, jobject, jlong canvasHandle, static void drawBitmapMesh(JNIEnv* env, jobject, jlong canvasHandle, jobject jbitmap, jint meshWidth, jint meshHeight, jfloatArray jverts, jint vertIndex, jintArray jcolors, jint colorIndex, jlong paintHandle) { + if (Canvas::GetApiLevel() < __ANDROID_API_P__) { + // Before P we forgot to respect these. Now that we do respect them, explicitly + // zero them for backward compatibility. + vertIndex = 0; + colorIndex = 0; + } + const int ptCount = (meshWidth + 1) * (meshHeight + 1); AutoJavaFloatArray vertA(env, jverts, vertIndex + (ptCount << 1)); AutoJavaIntArray colorA(env, jcolors, colorIndex + ptCount); @@ -474,7 +482,8 @@ static void drawBitmapMesh(JNIEnv* env, jobject, jlong canvasHandle, jobject jbi const Paint* paint = reinterpret_cast(paintHandle); Bitmap& bitmap = android::bitmap::toBitmap(env, jbitmap); get_canvas(canvasHandle)->drawBitmapMesh(bitmap, meshWidth, meshHeight, - vertA.ptr(), colorA.ptr(), paint); + vertA.ptr() + vertIndex*2, + colorA.ptr() + colorIndex, paint); } static void drawTextChars(JNIEnv* env, jobject, jlong canvasHandle, jcharArray text, diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index d925441e36570..b0bc1029c6df8 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -1490,6 +1490,10 @@ public class Canvas extends BaseCanvas { * across the top of the bitmap from left to right. A more general version of this method is * drawVertices(). * + * Prior to API level {@value Build.VERSION_CODES#P} vertOffset and colorOffset were ignored, + * effectively treating them as zeros. In API level {@value Build.VERSION_CODES#P} and above + * these parameters will be respected. + * * @param bitmap The bitmap to draw using the mesh * @param meshWidth The number of columns in the mesh. Nothing is drawn if this is 0 * @param meshHeight The number of rows in the mesh. Nothing is drawn if this is 0 diff --git a/libs/hwui/hwui/Canvas.h b/libs/hwui/hwui/Canvas.h index d04bb2e5ad034..f341cf96120da 100644 --- a/libs/hwui/hwui/Canvas.h +++ b/libs/hwui/hwui/Canvas.h @@ -276,6 +276,8 @@ public: const SkPath& path, float hOffset, float vOffset, const Paint& paint, const Typeface* typeface); + static int GetApiLevel() { return sApiLevel; } + protected: void drawTextDecorations(float x, float y, float length, const SkPaint& paint);