summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/java/android/view/GLES20Canvas.java29
-rw-r--r--core/jni/android_view_GLES20Canvas.cpp23
2 files changed, 46 insertions, 6 deletions
diff --git a/core/java/android/view/GLES20Canvas.java b/core/java/android/view/GLES20Canvas.java
index 0bb5f9f..1631fb3 100644
--- a/core/java/android/view/GLES20Canvas.java
+++ b/core/java/android/view/GLES20Canvas.java
@@ -833,19 +833,40 @@ class GLES20Canvas extends HardwareCanvas {
@Override
public void drawBitmap(int[] colors, int offset, int stride, float x, float y,
int width, int height, boolean hasAlpha, Paint paint) {
+ if (width < 0) {
+ throw new IllegalArgumentException("width must be >= 0");
+ }
+
+ if (height < 0) {
+ throw new IllegalArgumentException("height must be >= 0");
+ }
+
+ if (Math.abs(stride) < width) {
+ throw new IllegalArgumentException("abs(stride) must be >= width");
+ }
+
+ int lastScanline = offset + (height - 1) * stride;
+ int length = colors.length;
+
+ if (offset < 0 || (offset + width > length) || lastScanline < 0 ||
+ (lastScanline + width > length)) {
+ throw new ArrayIndexOutOfBoundsException();
+ }
+
// Shaders are ignored when drawing bitmaps
int modifier = paint != null ? setupColorFilter(paint) : MODIFIER_NONE;
try {
- final Bitmap.Config config = hasAlpha ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
- final Bitmap b = Bitmap.createBitmap(colors, offset, stride, width, height, config);
final int nativePaint = paint == null ? 0 : paint.mNativePaint;
- nDrawBitmap(mRenderer, b.mNativeBitmap, b.mBuffer, x, y, nativePaint);
- b.recycle();
+ nDrawBitmap(mRenderer, colors, offset, stride, x, y,
+ width, height, hasAlpha, nativePaint);
} finally {
if (modifier != MODIFIER_NONE) nResetModifiers(mRenderer, modifier);
}
}
+ private static native void nDrawBitmap(int renderer, int[] colors, int offset, int stride,
+ float x, float y, int width, int height, boolean hasAlpha, int nativePaint);
+
@Override
public void drawBitmap(int[] colors, int offset, int stride, int x, int y,
int width, int height, boolean hasAlpha, Paint paint) {
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp
index 60929ac..d8ec656 100644
--- a/core/jni/android_view_GLES20Canvas.cpp
+++ b/core/jni/android_view_GLES20Canvas.cpp
@@ -326,8 +326,8 @@ static void android_view_GLES20Canvas_concatMatrix(JNIEnv* env, jobject clazz,
// ----------------------------------------------------------------------------
static void android_view_GLES20Canvas_drawBitmap(JNIEnv* env, jobject clazz,
- OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer, float left,
- float top, SkPaint* paint) {
+ OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer,
+ jfloat left, jfloat top, SkPaint* paint) {
// This object allows the renderer to allocate a global JNI ref to the buffer object.
JavaHeapBitmapRef bitmapRef(env, bitmap, buffer);
@@ -354,6 +354,24 @@ static void android_view_GLES20Canvas_drawBitmapMatrix(JNIEnv* env, jobject claz
renderer->drawBitmap(bitmap, matrix, paint);
}
+static void android_view_GLES20Canvas_drawBitmapData(JNIEnv* env, jobject clazz,
+ OpenGLRenderer* renderer, jintArray colors, jint offset, jint stride,
+ jfloat left, jfloat top, jint width, jint height, jboolean hasAlpha, SkPaint* paint) {
+ SkBitmap bitmap;
+ SkBitmap::Config config = hasAlpha ? SkBitmap::kARGB_8888_Config : SkBitmap::kRGB_565_Config;
+ bitmap.setConfig(config, width, height);
+
+ if (!bitmap.allocPixels()) {
+ return;
+ }
+
+ if (!GraphicsJNI::SetPixels(env, colors, offset, stride, 0, 0, width, height, bitmap)) {
+ return;
+ }
+
+ renderer->drawBitmapData(&bitmap, left, top, paint);
+}
+
static void android_view_GLES20Canvas_drawBitmapMesh(JNIEnv* env, jobject clazz,
OpenGLRenderer* renderer, SkBitmap* bitmap, jbyteArray buffer,
jint meshWidth, jint meshHeight, jfloatArray vertices, jint offset,
@@ -880,6 +898,7 @@ static JNINativeMethod gMethods[] = {
{ "nDrawBitmap", "(II[BFFI)V", (void*) android_view_GLES20Canvas_drawBitmap },
{ "nDrawBitmap", "(II[BFFFFFFFFI)V",(void*) android_view_GLES20Canvas_drawBitmapRect },
{ "nDrawBitmap", "(II[BII)V", (void*) android_view_GLES20Canvas_drawBitmapMatrix },
+ { "nDrawBitmap", "(I[IIIFFIIZI)V", (void*) android_view_GLES20Canvas_drawBitmapData },
{ "nDrawBitmapMesh", "(II[BII[FI[III)V",(void*) android_view_GLES20Canvas_drawBitmapMesh },