From e30739a1e1d90183bc6bf7414e409e89016881f5 Mon Sep 17 00:00:00 2001 From: Timothy Liang Date: Tue, 31 Jul 2018 10:51:17 -0400 Subject: implemented copy surface as draw for metal gpu backend Bug: skia: Change-Id: Ie61bd6ad9f288b8a025d44f887a0954101a7d710 Reviewed-on: https://skia-review.googlesource.com/142687 Commit-Queue: Timothy Liang Reviewed-by: Greg Daniel --- tests/CopySurfaceTest.cpp | 185 ++++++++++++++++++++++++++-------------------- 1 file changed, 106 insertions(+), 79 deletions(-) (limited to 'tests') diff --git a/tests/CopySurfaceTest.cpp b/tests/CopySurfaceTest.cpp index 4921f5bbbe..d2f52498dc 100644 --- a/tests/CopySurfaceTest.cpp +++ b/tests/CopySurfaceTest.cpp @@ -15,6 +15,7 @@ #include "GrTextureProxy.h" #include "GrTypes.h" #include "ProxyUtils.h" +#include "SkGr.h" #include "SkImageInfo.h" #include "SkPoint.h" #include "SkRect.h" @@ -58,7 +59,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) { {-1 , -1 }, }; - const SkImageInfo ii = SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType); + static const SkImageInfo kImageInfos[] { + SkImageInfo::Make(kW, kH, kRGBA_8888_SkColorType, kPremul_SkAlphaType), + SkImageInfo::Make(kW, kH, kBGRA_8888_SkColorType, kPremul_SkAlphaType) + }; SkAutoTMalloc read(kW * kH); @@ -68,88 +72,111 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) { for (auto dRT : {true, false}) { for (auto srcRect : kSrcRects) { for (auto dstPoint : kDstPoints) { - auto src = sk_gpu_test::MakeTextureProxyFromData( - context, sRT, kW, kH, ii.colorType(), sOrigin, srcPixels.get(), - kRowBytes); - auto dst = sk_gpu_test::MakeTextureProxyFromData( - context, dRT, kW, kH, ii.colorType(), dOrigin, dstPixels.get(), - kRowBytes); - if (!src || !dst) { - ERRORF(reporter, - "Could not create surfaces for copy surface test."); - continue; - } + for (auto ii: kImageInfos) { + auto src = sk_gpu_test::MakeTextureProxyFromData( + context, sRT, kW, kH, ii.colorType(), sOrigin, + srcPixels.get(), kRowBytes); + auto dst = sk_gpu_test::MakeTextureProxyFromData( + context, dRT, kW, kH, ii.colorType(), dOrigin, + dstPixels.get(), kRowBytes); + + // Should always work if the color type is RGBA, but may not work + // for BGRA + if (ii.colorType() == kBGRA_8888_SkColorType) { + if (!src || !dst) { + ERRORF(reporter, + "Could not create surfaces for copy surface test."); + continue; + } + } else { + GrPixelConfig config = + SkColorType2GrPixelConfig(kBGRA_8888_SkColorType); + if (!context->contextPriv().caps()->isConfigTexturable( + config)) { + continue; + } + if (!src || !dst) { + ERRORF(reporter, + "Could not create surfaces for copy surface test."); + continue; + } + } - sk_sp dstContext = - context->contextPriv().makeWrappedSurfaceContext(std::move(dst)); - - bool result = dstContext->copy(src.get(), srcRect, dstPoint); - - bool expectedResult = true; - SkIPoint dstOffset = { dstPoint.fX - srcRect.fLeft, - dstPoint.fY - srcRect.fTop }; - SkIRect copiedDstRect = SkIRect::MakeXYWH(dstPoint.fX, - dstPoint.fY, - srcRect.width(), - srcRect.height()); - - SkIRect copiedSrcRect; - if (!copiedSrcRect.intersect(srcRect, SkIRect::MakeWH(kW, kH))) { - expectedResult = false; - } else { - // If the src rect was clipped, apply same clipping to each side of - // copied dst rect. - copiedDstRect.fLeft += copiedSrcRect.fLeft - srcRect.fLeft; - copiedDstRect.fTop += copiedSrcRect.fTop - srcRect.fTop; - copiedDstRect.fRight -= copiedSrcRect.fRight - srcRect.fRight; - copiedDstRect.fBottom -= copiedSrcRect.fBottom - srcRect.fBottom; - } - if (copiedDstRect.isEmpty() || - !copiedDstRect.intersect(SkIRect::MakeWH(kW, kH))) { - expectedResult = false; - } - // To make the copied src rect correct we would apply any dst clipping - // back to the src rect, but we don't use it again so don't bother. - if (expectedResult != result) { - ERRORF(reporter, "Expected return value %d from copySurface, got " - "%d.", expectedResult, result); - continue; - } + sk_sp dstContext = + context->contextPriv().makeWrappedSurfaceContext( + std::move(dst)); + + bool result = dstContext->copy(src.get(), srcRect, dstPoint); + + bool expectedResult = true; + SkIPoint dstOffset = { dstPoint.fX - srcRect.fLeft, + dstPoint.fY - srcRect.fTop }; + SkIRect copiedDstRect = SkIRect::MakeXYWH(dstPoint.fX, + dstPoint.fY, + srcRect.width(), + srcRect.height()); + + SkIRect copiedSrcRect; + if (!copiedSrcRect.intersect(srcRect, SkIRect::MakeWH(kW, kH))) { + expectedResult = false; + } else { + // If the src rect was clipped, apply same clipping to each side + // of copied dst rect. + copiedDstRect.fLeft += copiedSrcRect.fLeft - srcRect.fLeft; + copiedDstRect.fTop += copiedSrcRect.fTop - srcRect.fTop; + copiedDstRect.fRight -= copiedSrcRect.fRight - srcRect.fRight; + copiedDstRect.fBottom -= copiedSrcRect.fBottom - + srcRect.fBottom; + } + if (copiedDstRect.isEmpty() || + !copiedDstRect.intersect(SkIRect::MakeWH(kW, kH))) { + expectedResult = false; + } + // To make the copied src rect correct we would apply any dst + // clipping back to the src rect, but we don't use it again so + // don't bother. + if (expectedResult != result) { + ERRORF(reporter, "Expected return value %d from copySurface, " + "got %d.", expectedResult, result); + continue; + } - if (!expectedResult || !result) { - continue; - } + if (!expectedResult || !result) { + continue; + } - sk_memset32(read.get(), 0, kW * kH); - if (!dstContext->readPixels(ii, read.get(), kRowBytes, 0, 0)) { - ERRORF(reporter, "Error calling readPixels"); - continue; - } + sk_memset32(read.get(), 0, kW * kH); + if (!dstContext->readPixels(ii, read.get(), kRowBytes, 0, 0)) { + ERRORF(reporter, "Error calling readPixels"); + continue; + } - bool abort = false; - // Validate that pixels inside copiedDstRect received the correct value - // from src and that those outside were not modified. - for (int y = 0; y < kH && !abort; ++y) { - for (int x = 0; x < kW; ++x) { - uint32_t r = read.get()[y * kW + x]; - if (copiedDstRect.contains(x, y)) { - int sx = x - dstOffset.fX; - int sy = y - dstOffset.fY; - uint32_t s = srcPixels.get()[sy * kW + sx]; - if (s != r) { - ERRORF(reporter, "Expected dst %d,%d to contain " - "0x%08x copied from src location %d,%d. Got " - "0x%08x", x, y, s, sx, sy, r); - abort = true; - break; - } - } else { - uint32_t d = dstPixels.get()[y * kW + x]; - if (d != r) { - ERRORF(reporter, "Expected dst %d,%d to be unmodified (" - "0x%08x). Got 0x%08x", x, y, d, r); - abort = true; - break; + bool abort = false; + // Validate that pixels inside copiedDstRect received the correct + // value from src and that those outside were not modified. + for (int y = 0; y < kH && !abort; ++y) { + for (int x = 0; x < kW; ++x) { + uint32_t r = read.get()[y * kW + x]; + if (copiedDstRect.contains(x, y)) { + int sx = x - dstOffset.fX; + int sy = y - dstOffset.fY; + uint32_t s = srcPixels.get()[sy * kW + sx]; + if (s != r) { + ERRORF(reporter, "Expected dst %d,%d to contain " + "0x%08x copied from src location %d,%d. Got " + "0x%08x", x, y, s, sx, sy, r); + abort = true; + break; + } + } else { + uint32_t d = dstPixels.get()[y * kW + x]; + if (d != r) { + ERRORF(reporter, "Expected dst %d,%d to be " + "unmodified (0x%08x). Got 0x%08x", + x, y, d, r); + abort = true; + break; + } } } } -- cgit v1.2.3