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

Side by Side Diff: tests/SkpSkGrTest.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/SkResourceCacheTest.cpp ('k') | tools/VisualBench/VisualBenchmarkStream.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 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 "GrContext.h" 8 #include "GrContext.h"
9 #include "GrContextFactory.h" 9 #include "GrContextFactory.h"
10 #include "GrRenderTarget.h" 10 #include "GrRenderTarget.h"
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pn gName) { 371 static void writePict(const SkBitmap& bitmap, const char* outDir, const char* pn gName) {
372 SkString outFile = make_filepath(0, outDir, pngName); 372 SkString outFile = make_filepath(0, outDir, pngName);
373 if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, 373 if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap,
374 SkImageEncoder::kPNG_Type, 100)) { 374 SkImageEncoder::kPNG_Type, 100)) {
375 SkDebugf("unable to encode gr %s (width=%d height=%d)br \n", pngName, 375 SkDebugf("unable to encode gr %s (width=%d height=%d)br \n", pngName,
376 bitmap.width(), bitmap.height()); 376 bitmap.width(), bitmap.height());
377 } 377 }
378 } 378 }
379 379
380 void TestResult::testOne() { 380 void TestResult::testOne() {
381 SkPicture* pic = nullptr; 381 sk_sp<SkPicture> pic;
382 { 382 {
383 SkString d; 383 SkString d;
384 d.printf(" {%d, \"%s\"},", fDirNo, fFilename); 384 d.printf(" {%d, \"%s\"},", fDirNo, fFilename);
385 SkString path = make_filepath(fDirNo, IN_DIR, fFilename); 385 SkString path = make_filepath(fDirNo, IN_DIR, fFilename);
386 SkFILEStream stream(path.c_str()); 386 SkFILEStream stream(path.c_str());
387 if (!stream.isValid()) { 387 if (!stream.isValid()) {
388 SkDebugf("invalid stream %s\n", path.c_str()); 388 SkDebugf("invalid stream %s\n", path.c_str());
389 goto finish; 389 goto finish;
390 } 390 }
391 if (fTestStep == kEncodeFiles) { 391 if (fTestStep == kEncodeFiles) {
392 size_t length = stream.getLength(); 392 size_t length = stream.getLength();
393 SkTArray<char, true> bytes; 393 SkTArray<char, true> bytes;
394 bytes.push_back_n(length); 394 bytes.push_back_n(length);
395 stream.read(&bytes[0], length); 395 stream.read(&bytes[0], length);
396 stream.rewind(); 396 stream.rewind();
397 SkString wPath = make_filepath(0, outSkpDir, fFilename); 397 SkString wPath = make_filepath(0, outSkpDir, fFilename);
398 SkFILEWStream wStream(wPath.c_str()); 398 SkFILEWStream wStream(wPath.c_str());
399 wStream.write(&bytes[0], length); 399 wStream.write(&bytes[0], length);
400 wStream.flush(); 400 wStream.flush();
401 } 401 }
402 pic = SkPicture::CreateFromStream(&stream); 402 pic = SkPicture::MakeFromStream(&stream);
403 if (!pic) { 403 if (!pic) {
404 SkDebugf("unable to decode %s\n", fFilename); 404 SkDebugf("unable to decode %s\n", fFilename);
405 goto finish; 405 goto finish;
406 } 406 }
407 int pWidth = pic->width(); 407 int pWidth = pic->width();
408 int pHeight = pic->height(); 408 int pHeight = pic->height();
409 int pLargerWH = SkTMax(pWidth, pHeight); 409 int pLargerWH = SkTMax(pWidth, pHeight);
410 GrContextFactory contextFactory; 410 GrContextFactory contextFactory;
411 #ifdef SK_BUILD_FOR_WIN 411 #ifdef SK_BUILD_FOR_WIN
412 GrContext* context = contextFactory.get(kAngle); 412 GrContext* context = contextFactory.get(kAngle);
(...skipping 16 matching lines...) Expand all
429 dim.fY = (pHeight + scale - 1) / scale; 429 dim.fY = (pHeight + scale - 1) / scale;
430 bool success = bitmap.allocN32Pixels(dim.fX, dim.fY); 430 bool success = bitmap.allocN32Pixels(dim.fX, dim.fY);
431 if (success) { 431 if (success) {
432 break; 432 break;
433 } 433 }
434 SkDebugf("-%d-", scale); 434 SkDebugf("-%d-", scale);
435 } while ((scale *= 2) < 256); 435 } while ((scale *= 2) < 256);
436 if (scale >= 256) { 436 if (scale >= 256) {
437 SkDebugf("unable to allocate bitmap for %s (w=%d h=%d) (sw=%d sh=%d) \n", 437 SkDebugf("unable to allocate bitmap for %s (w=%d h=%d) (sw=%d sh=%d) \n",
438 fFilename, pWidth, pHeight, dim.fX, dim.fY); 438 fFilename, pWidth, pHeight, dim.fX, dim.fY);
439 goto finish; 439 return;
440 } 440 }
441 SkCanvas skCanvas(bitmap); 441 SkCanvas skCanvas(bitmap);
442 drawPict(pic, &skCanvas, fScaleOversized ? scale : 1); 442 drawPict(pic, &skCanvas, fScaleOversized ? scale : 1);
443 GrTextureDesc desc; 443 GrTextureDesc desc;
444 desc.fConfig = kSkia8888_GrPixelConfig; 444 desc.fConfig = kSkia8888_GrPixelConfig;
445 desc.fFlags = kRenderTarget_GrTextureFlagBit; 445 desc.fFlags = kRenderTarget_GrTextureFlagBit;
446 desc.fWidth = dim.fX; 446 desc.fWidth = dim.fX;
447 desc.fHeight = dim.fY; 447 desc.fHeight = dim.fY;
448 desc.fSampleCnt = 0; 448 desc.fSampleCnt = 0;
449 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, nul lptr, 0)); 449 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, nul lptr, 0));
450 if (!texture) { 450 if (!texture) {
451 SkDebugf("unable to allocate texture for %s (w=%d h=%d)\n", fFilenam e, 451 SkDebugf("unable to allocate texture for %s (w=%d h=%d)\n", fFilenam e,
452 dim.fX, dim.fY); 452 dim.fX, dim.fY);
453 goto finish; 453 return;
454 } 454 }
455 SkGpuDevice grDevice(context, texture.get()); 455 SkGpuDevice grDevice(context, texture.get());
456 SkCanvas grCanvas(&grDevice); 456 SkCanvas grCanvas(&grDevice);
457 drawPict(pic, &grCanvas, fScaleOversized ? scale : 1); 457 drawPict(pic.get(), &grCanvas, fScaleOversized ? scale : 1);
458 458
459 SkBitmap grBitmap; 459 SkBitmap grBitmap;
460 grBitmap.allocPixels(grCanvas.imageInfo()); 460 grBitmap.allocPixels(grCanvas.imageInfo());
461 grCanvas.readPixels(&grBitmap, 0, 0); 461 grCanvas.readPixels(&grBitmap, 0, 0);
462 462
463 if (fTestStep == kCompareBits) { 463 if (fTestStep == kCompareBits) {
464 fPixelError = similarBits(grBitmap, bitmap); 464 fPixelError = similarBits(grBitmap, bitmap);
465 int skTime = timePict(pic, &skCanvas); 465 int skTime = timePict(pic, &skCanvas);
466 int grTime = timePict(pic, &grCanvas); 466 int grTime = timePict(pic, &grCanvas);
467 fTime = skTime - grTime; 467 fTime = skTime - grTime;
468 } else if (fTestStep == kEncodeFiles) { 468 } else if (fTestStep == kEncodeFiles) {
469 SkString pngStr = make_png_name(fFilename); 469 SkString pngStr = make_png_name(fFilename);
470 const char* pngName = pngStr.c_str(); 470 const char* pngName = pngStr.c_str();
471 writePict(grBitmap, outGrDir, pngName); 471 writePict(grBitmap, outGrDir, pngName);
472 writePict(bitmap, outSkDir, pngName); 472 writePict(bitmap, outSkDir, pngName);
473 } 473 }
474 } 474 }
475 finish:
476 delete pic;
477 } 475 }
478 476
479 static SkString makeStatusString(int dirNo) { 477 static SkString makeStatusString(int dirNo) {
480 SkString statName; 478 SkString statName;
481 statName.printf("stats%d.txt", dirNo); 479 statName.printf("stats%d.txt", dirNo);
482 SkString statusFile = make_filepath(0, outStatusDir, statName.c_str()); 480 SkString statusFile = make_filepath(0, outStatusDir, statName.c_str());
483 return statusFile; 481 return statusFile;
484 } 482 }
485 483
486 class PreParser { 484 class PreParser {
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 int testIndex = 166; 745 int testIndex = 166;
748 int dirIndex = skipOverSkGr[testIndex - 166].directory; 746 int dirIndex = skipOverSkGr[testIndex - 166].directory;
749 SkString pictDir = make_in_dir_name(dirIndex); 747 SkString pictDir = make_in_dir_name(dirIndex);
750 if (pictDir.size() == 0) { 748 if (pictDir.size() == 0) {
751 return; 749 return;
752 } 750 }
753 SkString filename(skipOverSkGr[testIndex - 166].filename); 751 SkString filename(skipOverSkGr[testIndex - 166].filename);
754 TestResult::Test(dirIndex, filename.c_str(), kCompareBits, reporter->verbose ()); 752 TestResult::Test(dirIndex, filename.c_str(), kCompareBits, reporter->verbose ());
755 TestResult::Test(dirIndex, filename.c_str(), kEncodeFiles, reporter->verbose ()); 753 TestResult::Test(dirIndex, filename.c_str(), kEncodeFiles, reporter->verbose ());
756 } 754 }
OLDNEW
« no previous file with comments | « tests/SkResourceCacheTest.cpp ('k') | tools/VisualBench/VisualBenchmarkStream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698