1c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org/* 2c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org * Copyright 2014 Google Inc. 3c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org * 4c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be 5c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org * found in the LICENSE file. 6c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org * 7c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org * Simple tool to generate SKP files for testing. 8c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org */ 9c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org 10c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org#include "SkCanvas.h" 11c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org#include "SkColor.h" 12c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org#include "SkCommandLineFlags.h" 13c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org#include "SkPaint.h" 14c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org#include "SkPicture.h" 15770963f23f4fc313db0fa3bac18b1b8aafb55f17robertphillips@google.com#include "SkPictureRecorder.h" 16c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org#include "SkScalar.h" 17c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org#include "SkStream.h" 18c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org 19c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org// Flags used by this file, alphabetically: 20c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.orgDEFINE_int32(blue, 128, "Value of blue color channel in image, 0-255."); 21238771c9309e491373bdd68bf7e27c57f54175eccommit-bot@chromium.orgDEFINE_int32(border, 4, "Width of the black border around the image."); 22c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.orgDEFINE_int32(green, 128, "Value of green color channel in image, 0-255."); 23c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.orgDEFINE_int32(height, 200, "Height of canvas to create."); 24c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.orgDEFINE_int32(red, 128, "Value of red color channel in image, 0-255."); 25c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.orgDEFINE_int32(width, 300, "Width of canvas to create."); 26c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.orgDEFINE_string(writePath, "", "Filepath to write the SKP into."); 27c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org 28238771c9309e491373bdd68bf7e27c57f54175eccommit-bot@chromium.orgstatic void skpmaker(int width, int height, int border, SkColor color, 29c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org const char *writePath) { 3084b18c7e3e042bf206e1ace3d1b6ea5bb929fe51robertphillips@google.com SkPictureRecorder recorder; 315fb2ce38b3dcb8e60e9e112df23c9d42456d7069commit-bot@chromium.org SkCanvas* canvas = recorder.beginRecording(width, height, NULL, 0); 32c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org SkPaint paint; 33c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org paint.setStyle(SkPaint::kFill_Style); 34238771c9309e491373bdd68bf7e27c57f54175eccommit-bot@chromium.org paint.setColor(SK_ColorBLACK); 357e1a31db6acc4ab70bb58164cd5f451f939e71b6commit-bot@chromium.org canvas->drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height), paint); 36238771c9309e491373bdd68bf7e27c57f54175eccommit-bot@chromium.org paint.setColor(color); 37238771c9309e491373bdd68bf7e27c57f54175eccommit-bot@chromium.org canvas->drawRectCoords(SkIntToScalar(border), SkIntToScalar(border), 38238771c9309e491373bdd68bf7e27c57f54175eccommit-bot@chromium.org SkIntToScalar(width - border*2), SkIntToScalar(height - border*2), 39238771c9309e491373bdd68bf7e27c57f54175eccommit-bot@chromium.org paint); 4084b18c7e3e042bf206e1ace3d1b6ea5bb929fe51robertphillips@google.com SkAutoTUnref<SkPicture> pict(recorder.endRecording()); 41c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org SkFILEWStream stream(writePath); 4284b18c7e3e042bf206e1ace3d1b6ea5bb929fe51robertphillips@google.com pict->serialize(&stream); 43c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org} 44c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org 45c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.orgint tool_main(int argc, char** argv); 46c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.orgint tool_main(int argc, char** argv) { 47c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org SkCommandLineFlags::SetUsage("Creates a simple .skp file for testing."); 48c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org SkCommandLineFlags::Parse(argc, argv); 49c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org 50c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org // Validate flags. 51c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org if ((FLAGS_blue < 0) || (FLAGS_blue > 255)) { 52c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org SkDebugf("--blue must be within range [0,255]\n"); 53c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org exit(-1); 54c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org } 55c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org if ((FLAGS_green < 0) || (FLAGS_green > 255)) { 56c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org SkDebugf("--green must be within range [0,255]\n"); 57c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org exit(-1); 58c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org } 59c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org if (FLAGS_height <= 0) { 60c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org SkDebugf("--height must be >0\n"); 61c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org exit(-1); 62c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org } 63c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org if ((FLAGS_red < 0) || (FLAGS_red > 255)) { 64c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org SkDebugf("--red must be within range [0,255]\n"); 65c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org exit(-1); 66c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org } 67c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org if (FLAGS_width <= 0) { 68c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org SkDebugf("--width must be >0\n"); 69c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org exit(-1); 70c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org } 71c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org if (FLAGS_writePath.isEmpty()) { 72c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org SkDebugf("--writePath must be nonempty\n"); 73c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org exit(-1); 74c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org } 75c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org 76c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org SkColor color = SkColorSetRGB(FLAGS_red, FLAGS_green, FLAGS_blue); 77238771c9309e491373bdd68bf7e27c57f54175eccommit-bot@chromium.org skpmaker(FLAGS_width, FLAGS_height, FLAGS_border, color, FLAGS_writePath[0]); 78c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org return 0; 79c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org} 80c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org 81c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org#if !defined SK_BUILD_FOR_IOS 82c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.orgint main(int argc, char * const argv[]) { 83c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org return tool_main(argc, (char**) argv); 84c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org} 85c735598ce5b80dd8bdcf180aa8814cedb4a80975commit-bot@chromium.org#endif 86