From f2f1c17e331fe1e0ce695969970ecebc81e12ceb Mon Sep 17 00:00:00 2001 From: bsalomon Date: Tue, 5 Apr 2016 12:59:06 -0700 Subject: One signature for creating unit tests that run on premade GrContexts GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1860593002 Review URL: https://codereview.chromium.org/1860593002 --- dm/DM.cpp | 48 +++++------------------ tests/BitmapCopyTest.cpp | 5 ++- tests/BlurTest.cpp | 6 +-- tests/ClearTest.cpp | 3 +- tests/ClipBoundsTest.cpp | 4 +- tests/CopySurfaceTest.cpp | 3 +- tests/EGLImageTest.cpp | 5 ++- tests/FloatingPointTextureTest.cpp | 12 +++--- tests/GLProgramsTest.cpp | 15 ++++--- tests/GpuColorFilterTest.cpp | 4 +- tests/GpuDrawPathTest.cpp | 5 ++- tests/GpuLayerCacheTest.cpp | 6 +-- tests/GrContextAbandonTest.cpp | 4 +- tests/GrContextFactoryTest.cpp | 7 ++-- tests/GrDrawTargetTest.cpp | 6 +-- tests/GrPorterDuffTest.cpp | 4 +- tests/GrSurfaceTest.cpp | 3 +- tests/GrTextureMipMapInvalidationTest.cpp | 3 +- tests/ImageFilterCacheTest.cpp | 10 ++--- tests/ImageFilterTest.cpp | 48 +++++++++++------------ tests/ImageIsOpaqueTest.cpp | 3 +- tests/ImageNewShaderTest.cpp | 8 ++-- tests/ImageTest.cpp | 48 +++++++++++++---------- tests/PremulAlphaRoundTripTest.cpp | 4 +- tests/PrimitiveProcessorTest.cpp | 3 +- tests/ReadPixelsTest.cpp | 18 ++++----- tests/ReadWriteAlphaTest.cpp | 8 ++-- tests/RecordReplaceDrawTest.cpp | 6 +-- tests/RectangleTextureTest.cpp | 4 +- tests/ResourceCacheTest.cpp | 9 +++-- tests/SRGBReadWritePixelsTest.cpp | 3 +- tests/SpecialImageTest.cpp | 6 ++- tests/SpecialSurfaceTest.cpp | 9 +++-- tests/SurfaceTest.cpp | 63 ++++++++++++++++-------------- tests/TessellatingPathRendererTests.cpp | 7 ++-- tests/Test.h | 65 ++++++++++++++++--------------- tests/TestTest.cpp | 22 +++-------- tests/TextBlobCacheTest.cpp | 16 ++++---- tests/TextureStorageAllocator.cpp | 10 +++-- tests/WritePixelsTest.cpp | 6 +-- tools/gpu/GrContextFactory.cpp | 3 +- tools/gpu/GrContextFactory.h | 21 +++++----- 42 files changed, 270 insertions(+), 273 deletions(-) diff --git a/dm/DM.cpp b/dm/DM.cpp index 00cb279e81..4a81cee9e1 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -72,6 +72,7 @@ DEFINE_bool(simpleCodec, false, "Only decode images to native scale"); using namespace DM; using sk_gpu_test::GrContextFactory; using sk_gpu_test::GLTestContext; +using sk_gpu_test::ContextInfo; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ @@ -1415,28 +1416,8 @@ int dm_main() { // TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards. // Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0. namespace skiatest { -namespace { -typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*); -typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, GLTestContext*); -#if SK_SUPPORT_GPU -template -void call_test(T test, skiatest::Reporter* reporter, const GrContextFactory::ContextInfo& context); -template<> -void call_test(TestWithGrContext test, skiatest::Reporter* reporter, - const GrContextFactory::ContextInfo& context) { - test(reporter, context.fGrContext); -} -template<> -void call_test(TestWithGrContextAndGLContext test, skiatest::Reporter* reporter, - const GrContextFactory::ContextInfo& context) { - test(reporter, context.fGrContext, context.fGLContext); -} -#endif -} // namespace - -template -void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* reporter, - GrContextFactory* factory) { +void RunWithGPUTestContexts(GrContextTestFn* test, GPUTestContexts testContexts, + Reporter* reporter, GrContextFactory* factory) { #if SK_SUPPORT_GPU // Iterate over context types, except use "native" instead of explicitly trying OpenGL and // OpenGL ES. Do not use GLES on desktop, since tests do not account for not fixing @@ -1476,29 +1457,18 @@ void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* repo if ((testContexts & contextSelector) == 0) { continue; } - GrContextFactory::ContextInfo context = factory->getContextInfo(contextType); - if (context.fGrContext) { - call_test(test, reporter, context); + ContextInfo ctxInfo = factory->getContextInfo(contextType); + if (ctxInfo.fGrContext) { + (*test)(reporter, ctxInfo); } - context = factory->getContextInfo(contextType, + ctxInfo = factory->getContextInfo(contextType, GrContextFactory::kEnableNVPR_ContextOptions); - if (context.fGrContext) { - call_test(test, reporter, context); + if (ctxInfo.fGrContext) { + (*test)(reporter, ctxInfo); } } #endif } - -template -void RunWithGPUTestContexts(TestWithGrContext test, - GPUTestContexts testContexts, - Reporter* reporter, - GrContextFactory* factory); -template -void RunWithGPUTestContexts(TestWithGrContextAndGLContext test, - GPUTestContexts testContexts, - Reporter* reporter, - GrContextFactory* factory); } // namespace skiatest #if !defined(SK_BUILD_FOR_IOS) diff --git a/tests/BitmapCopyTest.cpp b/tests/BitmapCopyTest.cpp index 216e04273f..fb38c7e46f 100644 --- a/tests/BitmapCopyTest.cpp +++ b/tests/BitmapCopyTest.cpp @@ -639,7 +639,7 @@ DEF_TEST(BitmapReadPixels, reporter) { #include "SkColorPriv.h" /** Tests calling copyTo on a texture backed bitmap. Tests that all BGRA_8888/RGBA_8888 combinations of src and dst work. This test should be removed when SkGrPixelRef is removed. */ -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(BitmapCopy_Texture, reporter, ctx) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(BitmapCopy_Texture, reporter, ctxInfo) { static const SkPMColor kData[] = { 0xFF112233, 0xAF224499, 0xEF004466, 0x80773311 @@ -667,7 +667,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(BitmapCopy_Texture, reporter, ctx) { const void* srcData = (kSkia8888_GrPixelConfig == desc.fConfig) ? kData : swizData; SkAutoTUnref texture( - ctx->textureProvider()->createTexture(desc, SkBudgeted::kNo, srcData, 0)); + ctxInfo.fGrContext->textureProvider()->createTexture(desc, SkBudgeted::kNo, srcData, + 0)); if (!texture) { continue; diff --git a/tests/BlurTest.cpp b/tests/BlurTest.cpp index 679701de93..9b4bf4ebb2 100644 --- a/tests/BlurTest.cpp +++ b/tests/BlurTest.cpp @@ -314,7 +314,7 @@ static bool match(int* first, int* second, int count, int tol) { } // Test out the normal blur style with a wide range of sigmas -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(BlurSigmaRange, reporter, context) { +DEF_TEST(BlurSigmaRange, reporter) { static const int kSize = 100; // The geometry is offset a smidge to trigger: @@ -556,10 +556,10 @@ DEF_TEST(BlurAsABlur, reporter) { // This exercises the problem discovered in crbug.com/570232. The return value from // SkBlurMask::BoxBlur wasn't being checked in SkBlurMaskFilter.cpp::GrRRectBlurEffect::Create -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SmallBoxBlurBug, reporter, ctx) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SmallBoxBlurBug, reporter, ctxInfo) { SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); - auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info)); + auto surface(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kNo, info)); SkCanvas* canvas = surface->getCanvas(); SkRect r = SkRect::MakeXYWH(10, 10, 100, 100); diff --git a/tests/ClearTest.cpp b/tests/ClearTest.cpp index 25fcf85849..56f2fe17be 100644 --- a/tests/ClearTest.cpp +++ b/tests/ClearTest.cpp @@ -65,7 +65,8 @@ static bool reset_dc(SkAutoTUnref* dc, SkAutoTUnref* r return *dc != nullptr; } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearBatch, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; static const int kW = 10; static const int kH = 10; diff --git a/tests/ClipBoundsTest.cpp b/tests/ClipBoundsTest.cpp index 2f9e13de5f..abdd3f44fa 100644 --- a/tests/ClipBoundsTest.cpp +++ b/tests/ClipBoundsTest.cpp @@ -13,7 +13,7 @@ // Ensure that the 'getConservativeBounds' calls are returning bounds clamped // to the render target -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, ctxInfo) { static const int kXSize = 100; static const int kYSize = 100; @@ -24,7 +24,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrClipBounds, reporter, context) { desc.fHeight = kYSize; SkAutoTUnref texture( - context->textureProvider()->createTexture(desc, SkBudgeted::kYes, nullptr, 0)); + ctxInfo.fGrContext->textureProvider()->createTexture(desc, SkBudgeted::kYes, nullptr, 0)); if (!texture) { return; } diff --git a/tests/CopySurfaceTest.cpp b/tests/CopySurfaceTest.cpp index 3740f6e87c..af58bf9e5c 100644 --- a/tests/CopySurfaceTest.cpp +++ b/tests/CopySurfaceTest.cpp @@ -15,7 +15,8 @@ #include "SkUtils.h" -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; static const int kW = 10; static const int kH = 10; static const size_t kRowBytes = sizeof(uint32_t) * kW; diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp index 47dad8164e..12646d53dc 100644 --- a/tests/EGLImageTest.cpp +++ b/tests/EGLImageTest.cpp @@ -81,7 +81,10 @@ static void test_copy_surface(skiatest::Reporter* reporter, GrContext* context, test_read_pixels(reporter, context, copy, expectedPixelValues); } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(EGLImageTest, reporter, context0, glCtx0) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { + GrContext* context0 = ctxInfo.fGrContext; + sk_gpu_test::GLTestContext* glCtx0 = ctxInfo.fGLContext; + // Try to create a second GL context and then check if the contexts have necessary // extensions to run this test. diff --git a/tests/FloatingPointTextureTest.cpp b/tests/FloatingPointTextureTest.cpp index a20b8a2efa..0880ef67bb 100644 --- a/tests/FloatingPointTextureTest.cpp +++ b/tests/FloatingPointTextureTest.cpp @@ -60,8 +60,8 @@ void runFPTest(skiatest::Reporter* reporter, GrContext* context, static const int FP_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 4/*RGBA*/; static const float kMaxIntegerRepresentableInSPFloatingPoint = 16777216; // 2 ^ 24 -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FloatingPointTextureTest, reporter, context) { - runFPTest(reporter, context, FLT_MIN, FLT_MAX, FLT_EPSILON, +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FloatingPointTextureTest, reporter, ctxInfo) { + runFPTest(reporter, ctxInfo.fGrContext, FLT_MIN, FLT_MAX, FLT_EPSILON, kMaxIntegerRepresentableInSPFloatingPoint, FP_CONTROL_ARRAY_SIZE, kRGBA_float_GrPixelConfig); } @@ -69,16 +69,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FloatingPointTextureTest, reporter, context) static const int HALF_ALPHA_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 1 /*alpha-only*/; static const SkHalf kMaxIntegerRepresentableInHalfFloatingPoint = 0x6800; // 2 ^ 11 -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(HalfFloatAlphaTextureTest, reporter, context) { - runFPTest(reporter, context, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon, +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(HalfFloatAlphaTextureTest, reporter, ctxInfo) { + runFPTest(reporter, ctxInfo.fGrContext, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon, kMaxIntegerRepresentableInHalfFloatingPoint, HALF_ALPHA_CONTROL_ARRAY_SIZE, kAlpha_half_GrPixelConfig); } static const int HALF_RGBA_CONTROL_ARRAY_SIZE = DEV_W * DEV_H * 4 /*RGBA*/; -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(HalfFloatRGBATextureTest, reporter, context) { - runFPTest(reporter, context, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon, +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(HalfFloatRGBATextureTest, reporter, ctxInfo) { + runFPTest(reporter, ctxInfo.fGrContext, SK_HalfMin, SK_HalfMax, SK_HalfEpsilon, kMaxIntegerRepresentableInHalfFloatingPoint, HALF_RGBA_CONTROL_ARRAY_SIZE, kRGBA_half_GrPixelConfig); } diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index 52d1e0375c..cf442fd2b8 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -422,16 +422,19 @@ static int get_glprograms_max_stages(GrContext* context) { return 0; } -static void test_glprograms_native(skiatest::Reporter* reporter, GrContext* context) { - int maxStages = get_glprograms_max_stages(context); +static void test_glprograms_native(skiatest::Reporter* reporter, + const sk_gpu_test::ContextInfo& ctxInfo) { + int maxStages = get_glprograms_max_stages(ctxInfo.fGrContext); if (maxStages == 0) { return; } - REPORTER_ASSERT(reporter, GrDrawingManager::ProgramUnitTest(context, maxStages)); + REPORTER_ASSERT(reporter, GrDrawingManager::ProgramUnitTest(ctxInfo.fGrContext, maxStages)); } -static void test_glprograms_other_contexts(skiatest::Reporter* reporter, GrContext* context) { - int maxStages = get_glprograms_max_stages(context); +static void test_glprograms_other_contexts( + skiatest::Reporter* reporter, + const sk_gpu_test::ContextInfo& ctxInfo) { + int maxStages = get_glprograms_max_stages(ctxInfo.fGrContext); #ifdef SK_BUILD_FOR_WIN // Some long shaders run out of temporary registers in the D3D compiler on ANGLE and // command buffer. @@ -440,7 +443,7 @@ static void test_glprograms_other_contexts(skiatest::Reporter* reporter, GrConte if (maxStages == 0) { return; } - REPORTER_ASSERT(reporter, GrDrawingManager::ProgramUnitTest(context, maxStages)); + REPORTER_ASSERT(reporter, GrDrawingManager::ProgramUnitTest(ctxInfo.fGrContext, maxStages)); } DEF_GPUTEST(GLPrograms, reporter, /*factory*/) { diff --git a/tests/GpuColorFilterTest.cpp b/tests/GpuColorFilterTest.cpp index 186f8c699f..1788770e5b 100644 --- a/tests/GpuColorFilterTest.cpp +++ b/tests/GpuColorFilterTest.cpp @@ -32,7 +32,7 @@ static GrColor filterColor(const GrColor& color, uint32_t flags) { return color & mask; } -DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuColorFilter, reporter, context) { +DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuColorFilter, reporter, ctxInfo) { struct GetConstantComponentTestCase { // "Shape drawn with" uint32_t inputComponents; // "rgb of", "red of", "alpha of", ... @@ -99,7 +99,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuColorFilter, reporter, context) { for (size_t i = 0; i < SK_ARRAY_COUNT(filterTests); ++i) { const GetConstantComponentTestCase& test = filterTests[i]; auto cf(SkColorFilter::MakeModeFilter(test.filterColor, test.filterMode)); - SkAutoTUnref fp( cf->asFragmentProcessor(context)); + SkAutoTUnref fp( cf->asFragmentProcessor(ctxInfo.fGrContext)); REPORTER_ASSERT(reporter, fp); GrInvariantOutput inout(test.inputColor, static_cast(test.inputComponents), diff --git a/tests/GpuDrawPathTest.cpp b/tests/GpuDrawPathTest.cpp index bab6d3a89b..ef3b97dc1f 100644 --- a/tests/GpuDrawPathTest.cpp +++ b/tests/GpuDrawPathTest.cpp @@ -76,12 +76,13 @@ static void test_drawSameRectOvals(skiatest::Reporter*, SkCanvas* canvas) { fill_and_stroke(canvas, oval1, oval2, SkDashPathEffect::Make(intervals, 2, 0)); } -DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuDrawPath, reporter, context) { +DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuDrawPath, reporter, ctxInfo) { for (auto& test_func : { &test_drawPathEmpty, &test_drawSameRectOvals }) { for (auto& sampleCount : {0, 4, 16}) { SkImageInfo info = SkImageInfo::MakeN32Premul(255, 255); auto surface( - SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, sampleCount, nullptr)); + SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kNo, info, sampleCount, + nullptr)); if (!surface) { continue; } diff --git a/tests/GpuLayerCacheTest.cpp b/tests/GpuLayerCacheTest.cpp index bbc021fc78..2249eba904 100644 --- a/tests/GpuLayerCacheTest.cpp +++ b/tests/GpuLayerCacheTest.cpp @@ -107,7 +107,7 @@ static void lock_layer(skiatest::Reporter* reporter, // In particular it checks its interaction with the resource cache (w.r.t. // locking & unlocking textures). // TODO: need to add checks on VRAM usage! -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GpuLayerCache, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GpuLayerCache, reporter, ctxInfo) { // Add one more layer than can fit in the atlas static const int kInitialNumLayers = TestingAccess::NumPlots() + 1; @@ -126,9 +126,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GpuLayerCache, reporter, context) { picture = recorder.finishRecordingAsPicture(); } - GrResourceCache* resourceCache = context->getResourceCache(); + GrResourceCache* resourceCache = ctxInfo.fGrContext->getResourceCache(); - GrLayerCache cache(context); + GrLayerCache cache(ctxInfo.fGrContext); create_layers(reporter, &cache, *picture, kInitialNumLayers, 0); diff --git a/tests/GrContextAbandonTest.cpp b/tests/GrContextAbandonTest.cpp index e1ad8f7de7..8981657029 100644 --- a/tests/GrContextAbandonTest.cpp +++ b/tests/GrContextAbandonTest.cpp @@ -12,14 +12,14 @@ #include "GrContextFactory.h" #include "Test.h" -using sk_gpu_test::GrContextFactory; +using namespace sk_gpu_test; DEF_GPUTEST(GrContext_abandonContext, reporter, /*factory*/) { for (int testType = 0; testType < 6; ++testType) { for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { GrContextFactory testFactory; GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType) i; - GrContextFactory::ContextInfo info = testFactory.getContextInfo(ctxType); + ContextInfo info = testFactory.getContextInfo(ctxType); if (GrContext* context = info.fGrContext) { switch (testType) { case 0: diff --git a/tests/GrContextFactoryTest.cpp b/tests/GrContextFactoryTest.cpp index 6e51b2fda3..395fa6a37f 100644 --- a/tests/GrContextFactoryTest.cpp +++ b/tests/GrContextFactoryTest.cpp @@ -13,7 +13,7 @@ #include "GrCaps.h" #include "Test.h" -using sk_gpu_test::GrContextFactory; +using namespace sk_gpu_test; DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter, /*factory*/) { // Test that if NVPR is requested, the context always has path rendering @@ -74,7 +74,7 @@ DEF_GPUTEST(GrContextFactory_abandon, reporter, /*factory*/) { GrContextFactory testFactory; for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType) i; - GrContextFactory::ContextInfo info1 = testFactory.getContextInfo(ctxType); + ContextInfo info1 = testFactory.getContextInfo(ctxType); if (!info1.fGrContext) { continue; } @@ -84,8 +84,7 @@ DEF_GPUTEST(GrContextFactory_abandon, reporter, /*factory*/) { testFactory.abandonContexts(); // Test that we get different context after abandon. - GrContextFactory::ContextInfo info2 = - testFactory.getContextInfo(ctxType); + ContextInfo info2 = testFactory.getContextInfo(ctxType); REPORTER_ASSERT(reporter, info2.fGrContext); REPORTER_ASSERT(reporter, info2.fGLContext); REPORTER_ASSERT(reporter, info1.fGrContext != info2.fGrContext); diff --git a/tests/GrDrawTargetTest.cpp b/tests/GrDrawTargetTest.cpp index 30fc0a24aa..4f927091de 100644 --- a/tests/GrDrawTargetTest.cpp +++ b/tests/GrDrawTargetTest.cpp @@ -12,11 +12,11 @@ #include "GrContext.h" #include "GrGpu.h" -DEF_GPUTEST_FOR_ALL_CONTEXTS(GrDrawTargetPrint, reporter, context) { +DEF_GPUTEST_FOR_ALL_CONTEXTS(GrDrawTargetPrint, reporter, ctxInfo) { // This used to assert. - SkString result = context->caps()->dump(); + SkString result = ctxInfo.fGrContext->caps()->dump(); SkASSERT(!result.isEmpty()); - SkString shaderResult = context->caps()->shaderCaps()->dump(); + SkString shaderResult = ctxInfo.fGrContext->caps()->shaderCaps()->dump(); SkASSERT(!shaderResult.isEmpty()); } diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp index b0377715b4..a55fffe9be 100644 --- a/tests/GrPorterDuffTest.cpp +++ b/tests/GrPorterDuffTest.cpp @@ -28,8 +28,8 @@ static void test_color_opaque_no_coverage(skiatest::Reporter* reporter, const Gr static void test_lcd_coverage(skiatest::Reporter* reporter, const GrCaps& caps); static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const GrCaps& caps); -DEF_GPUTEST_FOR_NULL_CONTEXT(GrPorterDuff, reporter, context) { - const GrCaps& caps = *context->getGpu()->caps(); +DEF_GPUTEST_FOR_NULL_CONTEXT(GrPorterDuff, reporter, ctxInfo) { + const GrCaps& caps = *ctxInfo.fGrContext->getGpu()->caps(); if (!caps.shaderCaps()->dualSourceBlendingSupport()) { SkFAIL("Null context does not support dual source blending."); return; diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index ac0b399b69..280a1c8a72 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -18,7 +18,8 @@ // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture // and render targets to GrSurface all work as expected. -DEF_GPUTEST_FOR_NULL_CONTEXT(GrSurface, reporter, context) { +DEF_GPUTEST_FOR_NULL_CONTEXT(GrSurface, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; GrSurfaceDesc desc; desc.fConfig = kSkia8888_GrPixelConfig; desc.fFlags = kRenderTarget_GrSurfaceFlag; diff --git a/tests/GrTextureMipMapInvalidationTest.cpp b/tests/GrTextureMipMapInvalidationTest.cpp index 539a8ce55c..0a8ecb6cbc 100644 --- a/tests/GrTextureMipMapInvalidationTest.cpp +++ b/tests/GrTextureMipMapInvalidationTest.cpp @@ -19,7 +19,8 @@ // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture // and render targets to GrSurface all work as expected. -DEF_GPUTEST_FOR_NULL_CONTEXT(GrTextureMipMapInvalidationTest, reporter, context) { +DEF_GPUTEST_FOR_NULL_CONTEXT(GrTextureMipMapInvalidationTest, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; GrSurfaceDesc desc; desc.fConfig = kSkia8888_GrPixelConfig; desc.fFlags = kRenderTarget_GrSurfaceFlag; diff --git a/tests/ImageFilterCacheTest.cpp b/tests/ImageFilterCacheTest.cpp index 89c6dcf6aa..cd159f1943 100644 --- a/tests/ImageFilterCacheTest.cpp +++ b/tests/ImageFilterCacheTest.cpp @@ -187,8 +187,8 @@ static GrTexture* create_texture(GrContext* context) { return context->textureProvider()->createTexture(desc, SkBudgeted::kNo, srcBM.getPixels(), 0); } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, context) { - SkAutoTUnref srcTexture(create_texture(context)); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ctxInfo) { + SkAutoTUnref srcTexture(create_texture(ctxInfo.fGrContext)); if (!srcTexture) { return; } @@ -200,7 +200,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, co backendDesc.fHeight = kFullSize; backendDesc.fSampleCnt = 0; backendDesc.fTextureHandle = srcTexture->getTextureHandle(); - sk_sp srcImage(SkImage::MakeFromTexture(context, backendDesc, kPremul_SkAlphaType)); + sk_sp srcImage(SkImage::MakeFromTexture(ctxInfo.fGrContext, backendDesc, kPremul_SkAlphaType)); if (!srcImage) { return; } @@ -208,9 +208,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, co test_image_backed(reporter, srcImage); } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, ctxInfo) { - SkAutoTUnref srcTexture(create_texture(context)); + SkAutoTUnref srcTexture(create_texture(ctxInfo.fGrContext)); if (!srcTexture) { return; } diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 02496e22a9..ea27d7bdce 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -656,8 +656,8 @@ DEF_TEST(TestNegativeBlurSigma, reporter) { } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TestNegativeBlurSigma_Gpu, reporter, context) { - run_gpu_test(reporter, context, 100, test_negative_blur_sigma); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TestNegativeBlurSigma_Gpu, reporter, ctxInfo) { + run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_negative_blur_sigma); } #endif @@ -702,8 +702,8 @@ DEF_TEST(TestZeroBlurSigma, reporter) { } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TestZeroBlurSigma_Gpu, reporter, context) { - run_gpu_test(reporter, context, 100, test_zero_blur_sigma); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TestZeroBlurSigma_Gpu, reporter, ctxInfo) { + run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_zero_blur_sigma); } #endif @@ -736,8 +736,8 @@ DEF_TEST(ImageFilterFailAffectsTransparentBlack, reporter) { } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterFailAffectsTransparentBlack_Gpu, reporter, context) { - run_gpu_test(reporter, context, 100, test_fail_affects_transparent_black); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterFailAffectsTransparentBlack_Gpu, reporter, ctxInfo) { + run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_fail_affects_transparent_black); } #endif @@ -952,8 +952,8 @@ DEF_TEST(ImageFilterMergeResultSize, reporter) { } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterMergeResultSize_Gpu, reporter, context) { - run_gpu_test(reporter, context, 100, test_imagefilter_merge_result_size); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterMergeResultSize_Gpu, reporter, ctxInfo) { + run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_imagefilter_merge_result_size); } #endif @@ -1087,8 +1087,8 @@ DEF_TEST(ImageFilterCropRect, reporter) { } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCropRect_Gpu, reporter, context) { - run_gpu_test(reporter, context, 100, test_crop_rects); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCropRect_Gpu, reporter, ctxInfo) { + run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_crop_rects); } #endif @@ -1210,8 +1210,8 @@ DEF_TEST(ImageFilterClippedPictureImageFilter, reporter) { } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterClippedPictureImageFilter_Gpu, reporter, context) { - run_gpu_test(reporter, context, 2, test_clipped_picture_imagefilter); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterClippedPictureImageFilter_Gpu, reporter, ctxInfo) { + run_gpu_test(reporter, ctxInfo.fGrContext, 2, test_clipped_picture_imagefilter); } #endif @@ -1465,8 +1465,8 @@ DEF_TEST(ComposedImageFilterOffset, reporter) { } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ComposedImageFilterOffset_Gpu, reporter, context) { - run_gpu_test(reporter, context, 100, test_composed_imagefilter_offset); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ComposedImageFilterOffset_Gpu, reporter, ctxInfo) { + run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_composed_imagefilter_offset); } #endif @@ -1509,8 +1509,8 @@ DEF_TEST(ComposedImageFilterBounds, reporter) { } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ComposedImageFilterBounds_Gpu, reporter, context) { - run_gpu_test(reporter, context, 100, test_composed_imagefilter_bounds); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ComposedImageFilterBounds_Gpu, reporter, ctxInfo) { + run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_composed_imagefilter_bounds); } #endif @@ -1539,8 +1539,8 @@ DEF_TEST(PartialCropRect, reporter) { } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PartialCropRect_Gpu, reporter, context) { - run_gpu_test(reporter, context, 100, test_partial_crop_rect); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PartialCropRect_Gpu, reporter, ctxInfo) { + run_gpu_test(reporter, ctxInfo.fGrContext, 100, test_partial_crop_rect); } #endif @@ -1677,10 +1677,10 @@ DEF_TEST(BlurLargeImage, reporter) { #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(HugeBlurImageFilter_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(HugeBlurImageFilter_Gpu, reporter, ctxInfo) { const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); - SkAutoTUnref device(SkGpuDevice::Create(context, + SkAutoTUnref device(SkGpuDevice::Create(ctxInfo.fGrContext, SkBudgeted::kNo, SkImageInfo::MakeN32Premul(100, 100), 0, @@ -1691,10 +1691,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(HugeBlurImageFilter_Gpu, reporter, context) { test_huge_blur(&canvas, reporter); } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(XfermodeImageFilterCroppedInput_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(XfermodeImageFilterCroppedInput_Gpu, reporter, ctxInfo) { const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); - SkAutoTUnref device(SkGpuDevice::Create(context, + SkAutoTUnref device(SkGpuDevice::Create(ctxInfo.fGrContext, SkBudgeted::kNo, SkImageInfo::MakeN32Premul(1, 1), 0, @@ -1705,8 +1705,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(XfermodeImageFilterCroppedInput_Gpu, reporter test_xfermode_cropped_input(&canvas, reporter); } -DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, context) { - auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, +DEF_GPUTEST_FOR_ALL_CONTEXTS(BlurLargeImage_Gpu, reporter, ctxInfo) { + auto surface(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kYes, SkImageInfo::MakeN32Premul(100, 100))); test_large_blur_input(reporter, surface->getCanvas()); } diff --git a/tests/ImageIsOpaqueTest.cpp b/tests/ImageIsOpaqueTest.cpp index 6b8b64ac21..04d2e13fe2 100644 --- a/tests/ImageIsOpaqueTest.cpp +++ b/tests/ImageIsOpaqueTest.cpp @@ -66,7 +66,8 @@ DEF_TEST(ImageIsOpaqueTest, reporter) { #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageIsOpaqueTest_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageIsOpaqueTest_Gpu, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5); auto surfaceTransparent(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, infoTransparent)); check_isopaque(reporter, surfaceTransparent, false); diff --git a/tests/ImageNewShaderTest.cpp b/tests/ImageNewShaderTest.cpp index 4ae0b6de8e..164f11898e 100644 --- a/tests/ImageNewShaderTest.cpp +++ b/tests/ImageNewShaderTest.cpp @@ -139,15 +139,15 @@ void rasterToGpu(skiatest::Reporter* reporter, GrContext* context) { runShaderTest(reporter, sourceSurface.get(), destinationSurface.get(), info); } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageNewShader_GPU, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageNewShader_GPU, reporter, ctxInfo) { // GPU -> GPU - gpuToGpu(reporter, context); + gpuToGpu(reporter, ctxInfo.fGrContext); // GPU -> RASTER - gpuToRaster(reporter, context); + gpuToRaster(reporter, ctxInfo.fGrContext); // RASTER -> GPU - rasterToGpu(reporter, context); + rasterToGpu(reporter, ctxInfo.fGrContext); } #endif diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index a1c522b7b7..87fc8fd529 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -26,7 +26,7 @@ #include "SkUtils.h" #include "Test.h" -using sk_gpu_test::GrContextFactory; +using namespace sk_gpu_test; static void assert_equal(skiatest::Reporter* reporter, SkImage* a, const SkIRect* subsetA, SkImage* b) { @@ -176,8 +176,8 @@ DEF_TEST(ImageEncode, reporter) { } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageEncode_Gpu, reporter, context) { - test_encode(reporter, create_gpu_image(context).get()); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageEncode_Gpu, reporter, ctxInfo) { + test_encode(reporter, create_gpu_image(ctxInfo.fGrContext).get()); } #endif @@ -369,9 +369,9 @@ DEF_TEST(image_newfrombitmap, reporter) { * but we don't have that facility (at the moment) so we use a little internal knowledge * of *how* the raster version is cached, and look for that. */ -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_Gpu2Cpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_Gpu2Cpu, reporter, ctxInfo) { SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); - sk_sp image(create_gpu_image(context)); + sk_sp image(create_gpu_image(ctxInfo.fGrContext)); const uint32_t uniqueID = image->uniqueID(); auto surface(SkSurface::MakeRaster(info)); @@ -404,9 +404,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_Gpu2Cpu, reporter, context) { } } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_newTextureImage, reporter, context, glContext) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_newTextureImage, reporter, contextInfo) { + GrContext* context = contextInfo.fGrContext; + sk_gpu_test::GLTestContext* glContext = contextInfo.fGLContext; + GrContextFactory otherFactory; - GrContextFactory::ContextInfo otherContextInfo = + ContextInfo otherContextInfo = otherFactory.getContextInfo(GrContextFactory::kNativeGL_ContextType); glContext->makeCurrent(); @@ -574,8 +577,8 @@ DEF_TEST(ImageReadPixels, reporter) { test_read_pixels(reporter, image.get()); } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageReadPixels_Gpu, reporter, context) { - test_read_pixels(reporter, create_gpu_image(context).get()); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageReadPixels_Gpu, reporter, ctxInfo) { + test_read_pixels(reporter, create_gpu_image(ctxInfo.fGrContext).get()); } #endif @@ -637,13 +640,13 @@ DEF_TEST(ImageLegacyBitmap, reporter) { } } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageLegacyBitmap_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageLegacyBitmap_Gpu, reporter, ctxInfo) { const SkImage::LegacyBitmapMode modes[] = { SkImage::kRO_LegacyBitmapMode, SkImage::kRW_LegacyBitmapMode, }; for (auto& mode : modes) { - sk_sp image(create_gpu_image(context)); + sk_sp image(create_gpu_image(ctxInfo.fGrContext)); test_legacy_bitmap(reporter, image.get(), mode); } } @@ -681,8 +684,8 @@ DEF_TEST(ImagePeek, reporter) { test_peek(reporter, image.get(), false); } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImagePeek_Gpu, reporter, context) { - sk_sp image(create_gpu_image(context)); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImagePeek_Gpu, reporter, ctxInfo) { + sk_sp image(create_gpu_image(ctxInfo.fGrContext)); test_peek(reporter, image.get(), false); } #endif @@ -701,8 +704,8 @@ static void check_image_color(skiatest::Reporter* reporter, SkImage* image, SkPM REPORTER_ASSERT(reporter, image->readPixels(info, &pixel, sizeof(pixel), 0, 0)); REPORTER_ASSERT(reporter, pixel == expected); } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_NewFromTexture, reporter, context) { - GrTextureProvider* provider = context->textureProvider(); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_NewFromTexture, reporter, ctxInfo) { + GrTextureProvider* provider = ctxInfo.fGrContext->textureProvider(); const int w = 10; const int h = 10; SkPMColor storage[w * h]; @@ -730,9 +733,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_NewFromTexture, reporter, context) { backendDesc.fTextureHandle = tex->getTextureHandle(); TextureReleaseChecker releaseChecker; sk_sp refImg( - SkImage::MakeFromTexture(context, backendDesc, kPremul_SkAlphaType, + SkImage::MakeFromTexture(ctxInfo.fGrContext, backendDesc, kPremul_SkAlphaType, TextureReleaseChecker::Release, &releaseChecker)); - sk_sp cpyImg(SkImage::MakeFromTextureCopy(context, backendDesc, kPremul_SkAlphaType)); + sk_sp cpyImg(SkImage::MakeFromTextureCopy(ctxInfo.fGrContext, backendDesc, + kPremul_SkAlphaType)); check_image_color(reporter, refImg.get(), expected0); check_image_color(reporter, cpyImg.get(), expected0); @@ -795,7 +799,7 @@ static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co } } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, ctxInfo) { for (auto create : {&create_image, &create_image_565, &create_image_ct}) { @@ -809,7 +813,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, context) { if (!image->peekPixels(&pixmap)) { ERRORF(reporter, "peek failed"); } else { - sk_sp texImage(SkImage::MakeTextureFromPixmap(context, pixmap, + sk_sp texImage(SkImage::MakeTextureFromPixmap(ctxInfo.fGrContext, pixmap, SkBudgeted::kNo)); if (!texImage) { ERRORF(reporter, "NewTextureFromPixmap failed."); @@ -820,11 +824,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, context) { } } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredTextureImage, reporter, context, glContext) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredTextureImage, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; + sk_gpu_test::GLTestContext* glContext = ctxInfo.fGLContext; SkAutoTUnref proxy(context->threadSafeProxy()); GrContextFactory otherFactory; - GrContextFactory::ContextInfo otherContextInfo = + ContextInfo otherContextInfo = otherFactory.getContextInfo(GrContextFactory::kNativeGL_ContextType); glContext->makeCurrent(); diff --git a/tests/PremulAlphaRoundTripTest.cpp b/tests/PremulAlphaRoundTripTest.cpp index 5cc7a493c6..26badb66c4 100644 --- a/tests/PremulAlphaRoundTripTest.cpp +++ b/tests/PremulAlphaRoundTripTest.cpp @@ -105,11 +105,11 @@ DEF_TEST(PremulAlphaRoundTrip, reporter) { test_premul_alpha_roundtrip(reporter, device); } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PremulAlphaRoundTrip_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PremulAlphaRoundTrip_Gpu, reporter, ctxInfo) { const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256); SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); SkAutoTUnref device( - SkGpuDevice::Create(context, SkBudgeted::kNo, info, 0, &props, + SkGpuDevice::Create(ctxInfo.fGrContext, SkBudgeted::kNo, info, 0, &props, SkGpuDevice::kUninit_InitContents)); test_premul_alpha_roundtrip(reporter, device); } diff --git a/tests/PrimitiveProcessorTest.cpp b/tests/PrimitiveProcessorTest.cpp index a6f24848c6..d25a33c602 100644 --- a/tests/PrimitiveProcessorTest.cpp +++ b/tests/PrimitiveProcessorTest.cpp @@ -101,7 +101,8 @@ private: }; } -DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, context) { +DEF_GPUTEST_FOR_ALL_CONTEXTS(VertexAttributeCount, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; GrTextureDesc desc; desc.fHeight = 1; desc.fWidth = 1; diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp index 15aede559d..830dbb2861 100644 --- a/tests/ReadPixelsTest.cpp +++ b/tests/ReadPixelsTest.cpp @@ -387,7 +387,7 @@ DEF_TEST(ReadPixels, reporter) { test_readpixels(reporter, surface, kLastAligned_BitmapInit); } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, ctxInfo) { for (auto& origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) { GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; @@ -396,7 +396,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, context) { desc.fConfig = kSkia8888_GrPixelConfig; desc.fOrigin = origin; SkAutoTUnref surfaceTexture( - context->textureProvider()->createTexture(desc, SkBudgeted::kNo)); + ctxInfo.fGrContext->textureProvider()->createTexture(desc, SkBudgeted::kNo)); auto surface(SkSurface::MakeRenderTargetDirect(surfaceTexture->asRenderTarget())); desc.fFlags = kNone_GrSurfaceFlags; test_readpixels(reporter, surface, kLast_BitmapInit); @@ -442,7 +442,7 @@ static void test_readpixels_texture(skiatest::Reporter* reporter, GrTexture* tex } } } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, ctxInfo) { // On the GPU we will also try reading back from a non-renderable texture. for (auto& origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) { SkAutoTUnref texture; @@ -453,7 +453,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Texture, reporter, context) { desc.fConfig = kSkia8888_GrPixelConfig; desc.fOrigin = origin; desc.fFlags = kNone_GrSurfaceFlags; - texture.reset(context->textureProvider()->createTexture(desc, SkBudgeted::kNo)); + texture.reset(ctxInfo.fGrContext->textureProvider()->createTexture(desc, SkBudgeted::kNo)); test_readpixels_texture(reporter, texture); } } @@ -576,7 +576,7 @@ static void dump_to_file(const char name[], SkData* data) { * * https://bug.skia.org/4351 */ -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Subset_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Subset_Gpu, reporter, ctxInfo) { SkBitmap bitmap; make_ringed_bitmap(&bitmap, 6, 6); const SkIRect subset = SkIRect::MakeLTRB(2, 2, 4, 4); @@ -585,7 +585,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Subset_Gpu, reporter, context) { SkBitmap bm_subset, tx_subset; // ... one from a texture-subset - SkAutoTUnref fullTx(GrRefCachedBitmapTexture(context, bitmap, + SkAutoTUnref fullTx(GrRefCachedBitmapTexture(ctxInfo.fGrContext, bitmap, GrTextureParams::ClampNoFilter())); SkBitmap tx_full; GrWrapTextureInBitmap(fullTx, bitmap.width(), bitmap.height(), true, &tx_full); @@ -594,7 +594,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Subset_Gpu, reporter, context) { // ... one from a bitmap-subset SkBitmap tmp_subset; bitmap.extractSubset(&tmp_subset, subset); - SkAutoTUnref subsetTx(GrRefCachedBitmapTexture(context, tmp_subset, + SkAutoTUnref subsetTx(GrRefCachedBitmapTexture(ctxInfo.fGrContext, tmp_subset, GrTextureParams::ClampNoFilter())); GrWrapTextureInBitmap(subsetTx, tmp_subset.width(), tmp_subset.height(), true, &bm_subset); @@ -603,8 +603,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Subset_Gpu, reporter, context) { // do they draw the same? const SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); - auto surfA(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); - auto surfB(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); + auto surfA(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kNo, info)); + auto surfB(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kNo, info)); if (false) { // diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp index 1be775f8f3..64b4ef6da7 100644 --- a/tests/ReadWriteAlphaTest.cpp +++ b/tests/ReadWriteAlphaTest.cpp @@ -33,7 +33,7 @@ static void validate_alpha_data(skiatest::Reporter* reporter, int w, int h, cons } } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) { unsigned char alphaData[X_SIZE * Y_SIZE]; bool match; @@ -50,7 +50,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) { // We are initializing the texture with zeros here memset(alphaData, 0, X_SIZE * Y_SIZE); SkAutoTUnref texture( - context->textureProvider()->createTexture(desc, SkBudgeted::kNo , alphaData, 0)); + ctxInfo.fGrContext->textureProvider()->createTexture(desc, SkBudgeted::kNo , alphaData, + 0)); if (!texture) { if (!rt) { ERRORF(reporter, "Could not create alpha texture."); @@ -150,7 +151,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, context) { } } SkAutoTUnref texture( - context->textureProvider()->createTexture(desc, SkBudgeted::kNo, rgbaData, 0)); + ctxInfo.fGrContext->textureProvider()->createTexture(desc, SkBudgeted::kNo, + rgbaData, 0)); if (!texture) { // We always expect to be able to create a RGBA texture if (!rt && kRGBA_8888_GrPixelConfig == desc.fConfig) { diff --git a/tests/RecordReplaceDrawTest.cpp b/tests/RecordReplaceDrawTest.cpp index fe11106a65..5506551d6b 100644 --- a/tests/RecordReplaceDrawTest.cpp +++ b/tests/RecordReplaceDrawTest.cpp @@ -141,9 +141,9 @@ void test_replacements(skiatest::Reporter* r, GrContext* context, bool doReplace } } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RecordReplaceDraw, r, context) { - test_replacements(r, context, false); - test_replacements(r, context, true); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RecordReplaceDraw, r, ctxInfo) { + test_replacements(r, ctxInfo.fGrContext, true); + test_replacements(r, ctxInfo.fGrContext, false); } #endif diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp index 782a3b57b3..a4a1cf7960 100644 --- a/tests/RectangleTextureTest.cpp +++ b/tests/RectangleTextureTest.cpp @@ -137,7 +137,9 @@ static void test_clear(skiatest::Reporter* reporter, GrContext* context, } } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RectangleTexture, reporter, context, glContext) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; + sk_gpu_test::GLTestContext* glContext = ctxInfo.fGLContext; static const int kWidth = 13; static const int kHeight = 13; diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 0931876cf1..0ac64edd07 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -30,7 +30,8 @@ static const int gWidth = 640; static const int gHeight = 480; //////////////////////////////////////////////////////////////////////////////// -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; GrSurfaceDesc desc; desc.fConfig = kSkia8888_GrPixelConfig; desc.fFlags = kRenderTarget_GrSurfaceFlag; @@ -79,7 +80,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheCache, reporter, context) { context->setResourceCacheLimits(oldMaxNum, oldMaxBytes); } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheStencilBuffers, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheStencilBuffers, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; GrSurfaceDesc smallDesc; smallDesc.fFlags = kRenderTarget_GrSurfaceFlag; smallDesc.fConfig = kSkia8888_GrPixelConfig; @@ -186,7 +188,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheStencilBuffers, reporter, contex } } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; GrGpu* gpu = context->getGpu(); // this test is only valid for GL if (!gpu || !gpu->glContextForTesting()) { diff --git a/tests/SRGBReadWritePixelsTest.cpp b/tests/SRGBReadWritePixelsTest.cpp index 1446d7d0ac..1067baa9e2 100644 --- a/tests/SRGBReadWritePixelsTest.cpp +++ b/tests/SRGBReadWritePixelsTest.cpp @@ -138,7 +138,8 @@ void read_and_check_pixels(skiatest::Reporter* reporter, GrTexture* texture, uin // TODO: Add tests for copySurface between srgb/linear textures. Add tests for unpremul/premul // conversion during read/write along with srgb/linear conversions. -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SRGBReadWritePixels, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; #if defined(GOOGLE3) // Stack frame size is limited in GOOGLE3. static const int kW = 63; diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp index 770810a1c8..f16f5ff84c 100644 --- a/tests/SpecialImageTest.cpp +++ b/tests/SpecialImageTest.cpp @@ -203,7 +203,8 @@ static void test_texture_backed(skiatest::Reporter* reporter, } // Test out the SkSpecialImage::makeTextureImage entry point -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; SkBitmap bm = create_bm(); const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); @@ -266,7 +267,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, context) } } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; SkBitmap bm = create_bm(); GrSurfaceDesc desc; diff --git a/tests/SpecialSurfaceTest.cpp b/tests/SpecialSurfaceTest.cpp index cd4f0ae19b..b55bc4eb94 100644 --- a/tests/SpecialSurfaceTest.cpp +++ b/tests/SpecialSurfaceTest.cpp @@ -82,27 +82,28 @@ DEF_TEST(SpecialSurface_Raster2, reporter) { #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu1, reporter, ctxInfo) { GrSurfaceDesc desc; desc.fConfig = kSkia8888_GrPixelConfig; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fWidth = kSmallerSize; desc.fHeight = kSmallerSize; - sk_sp surf(SkSpecialSurface::MakeRenderTarget(nullptr, context, desc)); + sk_sp surf(SkSpecialSurface::MakeRenderTarget(nullptr, ctxInfo.fGrContext, + desc)); test_surface(surf, reporter, 0); } // test the more flexible factory -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu2, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialSurface_Gpu2, reporter, ctxInfo) { GrSurfaceDesc desc; desc.fConfig = kSkia8888_GrPixelConfig; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fWidth = kFullSize; desc.fHeight = kFullSize; - SkAutoTUnref temp(context->textureProvider()->createApproxTexture(desc)); + SkAutoTUnref temp(ctxInfo.fGrContext->textureProvider()->createApproxTexture(desc)); SkASSERT_RELEASE(temp); const SkIRect subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 4aaabd8062..e4d0519c78 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -74,16 +74,17 @@ DEF_TEST(SurfaceEmpty, reporter) { } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) { const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType); REPORTER_ASSERT(reporter, nullptr == - SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr)); + SkSurface::MakeRenderTarget(ctxInfo.fGrContext, SkBudgeted::kNo, info, 0, + nullptr)); } #endif #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, context) { - GrGpu* gpu = context->getGpu(); +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, ctxInfo) { + GrGpu* gpu = ctxInfo.fGrContext->getGpu(); if (!gpu) { return; } @@ -107,7 +108,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, context) { wrappedDesc.fFlags = kRenderTarget_GrBackendTextureFlag; wrappedDesc.fTextureHandle = texHandle; - auto surface(SkSurface::MakeFromBackendTexture(context, wrappedDesc, nullptr)); + auto surface(SkSurface::MakeFromBackendTexture(ctxInfo.fGrContext, wrappedDesc, nullptr)); REPORTER_ASSERT(reporter, surface); if (surface) { // Validate that we can draw to the canvas and that the original texture color is preserved @@ -185,10 +186,10 @@ DEF_TEST(SurfaceCanvasPeek, reporter) { } } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCanvasPeek_Gpu, reporter, ctxInfo) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { SkImageInfo requestInfo; - auto surface(surface_func(context, kPremul_SkAlphaType, &requestInfo)); + auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, &requestInfo)); test_canvas_peek(reporter, surface, requestInfo, false); } } @@ -218,9 +219,9 @@ DEF_TEST(SurfaceAccessPixels, reporter) { } } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceAccessPixels_Gpu, reporter, ctxInfo) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { - auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullptr)); test_access_pixels(reporter, surface); } } @@ -247,11 +248,11 @@ DEF_TEST(SurfaceSnapshotAlphaType, reporter) { } } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceSnapshotAlphaType_Gpu, reporter, ctxInfo) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { for (auto& isOpaque : { true, false }) { SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType; - auto surface(surface_func(context, alphaType, nullptr)); + auto surface(surface_func(ctxInfo.fGrContext, alphaType, nullptr)); test_snapshot_alphatype(reporter, surface, isOpaque); } } @@ -299,7 +300,7 @@ DEF_TEST(SurfaceBackendHandleAccessCopyOnWrite, reporter) { } } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu, reporter, ctxInfo) { const SkSurface::BackendHandleAccess accessModes[] = { SkSurface::kFlushRead_BackendHandleAccess, SkSurface::kFlushWrite_BackendHandleAccess, @@ -309,7 +310,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessCopyOnWrite_Gpu, re for (auto& handle_access_func : { &get_surface_backend_texture_handle, &get_surface_backend_render_target_handle }) { for (auto& accessMode : accessModes) { - auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullptr)); test_backend_handle_access_copy_on_write(reporter, surface.get(), accessMode, handle_access_func); } @@ -397,7 +398,8 @@ DEF_TEST(UniqueImageSnapshot, reporter) { } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { auto surface(surface_func(context, kOpaque_SkAlphaType, nullptr)); @@ -499,12 +501,12 @@ static void test_backend_handle_unique_id( REPORTER_ASSERT(reporter, image2->uniqueID() != image3->uniqueID()); } // No CPU test. -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBackendHandleAccessIDs_Gpu, reporter, ctxInfo) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { for (auto& test_func : { &test_backend_handle_unique_id, &test_backend_handle_gen_id }) { for (auto& handle_access_func : { &get_surface_backend_texture_handle, &get_surface_backend_render_target_handle}) { - auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullptr)); test_func(reporter, surface.get(), handle_access_func); } } @@ -591,9 +593,9 @@ DEF_TEST(SurfaceCopyOnWrite, reporter) { test_copy_on_write(reporter, create_surface().get()); } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCopyOnWrite_Gpu, reporter, ctxInfo) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { - auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullptr)); test_copy_on_write(reporter, surface.get()); } } @@ -613,9 +615,9 @@ DEF_TEST(SurfaceWriteableAfterSnapshotRelease, reporter) { test_writable_after_snapshot_release(reporter, create_surface().get()); } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWriteableAfterSnapshotRelease_Gpu, reporter, ctxInfo) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { - auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullptr)); test_writable_after_snapshot_release(reporter, surface.get()); } } @@ -654,10 +656,10 @@ static void test_crbug263329(skiatest::Reporter* reporter, REPORTER_ASSERT(reporter, as_IB(image3)->peekTexture() != as_IB(image1)->peekTexture()); REPORTER_ASSERT(reporter, as_IB(image2)->peekTexture() != as_IB(image1)->peekTexture()); } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCRBug263329_Gpu, reporter, ctxInfo) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { - auto surface1(surface_func(context, kPremul_SkAlphaType, nullptr)); - auto surface2(surface_func(context, kPremul_SkAlphaType, nullptr)); + auto surface1(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullptr)); + auto surface2(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullptr)); test_crbug263329(reporter, surface1.get(), surface2.get()); } } @@ -671,9 +673,9 @@ DEF_TEST(SurfaceGetTexture, reporter) { REPORTER_ASSERT(reporter, as_IB(image)->peekTexture() == nullptr); } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacepeekTexture_Gpu, reporter, ctxInfo) { for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { - auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullptr)); sk_sp image(surface->makeImageSnapshot()); GrTexture* texture = as_IB(image)->peekTexture(); REPORTER_ASSERT(reporter, texture); @@ -703,11 +705,11 @@ static SkBudgeted is_budgeted(const sk_sp image) { return is_budgeted(image.get()); } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceBudget, reporter, ctxInfo) { SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); for (auto sbudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { for (auto ibudgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) { - auto surface(SkSurface::MakeRenderTarget(context, sbudgeted, info)); + auto surface(SkSurface::MakeRenderTarget(ctxInfo.fGrContext, sbudgeted, info)); SkASSERT(surface); REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); @@ -765,13 +767,13 @@ DEF_TEST(SurfaceNoCanvas, reporter) { } } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceNoCanvas_Gpu, reporter, ctxInfo) { SkSurface::ContentChangeMode modes[] = { SkSurface::kDiscard_ContentChangeMode, SkSurface::kRetain_ContentChangeMode}; for (auto& surface_func : { &create_gpu_surface, &create_gpu_scratch_surface }) { for (auto& test_func : { &test_no_canvas1, &test_no_canvas2 }) { for (auto& mode : modes) { - auto surface(surface_func(context, kPremul_SkAlphaType, nullptr)); + auto surface(surface_func(ctxInfo.fGrContext, kPremul_SkAlphaType, nullptr)); test_func(reporter, surface.get(), mode); } } @@ -856,7 +858,8 @@ void test_surface_clear(skiatest::Reporter* reporter, sk_sp surface, } } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; std::function grSurfaceGetters[] = { [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLayerRenderTarget(); }, [] (SkSurface* s){ diff --git a/tests/TessellatingPathRendererTests.cpp b/tests/TessellatingPathRendererTests.cpp index 6cf2a938dc..32973ee1c8 100644 --- a/tests/TessellatingPathRendererTests.cpp +++ b/tests/TessellatingPathRendererTests.cpp @@ -252,17 +252,18 @@ static void test_path(GrDrawTarget* dt, GrRenderTarget* rt, GrResourceProvider* tess.drawPath(args); } -DEF_GPUTEST_FOR_ALL_CONTEXTS(TessellatingPathRendererTests, reporter, context) { +DEF_GPUTEST_FOR_ALL_CONTEXTS(TessellatingPathRendererTests, reporter, ctxInfo) { GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fWidth = 800; desc.fHeight = 800; desc.fConfig = kSkia8888_GrPixelConfig; desc.fOrigin = kTopLeft_GrSurfaceOrigin; - SkAutoTUnref texture(context->textureProvider()->createApproxTexture(desc)); + SkAutoTUnref texture( + ctxInfo.fGrContext->textureProvider()->createApproxTexture(desc)); GrTestTarget tt; GrRenderTarget* rt = texture->asRenderTarget(); - context->getTestTarget(&tt, rt); + ctxInfo.fGrContext->getTestTarget(&tt, rt); GrDrawTarget* dt = tt.target(); GrResourceProvider* rp = tt.resourceProvider(); diff --git a/tests/Test.h b/tests/Test.h index 7430372e7d..de99fa53e0 100644 --- a/tests/Test.h +++ b/tests/Test.h @@ -11,11 +11,16 @@ #include "SkTRegistry.h" #include "SkTypes.h" +#if SK_SUPPORT_GPU +#include "GrContextFactory.h" +#else namespace sk_gpu_test { class GrContextFactory; +class ContextInfo; class GLTestContext; } // namespace sk_gpu_test class GrContext; +#endif namespace skiatest { @@ -83,9 +88,11 @@ enum GPUTestContexts { | kNull_GPUTestContexts | kDebug_GPUTestContexts }; -template -void RunWithGPUTestContexts(T testFunction, GPUTestContexts contexts, Reporter* reporter, - sk_gpu_test::GrContextFactory* factory); + +typedef void GrContextTestFn(Reporter*, const sk_gpu_test::ContextInfo&); + +void RunWithGPUTestContexts(GrContextTestFn* testFunction, GPUTestContexts contexts, + Reporter* reporter, sk_gpu_test::GrContextFactory* factory); /** Timer provides wall-clock duration since its creation. */ class Timer { @@ -141,38 +148,32 @@ private: skiatest::Test(#name, false, test_##name)); \ void test_##name(skiatest::Reporter* reporter, sk_gpu_test::GrContextFactory*) -#define GPUTEST_EXPAND_MSVC(x) x -#define GPUTEST_APPLY(C, ...) GPUTEST_EXPAND_MSVC(C(__VA_ARGS__)) -#define GPUTEST_SELECT(a1, a2, N, ...) N -#define GPUTEST_CONTEXT_ARGS1(a1) GrContext* a1 -#define GPUTEST_CONTEXT_ARGS2(a1, a2) GrContext* a1, sk_gpu_test::GLTestContext* a2 -#define GPUTEST_CONTEXT_ARGS(...) \ - GPUTEST_APPLY(GPUTEST_SELECT(__VA_ARGS__, GPUTEST_CONTEXT_ARGS2, GPUTEST_CONTEXT_ARGS1), \ - __VA_ARGS__) - -#define DEF_GPUTEST(name, reporter, factory) \ - static void test_##name(skiatest::Reporter*, sk_gpu_test::GrContextFactory*); \ - skiatest::TestRegistry name##TestRegistry( \ - skiatest::Test(#name, true, test_##name)); \ +#define DEF_GPUTEST(name, reporter, factory) \ + static void test_##name(skiatest::Reporter*, sk_gpu_test::GrContextFactory*); \ + skiatest::TestRegistry name##TestRegistry( \ + skiatest::Test(#name, true, test_##name)); \ void test_##name(skiatest::Reporter* reporter, sk_gpu_test::GrContextFactory* factory) -#define DEF_GPUTEST_FOR_CONTEXTS(name, contexts, reporter, ...) \ - static void test_##name(skiatest::Reporter*, GPUTEST_CONTEXT_ARGS(__VA_ARGS__)); \ - static void test_gpu_contexts_##name(skiatest::Reporter* reporter, \ - sk_gpu_test::GrContextFactory* factory) { \ - skiatest::RunWithGPUTestContexts(test_##name, contexts, reporter, factory); \ - } \ - skiatest::TestRegistry name##TestRegistry( \ - skiatest::Test(#name, true, test_gpu_contexts_##name)); \ - void test_##name(skiatest::Reporter* reporter, GPUTEST_CONTEXT_ARGS(__VA_ARGS__)) - -#define DEF_GPUTEST_FOR_ALL_CONTEXTS(name, reporter, ...) \ - DEF_GPUTEST_FOR_CONTEXTS(name, skiatest::kAll_GPUTestContexts, reporter, __VA_ARGS__) -#define DEF_GPUTEST_FOR_RENDERING_CONTEXTS(name, reporter, ...) \ - DEF_GPUTEST_FOR_CONTEXTS(name, skiatest::kAllRendering_GPUTestContexts, reporter, __VA_ARGS__) -#define DEF_GPUTEST_FOR_NULL_CONTEXT(name, reporter, ...) \ - DEF_GPUTEST_FOR_CONTEXTS(name, skiatest::kNull_GPUTestContexts, reporter, __VA_ARGS__) +#define DEF_GPUTEST_FOR_CONTEXTS(name, contexts, reporter, context_info) \ + static void test_##name(skiatest::Reporter*, \ + const sk_gpu_test::ContextInfo& context_info); \ + static void test_gpu_contexts_##name(skiatest::Reporter* reporter, \ + sk_gpu_test::GrContextFactory* factory) { \ + skiatest::RunWithGPUTestContexts(test_##name, contexts, reporter, factory); \ + } \ + skiatest::TestRegistry name##TestRegistry( \ + skiatest::Test(#name, true, test_gpu_contexts_##name)); \ + void test_##name(skiatest::Reporter* reporter, \ + const sk_gpu_test::ContextInfo& context_info) + +#define DEF_GPUTEST_FOR_ALL_CONTEXTS(name, reporter, context_info) \ + DEF_GPUTEST_FOR_CONTEXTS(name, skiatest::kAll_GPUTestContexts, reporter, context_info) +#define DEF_GPUTEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info) \ + DEF_GPUTEST_FOR_CONTEXTS(name, skiatest::kAllRendering_GPUTestContexts, reporter, \ + context_info) +#define DEF_GPUTEST_FOR_NULL_CONTEXT(name, reporter, context_info) \ + DEF_GPUTEST_FOR_CONTEXTS(name, skiatest::kNull_GPUTestContexts, reporter, context_info) #define REQUIRE_PDF_DOCUMENT(TEST_NAME, REPORTER) \ do { \ diff --git a/tests/TestTest.cpp b/tests/TestTest.cpp index 66c9b2df5c..7443ffe325 100644 --- a/tests/TestTest.cpp +++ b/tests/TestTest.cpp @@ -29,36 +29,26 @@ DEF_GPUTEST(TestGpuFactory, reporter, factory) { // This is an example of a GPU test that tests a property that should work for all GPU contexts. // Note: Some of the contexts might not produce a rendering output. #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_ALL_CONTEXTS(TestGpuAllContexts, reporter, context) { +DEF_GPUTEST_FOR_ALL_CONTEXTS(TestGpuAllContexts, reporter, ctxInfo) { REPORTER_ASSERT(reporter, reporter); - REPORTER_ASSERT(reporter, context); + REPORTER_ASSERT(reporter, ctxInfo.fGrContext); } #endif // This is an example of a GPU test that tests a property that should work for all GPU contexts that // produce a rendering output. #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContexts, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TestGpuRenderingContexts, reporter, ctxInfo) { REPORTER_ASSERT(reporter, reporter); - REPORTER_ASSERT(reporter, context); + REPORTER_ASSERT(reporter, ctxInfo.fGrContext); } #endif // This is an example of a GPU test that tests a property that uses the null GPU context. It should // be used if the test tests some behavior that is mocked with the null context. #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_NULL_CONTEXT(TestGpuNullContext, reporter, context) { +DEF_GPUTEST_FOR_NULL_CONTEXT(TestGpuNullContext, reporter, ctxInfo) { REPORTER_ASSERT(reporter, reporter); - REPORTER_ASSERT(reporter, context); -} -#endif - -// This is an example of a GPU test that tests a property that should work for all GPU contexts. -// It uses the additional GLTestContext* glContext to implement the test. -#if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_ALL_CONTEXTS(TestGpuGrContextAndGLContext, reporter, context, glContext) { - REPORTER_ASSERT(reporter, reporter); - REPORTER_ASSERT(reporter, context); - REPORTER_ASSERT(reporter, glContext); + REPORTER_ASSERT(reporter, ctxInfo.fGrContext); } #endif diff --git a/tests/TextBlobCacheTest.cpp b/tests/TextBlobCacheTest.cpp index 6ec32637cb..d13d251f36 100644 --- a/tests/TextBlobCacheTest.cpp +++ b/tests/TextBlobCacheTest.cpp @@ -156,19 +156,19 @@ static void text_blob_cache_inner(skiatest::Reporter* reporter, GrContext* conte draw(canvas, 1, blobs); } -DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobCache, reporter, context) { - text_blob_cache_inner(reporter, context, 1024, 256, 30, true, false); +DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobCache, reporter, ctxInfo) { + text_blob_cache_inner(reporter, ctxInfo.fGrContext, 1024, 256, 30, true, false); } -DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobStressCache, reporter, context) { - text_blob_cache_inner(reporter, context, 256, 256, 10, true, true); +DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobStressCache, reporter, ctxInfo) { + text_blob_cache_inner(reporter, ctxInfo.fGrContext, 256, 256, 10, true, true); } -DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobAbnormal, reporter, context) { - text_blob_cache_inner(reporter, context, 256, 256, 10, false, false); +DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobAbnormal, reporter, ctxInfo) { + text_blob_cache_inner(reporter, ctxInfo.fGrContext, 256, 256, 10, false, false); } -DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobStressAbnormal, reporter, context) { - text_blob_cache_inner(reporter, context, 256, 256, 10, false, true); +DEF_GPUTEST_FOR_NULL_CONTEXT(TextBlobStressAbnormal, reporter, ctxInfo) { + text_blob_cache_inner(reporter, ctxInfo.fGrContext, 256, 256, 10, false, true); } #endif diff --git a/tests/TextureStorageAllocator.cpp b/tests/TextureStorageAllocator.cpp index fbd00d32f6..433b365932 100644 --- a/tests/TextureStorageAllocator.cpp +++ b/tests/TextureStorageAllocator.cpp @@ -53,7 +53,9 @@ class TestStorageAllocator { bool m_allowAllocation; }; -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTexture, reporter, context, glContext) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTexture, reporter, ctxInfo) { + GrContext* context = ctxInfo.fGrContext; + sk_gpu_test::GLTestContext* glContext = ctxInfo.fGLContext; static const int kWidth = 13; static const int kHeight = 13; @@ -88,11 +90,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTexture, reporter, context, glContext) REPORTER_ASSERT(reporter, GrColorUnpackG(dest) == 255); } -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTextureFailure, reporter, context, glContext) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTextureFailure, reporter, ctxInfo) { static const int kWidth = 13; static const int kHeight = 13; - const GrGLInterface* gl = glContext->gl(); + const GrGLInterface* gl = ctxInfo.fGLContext->gl(); TestStorageAllocator allocator; allocator.m_allowAllocation = false; allocator.m_gl = gl; @@ -101,7 +103,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CustomTextureFailure, reporter, context, glCo grAllocator.fDeallocateTextureStorage= &TestStorageAllocator::deallocateTextureStorage; grAllocator.fCtx = &allocator; auto surface(SkSurface_Gpu::MakeRenderTarget( - context, SkBudgeted::kNo, SkImageInfo::MakeN32Premul(kWidth, kHeight), 0, + ctxInfo.fGrContext, SkBudgeted::kNo, SkImageInfo::MakeN32Premul(kWidth, kHeight), 0, NULL, grAllocator)); REPORTER_ASSERT(reporter, !surface); } diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp index 6dda6ff89e..669d885c96 100644 --- a/tests/WritePixelsTest.cpp +++ b/tests/WritePixelsTest.cpp @@ -406,7 +406,7 @@ DEF_TEST(WritePixels, reporter) { } } #if SK_SUPPORT_GPU -DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixels_Gpu, reporter, context) { +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixels_Gpu, reporter, ctxInfo) { for (auto& origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) { GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; @@ -414,8 +414,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixels_Gpu, reporter, context) { desc.fHeight = DEV_H; desc.fConfig = kSkia8888_GrPixelConfig; desc.fOrigin = origin; - SkAutoTUnref texture(context->textureProvider()->createTexture(desc, - SkBudgeted::kNo)); + SkAutoTUnref texture( + ctxInfo.fGrContext->textureProvider()->createTexture(desc, SkBudgeted::kNo)); auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget())); test_write_pixels(reporter, surface.get()); } diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp index 18fbef8113..f54aa90c6c 100755 --- a/tools/gpu/GrContextFactory.cpp +++ b/tools/gpu/GrContextFactory.cpp @@ -82,8 +82,7 @@ const GrContextFactory::ContextType GrContextFactory::kNativeGL_ContextType = GrContextFactory::kGLES_ContextType; #endif -GrContextFactory::ContextInfo GrContextFactory::getContextInfo(ContextType type, - ContextOptions options) { +ContextInfo GrContextFactory::getContextInfo(ContextType type, ContextOptions options) { for (int i = 0; i < fContexts.count(); ++i) { Context& context = fContexts[i]; if (!context.fGLContext) { diff --git a/tools/gpu/GrContextFactory.h b/tools/gpu/GrContextFactory.h index 7c49faaf87..fe82819580 100644 --- a/tools/gpu/GrContextFactory.h +++ b/tools/gpu/GrContextFactory.h @@ -15,6 +15,17 @@ #include "SkTArray.h" namespace sk_gpu_test { + +struct ContextInfo { + ContextInfo() + : fGrContext(nullptr), fGLContext(nullptr) { } + ContextInfo(GrContext* grContext, GLTestContext* glContext) + : fGrContext(grContext), fGLContext(glContext) { } + GrContext* fGrContext; + GLTestContext* fGLContext; //! Valid until the factory destroys it via abandonContexts() or + //! destroyContexts(). +}; + /** * This is a simple class that is useful in test apps that use different * GrContexts backed by different types of GL contexts. It manages creating the @@ -109,16 +120,6 @@ public: void abandonContexts(); void releaseResourcesAndAbandonContexts(); - struct ContextInfo { - ContextInfo() - : fGrContext(nullptr), fGLContext(nullptr) { } - ContextInfo(GrContext* grContext, GLTestContext* glContext) - : fGrContext(grContext), fGLContext(glContext) { } - GrContext* fGrContext; - GLTestContext* fGLContext; //! Valid until the factory destroys it via abandonContexts() or - //! destroyContexts(). - }; - /** * Get a context initialized with a type of GL context. It also makes the GL context current. */ -- cgit v1.2.3