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

Commit 1b63e60a authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

Fix use case where the Java Canvas is reused.

When provided with a new bitmap device the canvas will retain
certain information such as it's matrix and clip.

bug: 8167188
Change-Id: I20ac8a24eebc85fb7c147504a103ce9a95b530b3
parent 29ae0663
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -65,6 +65,16 @@ public:
        return bitmap ? new SkCanvas(*bitmap) : new SkCanvas;
    }
    
    static void copyCanvasState(JNIEnv* env, jobject clazz,
                                SkCanvas* srcCanvas, SkCanvas* dstCanvas) {
        if (srcCanvas && dstCanvas) {
            if (NULL != srcCanvas->getDevice() && NULL != dstCanvas->getDevice()) {
                dstCanvas->clipRegion(srcCanvas->getTotalClip());
            }
            dstCanvas->setMatrix(srcCanvas->getTotalMatrix());
        }
    }

    static void freeCaches(JNIEnv* env, jobject) {
        // these are called in no particular order
        SkImageRef_GlobalPool::SetRAMUsed(0);
@@ -948,6 +958,7 @@ static void doDrawTextDecorations(SkCanvas* canvas, jfloat x, jfloat y, jfloat l
static JNINativeMethod gCanvasMethods[] = {
    {"finalizer", "(I)V", (void*) SkCanvasGlue::finalizer},
    {"initRaster","(I)I", (void*) SkCanvasGlue::initRaster},
    {"copyNativeCanvasState","(II)V", (void*) SkCanvasGlue::copyCanvasState},
    {"isOpaque","()Z", (void*) SkCanvasGlue::isOpaque},
    {"getWidth","()I", (void*) SkCanvasGlue::getWidth},
    {"getHeight","()I", (void*) SkCanvasGlue::getHeight},
+2 −0
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ public class Canvas {
        final int oldCanvas = mNativeCanvas;
        mNativeCanvas = nativeCanvas;
        mFinalizer.mNativeCanvas = nativeCanvas;
        copyNativeCanvasState(oldCanvas, mNativeCanvas);
        finalizer(oldCanvas);
    }
    
@@ -1612,6 +1613,7 @@ public class Canvas {
    public static native void freeTextLayoutCaches();

    private static native int initRaster(int nativeBitmapOrZero);
    private static native void copyNativeCanvasState(int srcCanvas, int dstCanvas);
    private static native int native_saveLayer(int nativeCanvas, RectF bounds,
                                               int paint, int layerFlags);
    private static native int native_saveLayer(int nativeCanvas, float l,