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

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

Allow a JNI local ref to be passed directly into globalRef().

Change-Id: If3063e88ec1eba7a13c983f5f71be6a2d84c4d60
parent e2975f17
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -473,16 +473,20 @@ void AndroidPixelRef::setLocalJNIRef(jbyteArray arr) {
    }
}

void AndroidPixelRef::globalRef() {
void AndroidPixelRef::globalRef(void* localref) {
    if (fOnJavaHeap && sk_atomic_inc(&fGlobalRefCnt) == 0) {
        JNIEnv *env = vm2env(fVM);

        // If JNI ref was passed, it is always used
        if (localref) fStorageObj = (jbyteArray) localref;

        if (fStorageObj == NULL) {
            SkDebugf("Cannot create a global ref, fStorage obj is NULL");
            SkDebugf("No valid local ref to create a JNI global ref\n");
            sk_throw();
        }
        if (fHasGlobalRef) {
            // This should never happen
            SkDebugf("Already holding a global ref");
            SkDebugf("Already holding a JNI global ref");
            sk_throw();
        }

+10 −1
Original line number Diff line number Diff line
@@ -92,7 +92,16 @@ public:

    void setLocalJNIRef(jbyteArray arr);

    virtual void globalRef();
    /** Used to hold a ref to the pixels when the Java bitmap may be collected.
     *  If specified, 'localref' is a valid JNI local reference to the byte array
     *  containing the pixel data.
     *
     *  'localref' may only be NULL if setLocalJNIRef() was already called with
     *  a JNI local ref that is still valid.
     */
    virtual void globalRef(void* localref=NULL);

    /** Release a ref that was acquired using globalRef(). */
    virtual void globalUnref();

private: