Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(691)

Unified Diff: samplecode/SampleApp.cpp

Issue 1177323002: Use SkPaintFilterCanvas for SampleApp paint filtering (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: review comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samplecode/SampleApp.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleApp.cpp
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index ae352aa5de7f9452b2ada156bba2eafc98b9a3a9..7e90e986ace244cf88805db94292864635d78b2c 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);
« no previous file with comments | « samplecode/SampleApp.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698