From 4efaf5e9feada3eddf286fb362f60d3b11a24e34 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Mon, 12 Oct 2020 21:30:00 +0000 Subject: [PATCH] Reland "Revert "Use ManagedBackendTexture in place of TestUtils backend texture helpers."" This reverts commit 21f8b5109951b16ff327f39072d7b5b141ac5c09. Reason for revert: D3D traced resource assert from unit test Original change's description: > Revert "Revert "Use ManagedBackendTexture in place of TestUtils backend texture helpers."" > > This reverts commit f625e4ce4504facbf0cfa210f8d9770b8431cdd9. > > Change-Id: Id73c53ec7ab8d4a5951712dc150d86e6349addbf > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325658 > Reviewed-by: Greg Daniel > Commit-Queue: Brian Salomon TBR=egdaniel@google.com,bsalomon@google.com # Not skipping CQ checks because this is a reland. Change-Id: I407f1d522d5c4f28d070cc2ce87af7faffca11fd Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325860 Reviewed-by: Brian Salomon Commit-Queue: Brian Salomon --- dm/DMSrcSink.cpp | 8 +- tests/DeferredDisplayListTest.cpp | 43 +++--- tests/EGLImageTest.cpp | 41 ++--- tests/GrMipMappedTest.cpp | 116 ++++++++------ tests/GrPorterDuffTest.cpp | 16 +- tests/GrSurfaceTest.cpp | 83 +++++----- tests/ImageTest.cpp | 51 +++---- tests/PromiseImageTest.cpp | 51 +++---- tests/ProxyTest.cpp | 56 +++---- tests/ResourceAllocatorTest.cpp | 38 +++-- tests/ResourceCacheTest.cpp | 48 +++--- tests/SurfaceTest.cpp | 183 +++++++++++++++-------- tests/TestUtils.cpp | 62 ++++++++ tests/TestUtils.h | 24 +++ tests/TextureProxyTest.cpp | 46 +++--- tests/VkBackendSurfaceTest.cpp | 69 ++++----- tests/VkWrapTests.cpp | 162 +++++++++++--------- tools/fm/fm.cpp | 8 +- tools/gpu/BackendSurfaceFactory.cpp | 93 ++++-------- tools/gpu/BackendSurfaceFactory.h | 15 -- tools/gpu/BackendTextureImageFactory.cpp | 32 ---- tools/gpu/BackendTextureImageFactory.h | 18 +-- tools/gpu/ManagedBackendTexture.cpp | 67 +-------- tools/gpu/ManagedBackendTexture.h | 35 +---- tools/gpu/vk/VkTestHelper.cpp | 6 - 25 files changed, 699 insertions(+), 672 deletions(-) diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index aeb3946bca..1ac89a6f15 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -1482,18 +1482,22 @@ sk_sp GPUSink::createDstSurface(GrDirectContext* context, SkISize siz break; case SkCommandLineConfigGpu::SurfType::kBackendTexture: surface = sk_gpu_test::MakeBackendTextureSurface(context, - info, + info.dimensions(), kTopLeft_GrSurfaceOrigin, fSampleCount, + info.colorType(), + info.refColorSpace(), GrMipmapped::kNo, GrProtected::kNo, &props); break; case SkCommandLineConfigGpu::SurfType::kBackendRenderTarget: surface = sk_gpu_test::MakeBackendRenderTargetSurface(context, - info, + info.dimensions(), kBottomLeft_GrSurfaceOrigin, fSampleCount, + info.colorType(), + info.refColorSpace(), GrProtected::kNo, &props); break; diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp index 6e78cb69dd..f4b4494a29 100644 --- a/tests/DeferredDisplayListTest.cpp +++ b/tests/DeferredDisplayListTest.cpp @@ -44,7 +44,6 @@ #include "tests/TestUtils.h" #include "tools/gpu/BackendSurfaceFactory.h" #include "tools/gpu/GrContextFactory.h" -#include "tools/gpu/ManagedBackendTexture.h" #include #include @@ -788,14 +787,10 @@ enum class DDLStage { kMakeImage, kDrawImage, kDetach, kDrawDDL }; DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) { auto dContext = ctxInfo.directContext(); - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext, - kSize, - kSize, - kRGBA_8888_SkColorType, - GrMipmapped::kNo, - GrRenderable::kNo, - GrProtected::kNo); - if (!mbet) { + GrBackendTexture backendTex; + CreateBackendTexture(dContext, &backendTex, kSize, kSize, kRGBA_8888_SkColorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo); + if (!backendTex.isValid()) { return; } @@ -803,6 +798,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) { sk_sp s = params.make(dContext); if (!s) { + dContext->deleteBackendTexture(backendTex); return; } @@ -816,21 +812,20 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) { auto rContext = canvas->recordingContext(); if (!rContext) { + s = nullptr; + dContext->deleteBackendTexture(backendTex); return; } // Wrapped Backend Textures are not supported in DDL TextureReleaseChecker releaseChecker; - sk_sp image = SkImage::MakeFromTexture( - rContext, - mbet->texture(), - kTopLeft_GrSurfaceOrigin, - kRGBA_8888_SkColorType, - kPremul_SkAlphaType, - nullptr, - sk_gpu_test::ManagedBackendTexture::ReleaseProc, - mbet->releaseContext(TextureReleaseChecker::Release, &releaseChecker)); + sk_sp image = + SkImage::MakeFromTexture(rContext, backendTex, kTopLeft_GrSurfaceOrigin, + kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr, + TextureReleaseChecker::Release, &releaseChecker); REPORTER_ASSERT(reporter, !image); + + dContext->deleteBackendTexture(backendTex); } static sk_sp dummy_fulfill_proc(void*) { @@ -994,14 +989,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSkSurfaceFlush, reporter, ctxInfo) { SkSurfaceCharacterization characterization; SkAssertResult(s->characterize(&characterization)); - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(context, ii); - if (!mbet) { - ERRORF(reporter, "Could not make texture."); + GrBackendTexture backendTexture; + + if (!CreateBackendTexture(context, &backendTexture, ii, SkColors::kCyan, GrMipmapped::kNo, + GrRenderable::kNo)) { + REPORTER_ASSERT(reporter, false); return; } FulfillInfo fulfillInfo; - fulfillInfo.fTex = SkPromiseImageTexture::Make(mbet->texture()); + fulfillInfo.fTex = SkPromiseImageTexture::Make(backendTexture); sk_sp ddl; @@ -1053,6 +1050,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLSkSurfaceFlush, reporter, ctxInfo) { REPORTER_ASSERT(reporter, fulfillInfo.fTex->unique()); fulfillInfo.fTex.reset(); + + DeleteBackendTexture(context, backendTexture); } //////////////////////////////////////////////////////////////////////////////// diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp index 34d3d57588..d1e75a8e3f 100644 --- a/tests/EGLImageTest.cpp +++ b/tests/EGLImageTest.cpp @@ -17,20 +17,22 @@ #include "tests/Test.h" #include "tests/TestUtils.h" #include "tools/gpu/GrContextFactory.h" -#include "tools/gpu/ManagedBackendTexture.h" #include "tools/gpu/gl/GLTestContext.h" #ifdef SK_GL using sk_gpu_test::GLTestContext; -static void cleanup(GLTestContext* glctx0, - GrGLuint texID0, - GLTestContext* glctx1, - sk_sp dContext, +static void cleanup(GLTestContext* glctx0, GrGLuint texID0, GLTestContext* glctx1, + sk_sp dContext, GrBackendTexture* backendTex1, GrEGLImage image1) { if (glctx1) { glctx1->makeCurrent(); + if (dContext) { + if (backendTex1 && backendTex1->isValid()) { + dContext->deleteBackendTexture(*backendTex1); + } + } if (GR_EGL_NO_IMAGE != image1) { glctx1->destroyEGLImage(image1); } @@ -62,18 +64,19 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { return; } sk_sp context1 = GrDirectContext::MakeGL(sk_ref_sp(glCtx1->gl())); + GrBackendTexture backendTexture1; GrEGLImage image = GR_EGL_NO_IMAGE; GrGLTextureInfo externalTexture; externalTexture.fID = 0; if (!context1) { - cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image); return; } if (!glCtx1->gl()->hasExtension("EGL_KHR_image") || !glCtx1->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) { - cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image); return; } @@ -83,25 +86,25 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { context1->flushAndSubmit(); static const int kSize = 100; - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( - context1.get(), kSize, kSize, kRGBA_8888_SkColorType, GrMipmapped::kNo, - GrRenderable::kNo, GrProtected::kNo); + CreateBackendTexture(context1.get(), &backendTexture1, kSize, kSize, kRGBA_8888_SkColorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, + GrProtected::kNo); - if (!mbet) { + if (!backendTexture1.isValid()) { ERRORF(reporter, "Error creating texture for EGL Image"); - cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image); return; } GrGLTextureInfo texInfo; - if (!mbet->texture().getGLTextureInfo(&texInfo)) { + if (!backendTexture1.getGLTextureInfo(&texInfo)) { ERRORF(reporter, "Failed to get GrGLTextureInfo"); return; } if (GR_GL_TEXTURE_2D != texInfo.fTarget) { ERRORF(reporter, "Expected backend texture to be 2D"); - cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image); return; } @@ -109,7 +112,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { image = glCtx1->texture2DToEGLImage(texInfo.fID); if (GR_EGL_NO_IMAGE == image) { ERRORF(reporter, "Error creating EGL Image from texture"); - cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image); return; } @@ -144,7 +147,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { externalTexture.fFormat = GR_GL_RGBA8; if (0 == externalTexture.fID) { ERRORF(reporter, "Error converting EGL Image back to texture"); - cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image); return; } @@ -160,7 +163,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType); if (!texProxy) { ERRORF(reporter, "Error wrapping external texture in GrTextureProxy."); - cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image); return; } GrSwizzle swizzle = @@ -171,7 +174,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { if (!surfaceContext) { ERRORF(reporter, "Error wrapping external texture in GrSurfaceContext."); - cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image); return; } @@ -203,7 +206,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { TestCopyFromSurface(reporter, context0, surfaceContext->asSurfaceProxy(), surfaceContext->origin(), colorType, pixels.get(), "EGLImageTest-copy"); - cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, image); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, &backendTexture1, image); } #endif // SK_GL diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp index 6a5199e7c0..ec90a81eb1 100644 --- a/tests/GrMipMappedTest.cpp +++ b/tests/GrMipMappedTest.cpp @@ -28,9 +28,6 @@ #include "src/image/SkSurface_Gpu.h" #include "tests/Test.h" #include "tests/TestUtils.h" -#include "tools/gpu/BackendSurfaceFactory.h" -#include "tools/gpu/BackendTextureImageFactory.h" -#include "tools/gpu/ManagedBackendTexture.h" static constexpr int kSize = 8; @@ -47,50 +44,42 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { // createBackendTexture currently doesn't support uploading data to mip maps // so we don't send any. However, we pretend there is data for the checks below which is // fine since we are never actually using these textures for any work on the gpu. - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithData(dContext, - kSize, - kSize, - kRGBA_8888_SkColorType, - SkColors::kTransparent, - mipMapped, - renderable, - GrProtected::kNo); + GrBackendTexture backendTex; + CreateBackendTexture(dContext, &backendTex, kSize, kSize, kRGBA_8888_SkColorType, + SkColors::kTransparent, mipMapped, renderable); sk_sp proxy; sk_sp image; if (GrRenderable::kYes == renderable) { sk_sp surface = SkSurface::MakeFromBackendTexture( - dContext, - mbet->texture(), - kTopLeft_GrSurfaceOrigin, - 0, - kRGBA_8888_SkColorType, - /*color space*/ nullptr, - /*surface props*/ nullptr, - sk_gpu_test::ManagedBackendTexture::ReleaseProc, - mbet->releaseContext()); + dContext, + backendTex, + kTopLeft_GrSurfaceOrigin, + 0, + kRGBA_8888_SkColorType, + nullptr, + nullptr); SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice(); proxy = device->accessRenderTargetContext()->asTextureProxyRef(); } else { - image = SkImage::MakeFromTexture(dContext, - mbet->texture(), + image = SkImage::MakeFromTexture(dContext, backendTex, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, - kPremul_SkAlphaType, - /* color space */ nullptr, - sk_gpu_test::ManagedBackendTexture::ReleaseProc, - mbet->releaseContext()); + kPremul_SkAlphaType, nullptr, + nullptr, nullptr); const GrSurfaceProxyView* view = as_IB(image)->view(dContext); REPORTER_ASSERT(reporter, view); if (!view) { - continue; + dContext->deleteBackendTexture(backendTex); + return; } proxy = view->asTextureProxyRef(); } REPORTER_ASSERT(reporter, proxy); if (!proxy) { - continue; + dContext->deleteBackendTexture(backendTex); + return; } REPORTER_ASSERT(reporter, proxy->isInstantiated()); @@ -98,7 +87,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { GrTexture* texture = proxy->peekTexture(); REPORTER_ASSERT(reporter, texture); if (!texture) { - continue; + dContext->deleteBackendTexture(backendTex); + return; } if (GrMipmapped::kYes == mipMapped) { @@ -111,6 +101,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) { } else { REPORTER_ASSERT(reporter, GrMipmapped::kNo == texture->mipmapped()); } + dContext->deleteBackendTexture(backendTex); } } } @@ -125,14 +116,20 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, for (auto betMipMapped : {GrMipmapped::kNo, GrMipmapped::kYes}) { for (auto requestMipMapped : {GrMipmapped::kNo, GrMipmapped::kYes}) { - auto ii = - SkImageInfo::Make({kSize, kSize}, kRGBA_8888_SkColorType, kPremul_SkAlphaType); - sk_sp image = sk_gpu_test::MakeBackendTextureImage( - dContext, ii, SkColors::kTransparent, betMipMapped); + GrBackendTexture backendTex; + CreateBackendTexture(dContext, &backendTex, kSize, kSize, kRGBA_8888_SkColorType, + SkColors::kTransparent, betMipMapped, GrRenderable::kNo); + + sk_sp image = SkImage::MakeFromTexture(dContext, backendTex, + kTopLeft_GrSurfaceOrigin, + kRGBA_8888_SkColorType, + kPremul_SkAlphaType, nullptr, + nullptr, nullptr); GrTextureProxy* proxy = as_IB(image)->peekProxy(); REPORTER_ASSERT(reporter, proxy); if (!proxy) { + dContext->deleteBackendTexture(backendTex); return; } @@ -141,6 +138,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, sk_sp texture = sk_ref_sp(proxy->peekTexture()); REPORTER_ASSERT(reporter, texture); if (!texture) { + dContext->deleteBackendTexture(backendTex); return; } @@ -149,6 +147,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, kPremul_SkAlphaType, nullptr); REPORTER_ASSERT(reporter, imageGen); if (!imageGen) { + dContext->deleteBackendTexture(backendTex); return; } @@ -161,6 +160,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, REPORTER_ASSERT(reporter, genProxy); if (!genProxy) { + dContext->deleteBackendTexture(backendTex); return; } @@ -172,16 +172,17 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, REPORTER_ASSERT(reporter, genProxy->isInstantiated()); if (!genProxy->isInstantiated()) { + dContext->deleteBackendTexture(backendTex); return; } GrTexture* genTexture = genProxy->peekTexture(); REPORTER_ASSERT(reporter, genTexture); if (!genTexture) { + dContext->deleteBackendTexture(backendTex); return; } - GrBackendTexture backendTex = texture->getBackendTexture(); GrBackendTexture genBackendTex = genTexture->getBackendTexture(); if (GrBackendApi::kOpenGL == genBackendTex.backend()) { @@ -251,6 +252,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, } else { REPORTER_ASSERT(reporter, false); } + + // Must make sure the uses of the backend texture have finished (we possibly have a + // queued up copy) before we delete the backend texture. + dContext->flushAndSubmit(); + + dContext->priv().getGpu()->testingOnly_flushGpuAndSync(); + + dContext->deleteBackendTexture(backendTex); } } } @@ -269,24 +278,28 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn for (auto isWrapped : {false, true}) { GrMipmapped mipMapped = willUseMips ? GrMipmapped::kYes : GrMipmapped::kNo; sk_sp surface; - SkImageInfo info = - SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType); + GrBackendTexture backendTex; + CreateBackendTexture(dContext, &backendTex, kSize, kSize, kRGBA_8888_SkColorType, + SkColors::kTransparent, mipMapped, GrRenderable::kYes); if (isWrapped) { - surface = sk_gpu_test::MakeBackendTextureSurface(dContext, - info, - kTopLeft_GrSurfaceOrigin, - /* sample count */ 1, - mipMapped); + surface = SkSurface::MakeFromBackendTexture(dContext, + backendTex, + kTopLeft_GrSurfaceOrigin, + 0, + kRGBA_8888_SkColorType, + nullptr, + nullptr); } else { - surface = SkSurface::MakeRenderTarget(dContext, - SkBudgeted::kYes, - info, - /* sample count */ 1, - kTopLeft_GrSurfaceOrigin, - nullptr, + SkImageInfo info = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, + kPremul_SkAlphaType); + surface = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kYes, info, 0, + kTopLeft_GrSurfaceOrigin, nullptr, willUseMips); } REPORTER_ASSERT(reporter, surface); + if (!surface) { + dContext->deleteBackendTexture(backendTex); + } SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice(); GrTextureProxy* texProxy = device->accessRenderTargetContext()->asTextureProxy(); REPORTER_ASSERT(reporter, mipMapped == texProxy->mipmapped()); @@ -297,12 +310,21 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn sk_sp image = surface->makeImageSnapshot(); REPORTER_ASSERT(reporter, image); + if (!image) { + dContext->deleteBackendTexture(backendTex); + } texProxy = as_IB(image)->peekProxy(); REPORTER_ASSERT(reporter, mipMapped == texProxy->mipmapped()); texProxy->instantiate(resourceProvider); texture = texProxy->peekTexture(); REPORTER_ASSERT(reporter, mipMapped == texture->mipmapped()); + + // Must flush the dContext to make sure all the cmds (copies, etc.) from above are sent + // to the gpu before we delete the backendHandle. + dContext->flushAndSubmit(); + dContext->priv().getGpu()->testingOnly_flushGpuAndSync(); + dContext->deleteBackendTexture(backendTex); } } } diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp index 9eb370dda2..5ed939edfe 100644 --- a/tests/GrPorterDuffTest.cpp +++ b/tests/GrPorterDuffTest.cpp @@ -17,8 +17,8 @@ #include "src/gpu/effects/GrPorterDuffXferProcessor.h" #include "src/gpu/gl/GrGLCaps.h" #include "src/gpu/ops/GrMeshDrawOp.h" +#include "tests/TestUtils.h" #include "tools/gpu/GrContextFactory.h" -#include "tools/gpu/ManagedBackendTexture.h" //////////////////////////////////////////////////////////////////////////////// @@ -999,15 +999,16 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, options) { SK_ABORT("Mock context failed to honor request for no ARB_blend_func_extended."); } - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( - ctx, 100, 100, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo); + GrBackendTexture backendTex; + CreateBackendTexture(ctx, &backendTex, 100, 100, kRGBA_8888_SkColorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo); + GrXferProcessor::DstProxyView fakeDstProxyView; { sk_sp proxy = proxyProvider->wrapBackendTexture( - mbet->texture(), kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType, - mbet->refCountedCallback()); - GrSwizzle swizzle = - caps.getReadSwizzle(mbet->texture().getBackendFormat(), GrColorType::kRGBA_8888); + backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); + GrSwizzle swizzle = caps.getReadSwizzle(backendTex.getBackendFormat(), + GrColorType::kRGBA_8888); fakeDstProxyView.setProxyView({std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle}); } @@ -1033,4 +1034,5 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, options) { } } } + ctx->deleteBackendTexture(backendTex); } diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index 05dd427014..ac488a2955 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -22,8 +22,6 @@ #include "src/gpu/GrTexture.h" #include "tests/Test.h" #include "tests/TestUtils.h" -#include "tools/gpu/BackendTextureImageFactory.h" -#include "tools/gpu/ManagedBackendTexture.h" // Tests that GrSurface::asTexture(), GrSurface::asRenderTarget(), and static upcasting of texture // and render targets to GrSurface all work as expected. @@ -359,11 +357,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) { // that they'd succeed if the texture wasn't kRead. We want to be sure we're failing with // kRead for the right reason. for (auto ioType : {kRead_GrIOType, kRW_GrIOType}) { - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithData( - dContext, srcPixmap, GrRenderable::kNo, GrProtected::kNo); - auto proxy = proxyProvider->wrapBackendTexture(mbet->texture(), kBorrow_GrWrapOwnership, - GrWrapCacheable::kNo, ioType, - mbet->refCountedCallback()); + auto backendTex = dContext->createBackendTexture(&srcPixmap, 1, + GrRenderable::kYes, GrProtected::kNo); + + auto proxy = proxyProvider->wrapBackendTexture( + backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, ioType); GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), GrColorType::kRGBA_8888); GrSurfaceProxyView view(proxy, kTopLeft_GrSurfaceOrigin, swizzle); @@ -417,45 +415,51 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) { // Mip regen should not work with a read only texture. if (dContext->priv().caps()->mipmapSupport()) { - mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext, - kSize, - kSize, - kRGBA_8888_SkColorType, - GrMipmapped::kYes, - GrRenderable::kNo, - GrProtected::kNo); - proxy = proxyProvider->wrapBackendTexture(mbet->texture(), kBorrow_GrWrapOwnership, - GrWrapCacheable::kNo, ioType, - mbet->refCountedCallback()); + DeleteBackendTexture(dContext, backendTex); + backendTex = dContext->createBackendTexture( + kSize, kSize, kRGBA_8888_SkColorType, + SkColors::kTransparent, GrMipmapped::kYes, GrRenderable::kYes, + GrProtected::kNo); + proxy = proxyProvider->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, + GrWrapCacheable::kNo, ioType); dContext->flushAndSubmit(); proxy->peekTexture()->markMipmapsDirty(); // avoids assert in GrGpu. auto regenResult = dContext->priv().getGpu()->regenerateMipMapLevels(proxy->peekTexture()); REPORTER_ASSERT(reporter, regenResult == (ioType == kRW_GrIOType)); } + DeleteBackendTexture(dContext, backendTex); } } static const int kSurfSize = 10; static sk_sp make_wrapped_texture(GrDirectContext* dContext, GrRenderable renderable) { - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( - dContext, kSurfSize, kSurfSize, kRGBA_8888_SkColorType, GrMipmapped::kNo, renderable); - SkASSERT(mbet); - sk_sp proxy; - if (renderable == GrRenderable::kYes) { - proxy = dContext->priv().proxyProvider()->wrapRenderableBackendTexture( - mbet->texture(), 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, - mbet->refCountedCallback()); + GrBackendTexture backendTexture; + CreateBackendTexture(dContext, &backendTexture, kSurfSize, kSurfSize, kRGBA_8888_SkColorType, + SkColors::kTransparent, GrMipmapped::kNo, renderable, GrProtected::kNo); + SkASSERT(backendTexture.isValid()); + sk_sp texture; + if (GrRenderable::kYes == renderable) { + texture = dContext->priv().resourceProvider()->wrapRenderableBackendTexture( + backendTexture, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo); } else { - proxy = dContext->priv().proxyProvider()->wrapBackendTexture( - mbet->texture(), kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType, - mbet->refCountedCallback()); + texture = dContext->priv().resourceProvider()->wrapBackendTexture( + backendTexture, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType); } - if (!proxy) { - return nullptr; - } - return sk_ref_sp(proxy->peekTexture()); + // Add a release proc that deletes the GrBackendTexture. + struct ReleaseContext { + GrDirectContext* fDContext; + GrBackendTexture fBackendTexture; + }; + auto release = [](void* rc) { + auto releaseContext = static_cast(rc); + auto dContext = releaseContext->fDContext; + dContext->deleteBackendTexture(releaseContext->fBackendTexture); + delete releaseContext; + }; + texture->setRelease(release, new ReleaseContext{dContext, backendTexture}); + return texture; } static sk_sp make_normal_texture(GrDirectContext* dContext, GrRenderable renderable) { @@ -773,11 +777,22 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(TextureIdleProcFlushTest, reporter, contextInfo) { // is a wrapped-texture backed image. surf->getCanvas()->clear(SK_ColorWHITE); auto img1 = surf->makeImageSnapshot(); - auto img2 = sk_gpu_test::MakeBackendTextureImage(dContext, info, SkColors::kBlack); - REPORTER_ASSERT(reporter, img1 && img2); + + GrBackendTexture backendTexture; + + if (!CreateBackendTexture(dContext, &backendTexture, info, SkColors::kBlack, + GrMipmapped::kNo, GrRenderable::kNo)) { + REPORTER_ASSERT(reporter, false); + continue; + } + + auto img2 = SkImage::MakeFromTexture(dContext, backendTexture, kTopLeft_GrSurfaceOrigin, + info.colorType(), info.alphaType(), nullptr); surf->getCanvas()->drawImage(std::move(img1), 0, 0); surf->getCanvas()->drawImage(std::move(img2), 1, 1); idleTexture.reset(); + + DeleteBackendTexture(dContext, backendTexture); } } } diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 92222bc5bf..2a9c4da959 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -36,9 +36,9 @@ #include "src/image/SkImage_Base.h" #include "src/image/SkImage_GpuYUVA.h" #include "tests/Test.h" +#include "tests/TestUtils.h" #include "tools/Resources.h" #include "tools/ToolUtils.h" -#include "tools/gpu/ManagedBackendTexture.h" using namespace sk_gpu_test; @@ -487,17 +487,19 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsImage, reporter SkColorType colorType = static_cast(ct); bool can = dContext->colorTypeSupportedAsImage(colorType); - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( - dContext, kSize, kSize, colorType, GrMipmapped::kNo, GrRenderable::kNo); - if (!mbet) { - ERRORF(reporter, "Could not create texture with color type %d.", colorType); - continue; - } - auto img = SkImage::MakeFromTexture(dContext, mbet->texture(), kTopLeft_GrSurfaceOrigin, + GrBackendTexture backendTex; + CreateBackendTexture(dContext, &backendTex, kSize, kSize, colorType, SkColors::kTransparent, + GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo); + + auto img = SkImage::MakeFromTexture(dContext, backendTex, kTopLeft_GrSurfaceOrigin, colorType, kOpaque_SkAlphaType, nullptr); REPORTER_ASSERT(reporter, can == SkToBool(img), "colorTypeSupportedAsImage:%d, actual:%d, ct:%d", can, SkToBool(img), colorType); + + img.reset(); + dContext->flushAndSubmit(); + dContext->deleteBackendTexture(backendTex); } } @@ -830,36 +832,27 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c auto dContext = ctxInfo.directContext(); - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext, - kWidth, - kHeight, - kRGBA_8888_SkColorType, - GrMipmapped::kNo, - GrRenderable::kNo, - GrProtected::kNo); - if (!mbet) { + SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, SkColorType::kRGBA_8888_SkColorType, + kPremul_SkAlphaType); + GrBackendTexture backendTex; + if (!CreateBackendTexture(dContext, &backendTex, ii, SkColors::kRed, GrMipmapped::kNo, + GrRenderable::kNo)) { ERRORF(reporter, "couldn't create backend texture\n"); } TextureReleaseChecker releaseChecker; GrSurfaceOrigin texOrigin = kBottomLeft_GrSurfaceOrigin; - sk_sp refImg = SkImage::MakeFromTexture( - dContext, - mbet->texture(), - texOrigin, - kRGBA_8888_SkColorType, - kPremul_SkAlphaType, - /*color space*/nullptr, - sk_gpu_test::ManagedBackendTexture::ReleaseProc, - mbet->releaseContext(TextureReleaseChecker::Release, &releaseChecker)); + sk_sp refImg( + SkImage::MakeFromTexture(dContext, backendTex, texOrigin, kRGBA_8888_SkColorType, + kPremul_SkAlphaType, nullptr, + TextureReleaseChecker::Release, &releaseChecker)); GrSurfaceOrigin readBackOrigin; GrBackendTexture readBackBackendTex = refImg->getBackendTexture(false, &readBackOrigin); - if (!GrBackendTexture::TestingOnly_Equals(readBackBackendTex, mbet->texture())) { + if (!GrBackendTexture::TestingOnly_Equals(readBackBackendTex, backendTex)) { ERRORF(reporter, "backend mismatch\n"); } - REPORTER_ASSERT(reporter, - GrBackendTexture::TestingOnly_Equals(readBackBackendTex, mbet->texture())); + REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(readBackBackendTex, backendTex)); if (readBackOrigin != texOrigin) { ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, texOrigin); } @@ -869,6 +862,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); refImg.reset(nullptr); // force a release of the image REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); + + DeleteBackendTexture(dContext, backendTex); } static void test_cross_context_image(skiatest::Reporter* reporter, const GrContextOptions& options, diff --git a/tests/PromiseImageTest.cpp b/tests/PromiseImageTest.cpp index 4b73db0514..126b44b43c 100644 --- a/tests/PromiseImageTest.cpp +++ b/tests/PromiseImageTest.cpp @@ -15,7 +15,7 @@ #include "src/gpu/GrGpu.h" #include "src/gpu/GrTexture.h" #include "src/image/SkImage_Gpu.h" -#include "tools/gpu/ManagedBackendTexture.h" +#include "tests/TestUtils.h" using namespace sk_gpu_test; @@ -270,37 +270,23 @@ DEF_GPUTEST(PromiseImageTextureShutdown, reporter, ctxInfo) { continue; } - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(ctx, - kWidth, - kHeight, - kAlpha_8_SkColorType, - GrMipmapped::kNo, - GrRenderable::kNo); - if (!mbet) { - ERRORF(reporter, "Could not create texture alpha texture."); - continue; - } + GrBackendTexture backendTex; + CreateBackendTexture(ctx, &backendTex, kWidth, kHeight, kAlpha_8_SkColorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, + GrProtected::kNo); + REPORTER_ASSERT(reporter, backendTex.isValid()); SkImageInfo info = SkImageInfo::Make(kWidth, kHeight, kRGBA_8888_SkColorType, kPremul_SkAlphaType); sk_sp surface = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info); SkCanvas* canvas = surface->getCanvas(); - PromiseTextureChecker promiseChecker(mbet->texture(), reporter, false); + PromiseTextureChecker promiseChecker(backendTex, reporter, false); sk_sp image(SkImage_Gpu::MakePromiseTexture( - ctx, - mbet->texture().getBackendFormat(), - kWidth, - kHeight, - GrMipmapped::kNo, - kTopLeft_GrSurfaceOrigin, - kAlpha_8_SkColorType, - kPremul_SkAlphaType, - /*color space*/ nullptr, - PromiseTextureChecker::Fulfill, - PromiseTextureChecker::Release, - PromiseTextureChecker::Done, - &promiseChecker, + ctx, backendTex.getBackendFormat(), kWidth, kHeight, GrMipmapped::kNo, + kTopLeft_GrSurfaceOrigin, kAlpha_8_SkColorType, kPremul_SkAlphaType, nullptr, + PromiseTextureChecker::Fulfill, PromiseTextureChecker::Release, + PromiseTextureChecker::Done, &promiseChecker, SkDeferredDisplayListRecorder::PromiseImageApiVersion::kNew)); REPORTER_ASSERT(reporter, image); @@ -391,12 +377,15 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PromiseImageNullFulfill, reporter, ctxInfo) { auto dContext = ctxInfo.directContext(); - GrBackendFormat backendFormat = - dContext->defaultBackendFormat(kRGBA_8888_SkColorType, GrRenderable::kYes); - if (!backendFormat.isValid()) { - ERRORF(reporter, "No valid default kRGBA_8888 texture format."); - return; - } + // Do all this just to get a valid backend format for the image. + GrBackendTexture backendTex; + CreateBackendTexture(dContext, &backendTex, kWidth, kHeight, kRGBA_8888_SkColorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kYes, + GrProtected::kNo); + REPORTER_ASSERT(reporter, backendTex.isValid()); + GrBackendFormat backendFormat = backendTex.getBackendFormat(); + REPORTER_ASSERT(reporter, backendFormat.isValid()); + dContext->deleteBackendTexture(backendTex); struct Counts { int fFulfillCount = 0; diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp index 09de88b773..0c1f72a50b 100644 --- a/tests/ProxyTest.cpp +++ b/tests/ProxyTest.cpp @@ -7,6 +7,8 @@ // This is a GPU-backend specific test. +#include "tests/Test.h" + #include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrDirectContext.h" #include "src/gpu/GrContextPriv.h" @@ -20,8 +22,6 @@ #include "src/gpu/GrTexture.h" #include "src/gpu/GrTextureProxy.h" #include "src/gpu/SkGr.h" -#include "tests/Test.h" -#include "tools/gpu/ManagedBackendTexture.h" #ifdef SK_GL #include "src/gpu/gl/GrGLDefines.h" #include "src/gpu/gl/GrGLUtil.h" @@ -265,57 +265,47 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { // Tests wrapBackendTexture that is only renderable { - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(direct, - kWidthHeight, - kWidthHeight, - colorType, - GrMipmapped::kNo, - GrRenderable::kYes); - if (!mbet) { - ERRORF(reporter, - "Could not create renderable backend texture of color type %d", - colorType); - continue; - } + GrBackendTexture backendTex; + CreateBackendTexture(direct, &backendTex, kWidthHeight, kWidthHeight, colorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kYes, + GrProtected::kNo); + sk_sp sProxy = proxyProvider->wrapRenderableBackendTexture( - mbet->texture(), supportedNumSamples, kBorrow_GrWrapOwnership, + backendTex, supportedNumSamples, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, nullptr); if (!sProxy) { - ERRORF(reporter, "wrapRenderableBackendTexture failed"); - continue; + direct->deleteBackendTexture(backendTex); + continue; // This can fail on Mesa } check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo); check_rendertarget(reporter, caps, resourceProvider, sProxy->asRenderTargetProxy(), supportedNumSamples, SkBackingFit::kExact, caps.maxWindowRectangles()); + + direct->deleteBackendTexture(backendTex); } + // Tests wrapBackendTexture that is only textureable { - // Tests wrapBackendTexture that is only textureable - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(direct, - kWidthHeight, - kWidthHeight, - colorType, - GrMipmapped::kNo, - GrRenderable::kNo); - if (!mbet) { - ERRORF(reporter, - "Could not create non-renderable backend texture of color type %d", - colorType); - continue; - } + // Internal offscreen texture + GrBackendTexture backendTex; + CreateBackendTexture(direct, &backendTex, kWidthHeight, kWidthHeight, colorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, + GrProtected::kNo); + sk_sp sProxy = proxyProvider->wrapBackendTexture( - mbet->texture(), kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, - kRead_GrIOType, mbet->refCountedCallback()); + backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); if (!sProxy) { - ERRORF(reporter, "wrapBackendTexture failed"); + direct->deleteBackendTexture(backendTex); continue; } check_surface(reporter, sProxy.get(), kWidthHeight, kWidthHeight, SkBudgeted::kNo); check_texture(reporter, resourceProvider, sProxy->asTextureProxy(), SkBackingFit::kExact); + + direct->deleteBackendTexture(backendTex); } } } diff --git a/tests/ResourceAllocatorTest.cpp b/tests/ResourceAllocatorTest.cpp index 1d1e7e1f4b..69c3e015dd 100644 --- a/tests/ResourceAllocatorTest.cpp +++ b/tests/ResourceAllocatorTest.cpp @@ -17,7 +17,7 @@ #include "src/gpu/GrTexture.h" #include "src/gpu/GrTextureProxy.h" #include "tests/Test.h" -#include "tools/gpu/ManagedBackendTexture.h" +#include "tests/TestUtils.h" struct ProxyParams { int fSize; @@ -36,24 +36,27 @@ static sk_sp make_deferred(GrProxyProvider* proxyProvider, const GrMipmapped::kNo, p.fFit, p.fBudgeted, GrProtected::kNo); } -static sk_sp make_backend(GrDirectContext* dContext, const ProxyParams& p) { +static sk_sp make_backend(GrDirectContext* dContext, + const ProxyParams& p, + GrBackendTexture* backendTex) { GrProxyProvider* proxyProvider = dContext->priv().proxyProvider(); SkColorType skColorType = GrColorTypeToSkColorType(p.fColorType); SkASSERT(SkColorType::kUnknown_SkColorType != skColorType); - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( - dContext, p.fSize, p.fSize, skColorType, GrMipmapped::kNo, GrRenderable::kNo); + CreateBackendTexture(dContext, backendTex, p.fSize, p.fSize, skColorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo); - if (!mbet) { + if (!backendTex->isValid()) { return nullptr; } - return proxyProvider->wrapBackendTexture(mbet->texture(), - kBorrow_GrWrapOwnership, - GrWrapCacheable::kNo, - kRead_GrIOType, - mbet->refCountedCallback()); + return proxyProvider->wrapBackendTexture(*backendTex, kBorrow_GrWrapOwnership, + GrWrapCacheable::kNo, kRead_GrIOType); +} + +static void cleanup_backend(GrDirectContext* dContext, const GrBackendTexture& backendTex) { + dContext->deleteBackendTexture(backendTex); } // Basic test that two proxies with overlapping intervals and compatible descriptors are @@ -213,11 +216,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) { TestCase t[1] = { {{64, kNotRT, kRGBA, kE, 1, kNotB}, {64, kNotRT, kRGBA, kE, 1, kNotB}, kDontShare}}; - sk_sp p1 = make_backend(direct, t[0].fP1); + GrBackendTexture backEndTex; + sk_sp p1 = make_backend(direct, t[0].fP1, &backEndTex); sk_sp p2 = make_deferred(proxyProvider, caps, t[0].fP2); non_overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2), t[0].fExpectation); + + cleanup_backend(direct, backEndTex); } } @@ -340,15 +346,18 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorCurOpsTaskIndexTest, // Wrapped proxy that will be ignored by the resourceAllocator. We use this to try and get the // resource allocator fCurOpsTaskIndex to fall behind what it really should be. - sk_sp proxyWrapped = make_backend(context, params); + GrBackendTexture backEndTex; + sk_sp proxyWrapped = make_backend(context, params, &backEndTex); if (!proxyWrapped) { return; } // Same as above, but we actually need to have at least two intervals that don't go through the // resource allocator to expose the index bug. - sk_sp proxyWrapped2 = make_backend(context, params); + GrBackendTexture backEndTex2; + sk_sp proxyWrapped2 = make_backend(context, params, &backEndTex2); if (!proxyWrapped2) { + cleanup_backend(context, backEndTex); return; } @@ -389,6 +398,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorCurOpsTaskIndexTest, REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error); REPORTER_ASSERT(reporter, 3 == startIndex && 4 == stopIndex); + cleanup_backend(context, backEndTex); + cleanup_backend(context, backEndTex2); + context->setResourceCacheLimit(origMaxBytes); } diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index aa9913adbf..d74df1a2d3 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -7,11 +7,7 @@ #include "include/core/SkTypes.h" -#include "include/core/SkCanvas.h" -#include "include/core/SkSurface.h" #include "include/gpu/GrDirectContext.h" -#include "src/core/SkMessageBus.h" -#include "src/core/SkMipmap.h" #include "src/gpu/GrContextPriv.h" #include "src/gpu/GrGpu.h" #include "src/gpu/GrGpuResourceCacheAccess.h" @@ -22,10 +18,15 @@ #include "src/gpu/GrResourceCache.h" #include "src/gpu/GrResourceProvider.h" #include "src/gpu/GrTexture.h" +#include "tools/gpu/GrContextFactory.h" + +#include "include/core/SkCanvas.h" +#include "include/core/SkSurface.h" +#include "src/core/SkMessageBus.h" +#include "src/core/SkMipmap.h" #include "src/gpu/SkGr.h" #include "tests/Test.h" -#include "tools/gpu/GrContextFactory.h" -#include "tools/gpu/ManagedBackendTexture.h" +#include "tests/TestUtils.h" #include @@ -190,44 +191,51 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxI return; } + GrBackendTexture backendTextures[2]; static const int kW = 100; static const int kH = 100; - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( - context, kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo); - GrBackendTexture unmbet = context->createBackendTexture( - kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo); - if (!mbet || !unmbet.isValid()) { - ERRORF(reporter, "Could not create backend texture."); + CreateBackendTexture(context, &backendTextures[0], kW, kH, kRGBA_8888_SkColorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, + GrProtected::kNo); + CreateBackendTexture(context, &backendTextures[1], kW, kH, kRGBA_8888_SkColorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, + GrProtected::kNo); + REPORTER_ASSERT(reporter, backendTextures[0].isValid()); + REPORTER_ASSERT(reporter, backendTextures[1].isValid()); + if (!backendTextures[0].isValid() || !backendTextures[1].isValid()) { return; } context->resetContext(); sk_sp borrowed(resourceProvider->wrapBackendTexture( - mbet->texture(), kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType)); + backendTextures[0], kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType)); sk_sp adopted(resourceProvider->wrapBackendTexture( - unmbet, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType)); + backendTextures[1], kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType)); REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr); if (!borrowed || !adopted) { return; } - borrowed.reset(); - adopted.reset(); + borrowed.reset(nullptr); + adopted.reset(nullptr); - context->flushAndSubmit(/*sync*/ true); + context->flushAndSubmit(); - bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(mbet->texture()); - bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(unmbet); + bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(backendTextures[0]); + bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(backendTextures[1]); REPORTER_ASSERT(reporter, borrowedIsAlive); REPORTER_ASSERT(reporter, !adoptedIsAlive); + if (borrowedIsAlive) { + context->deleteBackendTexture(backendTextures[0]); + } if (adoptedIsAlive) { - context->deleteBackendTexture(unmbet); + context->deleteBackendTexture(backendTextures[1]); } context->resetContext(); diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index c4fc29b489..fe588cf8d8 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -29,14 +29,15 @@ #include "src/image/SkImage_Gpu.h" #include "src/image/SkSurface_Gpu.h" #include "tests/Test.h" -#include "tools/ToolUtils.h" +#include "tests/TestUtils.h" #include "tools/gpu/BackendSurfaceFactory.h" -#include "tools/gpu/ManagedBackendTexture.h" #include #include #include +#include "tools/ToolUtils.h" + static void release_direct_surface_storage(void* pixels, void* context) { SkASSERT(pixels == context); sk_free(pixels); @@ -107,13 +108,19 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsSurface, report REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d", colorType, can, SkToBool(surf)); - surf = sk_gpu_test::MakeBackendTextureSurface(context, - {kSize, kSize}, - kTopLeft_GrSurfaceOrigin, - /*sample cnt*/ 1, - colorType); + GrBackendTexture backendTex; + CreateBackendTexture(context, &backendTex, kSize, kSize, colorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kYes, + GrProtected::kNo); + surf = SkSurface::MakeFromBackendTexture(context, backendTex, + kTopLeft_GrSurfaceOrigin, 0, colorType, + nullptr, nullptr); REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d", colorType, can, SkToBool(surf)); + + surf.reset(); + context->flushAndSubmit(); + context->deleteBackendTexture(backendTex); } // The MSAA test only makes sense if the colorType is renderable to begin with. @@ -126,8 +133,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsSurface, report REPORTER_ASSERT(reporter, can == SkToBool(surf), "ct: %d, can: %d, surf: %d", colorType, can, SkToBool(surf)); - surf = sk_gpu_test::MakeBackendTextureSurface( - context, {kSize, kSize}, kTopLeft_GrSurfaceOrigin, kSampleCnt, colorType); + GrBackendTexture backendTex; + CreateBackendTexture(context, &backendTex, kSize, kSize, colorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kYes, + GrProtected::kNo); + surf = SkSurface::MakeFromBackendTexture(context, backendTex, + kTopLeft_GrSurfaceOrigin, kSampleCnt, + colorType, nullptr, nullptr); REPORTER_ASSERT(reporter, can == SkToBool(surf), "colorTypeSupportedAsSurface:%d, surf:%d, ct:%d", can, SkToBool(surf), colorType); @@ -135,13 +147,15 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsSurface, report if (surf) { auto rtc = ((SkSurface_Gpu*)(surf.get()))->getDevice()->accessRenderTargetContext(); int storedCnt = rtc->numSamples(); - GrBackendFormat format = rtc->writeSurfaceView().proxy()->backendFormat(); - int allowedCnt = - context->priv().caps()->getRenderTargetSampleCount(storedCnt, format); + int allowedCnt = context->priv().caps()->getRenderTargetSampleCount( + storedCnt, backendTex.getBackendFormat()); REPORTER_ASSERT(reporter, storedCnt == allowedCnt, "Should store an allowed sample count (%d vs %d)", allowedCnt, storedCnt); } + surf.reset(); + context->flushAndSubmit(); + context->deleteBackendTexture(backendTex); } for (int sampleCnt : {1, 2}) { @@ -187,27 +201,39 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_maxSurfaceSamplesForColorType, repo for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) { SkColorType colorType = static_cast(ct); - int maxSampleCnt = context->maxSurfaceSampleCountForColorType(colorType); - if (!maxSampleCnt) { + int max = context->maxSurfaceSampleCountForColorType(colorType); + if (!max) { continue; } + + GrBackendTexture backendTex; + CreateBackendTexture(context, &backendTex, kSize, kSize, colorType, + SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kYes, + GrProtected::kNo); + if (!backendTex.isValid()) { + continue; + } + SkScopeExit freeTex([&backendTex, context] { + context->deleteBackendTexture(backendTex); + }); + if (!context->colorTypeSupportedAsSurface(colorType)) { continue; } auto info = SkImageInfo::Make(kSize, kSize, colorType, kOpaque_SkAlphaType, nullptr); - auto surf = sk_gpu_test::MakeBackendTextureSurface( - context, info, kTopLeft_GrSurfaceOrigin, maxSampleCnt); + auto surf = SkSurface::MakeFromBackendTexture(context, backendTex, + kTopLeft_GrSurfaceOrigin, max, + colorType, nullptr, nullptr); + REPORTER_ASSERT(reporter, surf); if (!surf) { - ERRORF(reporter, "Could not make surface of color type %d.", colorType); continue; } int sampleCnt = ((SkSurface_Gpu*)(surf.get())) ->getDevice() ->accessRenderTargetContext() ->numSamples(); - REPORTER_ASSERT(reporter, sampleCnt == maxSampleCnt, "Exected: %d, actual: %d", - maxSampleCnt, sampleCnt); + REPORTER_ASSERT(reporter, sampleCnt == max, "Exected: %d, actual: %d", max, sampleCnt); } } @@ -653,7 +679,9 @@ DEF_TEST(surface_raster_zeroinitialized, reporter) { static sk_sp create_gpu_surface_backend_texture(GrDirectContext* dContext, int sampleCnt, - const SkColor4f& color) { + const SkColor4f& color, + GrBackendTexture* outTexture) { + // On Pixel and Pixel2XL's with Adreno 530 and 540s, setting width and height to 10s reliably // triggers what appears to be a driver race condition where the 10x10 surface from the // OverdrawSurface_gpu test is reused(?) for this surface created by the SurfacePartialDraw_gpu @@ -677,16 +705,25 @@ static sk_sp create_gpu_surface_backend_texture(GrDirectContext* dCon const int kHeight = 100; #endif - auto surf = sk_gpu_test::MakeBackendTextureSurface(dContext, - {kWidth, kHeight}, - kTopLeft_GrSurfaceOrigin, - sampleCnt, - kRGBA_8888_SkColorType); - if (!surf) { + SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, SkColorType::kRGBA_8888_SkColorType, + kPremul_SkAlphaType); + + if (!CreateBackendTexture(dContext, outTexture, ii, color, + GrMipmapped::kNo, GrRenderable::kYes)) { return nullptr; } - surf->getCanvas()->clear(color); - return surf; + + sk_sp surface = SkSurface::MakeFromBackendTexture(dContext, + *outTexture, + kTopLeft_GrSurfaceOrigin, + sampleCnt, + kRGBA_8888_SkColorType, + nullptr, nullptr); + if (!surface) { + DeleteBackendTexture(dContext, *outTexture); + return nullptr; + } + return surface; } static bool supports_readpixels(const GrCaps* caps, SkSurface* surface) { @@ -701,7 +738,8 @@ static bool supports_readpixels(const GrCaps* caps, SkSurface* surface) { static sk_sp create_gpu_surface_backend_render_target(GrDirectContext* dContext, int sampleCnt, - const SkColor4f& color) { + const SkColor4f& color, + GrBackendTexture* outTexture) { const int kWidth = 10; const int kHeight = 10; @@ -709,7 +747,10 @@ static sk_sp create_gpu_surface_backend_render_target(GrDirectContext {kWidth, kHeight}, kTopLeft_GrSurfaceOrigin, sampleCnt, - kRGBA_8888_SkColorType); + kRGBA_8888_SkColorType, + nullptr, + GrProtected::kNo, + nullptr); if (!surf) { return nullptr; } @@ -782,7 +823,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) { const SkColor4f kOrigColor{.67f, .67f, .67f, 1}; for (auto& surfaceFunc : {&create_gpu_surface_backend_texture, &create_gpu_surface_backend_render_target}) { - auto surface = surfaceFunc(dContext, 1, kOrigColor); + GrBackendTexture backendTex; + auto surface = surfaceFunc(dContext, 1, kOrigColor, &backendTex); if (!surface) { ERRORF(reporter, "Could not create GPU SkSurface."); return; @@ -796,6 +838,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, ctxInfo) { auto imageSurfaceCtx = makeImageSurfaceContext(surface.get()); test_surface_context_clear(reporter, dContext, imageSurfaceCtx.get(), kOrigColor.toSkColor()); + dContext->deleteBackendTexture(backendTex); } } @@ -861,9 +904,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfacePartialDraw_Gpu, reporter, ctxInfo) { // Validate that we can draw to the canvas and that the original texture color is // preserved in pixels that aren't rendered to via the surface. // This works only for non-multisampled case. - auto surface = surfaceFunc(context, 1, kOrigColor); - if (surface && supports_readpixels(context->priv().caps(), surface.get())) { + GrBackendTexture backendTex; + auto surface = surfaceFunc(context, 1, kOrigColor, &backendTex); + const GrCaps* caps = context->priv().caps(); + if (!supports_readpixels(caps, surface.get())) { + continue; + } + if (surface) { test_surface_draw_partially(reporter, surface, kOrigColor.toSkColor()); + surface.reset(); + context->deleteBackendTexture(backendTex); } } } @@ -885,7 +935,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedWithRelease_Gpu, reporter, ctxI GrGpu* gpu = ctx->priv().getGpu(); for (bool useTexture : {false, true}) { - sk_sp mbet; + GrBackendTexture backendTex; GrBackendRenderTarget backendRT; sk_sp surface; @@ -895,22 +945,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedWithRelease_Gpu, reporter, ctxI if (useTexture) { SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, SkColorType::kRGBA_8888_SkColorType, kPremul_SkAlphaType); - mbet = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(ctx, ii, GrMipMapped::kNo, - GrRenderable::kYes); - if (!mbet) { + if (!CreateBackendTexture(ctx, &backendTex, ii, SkColors::kRed, GrMipmapped::kNo, + GrRenderable::kYes)) { continue; } - surface = SkSurface::MakeFromBackendTexture( - ctx, - mbet->texture(), - texOrigin, - /*sample count*/ 1, - kRGBA_8888_SkColorType, - /*color space*/ nullptr, - /*surface props*/ nullptr, - sk_gpu_test::ManagedBackendTexture::ReleaseProc, - mbet->releaseContext(ReleaseChecker::Release, &releaseChecker)); + surface = SkSurface::MakeFromBackendTexture(ctx, backendTex, texOrigin, 1, + kRGBA_8888_SkColorType, + nullptr, nullptr, + ReleaseChecker::Release, + &releaseChecker); } else { backendRT = gpu->createTestingOnlyBackendRenderTarget({kWidth, kHeight}, GrColorType::kRGBA_8888); @@ -937,7 +981,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedWithRelease_Gpu, reporter, ctxI surface.reset(nullptr); // force a release of the surface REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); - if (!useTexture) { + if (useTexture) { + DeleteBackendTexture(ctx, backendTex); + } else { gpu->deleteTestingOnlyBackendRenderTarget(backendRT); } } @@ -958,7 +1004,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAttachStencil_Gpu, reporter, ctxInf for (auto& surfaceFunc : {&create_gpu_surface_backend_texture, &create_gpu_surface_backend_render_target}) { for (int sampleCnt : {1, 4, 8}) { - auto surface = surfaceFunc(context, sampleCnt, kOrigColor); + GrBackendTexture backendTex; + auto surface = surfaceFunc(context, sampleCnt, kOrigColor, &backendTex); if (!surface && sampleCnt > 1) { // Certain platforms don't support MSAA, skip these. @@ -970,6 +1017,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SurfaceAttachStencil_Gpu, reporter, ctxInf GrRenderTarget* rt = surface->getCanvas() ->internal_private_accessTopLayerRenderTargetContext()->accessRenderTarget(); REPORTER_ASSERT(reporter, resourceProvider->attachStencilAttachment(rt, sampleCnt)); + if (backendTex.isValid()) { + context->deleteBackendTexture(backendTex); + } } } } @@ -978,29 +1028,34 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReplaceSurfaceBackendTexture, reporter, ctxIn auto context = ctxInfo.directContext(); for (int sampleCnt : {1, 2}) { + GrBackendTexture backendTexture1; auto ii = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); - auto mbet1 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo( - context, ii, GrMipmapped::kNo, GrRenderable::kYes); - if (!mbet1) { + if (!CreateBackendTexture(context, &backendTexture1, ii, SkColors::kTransparent, + GrMipmapped::kNo, GrRenderable::kYes)) { continue; } - auto mbet2 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo( - context, ii, GrMipmapped::kNo, GrRenderable::kYes); - if (!mbet2) { + SkScopeExit delete1( + [context, &backendTexture1] { DeleteBackendTexture(context, backendTexture1); }); + GrBackendTexture backendTexture2; + if (!CreateBackendTexture(context, &backendTexture2, ii, SkColors::kTransparent, + GrMipmapped::kNo, GrRenderable::kYes)) { ERRORF(reporter, "Expected to be able to make second texture"); continue; } + SkScopeExit delete2( + [context, &backendTexture2] { DeleteBackendTexture(context, backendTexture2); }); auto ii2 = ii.makeWH(8, 8); - auto mbet3 = sk_gpu_test::ManagedBackendTexture::MakeFromInfo( - context, ii2, GrMipmapped::kNo, GrRenderable::kYes); GrBackendTexture backendTexture3; - if (!mbet3) { + if (!CreateBackendTexture(context, &backendTexture3, ii2, SkColors::kTransparent, + GrMipmapped::kNo, GrRenderable::kYes)) { ERRORF(reporter, "Couldn't create different sized texture."); continue; } + SkScopeExit delete3( + [context, &backendTexture3] { DeleteBackendTexture(context, backendTexture3); }); auto surf = SkSurface::MakeFromBackendTexture( - context, mbet1->texture(), kTopLeft_GrSurfaceOrigin, sampleCnt, + context, backendTexture1, kTopLeft_GrSurfaceOrigin, sampleCnt, kRGBA_8888_SkColorType, ii.refColorSpace(), nullptr); if (!surf) { continue; @@ -1011,7 +1066,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReplaceSurfaceBackendTexture, reporter, ctxIn surf->getCanvas()->saveLayer(nullptr, nullptr); surf->getCanvas()->clipRect(SkRect::MakeXYWH(0, 0, 1, 1)); // switch origin while we're at it. - bool replaced = surf->replaceBackendTexture(mbet2->texture(), kBottomLeft_GrSurfaceOrigin); + bool replaced = surf->replaceBackendTexture(backendTexture2, kBottomLeft_GrSurfaceOrigin); REPORTER_ASSERT(reporter, replaced); SkPaint paint; paint.setColor(SK_ColorRED); @@ -1036,7 +1091,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReplaceSurfaceBackendTexture, reporter, ctxIn } // The original texture should still be all blue. surf = SkSurface::MakeFromBackendTexture( - context, mbet1->texture(), kBottomLeft_GrSurfaceOrigin, sampleCnt, + context, backendTexture1, kBottomLeft_GrSurfaceOrigin, sampleCnt, kRGBA_8888_SkColorType, ii.refColorSpace(), nullptr); if (!surf) { ERRORF(reporter, "Could not create second surface."); @@ -1058,17 +1113,17 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReplaceSurfaceBackendTexture, reporter, ctxIn // Can't replace with the same texture REPORTER_ASSERT(reporter, - !surf->replaceBackendTexture(mbet1->texture(), kTopLeft_GrSurfaceOrigin)); + !surf->replaceBackendTexture(backendTexture1, kTopLeft_GrSurfaceOrigin)); // Can't replace with invalid texture REPORTER_ASSERT(reporter, !surf->replaceBackendTexture({}, kTopLeft_GrSurfaceOrigin)); // Can't replace with different size texture. REPORTER_ASSERT(reporter, - !surf->replaceBackendTexture(mbet3->texture(), kTopLeft_GrSurfaceOrigin)); + !surf->replaceBackendTexture(backendTexture3, kTopLeft_GrSurfaceOrigin)); // Can't replace texture of non-wrapped SkSurface. surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, ii, sampleCnt, nullptr); REPORTER_ASSERT(reporter, surf); if (surf) { - REPORTER_ASSERT(reporter, !surf->replaceBackendTexture(mbet1->texture(), + REPORTER_ASSERT(reporter, !surf->replaceBackendTexture(backendTexture1, kTopLeft_GrSurfaceOrigin)); } } diff --git a/tests/TestUtils.cpp b/tests/TestUtils.cpp index 6c01b4f004..3499376097 100644 --- a/tests/TestUtils.cpp +++ b/tests/TestUtils.cpp @@ -107,6 +107,68 @@ void FillPixelData(int width, int height, GrColor* data) { } } +bool CreateBackendTexture(GrDirectContext* dContext, + GrBackendTexture* backendTex, + int width, int height, + SkColorType colorType, + const SkColor4f& color, + GrMipmapped mipMapped, + GrRenderable renderable, + GrProtected isProtected) { + SkImageInfo info = SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType); + return CreateBackendTexture(dContext, backendTex, info, color, mipMapped, renderable, + isProtected); +} + +bool CreateBackendTexture(GrDirectContext* dContext, + GrBackendTexture* backendTex, + const SkImageInfo& ii, + const SkColor4f& color, + GrMipmapped mipMapped, + GrRenderable renderable, + GrProtected isProtected) { + bool finishedBECreate = false; + auto markFinished = [](void* context) { + *(bool*)context = true; + }; + + *backendTex = dContext->createBackendTexture(ii.width(), ii.height(), ii.colorType(), + color, mipMapped, renderable, isProtected, + markFinished, &finishedBECreate); + if (backendTex->isValid()) { + dContext->submit(); + while (!finishedBECreate) { + dContext->checkAsyncWorkCompletion(); + } + } + return backendTex->isValid(); +} + +bool CreateBackendTexture(GrDirectContext* dContext, + GrBackendTexture* backendTex, + const SkBitmap& bm) { + bool finishedBECreate = false; + auto markFinished = [](void* context) { + *(bool*)context = true; + }; + + *backendTex = dContext->createBackendTexture(bm.pixmap(), GrRenderable::kNo, GrProtected::kNo, + markFinished, &finishedBECreate); + if (backendTex->isValid()) { + dContext->submit(); + while (!finishedBECreate) { + dContext->checkAsyncWorkCompletion(); + } + } + return backendTex->isValid(); +} + +void DeleteBackendTexture(GrDirectContext* dContext, const GrBackendTexture& backendTex) { + dContext->flush(); + dContext->submit(true); + dContext->deleteBackendTexture(backendTex); +} + bool DoesFullBufferContainCorrectColor(const GrColor* srcBuffer, const GrColor* dstBuffer, int width, int height) { diff --git a/tests/TestUtils.h b/tests/TestUtils.h index c5964b0654..d8e7abd6de 100644 --- a/tests/TestUtils.h +++ b/tests/TestUtils.h @@ -34,6 +34,30 @@ void TestCopyFromSurface(skiatest::Reporter*, GrDirectContext*, GrSurfaceProxy* // Fills data with a red-green gradient void FillPixelData(int width, int height, GrColor* data); +// Create a solid colored backend texture and syncs the CPU to wait for upload to finish +bool CreateBackendTexture(GrDirectContext*, + GrBackendTexture* backendTex, + int width, int height, + SkColorType colorType, + const SkColor4f& color, + GrMipmapped, + GrRenderable, + GrProtected = GrProtected::kNo); + +bool CreateBackendTexture(GrDirectContext*, + GrBackendTexture* backendTex, + const SkImageInfo& ii, + const SkColor4f& color, + GrMipmapped, + GrRenderable, + GrProtected = GrProtected::kNo); + +bool CreateBackendTexture(GrDirectContext*, + GrBackendTexture* backendTex, + const SkBitmap& bm); + +void DeleteBackendTexture(GrDirectContext*, const GrBackendTexture& backendTex); + // Checks srcBuffer and dstBuffer contain the same colors bool DoesFullBufferContainCorrectColor(const GrColor* srcBuffer, const GrColor* dstBuffer, diff --git a/tests/TextureProxyTest.cpp b/tests/TextureProxyTest.cpp index dff9e5266d..fe2a0cda65 100644 --- a/tests/TextureProxyTest.cpp +++ b/tests/TextureProxyTest.cpp @@ -9,7 +9,6 @@ #include "tests/Test.h" -#include "include/core/SkImage.h" #include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrDirectContext.h" #include "src/gpu/GrContextPriv.h" @@ -19,8 +18,9 @@ #include "src/gpu/GrResourceProvider.h" #include "src/gpu/GrTexture.h" #include "src/gpu/GrTextureProxy.h" + +#include "include/core/SkImage.h" #include "src/gpu/SkGr.h" -#include "tools/gpu/ManagedBackendTexture.h" #ifdef SK_DAWN #include "src/gpu/dawn/GrDawnGpu.h" @@ -96,26 +96,29 @@ static sk_sp wrapped_with_key(skiatest::Reporter* reporter, GrRe return proxy; } -static sk_sp create_wrapped_backend(GrDirectContext* dContext) { - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( - dContext, - kSize.width(), - kSize.height(), - GrColorTypeToSkColorType(kColorType), - GrMipmapped::kNo, - GrRenderable::kNo, - GrProtected::kNo); - if (!mbet) { +static sk_sp create_wrapped_backend(GrDirectContext* dContext, + SkBackingFit fit, + sk_sp* backingSurface) { + GrProxyProvider* proxyProvider = dContext->priv().proxyProvider(); + GrResourceProvider* resourceProvider = dContext->priv().resourceProvider(); + + GrBackendFormat format = + proxyProvider->caps()->getDefaultBackendFormat(kColorType, GrRenderable::kYes); + + *backingSurface = + resourceProvider->createTexture(kSize, format, GrRenderable::kNo, 1, GrMipmapped::kNo, + SkBudgeted::kNo, GrProtected::kNo); + if (!(*backingSurface)) { return nullptr; } - GrProxyProvider* proxyProvider = dContext->priv().proxyProvider(); - return proxyProvider->wrapBackendTexture(mbet->texture(), - kBorrow_GrWrapOwnership, - GrWrapCacheable::kYes, - kRead_GrIOType, - mbet->refCountedCallback()); + + GrBackendTexture backendTex = (*backingSurface)->getBackendTexture(); + + return proxyProvider->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, + GrWrapCacheable::kYes, kRead_GrIOType); } + // This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning // and looking them up work, etc. static void basic_test(GrDirectContext* dContext, @@ -335,11 +338,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) { } REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); + sk_sp backingTex; + sk_sp proxy = create_wrapped_backend(direct, fit, &backingTex); + basic_test(direct, reporter, std::move(proxy)); + + backingTex = nullptr; cache->purgeAllUnlocked(); } - basic_test(direct, reporter, create_wrapped_backend(direct)); - invalidation_test(direct, reporter); invalidation_and_instantiation_test(direct, reporter); } diff --git a/tests/VkBackendSurfaceTest.cpp b/tests/VkBackendSurfaceTest.cpp index b9f28476fd..dc61c39a14 100644 --- a/tests/VkBackendSurfaceTest.cpp +++ b/tests/VkBackendSurfaceTest.cpp @@ -11,11 +11,15 @@ #if defined(SK_VULKAN) +#include "include/gpu/vk/GrVkVulkan.h" + +#include "tests/Test.h" +#include "tests/TestUtils.h" + #include "include/core/SkImage.h" #include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrDirectContext.h" #include "include/gpu/vk/GrVkTypes.h" -#include "include/gpu/vk/GrVkVulkan.h" #include "src/gpu/GrRenderTargetContext.h" #include "src/gpu/GrTexture.h" #include "src/gpu/GrTextureProxy.h" @@ -26,50 +30,41 @@ #include "src/image/SkImage_Base.h" #include "src/image/SkImage_GpuBase.h" #include "src/image/SkSurface_Gpu.h" -#include "tests/Test.h" -#include "tools/gpu/ManagedBackendTexture.h" DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) { auto dContext = ctxInfo.directContext(); - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( - dContext, 1, 1, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo); - if (!mbet) { - ERRORF(reporter, "Could not create backend texture."); - return; - } + GrBackendTexture backendTex; + CreateBackendTexture(dContext, &backendTex, 1, 1, kRGBA_8888_SkColorType, + SkColors::kTransparent, GrMipmapped::kNo, + GrRenderable::kNo, GrProtected::kNo); + REPORTER_ASSERT(reporter, backendTex.isValid()); GrVkImageInfo info; - REPORTER_ASSERT(reporter, mbet->texture().getVkImageInfo(&info)); + REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info)); VkImageLayout initLayout = info.fImageLayout; // Verify that setting that layout via a copy of a backendTexture is reflected in all the // backendTextures. - GrBackendTexture backendTex1 = mbet->texture(); - GrBackendTexture backendTex2 = backendTex1; - REPORTER_ASSERT(reporter, backendTex2.getVkImageInfo(&info)); + GrBackendTexture backendTexCopy = backendTex; + REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info)); REPORTER_ASSERT(reporter, initLayout == info.fImageLayout); - backendTex2.setVkImageLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + backendTexCopy.setVkImageLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - REPORTER_ASSERT(reporter, backendTex1.getVkImageInfo(&info)); + REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info)); REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout); - REPORTER_ASSERT(reporter, backendTex2.getVkImageInfo(&info)); + REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info)); REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout); // Setting back the layout since we didn't actually change it - backendTex1.setVkImageLayout(initLayout); + backendTex.setVkImageLayout(initLayout); - sk_sp wrappedImage = SkImage::MakeFromTexture( - dContext, - backendTex1, - kTopLeft_GrSurfaceOrigin, - kRGBA_8888_SkColorType, - kPremul_SkAlphaType, - /*color space*/ nullptr, - sk_gpu_test::ManagedBackendTexture::ReleaseProc, - mbet->releaseContext()); + sk_sp wrappedImage = SkImage::MakeFromTexture(dContext, backendTex, + kTopLeft_GrSurfaceOrigin, + kRGBA_8888_SkColorType, + kPremul_SkAlphaType, nullptr); REPORTER_ASSERT(reporter, wrappedImage.get()); const GrSurfaceProxyView* view = as_IB(wrappedImage)->view(dContext); @@ -83,7 +78,7 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) { REPORTER_ASSERT(reporter, initLayout == vkTexture->currentLayout()); vkTexture->updateImageLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL); - REPORTER_ASSERT(reporter, backendTex1.getVkImageInfo(&info)); + REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info)); REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL == info.fImageLayout); GrBackendTexture backendTexImage = wrappedImage->getBackendTexture(false); @@ -96,10 +91,10 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) { vkTexture->updateImageLayout(initLayout); - REPORTER_ASSERT(reporter, backendTex1.getVkImageInfo(&info)); + REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info)); REPORTER_ASSERT(reporter, initLayout == info.fImageLayout); - REPORTER_ASSERT(reporter, backendTex2.getVkImageInfo(&info)); + REPORTER_ASSERT(reporter, backendTexCopy.getVkImageInfo(&info)); REPORTER_ASSERT(reporter, initLayout == info.fImageLayout); REPORTER_ASSERT(reporter, backendTexImage.getVkImageInfo(&info)); @@ -108,23 +103,25 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) { // Check that we can do things like assigning the backend texture to invalid one, assign an // invalid one, assin a backend texture to inself etc. Success here is that we don't hit any of // our ref counting asserts. - REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex1, backendTex2)); + REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(backendTex, backendTexCopy)); GrBackendTexture invalidTexture; REPORTER_ASSERT(reporter, !invalidTexture.isValid()); - REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex2)); + REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTexCopy)); - backendTex2 = invalidTexture; - REPORTER_ASSERT(reporter, !backendTex2.isValid()); - REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex2)); + backendTexCopy = invalidTexture; + REPORTER_ASSERT(reporter, !backendTexCopy.isValid()); + REPORTER_ASSERT(reporter, !GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTexCopy)); - invalidTexture = backendTex1; + invalidTexture = backendTex; REPORTER_ASSERT(reporter, invalidTexture.isValid()); - REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex1)); + REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, backendTex)); invalidTexture = static_cast(invalidTexture); REPORTER_ASSERT(reporter, invalidTexture.isValid()); REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, invalidTexture)); + + dContext->deleteBackendTexture(backendTex); } // This test is disabled because it executes illegal vulkan calls which cause the validations layers diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp index 7f163f8a42..17a1c02320 100644 --- a/tests/VkWrapTests.cpp +++ b/tests/VkWrapTests.cpp @@ -11,19 +11,21 @@ #if defined(SK_VULKAN) +#include "include/gpu/vk/GrVkVulkan.h" + #include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrDirectContext.h" -#include "include/gpu/vk/GrVkTypes.h" -#include "include/gpu/vk/GrVkVulkan.h" #include "src/gpu/GrContextPriv.h" #include "src/gpu/GrRenderTarget.h" #include "src/gpu/GrTexture.h" +#include "tools/gpu/GrContextFactory.h" + +#include "include/gpu/vk/GrVkTypes.h" #include "src/gpu/vk/GrVkCaps.h" #include "src/gpu/vk/GrVkGpu.h" #include "src/gpu/vk/GrVkMemory.h" #include "tests/Test.h" -#include "tools/gpu/GrContextFactory.h" -#include "tools/gpu/ManagedBackendTexture.h" +#include "tests/TestUtils.h" using sk_gpu_test::GrContextFactory; @@ -32,36 +34,30 @@ const int kH = 1024; const SkColorType kColorType = SkColorType::kRGBA_8888_SkColorType; void wrap_tex_test(skiatest::Reporter* reporter, GrDirectContext* dContext) { + GrGpu* gpu = dContext->priv().getGpu(); - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( - dContext, kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo); - if (!mbet) { - ERRORF(reporter, "Could not create backend texture."); - return; - } - - GrBackendTexture origBackendTex = mbet->texture(); + GrBackendTexture origBackendTex; + CreateBackendTexture(dContext, &origBackendTex, kW, kH, kColorType, SkColors::kTransparent, + GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo); GrVkImageInfo imageInfo; SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); - { - sk_sp tex = gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership, - GrWrapCacheable::kNo, kRead_GrIOType); - REPORTER_ASSERT(reporter, tex); - } + sk_sp tex = gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership, + GrWrapCacheable::kNo, kRead_GrIOType); + REPORTER_ASSERT(reporter, tex); // image is null { GrVkImageInfo backendCopy = imageInfo; backendCopy.fImage = VK_NULL_HANDLE; GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); - sk_sp tex = gpu->wrapBackendTexture( - backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); + tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, + kRead_GrIOType); REPORTER_ASSERT(reporter, !tex); - tex = gpu->wrapBackendTexture( - backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); + tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, + kRead_GrIOType); REPORTER_ASSERT(reporter, !tex); } @@ -70,11 +66,11 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrDirectContext* dContext) { GrVkImageInfo backendCopy = imageInfo; backendCopy.fAlloc = GrVkAlloc(); GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); - sk_sp tex = gpu->wrapBackendTexture( - backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); + tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, + kRead_GrIOType); REPORTER_ASSERT(reporter, tex); - tex = gpu->wrapBackendTexture( - backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); + tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, + kRead_GrIOType); REPORTER_ASSERT(reporter, !tex); } @@ -82,71 +78,84 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrDirectContext* dContext) { { GrVkImageInfo backendCopy = imageInfo; GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); - sk_sp tex = gpu->wrapBackendTexture( - backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); + tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, + kRead_GrIOType); REPORTER_ASSERT(reporter, tex); - if (tex) { - mbet->wasAdopted(); - } + } + + // image has MSAA + { + GrVkImageInfo backendCopy = imageInfo; + backendCopy.fSampleCount = 4; + GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); + tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, + kRead_GrIOType); + REPORTER_ASSERT(reporter, !tex); + tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, + kRead_GrIOType); + REPORTER_ASSERT(reporter, !tex); } } void wrap_rt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) { GrGpu* gpu = dContext->priv().getGpu(); - GrColorType ct = SkColorTypeToGrColorType(kColorType); - for (int sampleCnt : {1, 4}) { - GrBackendFormat format = gpu->caps()->getDefaultBackendFormat(ct, GrRenderable::kYes); - if (sampleCnt > gpu->caps()->maxRenderTargetSampleCount(format)) { - continue; - } + GrBackendTexture origBackendTex; + CreateBackendTexture(dContext, &origBackendTex, kW, kH, kColorType, SkColors::kTransparent, + GrMipmapped::kNo, GrRenderable::kYes, GrProtected::kNo); - GrBackendRenderTarget origBackendRT = - gpu->createTestingOnlyBackendRenderTarget({kW, kH}, ct, sampleCnt); - if (!origBackendRT.isValid()) { - ERRORF(reporter, "Could not create backend render target."); - } + GrVkImageInfo imageInfo; + SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); - GrVkImageInfo imageInfo; - REPORTER_ASSERT(reporter, origBackendRT.getVkImageInfo(&imageInfo)); + GrBackendRenderTarget origBackendRT(kW, kH, 1, imageInfo); - sk_sp rt = gpu->wrapBackendRenderTarget(origBackendRT); + sk_sp rt = gpu->wrapBackendRenderTarget(origBackendRT); + REPORTER_ASSERT(reporter, rt); + + // image is null + { + GrVkImageInfo backendCopy = imageInfo; + backendCopy.fImage = VK_NULL_HANDLE; + GrBackendRenderTarget backendRT(kW, kH, 1, backendCopy); + rt = gpu->wrapBackendRenderTarget(backendRT); + REPORTER_ASSERT(reporter, !rt); + } + + // alloc is null + { + GrVkImageInfo backendCopy = imageInfo; + backendCopy.fAlloc = GrVkAlloc(); + // can wrap null alloc + GrBackendRenderTarget backendRT(kW, kH, 1, backendCopy); + rt = gpu->wrapBackendRenderTarget(backendRT); REPORTER_ASSERT(reporter, rt); + } - // image is null - { - GrVkImageInfo backendCopy = imageInfo; - backendCopy.fImage = VK_NULL_HANDLE; - GrBackendRenderTarget backendRT(kW, kH, 1, backendCopy); - rt = gpu->wrapBackendRenderTarget(backendRT); - REPORTER_ASSERT(reporter, !rt); - } - - // alloc is null - { - GrVkImageInfo backendCopy = imageInfo; - backendCopy.fAlloc = GrVkAlloc(); - // can wrap null alloc - GrBackendRenderTarget backendRT(kW, kH, 1, backendCopy); + // Image has MSAA + { + GrColorType ct = SkColorTypeToGrColorType(kColorType); + GrGpu* gpu = dContext->priv().getGpu(); + GrBackendRenderTarget backendRT = + gpu->createTestingOnlyBackendRenderTarget({kW, kW}, ct, 4); + if (backendRT.isValid()) { rt = gpu->wrapBackendRenderTarget(backendRT); REPORTER_ASSERT(reporter, rt); + dContext->priv().getGpu()->deleteTestingOnlyBackendRenderTarget(backendRT); } - - gpu->deleteTestingOnlyBackendRenderTarget(origBackendRT); } + + // When we wrapBackendRenderTarget it is always borrowed, so we must make sure to free the + // resource when we're done. + dContext->deleteBackendTexture(origBackendTex); } void wrap_trt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) { GrGpu* gpu = dContext->priv().getGpu(); - auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( - dContext, kW, kH, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kYes); - if (!mbet) { - ERRORF(reporter, "Could not create renderable backend texture."); - return; - } - GrBackendTexture origBackendTex = mbet->texture(); + GrBackendTexture origBackendTex; + CreateBackendTexture(dContext, &origBackendTex, kW, kH, kColorType, SkColors::kTransparent, + GrMipmapped::kNo, GrRenderable::kYes, GrProtected::kNo); GrVkImageInfo imageInfo; SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); @@ -181,6 +190,15 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) { REPORTER_ASSERT(reporter, !tex); } + // check adopt creation + { + GrVkImageInfo backendCopy = imageInfo; + GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); + tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership, + GrWrapCacheable::kNo); + REPORTER_ASSERT(reporter, tex); + } + // check rendering with MSAA { int maxSamples = dContext->priv().caps()->maxRenderTargetSampleCount( @@ -191,16 +209,14 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrDirectContext* dContext) { REPORTER_ASSERT(reporter, SkToBool(tex) == shouldSucceed); } - // check adopt creation + // Image has MSAA { GrVkImageInfo backendCopy = imageInfo; + backendCopy.fSampleCount = 4; GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo); - REPORTER_ASSERT(reporter, tex); - if (tex) { - mbet->wasAdopted(); - } + REPORTER_ASSERT(reporter, !tex); } } diff --git a/tools/fm/fm.cpp b/tools/fm/fm.cpp index a18279f4b3..6e1c4b0ced 100644 --- a/tools/fm/fm.cpp +++ b/tools/fm/fm.cpp @@ -323,9 +323,11 @@ static sk_sp draw_with_gpu(std::function draw, case SurfaceType::kBackendTexture: surface = sk_gpu_test::MakeBackendTextureSurface(context, - info, + info.dimensions(), kTopLeft_GrSurfaceOrigin, FLAGS_samples, + info.colorType(), + info.refColorSpace(), GrMipmapped::kNo, GrProtected::kNo, &props); @@ -333,9 +335,11 @@ static sk_sp draw_with_gpu(std::function draw, case SurfaceType::kBackendRenderTarget: surface = sk_gpu_test::MakeBackendRenderTargetSurface(context, - info, + info.dimensions(), kBottomLeft_GrSurfaceOrigin, FLAGS_samples, + info.colorType(), + info.refColorSpace(), GrProtected::kNo, &props); break; diff --git a/tools/gpu/BackendSurfaceFactory.cpp b/tools/gpu/BackendSurfaceFactory.cpp index 2c24760b9e..32a6500692 100644 --- a/tools/gpu/BackendSurfaceFactory.cpp +++ b/tools/gpu/BackendSurfaceFactory.cpp @@ -15,38 +15,7 @@ namespace sk_gpu_test { -sk_sp MakeBackendTextureSurface(GrDirectContext* dContext, - const SkImageInfo& ii, - GrSurfaceOrigin origin, - int sampleCnt, - GrMipmapped mipMapped, - GrProtected isProtected, - const SkSurfaceProps* props) { - if (ii.alphaType() == kUnpremul_SkAlphaType) { - return nullptr; - } - auto mbet = ManagedBackendTexture::MakeWithoutData(dContext, - ii.width(), - ii.height(), - ii.colorType(), - mipMapped, - GrRenderable::kYes, - isProtected); - if (!mbet) { - return nullptr; - } - return SkSurface::MakeFromBackendTexture(dContext, - mbet->texture(), - origin, - sampleCnt, - ii.colorType(), - ii.refColorSpace(), - props, - ManagedBackendTexture::ReleaseProc, - mbet->releaseContext()); -} - -sk_sp MakeBackendTextureSurface(GrDirectContext* dContext, +sk_sp MakeBackendTextureSurface(GrDirectContext* context, SkISize dimensions, GrSurfaceOrigin origin, int sampleCnt, @@ -55,29 +24,45 @@ sk_sp MakeBackendTextureSurface(GrDirectContext* dContext, GrMipmapped mipMapped, GrProtected isProtected, const SkSurfaceProps* props) { - auto ii = SkImageInfo::Make(dimensions, colorType, kPremul_SkAlphaType, std::move(colorSpace)); - return MakeBackendTextureSurface( - dContext, ii, origin, sampleCnt, mipMapped, isProtected, props); -} -sk_sp MakeBackendRenderTargetSurface(GrDirectContext* dContext, - const SkImageInfo& ii, - GrSurfaceOrigin origin, - int sampleCnt, - GrProtected isProtected, - const SkSurfaceProps* props) { - if (ii.alphaType() == kUnpremul_SkAlphaType) { + auto mbet = ManagedBackendTexture::MakeWithoutData(context, + dimensions.fWidth, + dimensions.fHeight, + colorType, + mipMapped, + GrRenderable::kYes, + isProtected); + if (!mbet) { return nullptr; } - auto ct = SkColorTypeToGrColorType(ii.colorType()); + return SkSurface::MakeFromBackendTexture(context, + mbet->texture(), + origin, + sampleCnt, + colorType, + std::move(colorSpace), + props, + ManagedBackendTexture::ReleaseProc, + mbet->releaseContext()); +} + +sk_sp MakeBackendRenderTargetSurface(GrDirectContext* context, + SkISize dimensions, + GrSurfaceOrigin origin, + int sampleCnt, + SkColorType colorType, + sk_sp colorSpace, + GrProtected isProtected, + const SkSurfaceProps* props) { + auto ct = SkColorTypeToGrColorType(colorType); struct ReleaseContext { GrDirectContext* fContext; GrBackendRenderTarget fRenderTarget; }; - auto bert = dContext->priv().getGpu()->createTestingOnlyBackendRenderTarget( - ii.dimensions(), ct, sampleCnt, isProtected); - auto rc = new ReleaseContext{dContext, bert}; + auto bert = context->priv().getGpu()->createTestingOnlyBackendRenderTarget( + dimensions, ct, sampleCnt, isProtected); + auto rc = new ReleaseContext{context, bert}; SkASSERT(!bert.isValid() || bert.sampleCnt() >= sampleCnt); auto proc = [](void* c) { @@ -89,19 +74,7 @@ sk_sp MakeBackendRenderTargetSurface(GrDirectContext* dContext, }; return SkSurface::MakeFromBackendRenderTarget( - dContext, bert, origin, ii.colorType(), ii.refColorSpace(), props, proc, rc); -} - -sk_sp MakeBackendRenderTargetSurface(GrDirectContext* dContext, - SkISize dimensions, - GrSurfaceOrigin origin, - int sampleCnt, - SkColorType colorType, - sk_sp colorSpace, - GrProtected isProtected, - const SkSurfaceProps* props) { - auto ii = SkImageInfo::Make(dimensions, colorType, kPremul_SkAlphaType, std::move(colorSpace)); - return MakeBackendRenderTargetSurface(dContext, ii, origin, sampleCnt, isProtected, props); + context, bert, origin, colorType, std::move(colorSpace), props, proc, rc); } } // namespace sk_gpu_test diff --git a/tools/gpu/BackendSurfaceFactory.h b/tools/gpu/BackendSurfaceFactory.h index ca35a47ed0..c0177e77aa 100644 --- a/tools/gpu/BackendSurfaceFactory.h +++ b/tools/gpu/BackendSurfaceFactory.h @@ -19,14 +19,6 @@ class SkSurfaceProps; namespace sk_gpu_test { -sk_sp MakeBackendTextureSurface(GrDirectContext*, - const SkImageInfo&, - GrSurfaceOrigin, - int sampleCnt, - GrMipmapped = GrMipmapped::kNo, - GrProtected = GrProtected::kNo, - const SkSurfaceProps* = nullptr); - sk_sp MakeBackendTextureSurface(GrDirectContext*, SkISize, GrSurfaceOrigin, @@ -38,13 +30,6 @@ sk_sp MakeBackendTextureSurface(GrDirectContext*, const SkSurfaceProps* = nullptr); /** Creates an SkSurface backed by a non-textureable render target. */ -sk_sp MakeBackendRenderTargetSurface(GrDirectContext*, - const SkImageInfo&, - GrSurfaceOrigin, - int sampleCnt, - GrProtected = GrProtected::kNo, - const SkSurfaceProps* = nullptr); - sk_sp MakeBackendRenderTargetSurface(GrDirectContext*, SkISize, GrSurfaceOrigin, diff --git a/tools/gpu/BackendTextureImageFactory.cpp b/tools/gpu/BackendTextureImageFactory.cpp index e2950af590..b0faf45d70 100644 --- a/tools/gpu/BackendTextureImageFactory.cpp +++ b/tools/gpu/BackendTextureImageFactory.cpp @@ -40,36 +40,4 @@ sk_sp MakeBackendTextureImage(GrDirectContext* dContext, ManagedBackendTexture::ReleaseProc, mbet->releaseContext()); } - -sk_sp MakeBackendTextureImage(GrDirectContext* dContext, - const SkImageInfo& info, - SkColor4f color, - GrMipmapped mipmapped, - GrRenderable renderable, - GrSurfaceOrigin origin) { - if (info.alphaType() == kOpaque_SkAlphaType) { - color = color.makeOpaque(); - } else if (info.alphaType() == kPremul_SkAlphaType) { - auto pmColor = color.premul(); - color = {pmColor.fR, pmColor.fG, pmColor.fB, pmColor.fA}; - } - auto mbet = ManagedBackendTexture::MakeWithData(dContext, - info.width(), - info.height(), - info.colorType(), - color, - mipmapped, - renderable, - GrProtected::kNo); - - return SkImage::MakeFromTexture(dContext, - mbet->texture(), - origin, - info.colorType(), - info.alphaType(), - info.refColorSpace(), - ManagedBackendTexture::ReleaseProc, - mbet->releaseContext()); -} - } // namespace sk_gpu_test diff --git a/tools/gpu/BackendTextureImageFactory.h b/tools/gpu/BackendTextureImageFactory.h index 289f268818..3de31a581f 100644 --- a/tools/gpu/BackendTextureImageFactory.h +++ b/tools/gpu/BackendTextureImageFactory.h @@ -5,15 +5,12 @@ * found in the LICENSE file. */ -#include "include/core/SkColor.h" #include "include/core/SkRefCnt.h" #include "include/gpu/GrTypes.h" class GrDirectContext; -class SkColorSpace; class SkImage; class SkPixmap; -struct SkISize; namespace sk_gpu_test { /** @@ -23,17 +20,6 @@ namespace sk_gpu_test { * For testing purposes the texture can be made renderable to exercise different code paths for * renderable textures/formats. */ -sk_sp MakeBackendTextureImage(GrDirectContext*, - const SkPixmap&, - GrRenderable, - GrSurfaceOrigin); - -/** Creates an image of with a solid color. */ -sk_sp MakeBackendTextureImage(GrDirectContext*, - const SkImageInfo& info, - SkColor4f, - GrMipmapped = GrMipmapped::kNo, - GrRenderable = GrRenderable::kNo, - GrSurfaceOrigin = GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin); - +sk_sp MakeBackendTextureImage(GrDirectContext*, const SkPixmap&, + GrRenderable, GrSurfaceOrigin); } // namespace sk_gpu_test diff --git a/tools/gpu/ManagedBackendTexture.cpp b/tools/gpu/ManagedBackendTexture.cpp index 192a57ca10..8409caa409 100644 --- a/tools/gpu/ManagedBackendTexture.cpp +++ b/tools/gpu/ManagedBackendTexture.cpp @@ -7,27 +7,10 @@ #include "tools/gpu/ManagedBackendTexture.h" -#include "include/core/SkImageInfo.h" -#include "include/private/GrTypesPriv.h" -#include "src/core/SkMipmap.h" - -namespace { - -struct Context { - sk_sp fMBET; - GrGpuFinishedProc fWrappedProc = nullptr; - GrGpuFinishedContext fWrappedContext = nullptr; -}; - -} // anonymous namespace - namespace sk_gpu_test { -void ManagedBackendTexture::ReleaseProc(void* ctx) { - std::unique_ptr context(static_cast(ctx)); - if (context->fWrappedProc) { - context->fWrappedProc(context->fWrappedContext); - } +void ManagedBackendTexture::ReleaseProc(void* context) { + static_cast(context)->unref(); } ManagedBackendTexture::~ManagedBackendTexture() { @@ -36,49 +19,9 @@ ManagedBackendTexture::~ManagedBackendTexture() { } } -void* ManagedBackendTexture::releaseContext(GrGpuFinishedProc wrappedProc, - GrGpuFinishedContext wrappedCtx) const { - // Make sure we don't get a wrapped ctx without a wrapped proc - SkASSERT(!wrappedCtx || wrappedProc); - return new Context{sk_ref_sp(this), wrappedProc, wrappedCtx}; -} - -sk_sp ManagedBackendTexture::refCountedCallback() const { - return sk_make_sp(ReleaseProc, this->releaseContext()); -} - -void ManagedBackendTexture::wasAdopted() { fTexture = {}; } - -sk_sp ManagedBackendTexture::MakeFromInfo(GrDirectContext* dContext, - const SkImageInfo& ii, - GrMipmapped mipmapped, - GrRenderable renderable, - GrProtected isProtected) { - return MakeWithoutData( - dContext, ii.width(), ii.height(), ii.colorType(), mipmapped, renderable, isProtected); -} - -sk_sp ManagedBackendTexture::MakeFromBitmap(GrDirectContext* dContext, - const SkBitmap& bitmap, - GrMipmapped mipmapped, - GrRenderable renderable, - GrProtected isProtected) { - std::vector levels({bitmap.pixmap()}); - std::unique_ptr mm; - - if (mipmapped == GrMipmapped::kYes) { - mm.reset(SkMipmap::Build(bitmap, nullptr)); - if (!mm) { - return nullptr; - } - for (int i = 0; i < mm->countLevels(); ++i) { - SkMipmap::Level level; - SkAssertResult(mm->getLevel(i, &level)); - levels.push_back(level.fPixmap); - } - } - return MakeWithData( - dContext, levels.data(), static_cast(levels.size()), renderable, isProtected); +void* ManagedBackendTexture::releaseContext() { + this->ref(); + return static_cast(this); } } // namespace sk_gpu_test diff --git a/tools/gpu/ManagedBackendTexture.h b/tools/gpu/ManagedBackendTexture.h index 931e71b687..cd3b023987 100644 --- a/tools/gpu/ManagedBackendTexture.h +++ b/tools/gpu/ManagedBackendTexture.h @@ -11,9 +11,6 @@ #include "include/core/SkRefCnt.h" #include "include/gpu/GrDirectContext.h" -class GrRefCntedCallback; -struct SkImageInfo; - namespace sk_gpu_test { class ManagedBackendTexture : public SkNVRefCnt { @@ -37,19 +34,6 @@ public: template static sk_sp MakeWithoutData(GrDirectContext*, Args&&...); - - static sk_sp MakeFromInfo(GrDirectContext* dContext, - const SkImageInfo&, - GrMipmapped = GrMipmapped::kNo, - GrRenderable = GrRenderable::kNo, - GrProtected = GrProtected::kNo); - - static sk_sp MakeFromBitmap(GrDirectContext*, - const SkBitmap&, - GrMipmapped, - GrRenderable, - GrProtected = GrProtected::kNo); - /** GrGpuFinishedProc or image/surface release proc. */ static void ReleaseProc(void* context); @@ -57,18 +41,9 @@ public: /** * The context to use with ReleaseProc. This adds a ref so it *must* be balanced by a call to - * ReleaseProc. If a wrappedProc is provided then it will be called by ReleaseProc. + * ReleaseProc. */ - void* releaseContext(GrGpuFinishedProc wrappedProc = nullptr, - GrGpuFinishedContext wrappedContext = nullptr) const; - - sk_sp refCountedCallback() const; - - /** - * Call if the underlying GrBackendTexture was adopted by a GrContext. This clears this out the - * MBET without deleting the texture. - */ - void wasAdopted(); + void* releaseContext(); const GrBackendTexture& texture() { return fTexture; } @@ -77,7 +52,7 @@ private: ManagedBackendTexture(const ManagedBackendTexture&) = delete; ManagedBackendTexture(ManagedBackendTexture&&) = delete; - sk_sp fDContext; + GrDirectContext* fDContext = nullptr; GrBackendTexture fTexture; }; @@ -85,7 +60,7 @@ template inline sk_sp ManagedBackendTexture::MakeWithData(GrDirectContext* dContext, Args&&... args) { sk_sp mbet(new ManagedBackendTexture); - mbet->fDContext = sk_ref_sp(dContext); + mbet->fDContext = dContext; mbet->fTexture = dContext->createBackendTexture(std::forward(args)..., ReleaseProc, mbet->releaseContext()); @@ -97,7 +72,7 @@ inline sk_sp ManagedBackendTexture::MakeWithoutData( GrDirectContext* dContext, Args&&... args) { sk_sp mbet(new ManagedBackendTexture); - mbet->fDContext = sk_ref_sp(dContext); + mbet->fDContext = dContext; mbet->fTexture = dContext->createBackendTexture(std::forward(args)...); return mbet; } diff --git a/tools/gpu/vk/VkTestHelper.cpp b/tools/gpu/vk/VkTestHelper.cpp index 12c6807475..57dc666a72 100644 --- a/tools/gpu/vk/VkTestHelper.cpp +++ b/tools/gpu/vk/VkTestHelper.cpp @@ -86,12 +86,6 @@ bool VkTestHelper::init() { } void VkTestHelper::cleanup() { - // Make sure any work, release procs, etc left on the context are finished with before we start - // tearing everything down. - if (fDirectContext) { - fDirectContext->flushAndSubmit(true); - } - fDirectContext.reset(); fBackendContext.fMemoryAllocator.reset();