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

Side by Side Diff: tests/BitmapCopyTest.cpp

Issue 1577393002: Make SkBitmap::CopyTo respect requested dst color type when bitmap is texture backed. (Closed) Base URL: https://skia.googlesource.com/skia.git@m48
Patch Set: Fix up test for older Created 4 years, 11 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 | « src/gpu/SkGrPixelRef.cpp ('k') | 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkRect.h" 9 #include "SkRect.h"
10 #include "Test.h" 10 #include "Test.h"
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 REPORTER_ASSERT(reporter, check_4x4_pixel(dstC, sx, sy)) ; 624 REPORTER_ASSERT(reporter, check_4x4_pixel(dstC, sx, sy)) ;
625 } else { 625 } else {
626 REPORTER_ASSERT(reporter, 0 == dstC); 626 REPORTER_ASSERT(reporter, 0 == dstC);
627 } 627 }
628 } 628 }
629 } 629 }
630 } 630 }
631 } 631 }
632 } 632 }
633 633
634 #if SK_SUPPORT_GPU
635
636 #include "GrContext.h"
637 #include "GrContextFactory.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(BitmapCopy_Texture, reporter, factory) {
643
644 for (int glCtxType = 0; glCtxType < GrContextFactory::kGLContextTypeCnt; ++g lCtxType) {
645 GrContextFactory::GLContextType type =
646 static_cast<GrContextFactory::GLContextType>(glCtxType);
647
648 if (!GrContextFactory::IsRenderingGLContext(type)) {
649 continue;
650 }
651
652 GrContext* ctx = factory->get(type);
653
654 if (!ctx) {
655 continue;
656 }
657
658 static const SkPMColor kData[] = {
659 0xFF112233, 0xAF224499,
660 0xEF004466, 0x80773311
661 };
662
663 uint32_t swizData[SK_ARRAY_COUNT(kData)];
664 for (size_t i = 0; i < SK_ARRAY_COUNT(kData); ++i) {
665 swizData[i] = SkSwizzle_RB(kData[i]);
666 }
667
668 static const GrPixelConfig kSrcConfigs[] = {
669 kRGBA_8888_GrPixelConfig,
670 kBGRA_8888_GrPixelConfig,
671 };
672
673 for (size_t srcC = 0; srcC < SK_ARRAY_COUNT(kSrcConfigs); ++srcC) {
674 for (int rt = 0; rt < 2; ++rt) {
675 GrSurfaceDesc desc;
676 desc.fConfig = kSrcConfigs[srcC];
677 desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurface Flags;
678 desc.fWidth = 2;
679 desc.fHeight = 2;
680 desc.fOrigin = kTopLeft_GrSurfaceOrigin;
681
682 const void* srcData = (kSkia8888_GrPixelConfig == desc.fConfig) ? kData : swizData;
683
684 SkAutoTUnref<GrTexture> texture(
685 ctx->textureProvider()->createTexture(desc, false, srcData, 0));
686
687 SkBitmap srcBmp;
688 GrWrapTextureInBitmap(texture, 2, 2, false, &srcBmp);
689 if (srcBmp.isNull()) {
690 ERRORF(reporter, "Could not wrap texture in bitmap.");
691 continue;
692 }
693 static const SkColorType kDstCTs[] = { kRGBA_8888_SkColorType, k BGRA_8888_SkColorType };
694 for (size_t dCT = 0; dCT < SK_ARRAY_COUNT(kDstCTs); ++dCT) {
695 SkBitmap dstBmp;
696 if (!srcBmp.copyTo(&dstBmp, kDstCTs[dCT])) {
697 ERRORF(reporter, "CopyTo failed.");
698 }
699 if (dstBmp.colorType() != kDstCTs[dCT]) {
700 ERRORF(reporter, "SkBitmap::CopyTo did not respect passe d in color type.");
701 }
702 SkAutoLockPixels alp(dstBmp);
703 uint8_t* dstBmpPixels = static_cast<uint8_t*>(dstBmp.getPixe ls());
704 const uint32_t* refData;
705 #if defined(SK_PMCOLOR_IS_RGBA)
706 refData = (kRGBA_8888_SkColorType == dstBmp.colorType()) ? k Data : swizData;
707 #elif defined(SK_PMCOLOR_IS_BGRA)
708 refData = (kBGRA_8888_SkColorType == dstBmp.colorType()) ? k Data : swizData;
709 #else
710 #error "PM Color must be BGRA or RGBA to use GPU backend."
711 #endif
712 bool foundError = false;
713 for (int y = 0; y < 2 && !foundError; ++y) {
714 uint32_t* dstBmpRow = reinterpret_cast<uint32_t*>(dstBmp Pixels);
715 for (int x = 0; x < 2 && !foundError; ++x) {
716 if (refData[2 * y + x] != dstBmpRow[x]) {
717 ERRORF(reporter, "Expected pixel 0x%08x, found 0 x%08x.",
718 refData[2 * y + x], dstBmpRow[x]);
719 foundError = true;
720 }
721 }
722 dstBmpPixels += dstBmp.rowBytes();
723 }
724 }
725 }
726 }
727 }
728 }
729
730 #endif
OLDNEW
« no previous file with comments | « src/gpu/SkGrPixelRef.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698