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

Commit a35778c7 authored by John Reck's avatar John Reck
Browse files

Yank ResourceCache out of Caches

Bug: 17947547

Pull the ResourceCache (aka, ref-counting side channel) out of
Caches so that DisplayListRenderer doesn't use Caches, avoiding
the risk of instantiating Caches on the wrong thread or
without a GL context

Change-Id: I7d63b70b3b0a0163308c5dedd6ef255eadebe8fd
parent b9744c1c
Loading
Loading
Loading
Loading
+5 −5
Original line number Original line Diff line number Diff line
@@ -17,7 +17,7 @@


#include <jni.h>
#include <jni.h>


#include <Caches.h>
#include <ResourceCache.h>


#if 0
#if 0
    #define TRACE_BITMAP(code)  code
    #define TRACE_BITMAP(code)  code
@@ -365,8 +365,8 @@ static jobject Bitmap_copy(JNIEnv* env, jobject, jlong srcHandle,
static void Bitmap_destructor(JNIEnv* env, jobject, jlong bitmapHandle) {
static void Bitmap_destructor(JNIEnv* env, jobject, jlong bitmapHandle) {
    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
#ifdef USE_OPENGL_RENDERER
#ifdef USE_OPENGL_RENDERER
    if (android::uirenderer::Caches::hasInstance()) {
    if (android::uirenderer::ResourceCache::hasInstance()) {
        android::uirenderer::Caches::getInstance().resourceCache.destructor(bitmap);
        android::uirenderer::ResourceCache::getInstance().destructor(bitmap);
        return;
        return;
    }
    }
#endif // USE_OPENGL_RENDERER
#endif // USE_OPENGL_RENDERER
@@ -376,9 +376,9 @@ static void Bitmap_destructor(JNIEnv* env, jobject, jlong bitmapHandle) {
static jboolean Bitmap_recycle(JNIEnv* env, jobject, jlong bitmapHandle) {
static jboolean Bitmap_recycle(JNIEnv* env, jobject, jlong bitmapHandle) {
    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
    SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle);
#ifdef USE_OPENGL_RENDERER
#ifdef USE_OPENGL_RENDERER
    if (android::uirenderer::Caches::hasInstance()) {
    if (android::uirenderer::ResourceCache::hasInstance()) {
        bool result;
        bool result;
        result = android::uirenderer::Caches::getInstance().resourceCache.recycle(bitmap);
        result = android::uirenderer::ResourceCache::getInstance().recycle(bitmap);
        return result ? JNI_TRUE : JNI_FALSE;
        return result ? JNI_TRUE : JNI_FALSE;
    }
    }
#endif // USE_OPENGL_RENDERER
#endif // USE_OPENGL_RENDERER
+3 −3
Original line number Original line Diff line number Diff line
@@ -21,7 +21,7 @@
#include <androidfw/ResourceTypes.h>
#include <androidfw/ResourceTypes.h>
#include <utils/Log.h>
#include <utils/Log.h>


#include <Caches.h>
#include <ResourceCache.h>


#include "Paint.h"
#include "Paint.h"
#include "Canvas.h"
#include "Canvas.h"
@@ -80,9 +80,9 @@ public:
    static void finalize(JNIEnv* env, jobject, jlong patchHandle) {
    static void finalize(JNIEnv* env, jobject, jlong patchHandle) {
        int8_t* patch = reinterpret_cast<int8_t*>(patchHandle);
        int8_t* patch = reinterpret_cast<int8_t*>(patchHandle);
#ifdef USE_OPENGL_RENDERER
#ifdef USE_OPENGL_RENDERER
        if (android::uirenderer::Caches::hasInstance()) {
        if (android::uirenderer::ResourceCache::hasInstance()) {
            Res_png_9patch* p = (Res_png_9patch*) patch;
            Res_png_9patch* p = (Res_png_9patch*) patch;
            android::uirenderer::Caches::getInstance().resourceCache.destructor(p);
            android::uirenderer::ResourceCache::getInstance().destructor(p);
            return;
            return;
        }
        }
#endif // USE_OPENGL_RENDERER
#endif // USE_OPENGL_RENDERER
+3 −3
Original line number Original line Diff line number Diff line
@@ -27,7 +27,7 @@
#include "SkPath.h"
#include "SkPath.h"
#include "SkPathOps.h"
#include "SkPathOps.h"


#include <Caches.h>
#include <ResourceCache.h>
#include <vector>
#include <vector>
#include <map>
#include <map>


@@ -39,8 +39,8 @@ public:
    static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) {
    static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) {
        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
        SkPath* obj = reinterpret_cast<SkPath*>(objHandle);
#ifdef USE_OPENGL_RENDERER
#ifdef USE_OPENGL_RENDERER
        if (android::uirenderer::Caches::hasInstance()) {
        if (android::uirenderer::ResourceCache::hasInstance()) {
            android::uirenderer::Caches::getInstance().resourceCache.destructor(obj);
            android::uirenderer::ResourceCache::getInstance().destructor(obj);
            return;
            return;
        }
        }
#endif
#endif
+0 −1
Original line number Original line Diff line number Diff line
@@ -340,7 +340,6 @@ public:
    TessellationCache tessellationCache;
    TessellationCache tessellationCache;
    TextDropShadowCache dropShadowCache;
    TextDropShadowCache dropShadowCache;
    FboCache fboCache;
    FboCache fboCache;
    ResourceCache resourceCache;


    GammaFontRenderer* fontRenderer;
    GammaFontRenderer* fontRenderer;


+8 −9
Original line number Original line Diff line number Diff line
@@ -39,29 +39,28 @@ DisplayListData::~DisplayListData() {
}
}


void DisplayListData::cleanupResources() {
void DisplayListData::cleanupResources() {
    Caches& caches = Caches::getInstance();
    ResourceCache& resourceCache = ResourceCache::getInstance();
    caches.unregisterFunctors(functors.size());
    resourceCache.lock();
    caches.resourceCache.lock();


    for (size_t i = 0; i < bitmapResources.size(); i++) {
    for (size_t i = 0; i < bitmapResources.size(); i++) {
        caches.resourceCache.decrementRefcountLocked(bitmapResources.itemAt(i));
        resourceCache.decrementRefcountLocked(bitmapResources.itemAt(i));
    }
    }


    for (size_t i = 0; i < ownedBitmapResources.size(); i++) {
    for (size_t i = 0; i < ownedBitmapResources.size(); i++) {
        const SkBitmap* bitmap = ownedBitmapResources.itemAt(i);
        const SkBitmap* bitmap = ownedBitmapResources.itemAt(i);
        caches.resourceCache.decrementRefcountLocked(bitmap);
        resourceCache.decrementRefcountLocked(bitmap);
        caches.resourceCache.destructorLocked(bitmap);
        resourceCache.destructorLocked(bitmap);
    }
    }


    for (size_t i = 0; i < patchResources.size(); i++) {
    for (size_t i = 0; i < patchResources.size(); i++) {
        caches.resourceCache.decrementRefcountLocked(patchResources.itemAt(i));
        resourceCache.decrementRefcountLocked(patchResources.itemAt(i));
    }
    }


    for (size_t i = 0; i < sourcePaths.size(); i++) {
    for (size_t i = 0; i < sourcePaths.size(); i++) {
        caches.resourceCache.decrementRefcountLocked(sourcePaths.itemAt(i));
        resourceCache.decrementRefcountLocked(sourcePaths.itemAt(i));
    }
    }


    caches.resourceCache.unlock();
    resourceCache.unlock();


    for (size_t i = 0; i < paints.size(); i++) {
    for (size_t i = 0; i < paints.size(); i++) {
        delete paints.itemAt(i);
        delete paints.itemAt(i);
Loading