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

Side by Side Diff: samplecode/SamplePictFile.cpp

Issue 2263203002: 'F' will toggle filtering for the --picture sample (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 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/DecodeFile.h ('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 "DecodeFile.h" 8 #include "DecodeFile.h"
9 #include "SampleCode.h" 9 #include "SampleCode.h"
10 #include "SkDumpCanvas.h" 10 #include "SkDumpCanvas.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 PictFileView(const char name[] = nullptr) 48 PictFileView(const char name[] = nullptr)
49 : fFilename(name) 49 : fFilename(name)
50 , fBBox(kNo_BBoxType) 50 , fBBox(kNo_BBoxType)
51 , fTileSize(SkSize::Make(0, 0)) { 51 , fTileSize(SkSize::Make(0, 0)) {
52 for (int i = 0; i < kBBoxTypeCount; ++i) { 52 for (int i = 0; i < kBBoxTypeCount; ++i) {
53 fPictures[i] = nullptr; 53 fPictures[i] = nullptr;
54 } 54 }
55 fCount = 0; 55 fCount = 0;
56 } 56 }
57 57
58 virtual ~PictFileView() { 58 ~PictFileView() override {
59 this->freePictures();
60 }
61
62 void freePictures() {
59 for (int i = 0; i < kBBoxTypeCount; ++i) { 63 for (int i = 0; i < kBBoxTypeCount; ++i) {
60 SkSafeUnref(fPictures[i]); 64 SkSafeUnref(fPictures[i]);
65 fPictures[i] = nullptr;
61 } 66 }
62 } 67 }
63 68
64 void onTileSizeChanged(const SkSize &tileSize) override { 69 void onTileSizeChanged(const SkSize &tileSize) override {
65 if (tileSize != fTileSize) { 70 if (tileSize != fTileSize) {
66 fTileSize = tileSize; 71 fTileSize = tileSize;
67 } 72 }
68 } 73 }
69 74
70 protected: 75 protected:
(...skipping 16 matching lines...) Expand all
87 } 92 }
88 SampleCode::TitleR(evt, name.c_str()); 93 SampleCode::TitleR(evt, name.c_str());
89 return true; 94 return true;
90 } 95 }
91 SkUnichar uni; 96 SkUnichar uni;
92 if (SampleCode::CharQ(*evt, &uni)) { 97 if (SampleCode::CharQ(*evt, &uni)) {
93 switch (uni) { 98 switch (uni) {
94 case 'n': fCount += 1; this->inval(nullptr); return true; 99 case 'n': fCount += 1; this->inval(nullptr); return true;
95 case 'p': fCount -= 1; this->inval(nullptr); return true; 100 case 'p': fCount -= 1; this->inval(nullptr); return true;
96 case 's': fCount = 0; this->inval(nullptr); return true; 101 case 's': fCount = 0; this->inval(nullptr); return true;
102 case 'F':
103 fFilterQuality = (kNone_SkFilterQuality == fFilterQuality) ?
104 kHigh_SkFilterQuality : kNone_SkFilterQuali ty;
105 this->freePictures();
106 this->inval(nullptr);
107 return true;
97 default: break; 108 default: break;
98 } 109 }
99 } 110 }
100 return this->INHERITED::onQuery(evt); 111 return this->INHERITED::onQuery(evt);
101 } 112 }
102 113
103 bool onEvent(const SkEvent& evt) override { 114 bool onEvent(const SkEvent& evt) override {
104 if (evt.isType("PictFileView::toggleBBox")) { 115 if (evt.isType("PictFileView::toggleBBox")) {
105 fBBox = (BBoxType)((fBBox + 1) % kBBoxTypeCount); 116 fBBox = (BBoxType)((fBBox + 1) % kBBoxTypeCount);
106 return true; 117 return true;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 152
142 kLast_BBoxType = kRTree_BBoxType, 153 kLast_BBoxType = kRTree_BBoxType,
143 }; 154 };
144 static const int kBBoxTypeCount = kLast_BBoxType + 1; 155 static const int kBBoxTypeCount = kLast_BBoxType + 1;
145 156
146 SkString fFilename; 157 SkString fFilename;
147 SkPicture* fPictures[kBBoxTypeCount]; 158 SkPicture* fPictures[kBBoxTypeCount];
148 BBoxType fBBox; 159 BBoxType fBBox;
149 SkSize fTileSize; 160 SkSize fTileSize;
150 int fCount; 161 int fCount;
162 SkFilterQuality fFilterQuality = kNone_SkFilterQuality;
151 163
152 sk_sp<SkPicture> LoadPicture(const char path[], BBoxType bbox) { 164 sk_sp<SkPicture> LoadPicture(const char path[], BBoxType bbox) {
153 sk_sp<SkPicture> pic; 165 sk_sp<SkPicture> pic;
154 166
155 SkBitmap bm; 167 if (sk_sp<SkImage> img = decode_file(path)) {
156 if (decode_file(path, &bm)) {
157 bm.setImmutable();
158 SkPictureRecorder recorder; 168 SkPictureRecorder recorder;
159 SkCanvas* can = recorder.beginRecording(SkIntToScalar(bm.width()), 169 SkCanvas* can = recorder.beginRecording(SkIntToScalar(img->width()),
160 SkIntToScalar(bm.height()), 170 SkIntToScalar(img->height()) ,
161 nullptr, 0); 171 nullptr, 0);
162 can->drawBitmap(bm, 0, 0, nullptr); 172 SkPaint paint;
173 paint.setFilterQuality(fFilterQuality);
174 can->drawImage(img, 0, 0, &paint);
163 pic = recorder.finishRecordingAsPicture(); 175 pic = recorder.finishRecordingAsPicture();
164 } else { 176 } else {
165 SkFILEStream stream(path); 177 SkFILEStream stream(path);
166 if (stream.isValid()) { 178 if (stream.isValid()) {
167 pic = SkPicture::MakeFromStream(&stream); 179 pic = SkPicture::MakeFromStream(&stream);
168 } else { 180 } else {
169 SkDebugf("coun't load picture at \"path\"\n", path); 181 SkDebugf("coun't load picture at \"path\"\n", path);
170 } 182 }
171 183
172 if (false) { // re-record 184 if (false) { // re-record
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 SampleView* CreateSamplePictFileView(const char filename[]) { 225 SampleView* CreateSamplePictFileView(const char filename[]) {
214 return new PictFileView(filename); 226 return new PictFileView(filename);
215 } 227 }
216 228
217 ////////////////////////////////////////////////////////////////////////////// 229 //////////////////////////////////////////////////////////////////////////////
218 230
219 #if 0 231 #if 0
220 static SkView* MyFactory() { return new PictFileView; } 232 static SkView* MyFactory() { return new PictFileView; }
221 static SkViewRegister reg(MyFactory); 233 static SkViewRegister reg(MyFactory);
222 #endif 234 #endif
OLDNEW
« no previous file with comments | « samplecode/DecodeFile.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698