Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit afde46ed authored by Patrick Dubroy's avatar Patrick Dubroy
Browse files

Turn fatal assertion in decodeRegion into a warning.

parent ccc15650
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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);
}

+5 −3
Original line number Diff line number Diff line
@@ -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);
+17 −1
Original line number Diff line number Diff line
@@ -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 {