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

Commit 77c9990a authored by Android (Google) Code Review's avatar Android (Google) Code Review
Browse files

Merge change 599 into donut

* changes:
  Add call to (new) Canvas.freeCaches() in response to low-memory
parents b8adcad6 caf0df1b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -3497,6 +3497,9 @@ public final class ActivityThread {
            EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased);
        }
        
        // Ask graphics to free up as much as possible (font/image caches)
        Canvas.freeCaches();

        BinderInternal.forceGc("mem");
    }

+7 −2
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@
#include "SkCanvas.h"
#include "SkDevice.h"
#include "SkGLCanvas.h"
#include "SkGraphics.h"
#include "SkImageRef_GlobalPool.h"
#include "SkShader.h"
#include "SkTemplates.h"

@@ -58,8 +60,11 @@ public:
        return new SkGLCanvas;
    }
    
    static void freeGlCaches(JNIEnv* env, jobject) {
    static void freeCaches(JNIEnv* env, jobject) {
        // these are called in no particular order
        SkGLCanvas::DeleteAllTextures();
        SkImageRef_GlobalPool::SetRAMUsed(0);
        SkGraphics::SetFontCacheUsed(0);
    }
    
    static jboolean isOpaque(JNIEnv* env, jobject jcanvas) {
@@ -933,7 +938,7 @@ static JNINativeMethod gCanvasMethods[] = {
        (void*) SkCanvasGlue::drawTextOnPath__StringPathFFPaint},
    {"native_drawPicture", "(II)V", (void*) SkCanvasGlue::drawPicture},

    {"freeGlCaches", "()V", (void*) SkCanvasGlue::freeGlCaches}
    {"freeCaches", "()V", (void*) SkCanvasGlue::freeCaches}
};

#include <android_runtime/AndroidRuntime.h>
+11 −1
Original line number Diff line number Diff line
@@ -112,7 +112,9 @@ public class Canvas {
     * on behalf of the Canvas. Any subsequent drawing with a GL-backed Canvas
     * will have to recreate those resources.
     */
    public static native void freeGlCaches();
    public static void freeGlCaches() {
        freeCaches();
    }
        
    /**
     * Specify a bitmap for the canvas to draw into.
@@ -1405,6 +1407,14 @@ public class Canvas {
        finalizer(mNativeCanvas);
    }

    /**
     * Free up as much memory as possible from private caches (e.g. fonts,
     * images)
     *
     * @hide - for now
     */
    public static native void freeCaches();

    private static native int initRaster(int nativeBitmapOrZero);
    private static native int initGL();
    private static native void native_setBitmap(int nativeCanvas, int bitmap);