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