| OLD | NEW |
| 1 #include <sys/time.h> | 1 #include <sys/time.h> |
| 2 #include <sys/resource.h> | 2 #include <sys/resource.h> |
| 3 | 3 |
| 4 #include "GrContextFactory.h" | |
| 5 | |
| 6 #include "SkCanvas.h" | 4 #include "SkCanvas.h" |
| 7 #include "SkCommandLineFlags.h" | 5 #include "SkCommandLineFlags.h" |
| 8 #include "SkData.h" | 6 #include "SkData.h" |
| 9 #include "SkForceLinking.h" | 7 #include "SkForceLinking.h" |
| 10 #include "SkGraphics.h" | 8 #include "SkGraphics.h" |
| 11 #include "SkImageDecoder.h" | 9 #include "SkImageDecoder.h" |
| 12 #include "SkImageEncoder.h" | 10 #include "SkImageEncoder.h" |
| 13 #include "SkImageInfo.h" | 11 #include "SkImageInfo.h" |
| 14 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
| 15 #include "SkStream.h" | 13 #include "SkStream.h" |
| 16 #include "SkSurface.h" | 14 #include "SkSurface.h" |
| 17 | 15 |
| 18 #include "seccomp_bpf.h" | 16 #include "seccomp_bpf.h" |
| 19 | 17 |
| 20 __SK_FORCE_IMAGE_DECODER_LINKING; | 18 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 21 | 19 |
| 22 DEFINE_string(out, "", "Filename of the PNG to write to."); | 20 DEFINE_string(out, "", "Filename of the PNG to write to."); |
| 23 DEFINE_string(source, "", "Filename of the source image."); | 21 DEFINE_string(source, "", "Filename of the source image."); |
| 24 DEFINE_int32(width, 256, "Width of output image."); | 22 DEFINE_int32(width, 256, "Width of output image."); |
| 25 DEFINE_int32(height, 256, "Height of output image."); | 23 DEFINE_int32(height, 256, "Height of output image."); |
| 26 DEFINE_bool(gpu, false, "Use GPU (Mesa) rendering."); | |
| 27 | 24 |
| 28 // Defined in template.cpp. | 25 // Defined in template.cpp. |
| 29 extern SkBitmap source; | 26 extern SkBitmap source; |
| 30 | 27 |
| 31 static bool install_syscall_filter() { | 28 static bool install_syscall_filter() { |
| 32 | 29 |
| 33 #ifndef SK_UNSAFE_BUILD_DESKTOP_ONLY | 30 #ifndef SK_UNSAFE_BUILD_DESKTOP_ONLY |
| 34 struct sock_filter filter[] = { | 31 struct sock_filter filter[] = { |
| 35 /* Grab the system call number. */ | 32 /* Grab the system call number. */ |
| 36 EXAMINE_SYSCALL, | 33 EXAMINE_SYSCALL, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 112 |
| 116 SkString sourcePath = SkOSPath::Join(sourceDir, FLAGS_source[0]); | 113 SkString sourcePath = SkOSPath::Join(sourceDir, FLAGS_source[0]); |
| 117 if (!SkImageDecoder::DecodeFile(sourcePath.c_str(), &source)) { | 114 if (!SkImageDecoder::DecodeFile(sourcePath.c_str(), &source)) { |
| 118 perror("Unable to read the source image."); | 115 perror("Unable to read the source image."); |
| 119 } | 116 } |
| 120 } | 117 } |
| 121 | 118 |
| 122 SkFILEWStream stream(FLAGS_out[0]); | 119 SkFILEWStream stream(FLAGS_out[0]); |
| 123 | 120 |
| 124 SkImageInfo info = SkImageInfo::MakeN32(FLAGS_width, FLAGS_height, kPremul_S
kAlphaType); | 121 SkImageInfo info = SkImageInfo::MakeN32(FLAGS_width, FLAGS_height, kPremul_S
kAlphaType); |
| 125 | 122 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
| 126 SkCanvas* canvas; | 123 SkCanvas* canvas = surface->getCanvas(); |
| 127 SkAutoTUnref<SkSurface> surface; | |
| 128 | |
| 129 GrContextFactory* grFactory = NULL; | |
| 130 | |
| 131 if (FLAGS_gpu) { | |
| 132 GrContext::Options grContextOpts; | |
| 133 grFactory = new GrContextFactory(grContextOpts); | |
| 134 GrContext* gr = grFactory->get(GrContextFactory::kMESA_GLContextType); | |
| 135 surface.reset(SkSurface::NewRenderTarget(gr,info)); | |
| 136 } else { | |
| 137 surface.reset(SkSurface::NewRaster(info)); | |
| 138 } | |
| 139 | |
| 140 canvas = surface->getCanvas(); | |
| 141 | 124 |
| 142 setLimits(); | 125 setLimits(); |
| 143 | 126 |
| 144 if (!install_syscall_filter()) { | 127 if (!install_syscall_filter()) { |
| 145 return 1; | 128 return 1; |
| 146 } | 129 } |
| 147 | 130 |
| 148 draw(canvas); | 131 draw(canvas); |
| 149 | 132 |
| 150 // Write out the image as a PNG. | 133 // Write out the image as a PNG. |
| 151 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 134 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 152 SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100)); | 135 SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100)); |
| 153 if (NULL == data.get()) { | 136 if (NULL == data.get()) { |
| 154 printf("Failed to encode\n"); | 137 printf("Failed to encode\n"); |
| 155 exit(1); | 138 exit(1); |
| 156 } | 139 } |
| 157 stream.write(data->data(), data->size()); | 140 stream.write(data->data(), data->size()); |
| 158 delete grFactory; | |
| 159 } | 141 } |
| OLD | NEW |