summaryrefslogtreecommitdiffstats
path: root/core/jni/android/graphics/NinePatch.cpp
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-02-10 15:44:00 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-02-10 15:44:00 -0800
commitd24b8183b93e781080b2c16c487e60d51c12da31 (patch)
treefbb89154858984eb8e41556da7e9433040d55cd4 /core/jni/android/graphics/NinePatch.cpp
parentf1e484acb594a726fb57ad0ae4cfe902c7f35858 (diff)
downloadframeworks_base-d24b8183b93e781080b2c16c487e60d51c12da31.zip
frameworks_base-d24b8183b93e781080b2c16c487e60d51c12da31.tar.gz
frameworks_base-d24b8183b93e781080b2c16c487e60d51c12da31.tar.bz2
auto import from //branches/cupcake/...@130745
Diffstat (limited to 'core/jni/android/graphics/NinePatch.cpp')
-rw-r--r--core/jni/android/graphics/NinePatch.cpp25
1 files changed, 10 insertions, 15 deletions
diff --git a/core/jni/android/graphics/NinePatch.cpp b/core/jni/android/graphics/NinePatch.cpp
index 9e943f3..b11edfc 100644
--- a/core/jni/android/graphics/NinePatch.cpp
+++ b/core/jni/android/graphics/NinePatch.cpp
@@ -47,19 +47,17 @@ public:
static void draw(JNIEnv* env, SkCanvas* canvas, SkRect& bounds,
const SkBitmap* bitmap, jbyteArray chunkObj, const SkPaint* paint)
{
- const jbyte* array = env->GetByteArrayElements(chunkObj, 0);
- if (array != NULL) {
- size_t chunkSize = env->GetArrayLength(chunkObj);
+ size_t chunkSize = env->GetArrayLength(chunkObj);
+ void* storage = alloca(chunkSize);
+ env->GetByteArrayRegion(chunkObj, 0, chunkSize,
+ reinterpret_cast<jbyte*>(storage));
+ if (!env->ExceptionCheck()) {
// need to deserialize the chunk
- void* storage = alloca(chunkSize);
Res_png_9patch* chunk = static_cast<Res_png_9patch*>(storage);
- memcpy(chunk, array, chunkSize);
assert(chunkSize == chunk->serializedSize());
// this relies on deserialization being done in place
Res_png_9patch::deserialize(chunk);
NinePatch_Draw(canvas, bounds, *bitmap, *chunk, paint, NULL);
- env->ReleaseByteArrayElements(chunkObj, const_cast<jbyte*>(array),
- JNI_ABORT);
}
}
@@ -102,23 +100,20 @@ public:
SkRect bounds;
GraphicsJNI::jrect_to_rect(env, boundsRect, &bounds);
- const jbyte* array = (jbyte*)env->GetByteArrayElements(chunkObj, 0);
- if (array != NULL) {
- size_t chunkSize = env->GetArrayLength(chunkObj);
+ size_t chunkSize = env->GetArrayLength(chunkObj);
+ void* storage = alloca(chunkSize);
+ env->GetByteArrayRegion(chunkObj, 0, chunkSize,
+ reinterpret_cast<jbyte*>(storage));
+ if (!env->ExceptionCheck()) {
// need to deserialize the chunk
- void* storage = alloca(chunkSize);
Res_png_9patch* chunk = static_cast<Res_png_9patch*>(storage);
- memcpy(chunk, array, chunkSize);
assert(chunkSize == chunk->serializedSize());
// this relies on deserialization being done in place
Res_png_9patch::deserialize(chunk);
SkRegion* region = NULL;
NinePatch_Draw(NULL, bounds, *bitmap, *chunk, NULL, &region);
- env->ReleaseByteArrayElements(chunkObj, const_cast<jbyte*>(array),
- JNI_ABORT);
return (jint)region;
}
-
return 0;
}