blob: 4672a38b6b05d10a56fc71d77b3633e24343ad7c [file] [log] [blame]
commit-bot@chromium.orgfe788472014-04-28 13:19:34 +00001/*
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
commit-bot@chromium.orgfe788472014-04-28 13:19:34 +00008#include "SkCommandLineFlags.h"
9#include "SkPicture.h"
fmalita796e3652016-05-13 11:40:07 -070010#include "SkPictureAnalyzer.h"
commit-bot@chromium.orgfe788472014-04-28 13:19:34 +000011#include "SkPictureRecorder.h"
12#include "SkStream.h"
13
14DEFINE_string2(readFile, r, "", "skp file to process.");
15DEFINE_bool2(quiet, q, false, "quiet");
16
17// This tool just loads a single skp, replays into a new SkPicture (to
18// regenerate the GPU-specific tracking information) and reports
19// the value of the suitableForGpuRasterization method.
20// Return codes:
21static const int kSuccess = 0;
22static const int kError = 1;
23
24int tool_main(int argc, char** argv);
25int tool_main(int argc, char** argv) {
26#if SK_SUPPORT_GPU
27 SkCommandLineFlags::SetUsage("Reports on an skp file's suitability for GPU rasterization");
28 SkCommandLineFlags::Parse(argc, argv);
29
30 if (FLAGS_readFile.count() != 1) {
31 if (!FLAGS_quiet) {
32 SkDebugf("Missing input file\n");
33 }
34 return kError;
35 }
36
37 SkFILEStream inputStream(FLAGS_readFile[0]);
38 if (!inputStream.isValid()) {
39 if (!FLAGS_quiet) {
40 SkDebugf("Couldn't open file\n");
41 }
42 return kError;
43 }
44
reedca2622b2016-03-18 07:25:55 -070045 sk_sp<SkPicture> picture(SkPicture::MakeFromStream(&inputStream));
46 if (nullptr == picture) {
commit-bot@chromium.orgfe788472014-04-28 13:19:34 +000047 if (!FLAGS_quiet) {
48 SkDebugf("Could not read the SkPicture\n");
49 }
50 return kError;
51 }
52
53 // The SkPicture tracking information is only generated during recording
54 // an isn't serialized. Replay the picture to regenerated the tracking data.
55 SkPictureRecorder recorder;
halcanary9d524f22016-03-29 09:03:52 -070056 picture->playback(recorder.beginRecording(picture->cullRect().width(),
57 picture->cullRect().height(),
halcanary96fcdcc2015-08-27 07:41:13 -070058 nullptr, 0));
reedca2622b2016-03-18 07:25:55 -070059 sk_sp<SkPicture> recorded(recorder.finishRecordingAsPicture());
commit-bot@chromium.orgfe788472014-04-28 13:19:34 +000060
fmalita796e3652016-05-13 11:40:07 -070061 if (SkPictureGpuAnalyzer(recorded).suitableForGpuRasterization(nullptr)) {
commit-bot@chromium.orgfe788472014-04-28 13:19:34 +000062 SkDebugf("suitable\n");
63 } else {
64 SkDebugf("unsuitable\n");
65 }
skia.committer@gmail.com1c743742014-04-29 03:05:14 +000066
commit-bot@chromium.orgfe788472014-04-28 13:19:34 +000067 return kSuccess;
68#else
69 SkDebugf("gpuveto is only useful when GPU rendering is enabled\n");
70 return kError;
71#endif
72}
73
74#if !defined SK_BUILD_FOR_IOS
75int main(int argc, char * const argv[]) {
76 return tool_main(argc, (char**) argv);
77}
78#endif