From 1530283c483cb88aa725bce50a6d193dd00ee570 Mon Sep 17 00:00:00 2001 From: kkinnunen Date: Tue, 1 Dec 2015 04:35:26 -0800 Subject: Generate list of GPU contexts outside tests Use DEF_GPUTEST_FOR_*_CONTEXT macros to obtain the test GPU context. Makes changing the context -related classes easier, since not all tests need to be changed. BUG=skia:2992 Review URL: https://codereview.chromium.org/1448873002 --- tests/PremulAlphaRoundTripTest.cpp | 113 ++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 65 deletions(-) (limited to 'tests/PremulAlphaRoundTripTest.cpp') diff --git a/tests/PremulAlphaRoundTripTest.cpp b/tests/PremulAlphaRoundTripTest.cpp index 211006ad21..7f94485d46 100644 --- a/tests/PremulAlphaRoundTripTest.cpp +++ b/tests/PremulAlphaRoundTripTest.cpp @@ -12,7 +12,7 @@ #include "sk_tool_utils.h" #if SK_SUPPORT_GPU -#include "GrContextFactory.h" +#include "GrContext.h" #include "SkGpuDevice.h" #endif @@ -63,72 +63,55 @@ static void fillCanvas(SkCanvas* canvas, SkColorType colorType, PackUnpremulProc canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0); } -DEF_GPUTEST(PremulAlphaRoundTrip, reporter, factory) { - const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256); - - for (int dtype = 0; dtype < 2; ++dtype) { - - int glCtxTypeCnt = 1; -#if SK_SUPPORT_GPU - if (0 != dtype) { - glCtxTypeCnt = GrContextFactory::kGLContextTypeCnt; - } -#endif - SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); - for (int glCtxType = 0; glCtxType < glCtxTypeCnt; ++glCtxType) { - SkAutoTUnref device; - if (0 == dtype) { - device.reset(SkBitmapDevice::Create(info, props)); - } else { -#if SK_SUPPORT_GPU - GrContextFactory::GLContextType type = - static_cast(glCtxType); - if (!GrContextFactory::IsRenderingGLContext(type)) { - continue; - } - GrContext* ctx = factory->get(type); - if (nullptr == ctx) { - continue; - } - device.reset(SkGpuDevice::Create(ctx, SkSurface::kNo_Budgeted, info, 0, &props, - SkGpuDevice::kUninit_InitContents)); -#else - continue; -#endif - } - SkCanvas canvas(device); - - for (size_t upmaIdx = 0; upmaIdx < SK_ARRAY_COUNT(gUnpremul); ++upmaIdx) { - fillCanvas(&canvas, gUnpremul[upmaIdx].fColorType, gUnpremul[upmaIdx].fPackProc); - - const SkImageInfo info = SkImageInfo::Make(256, 256, gUnpremul[upmaIdx].fColorType, - kUnpremul_SkAlphaType); - SkBitmap readBmp1; - readBmp1.allocPixels(info); - SkBitmap readBmp2; - readBmp2.allocPixels(info); - - readBmp1.eraseColor(0); - readBmp2.eraseColor(0); - - canvas.readPixels(&readBmp1, 0, 0); - sk_tool_utils::write_pixels(&canvas, readBmp1, 0, 0, gUnpremul[upmaIdx].fColorType, - kUnpremul_SkAlphaType); - canvas.readPixels(&readBmp2, 0, 0); - - bool success = true; - for (int y = 0; y < 256 && success; ++y) { - const uint32_t* pixels1 = readBmp1.getAddr32(0, y); - const uint32_t* pixels2 = readBmp2.getAddr32(0, y); - for (int x = 0; x < 256 && success; ++x) { - // We see sporadic failures here. May help to see where it goes wrong. - if (pixels1[x] != pixels2[x]) { - SkDebugf("%x != %x, x = %d, y = %d\n", pixels1[x], pixels2[x], x, y); - } - REPORTER_ASSERT(reporter, success = pixels1[x] == pixels2[x]); - } +static void test_premul_alpha_roundtrip(skiatest::Reporter* reporter, SkBaseDevice* device) { + SkCanvas canvas(device); + for (size_t upmaIdx = 0; upmaIdx < SK_ARRAY_COUNT(gUnpremul); ++upmaIdx) { + fillCanvas(&canvas, gUnpremul[upmaIdx].fColorType, gUnpremul[upmaIdx].fPackProc); + + const SkImageInfo info = SkImageInfo::Make(256, 256, gUnpremul[upmaIdx].fColorType, + kUnpremul_SkAlphaType); + SkBitmap readBmp1; + readBmp1.allocPixels(info); + SkBitmap readBmp2; + readBmp2.allocPixels(info); + + readBmp1.eraseColor(0); + readBmp2.eraseColor(0); + + canvas.readPixels(&readBmp1, 0, 0); + sk_tool_utils::write_pixels(&canvas, readBmp1, 0, 0, gUnpremul[upmaIdx].fColorType, + kUnpremul_SkAlphaType); + canvas.readPixels(&readBmp2, 0, 0); + + bool success = true; + for (int y = 0; y < 256 && success; ++y) { + const uint32_t* pixels1 = readBmp1.getAddr32(0, y); + const uint32_t* pixels2 = readBmp2.getAddr32(0, y); + for (int x = 0; x < 256 && success; ++x) { + // We see sporadic failures here. May help to see where it goes wrong. + if (pixels1[x] != pixels2[x]) { + SkDebugf("%x != %x, x = %d, y = %d\n", pixels1[x], pixels2[x], x, y); } + REPORTER_ASSERT(reporter, success = pixels1[x] == pixels2[x]); } } } } + +DEF_TEST(PremulAlphaRoundTrip, reporter) { + const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256); + SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); + SkAutoTUnref device(SkBitmapDevice::Create(info, props)); + test_premul_alpha_roundtrip(reporter, device); +} +#if SK_SUPPORT_GPU +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PremulAlphaRoundTrip_Gpu, reporter, context) { + const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256); + SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); + SkAutoTUnref device( + SkGpuDevice::Create(context, SkSurface::kNo_Budgeted, info, 0, &props, + SkGpuDevice::kUninit_InitContents)); + test_premul_alpha_roundtrip(reporter, device); +} +#endif + -- cgit v1.2.3