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

Unified Diff: samplecode/SamplePictFile.cpp

Issue 1272063002: allow for stepping through a picture with 'n' and 'p' (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 4 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.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SamplePictFile.cpp
diff --git a/samplecode/SamplePictFile.cpp b/samplecode/SamplePictFile.cpp
index a0bab7da4ebd016f45097dd645a729bc4f1325ec..c0973a5042697e2a40ae88e16bd251eb7fc117e3 100644
--- a/samplecode/SamplePictFile.cpp
+++ b/samplecode/SamplePictFile.cpp
@@ -32,6 +32,18 @@
#include "SkGlyphCache.h"
+#include "SkDrawFilter.h"
+class SkCounterDrawFilter : public SkDrawFilter {
+public:
+ SkCounterDrawFilter(int count) : fCount(count) {}
+
+ bool filter(SkPaint*, Type t) override {
+ return --fCount >= 0;
+ }
+
+ int fCount;
+};
+
class PictFileView : public SampleView {
public:
PictFileView(const char name[] = NULL)
@@ -41,6 +53,7 @@ public:
for (int i = 0; i < kBBoxTypeCount; ++i) {
fPictures[i] = NULL;
}
+ fCount = 0;
}
virtual ~PictFileView() {
@@ -76,6 +89,15 @@ protected:
SampleCode::TitleR(evt, name.c_str());
return true;
}
+ SkUnichar uni;
+ if (SampleCode::CharQ(*evt, &uni)) {
+ switch (uni) {
+ case 'n': fCount += 1; this->inval(nullptr); return true;
+ case 'p': fCount -= 1; this->inval(nullptr); return true;
+ case 's': fCount = 0; this->inval(nullptr); return true;
+ default: break;
+ }
+ }
return this->INHERITED::onQuery(evt);
}
@@ -99,7 +121,12 @@ protected:
*picture = LoadPicture(fFilename.c_str(), fBBox);
}
if (*picture) {
+ SkCounterDrawFilter filter(fCount);
+ if (fCount > 0) {
+ canvas->setDrawFilter(&filter);
+ }
canvas->drawPicture(*picture);
+ canvas->setDrawFilter(NULL);
}
#ifdef SK_GLYPHCACHE_TRACK_HASH_STATS
@@ -121,6 +148,7 @@ private:
SkPicture* fPictures[kBBoxTypeCount];
BBoxType fBBox;
SkSize fTileSize;
+ int fCount;
SkPicture* LoadPicture(const char path[], BBoxType bbox) {
SkAutoTUnref<SkPicture> pic;
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698