aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-24 19:30:41 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-24 19:30:41 +0000
commit63f1127a70428dca12141c0ad12e1103ae8db35f (patch)
treefe73221eec1f5a204b41c9d0114558c7022aa6f5 /tools
parent6f261bed0252e3f3caa595798364e0bf12a2573a (diff)
Make filter tool actually filter the read in SkPicture
Diffstat (limited to 'tools')
-rw-r--r--tools/filtermain.cpp86
1 files changed, 68 insertions, 18 deletions
diff --git a/tools/filtermain.cpp b/tools/filtermain.cpp
index b415219564..cfd6487879 100644
--- a/tools/filtermain.cpp
+++ b/tools/filtermain.cpp
@@ -26,7 +26,33 @@ static void usage() {
class SkFilterRecord : public SkPictureRecord {
public:
SkFilterRecord(uint32_t recordFlags, SkDevice* device)
- : INHERITED(recordFlags, device) {
+ : INHERITED(recordFlags, device)
+ , fTransSkipped(0)
+ , fTransTot(0)
+ , fScalesSkipped(0)
+ , fScalesTot(0) {
+ }
+
+ virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE {
+ ++fTransTot;
+
+ if (0 == dx && 0 == dy) {
+ ++fTransSkipped;
+ return true;
+ }
+
+ return INHERITED::translate(dx, dy);
+ }
+
+ virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE {
+ ++fScalesTot;
+
+ if (SK_Scalar1 == sx && SK_Scalar1 == sy) {
+ ++fScalesSkipped;
+ return true;
+ }
+
+ return INHERITED::scale(sx, sy);
}
void saveImages(const SkString& path) {
@@ -50,10 +76,35 @@ public:
bitmaps->unref();
}
+ void report() {
+ SkDebugf("%d Trans skipped (out of %d)\n", fTransSkipped, fTransTot);
+ SkDebugf("%d Scales skipped (out of %d)\n", fScalesSkipped, fScalesTot);
+ }
+
+protected:
+ int fTransSkipped;
+ int fTransTot;
+
+ int fScalesSkipped;
+ int fScalesTot;
+
private:
typedef SkPictureRecord INHERITED;
};
+// Wrap SkPicture to allow installation of a SkFilterRecord object
+class SkFilterPicture : public SkPicture {
+public:
+ SkFilterPicture(SkPictureRecord* record) {
+ fRecord = record;
+ SkSafeRef(fRecord);
+ }
+
+private:
+ typedef SkPicture INHERITED;
+};
+
+
// This function is not marked as 'static' so it can be referenced externally
// in the iOS build.
int tool_main(int argc, char** argv) {
@@ -122,29 +173,28 @@ int tool_main(int argc, char** argv) {
return -1;
}
- if (!outFile.isEmpty()) {
- // Playback the read in picture to another picture to allow whatever
- // translation occurs inside Skia to occur
- SkPicture outPicture;
- inPicture->draw(outPicture.beginRecording(inPicture->width(), inPicture->height()));
- outPicture.endRecording();
+ SkBitmap bm;
+ bm.setConfig(SkBitmap::kNo_Config, inPicture->width(), inPicture->height());
+ SkAutoTUnref<SkDevice> dev(SkNEW_ARGS(SkDevice, (bm)));
+
+ SkAutoTUnref<SkFilterRecord> filterRecord(SkNEW_ARGS(SkFilterRecord, (0, dev)));
+ // Playback the read in picture to the SkFilterRecorder to allow filtering
+ filterRecord->beginRecording();
+ inPicture->draw(filterRecord);
+ filterRecord->endRecording();
+
+ filterRecord->report();
+
+ if (!outFile.isEmpty()) {
+ SkFilterPicture outPicture(filterRecord);
SkFILEWStream outStream(outFile.c_str());
+
outPicture.serialize(&outStream);
}
if (!textureDir.isEmpty()) {
- SkBitmap bm;
- bm.setConfig(SkBitmap::kNo_Config, inPicture->width(), inPicture->height());
- SkAutoTUnref<SkDevice> dev(SkNEW_ARGS(SkDevice, (bm)));
-
- SkFilterRecord filterRecord(0, dev);
-
- filterRecord.beginRecording();
- inPicture->draw(&filterRecord);
- filterRecord.endRecording();
-
- filterRecord.saveImages(textureDir);
+ filterRecord->saveImages(textureDir);
}
SkGraphics::Term();