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

Side by Side Diff: tests/ReadPixelsTest.cpp

Issue 1817383002: switch surface to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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/PathTest.cpp ('k') | tests/RecordDrawTest.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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // overlapping bottom left and bottom right corners 317 // overlapping bottom left and bottom right corners
318 SkIRect::MakeLTRB(-10, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10), 318 SkIRect::MakeLTRB(-10, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10),
319 // touching entire left edge 319 // touching entire left edge
320 SkIRect::MakeLTRB(0, DEV_H, DEV_W, DEV_H + 10), 320 SkIRect::MakeLTRB(0, DEV_H, DEV_W, DEV_H + 10),
321 // overlapping bottom right corner 321 // overlapping bottom right corner
322 SkIRect::MakeLTRB(3 * DEV_W / 4, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10), 322 SkIRect::MakeLTRB(3 * DEV_W / 4, 3 * DEV_H / 4, DEV_W + 10, DEV_H + 10),
323 // overlapping top right and bottom right corners 323 // overlapping top right and bottom right corners
324 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10), 324 SkIRect::MakeLTRB(3 * DEV_W / 4, -10, DEV_W + 10, DEV_H + 10),
325 }; 325 };
326 326
327 static void test_readpixels(skiatest::Reporter* reporter, SkSurface* surface, 327 static void test_readpixels(skiatest::Reporter* reporter, const sk_sp<SkSurface> & surface,
328 BitmapInit lastBitmapInit) { 328 BitmapInit lastBitmapInit) {
329 SkCanvas* canvas = surface->getCanvas(); 329 SkCanvas* canvas = surface->getCanvas();
330 fill_src_canvas(canvas); 330 fill_src_canvas(canvas);
331 for (size_t rect = 0; rect < SK_ARRAY_COUNT(gReadPixelsTestRects); ++rect) { 331 for (size_t rect = 0; rect < SK_ARRAY_COUNT(gReadPixelsTestRects); ++rect) {
332 const SkIRect& srcRect = gReadPixelsTestRects[rect]; 332 const SkIRect& srcRect = gReadPixelsTestRects[rect];
333 for (BitmapInit bmi = kFirstBitmapInit; bmi <= lastBitmapInit; bmi = nex tBMI(bmi)) { 333 for (BitmapInit bmi = kFirstBitmapInit; bmi <= lastBitmapInit; bmi = nex tBMI(bmi)) {
334 for (size_t c = 0; c < SK_ARRAY_COUNT(gReadPixelsConfigs); ++c) { 334 for (size_t c = 0; c < SK_ARRAY_COUNT(gReadPixelsConfigs); ++c) {
335 SkBitmap bmp; 335 SkBitmap bmp;
336 init_bitmap(&bmp, srcRect, bmi, 336 init_bitmap(&bmp, srcRect, bmi,
337 gReadPixelsConfigs[c].fColorType, gReadPixelsConfigs [c].fAlphaType); 337 gReadPixelsConfigs[c].fColorType, gReadPixelsConfigs [c].fAlphaType);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 check_read(reporter, wkbmp, clippedRect.fLeft, 375 check_read(reporter, wkbmp, clippedRect.fLeft,
376 clippedRect.fTop, true, false); 376 clippedRect.fTop, true, false);
377 } else { 377 } else {
378 REPORTER_ASSERT(reporter, !success); 378 REPORTER_ASSERT(reporter, !success);
379 } 379 }
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 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(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, context) {
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 context->textureProvider()->createTexture(desc, SkBudgeted::kNo));
400 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTargetDirect(surface Texture->asRenderTarget())); 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);
410 for (size_t rect = 0; rect < SK_ARRAY_COUNT(gReadPixelsTestRects); ++rect) { 410 for (size_t rect = 0; rect < SK_ARRAY_COUNT(gReadPixelsTestRects); ++rect) {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(context, tmp_subse t,
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 SkAutoTUnref<SkSurface> surfA(SkSurface::NewRenderTarget(context, SkBudgeted ::kNo, info, 0)); 606 auto surfA(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
607 SkAutoTUnref<SkSurface> surfB(SkSurface::NewRenderTarget(context, SkBudgeted ::kNo, info, 0)); 607 auto surfB(SkSurface::MakeRenderTarget(context, 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, bm_subset, quality)) ; 616 SkAutoTUnref<SkData> dataA(draw_into_surface(surfA.get(), bm_subset, qua lity));
617 SkAutoTUnref<SkData> dataB(draw_into_surface(surfB, tx_subset, quality)) ; 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/PathTest.cpp ('k') | tests/RecordDrawTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698