diff options
author | Robert Phillips <robertphillips@google.com> | 2017-01-27 10:11:42 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-27 15:52:20 +0000 |
commit | 3500b77f7d08dbe4c17811733cc3e4dbab889f0a (patch) | |
tree | e9e7582c09ddd926d9486a1e5a0497e8cb0831b6 /tests/RectangleTextureTest.cpp | |
parent | 052fd5158f7f85e478a9f87c45fecaacf7d0f5f3 (diff) |
Consolidate read/write-Pixels testing code - take 2
Change-Id: I0de058a9eec749a7086138ac2eb79732f06ce55e
Reviewed-on: https://skia-review.googlesource.com/7650
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tests/RectangleTextureTest.cpp')
-rw-r--r-- | tests/RectangleTextureTest.cpp | 103 |
1 files changed, 11 insertions, 92 deletions
diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp index 523c2e3437..d55b882f7e 100644 --- a/tests/RectangleTextureTest.cpp +++ b/tests/RectangleTextureTest.cpp @@ -6,6 +6,8 @@ */ #include "Test.h" +#include "TestUtils.h" + #if SK_SUPPORT_GPU #include "GrContext.h" #include "GrContextPriv.h" @@ -14,92 +16,6 @@ #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[]) { @@ -120,7 +36,8 @@ 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); + test_read_pixels(reporter, context, rtContext.get(), expectedPixelValues, + "RectangleTexture-basic-draw"); } } @@ -165,7 +82,7 @@ static void test_clear(skiatest::Reporter* reporter, GrContext* context, } } - test_read_pixels(reporter, context, rtc, expectedPixels.get()); + test_read_pixels(reporter, context, rtc, expectedPixels.get(), "RectangleTexture-clear"); } } @@ -237,17 +154,19 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) { test_basic_draw_as_src(reporter, context, rectProxy, refPixels); - test_copy_surface_src(reporter, context, rectProxy.get(), refPixels); + // Test copy to both a texture and RT + test_copy_from_surface(reporter, context, rectProxy.get(), refPixels, + false, "RectangleTexture-copy-from"); sk_sp<GrSurfaceContext> rectContext = context->contextPriv().makeWrappedSurfaceContext( std::move(rectProxy), nullptr); SkASSERT(rectContext); - test_read_pixels(reporter, context, rectContext.get(), refPixels); + test_read_pixels(reporter, context, rectContext.get(), refPixels, "RectangleTexture-read"); - test_copy_surface_dst(reporter, context, rectContext.get()); + test_copy_to_surface(reporter, context, rectContext.get(), "RectangleTexture-copy-to"); - test_write_pixels(reporter, context, rectContext.get()); + test_write_pixels(reporter, context, rectContext.get(), true, "RectangleTexture-write"); test_clear(reporter, context, rectContext.get()); |