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

Side by Side Diff: tests/PathOpsSkpClipTest.cpp

Issue 1811703002: return pictures as sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rely on RVO in picturerecorder Created 4 years, 9 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 | « tests/ImageTest.cpp ('k') | tests/PictureBBHTest.cpp » ('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 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 "CrashHandler.h" 8 #include "CrashHandler.h"
9 // #include "OverwriteLine.h" 9 // #include "OverwriteLine.h"
10 #include "Resources.h" 10 #include "Resources.h"
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pn gName) { 430 static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pn gName) {
431 SkString outFile = get_sum_path(outDir); 431 SkString outFile = get_sum_path(outDir);
432 outFile.appendf("%s%s", PATH_SLASH, pngName); 432 outFile.appendf("%s%s", PATH_SLASH, pngName);
433 if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPN G_Type, 100)) { 433 if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, SkImageEncoder::kPN G_Type, 100)) {
434 SkDebugf("unable to encode gr %s (width=%d height=%d)\n", pngName, 434 SkDebugf("unable to encode gr %s (width=%d height=%d)\n", pngName,
435 bitmap.width(), bitmap.height()); 435 bitmap.width(), bitmap.height());
436 } 436 }
437 } 437 }
438 438
439 void TestResult::testOne() { 439 void TestResult::testOne() {
440 SkPicture* pic = nullptr; 440 sk_sp<SkPicture> pic;
441 { 441 {
442 #if DEBUG_SHOW_TEST_NAME 442 #if DEBUG_SHOW_TEST_NAME
443 if (fTestStep == kCompareBits) { 443 if (fTestStep == kCompareBits) {
444 SkString testName(fFilename); 444 SkString testName(fFilename);
445 const char http[] = "http"; 445 const char http[] = "http";
446 if (testName.startsWith(http)) { 446 if (testName.startsWith(http)) {
447 testName.remove(0, sizeof(http) - 1); 447 testName.remove(0, sizeof(http) - 1);
448 } 448 }
449 while (testName.startsWith("_")) { 449 while (testName.startsWith("_")) {
450 testName.remove(0, 1); 450 testName.remove(0, 1);
451 } 451 }
452 const char dotSkp[] = ".skp"; 452 const char dotSkp[] = ".skp";
453 if (testName.endsWith(dotSkp)) { 453 if (testName.endsWith(dotSkp)) {
454 size_t len = testName.size(); 454 size_t len = testName.size();
455 testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1); 455 testName.remove(len - (sizeof(dotSkp) - 1), sizeof(dotSkp) - 1);
456 } 456 }
457 testName.prepend("skp"); 457 testName.prepend("skp");
458 testName.append("1"); 458 testName.append("1");
459 strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRI NG_LENGTH); 459 strncpy(DEBUG_FILENAME_STRING, testName.c_str(), DEBUG_FILENAME_STRI NG_LENGTH);
460 } else if (fTestStep == kEncodeFiles) { 460 } else if (fTestStep == kEncodeFiles) {
461 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH); 461 strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
462 } 462 }
463 #endif 463 #endif
464 SkString path = get_in_path(fDirNo, fFilename); 464 SkString path = get_in_path(fDirNo, fFilename);
465 SkFILEStream stream(path.c_str()); 465 SkFILEStream stream(path.c_str());
466 if (!stream.isValid()) { 466 if (!stream.isValid()) {
467 SkDebugf("invalid stream %s\n", path.c_str()); 467 SkDebugf("invalid stream %s\n", path.c_str());
468 goto finish; 468 return;
469 } 469 }
470 pic = SkPicture::CreateFromStream(&stream); 470 pic = SkPicture::MakeFromStream(&stream);
471 if (!pic) { 471 if (!pic) {
472 SkDebugf("unable to decode %s\n", fFilename); 472 SkDebugf("unable to decode %s\n", fFilename);
473 goto finish; 473 return;
474 } 474 }
475 SkScalar width = pic->cullRect().width(); 475 SkScalar width = pic->cullRect().width();
476 SkScalar height = pic->cullRect().height(); 476 SkScalar height = pic->cullRect().height();
477 SkBitmap oldBitmap, opBitmap; 477 SkBitmap oldBitmap, opBitmap;
478 fScale = 1; 478 fScale = 1;
479 while (width / fScale > 32767 || height / fScale > 32767) { 479 while (width / fScale > 32767 || height / fScale > 32767) {
480 ++fScale; 480 ++fScale;
481 } 481 }
482 do { 482 do {
483 int dimX = SkScalarCeilToInt(width / fScale); 483 int dimX = SkScalarCeilToInt(width / fScale);
484 int dimY = SkScalarCeilToInt(height / fScale); 484 int dimY = SkScalarCeilToInt(height / fScale);
485 if (oldBitmap.tryAllocN32Pixels(dimX, dimY) && opBitmap.tryAllocN32P ixels(dimX, dimY)) { 485 if (oldBitmap.tryAllocN32Pixels(dimX, dimY) && opBitmap.tryAllocN32P ixels(dimX, dimY)) {
486 break; 486 break;
487 } 487 }
488 SkDebugf("-%d-", fScale); 488 SkDebugf("-%d-", fScale);
489 } while (++fScale < 256); 489 } while (++fScale < 256);
490 if (fScale >= 256) { 490 if (fScale >= 256) {
491 SkDebugf("unable to allocate bitmap for %s (w=%f h=%f)\n", fFilename , 491 SkDebugf("unable to allocate bitmap for %s (w=%f h=%f)\n", fFilename ,
492 width, height); 492 width, height);
493 goto finish; 493 return;
494 } 494 }
495 oldBitmap.eraseColor(SK_ColorWHITE); 495 oldBitmap.eraseColor(SK_ColorWHITE);
496 SkCanvas oldCanvas(oldBitmap); 496 SkCanvas oldCanvas(oldBitmap);
497 oldCanvas.setAllowSimplifyClip(false); 497 oldCanvas.setAllowSimplifyClip(false);
498 opBitmap.eraseColor(SK_ColorWHITE); 498 opBitmap.eraseColor(SK_ColorWHITE);
499 SkCanvas opCanvas(opBitmap); 499 SkCanvas opCanvas(opBitmap);
500 opCanvas.setAllowSimplifyClip(true); 500 opCanvas.setAllowSimplifyClip(true);
501 drawPict(pic, &oldCanvas, fScale); 501 drawPict(pic.get(), &oldCanvas, fScale);
502 drawPict(pic, &opCanvas, fScale); 502 drawPict(pic.get(), &opCanvas, fScale);
503 if (fTestStep == kCompareBits) { 503 if (fTestStep == kCompareBits) {
504 fPixelError = similarBits(oldBitmap, opBitmap); 504 fPixelError = similarBits(oldBitmap, opBitmap);
505 int oldTime = timePict(pic, &oldCanvas); 505 int oldTime = timePict(pic.get(), &oldCanvas);
506 int opTime = timePict(pic, &opCanvas); 506 int opTime = timePict(pic.get(), &opCanvas);
507 fTime = SkTMax(0, oldTime - opTime); 507 fTime = SkTMax(0, oldTime - opTime);
508 } else if (fTestStep == kEncodeFiles) { 508 } else if (fTestStep == kEncodeFiles) {
509 SkString pngStr = make_png_name(fFilename); 509 SkString pngStr = make_png_name(fFilename);
510 const char* pngName = pngStr.c_str(); 510 const char* pngName = pngStr.c_str();
511 writePict(oldBitmap, outOldDir, pngName); 511 writePict(oldBitmap, outOldDir, pngName);
512 writePict(opBitmap, outOpDir, pngName); 512 writePict(opBitmap, outOpDir, pngName);
513 } 513 }
514 } 514 }
515 finish:
516 if (pic) {
517 pic->unref();
518 }
519 } 515 }
520 516
521 DEFINE_string2(match, m, "PathOpsSkpClipThreaded", 517 DEFINE_string2(match, m, "PathOpsSkpClipThreaded",
522 "[~][^]substring[$] [...] of test name to run.\n" 518 "[~][^]substring[$] [...] of test name to run.\n"
523 "Multiple matches may be separated by spaces.\n" 519 "Multiple matches may be separated by spaces.\n"
524 "~ causes a matching test to always be skipped\n" 520 "~ causes a matching test to always be skipped\n"
525 "^ requires the start of the test to match\n" 521 "^ requires the start of the test to match\n"
526 "$ requires the end of the test to match\n" 522 "$ requires the end of the test to match\n"
527 "^ and $ requires an exact match\n" 523 "^ and $ requires an exact match\n"
528 "If a test does not match any list entry,\n" 524 "If a test does not match any list entry,\n"
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 } 1093 }
1098 } 1094 }
1099 return 0; 1095 return 0;
1100 } 1096 }
1101 1097
1102 #if !defined(SK_BUILD_FOR_IOS) 1098 #if !defined(SK_BUILD_FOR_IOS)
1103 int main(int argc, char * const argv[]) { 1099 int main(int argc, char * const argv[]) {
1104 return tool_main(argc, (char**) argv); 1100 return tool_main(argc, (char**) argv);
1105 } 1101 }
1106 #endif 1102 #endif
OLDNEW
« no previous file with comments | « tests/ImageTest.cpp ('k') | tests/PictureBBHTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698