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

Side by Side Diff: tests/ReadPixelsTest.cpp

Issue 2143003006: Remove unit test that tests subsetting texture backed bitmaps. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Delete more code Created 4 years, 5 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 | « no previous file | no next file » | 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"
11 #include "SkRegion.h" 11 #include "SkRegion.h"
12 #include "SkSurface.h" 12 #include "SkSurface.h"
13 #include "Test.h" 13 #include "Test.h"
14 14
15 #if SK_SUPPORT_GPU 15 #if SK_SUPPORT_GPU
16 #include "GrContext.h" 16 #include "GrContext.h"
17 #include "SkGr.h" 17 #include "SkGr.h"
18 #include "SkGrPriv.h"
19 #endif 18 #endif
20 19
21 #include <initializer_list> 20 #include <initializer_list>
22 21
23 static const int DEV_W = 100, DEV_H = 100; 22 static const int DEV_W = 100, DEV_H = 100;
24 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H); 23 static const SkIRect DEV_RECT = SkIRect::MakeWH(DEV_W, DEV_H);
25 static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1, 24 static const SkRect DEV_RECT_S = SkRect::MakeWH(DEV_W * SK_Scalar1,
26 DEV_H * SK_Scalar1); 25 DEV_H * SK_Scalar1);
27 26
28 static SkPMColor get_src_color(int x, int y) { 27 static SkPMColor get_src_color(int x, int y) {
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 desc.fHeight = DEV_H; 452 desc.fHeight = DEV_H;
454 desc.fConfig = kSkia8888_GrPixelConfig; 453 desc.fConfig = kSkia8888_GrPixelConfig;
455 desc.fOrigin = origin; 454 desc.fOrigin = origin;
456 desc.fFlags = kNone_GrSurfaceFlags; 455 desc.fFlags = kNone_GrSurfaceFlags;
457 texture.reset(ctxInfo.grContext()->textureProvider()->createTexture(desc , 456 texture.reset(ctxInfo.grContext()->textureProvider()->createTexture(desc ,
458 SkBu dgeted::kNo)); 457 SkBu dgeted::kNo));
459 test_readpixels_texture(reporter, texture); 458 test_readpixels_texture(reporter, texture);
460 } 459 }
461 } 460 }
462 #endif 461 #endif
463 /////////////////////
464 #if SK_SUPPORT_GPU
465
466 // make_ringed_bitmap was lifted from gm/bleed.cpp, as that GM was what showed t he following
467 // bug when a change was made to SkImage_Raster.cpp. It is possible that other t est bitmaps
468 // would also tickle https://bug.skia.org/4351 but this one is know to do it, so I've pasted the code
469 // here so we have a dependable repro case.
470
471 // Create a black&white checked texture with 2 1-pixel rings
472 // around the outside edge. The inner ring is red and the outer ring is blue.
473 static void make_ringed_bitmap(SkBitmap* result, int width, int height) {
474 SkASSERT(0 == width % 2 && 0 == height % 2);
475
476 static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED);
477 static const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE);
478 static const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK);
479 static const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE);
480
481 result->allocN32Pixels(width, height, true);
482
483 SkPMColor* scanline = result->getAddr32(0, 0);
484 for (int x = 0; x < width; ++x) {
485 scanline[x] = kBlue;
486 }
487 scanline = result->getAddr32(0, 1);
488 scanline[0] = kBlue;
489 for (int x = 1; x < width - 1; ++x) {
490 scanline[x] = kRed;
491 }
492 scanline[width-1] = kBlue;
493
494 for (int y = 2; y < height/2; ++y) {
495 scanline = result->getAddr32(0, y);
496 scanline[0] = kBlue;
497 scanline[1] = kRed;
498 for (int x = 2; x < width/2; ++x) {
499 scanline[x] = kBlack;
500 }
501 for (int x = width/2; x < width-2; ++x) {
502 scanline[x] = kWhite;
503 }
504 scanline[width-2] = kRed;
505 scanline[width-1] = kBlue;
506 }
507
508 for (int y = height/2; y < height-2; ++y) {
509 scanline = result->getAddr32(0, y);
510 scanline[0] = kBlue;
511 scanline[1] = kRed;
512 for (int x = 2; x < width/2; ++x) {
513 scanline[x] = kWhite;
514 }
515 for (int x = width/2; x < width-2; ++x) {
516 scanline[x] = kBlack;
517 }
518 scanline[width-2] = kRed;
519 scanline[width-1] = kBlue;
520 }
521
522 scanline = result->getAddr32(0, height-2);
523 scanline[0] = kBlue;
524 for (int x = 1; x < width - 1; ++x) {
525 scanline[x] = kRed;
526 }
527 scanline[width-1] = kBlue;
528
529 scanline = result->getAddr32(0, height-1);
530 for (int x = 0; x < width; ++x) {
531 scanline[x] = kBlue;
532 }
533 result->setImmutable();
534 }
535
536 static void compare_textures(skiatest::Reporter* reporter, GrTexture* txa, GrTex ture* txb) {
537 REPORTER_ASSERT(reporter, txa->width() == 2);
538 REPORTER_ASSERT(reporter, txa->height() == 2);
539 REPORTER_ASSERT(reporter, txb->width() == 2);
540 REPORTER_ASSERT(reporter, txb->height() == 2);
541 REPORTER_ASSERT(reporter, txa->config() == txb->config());
542
543 SkPMColor pixelsA[4], pixelsB[4];
544 REPORTER_ASSERT(reporter, txa->readPixels(0, 0, 2, 2, txa->config(), pixelsA ));
545 REPORTER_ASSERT(reporter, txb->readPixels(0, 0, 2, 2, txa->config(), pixelsB ));
546 REPORTER_ASSERT(reporter, 0 == memcmp(pixelsA, pixelsB, sizeof(pixelsA)));
547 }
548
549 static SkData* draw_into_surface(SkSurface* surf, const SkBitmap& bm, SkFilterQu ality quality) {
550 SkCanvas* canvas = surf->getCanvas();
551 canvas->clear(SK_ColorBLUE);
552
553 SkPaint paint;
554 paint.setFilterQuality(quality);
555
556 canvas->translate(40, 100);
557 canvas->rotate(30);
558 canvas->scale(20, 30);
559 canvas->translate(-SkScalarHalf(bm.width()), -SkScalarHalf(bm.height()));
560 canvas->drawBitmap(bm, 0, 0, &paint);
561
562 return surf->makeImageSnapshot()->encode();
563 }
564
565 #include "SkStream.h"
566 static void dump_to_file(const char name[], SkData* data) {
567 SkFILEWStream file(name);
568 file.write(data->data(), data->size());
569 }
570
571 /*
572 * Test two different ways to turn a subset of a bitmap into a texture
573 * - subset and then upload to a texture
574 * - upload to a texture and then subset
575 *
576 * These two techniques result in the same pixels (ala readPixels)
577 * but when we draw them (rotated+scaled) we don't always get the same results.
578 *
579 * https://bug.skia.org/4351
580 */
581 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Subset_Gpu, reporter, ctxInfo) {
582 SkBitmap bitmap;
583 make_ringed_bitmap(&bitmap, 6, 6);
584 const SkIRect subset = SkIRect::MakeLTRB(2, 2, 4, 4);
585
586 // make two textures...
587 SkBitmap bm_subset, tx_subset;
588
589 // ... one from a texture-subset
590 SkAutoTUnref<GrTexture> fullTx(GrRefCachedBitmapTexture(ctxInfo.grContext(), bitmap,
591 GrTextureParams::Cla mpNoFilter(),
592 SkSourceGammaTreatme nt::kRespect));
593 SkBitmap tx_full;
594 GrWrapTextureInBitmap(fullTx, bitmap.width(), bitmap.height(), true, &tx_ful l);
595 tx_full.extractSubset(&tx_subset, subset);
596
597 // ... one from a bitmap-subset
598 SkBitmap tmp_subset;
599 bitmap.extractSubset(&tmp_subset, subset);
600 SkAutoTUnref<GrTexture> subsetTx(GrRefCachedBitmapTexture(ctxInfo.grContext( ), tmp_subset,
601 GrTextureParams::C lampNoFilter(),
602 SkSourceGammaTreat ment::kRespect));
603 GrWrapTextureInBitmap(subsetTx, tmp_subset.width(), tmp_subset.height(), tru e, &bm_subset);
604
605 // did we get the same subset?
606 compare_textures(reporter, bm_subset.getTexture(), tx_subset.getTexture());
607
608 // do they draw the same?
609 const SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
610 auto surfA(SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, info));
611 auto surfB(SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, info));
612
613 if (false) {
614 //
615 // BUG: depending on the driver, if we calls this with various quality settings, it
616 // may fail.
617 //
618 SkFilterQuality quality = kLow_SkFilterQuality;
619
620 SkAutoTUnref<SkData> dataA(draw_into_surface(surfA.get(), bm_subset, qua lity));
621 SkAutoTUnref<SkData> dataB(draw_into_surface(surfB.get(), tx_subset, qua lity));
622
623 REPORTER_ASSERT(reporter, dataA->equals(dataB));
624 if (false) {
625 dump_to_file("test_image_A.png", dataA);
626 dump_to_file("test_image_B.png", dataB);
627 }
628 }
629 }
630 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698