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

Side by Side Diff: tools/render_pictures_main.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 months 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 | « tools/render_pdfs_main.cpp ('k') | tools/sk_tool_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "LazyDecodeBitmap.h" 8 #include "LazyDecodeBitmap.h"
9 #include "CopyTilesRenderer.h" 9 #include "CopyTilesRenderer.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 * Sets gInputFileName to name, minus any extension ".*" 105 * Sets gInputFileName to name, minus any extension ".*"
106 * Sets gImageNo to 0, so images from file "X.skp" will 106 * Sets gImageNo to 0, so images from file "X.skp" will
107 * look like "X_<gImageNo>.<suffix>", beginning with 0 107 * look like "X_<gImageNo>.<suffix>", beginning with 0
108 * for each new skp. 108 * for each new skp.
109 */ 109 */
110 static void reset_image_file_base_name(const SkString& name) { 110 static void reset_image_file_base_name(const SkString& name) {
111 gImageNo = 0; 111 gImageNo = 0;
112 // Remove ".skp" 112 // Remove ".skp"
113 const char* cName = name.c_str(); 113 const char* cName = name.c_str();
114 const char* dot = strrchr(cName, '.'); 114 const char* dot = strrchr(cName, '.');
115 if (dot != NULL) { 115 if (dot != nullptr) {
116 gInputFileName.set(cName, dot - cName); 116 gInputFileName.set(cName, dot - cName);
117 } else { 117 } else {
118 gInputFileName.set(name); 118 gInputFileName.set(name);
119 } 119 }
120 } 120 }
121 121
122 /** 122 /**
123 * Write the raw encoded bitmap data to a file. 123 * Write the raw encoded bitmap data to a file.
124 */ 124 */
125 static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitma p) { 125 static bool write_image_to_file(const void* buffer, size_t size, SkBitmap* bitma p) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 reset_image_file_base_name(inputFilename); 174 reset_image_file_base_name(inputFilename);
175 proc = &write_image_to_file; 175 proc = &write_image_to_file;
176 } else { 176 } else {
177 proc = &SkImageDecoder::DecodeMemory; 177 proc = &SkImageDecoder::DecodeMemory;
178 } 178 }
179 179
180 SkDebugf("deserializing... %s\n", inputPath.c_str()); 180 SkDebugf("deserializing... %s\n", inputPath.c_str());
181 181
182 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, pr oc)); 182 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, pr oc));
183 183
184 if (NULL == picture) { 184 if (nullptr == picture) {
185 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str()); 185 SkDebugf("Could not read an SkPicture from %s\n", inputPath.c_str());
186 return false; 186 return false;
187 } 187 }
188 188
189 while (FLAGS_bench_record) { 189 while (FLAGS_bench_record) {
190 SkPictureRecorder recorder; 190 SkPictureRecorder recorder;
191 picture->playback(recorder.beginRecording(picture->cullRect().width(), 191 picture->playback(recorder.beginRecording(picture->cullRect().width(),
192 picture->cullRect().height(), 192 picture->cullRect().height(),
193 NULL, 0)); 193 nullptr, 0));
194 SkAutoTUnref<SkPicture> other(recorder.endRecording()); 194 SkAutoTUnref<SkPicture> other(recorder.endRecording());
195 } 195 }
196 196
197 SkDebugf("drawing... [%f %f %f %f] %s\n", 197 SkDebugf("drawing... [%f %f %f %f] %s\n",
198 picture->cullRect().fLeft, picture->cullRect().fTop, 198 picture->cullRect().fLeft, picture->cullRect().fTop,
199 picture->cullRect().fRight, picture->cullRect().fBottom, 199 picture->cullRect().fRight, picture->cullRect().fBottom,
200 inputPath.c_str()); 200 inputPath.c_str());
201 201
202 renderer.init(picture, &writePathString, &mismatchPathString, &inputFilename , 202 renderer.init(picture, &writePathString, &mismatchPathString, &inputFilename ,
203 FLAGS_writeChecksumBasedFilenames, FLAGS_mpd); 203 FLAGS_writeChecksumBasedFilenames, FLAGS_mpd);
(...skipping 17 matching lines...) Expand all
221 } 221 }
222 222
223 static int MaxByteDiff(uint32_t v1, uint32_t v2) { 223 static int MaxByteDiff(uint32_t v1, uint32_t v2) {
224 return SkMax32(SkMax32(SkTAbs(getByte(v1, 0) - getByte(v2, 0)), SkTAbs(getBy te(v1, 1) - getByte(v2, 1))), 224 return SkMax32(SkMax32(SkTAbs(getByte(v1, 0) - getByte(v2, 0)), SkTAbs(getBy te(v1, 1) - getByte(v2, 1))),
225 SkMax32(SkTAbs(getByte(v1, 2) - getByte(v2, 2)), SkTAbs(getBy te(v1, 3) - getByte(v2, 3)))); 225 SkMax32(SkTAbs(getByte(v1, 2) - getByte(v2, 2)), SkTAbs(getBy te(v1, 3) - getByte(v2, 3))));
226 } 226 }
227 227
228 class AutoRestoreBbhType { 228 class AutoRestoreBbhType {
229 public: 229 public:
230 AutoRestoreBbhType() { 230 AutoRestoreBbhType() {
231 fRenderer = NULL; 231 fRenderer = nullptr;
232 fSavedBbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType; 232 fSavedBbhType = sk_tools::PictureRenderer::kNone_BBoxHierarchyType;
233 } 233 }
234 234
235 void set(sk_tools::PictureRenderer* renderer, 235 void set(sk_tools::PictureRenderer* renderer,
236 sk_tools::PictureRenderer::BBoxHierarchyType bbhType) { 236 sk_tools::PictureRenderer::BBoxHierarchyType bbhType) {
237 fRenderer = renderer; 237 fRenderer = renderer;
238 fSavedBbhType = renderer->getBBoxHierarchyType(); 238 fSavedBbhType = renderer->getBBoxHierarchyType();
239 renderer->setBBoxHierarchyType(bbhType); 239 renderer->setBBoxHierarchyType(bbhType);
240 } 240 }
241 241
242 ~AutoRestoreBbhType() { 242 ~AutoRestoreBbhType() {
243 if (fRenderer) { 243 if (fRenderer) {
244 fRenderer->setBBoxHierarchyType(fSavedBbhType); 244 fRenderer->setBBoxHierarchyType(fSavedBbhType);
245 } 245 }
246 } 246 }
247 247
248 private: 248 private:
249 sk_tools::PictureRenderer* fRenderer; 249 sk_tools::PictureRenderer* fRenderer;
250 sk_tools::PictureRenderer::BBoxHierarchyType fSavedBbhType; 250 sk_tools::PictureRenderer::BBoxHierarchyType fSavedBbhType;
251 }; 251 };
252 252
253 /** 253 /**
254 * Render the SKP file(s) within inputPath. 254 * Render the SKP file(s) within inputPath.
255 * 255 *
256 * @param inputPath path to an individual SKP file, or a directory of SKP files 256 * @param inputPath path to an individual SKP file, or a directory of SKP files
257 * @param writePath if not NULL, write all image(s) generated into this director y 257 * @param writePath if not nullptr, write all image(s) generated into this direc tory
258 * @param mismatchPath if not NULL, write any image(s) not matching expectations into this directory 258 * @param mismatchPath if not nullptr, write any image(s) not matching expectati ons into this directory
259 * @param renderer PictureRenderer to use to render the SKPs 259 * @param renderer PictureRenderer to use to render the SKPs
260 * @param jsonSummaryPtr if not NULL, add the image(s) generated to this summary 260 * @param jsonSummaryPtr if not nullptr, add the image(s) generated to this summ ary
261 */ 261 */
262 static bool render_picture(const SkString& inputPath, const SkString* writePath, 262 static bool render_picture(const SkString& inputPath, const SkString* writePath,
263 const SkString* mismatchPath, sk_tools::PictureRender er& renderer, 263 const SkString* mismatchPath, sk_tools::PictureRender er& renderer,
264 sk_tools::ImageResultsAndExpectations *jsonSummaryPtr ) { 264 sk_tools::ImageResultsAndExpectations *jsonSummaryPtr ) {
265 int diffs[256] = {0}; 265 int diffs[256] = {0};
266 SkBitmap* bitmap = NULL; 266 SkBitmap* bitmap = nullptr;
267 renderer.setJsonSummaryPtr(jsonSummaryPtr); 267 renderer.setJsonSummaryPtr(jsonSummaryPtr);
268 bool success = render_picture_internal(inputPath, 268 bool success = render_picture_internal(inputPath,
269 FLAGS_writeWholeImage ? NULL : writePath, 269 FLAGS_writeWholeImage ? nullptr : writePath,
270 FLAGS_writeWholeImage ? NULL : mismatchPath, 270 FLAGS_writeWholeImage ? nullptr : mismatchPath,
271 renderer, 271 renderer,
272 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : NULL); 272 FLAGS_validate || FLAGS_writeWholeImage ? &bitmap : nullptr);
273 273
274 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == NULL )) { 274 if (!success || ((FLAGS_validate || FLAGS_writeWholeImage) && bitmap == null ptr)) {
275 SkDebugf("Failed to draw the picture.\n"); 275 SkDebugf("Failed to draw the picture.\n");
276 delete bitmap; 276 delete bitmap;
277 return false; 277 return false;
278 } 278 }
279 279
280 if (FLAGS_validate) { 280 if (FLAGS_validate) {
281 SkBitmap* referenceBitmap = NULL; 281 SkBitmap* referenceBitmap = nullptr;
282 sk_tools::PictureRenderer* referenceRenderer; 282 sk_tools::PictureRenderer* referenceRenderer;
283 // If the renderer uses a BBoxHierarchy, then the reference renderer 283 // If the renderer uses a BBoxHierarchy, then the reference renderer
284 // will be the same renderer, without the bbh. 284 // will be the same renderer, without the bbh.
285 AutoRestoreBbhType arbbh; 285 AutoRestoreBbhType arbbh;
286 if (sk_tools::PictureRenderer::kNone_BBoxHierarchyType != 286 if (sk_tools::PictureRenderer::kNone_BBoxHierarchyType !=
287 renderer.getBBoxHierarchyType()) { 287 renderer.getBBoxHierarchyType()) {
288 referenceRenderer = &renderer; 288 referenceRenderer = &renderer;
289 referenceRenderer->ref(); // to match auto unref below 289 referenceRenderer->ref(); // to match auto unref below
290 arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHi erarchyType); 290 arbbh.set(referenceRenderer, sk_tools::PictureRenderer::kNone_BBoxHi erarchyType);
291 } else { 291 } else {
292 #if SK_SUPPORT_GPU 292 #if SK_SUPPORT_GPU
293 referenceRenderer = new sk_tools::SimplePictureRenderer(renderer.get GrContextOptions()); 293 referenceRenderer = new sk_tools::SimplePictureRenderer(renderer.get GrContextOptions());
294 #else 294 #else
295 referenceRenderer = new sk_tools::SimplePictureRenderer; 295 referenceRenderer = new sk_tools::SimplePictureRenderer;
296 #endif 296 #endif
297 } 297 }
298 SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRe nderer); 298 SkAutoTUnref<sk_tools::PictureRenderer> aurReferenceRenderer(referenceRe nderer);
299 299
300 success = render_picture_internal(inputPath, NULL, NULL, *referenceRende rer, 300 success = render_picture_internal(inputPath, nullptr, nullptr, *referenc eRenderer,
301 &referenceBitmap); 301 &referenceBitmap);
302 302
303 if (!success || NULL == referenceBitmap || NULL == referenceBitmap->getP ixels()) { 303 if (!success || nullptr == referenceBitmap || nullptr == referenceBitmap ->getPixels()) {
304 SkDebugf("Failed to draw the reference picture.\n"); 304 SkDebugf("Failed to draw the reference picture.\n");
305 delete bitmap; 305 delete bitmap;
306 delete referenceBitmap; 306 delete referenceBitmap;
307 return false; 307 return false;
308 } 308 }
309 309
310 if (success && (bitmap->width() != referenceBitmap->width())) { 310 if (success && (bitmap->width() != referenceBitmap->width())) {
311 SkDebugf("Expected image width: %i, actual image width %i.\n", 311 SkDebugf("Expected image width: %i, actual image width %i.\n",
312 referenceBitmap->width(), bitmap->width()); 312 referenceBitmap->width(), bitmap->width());
313 delete bitmap; 313 delete bitmap;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 SkString inputFilename = SkOSPath::Basename(inputPath.c_str()); 356 SkString inputFilename = SkOSPath::Basename(inputPath.c_str());
357 SkString outputFilename(inputFilename); 357 SkString outputFilename(inputFilename);
358 sk_tools::replace_char(&outputFilename, '.', '_'); 358 sk_tools::replace_char(&outputFilename, '.', '_');
359 outputFilename.append(".png"); 359 outputFilename.append(".png");
360 360
361 if (jsonSummaryPtr) { 361 if (jsonSummaryPtr) {
362 sk_tools::ImageDigest imageDigest(*bitmap); 362 sk_tools::ImageDigest imageDigest(*bitmap);
363 jsonSummaryPtr->add(inputFilename.c_str(), outputFilename.c_str(), i mageDigest); 363 jsonSummaryPtr->add(inputFilename.c_str(), outputFilename.c_str(), i mageDigest);
364 if ((mismatchPath) && !mismatchPath->isEmpty() && 364 if ((mismatchPath) && !mismatchPath->isEmpty() &&
365 !jsonSummaryPtr->getExpectation(inputFilename.c_str()).matches(i mageDigest)) { 365 !jsonSummaryPtr->getExpectation(inputFilename.c_str()).matches(i mageDigest)) {
366 success &= sk_tools::write_bitmap_to_disk(*bitmap, *mismatchPath , NULL, 366 success &= sk_tools::write_bitmap_to_disk(*bitmap, *mismatchPath , nullptr,
367 outputFilename); 367 outputFilename);
368 } 368 }
369 } 369 }
370 370
371 if ((writePath) && !writePath->isEmpty()) { 371 if ((writePath) && !writePath->isEmpty()) {
372 success &= sk_tools::write_bitmap_to_disk(*bitmap, *writePath, NULL, outputFilename); 372 success &= sk_tools::write_bitmap_to_disk(*bitmap, *writePath, nullp tr, outputFilename);
373 } 373 }
374 } 374 }
375 delete bitmap; 375 delete bitmap;
376 376
377 return success; 377 return success;
378 } 378 }
379 379
380 380
381 static int process_input(const char* input, const SkString* writePath, 381 static int process_input(const char* input, const SkString* writePath,
382 const SkString* mismatchPath, sk_tools::PictureRenderer & renderer, 382 const SkString* mismatchPath, sk_tools::PictureRenderer & renderer,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 436 }
437 } 437 }
438 438
439 SkString errorString; 439 SkString errorString;
440 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString, 440 SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString,
441 kRender_Pictu reTool)); 441 kRender_Pictu reTool));
442 if (errorString.size() > 0) { 442 if (errorString.size() > 0) {
443 SkDebugf("%s\n", errorString.c_str()); 443 SkDebugf("%s\n", errorString.c_str());
444 } 444 }
445 445
446 if (renderer.get() == NULL) { 446 if (renderer.get() == nullptr) {
447 exit(-1); 447 exit(-1);
448 } 448 }
449 449
450 SkAutoGraphics ag; 450 SkAutoGraphics ag;
451 451
452 SkString writePath; 452 SkString writePath;
453 if (FLAGS_writePath.count() == 1) { 453 if (FLAGS_writePath.count() == 1) {
454 writePath.set(FLAGS_writePath[0]); 454 writePath.set(FLAGS_writePath[0]);
455 } 455 }
456 SkString mismatchPath; 456 SkString mismatchPath;
457 if (FLAGS_mismatchPath.count() == 1) { 457 if (FLAGS_mismatchPath.count() == 1) {
458 mismatchPath.set(FLAGS_mismatchPath[0]); 458 mismatchPath.set(FLAGS_mismatchPath[0]);
459 } 459 }
460 sk_tools::ImageResultsAndExpectations jsonSummary; 460 sk_tools::ImageResultsAndExpectations jsonSummary;
461 sk_tools::ImageResultsAndExpectations* jsonSummaryPtr = NULL; 461 sk_tools::ImageResultsAndExpectations* jsonSummaryPtr = nullptr;
462 if (FLAGS_writeJsonSummaryPath.count() == 1) { 462 if (FLAGS_writeJsonSummaryPath.count() == 1) {
463 jsonSummaryPtr = &jsonSummary; 463 jsonSummaryPtr = &jsonSummary;
464 if (FLAGS_readJsonSummaryPath.count() == 1) { 464 if (FLAGS_readJsonSummaryPath.count() == 1) {
465 SkASSERT(jsonSummary.readExpectationsFile(FLAGS_readJsonSummaryPath[ 0])); 465 SkASSERT(jsonSummary.readExpectationsFile(FLAGS_readJsonSummaryPath[ 0]));
466 } 466 }
467 } 467 }
468 468
469 int failures = 0; 469 int failures = 0;
470 for (int i = 0; i < FLAGS_readPath.count(); i ++) { 470 for (int i = 0; i < FLAGS_readPath.count(); i ++) {
471 failures += process_input(FLAGS_readPath[i], &writePath, &mismatchPath, *renderer.get(), 471 failures += process_input(FLAGS_readPath[i], &writePath, &mismatchPath, *renderer.get(),
(...skipping 30 matching lines...) Expand all
502 jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]); 502 jsonSummary.writeToFile(FLAGS_writeJsonSummaryPath[0]);
503 } 503 }
504 return 0; 504 return 0;
505 } 505 }
506 506
507 #if !defined SK_BUILD_FOR_IOS 507 #if !defined SK_BUILD_FOR_IOS
508 int main(int argc, char * const argv[]) { 508 int main(int argc, char * const argv[]) {
509 return tool_main(argc, (char**) argv); 509 return tool_main(argc, (char**) argv);
510 } 510 }
511 #endif 511 #endif
OLDNEW
« no previous file with comments | « tools/render_pdfs_main.cpp ('k') | tools/sk_tool_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698