Merge "detect api version, and start respecting offsets" into pi-dev am: dfdc379144
am: 90405d02cd
Change-Id: Ied06df3460e90779e3015e6ba64406a068df5472
diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp
index 0017f6c..c9bfa13 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 <android/api-level.h>
#include <androidfw/ResourceTypes.h>
#include <hwui/Canvas.h>
#include <hwui/Paint.h>
@@ -467,6 +468,13 @@
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 @@
const Paint* paint = reinterpret_cast<Paint*>(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 d925441..b0bc102 100644
--- a/graphics/java/android/graphics/Canvas.java
+++ b/graphics/java/android/graphics/Canvas.java
@@ -1490,6 +1490,10 @@
* 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 d04bb2e..f341cf9 100644
--- a/libs/hwui/hwui/Canvas.h
+++ b/libs/hwui/hwui/Canvas.h
@@ -276,6 +276,8 @@
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);