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