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

Commit 27f0b17d authored by Chet Haase's avatar Chet Haase
Browse files

Fix native resource leak when OpenGL renderer is not being used.

Native resources (bitmaps, matrices, paints, shaders) are shared when display lists
are used, and a refcounting system is in place to take care of disposing when all
clients are finished with them. But the cache where these refcounts are tracked is
not enabled when the Open GL renderer is not being used. This results in the native
destructors not being called, and the resources are leaked.

Change-Id: Ic7aeb55e4636dcad229846601407e596160346e6
parent 2754b4bd
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -256,20 +256,20 @@ static void Bitmap_destructor(JNIEnv* env, jobject, SkBitmap* bitmap) {
#ifdef USE_OPENGL_RENDERER
    if (android::uirenderer::Caches::hasInstance()) {
        android::uirenderer::Caches::getInstance().resourceCache.destructor(bitmap);
        return;
    }
#else // !USE_OPENGL_RENDERER
#endif // USE_OPENGL_RENDERER
    delete bitmap;
#endif
}

static void Bitmap_recycle(JNIEnv* env, jobject, SkBitmap* bitmap) {
#ifdef USE_OPENGL_RENDERER
    if (android::uirenderer::Caches::hasInstance()) {
        android::uirenderer::Caches::getInstance().resourceCache.recycle(bitmap);
        return;
    }
#else // !USE_OPENGL_RENDERER
    bitmap->setPixels(NULL, NULL);
#endif // USE_OPENGL_RENDERER
    bitmap->setPixels(NULL, NULL);
}

// These must match the int values in Bitmap.java
+2 −2
Original line number Diff line number Diff line
@@ -35,10 +35,10 @@ public:
#ifdef USE_OPENGL_RENDERER
        if (android::uirenderer::Caches::hasInstance()) {
            android::uirenderer::Caches::getInstance().resourceCache.destructor(obj);
            return;
        }
#else // !USE_OPENGL_RENDERER
#endif // USE_OPENGL_RENDERER
        delete obj;
#endif
    }

    static SkMatrix* create(JNIEnv* env, jobject clazz, const SkMatrix* src) {
+2 −2
Original line number Diff line number Diff line
@@ -66,10 +66,10 @@ public:
#ifdef USE_OPENGL_RENDERER
        if (android::uirenderer::Caches::hasInstance()) {
            android::uirenderer::Caches::getInstance().resourceCache.destructor(obj);
            return;
        }
#else // !USE_OPENGL_RENDERER
#endif // USE_OPENGL_RENDERER
        delete obj;
#endif
    }

    static SkPaint* init(JNIEnv* env, jobject clazz) {