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

Side by Side Diff: tests/ReadPixelsTest.cpp

Issue 1860593002: One signature for creating unit tests that run on premade GrContexts (Closed) Base URL: https://skia.googlesource.com/skia.git@try_no_native
Patch Set: another guess to fix windows Created 4 years, 8 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/PrimitiveProcessorTest.cpp ('k') | tests/ReadWriteAlphaTest.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 2011 Google Inc. 2 * Copyright 2011 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkMathPriv.h" 10 #include "SkMathPriv.h"
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 380 }
381 } 381 }
382 } 382 }
383 DEF_TEST(ReadPixels, reporter) { 383 DEF_TEST(ReadPixels, reporter) {
384 const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H); 384 const SkImageInfo info = SkImageInfo::MakeN32Premul(DEV_W, DEV_H);
385 auto surface(SkSurface::MakeRaster(info)); 385 auto surface(SkSurface::MakeRaster(info));
386 // SW readback fails a premul check when reading back to an unaligned rowbyt es. 386 // SW readback fails a premul check when reading back to an unaligned rowbyt es.
387 test_readpixels(reporter, surface, kLastAligned_BitmapInit); 387 test_readpixels(reporter, surface, kLastAligned_BitmapInit);
388 } 388 }
389 #if SK_SUPPORT_GPU 389 #if SK_SUPPORT_GPU
390 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, context) { 390 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, ctxInfo) {
391 for (auto& origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) { 391 for (auto& origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
392 GrSurfaceDesc desc; 392 GrSurfaceDesc desc;
393 desc.fFlags = kRenderTarget_GrSurfaceFlag; 393 desc.fFlags = kRenderTarget_GrSurfaceFlag;
394 desc.fWidth = DEV_W; 394 desc.fWidth = DEV_W;
395 desc.fHeight = DEV_H; 395 desc.fHeight = DEV_H;
396 desc.fConfig = kSkia8888_GrPixelConfig; 396 desc.fConfig = kSkia8888_GrPixelConfig;
397 desc.fOrigin = origin; 397 desc.fOrigin = origin;
398 SkAutoTUnref<GrTexture> surfaceTexture( 398 SkAutoTUnref<GrTexture> surfaceTexture(
399 context->textureProvider()->createTexture(desc, SkBudgeted::kNo)); 399 ctxInfo.fGrContext->textureProvider()->createTexture(desc, SkBudgete d::kNo));
400 auto surface(SkSurface::MakeRenderTargetDirect(surfaceTexture->asRenderT arget())); 400 auto surface(SkSurface::MakeRenderTargetDirect(surfaceTexture->asRenderT arget()));
401 desc.fFlags = kNone_GrSurfaceFlags; 401 desc.fFlags = kNone_GrSurfaceFlags;
402 test_readpixels(reporter, surface, kLast_BitmapInit); 402 test_readpixels(reporter, surface, kLast_BitmapInit);
403 } 403 }
404 } 404 }
405 #endif 405 #endif
406 406
407 #if SK_SUPPORT_GPU 407 #if SK_SUPPORT_GPU
408 static void test_readpixels_texture(skiatest::Reporter* reporter, GrTexture* tex ture) { 408 static void test_readpixels_texture(skiatest::Reporter* reporter, GrTexture* tex ture) {
409 fill_src_texture(texture); 409 fill_src_texture(texture);
(...skipping 25 matching lines...) Expand all
435 bmp.height(), dstConfig, bmp.getPixels(), 435 bmp.height(), dstConfig, bmp.getPixels(),
436 bmp.rowBytes(), flags); 436 bmp.rowBytes(), flags);
437 bmp.unlockPixels(); 437 bmp.unlockPixels();
438 check_read(reporter, bmp, srcRect.fLeft, srcRect.fTop, 438 check_read(reporter, bmp, srcRect.fLeft, srcRect.fTop,
439 success, true); 439 success, true);
440 } 440 }
441 } 441 }
442 } 442 }
443 } 443 }
444 } 444 }
445 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, context) { 445 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) {
446 // On the GPU we will also try reading back from a non-renderable texture. 446 // On the GPU we will also try reading back from a non-renderable texture.
447 for (auto& origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) { 447 for (auto& origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) {
448 SkAutoTUnref<GrTexture> texture; 448 SkAutoTUnref<GrTexture> texture;
449 GrSurfaceDesc desc; 449 GrSurfaceDesc desc;
450 desc.fFlags = kRenderTarget_GrSurfaceFlag; 450 desc.fFlags = kRenderTarget_GrSurfaceFlag;
451 desc.fWidth = DEV_W; 451 desc.fWidth = DEV_W;
452 desc.fHeight = DEV_H; 452 desc.fHeight = DEV_H;
453 desc.fConfig = kSkia8888_GrPixelConfig; 453 desc.fConfig = kSkia8888_GrPixelConfig;
454 desc.fOrigin = origin; 454 desc.fOrigin = origin;
455 desc.fFlags = kNone_GrSurfaceFlags; 455 desc.fFlags = kNone_GrSurfaceFlags;
456 texture.reset(context->textureProvider()->createTexture(desc, SkBudgeted ::kNo)); 456 texture.reset(ctxInfo.fGrContext->textureProvider()->createTexture(desc, SkBudgeted::kNo));
457 test_readpixels_texture(reporter, texture); 457 test_readpixels_texture(reporter, texture);
458 } 458 }
459 } 459 }
460 #endif 460 #endif
461 ///////////////////// 461 /////////////////////
462 #if SK_SUPPORT_GPU 462 #if SK_SUPPORT_GPU
463 463
464 // make_ringed_bitmap was lifted from gm/bleed.cpp, as that GM was what showed t he following 464 // make_ringed_bitmap was lifted from gm/bleed.cpp, as that GM was what showed t he following
465 // bug when a change was made to SkImage_Raster.cpp. It is possible that other t est bitmaps 465 // bug when a change was made to SkImage_Raster.cpp. It is possible that other t est bitmaps
466 // would also tickle https://bug.skia.org/4351 but this one is know to do it, so I've pasted the code 466 // would also tickle https://bug.skia.org/4351 but this one is know to do it, so I've pasted the code
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 /* 569 /*
570 * Test two different ways to turn a subset of a bitmap into a texture 570 * Test two different ways to turn a subset of a bitmap into a texture
571 * - subset and then upload to a texture 571 * - subset and then upload to a texture
572 * - upload to a texture and then subset 572 * - upload to a texture and then subset
573 * 573 *
574 * These two techniques result in the same pixels (ala readPixels) 574 * These two techniques result in the same pixels (ala readPixels)
575 * but when we draw them (rotated+scaled) we don't always get the same results. 575 * but when we draw them (rotated+scaled) we don't always get the same results.
576 * 576 *
577 * https://bug.skia.org/4351 577 * https://bug.skia.org/4351
578 */ 578 */
579 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Subset_Gpu, reporter, context) { 579 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Subset_Gpu, reporter, ctxInfo) {
580 SkBitmap bitmap; 580 SkBitmap bitmap;
581 make_ringed_bitmap(&bitmap, 6, 6); 581 make_ringed_bitmap(&bitmap, 6, 6);
582 const SkIRect subset = SkIRect::MakeLTRB(2, 2, 4, 4); 582 const SkIRect subset = SkIRect::MakeLTRB(2, 2, 4, 4);
583 583
584 // make two textures... 584 // make two textures...
585 SkBitmap bm_subset, tx_subset; 585 SkBitmap bm_subset, tx_subset;
586 586
587 // ... one from a texture-subset 587 // ... one from a texture-subset
588 SkAutoTUnref<GrTexture> fullTx(GrRefCachedBitmapTexture(context, bitmap, 588 SkAutoTUnref<GrTexture> fullTx(GrRefCachedBitmapTexture(ctxInfo.fGrContext, bitmap,
589 GrTextureParams::Cla mpNoFilter())); 589 GrTextureParams::Cla mpNoFilter()));
590 SkBitmap tx_full; 590 SkBitmap tx_full;
591 GrWrapTextureInBitmap(fullTx, bitmap.width(), bitmap.height(), true, &tx_ful l); 591 GrWrapTextureInBitmap(fullTx, bitmap.width(), bitmap.height(), true, &tx_ful l);
592 tx_full.extractSubset(&tx_subset, subset); 592 tx_full.extractSubset(&tx_subset, subset);
593 593
594 // ... one from a bitmap-subset 594 // ... one from a bitmap-subset
595 SkBitmap tmp_subset; 595 SkBitmap tmp_subset;
596 bitmap.extractSubset(&tmp_subset, subset); 596 bitmap.extractSubset(&tmp_subset, subset);
597 SkAutoTUnref<GrTexture> subsetTx(GrRefCachedBitmapTexture(context, tmp_subse t, 597 SkAutoTUnref<GrTexture> subsetTx(GrRefCachedBitmapTexture(ctxInfo.fGrContext , tmp_subset,
598 GrTextureParams::C lampNoFilter())); 598 GrTextureParams::C lampNoFilter()));
599 GrWrapTextureInBitmap(subsetTx, tmp_subset.width(), tmp_subset.height(), tru e, &bm_subset); 599 GrWrapTextureInBitmap(subsetTx, tmp_subset.width(), tmp_subset.height(), tru e, &bm_subset);
600 600
601 // did we get the same subset? 601 // did we get the same subset?
602 compare_textures(reporter, bm_subset.getTexture(), tx_subset.getTexture()); 602 compare_textures(reporter, bm_subset.getTexture(), tx_subset.getTexture());
603 603
604 // do they draw the same? 604 // do they draw the same?
605 const SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); 605 const SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
606 auto surfA(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); 606 auto surfA(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kNo, info));
607 auto surfB(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); 607 auto surfB(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kNo, info));
608 608
609 if (false) { 609 if (false) {
610 // 610 //
611 // BUG: depending on the driver, if we calls this with various quality settings, it 611 // BUG: depending on the driver, if we calls this with various quality settings, it
612 // may fail. 612 // may fail.
613 // 613 //
614 SkFilterQuality quality = kLow_SkFilterQuality; 614 SkFilterQuality quality = kLow_SkFilterQuality;
615 615
616 SkAutoTUnref<SkData> dataA(draw_into_surface(surfA.get(), bm_subset, qua lity)); 616 SkAutoTUnref<SkData> dataA(draw_into_surface(surfA.get(), bm_subset, qua lity));
617 SkAutoTUnref<SkData> dataB(draw_into_surface(surfB.get(), tx_subset, qua lity)); 617 SkAutoTUnref<SkData> dataB(draw_into_surface(surfB.get(), tx_subset, qua lity));
618 618
619 REPORTER_ASSERT(reporter, dataA->equals(dataB)); 619 REPORTER_ASSERT(reporter, dataA->equals(dataB));
620 if (false) { 620 if (false) {
621 dump_to_file("test_image_A.png", dataA); 621 dump_to_file("test_image_A.png", dataA);
622 dump_to_file("test_image_B.png", dataB); 622 dump_to_file("test_image_B.png", dataB);
623 } 623 }
624 } 624 }
625 } 625 }
626 #endif 626 #endif
OLDNEW
« no previous file with comments | « tests/PrimitiveProcessorTest.cpp ('k') | tests/ReadWriteAlphaTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698