Home | History | Annotate | Download | only in tools
      1 /*
      2  * Copyright 2014 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #include <stdio.h>
      9 
     10 #include "SkCommandLineFlags.h"
     11 #include "SkGraphics.h"
     12 #include "SkPicture.h"
     13 #include "SkRecordOpts.h"
     14 #include "SkRecorder.h"
     15 #include "SkStream.h"
     16 
     17 #include "DumpRecord.h"
     18 #include "LazyDecodeBitmap.h"
     19 
     20 DEFINE_string2(skps, r, "", ".SKPs to dump.");
     21 DEFINE_string(match, "", "The usual filters on file names to dump.");
     22 DEFINE_bool2(optimize, O, false, "Run SkRecordOptimize before dumping.");
     23 DEFINE_int32(tile, 1000000000, "Simulated tile size.");
     24 DEFINE_bool(timeWithCommand, false, "If true, print time next to command, else in first column.");
     25 
     26 static void dump(const char* name, int w, int h, const SkRecord& record) {
     27     SkBitmap bitmap;
     28     bitmap.allocN32Pixels(w, h);
     29     SkCanvas canvas(bitmap);
     30     canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile),
     31                                    SkIntToScalar(FLAGS_tile)));
     32 
     33     printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name);
     34 
     35     DumpRecord(record, &canvas, FLAGS_timeWithCommand);
     36 }
     37 
     38 
     39 int tool_main(int argc, char** argv);
     40 int tool_main(int argc, char** argv) {
     41     SkCommandLineFlags::Parse(argc, argv);
     42     SkAutoGraphics ag;
     43 
     44     for (int i = 0; i < FLAGS_skps.count(); i++) {
     45         if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) {
     46             continue;
     47         }
     48 
     49         SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(FLAGS_skps[i]));
     50         if (!stream) {
     51             SkDebugf("Could not read %s.\n", FLAGS_skps[i]);
     52             exit(1);
     53         }
     54         SkAutoTUnref<SkPicture> src(
     55                 SkPicture::CreateFromStream(stream, sk_tools::LazyDecodeBitmap));
     56         if (!src) {
     57             SkDebugf("Could not read %s as an SkPicture.\n", FLAGS_skps[i]);
     58             exit(1);
     59         }
     60         const int w = src->width(), h = src->height();
     61 
     62         SkRecord record;
     63         SkRecorder canvas(&record, w, h);
     64         src->draw(&canvas);
     65 
     66         if (FLAGS_optimize) {
     67             SkRecordOptimize(&record);
     68         }
     69 
     70         dump(FLAGS_skps[i], w, h, record);
     71     }
     72 
     73     return 0;
     74 }
     75 
     76 #if !defined SK_BUILD_FOR_IOS
     77 int main(int argc, char * const argv[]) {
     78     return tool_main(argc, (char**) argv);
     79 }
     80 #endif
     81