Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
| 446 // Create a black&white checked texture with 2 1-pixel rings | |
| 447 // around the outside edge. The inner ring is red and the outer ring is blue. | |
| 448 static void make_ringed_bitmap(SkBitmap* result, int width, int height) { | |
| 449 SkASSERT(0 == width % 2 && 0 == height % 2); | |
| 450 | |
| 451 static const SkPMColor kRed = SkPreMultiplyColor(SK_ColorRED); | |
| 452 static const SkPMColor kBlue = SkPreMultiplyColor(SK_ColorBLUE); | |
| 453 static const SkPMColor kBlack = SkPreMultiplyColor(SK_ColorBLACK); | |
| 454 static const SkPMColor kWhite = SkPreMultiplyColor(SK_ColorWHITE); | |
| 455 | |
| 456 result->allocN32Pixels(width, height, true); | |
| 457 | |
| 458 SkPMColor* scanline = result->getAddr32(0, 0); | |
| 459 for (int x = 0; x < width; ++x) { | |
| 460 scanline[x] = kBlue; | |
| 461 } | |
| 462 scanline = result->getAddr32(0, 1); | |
| 463 scanline[0] = kBlue; | |
| 464 for (int x = 1; x < width - 1; ++x) { | |
| 465 scanline[x] = kRed; | |
| 466 } | |
| 467 scanline[width-1] = kBlue; | |
| 468 | |
| 469 for (int y = 2; y < height/2; ++y) { | |
| 470 scanline = result->getAddr32(0, y); | |
| 471 scanline[0] = kBlue; | |
| 472 scanline[1] = kRed; | |
| 473 for (int x = 2; x < width/2; ++x) { | |
| 474 scanline[x] = kBlack; | |
| 475 } | |
| 476 for (int x = width/2; x < width-2; ++x) { | |
| 477 scanline[x] = kWhite; | |
| 478 } | |
| 479 scanline[width-2] = kRed; | |
| 480 scanline[width-1] = kBlue; | |
| 481 } | |
| 482 | |
| 483 for (int y = height/2; y < height-2; ++y) { | |
| 484 scanline = result->getAddr32(0, y); | |
| 485 scanline[0] = kBlue; | |
| 486 scanline[1] = kRed; | |
| 487 for (int x = 2; x < width/2; ++x) { | |
| 488 scanline[x] = kWhite; | |
| 489 } | |
| 490 for (int x = width/2; x < width-2; ++x) { | |
| 491 scanline[x] = kBlack; | |
| 492 } | |
| 493 scanline[width-2] = kRed; | |
| 494 scanline[width-1] = kBlue; | |
| 495 } | |
| 496 | |
| 497 scanline = result->getAddr32(0, height-2); | |
| 498 scanline[0] = kBlue; | |
| 499 for (int x = 1; x < width - 1; ++x) { | |
| 500 scanline[x] = kRed; | |
| 501 } | |
| 502 scanline[width-1] = kBlue; | |
| 503 | |
| 504 scanline = result->getAddr32(0, height-1); | |
| 505 for (int x = 0; x < width; ++x) { | |
| 506 scanline[x] = kBlue; | |
| 507 } | |
| 508 result->setImmutable(); | |
| 509 } | |
| 510 | |
| 511 #if SK_SUPPORT_GPU | |
| 512 static void compare_textures(skiatest::Reporter* reporter, GrTexture* txa, GrTex ture* txb) { | |
| 513 REPORTER_ASSERT(reporter, txa->width() == 2); | |
| 514 REPORTER_ASSERT(reporter, txa->height() == 2); | |
| 515 REPORTER_ASSERT(reporter, txb->width() == 2); | |
| 516 REPORTER_ASSERT(reporter, txb->height() == 2); | |
| 517 REPORTER_ASSERT(reporter, txa->config() == txb->config()); | |
| 518 | |
| 519 SkPMColor pixelsA[4], pixelsB[4]; | |
| 520 REPORTER_ASSERT(reporter, txa->readPixels(0, 0, 2, 2, txa->config(), pixelsA )); | |
| 521 REPORTER_ASSERT(reporter, txb->readPixels(0, 0, 2, 2, txa->config(), pixelsB )); | |
| 522 REPORTER_ASSERT(reporter, 0 == memcmp(pixelsA, pixelsB, sizeof(pixelsA))); | |
| 523 } | |
| 524 | |
| 525 static SkData* draw_into_surface(SkSurface* surf, const SkBitmap& bm, SkFilterQu ality quality) { | |
| 526 SkCanvas* canvas = surf->getCanvas(); | |
| 527 canvas->clear(SK_ColorBLUE); | |
| 528 | |
| 529 SkPaint paint; | |
| 530 paint.setFilterQuality(quality); | |
| 531 | |
| 532 canvas->translate(40, 100); | |
| 533 canvas->rotate(30); | |
| 534 canvas->scale(20, 30); | |
| 535 canvas->translate(-SkScalarHalf(bm.width()), -SkScalarHalf(bm.height())); | |
| 536 canvas->drawBitmap(bm, 0, 0, &paint); | |
| 537 | |
| 538 SkAutoTUnref<SkImage> image(surf->newImageSnapshot()); | |
| 539 return image->encode(); | |
| 540 } | |
| 541 | |
| 542 #include "SkStream.h" | |
| 543 static void dump_to_file(const char name[], SkData* data) { | |
| 544 SkFILEWStream file(name); | |
| 545 file.write(data->data(), data->size()); | |
| 546 } | |
| 547 | |
| 548 /* | |
| 549 * Test two different ways to turn a subset of a bitmap into a texture | |
| 550 * - subset and then upload to a texture | |
| 551 * - upload to a texture and then subset | |
| 552 * | |
| 553 * These two techniques result in the same pixels (ala readPixels) | |
| 554 * but when we draw them (rotated+scaled) we don't always get the same results. | |
| 555 * | |
| 556 * skbug.com/4351 | |
| 557 */ | |
| 558 DEF_GPUTEST(ReadPixels_Subset_Gpu, reporter, factory) { | |
| 559 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType); | |
| 560 if (!ctx) { | |
| 561 REPORTER_ASSERT(reporter, false); | |
| 562 return; | |
| 563 } | |
| 564 | |
| 565 SkBitmap bitmap; | |
| 566 make_ringed_bitmap(&bitmap, 6, 6); | |
| 567 const SkIRect subset = SkIRect::MakeLTRB(2, 2, 4, 4); | |
| 568 | |
| 569 // make two textures... | |
|
robertphillips
2015/09/16 19:49:29
bmSubset ?
txSubset ?
| |
| 570 SkBitmap bm_subset, tx_subset; | |
| 571 | |
| 572 // ... one from a texture-subset | |
| 573 SkAutoTUnref<GrTexture> fullTx(GrRefCachedBitmapTexture(ctx, bitmap, | |
| 574 kUntiled_SkImageUsag eType)); | |
|
robertphillips
2015/09/16 19:49:29
txFull ?
| |
| 575 SkBitmap tx_full; | |
| 576 GrWrapTextureInBitmap(fullTx, bitmap.width(), bitmap.height(), true, &tx_ful l); | |
| 577 tx_full.extractSubset(&tx_subset, subset); | |
| 578 | |
| 579 // ... one from a bitmap-subset | |
| 580 SkBitmap tmp_subset; | |
| 581 bitmap.extractSubset(&tmp_subset, subset); | |
| 582 SkAutoTUnref<GrTexture> subsetTx(GrRefCachedBitmapTexture(ctx, tmp_subset, | |
| 583 kUntiled_SkImageUs ageType)); | |
| 584 GrWrapTextureInBitmap(subsetTx, tmp_subset.width(), tmp_subset.height(), tru e, &bm_subset); | |
| 585 | |
| 586 // did we get the same subset? | |
| 587 compare_textures(reporter, bm_subset.getTexture(), tx_subset.getTexture()); | |
| 588 | |
| 589 // do they draw the same? | |
| 590 const SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); | |
| 591 SkAutoTUnref<SkSurface> surfA(SkSurface::NewRenderTarget(ctx, SkSurface::kNo _Budgeted, info, 0)); | |
| 592 SkAutoTUnref<SkSurface> surfB(SkSurface::NewRenderTarget(ctx, SkSurface::kNo _Budgeted, info, 0)); | |
| 593 | |
| 594 // | |
| 595 // BUG: if we change this to kNone_SkFilterQuality or kHigh_SkFilterQuality , it fails | |
| 596 // | |
| 597 SkFilterQuality quality = kLow_SkFilterQuality; | |
| 598 | |
| 599 SkAutoTUnref<SkData> dataA(draw_into_surface(surfA, bm_subset, quality)); | |
| 600 SkAutoTUnref<SkData> dataB(draw_into_surface(surfB, tx_subset, quality)); | |
| 601 | |
| 602 REPORTER_ASSERT(reporter, dataA->equals(dataB)); | |
| 603 if (false) { | |
| 604 dump_to_file("test_image_A.png", dataA); | |
| 605 dump_to_file("test_image_B.png", dataB); | |
| 606 } | |
| 607 } | |
| 608 #endif | |
| OLD | NEW |