Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / tools / render_pictures_main.cpp
index 850053c..13cef09 100644 (file)
 #include "picture_utils.h"
 
 // Flags used by this file, alphabetically:
-DEFINE_int32(clone, 0, "Clone the picture n times before rendering.");
+DEFINE_bool(bench_record, false, "If true, drop into an infinite loop of recording the picture.");
 DECLARE_bool(deferImageDecoding);
+DEFINE_string(descriptions, "", "one or more key=value pairs to add to the descriptions section "
+              "of the JSON summary.");
 DEFINE_int32(maxComponentDiff, 256, "Maximum diff on a component, 0 - 256. Components that differ "
              "by more than this amount are considered errors, though all diffs are reported. "
              "Requires --validate.");
 DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
               "pixel mismatches into this directory.");
+DEFINE_bool(preprocess, false, "If true, perform device specific preprocessing before rendering.");
 DEFINE_string(readJsonSummaryPath, "", "JSON file to read image expectations from.");
 DECLARE_string(readPath);
 DEFINE_bool(writeChecksumBasedFilenames, false,
@@ -48,10 +51,6 @@ DEFINE_bool(validate, false, "Verify that the rendered image contains the same p
             "the picture rendered in simple mode. When used in conjunction with --bbh, results "
             "are validated against the picture rendered in the same mode, but without the bbh.");
 
-DEFINE_bool(bench_record, false, "If true, drop into an infinite loop of recording the picture.");
-
-DEFINE_bool(preprocess, false, "If true, perform device specific preprocessing before rendering.");
-
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 
 /**
@@ -124,7 +123,7 @@ static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitma
     SkString name = SkStringPrintf("%s_%d%s", gInputFileName.c_str(), gImageNo++,
                                    get_suffix_from_format(format));
     SkString dir(FLAGS_writePath[0]);
-    outPath = SkOSPath::SkPathJoin(dir.c_str(), name.c_str());
+    outPath = SkOSPath::Join(dir.c_str(), name.c_str());
     SkFILEWStream fileStream(outPath.c_str());
     if (!(fileStream.isValid() && fileStream.write(buffer, size))) {
         SkDebugf("Failed to write encoded data to \"%s\"\n", outPath.c_str());
@@ -143,7 +142,7 @@ static bool render_picture_internal(const SkString& inputPath, const SkString* w
                                     const SkString* mismatchPath,
                                     sk_tools::PictureRenderer& renderer,
                                     SkBitmap** out) {
-    SkString inputFilename = SkOSPath::SkBasename(inputPath.c_str());
+    SkString inputFilename = SkOSPath::Basename(inputPath.c_str());
     SkString writePathString;
     if (NULL != writePath && writePath->size() > 0 && !FLAGS_writeEncodedImages) {
         writePathString.set(*writePath);
@@ -173,23 +172,25 @@ static bool render_picture_internal(const SkString& inputPath, const SkString* w
 
     SkDebugf("deserializing... %s\n", inputPath.c_str());
 
-    SkPicture* picture = SkPicture::CreateFromStream(&inputStream, proc);
+    SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, proc));
 
     if (NULL == picture) {
         SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
         return false;
     }
 
-    while (FLAGS_bench_record) {
+    if (FLAGS_preprocess) {
+        // Because the GPU preprocessing step relies on the in-memory picture
+        // statistics we need to rerecord the picture here
         SkPictureRecorder recorder;
         picture->draw(recorder.beginRecording(picture->width(), picture->height(), NULL, 0));
-        SkAutoTUnref<SkPicture> other(recorder.endRecording());
+        picture.reset(recorder.endRecording());
     }
 
-    for (int i = 0; i < FLAGS_clone; ++i) {
-        SkPicture* clone = picture->clone();
-        SkDELETE(picture);
-        picture = clone;
+    while (FLAGS_bench_record) {
+        SkPictureRecorder recorder;
+        picture->draw(recorder.beginRecording(picture->width(), picture->height(), NULL, 0));
+        SkAutoTUnref<SkPicture> other(recorder.endRecording());
     }
 
     SkDebugf("drawing... [%i %i] %s\n", picture->width(), picture->height(),
@@ -214,7 +215,6 @@ static bool render_picture_internal(const SkString& inputPath, const SkString* w
 
     renderer.end();
 
-    SkDELETE(picture);
     return success;
 }
 
@@ -352,7 +352,7 @@ static bool render_picture(const SkString& inputPath, const SkString* writePath,
     if (FLAGS_writeWholeImage) {
         sk_tools::force_all_opaque(*bitmap);
 
-        SkString inputFilename = SkOSPath::SkBasename(inputPath.c_str());
+        SkString inputFilename = SkOSPath::Basename(inputPath.c_str());
         SkString outputFilename(inputFilename);
         sk_tools::replace_char(&outputFilename, '.', '_');
         outputFilename.append(".png");
@@ -386,7 +386,7 @@ static int process_input(const char* input, const SkString* writePath,
     SkDebugf("process_input, %s\n", input);
     if (iter.next(&inputFilename)) {
         do {
-            SkString inputPath = SkOSPath::SkPathJoin(input, inputFilename.c_str());
+            SkString inputPath = SkOSPath::Join(input, inputFilename.c_str());
             if (!render_picture(inputPath, writePath, mismatchPath, renderer, jsonSummaryPtr)) {
                 ++failures;
             }
@@ -424,11 +424,6 @@ int tool_main(int argc, char** argv) {
         exit(-1);
     }
 
-    if (FLAGS_clone < 0) {
-        SkDebugf("--clone must be >= 0. Was %i\n", FLAGS_clone);
-        exit(-1);
-    }
-
     if (FLAGS_writeEncodedImages) {
         if (FLAGS_writePath.isEmpty()) {
             SkDebugf("--writeEncodedImages requires --writePath\n");
@@ -491,6 +486,13 @@ int tool_main(int argc, char** argv) {
 #endif
 #endif
     if (FLAGS_writeJsonSummaryPath.count() == 1) {
+        // If there were any descriptions on the command line, insert them now.
+        for (int i=0; i<FLAGS_descriptions.count(); i++) {
+            SkTArray<SkString> tokens;
+            SkStrSplit(FLAGS_descriptions[i], "=", &tokens);
+            SkASSERT(tokens.count() == 2);
+            jsonSummary.addDescription(tokens[0].c_str(), tokens[1].c_str());
+        }
         jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]);
     }
     return 0;