diff options
-rw-r--r-- | src/gpu/GrProxyProvider.cpp | 9 | ||||
-rw-r--r-- | src/gpu/GrProxyProvider.h | 3 | ||||
-rw-r--r-- | tools/gpu/ProxyUtils.cpp | 45 |
3 files changed, 43 insertions, 14 deletions
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp index 5091228a60..758a0d1601 100644 --- a/src/gpu/GrProxyProvider.cpp +++ b/src/gpu/GrProxyProvider.cpp @@ -456,7 +456,8 @@ sk_sp<GrTextureProxy> GrProxyProvider::wrapBackendTexture(const GrBackendTexture } sk_sp<GrTextureProxy> GrProxyProvider::wrapRenderableBackendTexture( - const GrBackendTexture& backendTex, GrSurfaceOrigin origin, int sampleCnt) { + const GrBackendTexture& backendTex, GrSurfaceOrigin origin, int sampleCnt, + GrWrapOwnership ownership) { if (this->isAbandoned()) { return nullptr; } @@ -483,13 +484,13 @@ sk_sp<GrTextureProxy> GrProxyProvider::wrapRenderableBackendTexture( } sk_sp<GrTextureProxy> proxy = this->createLazyProxy( - [backendTex, sampleCnt](GrResourceProvider* resourceProvider) { + [backendTex, sampleCnt, ownership](GrResourceProvider* resourceProvider) { if (!resourceProvider) { return sk_sp<GrTexture>(); } - sk_sp<GrTexture> tex = resourceProvider->wrapRenderableBackendTexture(backendTex, - sampleCnt); + sk_sp<GrTexture> tex = resourceProvider->wrapRenderableBackendTexture( + backendTex, sampleCnt, ownership); if (!tex) { return sk_sp<GrTexture>(); } diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h index 0500e2f17c..2f2eeb1113 100644 --- a/src/gpu/GrProxyProvider.h +++ b/src/gpu/GrProxyProvider.h @@ -129,7 +129,8 @@ public: */ sk_sp<GrTextureProxy> wrapRenderableBackendTexture(const GrBackendTexture&, GrSurfaceOrigin, - int sampleCnt); + int sampleCnt, + GrWrapOwnership = kBorrow_GrWrapOwnership); /* * Create a render target proxy that wraps a backend rendertarget diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp index e02bf5fd26..0102eda9e7 100644 --- a/tools/gpu/ProxyUtils.cpp +++ b/tools/gpu/ProxyUtils.cpp @@ -6,8 +6,10 @@ */ #include "ProxyUtils.h" +#include "GrBackendSurface.h" #include "GrContextPriv.h" #include "GrDrawingManager.h" +#include "GrGpu.h" #include "GrProxyProvider.h" namespace sk_gpu_test { @@ -16,15 +18,40 @@ sk_sp<GrTextureProxy> MakeTextureProxyFromData(GrContext* context, bool isRT, in GrColorType ct, GrSRGBEncoded srgbEncoded, GrSurfaceOrigin origin, const void* data, size_t rowBytes) { - GrSurfaceDesc desc; - desc.fConfig = GrColorTypeToPixelConfig(ct, srgbEncoded); - desc.fWidth = width; - desc.fHeight = height; - desc.fFlags = isRT ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags; - auto proxy = context->contextPriv().proxyProvider()->createProxy( - desc, origin, SkBackingFit::kExact, SkBudgeted::kYes); - if (!proxy) { - return nullptr; + auto config = GrColorTypeToPixelConfig(ct, srgbEncoded); + sk_sp<GrTextureProxy> proxy; + if (kBottomLeft_GrSurfaceOrigin == origin) { + // We (soon will) only support using kBottomLeft with wrapped textures. + auto backendTex = context->contextPriv().getGpu()->createTestingOnlyBackendTexture( + nullptr, width, height, config, isRT, GrMipMapped::kNo); + if (!backendTex.isValid()) { + return nullptr; + } + // Adopt ownership so our caller doesn't have to worry about deleting the backend texture. + if (isRT) { + proxy = context->contextPriv().proxyProvider()->wrapRenderableBackendTexture( + backendTex, origin, 1, kAdopt_GrWrapOwnership); + } else { + proxy = context->contextPriv().proxyProvider()->wrapBackendTexture( + backendTex, origin, kAdopt_GrWrapOwnership); + } + + if (!proxy) { + context->contextPriv().getGpu()->deleteTestingOnlyBackendTexture(&backendTex); + return nullptr; + } + + } else { + GrSurfaceDesc desc; + desc.fConfig = config; + desc.fWidth = width; + desc.fHeight = height; + desc.fFlags = isRT ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags; + proxy = context->contextPriv().proxyProvider()->createProxy( + desc, origin, SkBackingFit::kExact, SkBudgeted::kYes); + if (!proxy) { + return nullptr; + } } auto sContext = context->contextPriv().makeWrappedSurfaceContext(proxy, nullptr); if (!sContext) { |