Merge "Improve performance of unclipped save layers."
This commit is contained in:
committed by
Android (Google) Code Review
commit
eaa8ba1692
@@ -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},
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -18,6 +18,7 @@ X(Flush)
|
||||
X(Save)
|
||||
X(Restore)
|
||||
X(SaveLayer)
|
||||
X(SaveBehind)
|
||||
X(Concat)
|
||||
X(SetMatrix)
|
||||
X(Translate)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "hwui/PaintFilter.h"
|
||||
#include "pipeline/skia/AnimatedDrawables.h"
|
||||
|
||||
#include <SkAndroidFrameworkUtils.h>
|
||||
#include <SkAnimatedImage.h>
|
||||
#include <SkCanvasStateUtils.h>
|
||||
#include <SkColorFilter.h>
|
||||
@@ -185,6 +186,11 @@ int SkiaCanvas::saveLayerAlpha(float left, float top, float right, float bottom,
|
||||
return this->saveLayer(left, top, right, bottom, nullptr, flags);
|
||||
}
|
||||
|
||||
int SkiaCanvas::saveUnclippedLayer(int left, int top, int right, int bottom) {
|
||||
SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom);
|
||||
return SkAndroidFrameworkUtils::SaveBehind(mCanvas, &bounds);
|
||||
}
|
||||
|
||||
class SkiaCanvas::Clip {
|
||||
public:
|
||||
Clip(const SkRect& rect, SkClipOp op, const SkMatrix& m)
|
||||
|
||||
@@ -74,6 +74,7 @@ public:
|
||||
SaveFlags::Flags flags) override;
|
||||
virtual int saveLayerAlpha(float left, float top, float right, float bottom, int alpha,
|
||||
SaveFlags::Flags flags) override;
|
||||
virtual int saveUnclippedLayer(int left, int top, int right, int bottom) override;
|
||||
|
||||
virtual void getMatrix(SkMatrix* outMatrix) const override;
|
||||
virtual void setMatrix(const SkMatrix& matrix) override;
|
||||
|
||||
@@ -196,6 +196,7 @@ public:
|
||||
SaveFlags::Flags flags) = 0;
|
||||
virtual int saveLayerAlpha(float left, float top, float right, float bottom, int alpha,
|
||||
SaveFlags::Flags flags) = 0;
|
||||
virtual int saveUnclippedLayer(int, int, int, int) = 0;
|
||||
|
||||
// Matrix
|
||||
virtual void getMatrix(SkMatrix* outMatrix) const = 0;
|
||||
|
||||
Reference in New Issue
Block a user