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

Side by Side Diff: tests/ReadPixelsTest.cpp

Issue 1352613002: add test for skbug.com/4351 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add comment as to the origin of the test bitmap we use Created 5 years, 3 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"
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 check_read(reporter, wkbmp, clippedRect.fLeft, 433 check_read(reporter, wkbmp, clippedRect.fLeft,
434 clippedRect.fTop, true, false); 434 clippedRect.fTop, true, false);
435 } else { 435 } else {
436 REPORTER_ASSERT(reporter, !success); 436 REPORTER_ASSERT(reporter, !success);
437 } 437 }
438 } 438 }
439 } 439 }
440 } 440 }
441 } 441 }
442 } 442 }
443
444 /////////////////////
445 #if SK_SUPPORT_GPU
446
447 // make_ringed_bitmap was lifted from gm/bleed.cpp, as that GM was what showed t he following
448 // bug when a change was made to SkImage_Raster.cpp. It is possible that other t est bitmaps
449 // would also tickle skbug.com/4351 but this one is know to do it, so I've paste d the code
450 // here so we have a dependable repro case.
451
452 // Create a black&white checked texture with 2 1-pixel rings
453 // around the outside edge. The inner ring is red and the outer ring is blue.
454 static void make_ringed_bitmap(SkBitmap* result, int width, int height) {
455 SkASSERT(0 == width % 2 && 0 == height % 2);
456
457 static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED);
458 static const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE);
459 static const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK);
460 static const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE);
461
462 result->allocN32Pixels(width, height, true);
463
464 SkPMColor* scanline = result->getAddr32(0, 0);
465 for (int x = 0; x < width; ++x) {
466 scanline[x] = kBlue;
467 }
468 scanline = result->getAddr32(0, 1);
469 scanline[0] = kBlue;
470 for (int x = 1; x < width - 1; ++x) {
471 scanline[x] = kRed;
472 }
473 scanline[width-1] = kBlue;
474
475 for (int y = 2; y < height/2; ++y) {
476 scanline = result->getAddr32(0, y);
477 scanline[0] = kBlue;
478 scanline[1] = kRed;
479 for (int x = 2; x < width/2; ++x) {
480 scanline[x] = kBlack;
481 }
482 for (int x = width/2; x < width-2; ++x) {
483 scanline[x] = kWhite;
484 }
485 scanline[width-2] = kRed;
486 scanline[width-1] = kBlue;
487 }
488
489 for (int y = height/2; y < height-2; ++y) {
490 scanline = result->getAddr32(0, y);
491 scanline[0] = kBlue;
492 scanline[1] = kRed;
493 for (int x = 2; x < width/2; ++x) {
494 scanline[x] = kWhite;
495 }
496 for (int x = width/2; x < width-2; ++x) {
497 scanline[x] = kBlack;
498 }
499 scanline[width-2] = kRed;
500 scanline[width-1] = kBlue;
501 }
502
503 scanline = result->getAddr32(0, height-2);
504 scanline[0] = kBlue;
505 for (int x = 1; x < width - 1; ++x) {
506 scanline[x] = kRed;
507 }
508 scanline[width-1] = kBlue;
509
510 scanline = result->getAddr32(0, height-1);
511 for (int x = 0; x < width; ++x) {
512 scanline[x] = kBlue;
513 }
514 result->setImmutable();
515 }
516
517 static void compare_textures(skiatest::Reporter* reporter, GrTexture* txa, GrTex ture* txb) {
518 REPORTER_ASSERT(reporter, txa->width() == 2);
519 REPORTER_ASSERT(reporter, txa->height() == 2);
520 REPORTER_ASSERT(reporter, txb->width() == 2);
521 REPORTER_ASSERT(reporter, txb->height() == 2);
522 REPORTER_ASSERT(reporter, txa->config() == txb->config());
523
524 SkPMColor pixelsA[4], pixelsB[4];
525 REPORTER_ASSERT(reporter, txa->readPixels(0, 0, 2, 2, txa->config(), pixelsA ));
526 REPORTER_ASSERT(reporter, txb->readPixels(0, 0, 2, 2, txa->config(), pixelsB ));
527 REPORTER_ASSERT(reporter, 0 == memcmp(pixelsA, pixelsB, sizeof(pixelsA)));
528 }
529
530 static SkData* draw_into_surface(SkSurface* surf, const SkBitmap& bm, SkFilterQu ality quality) {
531 SkCanvas* canvas = surf->getCanvas();
532 canvas->clear(SK_ColorBLUE);
533
534 SkPaint paint;
535 paint.setFilterQuality(quality);
536
537 canvas->translate(40, 100);
538 canvas->rotate(30);
539 canvas->scale(20, 30);
540 canvas->translate(-SkScalarHalf(bm.width()), -SkScalarHalf(bm.height()));
541 canvas->drawBitmap(bm, 0, 0, &paint);
542
543 SkAutoTUnref<SkImage> image(surf->newImageSnapshot());
544 return image->encode();
545 }
546
547 #include "SkStream.h"
548 static void dump_to_file(const char name[], SkData* data) {
549 SkFILEWStream file(name);
550 file.write(data->data(), data->size());
551 }
552
553 /*
554 * Test two different ways to turn a subset of a bitmap into a texture
555 * - subset and then upload to a texture
556 * - upload to a texture and then subset
557 *
558 * These two techniques result in the same pixels (ala readPixels)
559 * but when we draw them (rotated+scaled) we don't always get the same results.
560 *
561 * skbug.com/4351
562 */
563 DEF_GPUTEST(ReadPixels_Subset_Gpu, reporter, factory) {
564 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType);
565 if (!ctx) {
566 REPORTER_ASSERT(reporter, false);
567 return;
568 }
569
570 SkBitmap bitmap;
571 make_ringed_bitmap(&bitmap, 6, 6);
572 const SkIRect subset = SkIRect::MakeLTRB(2, 2, 4, 4);
573
574 // make two textures...
575 SkBitmap bm_subset, tx_subset;
576
577 // ... one from a texture-subset
578 SkAutoTUnref<GrTexture> fullTx(GrRefCachedBitmapTexture(ctx, bitmap,
579 kUntiled_SkImageUsag eType));
580 SkBitmap tx_full;
581 GrWrapTextureInBitmap(fullTx, bitmap.width(), bitmap.height(), true, &tx_ful l);
582 tx_full.extractSubset(&tx_subset, subset);
583
584 // ... one from a bitmap-subset
585 SkBitmap tmp_subset;
586 bitmap.extractSubset(&tmp_subset, subset);
587 SkAutoTUnref<GrTexture> subsetTx(GrRefCachedBitmapTexture(ctx, tmp_subset,
588 kUntiled_SkImageUs ageType));
589 GrWrapTextureInBitmap(subsetTx, tmp_subset.width(), tmp_subset.height(), tru e, &bm_subset);
590
591 // did we get the same subset?
592 compare_textures(reporter, bm_subset.getTexture(), tx_subset.getTexture());
593
594 // do they draw the same?
595 const SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128);
596 SkAutoTUnref<SkSurface> surfA(SkSurface::NewRenderTarget(ctx, SkSurface::kNo _Budgeted, info, 0));
597 SkAutoTUnref<SkSurface> surfB(SkSurface::NewRenderTarget(ctx, SkSurface::kNo _Budgeted, info, 0));
598
599 //
600 // BUG: if we change this to kNone_SkFilterQuality or kHigh_SkFilterQuality , it fails
601 //
602 SkFilterQuality quality = kLow_SkFilterQuality;
603
604 SkAutoTUnref<SkData> dataA(draw_into_surface(surfA, bm_subset, quality));
605 SkAutoTUnref<SkData> dataB(draw_into_surface(surfB, tx_subset, quality));
606
607 REPORTER_ASSERT(reporter, dataA->equals(dataB));
608 if (false) {
609 dump_to_file("test_image_A.png", dataA);
610 dump_to_file("test_image_B.png", dataB);
611 }
612 }
613 #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