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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkDumpCanvas.h" 9 #include "SkDumpCanvas.h"
10 #include "SkView.h" 10 #include "SkView.h"
(...skipping 14 matching lines...) Expand all
25 #include "SkTime.h" 25 #include "SkTime.h"
26 #include "SkTypeface.h" 26 #include "SkTypeface.h"
27 #include "SkXfermode.h" 27 #include "SkXfermode.h"
28 28
29 #include "SkStream.h" 29 #include "SkStream.h"
30 #include "SkSurface.h" 30 #include "SkSurface.h"
31 #include "SkXMLParser.h" 31 #include "SkXMLParser.h"
32 32
33 #include "SkGlyphCache.h" 33 #include "SkGlyphCache.h"
34 34
35 #include "SkDrawFilter.h"
36 class SkCounterDrawFilter : public SkDrawFilter {
37 public:
38 SkCounterDrawFilter(int count) : fCount(count) {}
39
40 bool filter(SkPaint*, Type t) override {
41 return --fCount >= 0;
42 }
43
44 int fCount;
45 };
46
35 class PictFileView : public SampleView { 47 class PictFileView : public SampleView {
36 public: 48 public:
37 PictFileView(const char name[] = NULL) 49 PictFileView(const char name[] = NULL)
38 : fFilename(name) 50 : fFilename(name)
39 , fBBox(kNo_BBoxType) 51 , fBBox(kNo_BBoxType)
40 , fTileSize(SkSize::Make(0, 0)) { 52 , fTileSize(SkSize::Make(0, 0)) {
41 for (int i = 0; i < kBBoxTypeCount; ++i) { 53 for (int i = 0; i < kBBoxTypeCount; ++i) {
42 fPictures[i] = NULL; 54 fPictures[i] = NULL;
43 } 55 }
56 fCount = 0;
44 } 57 }
45 58
46 virtual ~PictFileView() { 59 virtual ~PictFileView() {
47 for (int i = 0; i < kBBoxTypeCount; ++i) { 60 for (int i = 0; i < kBBoxTypeCount; ++i) {
48 SkSafeUnref(fPictures[i]); 61 SkSafeUnref(fPictures[i]);
49 } 62 }
50 } 63 }
51 64
52 void onTileSizeChanged(const SkSize &tileSize) override { 65 void onTileSizeChanged(const SkSize &tileSize) override {
53 if (tileSize != fTileSize) { 66 if (tileSize != fTileSize) {
(...skipping 15 matching lines...) Expand all
69 case kRTree_BBoxType: 82 case kRTree_BBoxType:
70 name.append(" <bbox: R>"); 83 name.append(" <bbox: R>");
71 break; 84 break;
72 default: 85 default:
73 SkASSERT(false); 86 SkASSERT(false);
74 break; 87 break;
75 } 88 }
76 SampleCode::TitleR(evt, name.c_str()); 89 SampleCode::TitleR(evt, name.c_str());
77 return true; 90 return true;
78 } 91 }
92 SkUnichar uni;
93 if (SampleCode::CharQ(*evt, &uni)) {
94 switch (uni) {
95 case 'n': fCount += 1; this->inval(nullptr); return true;
96 case 'p': fCount -= 1; this->inval(nullptr); return true;
97 case 's': fCount = 0; this->inval(nullptr); return true;
98 default: break;
99 }
100 }
79 return this->INHERITED::onQuery(evt); 101 return this->INHERITED::onQuery(evt);
80 } 102 }
81 103
82 bool onEvent(const SkEvent& evt) override { 104 bool onEvent(const SkEvent& evt) override {
83 if (evt.isType("PictFileView::toggleBBox")) { 105 if (evt.isType("PictFileView::toggleBBox")) {
84 fBBox = (BBoxType)((fBBox + 1) % kBBoxTypeCount); 106 fBBox = (BBoxType)((fBBox + 1) % kBBoxTypeCount);
85 return true; 107 return true;
86 } 108 }
87 return this->INHERITED::onEvent(evt); 109 return this->INHERITED::onEvent(evt);
88 } 110 }
89 111
90 void onDrawContent(SkCanvas* canvas) override { 112 void onDrawContent(SkCanvas* canvas) override {
91 SkASSERT(static_cast<int>(fBBox) < kBBoxTypeCount); 113 SkASSERT(static_cast<int>(fBBox) < kBBoxTypeCount);
92 SkPicture** picture = fPictures + fBBox; 114 SkPicture** picture = fPictures + fBBox;
93 115
94 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS 116 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS
95 SkGraphics::PurgeFontCache(); 117 SkGraphics::PurgeFontCache();
96 #endif 118 #endif
97 119
98 if (!*picture) { 120 if (!*picture) {
99 *picture = LoadPicture(fFilename.c_str(), fBBox); 121 *picture = LoadPicture(fFilename.c_str(), fBBox);
100 } 122 }
101 if (*picture) { 123 if (*picture) {
124 SkCounterDrawFilter filter(fCount);
125 if (fCount > 0) {
126 canvas->setDrawFilter(&filter);
127 }
102 canvas->drawPicture(*picture); 128 canvas->drawPicture(*picture);
129 canvas->setDrawFilter(NULL);
103 } 130 }
104 131
105 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS 132 #ifdef SK_GLYPHCACHE_TRACK_HASH_STATS
106 SkGlyphCache::Dump(); 133 SkGlyphCache::Dump();
107 SkDebugf("\n"); 134 SkDebugf("\n");
108 #endif 135 #endif
109 } 136 }
110 137
111 private: 138 private:
112 enum BBoxType { 139 enum BBoxType {
113 kNo_BBoxType, 140 kNo_BBoxType,
114 kRTree_BBoxType, 141 kRTree_BBoxType,
115 142
116 kLast_BBoxType = kRTree_BBoxType, 143 kLast_BBoxType = kRTree_BBoxType,
117 }; 144 };
118 static const int kBBoxTypeCount = kLast_BBoxType + 1; 145 static const int kBBoxTypeCount = kLast_BBoxType + 1;
119 146
120 SkString fFilename; 147 SkString fFilename;
121 SkPicture* fPictures[kBBoxTypeCount]; 148 SkPicture* fPictures[kBBoxTypeCount];
122 BBoxType fBBox; 149 BBoxType fBBox;
123 SkSize fTileSize; 150 SkSize fTileSize;
151 int fCount;
124 152
125 SkPicture* LoadPicture(const char path[], BBoxType bbox) { 153 SkPicture* LoadPicture(const char path[], BBoxType bbox) {
126 SkAutoTUnref<SkPicture> pic; 154 SkAutoTUnref<SkPicture> pic;
127 155
128 SkBitmap bm; 156 SkBitmap bm;
129 if (SkImageDecoder::DecodeFile(path, &bm)) { 157 if (SkImageDecoder::DecodeFile(path, &bm)) {
130 bm.setImmutable(); 158 bm.setImmutable();
131 SkPictureRecorder recorder; 159 SkPictureRecorder recorder;
132 SkCanvas* can = recorder.beginRecording(SkIntToScalar(bm.width()), 160 SkCanvas* can = recorder.beginRecording(SkIntToScalar(bm.width()),
133 SkIntToScalar(bm.height()), 161 SkIntToScalar(bm.height()),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 SampleView* CreateSamplePictFileView(const char filename[]) { 214 SampleView* CreateSamplePictFileView(const char filename[]) {
187 return new PictFileView(filename); 215 return new PictFileView(filename);
188 } 216 }
189 217
190 ////////////////////////////////////////////////////////////////////////////// 218 //////////////////////////////////////////////////////////////////////////////
191 219
192 #if 0 220 #if 0
193 static SkView* MyFactory() { return new PictFileView; } 221 static SkView* MyFactory() { return new PictFileView; }
194 static SkViewRegister reg(MyFactory); 222 static SkViewRegister reg(MyFactory);
195 #endif 223 #endif
OLDNEW
« 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