diff options
author | 2012-12-07 20:56:13 +0000 | |
---|---|---|
committer | 2012-12-07 20:56:13 +0000 | |
commit | d3d377f1d6f2b4450ca34a3c1b9de880b8a0632c (patch) | |
tree | a38882e6f449d1095e433ef474a474c5801aacf4 /tools/filtermain.cpp | |
parent | 5f97114fd28e03e8c4c1c22c924d383b45cdced1 (diff) |
Update filter tool to write out paths to .cpp file
https://codereview.appspot.com/6843125/
git-svn-id: http://skia.googlecode.com/svn/trunk@6714 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools/filtermain.cpp')
-rw-r--r-- | tools/filtermain.cpp | 72 |
1 files changed, 63 insertions, 9 deletions
diff --git a/tools/filtermain.cpp b/tools/filtermain.cpp index 5dbdc22f62..28020cd02a 100644 --- a/tools/filtermain.cpp +++ b/tools/filtermain.cpp @@ -15,14 +15,16 @@ #include "SkPictureRecord.h" #include "SkStream.h" #include "picture_utils.h" +#include "path_utils.h" static void usage() { - SkDebugf("Usage: filter -i inFile [-o outFile] [-t textureDir] [-h|--help]"); - SkDebugf("\n\n"); + SkDebugf("Usage: filter -i inFile [-o outFile] [--input-dir path] [--output-dir path]\n"); + SkDebugf(" [-p pathFile] [-t textureDir] [-h|--help]\n\n"); SkDebugf(" -i inFile : file to file.\n"); SkDebugf(" -o outFile : result of filtering.\n"); SkDebugf(" --input-dir : process all files in dir with .skp extension.\n"); SkDebugf(" --output-dir : results of filtering the input dir.\n"); + SkDebugf(" -p pathFile : file in which to place compileable path data.\n"); SkDebugf(" -t textureDir : directory in which to place textures. (only available w/ single file)\n"); SkDebugf(" -h|--help : Show this help message.\n"); } @@ -30,12 +32,30 @@ static void usage() { // SkFilterRecord allows the filter to manipulate the read in SkPicture class SkFilterRecord : public SkPictureRecord { public: - SkFilterRecord(uint32_t recordFlags, SkDevice* device) + SkFilterRecord(uint32_t recordFlags, SkDevice* device, SkFILEWStream* pathStream) : INHERITED(recordFlags, device) , fTransSkipped(0) , fTransTot(0) , fScalesSkipped(0) - , fScalesTot(0) { + , fScalesTot(0) + , fPathStream(pathStream) { + } + + virtual ~SkFilterRecord() { + } + + virtual bool clipPath(const SkPath& path, SkRegion::Op op, bool doAntiAlias) SK_OVERRIDE { + if (!path.isRect(NULL) && 4 < path.countPoints()) { + sk_tools::dump_path(fPathStream, path); + } + return INHERITED::clipPath(path, op, doAntiAlias); + } + + virtual void drawPath(const SkPath& path, const SkPaint& p) SK_OVERRIDE { + if (!path.isRect(NULL) && 4 < path.countPoints()) { + sk_tools::dump_path(fPathStream, path); + } + INHERITED::drawPath(path, p); } virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE { @@ -97,6 +117,7 @@ protected: int fScalesSkipped; int fScalesTot; + SkFILEWStream* fPathStream; private: typedef SkPictureRecord INHERITED; }; @@ -119,7 +140,8 @@ static bool PNGEncodeBitmapToStream(SkWStream* stream, const SkBitmap& bitmap) { return SkImageEncoder::EncodeStream(stream, bitmap, SkImageEncoder::kPNG_Type, 100); } -int filter_picture(const SkString& inFile, const SkString& outFile, const SkString& textureDir) { +int filter_picture(const SkString& inFile, const SkString& outFile, + const SkString& textureDir, SkFILEWStream *pathStream) { SkPicture* inPicture = NULL; SkFILEStream inStream(inFile.c_str()); @@ -136,7 +158,7 @@ int filter_picture(const SkString& inFile, const SkString& outFile, const SkStri bm.setConfig(SkBitmap::kNo_Config, inPicture->width(), inPicture->height()); SkAutoTUnref<SkDevice> dev(SkNEW_ARGS(SkDevice, (bm))); - SkAutoTUnref<SkFilterRecord> filterRecord(SkNEW_ARGS(SkFilterRecord, (0, dev))); + SkAutoTUnref<SkFilterRecord> filterRecord(SkNEW_ARGS(SkFilterRecord, (0, dev, pathStream))); // Playback the read in picture to the SkFilterRecorder to allow filtering filterRecord->beginRecording(); @@ -169,7 +191,7 @@ int tool_main(int argc, char** argv) { return -1; } - SkString inFile, outFile, inDir, outDir, textureDir; + SkString inFile, outFile, inDir, outDir, textureDir, pathFile; char* const* stop = argv + argc; for (++argv; argv < stop; ++argv) { @@ -209,6 +231,15 @@ int tool_main(int argc, char** argv) { usage(); return -1; } + } else if (strcmp(*argv, "-p") == 0) { + argv++; + if (argv < stop && **argv) { + pathFile.set(*argv); + } else { + SkDebugf("missing arg for -p\n"); + usage(); + return -1; + } } else if (strcmp(*argv, "-t") == 0) { argv++; if (argv < stop && **argv) { @@ -234,6 +265,19 @@ int tool_main(int argc, char** argv) { return -1; } + SkFILEWStream *pathStream = NULL; + + if (!pathFile.isEmpty()) { + pathStream = new SkFILEWStream(pathFile.c_str()); + if (!pathStream->isValid()) { + SkDebugf("Could open path file %s\n", pathFile.c_str()); + delete pathStream; + return -1; + } + + sk_tools::dump_path_prefix(pathStream); + } + SkOSFile::Iter iter(inDir.c_str(), "skp"); int failures = 0; SkString inputFilename, outputFilename; @@ -245,16 +289,26 @@ int tool_main(int argc, char** argv) { sk_tools::make_filepath(&outFile, outDir, inputFilename); } SkDebugf("Executing %s\n", inputFilename.c_str()); - filter_picture(inFile, outFile, textureDir); + filter_picture(inFile, outFile, textureDir, pathStream); } while(iter.next(&inputFilename)); } else if (!inFile.isEmpty()) { - filter_picture(inFile, outFile, textureDir); + filter_picture(inFile, outFile, textureDir, pathStream); } else { usage(); + if (NULL != pathStream) { + delete pathStream; + pathStream = NULL; + } return -1; } + if (NULL != pathStream) { + sk_tools::dump_path_suffix(pathStream); + delete pathStream; + pathStream = NULL; + } + SkGraphics::Term(); return 0; } |