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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
9 #include "SkRect.h" | 9 #include "SkRect.h" |
10 #include "SkTemplates.h" | 10 #include "SkTemplates.h" |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 REPORTER_ASSERT(reporter, check_4x4_pixel(dstC, sx, sy))
; | 625 REPORTER_ASSERT(reporter, check_4x4_pixel(dstC, sx, sy))
; |
626 } else { | 626 } else { |
627 REPORTER_ASSERT(reporter, 0 == dstC); | 627 REPORTER_ASSERT(reporter, 0 == dstC); |
628 } | 628 } |
629 } | 629 } |
630 } | 630 } |
631 } | 631 } |
632 } | 632 } |
633 } | 633 } |
634 | 634 |
| 635 #if SK_SUPPORT_GPU |
| 636 |
| 637 #include "GrContext.h" |
| 638 #include "SkGr.h" |
| 639 #include "SkColorPriv.h" |
| 640 /** Tests calling copyTo on a texture backed bitmap. Tests that all BGRA_8888/RG
BA_8888 combinations |
| 641 of src and dst work. This test should be removed when SkGrPixelRef is remove
d. */ |
| 642 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(BitmapCopy_Texture, reporter, ctx) { |
| 643 static const SkPMColor kData[] = { |
| 644 0xFF112233, 0xAF224499, |
| 645 0xEF004466, 0x80773311 |
| 646 }; |
| 647 |
| 648 uint32_t swizData[SK_ARRAY_COUNT(kData)]; |
| 649 for (size_t i = 0; i < SK_ARRAY_COUNT(kData); ++i) { |
| 650 swizData[i] = SkSwizzle_RB(kData[i]); |
| 651 } |
| 652 |
| 653 static const GrPixelConfig kSrcConfigs[] = { |
| 654 kRGBA_8888_GrPixelConfig, |
| 655 kBGRA_8888_GrPixelConfig, |
| 656 }; |
| 657 |
| 658 for (size_t srcC = 0; srcC < SK_ARRAY_COUNT(kSrcConfigs); ++srcC) { |
| 659 for (int rt = 0; rt < 2; ++rt) { |
| 660 GrSurfaceDesc desc; |
| 661 desc.fConfig = kSrcConfigs[srcC]; |
| 662 desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlag
s; |
| 663 desc.fWidth = 2; |
| 664 desc.fHeight = 2; |
| 665 desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 666 |
| 667 const void* srcData = (kSkia8888_GrPixelConfig == desc.fConfig) ? kD
ata : swizData; |
| 668 |
| 669 SkAutoTUnref<GrTexture> texture( |
| 670 ctx->textureProvider()->createTexture(desc, false, srcData, 0)); |
| 671 |
| 672 SkBitmap srcBmp; |
| 673 GrWrapTextureInBitmap(texture, 2, 2, false, &srcBmp); |
| 674 if (srcBmp.isNull()) { |
| 675 ERRORF(reporter, "Could not wrap texture in bitmap."); |
| 676 continue; |
| 677 } |
| 678 static const SkColorType kDstCTs[] = { kRGBA_8888_SkColorType, kBGRA
_8888_SkColorType }; |
| 679 for (size_t dCT = 0; dCT < SK_ARRAY_COUNT(kDstCTs); ++dCT) { |
| 680 SkBitmap dstBmp; |
| 681 if (!srcBmp.copyTo(&dstBmp, kDstCTs[dCT])) { |
| 682 ERRORF(reporter, "CopyTo failed."); |
| 683 } |
| 684 if (dstBmp.colorType() != kDstCTs[dCT]) { |
| 685 ERRORF(reporter, "SkBitmap::CopyTo did not respect passed in
color type."); |
| 686 } |
| 687 SkAutoLockPixels alp(dstBmp); |
| 688 uint8_t* dstBmpPixels = static_cast<uint8_t*>(dstBmp.getPixels()
); |
| 689 const uint32_t* refData; |
| 690 #if defined(SK_PMCOLOR_IS_RGBA) |
| 691 refData = (kRGBA_8888_SkColorType == dstBmp.colorType()) ? kData
: swizData; |
| 692 #elif defined(SK_PMCOLOR_IS_BGRA) |
| 693 refData = (kBGRA_8888_SkColorType == dstBmp.colorType()) ? kData
: swizData; |
| 694 #else |
| 695 #error "PM Color must be BGRA or RGBA to use GPU backend." |
| 696 #endif |
| 697 bool foundError = false; |
| 698 for (int y = 0; y < 2 && !foundError; ++y) { |
| 699 uint32_t* dstBmpRow = reinterpret_cast<uint32_t*>(dstBmpPixe
ls); |
| 700 for (int x = 0; x < 2 && !foundError; ++x) { |
| 701 if (refData[2 * y + x] != dstBmpRow[x]) { |
| 702 ERRORF(reporter, "Expected pixel 0x%08x, found 0x%08
x.", |
| 703 refData[2 * y + x], dstBmpRow[x]); |
| 704 foundError = true; |
| 705 } |
| 706 } |
| 707 dstBmpPixels += dstBmp.rowBytes(); |
| 708 } |
| 709 } |
| 710 } |
| 711 } |
| 712 } |
| 713 |
| 714 #endif |
OLD | NEW |