aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2015-06-15 07:07:32 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-06-15 07:07:32 -0700
commit822ace900142aecebc5637454f8361c0d3572f3f (patch)
tree80a0230234ed9742b576dcbcb280226404d57509
parentfd674ddbd6cf403ce009de58c1ba4b2bb660e9ab (diff)
Use SkPaintFilterCanvas for SampleApp paint filtering
(one less SkDrawFilter user) BUG=skia:3587 R=robertphillips@google.com,reed@google.com Review URL: https://codereview.chromium.org/1177323002
-rw-r--r--samplecode/SampleApp.cpp48
-rw-r--r--samplecode/SampleApp.h3
2 files changed, 28 insertions, 23 deletions
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index ae352aa5de..7e90e986ac 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -23,6 +23,7 @@
#include "SkImageEncoder.h"
#include "SkOSFile.h"
#include "SkPaint.h"
+#include "SkPaintFilterCanvas.h"
#include "SkPicture.h"
#include "SkPictureRecorder.h"
#include "SkStream.h"
@@ -463,20 +464,23 @@ static FilterQualityState gFilterQualityStates[] = {
{ kHigh_SkFilterQuality, "High", "F3 " },
};
-class FlagsDrawFilter : public SkDrawFilter {
+class FlagsFilterCanvas : public SkPaintFilterCanvas {
public:
- FlagsDrawFilter(SkOSMenu::TriState lcd, SkOSMenu::TriState aa,
- SkOSMenu::TriState subpixel, int hinting, int filterQuality)
- : fLCDState(lcd)
+ FlagsFilterCanvas(SkCanvas* canvas, SkOSMenu::TriState lcd, SkOSMenu::TriState aa,
+ SkOSMenu::TriState subpixel, int hinting, int filterQuality)
+ : INHERITED(canvas->imageInfo().width(), canvas->imageInfo().height())
+ , fLCDState(lcd)
, fAAState(aa)
, fSubpixelState(subpixel)
, fHintingState(hinting)
- , fFilterQualityIndex(filterQuality)
- {
+ , fFilterQualityIndex(filterQuality) {
SkASSERT((unsigned)filterQuality < SK_ARRAY_COUNT(gFilterQualityStates));
+
+ this->addCanvas(canvas);
}
- virtual bool filter(SkPaint* paint, Type t) {
+protected:
+ void onFilterPaint(SkPaint* paint, Type t) const override {
if (kText_Type == t && SkOSMenu::kMixedState != fLCDState) {
paint->setLCDRenderText(SkOSMenu::kOnState == fLCDState);
}
@@ -492,7 +496,6 @@ public:
if (0 != fHintingState && fHintingState < (int)SK_ARRAY_COUNT(gHintingStates)) {
paint->setHinting(gHintingStates[fHintingState].hinting);
}
- return true;
}
private:
@@ -501,6 +504,8 @@ private:
SkOSMenu::TriState fSubpixelState;
int fHintingState;
int fFilterQualityIndex;
+
+ typedef SkPaintFilterCanvas INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
@@ -1211,10 +1216,24 @@ SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) {
canvas->clipPath(fClipPath, SkRegion::kIntersect_Op, true);
}
+ // Install a flags filter proxy canvas if needed
+ if (fLCDState != SkOSMenu::kMixedState ||
+ fAAState != SkOSMenu::kMixedState ||
+ fSubpixelState != SkOSMenu::kMixedState ||
+ fHintingState > 0 ||
+ fFilterQualityIndex > 0) {
+
+ canvas = SkNEW_ARGS(FlagsFilterCanvas, (canvas, fLCDState, fAAState, fSubpixelState,
+ fHintingState, fFilterQualityIndex));
+ fFlagsFilterCanvas.reset(canvas);
+ }
+
return canvas;
}
#include "SkMultiPictureDraw.h"
void SampleWindow::afterChildren(SkCanvas* orig) {
+ fFlagsFilterCanvas.reset(NULL);
+
if (fSaveToPdf) {
fSaveToPdf = false;
fPDFDocument->endPage();
@@ -1242,8 +1261,6 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
SkAutoTUnref<const SkPicture> picture(fRecorder.endRecording());
if (true) {
- this->installDrawFilter(orig);
-
if (true) {
SkImageInfo info;
size_t rowBytes;
@@ -1337,8 +1354,6 @@ void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) {
canvas->concat(m);
}
- this->installDrawFilter(canvas);
-
if (fMeasureFPS) {
if (SampleView::SetRepeatDraw(child, FPS_REPEAT_COUNT)) {
fMeasureFPS_StartTime = SkTime::GetMSecs();
@@ -1351,10 +1366,6 @@ void SampleWindow::beforeChild(SkView* child, SkCanvas* canvas) {
}
}
-void SampleWindow::afterChild(SkView* child, SkCanvas* canvas) {
- canvas->setDrawFilter(NULL);
-}
-
void SampleWindow::changeZoomLevel(float delta) {
fZoomLevel += delta;
if (fZoomLevel > 0) {
@@ -1434,11 +1445,6 @@ void SampleWindow::showOverview() {
this->loadView(create_overview(fSamples.count(), fSamples.begin()));
}
-void SampleWindow::installDrawFilter(SkCanvas* canvas) {
- canvas->setDrawFilter(new FlagsDrawFilter(fLCDState, fAAState, fSubpixelState,
- fHintingState, fFilterQualityIndex))->unref();
-}
-
void SampleWindow::postAnimatingEvent() {
if (fAnimating) {
(new SkEvent(ANIMATING_EVENTTYPE, this->getSinkID()))->postDelay(ANIMATING_DELAY);
diff --git a/samplecode/SampleApp.h b/samplecode/SampleApp.h
index 8fc1a905b1..44eda1ecd8 100644
--- a/samplecode/SampleApp.h
+++ b/samplecode/SampleApp.h
@@ -145,7 +145,6 @@ protected:
SkCanvas* beforeChildren(SkCanvas*) override;
void afterChildren(SkCanvas*) override;
void beforeChild(SkView* child, SkCanvas* canvas) override;
- void afterChild(SkView* child, SkCanvas* canvas) override;
bool onEvent(const SkEvent& evt) override;
bool onQuery(SkEvent* evt) override;
@@ -164,6 +163,7 @@ private:
SkPictureRecorder fRecorder;
SkAutoTDelete<SkSurface> fDeferredSurface;
SkAutoTDelete<SkDeferredCanvas> fDeferredCanvas;
+ SkAutoTDelete<SkCanvas> fFlagsFilterCanvas;
SkPath fClipPath;
SkTouchGesture fGesture;
@@ -232,7 +232,6 @@ private:
void showZoomer(SkCanvas* canvas);
void updateMatrix();
void postAnimatingEvent();
- void installDrawFilter(SkCanvas*);
int findByTitle(const char*);
void listTitles();
SkSize tileSize() const;