From d6dcacd4fe0ef668e3c7f07b4a3709249efd3585 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Wed, 14 May 2014 20:26:00 +0000 Subject: [PATCH] DM: tweaks - translate filenames to task names instead of using a verbatim mode in WriteTask - add an option to write out only PNG data to the .png if you don't need -r to work BUG=skia: R=reed@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/288823002 git-svn-id: http://skia.googlecode.com/svn/trunk@14742 2bbb7eff-a529-9590-31e7-b0007b416f81 --- dm/DMSKPTask.cpp | 15 ++++++++++++--- dm/DMWriteTask.cpp | 19 ++++++++++--------- dm/DMWriteTask.h | 7 +------ 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/dm/DMSKPTask.cpp b/dm/DMSKPTask.cpp index 3eb4c5d6f1..53f8408b99 100644 --- a/dm/DMSKPTask.cpp +++ b/dm/DMSKPTask.cpp @@ -5,8 +5,17 @@ namespace DM { -SKPTask::SKPTask(Reporter* r, TaskRunner* tr, SkPicture* pic, SkString name) - : CpuTask(r, tr), fPicture(SkRef(pic)), fName(name) {} +// foo_bar.skp -> foo-bar_skp +static SkString filename_to_task_name(SkString filename) { + for (size_t i = 0; i < filename.size(); i++) { + if ('_' == filename[i]) { filename[i] = '-'; } + if ('.' == filename[i]) { filename[i] = '_'; } + } + return filename; +} + +SKPTask::SKPTask(Reporter* r, TaskRunner* tr, SkPicture* pic, SkString filename) + : CpuTask(r, tr), fPicture(SkRef(pic)), fName(filename_to_task_name(filename)) {} void SKPTask::draw() { SkBitmap bitmap; @@ -17,7 +26,7 @@ void SKPTask::draw() { (*this, fPicture, bitmap, RecordTask::kNoOptimize_Mode))); this->spawnChild(SkNEW_ARGS(RecordTask, (*this, fPicture, bitmap, RecordTask::kOptimize_Mode))); - this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap, WriteTask::kVerbatim_Mode))); + this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); } } // namespace DM diff --git a/dm/DMWriteTask.cpp b/dm/DMWriteTask.cpp index cfac4152e3..7c9bb628a7 100644 --- a/dm/DMWriteTask.cpp +++ b/dm/DMWriteTask.cpp @@ -9,6 +9,8 @@ #include "SkString.h" DEFINE_string2(writePath, w, "", "If set, write GMs here as .pngs."); +DEFINE_bool(writePngOnly, false, "If true, don't encode raw bitmap after .png data. " + "This means -r won't work, but skdiff will still work fine."); namespace DM { @@ -26,16 +28,12 @@ static int split_suffixes(int N, const char* name, SkTArray* out) { return consumed; } -WriteTask::WriteTask(const Task& parent, SkBitmap bitmap, Mode mode) +WriteTask::WriteTask(const Task& parent, SkBitmap bitmap) : CpuTask(parent), fBitmap(bitmap) { - if (mode == kVerbatim_Mode) { - fGmName.set(parent.name()); - } else { - const int suffixes = parent.depth() + 1; - const SkString& name = parent.name(); - const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), &fSuffixes); - fGmName.set(name.c_str(), name.size()-totalSuffixLength); - } + const int suffixes = parent.depth() + 1; + const SkString& name = parent.name(); + const int totalSuffixLength = split_suffixes(suffixes, name.c_str(), &fSuffixes); + fGmName.set(name.c_str(), name.size()-totalSuffixLength); } void WriteTask::makeDirOrFail(SkString dir) { @@ -61,6 +59,9 @@ struct PngAndRaw { SkDebugf("Can't encode a PNG.\n"); return false; } + if (FLAGS_writePngOnly) { + return true; + } // Pad out so the raw pixels start 4-byte aligned. const uint32_t maxPadding = 0; diff --git a/dm/DMWriteTask.h b/dm/DMWriteTask.h index 121dc0d13e..a90f66aec5 100644 --- a/dm/DMWriteTask.h +++ b/dm/DMWriteTask.h @@ -15,13 +15,8 @@ namespace DM { class WriteTask : public CpuTask { public: - enum Mode { - kParseName_Mode, // Parse the parent's name into directories by underscores. - kVerbatim_Mode, // Don't parse the name at all. - }; WriteTask(const Task& parent, // WriteTask must be a child Task. Pass its parent here. - SkBitmap bitmap, // Bitmap to write. - Mode = kParseName_Mode); + SkBitmap bitmap); // Bitmap to write. virtual void draw() SK_OVERRIDE; virtual bool shouldSkip() const SK_OVERRIDE; -- 2.34.1