From dbd8379e5fcab5747d4ec46d560975f8ee6f49ea Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Thu, 2 Jan 2014 18:10:34 +0000 Subject: [PATCH] create simple 'skpmaker' tool to generate SKP files for testing (needed to create self-test for render_pictures) BUG=skia:1943 R=rmistry@google.com, mtklein@google.com Author: epoger@google.com Review URL: https://codereview.chromium.org/108343006 git-svn-id: http://skia.googlecode.com/svn/trunk@12864 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gyp/tools.gyp | 21 ++++++++++++--- tools/skpmaker.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 tools/skpmaker.cpp diff --git a/gyp/tools.gyp b/gyp/tools.gyp index f748157..ce24d9d 100644 --- a/gyp/tools.gyp +++ b/gyp/tools.gyp @@ -13,17 +13,18 @@ 'target_name': 'tools', 'type': 'none', 'dependencies': [ + 'bbh_shootout', 'bench_pictures', 'filter', - 'lua_pictures', - 'bbh_shootout', 'lua_app', + 'lua_pictures', 'pinspect', 'render_pdfs', 'render_pictures', 'skdiff', - 'skpdiff', 'skhello', + 'skpdiff', + 'skpmaker', 'skimage', 'test_image_decoder', ], @@ -110,6 +111,20 @@ ], }, { + 'target_name': 'skpmaker', + 'type': 'executable', + 'sources': [ + '../tools/skpmaker.cpp', + ], + 'include_dirs': [ + '../src/core', + ], + 'dependencies': [ + 'flags.gyp:flags', + 'skia_lib.gyp:skia_lib', + ], + }, + { 'target_name': 'skimagediff', 'type': 'executable', 'sources': [ diff --git a/tools/skpmaker.cpp b/tools/skpmaker.cpp new file mode 100644 index 0000000..1388977 --- /dev/null +++ b/tools/skpmaker.cpp @@ -0,0 +1,79 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Simple tool to generate SKP files for testing. + */ + +#include "SkCanvas.h" +#include "SkColor.h" +#include "SkCommandLineFlags.h" +#include "SkPaint.h" +#include "SkPicture.h" +#include "SkScalar.h" +#include "SkStream.h" + +// Flags used by this file, alphabetically: +DEFINE_int32(blue, 128, "Value of blue color channel in image, 0-255."); +DEFINE_int32(green, 128, "Value of green color channel in image, 0-255."); +DEFINE_int32(height, 200, "Height of canvas to create."); +DEFINE_int32(red, 128, "Value of red color channel in image, 0-255."); +DEFINE_int32(width, 300, "Width of canvas to create."); +DEFINE_string(writePath, "", "Filepath to write the SKP into."); + +static void skpmaker(SkScalar width, SkScalar height, SkColor color, + const char *writePath) { + SkPicture pict; + SkCanvas* canvas = pict.beginRecording(width, height); + SkPaint paint; + paint.setStyle(SkPaint::kFill_Style); + paint.setColor(color); + canvas->drawRectCoords(0, 0, width, height, paint); + pict.endRecording(); + SkFILEWStream stream(writePath); + pict.serialize(&stream); +} + +int tool_main(int argc, char** argv); +int tool_main(int argc, char** argv) { + SkCommandLineFlags::SetUsage("Creates a simple .skp file for testing."); + SkCommandLineFlags::Parse(argc, argv); + + // Validate flags. + if ((FLAGS_blue < 0) || (FLAGS_blue > 255)) { + SkDebugf("--blue must be within range [0,255]\n"); + exit(-1); + } + if ((FLAGS_green < 0) || (FLAGS_green > 255)) { + SkDebugf("--green must be within range [0,255]\n"); + exit(-1); + } + if (FLAGS_height <= 0) { + SkDebugf("--height must be >0\n"); + exit(-1); + } + if ((FLAGS_red < 0) || (FLAGS_red > 255)) { + SkDebugf("--red must be within range [0,255]\n"); + exit(-1); + } + if (FLAGS_width <= 0) { + SkDebugf("--width must be >0\n"); + exit(-1); + } + if (FLAGS_writePath.isEmpty()) { + SkDebugf("--writePath must be nonempty\n"); + exit(-1); + } + + SkColor color = SkColorSetRGB(FLAGS_red, FLAGS_green, FLAGS_blue); + skpmaker(SkIntToScalar(FLAGS_width), SkIntToScalar(FLAGS_height), color, FLAGS_writePath[0]); + return 0; +} + +#if !defined SK_BUILD_FOR_IOS +int main(int argc, char * const argv[]) { + return tool_main(argc, (char**) argv); +} +#endif -- 2.7.4