record drawfilters

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2303033002

Review-Url: https://codereview.chromium.org/2303033002
This commit is contained in:
reed 2016-09-02 04:56:53 -07:00 committed by Commit bot
parent 400a93bd6c
commit 6ae6969434
5 changed files with 37 additions and 5 deletions

View File

@ -57,12 +57,9 @@ protected:
SkRect r = { 20, 20, 100, 100 };
canvas->setDrawFilter(nullptr);
canvas->drawRect(r, p);
TestFilter redNoBlur;
canvas->setDrawFilter(&redNoBlur);
canvas->setDrawFilter(new TestFilter)->unref();
canvas->translate(120.0f, 40.0f);
canvas->drawRect(r, p);
// Must unset if the DrawFilter is from the stack to avoid refcount errors!
canvas->setDrawFilter(nullptr);
}

View File

@ -7,6 +7,7 @@
#include "SkCanvas.h"
#include "SkData.h"
#include "SkDrawFilter.h"
#include "SkImageFilter.h"
#include "SkLiteDL.h"
#include "SkMath.h"
@ -52,7 +53,7 @@ static void make_threadsafe(SkPath* path, SkMatrix* matrix) {
namespace {
#define TYPES(M) \
M(Save) M(Restore) M(SaveLayer) \
M(SetDrawFilter) M(Save) M(Restore) M(SaveLayer) \
M(Concat) M(SetMatrix) M(Translate) M(TranslateZ) \
M(ClipPath) M(ClipRect) M(ClipRRect) M(ClipRegion) \
M(DrawPaint) M(DrawPath) M(DrawRect) M(DrawRegion) M(DrawOval) M(DrawArc) \
@ -75,6 +76,19 @@ namespace {
};
static_assert(sizeof(Op) == 4, "");
struct SetDrawFilter final : Op {
#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
static const auto kType = Type::SetDrawFilter;
SetDrawFilter(SkDrawFilter* df) : drawFilter(sk_ref_sp(df)) {}
sk_sp<SkDrawFilter> drawFilter;
#endif
void draw(SkCanvas* c, const SkMatrix&) {
#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
c->setDrawFilter(drawFilter.get());
#endif
}
};
struct Save final : Op {
static const auto kType = Type::Save;
void draw(SkCanvas* c, const SkMatrix&) { c->save(); }
@ -566,6 +580,12 @@ inline void SkLiteDL::map(const Fn fns[], Args... args) {
}
}
#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
void SkLiteDL::setDrawFilter(SkDrawFilter* df) {
this->push<SetDrawFilter>(0, df);
}
#endif
void SkLiteDL:: save() { this->push <Save>(0); }
void SkLiteDL::restore() { this->push<Restore>(0); }
void SkLiteDL::saveLayer(const SkRect* bounds, const SkPaint* paint,

View File

@ -23,6 +23,10 @@ public:
void makeThreadsafe();
bool empty() const { return fUsed == 0; }
#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
void setDrawFilter(SkDrawFilter*);
#endif
void save();
void saveLayer(const SkRect*, const SkPaint*, const SkImageFilter*, SkCanvas::SaveLayerFlags);
void restore();

View File

@ -22,6 +22,13 @@ sk_sp<SkSurface> SkLiteRecorder::onNewSurface(const SkImageInfo&, const SkSurfac
return nullptr;
}
#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
SkDrawFilter* SkLiteRecorder::setDrawFilter(SkDrawFilter* df) {
fDL->setDrawFilter(df);
return SkCanvas::setDrawFilter(df);
}
#endif
void SkLiteRecorder::willSave() { fDL->save(); }
SkCanvas::SaveLayerStrategy SkLiteRecorder::getSaveLayerStrategy(const SaveLayerRec& rec) {
fDL->saveLayer(rec.fBounds, rec.fPaint, rec.fBackdrop, rec.fSaveLayerFlags);

View File

@ -19,6 +19,10 @@ public:
sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
SkDrawFilter* setDrawFilter(SkDrawFilter*) override;
#endif
void willSave() override;
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
void willRestore() override;