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