OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "PictureRenderingFlags.h" | 8 #include "PictureRenderingFlags.h" |
9 | 9 |
10 #include "CopyTilesRenderer.h" | 10 #include "CopyTilesRenderer.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 "Defaults to empty string, which selects the API native to the " | 85 "Defaults to empty string, which selects the API native to the " |
86 "system."); | 86 "system."); |
87 DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling
back to " | 87 DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling
back to " |
88 "software path rendering."); | 88 "software path rendering."); |
89 #endif | 89 #endif |
90 | 90 |
91 sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) { | 91 sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) { |
92 error.reset(); | 92 error.reset(); |
93 | 93 |
94 bool useTiles = false; | 94 bool useTiles = false; |
95 const char* widthString = NULL; | 95 const char* widthString = nullptr; |
96 const char* heightString = NULL; | 96 const char* heightString = nullptr; |
97 bool isPowerOf2Mode = false; | 97 bool isPowerOf2Mode = false; |
98 bool isCopyMode = false; | 98 bool isCopyMode = false; |
99 const char* mode = NULL; | 99 const char* mode = nullptr; |
100 | 100 |
101 #if SK_SUPPORT_GPU | 101 #if SK_SUPPORT_GPU |
102 GrContextOptions grContextOpts; | 102 GrContextOptions grContextOpts; |
103 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks; | 103 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks; |
104 #define RENDERER_ARGS (grContextOpts) | 104 #define RENDERER_ARGS (grContextOpts) |
105 #else | 105 #else |
106 #define RENDERER_ARGS () | 106 #define RENDERER_ARGS () |
107 #endif | 107 #endif |
108 | 108 |
109 SkAutoTUnref<sk_tools::PictureRenderer> renderer; | 109 SkAutoTUnref<sk_tools::PictureRenderer> renderer; |
110 if (FLAGS_mode.count() >= 1) { | 110 if (FLAGS_mode.count() >= 1) { |
111 mode = FLAGS_mode[0]; | 111 mode = FLAGS_mode[0]; |
112 if (0 == strcmp(mode, "record")) { | 112 if (0 == strcmp(mode, "record")) { |
113 renderer.reset(new sk_tools::RecordPictureRenderer RENDERER_ARGS); | 113 renderer.reset(new sk_tools::RecordPictureRenderer RENDERER_ARGS); |
114 } else if (0 == strcmp(mode, "tile") || 0 == strcmp(mode, "pow2tile") | 114 } else if (0 == strcmp(mode, "tile") || 0 == strcmp(mode, "pow2tile") |
115 || 0 == strcmp(mode, "copyTile")) { | 115 || 0 == strcmp(mode, "copyTile")) { |
116 useTiles = true; | 116 useTiles = true; |
117 | 117 |
118 if (0 == strcmp(mode, "pow2tile")) { | 118 if (0 == strcmp(mode, "pow2tile")) { |
119 isPowerOf2Mode = true; | 119 isPowerOf2Mode = true; |
120 } else if (0 == strcmp(mode, "copyTile")) { | 120 } else if (0 == strcmp(mode, "copyTile")) { |
121 isCopyMode = true; | 121 isCopyMode = true; |
122 } | 122 } |
123 | 123 |
124 if (FLAGS_mode.count() < 2) { | 124 if (FLAGS_mode.count() < 2) { |
125 error.printf("Missing width for --mode %s\n", mode); | 125 error.printf("Missing width for --mode %s\n", mode); |
126 return NULL; | 126 return nullptr; |
127 } | 127 } |
128 | 128 |
129 widthString = FLAGS_mode[1]; | 129 widthString = FLAGS_mode[1]; |
130 if (FLAGS_mode.count() < 3) { | 130 if (FLAGS_mode.count() < 3) { |
131 error.printf("Missing height for --mode %s\n", mode); | 131 error.printf("Missing height for --mode %s\n", mode); |
132 return NULL; | 132 return nullptr; |
133 } | 133 } |
134 | 134 |
135 heightString = FLAGS_mode[2]; | 135 heightString = FLAGS_mode[2]; |
136 } else if (0 == strcmp(mode, "playbackCreation") && kBench_PictureTool =
= tool) { | 136 } else if (0 == strcmp(mode, "playbackCreation") && kBench_PictureTool =
= tool) { |
137 renderer.reset(new sk_tools::PlaybackCreationRenderer RENDERER_ARGS)
; | 137 renderer.reset(new sk_tools::PlaybackCreationRenderer RENDERER_ARGS)
; |
138 // undocumented | 138 // undocumented |
139 } else if (0 == strcmp(mode, "rerecord") && kRender_PictureTool == tool)
{ | 139 } else if (0 == strcmp(mode, "rerecord") && kRender_PictureTool == tool)
{ |
140 renderer.reset(new sk_tools::RecordPictureRenderer RENDERER_ARGS); | 140 renderer.reset(new sk_tools::RecordPictureRenderer RENDERER_ARGS); |
141 } else if (0 == strcmp(mode, "simple")) { | 141 } else if (0 == strcmp(mode, "simple")) { |
142 // Allow 'mode' to be set to 'simple', but do not create a renderer,
so we can | 142 // Allow 'mode' to be set to 'simple', but do not create a renderer,
so we can |
143 // ensure that pipe does not override a mode besides simple. The ren
derer will | 143 // ensure that pipe does not override a mode besides simple. The ren
derer will |
144 // be created below. | 144 // be created below. |
145 } else { | 145 } else { |
146 error.printf("%s is not a valid mode for --mode\n", mode); | 146 error.printf("%s is not a valid mode for --mode\n", mode); |
147 return NULL; | 147 return nullptr; |
148 } | 148 } |
149 } | 149 } |
150 | 150 |
151 if (useTiles) { | 151 if (useTiles) { |
152 SkASSERT(NULL == renderer); | 152 SkASSERT(nullptr == renderer); |
153 SkAutoTUnref<sk_tools::TiledPictureRenderer> tiledRenderer; | 153 SkAutoTUnref<sk_tools::TiledPictureRenderer> tiledRenderer; |
154 if (isCopyMode) { | 154 if (isCopyMode) { |
155 int xTiles = -1; | 155 int xTiles = -1; |
156 int yTiles = -1; | 156 int yTiles = -1; |
157 if (FLAGS_tiles.count() > 0) { | 157 if (FLAGS_tiles.count() > 0) { |
158 if (FLAGS_tiles.count() != 2) { | 158 if (FLAGS_tiles.count() != 2) { |
159 error.printf("--tiles requires an x value and a y value.\n")
; | 159 error.printf("--tiles requires an x value and a y value.\n")
; |
160 return NULL; | 160 return nullptr; |
161 } | 161 } |
162 xTiles = atoi(FLAGS_tiles[0]); | 162 xTiles = atoi(FLAGS_tiles[0]); |
163 yTiles = atoi(FLAGS_tiles[1]); | 163 yTiles = atoi(FLAGS_tiles[1]); |
164 } | 164 } |
165 | 165 |
166 int x, y; | 166 int x, y; |
167 if (xTiles != -1 && yTiles != -1) { | 167 if (xTiles != -1 && yTiles != -1) { |
168 x = xTiles; | 168 x = xTiles; |
169 y = yTiles; | 169 y = yTiles; |
170 if (x <= 0 || y <= 0) { | 170 if (x <= 0 || y <= 0) { |
171 error.printf("--tiles must be given values > 0\n"); | 171 error.printf("--tiles must be given values > 0\n"); |
172 return NULL; | 172 return nullptr; |
173 } | 173 } |
174 } else { | 174 } else { |
175 x = y = 4; | 175 x = y = 4; |
176 } | 176 } |
177 #if SK_SUPPORT_GPU | 177 #if SK_SUPPORT_GPU |
178 tiledRenderer.reset(new sk_tools::CopyTilesRenderer(grContextOpts, x
, y)); | 178 tiledRenderer.reset(new sk_tools::CopyTilesRenderer(grContextOpts, x
, y)); |
179 #else | 179 #else |
180 tiledRenderer.reset(new sk_tools::CopyTilesRenderer(x, y)); | 180 tiledRenderer.reset(new sk_tools::CopyTilesRenderer(x, y)); |
181 #endif | 181 #endif |
182 } else { | 182 } else { |
183 tiledRenderer.reset(new sk_tools::TiledPictureRenderer RENDERER_ARGS
); | 183 tiledRenderer.reset(new sk_tools::TiledPictureRenderer RENDERER_ARGS
); |
184 } | 184 } |
185 | 185 |
186 if (isPowerOf2Mode) { | 186 if (isPowerOf2Mode) { |
187 int minWidth = atoi(widthString); | 187 int minWidth = atoi(widthString); |
188 if (!SkIsPow2(minWidth) || minWidth < 0) { | 188 if (!SkIsPow2(minWidth) || minWidth < 0) { |
189 SkString err; | 189 SkString err; |
190 error.printf("-mode %s must be given a width" | 190 error.printf("-mode %s must be given a width" |
191 " value that is a power of two\n", mode); | 191 " value that is a power of two\n", mode); |
192 return NULL; | 192 return nullptr; |
193 } | 193 } |
194 tiledRenderer->setTileMinPowerOf2Width(minWidth); | 194 tiledRenderer->setTileMinPowerOf2Width(minWidth); |
195 } else if (sk_tools::is_percentage(widthString)) { | 195 } else if (sk_tools::is_percentage(widthString)) { |
196 if (isCopyMode) { | 196 if (isCopyMode) { |
197 error.printf("--mode %s does not support percentages.\n", mode); | 197 error.printf("--mode %s does not support percentages.\n", mode); |
198 return NULL; | 198 return nullptr; |
199 } | 199 } |
200 tiledRenderer->setTileWidthPercentage(atof(widthString)); | 200 tiledRenderer->setTileWidthPercentage(atof(widthString)); |
201 if (!(tiledRenderer->getTileWidthPercentage() > 0)) { | 201 if (!(tiledRenderer->getTileWidthPercentage() > 0)) { |
202 error.printf("--mode %s must be given a width percentage > 0\n",
mode); | 202 error.printf("--mode %s must be given a width percentage > 0\n",
mode); |
203 return NULL; | 203 return nullptr; |
204 } | 204 } |
205 } else { | 205 } else { |
206 tiledRenderer->setTileWidth(atoi(widthString)); | 206 tiledRenderer->setTileWidth(atoi(widthString)); |
207 if (!(tiledRenderer->getTileWidth() > 0)) { | 207 if (!(tiledRenderer->getTileWidth() > 0)) { |
208 error.printf("--mode %s must be given a width > 0\n", mode); | 208 error.printf("--mode %s must be given a width > 0\n", mode); |
209 return NULL; | 209 return nullptr; |
210 } | 210 } |
211 } | 211 } |
212 | 212 |
213 if (sk_tools::is_percentage(heightString)) { | 213 if (sk_tools::is_percentage(heightString)) { |
214 if (isCopyMode) { | 214 if (isCopyMode) { |
215 error.printf("--mode %s does not support percentages.\n", mode); | 215 error.printf("--mode %s does not support percentages.\n", mode); |
216 return NULL; | 216 return nullptr; |
217 } | 217 } |
218 tiledRenderer->setTileHeightPercentage(atof(heightString)); | 218 tiledRenderer->setTileHeightPercentage(atof(heightString)); |
219 if (!(tiledRenderer->getTileHeightPercentage() > 0)) { | 219 if (!(tiledRenderer->getTileHeightPercentage() > 0)) { |
220 error.printf("--mode %s must be given a height percentage > 0\n"
, mode); | 220 error.printf("--mode %s must be given a height percentage > 0\n"
, mode); |
221 return NULL; | 221 return nullptr; |
222 } | 222 } |
223 } else { | 223 } else { |
224 tiledRenderer->setTileHeight(atoi(heightString)); | 224 tiledRenderer->setTileHeight(atoi(heightString)); |
225 if (!(tiledRenderer->getTileHeight() > 0)) { | 225 if (!(tiledRenderer->getTileHeight() > 0)) { |
226 SkString err; | 226 SkString err; |
227 error.printf("--mode %s must be given a height > 0\n", mode); | 227 error.printf("--mode %s must be given a height > 0\n", mode); |
228 return NULL; | 228 return nullptr; |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 renderer.reset(tiledRenderer.detach()); | 232 renderer.reset(tiledRenderer.detach()); |
233 if (FLAGS_pipe) { | 233 if (FLAGS_pipe) { |
234 error.printf("Pipe rendering is currently not compatible with tiling
.\n" | 234 error.printf("Pipe rendering is currently not compatible with tiling
.\n" |
235 "Turning off pipe.\n"); | 235 "Turning off pipe.\n"); |
236 } | 236 } |
237 | 237 |
238 } else { // useTiles | 238 } else { // useTiles |
239 if (FLAGS_pipe) { | 239 if (FLAGS_pipe) { |
240 if (renderer != NULL) { | 240 if (renderer != nullptr) { |
241 error.printf("Pipe is incompatible with other modes.\n"); | 241 error.printf("Pipe is incompatible with other modes.\n"); |
242 return NULL; | 242 return nullptr; |
243 } | 243 } |
244 renderer.reset(new sk_tools::PipePictureRenderer RENDERER_ARGS); | 244 renderer.reset(new sk_tools::PipePictureRenderer RENDERER_ARGS); |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 if (NULL == renderer) { | 248 if (nullptr == renderer) { |
249 renderer.reset(new sk_tools::SimplePictureRenderer RENDERER_ARGS); | 249 renderer.reset(new sk_tools::SimplePictureRenderer RENDERER_ARGS); |
250 } | 250 } |
251 | 251 |
252 if (FLAGS_viewport.count() > 0) { | 252 if (FLAGS_viewport.count() > 0) { |
253 if (FLAGS_viewport.count() != 2) { | 253 if (FLAGS_viewport.count() != 2) { |
254 error.printf("--viewport requires a width and a height.\n"); | 254 error.printf("--viewport requires a width and a height.\n"); |
255 return NULL; | 255 return nullptr; |
256 } | 256 } |
257 SkISize viewport; | 257 SkISize viewport; |
258 viewport.fWidth = atoi(FLAGS_viewport[0]); | 258 viewport.fWidth = atoi(FLAGS_viewport[0]); |
259 viewport.fHeight = atoi(FLAGS_viewport[1]); | 259 viewport.fHeight = atoi(FLAGS_viewport[1]); |
260 renderer->setViewport(viewport); | 260 renderer->setViewport(viewport); |
261 } | 261 } |
262 | 262 |
263 sk_tools::PictureRenderer::SkDeviceTypes deviceType = | 263 sk_tools::PictureRenderer::SkDeviceTypes deviceType = |
264 sk_tools::PictureRenderer::kBitmap_DeviceType; | 264 sk_tools::PictureRenderer::kBitmap_DeviceType; |
265 #if SK_SUPPORT_GPU | 265 #if SK_SUPPORT_GPU |
266 GrGLStandard gpuAPI = kNone_GrGLStandard; | 266 GrGLStandard gpuAPI = kNone_GrGLStandard; |
267 if (1 == FLAGS_gpuAPI.count()) { | 267 if (1 == FLAGS_gpuAPI.count()) { |
268 if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) { | 268 if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) { |
269 gpuAPI = kGL_GrGLStandard; | 269 gpuAPI = kGL_GrGLStandard; |
270 } else if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) { | 270 } else if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) { |
271 gpuAPI = kGLES_GrGLStandard; | 271 gpuAPI = kGLES_GrGLStandard; |
272 } else { | 272 } else { |
273 error.printf("--gpuAPI invalid api value.\n"); | 273 error.printf("--gpuAPI invalid api value.\n"); |
274 return NULL; | 274 return nullptr; |
275 } | 275 } |
276 } else if (FLAGS_gpuAPI.count() > 1) { | 276 } else if (FLAGS_gpuAPI.count() > 1) { |
277 error.printf("--gpuAPI invalid api value.\n"); | 277 error.printf("--gpuAPI invalid api value.\n"); |
278 return NULL; | 278 return nullptr; |
279 } | 279 } |
280 | 280 |
281 int sampleCount = 0; | 281 int sampleCount = 0; |
282 bool useDFText = false; | 282 bool useDFText = false; |
283 #endif | 283 #endif |
284 if (FLAGS_config.count() > 0) { | 284 if (FLAGS_config.count() > 0) { |
285 if (0 == strcmp(FLAGS_config[0], "8888")) { | 285 if (0 == strcmp(FLAGS_config[0], "8888")) { |
286 deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType; | 286 deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType; |
287 } | 287 } |
288 #if SK_SUPPORT_GPU | 288 #if SK_SUPPORT_GPU |
(...skipping 26 matching lines...) Expand all Loading... |
315 } | 315 } |
316 #endif | 316 #endif |
317 #if SK_MESA | 317 #if SK_MESA |
318 else if (0 == strcmp(FLAGS_config[0], "mesa")) { | 318 else if (0 == strcmp(FLAGS_config[0], "mesa")) { |
319 deviceType = sk_tools::PictureRenderer::kMesa_DeviceType; | 319 deviceType = sk_tools::PictureRenderer::kMesa_DeviceType; |
320 } | 320 } |
321 #endif | 321 #endif |
322 #endif | 322 #endif |
323 else { | 323 else { |
324 error.printf("%s is not a valid mode for --config\n", FLAGS_config[0
]); | 324 error.printf("%s is not a valid mode for --config\n", FLAGS_config[0
]); |
325 return NULL; | 325 return nullptr; |
326 } | 326 } |
327 #if SK_SUPPORT_GPU | 327 #if SK_SUPPORT_GPU |
328 if (!renderer->setDeviceType(deviceType, gpuAPI)) { | 328 if (!renderer->setDeviceType(deviceType, gpuAPI)) { |
329 #else | 329 #else |
330 if (!renderer->setDeviceType(deviceType)) { | 330 if (!renderer->setDeviceType(deviceType)) { |
331 #endif | 331 #endif |
332 error.printf("Could not create backend for --config %s\n", FLAGS_con
fig[0]); | 332 error.printf("Could not create backend for --config %s\n", FLAGS_con
fig[0]); |
333 return NULL; | 333 return nullptr; |
334 } | 334 } |
335 #if SK_SUPPORT_GPU | 335 #if SK_SUPPORT_GPU |
336 renderer->setSampleCount(sampleCount); | 336 renderer->setSampleCount(sampleCount); |
337 renderer->setUseDFText(useDFText); | 337 renderer->setUseDFText(useDFText); |
338 #endif | 338 #endif |
339 } | 339 } |
340 | 340 |
341 | 341 |
342 sk_tools::PictureRenderer::BBoxHierarchyType bbhType | 342 sk_tools::PictureRenderer::BBoxHierarchyType bbhType |
343 = sk_tools::PictureRenderer::kNone_BBoxHierarchyType; | 343 = sk_tools::PictureRenderer::kNone_BBoxHierarchyType; |
344 if (FLAGS_bbh.count() > 0) { | 344 if (FLAGS_bbh.count() > 0) { |
345 const char* type = FLAGS_bbh[0]; | 345 const char* type = FLAGS_bbh[0]; |
346 if (0 == strcmp(type, "none")) { | 346 if (0 == strcmp(type, "none")) { |
347 bbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType; | 347 bbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType; |
348 } else if (0 == strcmp(type, "rtree")) { | 348 } else if (0 == strcmp(type, "rtree")) { |
349 bbhType = sk_tools::PictureRenderer::kRTree_BBoxHierarchyType; | 349 bbhType = sk_tools::PictureRenderer::kRTree_BBoxHierarchyType; |
350 } else { | 350 } else { |
351 error.printf("%s is not a valid value for --bbhType\n", type); | 351 error.printf("%s is not a valid value for --bbhType\n", type); |
352 return NULL; | 352 return nullptr; |
353 } | 353 } |
354 if (FLAGS_pipe && sk_tools::PictureRenderer::kNone_BBoxHierarchyType !=
bbhType) { | 354 if (FLAGS_pipe && sk_tools::PictureRenderer::kNone_BBoxHierarchyType !=
bbhType) { |
355 error.printf("--pipe and --bbh cannot be used together\n"); | 355 error.printf("--pipe and --bbh cannot be used together\n"); |
356 return NULL; | 356 return nullptr; |
357 } | 357 } |
358 } | 358 } |
359 renderer->setBBoxHierarchyType(bbhType); | 359 renderer->setBBoxHierarchyType(bbhType); |
360 renderer->setScaleFactor(SkDoubleToScalar(FLAGS_scale)); | 360 renderer->setScaleFactor(SkDoubleToScalar(FLAGS_scale)); |
361 | 361 |
362 return renderer.detach(); | 362 return renderer.detach(); |
363 } | 363 } |
OLD | NEW |