| commit-bot@chromium.org | fe78847 | 2014-04-28 13:19:34 +0000 | [diff] [blame] | 1 | /* | 
 | 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.org | fe78847 | 2014-04-28 13:19:34 +0000 | [diff] [blame] | 8 | #include "SkCommandLineFlags.h" | 
 | 9 | #include "SkPicture.h" | 
| fmalita | 796e365 | 2016-05-13 11:40:07 -0700 | [diff] [blame] | 10 | #include "SkPictureAnalyzer.h" | 
| commit-bot@chromium.org | fe78847 | 2014-04-28 13:19:34 +0000 | [diff] [blame] | 11 | #include "SkPictureRecorder.h" | 
 | 12 | #include "SkStream.h" | 
 | 13 |  | 
 | 14 | DEFINE_string2(readFile, r, "", "skp file to process."); | 
 | 15 | DEFINE_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: | 
 | 21 | static const int kSuccess = 0; | 
 | 22 | static const int kError = 1; | 
 | 23 |  | 
| Mike Klein | be28ee2 | 2017-02-06 12:46:20 -0500 | [diff] [blame] | 24 | int main(int argc, char** argv) { | 
| commit-bot@chromium.org | fe78847 | 2014-04-28 13:19:34 +0000 | [diff] [blame] | 25 | #if SK_SUPPORT_GPU | 
 | 26 |     SkCommandLineFlags::SetUsage("Reports on an skp file's suitability for GPU rasterization"); | 
 | 27 |     SkCommandLineFlags::Parse(argc, argv); | 
 | 28 |  | 
 | 29 |     if (FLAGS_readFile.count() != 1) { | 
 | 30 |         if (!FLAGS_quiet) { | 
 | 31 |             SkDebugf("Missing input file\n"); | 
 | 32 |         } | 
 | 33 |         return kError; | 
 | 34 |     } | 
 | 35 |  | 
 | 36 |     SkFILEStream inputStream(FLAGS_readFile[0]); | 
 | 37 |     if (!inputStream.isValid()) { | 
 | 38 |         if (!FLAGS_quiet) { | 
 | 39 |             SkDebugf("Couldn't open file\n"); | 
 | 40 |         } | 
 | 41 |         return kError; | 
 | 42 |     } | 
 | 43 |  | 
| reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 44 |     sk_sp<SkPicture> picture(SkPicture::MakeFromStream(&inputStream)); | 
 | 45 |     if (nullptr == picture) { | 
| commit-bot@chromium.org | fe78847 | 2014-04-28 13:19:34 +0000 | [diff] [blame] | 46 |         if (!FLAGS_quiet) { | 
 | 47 |             SkDebugf("Could not read the SkPicture\n"); | 
 | 48 |         } | 
 | 49 |         return kError; | 
 | 50 |     } | 
 | 51 |  | 
 | 52 |     // The SkPicture tracking information is only generated during recording | 
 | 53 |     // an isn't serialized. Replay the picture to regenerated the tracking data. | 
 | 54 |     SkPictureRecorder recorder; | 
| halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 55 |     picture->playback(recorder.beginRecording(picture->cullRect().width(), | 
 | 56 |                                               picture->cullRect().height(), | 
| halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 57 |                                               nullptr, 0)); | 
| reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 58 |     sk_sp<SkPicture> recorded(recorder.finishRecordingAsPicture()); | 
| commit-bot@chromium.org | fe78847 | 2014-04-28 13:19:34 +0000 | [diff] [blame] | 59 |  | 
| fmalita | 796e365 | 2016-05-13 11:40:07 -0700 | [diff] [blame] | 60 |     if (SkPictureGpuAnalyzer(recorded).suitableForGpuRasterization(nullptr)) { | 
| commit-bot@chromium.org | fe78847 | 2014-04-28 13:19:34 +0000 | [diff] [blame] | 61 |         SkDebugf("suitable\n"); | 
 | 62 |     } else { | 
 | 63 |         SkDebugf("unsuitable\n"); | 
 | 64 |     } | 
| skia.committer@gmail.com | 1c74374 | 2014-04-29 03:05:14 +0000 | [diff] [blame] | 65 |  | 
| commit-bot@chromium.org | fe78847 | 2014-04-28 13:19:34 +0000 | [diff] [blame] | 66 |     return kSuccess; | 
 | 67 | #else | 
 | 68 |     SkDebugf("gpuveto is only useful when GPU rendering is enabled\n"); | 
 | 69 |     return kError; | 
 | 70 | #endif | 
 | 71 | } |