Merge "detect api version, and start respecting offsets" into pi-dev

This commit is contained in:
TreeHugger Robot
2018-03-23 11:25:19 +00:00
committed by Android (Google) Code Review
3 changed files with 16 additions and 1 deletions

View File

@@ -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 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<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,

View File

@@ -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

View File

@@ -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);