From 26caf898f1db66bc6923b61ef902132bbdff51dd Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Fri, 27 Jan 2017 10:58:31 -0500 Subject: [PATCH] Add utilities to create GrSurfaceProxy & GrSurfaceContext from backend descs Change-Id: Iff2278de8ddd6c0dff74e5cf1996702bad31217b Reviewed-on: https://skia-review.googlesource.com/7647 Reviewed-by: Brian Osman Commit-Queue: Robert Phillips --- include/private/GrSurfaceProxy.h | 5 +++++ src/gpu/GrContext.cpp | 15 +++++++++++++++ src/gpu/GrContextPriv.h | 10 +++++----- src/gpu/GrSurfaceProxy.cpp | 7 +++++++ src/image/SkImage_Gpu.cpp | 14 +++----------- tests/EGLImageTest.cpp | 37 ++++++++++++++++--------------------- tests/RectangleTextureTest.cpp | 23 ++++++----------------- 7 files changed, 57 insertions(+), 54 deletions(-) diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h index 6f2a751..a08cb26 100644 --- a/include/private/GrSurfaceProxy.h +++ b/include/private/GrSurfaceProxy.h @@ -178,6 +178,11 @@ public: const GrSurfaceDesc&, SkBudgeted, const void* srcData, size_t rowBytes); + static sk_sp MakeWrappedBackend( + GrContext*, + GrBackendTextureDesc&, + GrWrapOwnership ownership = kBorrow_GrWrapOwnership); + const GrSurfaceDesc& desc() const { return fDesc; } GrSurfaceOrigin origin() const { diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index db8863f..88b14f3 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -628,6 +628,21 @@ sk_sp GrContextPriv::makeDeferredSurfaceContext(const GrSurfac return this->makeWrappedSurfaceContext(std::move(proxy), nullptr); } +sk_sp GrContextPriv::makeBackendSurfaceContext(const GrBackendTextureDesc& desc, + sk_sp colorSpace, + GrWrapOwnership ownership) { + ASSERT_SINGLE_OWNER_PRIV + + sk_sp surface(fContext->textureProvider()->wrapBackendTexture(desc, ownership)); + if (!surface) { + return nullptr; + } + + sk_sp proxy(GrSurfaceProxy::MakeWrapped(std::move(surface))); + + return this->makeWrappedSurfaceContext(std::move(proxy), std::move(colorSpace)); +} + sk_sp GrContextPriv::makeBackendTextureRenderTargetContext( const GrBackendTextureDesc& desc, sk_sp colorSpace, diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index ed9691c..8ad3483 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -35,11 +35,11 @@ public: SkBackingFit dstFit, SkBudgeted isDstBudgeted); - // TODO: add: - // sk_sp makeBackendSurfaceContext(const GrBackendTextureDesc& desc, - // sk_sp colorSpace, - // GrWrapOwnership = kBorrow_GrWrapOwnership); - // Maybe add a 'surfaceProps' param that is ignored for non-RTs? + // TODO: Maybe add a 'surfaceProps' param (that is ignored for non-RTs) and remove + // makeBackendTextureRenderTargetContext & makeBackendTextureAsRenderTargetRenderTargetContext + sk_sp makeBackendSurfaceContext(const GrBackendTextureDesc& desc, + sk_sp colorSpace, + GrWrapOwnership = kBorrow_GrWrapOwnership); sk_sp makeBackendTextureRenderTargetContext( const GrBackendTextureDesc& desc, diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index 4cf4611..1e9ac9b 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -159,6 +159,13 @@ sk_sp GrSurfaceProxy::MakeDeferred(const GrCaps& caps, return GrSurfaceProxy::MakeDeferred(caps, desc, SkBackingFit::kExact, budgeted); } +sk_sp GrSurfaceProxy::MakeWrappedBackend(GrContext* context, + GrBackendTextureDesc& desc, + GrWrapOwnership ownership) { + sk_sp tex(context->textureProvider()->wrapBackendTexture(desc, ownership)); + return GrSurfaceProxy::MakeWrapped(std::move(tex)); +} + #ifdef SK_DEBUG void GrSurfaceProxy::validate(GrContext* context) const { if (fTarget) { diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index ec1968f..8a27836 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -271,14 +271,8 @@ static sk_sp make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac uDesc.fWidth = yuvSizes[1].fWidth; uDesc.fHeight = yuvSizes[1].fHeight; - sk_sp yTex( - ctx->textureProvider()->wrapBackendTexture(yDesc, kBorrow_GrWrapOwnership)); - sk_sp yProxy = GrSurfaceProxy::MakeWrapped(std::move(yTex)); - - sk_sp uTex( - ctx->textureProvider()->wrapBackendTexture(uDesc, kBorrow_GrWrapOwnership)); - sk_sp uProxy = GrSurfaceProxy::MakeWrapped(std::move(uTex)); - + sk_sp yProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, yDesc); + sk_sp uProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, uDesc); sk_sp vProxy; if (nv12) { @@ -292,9 +286,7 @@ static sk_sp make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac vDesc.fWidth = yuvSizes[2].fWidth; vDesc.fHeight = yuvSizes[2].fHeight; - sk_sp vTex = sk_sp( - ctx->textureProvider()->wrapBackendTexture(vDesc, kBorrow_GrWrapOwnership)); - vProxy = GrSurfaceProxy::MakeWrapped(std::move(vTex)); + vProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, vDesc); } if (!yProxy || !uProxy || !vProxy) { return nullptr; diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp index 02ba4a8..3011355 100644 --- a/tests/EGLImageTest.cpp +++ b/tests/EGLImageTest.cpp @@ -135,27 +135,22 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { externalDesc.fHeight = kSize; externalDesc.fTextureHandle = reinterpret_cast(&externalTexture); - sk_sp externalTextureContext; + sk_sp surfaceContext = context0->contextPriv().makeBackendSurfaceContext( + externalDesc, nullptr); - { - sk_sp externalTextureObj( - context0->textureProvider()->wrapBackendTexture(externalDesc)); - if (!externalTextureObj) { - ERRORF(reporter, "Error wrapping external texture in GrTexture."); - cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image); - return; - } - - externalTextureContext = context0->contextPriv().makeWrappedSurfaceContext( - std::move(externalTextureObj)); + if (!surfaceContext) { + ERRORF(reporter, "Error wrapping external texture in GrSurfaceContext."); + cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image); + return; } // Should not be able to wrap as a RT { externalDesc.fFlags = kRenderTarget_GrBackendTextureFlag; - sk_sp externalTextureRTObj( - context0->textureProvider()->wrapBackendTexture(externalDesc)); - if (externalTextureRTObj) { + + sk_sp temp = context0->contextPriv().makeBackendSurfaceContext( + externalDesc, nullptr); + if (temp) { ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture as a RT."); } externalDesc.fFlags = kNone_GrBackendTextureFlag; @@ -164,24 +159,24 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { // Should not be able to wrap with a sample count { externalDesc.fSampleCnt = 4; - sk_sp externalTextureMSAAObj( - context0->textureProvider()->wrapBackendTexture(externalDesc)); - if (externalTextureMSAAObj) { + sk_sp temp = context0->contextPriv().makeBackendSurfaceContext( + externalDesc, nullptr); + if (temp) { ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture with MSAA."); } externalDesc.fSampleCnt = 0; } - test_read_pixels(reporter, context0, externalTextureContext.get(), pixels.get(), + test_read_pixels(reporter, context0, surfaceContext.get(), pixels.get(), "EGLImageTest-read"); // We should not be able to write to a EXTERNAL texture - test_write_pixels(reporter, context0, externalTextureContext.get(), false, + test_write_pixels(reporter, context0, surfaceContext.get(), false, "EGLImageTest-write"); // Only test RT-config // TODO: why do we always need to draw to copy from an external texture? - test_copy_from_surface(reporter, context0, externalTextureContext->asDeferredSurface(), + test_copy_from_surface(reporter, context0, surfaceContext->asDeferredSurface(), pixels.get(), true, "EGLImageTest-copy"); cleanup(glCtx0, externalTexture.fID, glCtx1.get(), context1, backendTexture1, image); diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp index d55b882..ef5f2d3 100644 --- a/tests/RectangleTextureTest.cpp +++ b/tests/RectangleTextureTest.cpp @@ -133,23 +133,12 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) { } } - sk_sp rectProxy; - - { - sk_sp rectangleTexture( - context->textureProvider()->wrapBackendTexture(rectangleDesc)); - if (!rectangleTexture) { - ERRORF(reporter, "Error wrapping rectangle texture in GrTexture."); - GR_GL_CALL(glContext->gl(), DeleteTextures(1, &rectTexID)); - continue; - } - - rectProxy = GrSurfaceProxy::MakeWrapped(std::move(rectangleTexture)); - if (!rectProxy) { - ERRORF(reporter, "Error creating proxy for rectangle texture."); - GR_GL_CALL(glContext->gl(), DeleteTextures(1, &rectTexID)); - continue; - } + sk_sp rectProxy = GrSurfaceProxy::MakeWrappedBackend(context, + rectangleDesc); + if (!rectProxy) { + ERRORF(reporter, "Error creating proxy for rectangle texture."); + GR_GL_CALL(glContext->gl(), DeleteTextures(1, &rectTexID)); + continue; } test_basic_draw_as_src(reporter, context, rectProxy, refPixels); -- 2.7.4