Turn fatal assertion in decodeRegion into a warning.
This commit is contained in:
@@ -248,8 +248,8 @@ static jobject nativeDecodeRegion(JNIEnv* env, jobject, SkBitmapRegionDecoder *b
|
||||
// promise we will never change our pixels (great for sharing and pictures)
|
||||
pr->setImmutable();
|
||||
|
||||
// now create the java bitmap
|
||||
jbyteArray buff = ((AndroidPixelRef*) pr)->getStorageObj();
|
||||
JavaPixelAllocator* allocator = (JavaPixelAllocator*) decoder->getAllocator();
|
||||
jbyteArray buff = allocator->getStorageObjAndReset();
|
||||
return GraphicsJNI::createBitmap(env, bitmap, buff, false, NULL, -1);
|
||||
}
|
||||
|
||||
|
||||
@@ -564,7 +564,8 @@ bool GraphicsJNI::mallocPixelRef(JNIEnv* env, SkBitmap* bitmap, SkColorTable* ct
|
||||
|
||||
JavaPixelAllocator::JavaPixelAllocator(JNIEnv* env, bool allocateInJavaHeap)
|
||||
: fAllocateInJavaHeap(allocateInJavaHeap),
|
||||
fStorageObj(NULL) {
|
||||
fStorageObj(NULL),
|
||||
fAllocCount(0) {
|
||||
if (env->GetJavaVM(&fVM) != JNI_OK) {
|
||||
SkDebugf("------ [%p] env->GetJavaVM failed\n", env);
|
||||
sk_throw();
|
||||
@@ -577,12 +578,13 @@ bool JavaPixelAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
|
||||
// If allocating in the Java heap, only allow a single object to be
|
||||
// allocated for the lifetime of this object.
|
||||
if (fStorageObj != NULL) {
|
||||
SkDebugf("ERROR: One-shot allocator has already allocated\n");
|
||||
sk_throw();
|
||||
SkDebugf("WARNING: One-shot allocator has already allocated (alloc count = %d)\n", fAllocCount);
|
||||
// sk_throw();
|
||||
}
|
||||
|
||||
if (fAllocateInJavaHeap) {
|
||||
fStorageObj = GraphicsJNI::allocateJavaPixelRef(env, bitmap, ctable);
|
||||
fAllocCount += 1;
|
||||
return fStorageObj != NULL;
|
||||
}
|
||||
return GraphicsJNI::mallocPixelRef(env, bitmap, ctable);
|
||||
|
||||
@@ -136,12 +136,28 @@ public:
|
||||
// overrides
|
||||
virtual bool allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable);
|
||||
|
||||
jbyteArray getStorageObj() { return fStorageObj; };
|
||||
/** Return the Java array object created for the last allocation.
|
||||
* This returns a local JNI reference which the caller is responsible
|
||||
* for storing appropriately (usually by passing it to the Bitmap
|
||||
* constructor).
|
||||
*/
|
||||
jbyteArray getStorageObj() { return fStorageObj; }
|
||||
|
||||
/** Same as getStorageObj(), but also resets the allocator so that it
|
||||
* can allocate again.
|
||||
*/
|
||||
jbyteArray getStorageObjAndReset() {
|
||||
jbyteArray result = fStorageObj;
|
||||
fStorageObj = NULL;
|
||||
fAllocCount = 0;
|
||||
return result;
|
||||
};
|
||||
|
||||
private:
|
||||
JavaVM* fVM;
|
||||
bool fAllocateInJavaHeap;
|
||||
jbyteArray fStorageObj;
|
||||
int fAllocCount;
|
||||
};
|
||||
|
||||
class JavaMemoryUsageReporter : public SkVMMemoryReporter {
|
||||
|
||||
Reference in New Issue
Block a user