aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/BitmapCopyTest.cpp
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2016-01-11 11:14:17 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-01-11 11:14:17 -0800
commit9d22fd6e7bd1e93bb192f4de649b6b170c9d261a (patch)
tree09feb3fe2b3dde0ecc6d876f8f73bab3d6939728 /tests/BitmapCopyTest.cpp
parentb4b42ed67137b71df3ea6ccd60b4bf9f0f6e58f3 (diff)
Make SkBitmap::CopyTo respect requested dst color type when bitmap is texture backed.
Diffstat (limited to 'tests/BitmapCopyTest.cpp')
-rw-r--r--tests/BitmapCopyTest.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp
index 6db63fae45..8b2cb3ce54 100644
--- a/tests/BitmapCopyTest.cpp
+++ b/tests/BitmapCopyTest.cpp
@@ -632,3 +632,83 @@ DEF_TEST(BitmapReadPixels, reporter) {
}
}
+#if SK_SUPPORT_GPU
+
+#include "GrContext.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_FOR_RENDERING_CONTEXTS(BitmapCopy_Texture, reporter, ctx) {
+ 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