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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samplecode/DecodeFile.h ('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 c1958c8973136a53201d5cecad66c21a7c051dd3..85483288c71eef79ef376cab15c8fad0c75fa275 100644
--- a/samplecode/SamplePictFile.cpp
+++ b/samplecode/SamplePictFile.cpp
@@ -55,9 +55,14 @@ public:
fCount = 0;
}
- virtual ~PictFileView() {
+ ~PictFileView() override {
+ this->freePictures();
+ }
+
+ void freePictures() {
for (int i = 0; i < kBBoxTypeCount; ++i) {
SkSafeUnref(fPictures[i]);
+ fPictures[i] = nullptr;
}
}
@@ -94,6 +99,12 @@ protected:
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;
+ case 'F':
+ fFilterQuality = (kNone_SkFilterQuality == fFilterQuality) ?
+ kHigh_SkFilterQuality : kNone_SkFilterQuality;
+ this->freePictures();
+ this->inval(nullptr);
+ return true;
default: break;
}
}
@@ -148,18 +159,19 @@ private:
BBoxType fBBox;
SkSize fTileSize;
int fCount;
+ SkFilterQuality fFilterQuality = kNone_SkFilterQuality;
sk_sp<SkPicture> LoadPicture(const char path[], BBoxType bbox) {
sk_sp<SkPicture> pic;
- SkBitmap bm;
- if (decode_file(path, &bm)) {
- bm.setImmutable();
+ if (sk_sp<SkImage> img = decode_file(path)) {
SkPictureRecorder recorder;
- SkCanvas* can = recorder.beginRecording(SkIntToScalar(bm.width()),
- SkIntToScalar(bm.height()),
+ SkCanvas* can = recorder.beginRecording(SkIntToScalar(img->width()),
+ SkIntToScalar(img->height()),
nullptr, 0);
- can->drawBitmap(bm, 0, 0, nullptr);
+ SkPaint paint;
+ paint.setFilterQuality(fFilterQuality);
+ can->drawImage(img, 0, 0, &paint);
pic = recorder.finishRecordingAsPicture();
} else {
SkFILEStream stream(path);
« 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