'F' will toggle filtering for the --picture sample

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2263203002

TBR=

Review-Url: https://codereview.chromium.org/2263203002
This commit is contained in:
reed 2016-08-22 07:41:46 -07:00 committed by Commit bot
parent 35bb74b444
commit ccebcec4ac
2 changed files with 28 additions and 9 deletions

View File

@ -8,9 +8,11 @@
#include "SkBitmap.h"
#include "SkCodec.h"
#include "SkData.h"
#include "SkImage.h"
inline bool decode_file(const char* filename, SkBitmap* bitmap,
SkColorType colorType = kN32_SkColorType, bool requireUnpremul = false) {
static inline bool decode_file(const char* filename, SkBitmap* bitmap,
SkColorType colorType = kN32_SkColorType,
bool requireUnpremul = false) {
SkASSERT(kIndex_8_SkColorType != colorType);
sk_sp<SkData> data(SkData::MakeFromFileName(filename));
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get()));
@ -29,3 +31,8 @@ inline bool decode_file(const char* filename, SkBitmap* bitmap,
return SkCodec::kSuccess == codec->getPixels(info, bitmap->getPixels(), bitmap->rowBytes());
}
static inline sk_sp<SkImage> decode_file(const char filename[]) {
sk_sp<SkData> data(SkData::MakeFromFileName(filename));
return data ? SkImage::MakeFromEncoded(data) : nullptr;
}

View File

@ -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);