diff options
author | Robert Phillips <robertphillips@google.com> | 2017-01-27 14:28:29 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-27 14:28:40 +0000 |
commit | 2b270e566263e93bcdfe00f858dba1970f5091f4 (patch) | |
tree | 533e6d0f750c4cb908ebb9593293fc4b2e57bd23 /tests/RectangleTextureTest.cpp | |
parent | 837e74365e511853df534cc23bd2128c7c235e2f (diff) |
Revert "Consolidate read/write-Pixels testing code"
This reverts commit 0bd4a23ef40d74ef051eb7f457c133d5febc377d.
Reason for revert: What?!?
Original change's description:
> Consolidate read/write-Pixels testing code
>
> Change-Id: I853f8f747ed0040333473fbc722cabac84e6ac83
> Reviewed-on: https://skia-review.googlesource.com/7560
> Commit-Queue: Robert Phillips <robertphillips@google.com>
> Reviewed-by: Brian Osman <brianosman@google.com>
>
TBR=robertphillips@google.com,brianosman@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Change-Id: I9cb049a4f86350f849d00839a55b55fb07e861b0
Reviewed-on: https://skia-review.googlesource.com/7648
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tests/RectangleTextureTest.cpp')
-rw-r--r-- | tests/RectangleTextureTest.cpp | 103 |
1 files changed, 92 insertions, 11 deletions
diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp index d55b882f7e..523c2e3437 100644 --- a/tests/RectangleTextureTest.cpp +++ b/tests/RectangleTextureTest.cpp @@ -6,8 +6,6 @@ */ #include "Test.h" -#include "TestUtils.h" - #if SK_SUPPORT_GPU #include "GrContext.h" #include "GrContextPriv.h" @@ -16,6 +14,92 @@ #include "gl/GrGLUtil.h" #include "gl/GLTestContext.h" +static void test_read_pixels(skiatest::Reporter* reporter, GrContext* context, + GrSurfaceContext* srcContext, uint32_t expectedPixelValues[]) { + int pixelCnt = srcContext->width() * srcContext->height(); + SkAutoTMalloc<uint32_t> pixels(pixelCnt); + memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt); + + SkImageInfo ii = SkImageInfo::Make(srcContext->width(), srcContext->height(), + kRGBA_8888_SkColorType, kPremul_SkAlphaType); + bool read = srcContext->readPixels(ii, pixels.get(), 0, 0, 0); + if (!read) { + ERRORF(reporter, "Error reading rectangle texture."); + } + + for (int i = 0; i < pixelCnt; ++i) { + if (pixels.get()[i] != expectedPixelValues[i]) { + ERRORF(reporter, "Error, pixel value %d should be 0x%08x, got 0x%08x.", i, + expectedPixelValues[i], pixels.get()[i]); + break; + } + } +} + +static void test_write_pixels(skiatest::Reporter* reporter, GrContext* context, + GrSurfaceContext* rectSurfaceContext) { + int pixelCnt = rectSurfaceContext->width() * rectSurfaceContext->height(); + SkAutoTMalloc<uint32_t> pixels(pixelCnt); + for (int y = 0; y < rectSurfaceContext->width(); ++y) { + for (int x = 0; x < rectSurfaceContext->height(); ++x) { + pixels.get()[y * rectSurfaceContext->width() + x] = GrColorPackRGBA(x, y, x + y, x * y); + } + } + + SkImageInfo ii = SkImageInfo::Make(rectSurfaceContext->width(), rectSurfaceContext->height(), + kRGBA_8888_SkColorType, kPremul_SkAlphaType); + bool write = rectSurfaceContext->writePixels(ii, pixels.get(), 0, 0, 0); + if (!write) { + ERRORF(reporter, "Error writing to rectangle texture."); + } + + test_read_pixels(reporter, context, rectSurfaceContext, pixels.get()); +} + +static void test_copy_surface_src(skiatest::Reporter* reporter, GrContext* context, + GrSurfaceProxy* rectProxy, uint32_t expectedPixelValues[]) { + GrSurfaceDesc copyDstDesc; + copyDstDesc.fConfig = kRGBA_8888_GrPixelConfig; + copyDstDesc.fWidth = rectProxy->width(); + copyDstDesc.fHeight = rectProxy->height(); + + for (auto flags : {kNone_GrSurfaceFlags, kRenderTarget_GrSurfaceFlag}) { + copyDstDesc.fFlags = flags; + + sk_sp<GrSurfaceContext> dstContext(GrSurfaceProxy::TestCopy(context, copyDstDesc, + rectProxy)); + + test_read_pixels(reporter, context, dstContext.get(), expectedPixelValues); + } +} + +static void test_copy_surface_dst(skiatest::Reporter* reporter, GrContext* context, + GrSurfaceContext* rectContext) { + + int pixelCnt = rectContext->width() * rectContext->height(); + SkAutoTMalloc<uint32_t> pixels(pixelCnt); + for (int y = 0; y < rectContext->width(); ++y) { + for (int x = 0; x < rectContext->height(); ++x) { + pixels.get()[y * rectContext->width() + x] = GrColorPackRGBA(y, x, x * y, x *+ y); + } + } + for (auto flags : {kNone_GrSurfaceFlags, kRenderTarget_GrSurfaceFlag}) { + GrSurfaceDesc copySrcDesc; + copySrcDesc.fConfig = kRGBA_8888_GrPixelConfig; + copySrcDesc.fWidth = rectContext->width(); + copySrcDesc.fHeight = rectContext->height(); + copySrcDesc.fFlags = flags; + + sk_sp<GrSurfaceProxy> src(GrSurfaceProxy::MakeDeferred(*context->caps(), + context->textureProvider(), + copySrcDesc, + SkBudgeted::kYes, pixels.get(), 0)); + rectContext->copy(src.get()); + + test_read_pixels(reporter, context, rectContext, pixels.get()); + } +} + // skbug.com/5932 static void test_basic_draw_as_src(skiatest::Reporter* reporter, GrContext* context, sk_sp<GrSurfaceProxy> rectProxy, uint32_t expectedPixelValues[]) { @@ -36,8 +120,7 @@ static void test_basic_draw_as_src(skiatest::Reporter* reporter, GrContext* cont paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.addColorFragmentProcessor(std::move(fp)); rtContext->drawPaint(GrNoClip(), std::move(paint), SkMatrix::I()); - test_read_pixels(reporter, context, rtContext.get(), expectedPixelValues, - "RectangleTexture-basic-draw"); + test_read_pixels(reporter, context, rtContext.get(), expectedPixelValues); } } @@ -82,7 +165,7 @@ static void test_clear(skiatest::Reporter* reporter, GrContext* context, } } - test_read_pixels(reporter, context, rtc, expectedPixels.get(), "RectangleTexture-clear"); + test_read_pixels(reporter, context, rtc, expectedPixels.get()); } } @@ -154,19 +237,17 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) { test_basic_draw_as_src(reporter, context, rectProxy, refPixels); - // Test copy to both a texture and RT - test_copy_from_surface(reporter, context, rectProxy.get(), refPixels, - false, "RectangleTexture-copy-from"); + test_copy_surface_src(reporter, context, rectProxy.get(), refPixels); sk_sp<GrSurfaceContext> rectContext = context->contextPriv().makeWrappedSurfaceContext( std::move(rectProxy), nullptr); SkASSERT(rectContext); - test_read_pixels(reporter, context, rectContext.get(), refPixels, "RectangleTexture-read"); + test_read_pixels(reporter, context, rectContext.get(), refPixels); - test_copy_to_surface(reporter, context, rectContext.get(), "RectangleTexture-copy-to"); + test_copy_surface_dst(reporter, context, rectContext.get()); - test_write_pixels(reporter, context, rectContext.get(), true, "RectangleTexture-write"); + test_write_pixels(reporter, context, rectContext.get()); test_clear(reporter, context, rectContext.get()); |