From b25e0650ddd8997b85b1bb7609dd0c42fb5d8083 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Wed, 22 Jul 2020 09:35:49 -0400 Subject: [PATCH] Convert more tests to GrDirectContext/GrRecordingContext pair TBR=bsalomon@google.com Change-Id: I5bb78f4e36c4037669e7907cbe818da743480ef4 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305009 Reviewed-by: Adlai Holler Reviewed-by: Brian Salomon Commit-Queue: Robert Phillips --- include/gpu/GrContextThreadSafeProxy.h | 6 +- tests/GrTestingBackendTextureUploadTest.cpp | 33 +++--- tests/ImageFilterCacheTest.cpp | 16 +-- tests/ImageFilterTest.cpp | 5 +- tests/ImageNewShaderTest.cpp | 22 ++-- tests/ImageTest.cpp | 117 ++++++++++---------- tests/LazyProxyTest.cpp | 14 +-- tests/VkDrawableTest.cpp | 28 +++-- 8 files changed, 123 insertions(+), 118 deletions(-) diff --git a/include/gpu/GrContextThreadSafeProxy.h b/include/gpu/GrContextThreadSafeProxy.h index 8a92f8dedb..6515ab6db7 100644 --- a/include/gpu/GrContextThreadSafeProxy.h +++ b/include/gpu/GrContextThreadSafeProxy.h @@ -64,8 +64,10 @@ public: */ SkSurfaceCharacterization createCharacterization( size_t cacheMaxResourceBytes, - const SkImageInfo& ii, const GrBackendFormat& backendFormat, - int sampleCount, GrSurfaceOrigin origin, + const SkImageInfo& ii, + const GrBackendFormat& backendFormat, + int sampleCount, + GrSurfaceOrigin origin, const SkSurfaceProps& surfaceProps, bool isMipMapped, bool willUseGLFBO0 = false, diff --git a/tests/GrTestingBackendTextureUploadTest.cpp b/tests/GrTestingBackendTextureUploadTest.cpp index d57ffd75d2..c2718614fb 100644 --- a/tests/GrTestingBackendTextureUploadTest.cpp +++ b/tests/GrTestingBackendTextureUploadTest.cpp @@ -14,13 +14,9 @@ #include "tests/Test.h" #include "tests/TestUtils.h" -void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, SkColorType ct, - GrRenderable renderable, bool doDataUpload, GrMipmapped mipMapped) { - auto direct = context->asDirectContext(); - if (!direct) { - return; - } - +static void testing_only_texture_test(skiatest::Reporter* reporter, GrDirectContext* dContext, + SkColorType ct, GrRenderable renderable, bool doDataUpload, + GrMipmapped mipMapped) { const int kWidth = 16; const int kHeight = 16; @@ -30,11 +26,11 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, expectedPixels.alloc(ii); actualPixels.alloc(ii); - const GrCaps* caps = direct->priv().caps(); + const GrCaps* caps = dContext->priv().caps(); GrColorType grCT = SkColorTypeToGrColorType(ct); - GrBackendFormat backendFormat = direct->defaultBackendFormat(ct, renderable); + GrBackendFormat backendFormat = dContext->defaultBackendFormat(ct, renderable); if (!backendFormat.isValid()) { return; } @@ -46,11 +42,11 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, FillPixelData(kWidth, kHeight, expectedPixels.writable_addr32(0, 0)); - backendTex = direct->createBackendTexture(&expectedPixels, 1, - renderable, GrProtected::kNo); + backendTex = dContext->createBackendTexture(&expectedPixels, 1, + renderable, GrProtected::kNo); } else { - backendTex = direct->createBackendTexture(kWidth, kHeight, ct, SkColors::kTransparent, - mipMapped, renderable, GrProtected::kNo); + backendTex = dContext->createBackendTexture(kWidth, kHeight, ct, SkColors::kTransparent, + mipMapped, renderable, GrProtected::kNo); size_t allocSize = SkAutoPixmapStorage::AllocSize(ii, nullptr); // createBackendTexture will fill the texture with 0's if no data is provided, so @@ -69,23 +65,24 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, sk_sp wrappedProxy; if (GrRenderable::kYes == renderable) { - wrappedProxy = direct->priv().proxyProvider()->wrapRenderableBackendTexture( + wrappedProxy = dContext->priv().proxyProvider()->wrapRenderableBackendTexture( backendTex, 1, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, nullptr); } else { - wrappedProxy = direct->priv().proxyProvider()->wrapBackendTexture( + wrappedProxy = dContext->priv().proxyProvider()->wrapBackendTexture( backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, GrIOType::kRW_GrIOType); } REPORTER_ASSERT(reporter, wrappedProxy); - GrSwizzle swizzle = direct->priv().caps()->getReadSwizzle(wrappedProxy->backendFormat(), grCT); + GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(wrappedProxy->backendFormat(), + grCT); GrSurfaceProxyView view(std::move(wrappedProxy), kTopLeft_GrSurfaceOrigin, swizzle); - auto surfaceContext = GrSurfaceContext::Make(direct, std::move(view), grCT, + auto surfaceContext = GrSurfaceContext::Make(dContext, std::move(view), grCT, kPremul_SkAlphaType, nullptr); REPORTER_ASSERT(reporter, surfaceContext); bool result = surfaceContext->readPixels({grCT, kPremul_SkAlphaType, nullptr, kWidth, kHeight}, actualPixels.writable_addr(), actualPixels.rowBytes(), - {0, 0}, direct); + {0, 0}, dContext); REPORTER_ASSERT(reporter, result); REPORTER_ASSERT(reporter, diff --git a/tests/ImageFilterCacheTest.cpp b/tests/ImageFilterCacheTest.cpp index 160c0f7b06..c57cf853b8 100644 --- a/tests/ImageFilterCacheTest.cpp +++ b/tests/ImageFilterCacheTest.cpp @@ -174,15 +174,15 @@ DEF_TEST(ImageFilterCache_RasterBacked, reporter) { // Shared test code for both the raster and gpu-backed image cases static void test_image_backed(skiatest::Reporter* reporter, - GrContext* context, + GrRecordingContext* rContext, const sk_sp& srcImage) { const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize); - sk_sp fullImg(SkSpecialImage::MakeFromImage(context, full, srcImage)); + sk_sp fullImg(SkSpecialImage::MakeFromImage(rContext, full, srcImage)); const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); - sk_sp subsetImg(SkSpecialImage::MakeFromImage(context, subset, srcImage)); + sk_sp subsetImg(SkSpecialImage::MakeFromImage(rContext, subset, srcImage)); test_find_existing(reporter, fullImg, subsetImg); test_dont_find_if_diff_key(reporter, fullImg, subsetImg); @@ -214,14 +214,14 @@ static GrSurfaceProxyView create_proxy_view(GrRecordingContext* context) { } DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ctxInfo) { - auto context = ctxInfo.directContext(); + auto dContext = ctxInfo.directContext(); - GrSurfaceProxyView srcView = create_proxy_view(context); + GrSurfaceProxyView srcView = create_proxy_view(dContext); if (!srcView.proxy()) { return; } - if (!srcView.proxy()->instantiate(context->priv().resourceProvider())) { + if (!srcView.proxy()->instantiate(dContext->priv().resourceProvider())) { return; } GrTexture* tex = srcView.proxy()->peekTexture(); @@ -229,7 +229,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ct GrBackendTexture backendTex = tex->getBackendTexture(); GrSurfaceOrigin texOrigin = kTopLeft_GrSurfaceOrigin; - sk_sp srcImage(SkImage::MakeFromTexture(context, + sk_sp srcImage(SkImage::MakeFromTexture(dContext, backendTex, texOrigin, kRGBA_8888_SkColorType, @@ -251,7 +251,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ct } REPORTER_ASSERT(reporter, readBackOrigin == texOrigin); - test_image_backed(reporter, context, srcImage); + test_image_backed(reporter, dContext, srcImage); } DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, ctxInfo) { diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp index 855604e450..74ec8616df 100644 --- a/tests/ImageFilterTest.cpp +++ b/tests/ImageFilterTest.cpp @@ -587,7 +587,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterNegativeBlurSigma_Gpu, reporter, c test_negative_blur_sigma(reporter, ctxInfo.directContext()); } -static void test_morphology_radius_with_mirror_ctm(skiatest::Reporter* reporter, GrContext* context) { +static void test_morphology_radius_with_mirror_ctm(skiatest::Reporter* reporter, + GrRecordingContext* rContext) { // Check that SkMorphologyImageFilter maps the radius correctly when the // CTM contains a mirroring transform. static const int kWidth = 32, kHeight = 32; @@ -605,7 +606,7 @@ static void test_morphology_radius_with_mirror_ctm(skiatest::Reporter* reporter, paint); sk_sp image = SkImage::MakeFromBitmap(bitmap); sk_sp imgSrc( - SkSpecialImage::MakeFromImage(context, SkIRect::MakeWH(kWidth, kHeight), image)); + SkSpecialImage::MakeFromImage(rContext, SkIRect::MakeWH(kWidth, kHeight), image)); SkIPoint offset; SkImageFilter_Base::Context ctx(SkMatrix::I(), SkIRect::MakeWH(32, 32), nullptr, diff --git a/tests/ImageNewShaderTest.cpp b/tests/ImageNewShaderTest.cpp index f5c22f1e0a..3ac725a557 100644 --- a/tests/ImageNewShaderTest.cpp +++ b/tests/ImageNewShaderTest.cpp @@ -103,42 +103,42 @@ DEF_TEST(ImageNewShader, reporter) { run_shader_test(reporter, sourceSurface.get(), destinationSurface.get(), info); } -static void gpu_to_gpu(skiatest::Reporter* reporter, GrContext* context) { +static void gpu_to_gpu(skiatest::Reporter* reporter, GrRecordingContext* rContext) { SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); - auto sourceSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); - auto destinationSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); + auto sourceSurface(SkSurface::MakeRenderTarget(rContext, SkBudgeted::kNo, info)); + auto destinationSurface(SkSurface::MakeRenderTarget(rContext, SkBudgeted::kNo, info)); run_shader_test(reporter, sourceSurface.get(), destinationSurface.get(), info); } -static void gpu_to_raster(skiatest::Reporter* reporter, GrContext* context) { +static void gpu_to_raster(skiatest::Reporter* reporter, GrRecordingContext* rContext) { SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); - auto sourceSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); + auto sourceSurface(SkSurface::MakeRenderTarget(rContext, SkBudgeted::kNo, info)); auto destinationSurface(SkSurface::MakeRaster(info)); run_shader_test(reporter, sourceSurface.get(), destinationSurface.get(), info); } -static void raster_to_gpu(skiatest::Reporter* reporter, GrContext* context) { +static void raster_to_gpu(skiatest::Reporter* reporter, GrRecordingContext* rContext) { SkImageInfo info = SkImageInfo::MakeN32Premul(5, 5); auto sourceSurface(SkSurface::MakeRaster(info)); - auto destinationSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); + auto destinationSurface(SkSurface::MakeRenderTarget(rContext, SkBudgeted::kNo, info)); run_shader_test(reporter, sourceSurface.get(), destinationSurface.get(), info); } DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageNewShader_GPU, reporter, ctxInfo) { - auto context = ctxInfo.directContext(); + auto dContext = ctxInfo.directContext(); // GPU -> GPU - gpu_to_gpu(reporter, context); + gpu_to_gpu(reporter, dContext); // GPU -> RASTER - gpu_to_raster(reporter, context); + gpu_to_raster(reporter, dContext); // RASTER -> GPU - raster_to_gpu(reporter, context); + raster_to_gpu(reporter, dContext); } diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 382fa97df2..923b17ee5b 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -147,11 +147,11 @@ static sk_sp create_codec_image() { auto src = SkEncodeBitmap(bitmap, SkEncodedImageFormat::kPNG, 100); return SkImage::MakeFromEncoded(std::move(src)); } -static sk_sp create_gpu_image(GrContext* context, +static sk_sp create_gpu_image(GrRecordingContext* rContext, bool withMips = false, SkBudgeted budgeted = SkBudgeted::kYes) { const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); - auto surface = SkSurface::MakeRenderTarget(context, budgeted, info, 0, + auto surface = SkSurface::MakeRenderTarget(rContext, budgeted, info, 0, kBottomLeft_GrSurfaceOrigin, nullptr, withMips); draw_image_test_pattern(surface->getCanvas()); return surface->makeImageSnapshot(); @@ -372,7 +372,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_Gpu2Cpu, reporter, ctxInfo) { } DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextInfo) { - auto context = contextInfo.directContext(); + auto dContext = contextInfo.directContext(); sk_gpu_test::TestContext* testContext = contextInfo.testContext(); GrContextFactory otherFactory; ContextInfo otherContextInfo = otherFactory.getContextInfo(contextInfo.type()); @@ -383,8 +383,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextIn // Create an image from a picture. create_picture_image, // Create a texture image. - [context] { return create_gpu_image(context, true, SkBudgeted::kYes); }, - [context] { return create_gpu_image(context, false, SkBudgeted::kNo); }, + [dContext] { return create_gpu_image(dContext, true, SkBudgeted::kYes); }, + [dContext] { return create_gpu_image(dContext, false, SkBudgeted::kNo); }, // Create a texture image in a another GrContext. [otherContextInfo] { auto restore = otherContextInfo.testContext()->makeCurrentAndAutoRestore(); @@ -405,11 +405,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextIn SkASSERT(origProxy); } for (auto budgeted : {SkBudgeted::kNo, SkBudgeted::kYes}) { - auto texImage = image->makeTextureImage(context, mipMapped, budgeted); + auto texImage = image->makeTextureImage(dContext, mipMapped, budgeted); if (!texImage) { GrContext* imageContext = as_IB(image)->context(); // We expect to fail if image comes from a different GrContext - if (!image->isTextureBacked() || imageContext == context) { + if (!image->isTextureBacked() || imageContext == dContext) { ERRORF(reporter, "makeTextureImage failed."); } continue; @@ -421,7 +421,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextIn GrTextureProxy* copyProxy = as_IB(texImage)->peekProxy()->asTextureProxy(); SkASSERT(copyProxy); bool shouldBeMipped = - mipMapped == GrMipmapped::kYes && context->priv().caps()->mipmapSupport(); + mipMapped == GrMipmapped::kYes && dContext->priv().caps()->mipmapSupport(); if (shouldBeMipped && copyProxy->mipmapped() == GrMipmapped::kNo) { ERRORF(reporter, "makeTextureImage returned non-mipmapped texture."); continue; @@ -445,7 +445,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextIn } } } - context->flushAndSubmit(); + dContext->flushAndSubmit(); } DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeNonTextureImage, reporter, contextInfo) { @@ -856,20 +856,20 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c static void test_cross_context_image(skiatest::Reporter* reporter, const GrContextOptions& options, const char* testName, - std::function(GrContext*)> imageMaker) { + std::function(GrDirectContext*)> imageMaker) { for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { GrContextFactory testFactory(options); GrContextFactory::ContextType ctxType = static_cast(i); ContextInfo ctxInfo = testFactory.getContextInfo(ctxType); - auto ctx = ctxInfo.directContext(); - if (!ctx) { + auto dContext = ctxInfo.directContext(); + if (!dContext) { continue; } // If we don't have proper support for this feature, the factory will fallback to returning // codec-backed images. Those will "work", but some of our checks will fail because we // expect the cross-context images not to work on multiple contexts at once. - if (!ctx->priv().caps()->crossContextTextureSupport()) { + if (!dContext->priv().caps()->crossContextTextureSupport()) { continue; } @@ -883,12 +883,12 @@ static void test_cross_context_image(skiatest::Reporter* reporter, const GrConte // Case #1: Create image, free image { - sk_sp refImg(imageMaker(ctx)); + sk_sp refImg(imageMaker(dContext)); refImg.reset(nullptr); // force a release of the image } SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); - sk_sp surface = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info); + sk_sp surface = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info); if (!surface) { ERRORF(reporter, "SkSurface::MakeRenderTarget failed for %s.", testName); continue; @@ -898,7 +898,7 @@ static void test_cross_context_image(skiatest::Reporter* reporter, const GrConte // Case #2: Create image, draw, flush, free image { - sk_sp refImg(imageMaker(ctx)); + sk_sp refImg(imageMaker(dContext)); canvas->drawImage(refImg, 0, 0); surface->flushAndSubmit(); @@ -908,7 +908,7 @@ static void test_cross_context_image(skiatest::Reporter* reporter, const GrConte // Case #3: Create image, draw, free image, flush { - sk_sp refImg(imageMaker(ctx)); + sk_sp refImg(imageMaker(dContext)); canvas->drawImage(refImg, 0, 0); refImg.reset(nullptr); // force a release of the image @@ -919,7 +919,7 @@ static void test_cross_context_image(skiatest::Reporter* reporter, const GrConte // Configure second context sk_gpu_test::TestContext* testContext = ctxInfo.testContext(); - ContextInfo otherContextInfo = testFactory.getSharedContextInfo(ctx); + ContextInfo otherContextInfo = testFactory.getSharedContextInfo(dContext); auto otherCtx = otherContextInfo.directContext(); sk_gpu_test::TestContext* otherTestContext = otherContextInfo.testContext(); @@ -934,7 +934,7 @@ static void test_cross_context_image(skiatest::Reporter* reporter, const GrConte // Case #4: Create image, draw*, flush*, free image { testContext->makeCurrent(); - sk_sp refImg(imageMaker(ctx)); + sk_sp refImg(imageMaker(dContext)); otherTestContext->makeCurrent(); canvas->drawImage(refImg, 0, 0); @@ -947,7 +947,7 @@ static void test_cross_context_image(skiatest::Reporter* reporter, const GrConte // Case #5: Create image, draw*, free image, flush* { testContext->makeCurrent(); - sk_sp refImg(imageMaker(ctx)); + sk_sp refImg(imageMaker(dContext)); otherTestContext->makeCurrent(); canvas->drawImage(refImg, 0, 0); @@ -969,10 +969,10 @@ static void test_cross_context_image(skiatest::Reporter* reporter, const GrConte GrRecordingContextPriv::AutoSuppressWarningMessages aswm(otherCtx); testContext->makeCurrent(); - sk_sp refImg(imageMaker(ctx)); + sk_sp refImg(imageMaker(dContext)); // Any context should be able to borrow the texture at this point - GrSurfaceProxyView view = as_IB(refImg)->refView(ctx, GrMipmapped::kNo); + GrSurfaceProxyView view = as_IB(refImg)->refView(dContext, GrMipmapped::kNo); REPORTER_ASSERT(reporter, view); // But once it's borrowed, no other context should be able to borrow @@ -982,7 +982,7 @@ static void test_cross_context_image(skiatest::Reporter* reporter, const GrConte // Original context (that's already borrowing) should be okay testContext->makeCurrent(); - GrSurfaceProxyView viewSecondRef = as_IB(refImg)->refView(ctx, GrMipmapped::kNo); + GrSurfaceProxyView viewSecondRef = as_IB(refImg)->refView(dContext, GrMipmapped::kNo); REPORTER_ASSERT(reporter, viewSecondRef); // Release first ref from the original context @@ -1018,8 +1018,8 @@ DEF_GPUTEST(SkImage_MakeCrossContextFromPixmapRelease, reporter, options) { return; } test_cross_context_image(reporter, options, "SkImage_MakeCrossContextFromPixmapRelease", - [&pixmap](GrContext* ctx) { - return SkImage::MakeCrossContextFromPixmap(ctx, pixmap, false); + [&pixmap](GrDirectContext* dContext) { + return SkImage::MakeCrossContextFromPixmap(dContext, pixmap, false); }); } @@ -1351,7 +1351,7 @@ DEF_TEST(Image_nonfinite_dst, reporter) { } } -static sk_sp make_yuva_image(GrContext* c) { +static sk_sp make_yuva_image(GrDirectContext* dContext) { SkAutoPixmapStorage pm; pm.alloc(SkImageInfo::Make(1, 1, kAlpha_8_SkColorType, kPremul_SkAlphaType)); const SkPixmap pmaps[] = {pm, pm, pm, pm}; @@ -1360,14 +1360,14 @@ static sk_sp make_yuva_image(GrContext* c) { {2, SkColorChannel::kA}, {3, SkColorChannel::kA}}; - return SkImage::MakeFromYUVAPixmaps(c, kJPEG_SkYUVColorSpace, pmaps, indices, + return SkImage::MakeFromYUVAPixmaps(dContext, kJPEG_SkYUVColorSpace, pmaps, indices, SkISize::Make(1, 1), kTopLeft_GrSurfaceOrigin, false); } DEF_GPUTEST_FOR_ALL_CONTEXTS(ImageFlush, reporter, ctxInfo) { - auto direct = ctxInfo.directContext(); + auto dContext = ctxInfo.directContext(); auto ii = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType); - auto s = SkSurface::MakeRenderTarget(direct, SkBudgeted::kYes, ii, 1, nullptr); + auto s = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kYes, ii, 1, nullptr); s->getCanvas()->clear(SK_ColorRED); auto i0 = s->makeImageSnapshot(); @@ -1375,58 +1375,59 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(ImageFlush, reporter, ctxInfo) { auto i1 = s->makeImageSnapshot(); s->getCanvas()->clear(SK_ColorGREEN); // Make a YUVA image. - auto i2 = make_yuva_image(direct); + auto i2 = make_yuva_image(dContext); // Flush all the setup work we did above and then make little lambda that reports the flush // count delta since the last time it was called. - direct->flushAndSubmit(); - auto numSubmits = [direct, - submitCnt = direct->priv().getGpu()->stats()->numSubmitToGpus()]() mutable { - int curr = direct->priv().getGpu()->stats()->numSubmitToGpus(); + dContext->flushAndSubmit(); + auto numSubmits = + [dContext, + submitCnt = dContext->priv().getGpu()->stats()->numSubmitToGpus()]() mutable { + int curr = dContext->priv().getGpu()->stats()->numSubmitToGpus(); int n = curr - submitCnt; submitCnt = curr; return n; }; // Images aren't used therefore flush is ignored, but submit is still called. - i0->flushAndSubmit(direct); - i1->flushAndSubmit(direct); - i2->flushAndSubmit(direct); + i0->flushAndSubmit(dContext); + i1->flushAndSubmit(dContext); + i2->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 3); // Syncing forces the flush to happen even if the images aren't used. - i0->flush(direct); - direct->submit(true); + i0->flush(dContext); + dContext->submit(true); REPORTER_ASSERT(reporter, numSubmits() == 1); - i1->flush(direct); - direct->submit(true); + i1->flush(dContext); + dContext->submit(true); REPORTER_ASSERT(reporter, numSubmits() == 1); - i2->flush(direct); - direct->submit(true); + i2->flush(dContext); + dContext->submit(true); REPORTER_ASSERT(reporter, numSubmits() == 1); // Use image 1 s->getCanvas()->drawImage(i1, 0, 0); // Flushing image 0 should do nothing, but submit is still called. - i0->flushAndSubmit(direct); + i0->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 1); // Flushing image 1 should flush. - i1->flushAndSubmit(direct); + i1->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 1); // Flushing image 2 should do nothing, but submit is still called. - i2->flushAndSubmit(direct); + i2->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 1); // Use image 2 s->getCanvas()->drawImage(i2, 0, 0); // Flushing image 0 should do nothing, but submit is still called. - i0->flushAndSubmit(direct); + i0->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 1); // Flushing image 1 do nothing, but submit is still called. - i1->flushAndSubmit(direct); + i1->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 1); // Flushing image 2 should flush. - i2->flushAndSubmit(direct); + i2->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 1); // Since we just did a simple image draw it should not have been flattened. REPORTER_ASSERT(reporter, @@ -1434,41 +1435,41 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(ImageFlush, reporter, ctxInfo) { REPORTER_ASSERT(reporter, static_cast(as_IB(i2.get()))->isTextureBacked()); // Flatten it and repeat. - as_IB(i2.get())->view(direct); + as_IB(i2.get())->view(dContext); REPORTER_ASSERT(reporter, static_cast(as_IB(i2.get()))->testingOnly_IsFlattened()); REPORTER_ASSERT(reporter, static_cast(as_IB(i2.get()))->isTextureBacked()); s->getCanvas()->drawImage(i2, 0, 0); // Flushing image 0 should do nothing, but submit is still called. - i0->flushAndSubmit(direct); + i0->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 1); // Flushing image 1 do nothing, but submit is still called. - i1->flushAndSubmit(direct); + i1->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 1); // Flushing image 2 should flush. - i2->flushAndSubmit(direct); + i2->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 1); // Test case where flatten happens before the first flush. - i2 = make_yuva_image(direct); + i2 = make_yuva_image(dContext); // On some systems where preferVRAMUseOverFlushes is false (ANGLE on Windows) the above may // actually flush in order to make textures for the YUV planes. TODO: Remove this when we // make the YUVA planes from backend textures rather than pixmaps that GrContext must upload. // Calling numSubmits rebases the flush count from here. numSubmits(); - as_IB(i2.get())->view(direct); + as_IB(i2.get())->view(dContext); REPORTER_ASSERT(reporter, static_cast(as_IB(i2.get()))->testingOnly_IsFlattened()); REPORTER_ASSERT(reporter, static_cast(as_IB(i2.get()))->isTextureBacked()); s->getCanvas()->drawImage(i2, 0, 0); // Flushing image 0 should do nothing, but submit is still called. - i0->flushAndSubmit(direct); + i0->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 1); // Flushing image 1 do nothing, but submit is still called. - i1->flushAndSubmit(direct); + i1->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 1); // Flushing image 2 should flush, but submit is still called. - i2->flushAndSubmit(direct); + i2->flushAndSubmit(dContext); REPORTER_ASSERT(reporter, numSubmits() == 1); } diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp index e4626c2967..9882feee75 100644 --- a/tests/LazyProxyTest.cpp +++ b/tests/LazyProxyTest.cpp @@ -303,13 +303,14 @@ class LazyFailedInstantiationTestOp : public GrDrawOp { public: DEFINE_OP_CLASS_ID - static std::unique_ptr Make(GrContext* context, + static std::unique_ptr Make(GrRecordingContext* rContext, GrProxyProvider* proxyProvider, int* testExecuteValue, bool shouldFailInstantiation) { - GrOpMemoryPool* pool = context->priv().opMemoryPool(); + GrOpMemoryPool* pool = rContext->priv().opMemoryPool(); - return pool->allocate(context, proxyProvider, + return pool->allocate(rContext->priv().caps(), + proxyProvider, testExecuteValue, shouldFailInstantiation); } @@ -321,14 +322,13 @@ public: private: friend class GrOpMemoryPool; // for ctor - LazyFailedInstantiationTestOp(GrContext* ctx, GrProxyProvider* proxyProvider, + LazyFailedInstantiationTestOp(const GrCaps* caps, GrProxyProvider* proxyProvider, int* testExecuteValue, bool shouldFailInstantiation) : INHERITED(ClassID()) , fTestExecuteValue(testExecuteValue) { SkISize dims = {kSize, kSize}; - GrBackendFormat format = - ctx->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, - GrRenderable::kNo); + GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, + GrRenderable::kNo); fLazyProxy = proxyProvider->createLazyProxy( [testExecuteValue, shouldFailInstantiation]( diff --git a/tests/VkDrawableTest.cpp b/tests/VkDrawableTest.cpp index d3e6e8fd36..b1214fc445 100644 --- a/tests/VkDrawableTest.cpp +++ b/tests/VkDrawableTest.cpp @@ -32,10 +32,11 @@ static const int DEV_W = 16, DEV_H = 16; class TestDrawable : public SkDrawable { public: - TestDrawable(const GrVkInterface* interface, GrContext* context, int32_t width, int32_t height) + TestDrawable(const GrVkInterface* interface, GrDirectContext* dContext, + int32_t width, int32_t height) : INHERITED() , fInterface(interface) - , fContext(context) + , fDContext(dContext) , fWidth(width) , fHeight(height) {} @@ -134,7 +135,8 @@ public: // GrContext using a GrVkSecondaryCBDrawContext. static void ImportDraw(TestDrawable* td, const SkMatrix& matrix, const SkIRect& clipBounds, const SkImageInfo& bufferInfo, const GrVkDrawableInfo& info) { - td->fDrawContext = GrVkSecondaryCBDrawContext::Make(td->fContext, bufferInfo, info, nullptr); + td->fDrawContext = GrVkSecondaryCBDrawContext::Make(td->fDContext, bufferInfo, + info, nullptr); if (!td->fDrawContext) { return; } @@ -150,7 +152,7 @@ public: // Draw to an offscreen target so that we end up with a mix of "real" secondary command // buffers and the imported secondary command buffer. - sk_sp surf = SkSurface::MakeRenderTarget(td->fContext, SkBudgeted::kYes, + sk_sp surf = SkSurface::MakeRenderTarget(td->fDContext, SkBudgeted::kYes, bufferInfo); surf->getCanvas()->clear(SK_ColorRED); @@ -168,7 +170,7 @@ public: // on before releasing the GrVkSecondaryCBDrawContext resources. To simulate that for this // test (and since we are running single threaded anyways), we will just force a sync of // the gpu and cpu here. - td->fContext->priv().getGpu()->testingOnly_flushGpuAndSync(); + td->fDContext->priv().getGpu()->testingOnly_flushGpuAndSync(); td->fDrawContext->releaseResources(); // We release the GrContext here manually to test that we waited long enough before @@ -177,7 +179,7 @@ public: // GrContext's resources earlier (before waiting on the gpu above), we would get vulkan // validation layer errors saying we freed some vulkan objects while they were still in use // on the GPU. - td->fContext->releaseResourcesAndAbandonContext(); + td->fDContext->releaseResourcesAndAbandonContext(); } @@ -189,7 +191,7 @@ public: return nullptr; } std::unique_ptr draw; - if (fContext) { + if (fDContext) { draw.reset(new DrawHandlerImport(this, ImportDraw, ImportSubmitted, matrix, clipBounds, bufferInfo)); } else { @@ -208,7 +210,7 @@ public: private: const GrVkInterface* fInterface; - GrContext* fContext; + GrDirectContext* fDContext; sk_sp fDrawContext; int32_t fWidth; int32_t fHeight; @@ -216,17 +218,19 @@ private: typedef SkDrawable INHERITED; }; -void draw_drawable_test(skiatest::Reporter* reporter, GrContext* context, GrContext* childContext) { - GrVkGpu* gpu = static_cast(context->priv().getGpu()); +void draw_drawable_test(skiatest::Reporter* reporter, + GrDirectContext* dContext, + GrDirectContext* childDContext) { + GrVkGpu* gpu = static_cast(dContext->priv().getGpu()); const SkImageInfo ii = SkImageInfo::Make(DEV_W, DEV_H, kRGBA_8888_SkColorType, kPremul_SkAlphaType); - sk_sp surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, + sk_sp surface(SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, ii, 0, kTopLeft_GrSurfaceOrigin, nullptr)); SkCanvas* canvas = surface->getCanvas(); canvas->clear(SK_ColorBLUE); - sk_sp drawable(new TestDrawable(gpu->vkInterface(), childContext, DEV_W, DEV_H)); + sk_sp drawable(new TestDrawable(gpu->vkInterface(), childDContext, DEV_W, DEV_H)); canvas->drawDrawable(drawable.get()); SkPaint paint;