aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2018-01-23 16:38:14 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-24 15:12:30 +0000
commitf2336e4500769bc0ff6a208289d757581b0ea91a (patch)
tree097f306d11e48aea68f6e2df26f0e3d3ef031c1c /src/gpu
parent4e69f14814d14fd44aa93404656280b388419265 (diff)
Add lazy proxy's for wrapping backend textures
Bug: skia: Change-Id: I3bb557cefc35312adc9515b5683d2ed747bb4eb3 Reviewed-on: https://skia-review.googlesource.com/96862 Commit-Queue: Greg Daniel <egdaniel@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrBackendTextureImageGenerator.cpp6
-rw-r--r--src/gpu/GrProxyProvider.cpp51
-rw-r--r--src/gpu/GrSurfaceProxy.cpp14
3 files changed, 55 insertions, 16 deletions
diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp
index b07115ef2d..064727e248 100644
--- a/src/gpu/GrBackendTextureImageGenerator.cpp
+++ b/src/gpu/GrBackendTextureImageGenerator.cpp
@@ -114,15 +114,14 @@ sk_sp<GrTextureProxy> GrBackendTextureImageGenerator::onGenerateTexture(
// Must make copies of member variables to capture in the lambda since this image generator may
// be deleted before we actuallly execute the lambda.
- GrSurfaceOrigin surfaceOrigin = fSurfaceOrigin;
sk_sp<GrSemaphore> semaphore = fSemaphore;
GrBackendTexture backendTexture = fBackendTexture;
RefHelper* refHelper = fRefHelper;
refHelper->ref();
sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
- [refHelper, semaphore, backendTexture, surfaceOrigin]
- (GrResourceProvider* resourceProvider, GrSurfaceOrigin* outOrigin) {
+ [refHelper, semaphore, backendTexture]
+ (GrResourceProvider* resourceProvider, GrSurfaceOrigin* /*outOrigin*/) {
if (!resourceProvider) {
// If we get here then we never created a texture to pass the refHelper ref off
// to. Thus we must unref it ourselves.
@@ -168,7 +167,6 @@ sk_sp<GrTextureProxy> GrBackendTextureImageGenerator::onGenerateTexture(
tex->setRelease(ReleaseRefHelper_TextureReleaseProc, refHelper);
}
- *outOrigin = surfaceOrigin;
return tex;
}, desc, mipMapped, SkBackingFit::kExact, SkBudgeted::kNo);
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index c49f6b8ea0..1267750687 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -330,17 +330,46 @@ sk_sp<GrTextureProxy> GrProxyProvider::createWrappedTextureProxy(
return nullptr;
}
- sk_sp<GrTexture> texture(fResourceProvider->wrapBackendTexture(backendTex, ownership));
- if (!texture) {
- return nullptr;
- }
- if (releaseProc) {
- texture->setRelease(releaseProc, releaseCtx);
- }
-
- SkASSERT(!texture->asRenderTarget()); // Strictly a GrTexture
-
- return this->createWrapped(std::move(texture), origin);
+ GrSurfaceDesc desc;
+ desc.fOrigin = origin;
+ desc.fWidth = backendTex.width();
+ desc.fHeight = backendTex.height();
+ desc.fConfig = backendTex.config();
+ GrMipMapped mipMapped = backendTex.hasMipMaps() ? GrMipMapped::kYes : GrMipMapped::kNo;
+
+ sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
+ [backendTex, ownership, releaseProc, releaseCtx]
+ (GrResourceProvider* resourceProvider, GrSurfaceOrigin* /*outOrigin*/) {
+ if (!resourceProvider) {
+ // This lazy proxy was never initialized. If it has a releaseProc we must call
+ // it now so that the client knows they can free the underlying backend object.
+ if (releaseProc) {
+ releaseProc(releaseCtx);
+ }
+ return sk_sp<GrTexture>();
+ }
+
+ sk_sp<GrTexture> tex = resourceProvider->wrapBackendTexture(backendTex,
+ ownership);
+ if (!tex) {
+ return sk_sp<GrTexture>();
+ }
+ if (releaseProc) {
+ tex->setRelease(releaseProc, releaseCtx);
+ }
+ 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, 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.
+ proxy->priv().doLazyInstantiation(fResourceProvider);
+ }
+ return proxy;
}
sk_sp<GrTextureProxy> GrProxyProvider::createWrappedTextureProxy(const GrBackendTexture& tex,
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index 9dadaca506..08e4dd3128 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -351,7 +351,19 @@ void GrSurfaceProxyPriv::doLazyInstantiation(GrResourceProvider* resourceProvide
SkASSERT(fProxy->fLazyInstantiateCallback);
SkASSERT(!fProxy->fTarget);
- sk_sp<GrTexture> texture = fProxy->fLazyInstantiateCallback(resourceProvider, &fProxy->fOrigin);
+ GrSurfaceOrigin* outOrigin;
+ if (GrSurfaceProxy::LazyState::kPartially == fProxy->lazyInstantiationState()) {
+ // In the partially instantiated case, we set the origin on the SurfaceProxy at creation
+ // time (via a GrSurfaceDesc). In the lambda, the creation of the texture never needs to
+ // know the origin, and it also can't change or have any effect on it. Thus we just pass in
+ // nullptr in this case since it should never be set.
+ outOrigin = nullptr;
+ } else {
+ outOrigin = &fProxy->fOrigin;
+ }
+
+ sk_sp<GrTexture> texture = fProxy->fLazyInstantiateCallback(resourceProvider, outOrigin);
+
// Indicate we are no longer pending lazy instantiation.
fProxy->fLazyInstantiateCallback = nullptr;