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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/SkGrPixelRef.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/BitmapCopyTest.cpp
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp
index 65427ffd7bbaf28253760a9a40f13e90b1ad869a..e47a631816499784d88a996a6400410d83e58adf 100644
--- a/tests/BitmapCopyTest.cpp
+++ b/tests/BitmapCopyTest.cpp
@@ -631,3 +631,100 @@ DEF_TEST(BitmapReadPixels, reporter) {
}
}
+#if SK_SUPPORT_GPU
+
+#include "GrContext.h"
+#include "GrContextFactory.h"
+#include "SkGr.h"
+#include "SkColorPriv.h"
+/** Tests calling copyTo on a texture backed bitmap. Tests that all BGRA_8888/RGBA_8888 combinations
+ of src and dst work. This test should be removed when SkGrPixelRef is removed. */
+DEF_GPUTEST(BitmapCopy_Texture, reporter, factory) {
+
+ for (int glCtxType = 0; glCtxType < GrContextFactory::kGLContextTypeCnt; ++glCtxType) {
+ GrContextFactory::GLContextType type =
+ static_cast<GrContextFactory::GLContextType>(glCtxType);
+
+ if (!GrContextFactory::IsRenderingGLContext(type)) {
+ continue;
+ }
+
+ GrContext* ctx = factory->get(type);
+
+ if (!ctx) {
+ continue;
+ }
+
+ static const SkPMColor kData[] = {
+ 0xFF112233, 0xAF224499,
+ 0xEF004466, 0x80773311
+ };
+
+ uint32_t swizData[SK_ARRAY_COUNT(kData)];
+ for (size_t i = 0; i < SK_ARRAY_COUNT(kData); ++i) {
+ swizData[i] = SkSwizzle_RB(kData[i]);
+ }
+
+ static const GrPixelConfig kSrcConfigs[] = {
+ kRGBA_8888_GrPixelConfig,
+ kBGRA_8888_GrPixelConfig,
+ };
+
+ for (size_t srcC = 0; srcC < SK_ARRAY_COUNT(kSrcConfigs); ++srcC) {
+ for (int rt = 0; rt < 2; ++rt) {
+ GrSurfaceDesc desc;
+ desc.fConfig = kSrcConfigs[srcC];
+ desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags;
+ desc.fWidth = 2;
+ desc.fHeight = 2;
+ desc.fOrigin = kTopLeft_GrSurfaceOrigin;
+
+ const void* srcData = (kSkia8888_GrPixelConfig == desc.fConfig) ? kData : swizData;
+
+ SkAutoTUnref<GrTexture> texture(
+ ctx->textureProvider()->createTexture(desc, false, srcData, 0));
+
+ SkBitmap srcBmp;
+ GrWrapTextureInBitmap(texture, 2, 2, false, &srcBmp);
+ if (srcBmp.isNull()) {
+ ERRORF(reporter, "Could not wrap texture in bitmap.");
+ continue;
+ }
+ static const SkColorType kDstCTs[] = { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType };
+ for (size_t dCT = 0; dCT < SK_ARRAY_COUNT(kDstCTs); ++dCT) {
+ SkBitmap dstBmp;
+ if (!srcBmp.copyTo(&dstBmp, kDstCTs[dCT])) {
+ ERRORF(reporter, "CopyTo failed.");
+ }
+ if (dstBmp.colorType() != kDstCTs[dCT]) {
+ ERRORF(reporter, "SkBitmap::CopyTo did not respect passed in color type.");
+ }
+ SkAutoLockPixels alp(dstBmp);
+ uint8_t* dstBmpPixels = static_cast<uint8_t*>(dstBmp.getPixels());
+ const uint32_t* refData;
+ #if defined(SK_PMCOLOR_IS_RGBA)
+ refData = (kRGBA_8888_SkColorType == dstBmp.colorType()) ? kData : swizData;
+ #elif defined(SK_PMCOLOR_IS_BGRA)
+ refData = (kBGRA_8888_SkColorType == dstBmp.colorType()) ? kData : swizData;
+ #else
+ #error "PM Color must be BGRA or RGBA to use GPU backend."
+ #endif
+ bool foundError = false;
+ for (int y = 0; y < 2 && !foundError; ++y) {
+ uint32_t* dstBmpRow = reinterpret_cast<uint32_t*>(dstBmpPixels);
+ for (int x = 0; x < 2 && !foundError; ++x) {
+ if (refData[2 * y + x] != dstBmpRow[x]) {
+ ERRORF(reporter, "Expected pixel 0x%08x, found 0x%08x.",
+ refData[2 * y + x], dstBmpRow[x]);
+ foundError = true;
+ }
+ }
+ dstBmpPixels += dstBmp.rowBytes();
+ }
+ }
+ }
+ }
+ }
+}
+
+#endif
« 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