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

Commit eaa8ba16 authored by Derek Sollenberger's avatar Derek Sollenberger Committed by Android (Google) Code Review
Browse files

Merge "Improve performance of unclipped save layers."

parents 7bfbe976 24fc901e
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -102,6 +102,10 @@ static jint saveLayerAlpha(jlong canvasHandle, jfloat l, jfloat t,
    return static_cast<jint>(get_canvas(canvasHandle)->saveLayerAlpha(l, t, r, b, alpha, flags));
}

static jint saveUnclippedLayer(jlong canvasHandle, jint l, jint t, jint r, jint b) {
    return reinterpret_cast<jint>(get_canvas(canvasHandle)->saveUnclippedLayer(l, t, r, b));
}

static bool restore(jlong canvasHandle) {
    Canvas* canvas = get_canvas(canvasHandle);
    if (canvas->getSaveCount() <= 1) {
@@ -651,6 +655,7 @@ static const JNINativeMethod gMethods[] = {
    {"nSave","(JI)I", (void*) CanvasJNI::save},
    {"nSaveLayer","(JFFFFJI)I", (void*) CanvasJNI::saveLayer},
    {"nSaveLayerAlpha","(JFFFFII)I", (void*) CanvasJNI::saveLayerAlpha},
    {"nSaveUnclippedLayer","(JIIII)I", (void*) CanvasJNI::saveUnclippedLayer},
    {"nGetSaveCount","(J)I", (void*) CanvasJNI::getSaveCount},
    {"nRestore","(J)Z", (void*) CanvasJNI::restore},
    {"nRestoreToCount","(JI)V", (void*) CanvasJNI::restoreToCount},
+3 −1
Original line number Diff line number Diff line
@@ -556,7 +556,7 @@ public class Canvas extends BaseCanvas {
     * @hide
     */
    public int saveUnclippedLayer(int left, int top, int right, int bottom) {
        return nSaveLayer(mNativeCanvasWrapper, left, top, right, bottom, 0, 0);
        return nSaveUnclippedLayer(mNativeCanvasWrapper, left, top, right, bottom);
    }

    /**
@@ -1395,6 +1395,8 @@ public class Canvas extends BaseCanvas {
    private static native int nSaveLayerAlpha(long nativeCanvas, float l, float t, float r, float b,
            int alpha, int layerFlags);
    @CriticalNative
    private static native int nSaveUnclippedLayer(long nativeCanvas, int l, int t, int r, int b);
    @CriticalNative
    private static native boolean nRestore(long canvasHandle);
    @CriticalNative
    private static native void nRestoreToCount(long canvasHandle, int saveCount);
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ X(Flush)
X(Save) 
X(Restore) 
X(SaveLayer)
X(SaveBehind)
X(Concat) 
X(SetMatrix) 
X(Translate)
+20 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include "VectorDrawable.h"

#include "SkAndroidFrameworkUtils.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkDrawShadowInfo.h"
@@ -116,6 +117,16 @@ struct SaveLayer final : Op {
                      clipMatrix.isIdentity() ? nullptr : &clipMatrix, flags});
    }
};
struct SaveBehind final : Op {
    static const auto kType = Type::SaveBehind;
    SaveBehind(const SkRect* subset) {
        if (subset) { this->subset = *subset; }
    }
    SkRect  subset = kUnset;
    void draw(SkCanvas* c, const SkMatrix&) const {
        SkAndroidFrameworkUtils::SaveBehind(c, &subset);
    }
};

struct Concat final : Op {
    static const auto kType = Type::Concat;
@@ -579,6 +590,10 @@ void DisplayListData::saveLayer(const SkRect* bounds, const SkPaint* paint,
    this->push<SaveLayer>(0, bounds, paint, backdrop, clipMask, clipMatrix, flags);
}

void DisplayListData::saveBehind(const SkRect* subset) {
    this->push<SaveBehind>(0, subset);
}

void DisplayListData::concat(const SkMatrix& matrix) {
    this->push<Concat>(0, matrix);
}
@@ -848,6 +863,11 @@ void RecordingCanvas::willRestore() {
    fDL->restore();
}

bool RecordingCanvas::onDoSaveBehind(const SkRect* subset) {
    fDL->saveBehind(subset);
    return false;
}

void RecordingCanvas::didConcat(const SkMatrix& matrix) {
    fDL->concat(matrix);
}
+2 −0
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ private:
    void save();
    void saveLayer(const SkRect*, const SkPaint*, const SkImageFilter*, const SkImage*,
                   const SkMatrix*, SkCanvas::SaveLayerFlags);
    void saveBehind(const SkRect*);
    void restore();

    void concat(const SkMatrix&);
@@ -146,6 +147,7 @@ public:
    void willSave() override;
    SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
    void willRestore() override;
    bool onDoSaveBehind(const SkRect*) override;

    void onFlush() override;

Loading