From 3500b77f7d08dbe4c17811733cc3e4dbab889f0a Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Fri, 27 Jan 2017 10:11:42 -0500 Subject: Consolidate read/write-Pixels testing code - take 2 Change-Id: I0de058a9eec749a7086138ac2eb79732f06ce55e Reviewed-on: https://skia-review.googlesource.com/7650 Reviewed-by: Brian Osman Commit-Queue: Robert Phillips --- tests/EGLImageTest.cpp | 66 ++++++++------------------------------------------ 1 file changed, 10 insertions(+), 56 deletions(-) (limited to 'tests/EGLImageTest.cpp') diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp index 79d326156a..02ba4a82df 100644 --- a/tests/EGLImageTest.cpp +++ b/tests/EGLImageTest.cpp @@ -6,6 +6,7 @@ */ #include "Test.h" +#include "TestUtils.h" #if SK_SUPPORT_GPU #include "GrContext.h" #include "GrContextPriv.h" @@ -41,58 +42,6 @@ static void cleanup(GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx } } -static void test_read_pixels(skiatest::Reporter* reporter, GrContext* context, - GrSurfaceContext* externalTextureContext, - uint32_t expectedPixelValues[]) { - int pixelCnt = externalTextureContext->width() * externalTextureContext->height(); - SkAutoTMalloc pixels(pixelCnt); - memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt); - - SkImageInfo ii = SkImageInfo::Make(externalTextureContext->width(), - externalTextureContext->height(), - kRGBA_8888_SkColorType, kPremul_SkAlphaType); - bool read = externalTextureContext->readPixels(ii, pixels.get(), 0, 0, 0); - if (!read) { - ERRORF(reporter, "Error reading external texture."); - } - for (int i = 0; i < pixelCnt; ++i) { - if (pixels.get()[i] != expectedPixelValues[i]) { - ERRORF(reporter, "Error, external texture 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* externalTextureContext) { - int pixelCnt = externalTextureContext->width() * externalTextureContext->height(); - SkAutoTMalloc pixels(pixelCnt); - memset(pixels.get(), 0, sizeof(uint32_t)*pixelCnt); - - SkImageInfo ii = SkImageInfo::Make(externalTextureContext->width(), - externalTextureContext->height(), - kRGBA_8888_SkColorType, kPremul_SkAlphaType); - bool write = externalTextureContext->writePixels(ii, pixels.get(), 0, 0, 0); - REPORTER_ASSERT_MESSAGE(reporter, !write, "Should not be able to write to a EXTERNAL" - " texture."); -} - -static void test_copy_surface(skiatest::Reporter* reporter, GrContext* context, - GrSurfaceProxy* externalTextureProxy, - uint32_t expectedPixelValues[]) { - GrSurfaceDesc copyDesc; - copyDesc.fConfig = kRGBA_8888_GrPixelConfig; - copyDesc.fWidth = externalTextureProxy->width(); - copyDesc.fHeight = externalTextureProxy->height(); - copyDesc.fFlags = kRenderTarget_GrSurfaceFlag; - - sk_sp copyContext(GrSurfaceProxy::TestCopy(context, copyDesc, - externalTextureProxy)); - - test_read_pixels(reporter, context, copyContext.get(), expectedPixelValues); -} - DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { GrContext* context0 = ctxInfo.grContext(); sk_gpu_test::GLTestContext* glCtx0 = ctxInfo.glContext(); @@ -223,12 +172,17 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { externalDesc.fSampleCnt = 0; } - test_read_pixels(reporter, context0, externalTextureContext.get(), pixels.get()); + test_read_pixels(reporter, context0, externalTextureContext.get(), pixels.get(), + "EGLImageTest-read"); - test_write_pixels(reporter, context0, externalTextureContext.get()); + // We should not be able to write to a EXTERNAL texture + test_write_pixels(reporter, context0, externalTextureContext.get(), false, + "EGLImageTest-write"); - test_copy_surface(reporter, context0, externalTextureContext->asDeferredSurface(), - pixels.get()); + // Only test RT-config + // TODO: why do we always need to draw to copy from an external texture? + test_copy_from_surface(reporter, context0, externalTextureContext->asDeferredSurface(), + pixels.get(), true, "EGLImageTest-copy"); cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image); } -- cgit v1.2.3