Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: experimental/webtry/main.cpp

Issue 688003002: fix issues with simultaneous configs and security jail on skfiddle (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | experimental/webtry/webtry.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 4 #include "GrContextFactory.h"
5 5
6 #include "SkCanvas.h" 6 #include "SkCanvas.h"
7 #include "SkCommandLineFlags.h" 7 #include "SkCommandLineFlags.h"
8 #include "SkData.h" 8 #include "SkData.h"
9 #include "SkForceLinking.h" 9 #include "SkForceLinking.h"
10 #include "SkGraphics.h" 10 #include "SkGraphics.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 stream->write(data->data(), data->size()); 114 stream->write(data->data(), data->size());
115 } 115 }
116 116
117 static void drawRaster(SkWStream* stream, SkImageInfo info) { 117 static void drawRaster(SkWStream* stream, SkImageInfo info) {
118 SkAutoTUnref<SkSurface> surface; 118 SkAutoTUnref<SkSurface> surface;
119 surface.reset(SkSurface::NewRaster(info)); 119 surface.reset(SkSurface::NewRaster(info));
120 drawAndDump(surface, stream); 120 drawAndDump(surface, stream);
121 } 121 }
122 122
123 static void drawGPU(SkWStream* stream, SkImageInfo info) { 123 static void drawGPU(SkWStream* stream, GrContext* gr, SkImageInfo info) {
124 SkAutoTUnref<SkSurface> surface; 124 SkAutoTUnref<SkSurface> surface;
125 GrContextFactory* grFactory = NULL;
126
127 GrContext::Options grContextOpts;
128 grFactory = new GrContextFactory(grContextOpts);
129 GrContext* gr = grFactory->get(GrContextFactory::kMESA_GLContextType);
130 surface.reset(SkSurface::NewRenderTarget(gr,info)); 125 surface.reset(SkSurface::NewRenderTarget(gr,info));
131 126
132 drawAndDump(surface, stream); 127 drawAndDump(surface, stream);
133
134 delete grFactory;
135 } 128 }
136 129
137 static void drawPDF(SkWStream* stream, SkImageInfo info) { 130 static void drawPDF(SkWStream* stream, SkImageInfo info) {
138 printf( "Not implemented yet...\n"); 131 printf( "Not implemented yet...\n");
139 } 132 }
140 133
141 int main(int argc, char** argv) { 134 int main(int argc, char** argv) {
142 SkCommandLineFlags::Parse(argc, argv); 135 SkCommandLineFlags::Parse(argc, argv);
143 SkAutoGraphics init; 136 SkAutoGraphics init;
144 137
(...skipping 10 matching lines...) Expand all
155 148
156 SkString sourcePath = SkOSPath::Join(sourceDir, FLAGS_source[0]); 149 SkString sourcePath = SkOSPath::Join(sourceDir, FLAGS_source[0]);
157 if (!SkImageDecoder::DecodeFile(sourcePath.c_str(), &source)) { 150 if (!SkImageDecoder::DecodeFile(sourcePath.c_str(), &source)) {
158 perror("Unable to read the source image."); 151 perror("Unable to read the source image.");
159 } 152 }
160 } 153 }
161 154
162 // make sure to open any needed output files before we set up the security 155 // make sure to open any needed output files before we set up the security
163 // jail 156 // jail
164 157
165 SkWStream* streams[3]; 158 SkWStream* streams[3] = {NULL, NULL, NULL};
166 159
167 if (FLAGS_raster) { 160 if (FLAGS_raster) {
168 SkString outPath; 161 SkString outPath;
169 outPath.printf("%s_raster.png", FLAGS_out[0]); 162 outPath.printf("%s_raster.png", FLAGS_out[0]);
170 streams[0] = SkNEW_ARGS(SkFILEWStream,(outPath.c_str())); 163 streams[0] = SkNEW_ARGS(SkFILEWStream,(outPath.c_str()));
171 } 164 }
172 if (FLAGS_gpu) { 165 if (FLAGS_gpu) {
173 SkString outPath; 166 SkString outPath;
174 outPath.printf("%s_gpu.png", FLAGS_out[0]); 167 outPath.printf("%s_gpu.png", FLAGS_out[0]);
175 streams[1] = SkNEW_ARGS(SkFILEWStream,(outPath.c_str())); 168 streams[1] = SkNEW_ARGS(SkFILEWStream,(outPath.c_str()));
176 } 169 }
177 if (FLAGS_pdf) { 170 if (FLAGS_pdf) {
178 SkString outPath; 171 SkString outPath;
179 outPath.printf("%s.pdf", FLAGS_out[0]); 172 outPath.printf("%s.pdf", FLAGS_out[0]);
180 streams[2] = SkNEW_ARGS(SkFILEWStream,(outPath.c_str())); 173 streams[2] = SkNEW_ARGS(SkFILEWStream,(outPath.c_str()));
181 } 174 }
182 175
183 SkImageInfo info = SkImageInfo::MakeN32(FLAGS_width, FLAGS_height, kPremul_S kAlphaType); 176 SkImageInfo info = SkImageInfo::MakeN32(FLAGS_width, FLAGS_height, kPremul_S kAlphaType);
184 177
178 GrContext *gr = NULL;
179 GrContextFactory* grFactory = NULL;
180
181 // need to set up the GPU context before we install system call restrictions
182 if (FLAGS_gpu) {
183
184 GrContext::Options grContextOpts;
185 grFactory = new GrContextFactory(grContextOpts);
186 gr = grFactory->get(GrContextFactory::kMESA_GLContextType);
187 }
188
185 setLimits(); 189 setLimits();
186 190
187 if (!install_syscall_filter()) { 191 if (!install_syscall_filter()) {
188 return 1; 192 return 1;
189 } 193 }
190 194
191 if (FLAGS_raster) { 195 if (NULL != streams[0]) {
192 drawRaster(streams[0], info); 196 drawRaster(streams[0], info);
193 } 197 }
194 if (FLAGS_gpu) { 198 if (NULL != streams[1]) {
195 drawGPU(streams[1], info); 199 drawGPU(streams[1], gr, info);
196 } 200 }
197 if (FLAGS_pdf) { 201 if (NULL != streams[2]) {
198 drawPDF(streams[2], info); 202 drawPDF(streams[2], info);
199 } 203 }
204
205 if (gr) {
206 delete grFactory;
207 }
200 } 208 }
OLDNEW
« no previous file with comments | « no previous file | experimental/webtry/webtry.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698