diff options
author | Eric Hassold <hassold@google.com> | 2011-02-23 16:46:11 -0800 |
---|---|---|
committer | Eric Hassold <hassold@google.com> | 2011-02-24 11:21:13 -0800 |
commit | ef7be262e5859efdf805d1b9612bc2b250d5971e (patch) | |
tree | bdebebf4da9bdae564336d534282283889662689 /core/jni | |
parent | b7508df1f6c1dd187660de8ce310f3fbed22b26c (diff) | |
download | frameworks_base-ef7be262e5859efdf805d1b9612bc2b250d5971e.zip frameworks_base-ef7be262e5859efdf805d1b9612bc2b250d5971e.tar.gz frameworks_base-ef7be262e5859efdf805d1b9612bc2b250d5971e.tar.bz2 |
Detect out of memory in extractAlpha
When extractAlpha() native method in Skia fails to allocate pixels,
it resets target bitmap. This change detects when such empty bitmap
is returned, and throws a OutOfMemory Java exception.
Depends on https://android-git.corp.google.com/g/97793
Bug: 3418381
Change-Id: I65a84998be089c49ed5005f6995bdc4f4d1669bc
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/android/graphics/Bitmap.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp index 1d961ec..9b7c83c 100644 --- a/core/jni/android/graphics/Bitmap.cpp +++ b/core/jni/android/graphics/Bitmap.cpp @@ -447,6 +447,13 @@ static jobject Bitmap_extractAlpha(JNIEnv* env, jobject clazz, JavaPixelAllocator allocator(env);
src->extractAlpha(dst, paint, &allocator, &offset);
+ // If Skia can't allocate pixels for destination bitmap, it resets
+ // it, that is set its pixels buffer to NULL, and zero width and height.
+ if (dst->getPixels() == NULL && src->getPixels() != NULL) {
+ delete dst;
+ doThrowOOME(env, "failed to allocate pixels for alpha");
+ return NULL;
+ }
if (offsetXY != 0 && env->GetArrayLength(offsetXY) >= 2) {
int* array = env->GetIntArrayElements(offsetXY, NULL);
array[0] = offset.fX;
@@ -651,4 +658,3 @@ int register_android_graphics_Bitmap(JNIEnv* env) return android::AndroidRuntime::registerNativeMethods(env, kClassPathName,
gBitmapMethods, SK_ARRAY_COUNT(gBitmapMethods));
}
-
|