From f7778979343998e4c10df8ebe43f02e60c700f0d Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Thu, 8 Mar 2018 10:13:17 -0500 Subject: Delazify wrapped backend textures/render target proxies These methods will fail on DDL contexts. This is in preparation for removing the ability to specify origin for lazy proxies. Change-Id: Iadcedfd4fce8ea2590729c974128e5c58cec38a8 Reviewed-on: https://skia-review.googlesource.com/112802 Commit-Queue: Brian Salomon Reviewed-by: Greg Daniel --- src/gpu/GrProxyProvider.cpp | 213 +++++++++++--------------------------------- src/gpu/gl/GrGLCaps.cpp | 7 -- src/gpu/gl/GrGLCaps.h | 1 - 3 files changed, 51 insertions(+), 170 deletions(-) (limited to 'src/gpu') diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp index 758a0d1601..dbd49a7ac3 100644 --- a/src/gpu/GrProxyProvider.cpp +++ b/src/gpu/GrProxyProvider.cpp @@ -408,51 +408,28 @@ sk_sp GrProxyProvider::wrapBackendTexture(const GrBackendTexture return nullptr; } - GrSurfaceDesc desc; - desc.fWidth = backendTex.width(); - desc.fHeight = backendTex.height(); - desc.fConfig = backendTex.config(); - GrMipMapped mipMapped = backendTex.hasMipMaps() ? GrMipMapped::kYes : GrMipMapped::kNo; + // This is only supported on a direct GrContext. + if (!fResourceProvider) { + return nullptr; + } + + sk_sp tex = fResourceProvider->wrapBackendTexture(backendTex, ownership); + if (!tex) { + return nullptr; + } sk_sp releaseHelper; if (releaseProc) { releaseHelper.reset(new GrReleaseProcHelper(releaseProc, releaseCtx)); + // This gives the texture a ref on the releaseHelper + tex->setRelease(releaseHelper); } - sk_sp proxy = this->createLazyProxy( - [backendTex, ownership, releaseHelper](GrResourceProvider* resourceProvider) { - if (!resourceProvider) { - // If this had a releaseHelper it will get unrefed when we delete this lambda - // and will call the release proc so that the client knows they can free the - // underlying backend object. - return sk_sp(); - } + SkASSERT(!tex->asRenderTarget()); // Strictly a GrTexture + // Make sure we match how we created the proxy with SkBudgeted::kNo + SkASSERT(SkBudgeted::kNo == tex->resourcePriv().isBudgeted()); - sk_sp tex = resourceProvider->wrapBackendTexture(backendTex, - ownership); - if (!tex) { - return sk_sp(); - } - if (releaseHelper) { - // This gives the texture a ref on the releaseHelper - tex->setRelease(releaseHelper); - } - SkASSERT(!tex->asRenderTarget()); // Strictly a GrTexture - // Make sure we match how we created the proxy with SkBudgeted::kNo - SkASSERT(SkBudgeted::kNo == tex->resourcePriv().isBudgeted()); - - return tex; - }, - desc, origin, mipMapped, SkBackingFit::kExact, SkBudgeted::kNo); - - if (fResourceProvider) { - // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however, - // we're better off instantiating the proxy immediately here. - if (!proxy->priv().doLazyInstantiation(fResourceProvider)) { - return nullptr; - } - } - return proxy; + return sk_sp(new GrTextureProxy(std::move(tex), origin)); } sk_sp GrProxyProvider::wrapRenderableBackendTexture( @@ -462,54 +439,27 @@ sk_sp GrProxyProvider::wrapRenderableBackendTexture( return nullptr; } + // This is only supported on a direct GrContext. + if (!fResourceProvider) { + return nullptr; + } + sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, backendTex.config()); if (!sampleCnt) { return nullptr; } - GrSurfaceDesc desc; - desc.fWidth = backendTex.width(); - desc.fHeight = backendTex.height(); - desc.fConfig = backendTex.config(); - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fSampleCnt = sampleCnt; - GrMipMapped mipMapped = backendTex.hasMipMaps() ? GrMipMapped::kYes : GrMipMapped::kNo; - - GrRenderTargetFlags renderTargetFlags = GrRenderTargetFlags::kNone; - if (fCaps->usesMixedSamples() && sampleCnt > 1) { - renderTargetFlags |= GrRenderTargetFlags::kMixedSampled; - } - if (fCaps->maxWindowRectangles() > 0) { - renderTargetFlags |= GrRenderTargetFlags::kWindowRectsSupport; + sk_sp tex = + fResourceProvider->wrapRenderableBackendTexture(backendTex, sampleCnt, ownership); + if (!tex) { + return nullptr; } - sk_sp proxy = this->createLazyProxy( - [backendTex, sampleCnt, ownership](GrResourceProvider* resourceProvider) { - if (!resourceProvider) { - return sk_sp(); - } - - sk_sp tex = resourceProvider->wrapRenderableBackendTexture( - backendTex, sampleCnt, ownership); - if (!tex) { - return sk_sp(); - } - SkASSERT(tex->asRenderTarget()); // A GrTextureRenderTarget - // Make sure we match how we created the proxy with SkBudgeted::kNo - SkASSERT(SkBudgeted::kNo == tex->resourcePriv().isBudgeted()); + SkASSERT(tex->asRenderTarget()); // A GrTextureRenderTarget + // Make sure we match how we created the proxy with SkBudgeted::kNo + SkASSERT(SkBudgeted::kNo == tex->resourcePriv().isBudgeted()); - return tex; - }, - desc, origin, mipMapped, renderTargetFlags, SkBackingFit::kExact, SkBudgeted::kNo); - - if (fResourceProvider) { - // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however, - // we're better off instantiating the proxy immediately here. - if (!proxy->priv().doLazyInstantiation(fResourceProvider)) { - return nullptr; - } - } - return proxy; + return sk_sp(new GrTextureRenderTargetProxy(std::move(tex), origin)); } sk_sp GrProxyProvider::wrapBackendRenderTarget( @@ -518,49 +468,21 @@ sk_sp GrProxyProvider::wrapBackendRenderTarget( return nullptr; } - GrSurfaceDesc desc; - desc.fWidth = backendRT.width(); - desc.fHeight = backendRT.height(); - desc.fConfig = backendRT.config(); - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fSampleCnt = backendRT.sampleCnt(); - - GrRenderTargetFlags renderTargetFlags = GrRenderTargetFlags::kNone; - if (fCaps->isMixedSamplesSupportedForRT(backendRT) && backendRT.sampleCnt() > 1) { - renderTargetFlags |= GrRenderTargetFlags::kMixedSampled; - } - if (fCaps->isWindowRectanglesSupportedForRT(backendRT)) { - renderTargetFlags |= GrRenderTargetFlags::kWindowRectsSupport; + // This is only supported on a direct GrContext. + if (!fResourceProvider) { + return nullptr; } - sk_sp proxy = this->createLazyRenderTargetProxy( - [backendRT](GrResourceProvider* resourceProvider) { - if (!resourceProvider) { - return sk_sp(); - } - - sk_sp rt = resourceProvider->wrapBackendRenderTarget(backendRT); - if (!rt) { - return sk_sp(); - } - SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable - SkASSERT(!rt->getUniqueKey().isValid()); - // Make sure we match how we created the proxy with SkBudgeted::kNo - SkASSERT(SkBudgeted::kNo == rt->resourcePriv().isBudgeted()); - - return rt; - }, - desc, origin, renderTargetFlags, Textureable::kNo, GrMipMapped::kNo, - SkBackingFit::kExact, SkBudgeted::kNo); - - if (fResourceProvider) { - // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however, - // we're better off instantiating the proxy immediately here. - if (!proxy->priv().doLazyInstantiation(fResourceProvider)) { - return nullptr; - } + sk_sp rt = fResourceProvider->wrapBackendRenderTarget(backendRT); + if (!rt) { + return nullptr; } - return proxy; + SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable + SkASSERT(!rt->getUniqueKey().isValid()); + // Make sure we match how we created the proxy with SkBudgeted::kNo + SkASSERT(SkBudgeted::kNo == rt->resourcePriv().isBudgeted()); + + return sk_sp(new GrRenderTargetProxy(std::move(rt), origin)); } sk_sp GrProxyProvider::wrapBackendTextureAsRenderTarget( @@ -569,55 +491,22 @@ sk_sp GrProxyProvider::wrapBackendTextureAsRenderTarget( return nullptr; } - sampleCnt = this->caps()->getRenderTargetSampleCount(sampleCnt, backendTex.config()); - if (!sampleCnt) { + // This is only supported on a direct GrContext. + if (!fResourceProvider) { return nullptr; } - GrSurfaceDesc desc; - desc.fWidth = backendTex.width(); - desc.fHeight = backendTex.height(); - desc.fConfig = backendTex.config(); - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fSampleCnt = sampleCnt; - - GrRenderTargetFlags renderTargetFlags = GrRenderTargetFlags::kNone; - if (fCaps->usesMixedSamples() && sampleCnt > 1) { - renderTargetFlags |= GrRenderTargetFlags::kMixedSampled; - } - if (fCaps->maxWindowRectangles() > 0) { - renderTargetFlags |= GrRenderTargetFlags::kWindowRectsSupport; + sk_sp rt = + fResourceProvider->wrapBackendTextureAsRenderTarget(backendTex, sampleCnt); + if (!rt) { + return nullptr; } + SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable + SkASSERT(!rt->getUniqueKey().isValid()); + // Make sure we match how we created the proxy with SkBudgeted::kNo + SkASSERT(SkBudgeted::kNo == rt->resourcePriv().isBudgeted()); - sk_sp proxy = this->createLazyRenderTargetProxy( - [backendTex, sampleCnt](GrResourceProvider* resourceProvider) { - if (!resourceProvider) { - return sk_sp(); - } - - sk_sp rt = resourceProvider->wrapBackendTextureAsRenderTarget( - backendTex, sampleCnt); - if (!rt) { - return sk_sp(); - } - SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable - SkASSERT(!rt->getUniqueKey().isValid()); - // Make sure we match how we created the proxy with SkBudgeted::kNo - SkASSERT(SkBudgeted::kNo == rt->resourcePriv().isBudgeted()); - - return rt; - }, - desc, origin, renderTargetFlags, Textureable::kNo, GrMipMapped::kNo, - SkBackingFit::kExact, SkBudgeted::kNo); - - if (fResourceProvider) { - // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however, - // we're better off instantiating the proxy immediately here. - if (!proxy->priv().doLazyInstantiation(fResourceProvider)) { - return nullptr; - } - } - return proxy; + return sk_sp(new GrRenderTargetProxy(std::move(rt), origin)); } sk_sp GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback, diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 957811e70f..aec7a37e1b 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -2452,13 +2452,6 @@ bool GrGLCaps::surfaceSupportsWritePixels(const GrSurface* surface) const { return true; } -bool GrGLCaps::onIsMixedSamplesSupportedForRT(const GrBackendRenderTarget& backendRT) const { - const GrGLFramebufferInfo* fbInfo = backendRT.getGLFramebufferInfo(); - SkASSERT(fbInfo); - // Mixed samples are not supported for FBO 0; - return fbInfo->fFBOID != 0; -} - bool GrGLCaps::onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget& backendRT) const { const GrGLFramebufferInfo* fbInfo = backendRT.getGLFramebufferInfo(); SkASSERT(fbInfo); diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h index dbcccd5edd..5d3fa6a6f6 100644 --- a/src/gpu/gl/GrGLCaps.h +++ b/src/gpu/gl/GrGLCaps.h @@ -435,7 +435,6 @@ private: void onApplyOptionsOverrides(const GrContextOptions& options) override; - bool onIsMixedSamplesSupportedForRT(const GrBackendRenderTarget&) const override; bool onIsWindowRectanglesSupportedForRT(const GrBackendRenderTarget&) const override; void initFSAASupport(const GrContextOptions& contextOptions, const GrGLContextInfo&, -- cgit v1.2.3