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

Unified Diff: tools/DumpRecord.cpp

Issue 282233003: Factor out DumpRecord method from dump_record tool for later use (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 7 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
Index: tools/DumpRecord.cpp
diff --git a/tools/dump_record.cpp b/tools/DumpRecord.cpp
similarity index 52%
copy from tools/dump_record.cpp
copy to tools/DumpRecord.cpp
index 2d851e7c9f62dc0e9a4b7130fb0b7d2c56c46a2f..cc80f0fbc00b42650d8c61b8f48e11113b26da32 100644
--- a/tools/dump_record.cpp
+++ b/tools/DumpRecord.cpp
@@ -9,7 +9,6 @@
#include "BenchTimer.h"
#include "LazyDecodeBitmap.h"
mtklein 2014/05/15 15:44:08 Should be you can prune a bunch of these includes
hal.canary 2014/05/15 15:59:27 Done.
-#include "SkCommandLineFlags.h"
#include "SkGraphics.h"
#include "SkOSFile.h"
#include "SkPicture.h"
@@ -19,15 +18,17 @@
#include "SkRecorder.h"
#include "SkStream.h"
-DEFINE_string2(skps, r, "", ".SKPs to dump.");
-DEFINE_string(match, "", "The usual filters on file names to dump.");
-DEFINE_bool2(optimize, O, false, "Run SkRecordOptimize before dumping.");
-DEFINE_int32(tile, 1000000000, "Simulated tile size.");
-DEFINE_bool(timeWithCommand, false, "If true, print time next to command, else in first column.");
+#include "DumpRecord.h"
+
+namespace {
class Dumper {
public:
- explicit Dumper(SkCanvas* canvas, int count) : fDigits(0), fIndent(0), fDraw(canvas) {
+ explicit Dumper(SkCanvas* canvas, int count, bool timeWithCommand)
+ : fDigits(0)
+ , fIndent(0)
+ , fDraw(canvas)
+ , fTimeWithCommand(timeWithCommand) {
while (count > 0) {
count /= 10;
fDigits++;
@@ -74,14 +75,14 @@ public:
private:
template <typename T>
void printNameAndTime(const T& command, double time) {
- if (!FLAGS_timeWithCommand) {
+ if (!fTimeWithCommand) {
printf("%6.1f ", time * 1000);
}
printf("%*d ", fDigits, fDraw.index());
for (int i = 0; i < fIndent; i++) {
putchar('\t');
}
- if (FLAGS_timeWithCommand) {
+ if (fTimeWithCommand) {
printf("%6.1f ", time * 1000);
}
puts(NameOf(command));
@@ -103,62 +104,19 @@ private:
int fDigits;
int fIndent;
SkRecords::Draw fDraw;
+ const bool fTimeWithCommand;
};
+} // namespace
-static void dump(const char* name, int w, int h, const SkRecord& record) {
- SkBitmap bitmap;
- bitmap.allocN32Pixels(w, h);
- SkCanvas canvas(bitmap);
- canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLAGS_tile)));
-
- printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name);
+////////////////////////////////////////////////////////////////////////////////
mtklein 2014/05/15 15:44:08 These things are just noise :(
hal.canary 2014/05/15 15:59:27 Done.
- for (Dumper dumper(&canvas, record.count()); dumper.index() < record.count(); dumper.next()) {
+void DumpRecord(const SkRecord& record,
+ SkCanvas* canvas,
+ bool timeWithCommand) {
+ for (Dumper dumper(canvas, record.count(), timeWithCommand);
+ dumper.index() < record.count();
+ dumper.next()) {
record.visit<void>(dumper.index(), dumper);
}
}
-
-int tool_main(int argc, char** argv);
-int tool_main(int argc, char** argv) {
- SkCommandLineFlags::Parse(argc, argv);
- SkAutoGraphics ag;
-
- for (int i = 0; i < FLAGS_skps.count(); i++) {
- if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) {
- continue;
- }
-
- SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(FLAGS_skps[i]));
- if (!stream) {
- SkDebugf("Could not read %s.\n", FLAGS_skps[i]);
- exit(1);
- }
- SkAutoTUnref<SkPicture> src(
- SkPicture::CreateFromStream(stream, sk_tools::LazyDecodeBitmap));
- if (!src) {
- SkDebugf("Could not read %s as an SkPicture.\n", FLAGS_skps[i]);
- exit(1);
- }
- const int w = src->width(), h = src->height();
-
- SkRecord record;
- SkRecorder canvas(SkRecorder::kWriteOnly_Mode, &record, w, h);
- src->draw(&canvas);
-
-
- if (FLAGS_optimize) {
- SkRecordOptimize(&record);
- }
-
- dump(FLAGS_skps[i], w, h, record);
- }
-
- return 0;
-}
-
-#if !defined SK_BUILD_FOR_IOS
-int main(int argc, char * const argv[]) {
- return tool_main(argc, (char**) argv);
-}
-#endif
« tools/DumpRecord.h ('K') | « tools/DumpRecord.h ('k') | tools/dump_record.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698