OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkForceLinking.h" | 9 #include "SkForceLinking.h" |
10 #include "SkGraphics.h" | 10 #include "SkGraphics.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 NULL, | 21 NULL, |
22 "[~][^]substring[$] [...] of GM name to run.\n" | 22 "[~][^]substring[$] [...] of GM name to run.\n" |
23 "Multiple matches may be separated by spaces.\n" | 23 "Multiple matches may be separated by spaces.\n" |
24 "~ causes a matching GM to always be skipped\n" | 24 "~ causes a matching GM to always be skipped\n" |
25 "^ requires the start of the GM to match\n" | 25 "^ requires the start of the GM to match\n" |
26 "$ requires the end of the GM to match\n" | 26 "$ requires the end of the GM to match\n" |
27 "^ and $ requires an exact match\n" | 27 "^ and $ requires an exact match\n" |
28 "If a GM does not match any list entry,\n" | 28 "If a GM does not match any list entry,\n" |
29 "it is skipped unless some list entry starts with ~"); | 29 "it is skipped unless some list entry starts with ~"); |
30 | 30 |
31 DEFINE_string2(writePath, w, "", "Write output here as .skps."); | 31 DEFINE_string2(writePath, w, "", "Write output in this directory as .skps."); |
32 | 32 |
33 __SK_FORCE_IMAGE_DECODER_LINKING; | 33 __SK_FORCE_IMAGE_DECODER_LINKING; |
34 | 34 |
35 static void gmtoskp(skiagm::GM* gm, SkWStream* outputStream) { | 35 static void gmtoskp(skiagm::GM* gm, SkWStream* outputStream) { |
36 SkPictureRecorder pictureRecorder; | 36 SkPictureRecorder pictureRecorder; |
37 SkRect bounds = SkRect::MakeWH(SkIntToScalar(gm->getISize().width()), | 37 SkRect bounds = SkRect::MakeWH(SkIntToScalar(gm->getISize().width()), |
38 SkIntToScalar(gm->getISize().height())); | 38 SkIntToScalar(gm->getISize().height())); |
39 SkCanvas* canvas = pictureRecorder.beginRecording(bounds, NULL, 0); | 39 SkCanvas* canvas = pictureRecorder.beginRecording(bounds, NULL, 0); |
40 canvas->concat(gm->getInitialTransform()); | 40 canvas->concat(gm->getInitialTransform()); |
41 gm->draw(canvas); | 41 gm->draw(canvas); |
42 canvas->flush(); | 42 canvas->flush(); |
43 SkAutoTUnref<SkPicture> pict(pictureRecorder.endRecordingAsPicture()); | 43 SkAutoTUnref<SkPicture> pict(pictureRecorder.endRecordingAsPicture()); |
44 pict->serialize(outputStream, NULL); | 44 pict->serialize(outputStream, NULL); |
45 } | 45 } |
46 | 46 |
47 int main(int argc, char** argv) { | 47 int main(int argc, char** argv) { |
48 SkAutoGraphics ag; | 48 SkAutoGraphics ag; |
49 SkCommandLineFlags::SetUsage(""); | 49 SkCommandLineFlags::SetUsage(""); |
50 SkCommandLineFlags::Parse(argc, argv); | 50 SkCommandLineFlags::Parse(argc, argv); |
51 if (FLAGS_writePath.isEmpty()) { | 51 if (FLAGS_writePath.isEmpty()) { |
| 52 SkDebugf("You need to specify a --writePath option"); |
52 return 1; | 53 return 1; |
53 } | 54 } |
54 const char* writePath = FLAGS_writePath[0]; | 55 const char* writePath = FLAGS_writePath[0]; |
55 if (!sk_mkdir(writePath)) { | 56 if (!sk_mkdir(writePath)) { |
56 return 1; | 57 |
| 58 return 2; |
57 } | 59 } |
58 for (const skiagm::GMRegistry* reg = skiagm::GMRegistry::Head(); | 60 for (const skiagm::GMRegistry* reg = skiagm::GMRegistry::Head(); |
59 reg != NULL; | 61 reg != NULL; |
60 reg = reg->next()) { | 62 reg = reg->next()) { |
61 SkAutoTDelete<skiagm::GM> gm(reg->factory()(NULL)); | 63 SkAutoTDelete<skiagm::GM> gm(reg->factory()(NULL)); |
62 if (!gm.get()) { | 64 if (!gm.get()) { |
63 continue; | 65 continue; |
64 } | 66 } |
65 const char* name = gm->getName(); | 67 const char* name = gm->getName(); |
66 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, name)) { | 68 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, name)) { |
67 SkString path = SkOSPath::Join(writePath, name); | 69 SkString path = SkOSPath::Join(writePath, name); |
68 path.append(".skp"); | 70 path.append(".skp"); |
69 SkFILEWStream outputStream(path.c_str()); | 71 SkFILEWStream outputStream(path.c_str()); |
70 if (!outputStream.isValid()) { | 72 if (!outputStream.isValid()) { |
71 SkDebugf("Could not open file %s\n", path.c_str()); | 73 SkDebugf("Could not open file %s\n", path.c_str()); |
72 return 1; | 74 return 3; |
73 } | 75 } |
74 gmtoskp(gm, &outputStream); | 76 gmtoskp(gm, &outputStream); |
75 } | 77 } |
76 } | 78 } |
77 return 0; | 79 return 0; |
78 } | 80 } |
OLD | NEW |