junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 1 | ''' |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 2 | Copyright 2012 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. |
commit-bot@chromium.org | 11f1562 | 2014-01-07 17:03:40 +0000 | [diff] [blame^] | 6 | |
| 7 | Compares the rendererings of serialized SkPictures to expected images. |
| 8 | |
| 9 | Launch with --help to see more information. |
| 10 | |
| 11 | TODO(epoger): Combine with overlapping tools/tests/render_pictures_test.py . |
| 12 | See https://code.google.com/p/skia/issues/detail?id=1943#c2 |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 13 | ''' |
| 14 | # common Python modules |
| 15 | import os |
| 16 | import optparse |
| 17 | import sys |
| 18 | import shutil |
| 19 | import tempfile |
| 20 | |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 21 | # modules declared within this same directory |
| 22 | import test_rendering |
| 23 | |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 24 | USAGE_STRING = 'Usage: %s input... expectedDir' |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 25 | HELP_STRING = ''' |
| 26 | |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 27 | Takes input SkPicture files and renders them as PNG files, and then compares |
| 28 | those resulting PNG files against PNG files found in expectedDir. |
| 29 | |
| 30 | Each instance of "input" can be either a file (name must end in .skp), or a |
| 31 | directory (in which case this script will process all .skp files within the |
| 32 | directory). |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 33 | ''' |
| 34 | |
keyar@chromium.org | e599ab7 | 2012-08-23 21:51:11 +0000 | [diff] [blame] | 35 | def ModeParse(option, opt_str, value, parser): |
| 36 | """Parses the --mode option of the commandline. |
| 37 | |
| 38 | The --mode option will either take in three parameters (if tile or |
| 39 | pow2tile) or a single parameter (otherwise). |
| 40 | """ |
| 41 | result = [value] |
| 42 | if value == "tile": |
| 43 | if (len(parser.rargs) < 2): |
| 44 | raise optparse.OptionValueError(("--mode tile mising width" |
| 45 | " and/or height parameters")) |
| 46 | result.extend(parser.rargs[:2]) |
| 47 | del parser.rargs[:2] |
| 48 | elif value == "pow2tile": |
| 49 | if (len(parser.rargs) < 2): |
| 50 | raise optparse.OptionValueError(("--mode pow2tile mising minWidth" |
| 51 | " and/or height parameters")) |
| 52 | result.extend(parser.rargs[:2]) |
| 53 | del parser.rargs[:2] |
| 54 | |
| 55 | setattr(parser.values, option.dest, result) |
| 56 | |
| 57 | |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 58 | def Main(args): |
| 59 | """Allow other scripts to call this script with fake command-line args. |
| 60 | |
| 61 | @param The commandline argument list |
| 62 | """ |
| 63 | parser = optparse.OptionParser(USAGE_STRING % '%prog' + HELP_STRING) |
| 64 | parser.add_option('--render_dir', dest='render_dir', |
| 65 | help = ("specify the location to output the rendered files." |
| 66 | " Default is a temp directory.")) |
| 67 | parser.add_option('--diff_dir', dest='diff_dir', |
| 68 | help = ("specify the location to output the diff files." |
| 69 | " Default is a temp directory.")) |
keyar@chromium.org | e599ab7 | 2012-08-23 21:51:11 +0000 | [diff] [blame] | 70 | parser.add_option('--mode', dest='mode', type='string', |
| 71 | action="callback", callback=ModeParse, |
| 72 | help = ("specify how rendering is to be done.")) |
| 73 | parser.add_option('--device', dest='device', |
| 74 | help = ("specify the device to render to.")) |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 75 | |
| 76 | options, arguments = parser.parse_args(args) |
| 77 | |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 78 | if (len(arguments) < 3): |
| 79 | print("Expected at least one input and one ouput folder.") |
| 80 | parser.print_help() |
| 81 | sys.exit(-1) |
| 82 | |
| 83 | inputs = arguments[1:-1] |
| 84 | expected_dir = arguments[-1] |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 85 | |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 86 | extra_args = '' |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 87 | |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 88 | if (options.mode is not None): |
| 89 | extra_args += ' --mode %s' % ' '.join(options.mode) |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 90 | |
edisonn@google.com | c2c4981 | 2012-10-10 15:08:12 +0000 | [diff] [blame] | 91 | if (options.device is not None): |
| 92 | extra_args += ' --device %s' % options.device |
| 93 | |
| 94 | test_rendering.TestRenderSkps(inputs, expected_dir, options.render_dir, |
| 95 | options.diff_dir, 'render_pictures', |
| 96 | extra_args) |
junov@chromium.org | 777442d | 2012-06-12 14:56:36 +0000 | [diff] [blame] | 97 | |
| 98 | if __name__ == '__main__': |
| 99 | Main(sys.argv) |