From 7fa5c31c2c9af834bee66d5fcf476e250076c8d6 Mon Sep 17 00:00:00 2001 From: Stan Iliev Date: Wed, 19 Apr 2017 00:23:39 +0000 Subject: [PATCH] Revert "Plumb GrBackendTexture throughout skia." This reverts commit 7da62b9059f3c1d31624a0e4da96ee5f908f9c12. Reason for revert: fix android roll Original change's description: > Plumb GrBackendTexture throughout skia. > > Bug: skia: > Change-Id: I1bae6768ee7229818a83ba608035a1f7867e6875 > Reviewed-on: https://skia-review.googlesource.com/13645 > Commit-Queue: Greg Daniel > Reviewed-by: Robert Phillips > TBR=egdaniel@google.com,bsalomon@google.com,robertphillips@google.com,brianosman@google.com,reviews@skia.org,stani@google.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: I5cb8763cc837c83ebc6d10366fe2dd3efe35fb89 Reviewed-on: https://skia-review.googlesource.com/13773 Reviewed-by: Stan Iliev Commit-Queue: Stan Iliev --- gm/rectangletexture.cpp | 13 ++-- include/core/SkCrossContextImageData.h | 15 ++-- include/gpu/GrBackendSurface.h | 32 ++++----- include/gpu/GrExternalTextureData.h | 1 - include/private/GrSurfaceProxy.h | 3 +- src/gpu/GrBackendSurface.cpp | 37 ++++------ src/gpu/GrContext.cpp | 27 +++----- src/gpu/GrContextPriv.h | 13 +--- src/gpu/GrGpu.cpp | 30 ++++---- src/gpu/GrGpu.h | 17 ++--- src/gpu/GrResourceProvider.cpp | 11 ++- src/gpu/GrResourceProvider.h | 9 +-- src/gpu/GrSurfaceProxy.cpp | 8 +-- src/gpu/gl/GrGLGpu.cpp | 48 ++++++------- src/gpu/gl/GrGLGpu.h | 11 +-- src/gpu/vk/GrVkGpu.cpp | 57 +++++++-------- src/gpu/vk/GrVkGpu.h | 12 +--- src/image/SkImage_Gpu.cpp | 123 ++++++++++++++------------------- src/image/SkSurface_Gpu.cpp | 60 +++++++--------- tests/BlendTest.cpp | 19 +++-- tests/EGLImageTest.cpp | 21 +++--- tests/GrPorterDuffTest.cpp | 20 ++---- tests/GrSurfaceTest.cpp | 22 +++--- tests/ImageFilterCacheTest.cpp | 33 +++++---- tests/ImageTest.cpp | 40 +++++------ tests/RectangleTextureTest.cpp | 25 ++++--- tests/ResourceCacheTest.cpp | 37 ++++------ tests/SurfaceTest.cpp | 78 +++++++++------------ tests/VkWrapTests.cpp | 113 ++++++++++-------------------- tools/gpu/GrTest.cpp | 23 +----- tools/gpu/GrTest.h | 4 -- 31 files changed, 382 insertions(+), 580 deletions(-) diff --git a/gm/rectangletexture.cpp b/gm/rectangletexture.cpp index d4f4552..1359d34 100644 --- a/gm/rectangletexture.cpp +++ b/gm/rectangletexture.cpp @@ -11,7 +11,6 @@ #if SK_SUPPORT_GPU -#include "GrBackendSurface.h" #include "GrContext.h" #include "GrGpu.h" #include "GrTest.h" @@ -108,11 +107,13 @@ protected: GrGLTextureInfo info; info.fID = id; info.fTarget = TARGET; - - GrBackendTexture rectangleTex(width, height, kRGBA_8888_GrPixelConfig, &info); - - if (sk_sp image = SkImage::MakeFromAdoptedTexture(context, rectangleTex, - kTopLeft_GrSurfaceOrigin)) { + GrBackendTextureDesc desc; + desc.fConfig = kRGBA_8888_GrPixelConfig; + desc.fWidth = width; + desc.fHeight = height; + desc.fOrigin = kTopLeft_GrSurfaceOrigin; + desc.fTextureHandle = reinterpret_cast(&info); + if (sk_sp image = SkImage::MakeFromAdoptedTexture(context, desc)) { return image; } GR_GL_CALL(gl, DeleteTextures(1, &id)); diff --git a/include/core/SkCrossContextImageData.h b/include/core/SkCrossContextImageData.h index a408f71..beaaaa6 100644 --- a/include/core/SkCrossContextImageData.h +++ b/include/core/SkCrossContextImageData.h @@ -12,7 +12,6 @@ #include "SkImage.h" #if SK_SUPPORT_GPU -#include "GrBackendSurface.h" #include "GrExternalTextureData.h" #endif @@ -69,15 +68,16 @@ public: ~SkCCIDBackendTexture() override {} private: - SkCCIDBackendTexture(const GrBackendTexture& backendTex, - GrSurfaceOrigin origin, + SkCCIDBackendTexture(const GrBackendTextureDesc& desc, std::unique_ptr textureData, SkAlphaType alphaType, sk_sp colorSpace) : fAlphaType(alphaType) , fColorSpace(std::move(colorSpace)) - , fBackendTex(backendTex) - , fOrigin(origin) - , fTextureData(std::move(textureData)) {} + , fDesc(desc) + , fTextureData(std::move(textureData)) { + // Point our texture desc at our copy of the backend information + fDesc.fTextureHandle = fTextureData->getBackendObject(); + } sk_sp makeImage(GrContext*) override; @@ -85,8 +85,7 @@ private: // and some backend-specific info (to reconstruct the texture). SkAlphaType fAlphaType; sk_sp fColorSpace; - GrBackendTexture fBackendTex; - GrSurfaceOrigin fOrigin; + GrBackendTextureDesc fDesc; std::unique_ptr fTextureData; friend class SkCrossContextImageData; diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h index fd99a43..e588b8a 100644 --- a/include/gpu/GrBackendSurface.h +++ b/include/gpu/GrBackendSurface.h @@ -15,18 +15,14 @@ struct GrGLTextureInfo; class GrBackendTexture { public: - // The passed in GrVkImageInfo must live until the GrBackendTexture is no longer used in - // creation of SkImages or SkSurfaces. GrBackendTexture(int width, int height, - const GrVkImageInfo* vkInfo); + GrVkImageInfo* vkInfo); - // The passed in GrGLTextureInfo must live until the GrBackendTexture is no longer used in - // creation of SkImages or SkSurfaces. GrBackendTexture(int width, int height, GrPixelConfig config, - const GrGLTextureInfo* glInfo); + GrGLTextureInfo* glInfo); int width() const { return fWidth; } int height() const { return fHeight; } @@ -35,11 +31,11 @@ public: // If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise // it returns nullptr. - const GrVkImageInfo* getVkImageInfo() const; + GrVkImageInfo* getVkImageInfo(); // If the backend API is GL, this returns a pointer to the GrGLTextureInfo struct. Otherwise // it returns nullptr. - const GrGLTextureInfo* getGLTextureInfo() const; + GrGLTextureInfo* getGLTextureInfo(); private: // Temporary constructor which can be used to convert from a GrBackendTextureDesc. @@ -55,30 +51,26 @@ private: GrBackend fBackend; union { - const GrVkImageInfo* fVkInfo; - const GrGLTextureInfo* fGLInfo; + GrVkImageInfo* fVkInfo; + GrGLTextureInfo* fGLInfo; GrBackendObject fHandle; }; }; class GrBackendRenderTarget { public: - // The passed in GrVkImageInfo must live until the GrBackendTexture is no longer used in - // creation of SkImages or SkSurfaces. GrBackendRenderTarget(int width, int height, int sampleCnt, int stencilBits, - const GrVkImageInfo* vkInfo); + GrVkImageInfo* vkInfo); - // The passed in GrGLTextureInfo must live until the GrBackendTexture is no longer used in - // creation of SkImages or SkSurfaces. GrBackendRenderTarget(int width, int height, int sampleCnt, int stencilBits, GrPixelConfig config, - const GrGLTextureInfo* glInfo); + GrGLTextureInfo* glInfo); int width() const { return fWidth; } int height() const { return fHeight; } @@ -89,11 +81,11 @@ public: // If the backend API is Vulkan, this returns a pointer to the GrVkImageInfo struct. Otherwise // it returns nullptr. - const GrVkImageInfo* getVkImageInfo() const; + GrVkImageInfo* getVkImageInfo(); // If the backend API is GL, this returns a pointer to the GrGLTextureInfo struct. Otherwise // it returns nullptr. - const GrGLTextureInfo* getGLTextureInfo() const; + GrGLTextureInfo* getGLTextureInfo(); private: // Temporary constructor which can be used to convert from a GrBackendRenderTargetDesc. @@ -112,8 +104,8 @@ private: GrBackend fBackend; union { - const GrVkImageInfo* fVkInfo; - const GrGLTextureInfo* fGLInfo; + GrVkImageInfo* fVkInfo; + GrGLTextureInfo* fGLInfo; GrBackendObject fHandle; }; }; diff --git a/include/gpu/GrExternalTextureData.h b/include/gpu/GrExternalTextureData.h index b3b0594..0ebc053 100644 --- a/include/gpu/GrExternalTextureData.h +++ b/include/gpu/GrExternalTextureData.h @@ -21,7 +21,6 @@ protected: virtual GrBackendObject getBackendObject() const = 0; virtual void attachToContext(GrContext*) = 0; - friend class SkCrossContextImageData; friend class SkCCIDBackendTexture; friend class SkImage; }; diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h index eb4f281..efcec13 100644 --- a/include/private/GrSurfaceProxy.h +++ b/include/private/GrSurfaceProxy.h @@ -13,7 +13,6 @@ #include "SkRect.h" -class GrBackendTexture; class GrCaps; class GrOpList; class GrRenderTargetOpList; @@ -190,7 +189,7 @@ public: const GrSurfaceDesc&, SkBudgeted, const void* srcData, size_t rowBytes); - static sk_sp MakeWrappedBackend(GrContext*, GrBackendTexture&, GrSurfaceOrigin); + static sk_sp MakeWrappedBackend(GrContext*, GrBackendTextureDesc&); const GrSurfaceDesc& desc() const { return fDesc; } diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp index 97b3b6e..9bf85cb 100644 --- a/src/gpu/GrBackendSurface.cpp +++ b/src/gpu/GrBackendSurface.cpp @@ -10,27 +10,20 @@ #ifdef SK_VULKAN #include "vk/GrVkTypes.h" #include "vk/GrVkUtil.h" -#endif - GrBackendTexture::GrBackendTexture(int width, int height, - const GrVkImageInfo* vkInfo) + GrVkImageInfo* vkInfo) : fWidth(width) , fHeight(height) - , fConfig( -#ifdef SK_VULKAN - GrVkFormatToPixelConfig(vkInfo->fFormat) -#else - kUnknown_GrPixelConfig -#endif - ) + , fConfig(GrVkFormatToPixelConfig(vkInfo->fFormat)) , fBackend(kVulkan_GrBackend) , fVkInfo(vkInfo) {} +#endif // SK_VULKAN GrBackendTexture::GrBackendTexture(int width, int height, GrPixelConfig config, - const GrGLTextureInfo* glInfo) + GrGLTextureInfo* glInfo) : fWidth(width) , fHeight(height) , fConfig(config) @@ -50,14 +43,14 @@ GrBackendTexture::GrBackendTexture(const GrBackendTextureDesc& desc, GrBackend b , fBackend(backend) , fHandle(desc.fTextureHandle) {} -const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const { +GrVkImageInfo* GrBackendTexture::getVkImageInfo() { if (kVulkan_GrBackend == fBackend) { return fVkInfo; } return nullptr; } -const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const { +GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() { if (kOpenGL_GrBackend == fBackend) { return fGLInfo; } @@ -66,31 +59,27 @@ const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const { //////////////////////////////////////////////////////////////////////////////////////////////////// +#ifdef SK_VULKAN GrBackendRenderTarget::GrBackendRenderTarget(int width, int height, int sampleCnt, int stencilBits, - const GrVkImageInfo* vkInfo) + GrVkImageInfo* vkInfo) : fWidth(width) , fHeight(height) , fSampleCnt(sampleCnt) , fStencilBits(stencilBits) - , fConfig( -#ifdef SK_VULKAN - GrVkFormatToPixelConfig(vkInfo->fFormat) -#else - kUnknown_GrPixelConfig -#endif - ) + , fConfig(GrVkFormatToPixelConfig(vkInfo->fFormat)) , fBackend(kVulkan_GrBackend) , fVkInfo(vkInfo) {} +#endif // SK_VULKAN GrBackendRenderTarget::GrBackendRenderTarget(int width, int height, int sampleCnt, int stencilBits, GrPixelConfig config, - const GrGLTextureInfo* glInfo) + GrGLTextureInfo* glInfo) : fWidth(width) , fHeight(height) , fSampleCnt(sampleCnt) @@ -115,14 +104,14 @@ GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTargetDesc& de , fBackend(backend) , fHandle(desc.fRenderTargetHandle) {} -const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const { +GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() { if (kVulkan_GrBackend == fBackend) { return fVkInfo; } return nullptr; } -const GrGLTextureInfo* GrBackendRenderTarget::getGLTextureInfo() const { +GrGLTextureInfo* GrBackendRenderTarget::getGLTextureInfo() { if (kOpenGL_GrBackend == fBackend) { return fGLInfo; } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index f2ed5d6..234303f 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -658,15 +658,11 @@ sk_sp GrContextPriv::makeDeferredSurfaceContext(const GrSurfac return this->makeWrappedSurfaceContext(std::move(proxy), nullptr); } -sk_sp GrContextPriv::makeBackendSurfaceContext(const GrBackendTexture& tex, - GrSurfaceOrigin origin, - GrBackendTextureFlags flags, - int sampleCnt, +sk_sp GrContextPriv::makeBackendSurfaceContext(const GrBackendTextureDesc& desc, sk_sp colorSpace) { ASSERT_SINGLE_OWNER_PRIV - sk_sp surface(fContext->resourceProvider()->wrapBackendTexture(tex, origin, - flags, sampleCnt)); + sk_sp surface(fContext->resourceProvider()->wrapBackendTexture(desc)); if (!surface) { return nullptr; } @@ -680,16 +676,13 @@ sk_sp GrContextPriv::makeBackendSurfaceContext(const GrBackend } sk_sp GrContextPriv::makeBackendTextureRenderTargetContext( - const GrBackendTexture& tex, - GrSurfaceOrigin origin, - int sampleCnt, + const GrBackendTextureDesc& desc, sk_sp colorSpace, const SkSurfaceProps* props) { ASSERT_SINGLE_OWNER_PRIV + SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag); - static const GrBackendTextureFlags kForceRT = kRenderTarget_GrBackendTextureFlag; - sk_sp surface(fContext->resourceProvider()->wrapBackendTexture(tex, origin, kForceRT, - sampleCnt)); + sk_sp surface(fContext->resourceProvider()->wrapBackendTexture(desc)); if (!surface) { return nullptr; } @@ -725,17 +718,13 @@ sk_sp GrContextPriv::makeBackendRenderTargetRenderTargetC } sk_sp GrContextPriv::makeBackendTextureAsRenderTargetRenderTargetContext( - const GrBackendTexture& tex, - GrSurfaceOrigin origin, - int sampleCnt, + const GrBackendTextureDesc& desc, sk_sp colorSpace, const SkSurfaceProps* surfaceProps) { ASSERT_SINGLE_OWNER_PRIV + SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag); - sk_sp surface(fContext->resourceProvider()->wrapBackendTextureAsRenderTarget( - tex, - origin, - sampleCnt)); + sk_sp surface(fContext->resourceProvider()->wrapBackendTextureAsRenderTarget(desc)); if (!surface) { return nullptr; } diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index c85ac2c..9fa1077 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -38,16 +38,11 @@ public: // TODO: Maybe add a 'surfaceProps' param (that is ignored for non-RTs) and remove // makeBackendTextureRenderTargetContext & makeBackendTextureAsRenderTargetRenderTargetContext - sk_sp makeBackendSurfaceContext(const GrBackendTexture& tex, - GrSurfaceOrigin origin, - GrBackendTextureFlags flags, - int sampleCnt, + sk_sp makeBackendSurfaceContext(const GrBackendTextureDesc& desc, sk_sp colorSpace); sk_sp makeBackendTextureRenderTargetContext( - const GrBackendTexture& tex, - GrSurfaceOrigin origin, - int sampleCnt, + const GrBackendTextureDesc& desc, sk_sp colorSpace, const SkSurfaceProps* = nullptr); @@ -57,9 +52,7 @@ public: const SkSurfaceProps* = nullptr); sk_sp makeBackendTextureAsRenderTargetRenderTargetContext( - const GrBackendTexture& tex, - GrSurfaceOrigin origin, - int sampleCnt, + const GrBackendTextureDesc& desc, sk_sp colorSpace, const SkSurfaceProps* = nullptr); diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index 940bfea..d4fdb19 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -8,7 +8,6 @@ #include "GrGpu.h" -#include "GrBackendSurface.h" #include "GrBuffer.h" #include "GrCaps.h" #include "GrContext.h" @@ -193,25 +192,21 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget return tex; } -sk_sp GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, - GrSurfaceOrigin origin, - GrBackendTextureFlags flags, - int sampleCnt, +sk_sp GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) { this->handleDirtyContext(); - if (!this->caps()->isConfigTexturable(backendTex.config())) { + if (!this->caps()->isConfigTexturable(desc.fConfig)) { return nullptr; } - if ((flags & kRenderTarget_GrBackendTextureFlag) && - !this->caps()->isConfigRenderable(backendTex.config(), sampleCnt > 0)) { + if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && + !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { return nullptr; } int maxSize = this->caps()->maxTextureSize(); - if (backendTex.width() > maxSize || backendTex.height() > maxSize) { + if (desc.fWidth > maxSize || desc.fHeight > maxSize) { return nullptr; } - sk_sp tex = this->onWrapBackendTexture(backendTex, origin, flags, sampleCnt, - ownership); + sk_sp tex = this->onWrapBackendTexture(desc, ownership); if (!tex) { return nullptr; } @@ -231,18 +226,19 @@ sk_sp GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget return this->onWrapBackendRenderTarget(desc); } -sk_sp GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, - GrSurfaceOrigin origin, - int sampleCnt) { +sk_sp GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc) { this->handleDirtyContext(); - if (!this->caps()->isConfigRenderable(tex.config(), sampleCnt > 0)) { + if (!(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) { + return nullptr; + } + if (!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { return nullptr; } int maxSize = this->caps()->maxTextureSize(); - if (tex.width() > maxSize || tex.height() > maxSize) { + if (desc.fWidth > maxSize || desc.fHeight > maxSize) { return nullptr; } - return this->onWrapBackendTextureAsRenderTarget(tex, origin, sampleCnt); + return this->onWrapBackendTextureAsRenderTarget(desc); } GrBuffer* GrGpu::createBuffer(size_t size, GrBufferType intendedType, diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index ad1b199..df8cb08 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -124,8 +124,7 @@ public: /** * Implements GrResourceProvider::wrapBackendTexture */ - sk_sp wrapBackendTexture(const GrBackendTexture&, GrSurfaceOrigin, - GrBackendTextureFlags, int sampleCnt, GrWrapOwnership); + sk_sp wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership); /** * Implements GrResourceProvider::wrapBackendRenderTarget @@ -135,9 +134,7 @@ public: /** * Implements GrResourceProvider::wrapBackendTextureAsRenderTarget */ - sk_sp wrapBackendTextureAsRenderTarget(const GrBackendTexture&, - GrSurfaceOrigin, - int sampleCnt); + sk_sp wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&); /** * Creates a buffer in GPU memory. For a client-side buffer use GrBuffer::CreateCPUBacked. @@ -545,15 +542,9 @@ private: SkBudgeted budgeted, const SkTArray& texels) = 0; - virtual sk_sp onWrapBackendTexture(const GrBackendTexture&, - GrSurfaceOrigin, - GrBackendTextureFlags, - int sampleCnt, - GrWrapOwnership) = 0; + virtual sk_sp onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0; virtual sk_sp onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) = 0; - virtual sk_sp onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, - GrSurfaceOrigin, - int sampleCnt)=0; + virtual sk_sp onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&)=0; virtual GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, const void* data) = 0; diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index db86011..6299264 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -234,16 +234,13 @@ GrTexture* GrResourceProvider::refScratchTexture(const GrSurfaceDesc& inDesc, return nullptr; } -sk_sp GrResourceProvider::wrapBackendTexture(const GrBackendTexture& tex, - GrSurfaceOrigin origin, - GrBackendTextureFlags flags, - int sampleCnt, +sk_sp GrResourceProvider::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) { ASSERT_SINGLE_OWNER if (this->isAbandoned()) { return nullptr; } - return fGpu->wrapBackendTexture(tex, origin, flags, sampleCnt, ownership); + return fGpu->wrapBackendTexture(desc, ownership); } sk_sp GrResourceProvider::wrapBackendRenderTarget( @@ -463,12 +460,12 @@ GrStencilAttachment* GrResourceProvider::attachStencilAttachment(GrRenderTarget* } sk_sp GrResourceProvider::wrapBackendTextureAsRenderTarget( - const GrBackendTexture& tex, GrSurfaceOrigin origin, int sampleCnt) + const GrBackendTextureDesc& desc) { if (this->isAbandoned()) { return nullptr; } - return this->gpu()->wrapBackendTextureAsRenderTarget(tex, origin, sampleCnt); + return this->gpu()->wrapBackendTextureAsRenderTarget(desc); } sk_sp SK_WARN_UNUSED_RESULT GrResourceProvider::makeSemaphore() { diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h index c3d96ff8..676d82f 100644 --- a/src/gpu/GrResourceProvider.h +++ b/src/gpu/GrResourceProvider.h @@ -85,10 +85,7 @@ public: * * @return GrTexture object or NULL on failure. */ - sk_sp wrapBackendTexture(const GrBackendTexture& tex, - GrSurfaceOrigin origin, - GrBackendTextureFlags flags, - int sampleCnt, + sk_sp wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership = kBorrow_GrWrapOwnership); /** @@ -202,9 +199,7 @@ public: * * @return GrRenderTarget object or NULL on failure. */ - sk_sp wrapBackendTextureAsRenderTarget(const GrBackendTexture&, - GrSurfaceOrigin origin, - int sampleCnt); + sk_sp wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc); /** * Assigns a unique key to a resource. If the key is associated with another resource that diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index b55d12a..f2a90eb 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -222,11 +222,9 @@ sk_sp GrSurfaceProxy::MakeDeferred(GrResourceProvider* resourceP return GrSurfaceProxy::MakeDeferred(resourceProvider, desc, SkBackingFit::kExact, budgeted); } -sk_sp GrSurfaceProxy::MakeWrappedBackend(GrContext* context, - GrBackendTexture& backendTex, - GrSurfaceOrigin origin) { - sk_sp tex(context->resourceProvider()->wrapBackendTexture( - backendTex, origin, kNone_GrBackendTextureFlag, 0)); +sk_sp GrSurfaceProxy::MakeWrappedBackend(GrContext* context, + GrBackendTextureDesc& desc) { + sk_sp tex(context->resourceProvider()->wrapBackendTexture(desc)); return GrSurfaceProxy::MakeWrapped(std::move(tex)); } diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 8d65617..d585e09 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -8,7 +8,6 @@ #include "GrGLGpu.h" #include "../private/GrGLSL.h" -#include "GrBackendSurface.h" #include "GrFixedClip.h" #include "GrGLBuffer.h" #include "GrGLGpuCommandBuffer.h" @@ -512,18 +511,15 @@ static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) } } -sk_sp GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTex, - GrSurfaceOrigin origin, - GrBackendTextureFlags flags, - int sampleCnt, +sk_sp GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) { - const GrGLTextureInfo* info = backendTex.getGLTextureInfo(); + const GrGLTextureInfo* info = reinterpret_cast(desc.fTextureHandle); if (!info || !info->fID) { return nullptr; } - // next line relies on GrBackendTextureFlags matching GrTexture's - bool renderTarget = SkToBool(flags & kRenderTarget_GrBackendTextureFlag); + // next line relies on GrBackendTextureDesc's flags matching GrTexture's + bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag); SkASSERT(!renderTarget || kAdoptAndCache_GrWrapOwnership != ownership); // Not supported GrGLTexture::IDDesc idDesc; @@ -547,7 +543,7 @@ sk_sp GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTe // Sample count is interpreted to mean the number of samples that Gr code should allocate // for a render buffer that resolves to the texture. We don't support MSAA textures. - if (sampleCnt && !renderTarget) { + if (desc.fSampleCnt && !renderTarget) { return nullptr; } @@ -558,19 +554,19 @@ sk_sp GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTe } GrSurfaceDesc surfDesc; - surfDesc.fFlags = (GrSurfaceFlags) flags; - surfDesc.fWidth = backendTex.width(); - surfDesc.fHeight = backendTex.height(); - surfDesc.fConfig = backendTex.config(); - surfDesc.fSampleCnt = SkTMin(sampleCnt, this->caps()->maxSampleCount()); + surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; + surfDesc.fWidth = desc.fWidth; + surfDesc.fHeight = desc.fHeight; + surfDesc.fConfig = desc.fConfig; + surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); // FIXME: this should be calling resolve_origin(), but Chrome code is currently // assuming the old behaviour, which is that backend textures are always // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); - if (kDefault_GrSurfaceOrigin == origin) { + if (kDefault_GrSurfaceOrigin == desc.fOrigin) { surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; } else { - surfDesc.fOrigin = origin; + surfDesc.fOrigin = desc.fOrigin; } if (renderTarget) { @@ -607,10 +603,8 @@ sk_sp GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTa return GrGLRenderTarget::MakeWrapped(this, desc, idDesc, wrapDesc.fStencilBits); } -sk_sp GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, - GrSurfaceOrigin origin, - int sampleCnt) { - const GrGLTextureInfo* info = tex.getGLTextureInfo(); +sk_sp GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc){ + const GrGLTextureInfo* info = reinterpret_cast(desc.fTextureHandle); if (!info || !info->fID) { return nullptr; } @@ -627,19 +621,19 @@ sk_sp GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBacken } GrSurfaceDesc surfDesc; - surfDesc.fFlags = kRenderTarget_GrSurfaceFlag; - surfDesc.fWidth = tex.width(); - surfDesc.fHeight = tex.height(); - surfDesc.fConfig = tex.config(); - surfDesc.fSampleCnt = SkTMin(sampleCnt, this->caps()->maxSampleCount()); + surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; + surfDesc.fWidth = desc.fWidth; + surfDesc.fHeight = desc.fHeight; + surfDesc.fConfig = desc.fConfig; + surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); // FIXME: this should be calling resolve_origin(), but Chrome code is currently // assuming the old behaviour, which is that backend textures are always // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); - if (kDefault_GrSurfaceOrigin == origin) { + if (kDefault_GrSurfaceOrigin == desc.fOrigin) { surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; } else { - surfDesc.fOrigin = origin; + surfDesc.fOrigin = desc.fOrigin; } GrGLRenderTarget::IDDesc rtIDDesc; diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index 9bfe099..1fc2557 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -170,16 +170,9 @@ private: GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, const void* data) override; - - sk_sp onWrapBackendTexture(const GrBackendTexture&, - GrSurfaceOrigin, - GrBackendTextureFlags, - int sampleCnt, - GrWrapOwnership) override; + sk_sp onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override; sk_sp onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override; - sk_sp onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, - GrSurfaceOrigin, - int sampleCnt) override; + sk_sp onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override; gr_instanced::InstancedRendering* onCreateInstancedRendering() override; diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index 12d9876..71a8668 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -7,7 +7,6 @@ #include "GrVkGpu.h" -#include "GrBackendSurface.h" #include "GrContextOptions.h" #include "GrGeometryProcessor.h" #include "GrGpuResourceCacheAccess.h" @@ -781,39 +780,41 @@ static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin) { } } -sk_sp GrVkGpu::onWrapBackendTexture(const GrBackendTexture& backendTex, - GrSurfaceOrigin origin, - GrBackendTextureFlags flags, - int sampleCnt, +sk_sp GrVkGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) { - const GrVkImageInfo* info = backendTex.getVkImageInfo(); - if (!info) { + if (0 == desc.fTextureHandle) { return nullptr; } int maxSize = this->caps()->maxTextureSize(); - if (backendTex.width() > maxSize || backendTex.height() > maxSize) { + if (desc.fWidth > maxSize || desc.fHeight > maxSize) { return nullptr; } + const GrVkImageInfo* info = reinterpret_cast(desc.fTextureHandle); if (VK_NULL_HANDLE == info->fImage || VK_NULL_HANDLE == info->fAlloc.fMemory) { return nullptr; } - - SkASSERT(backendTex.config() == GrVkFormatToPixelConfig(info->fFormat)); +#ifdef SK_DEBUG + VkFormat format; + if (!GrPixelConfigToVkFormat(desc.fConfig, &format)) { + return nullptr; + } + SkASSERT(format == info->fFormat); +#endif GrSurfaceDesc surfDesc; - // next line relies on GrBackendTextureFlags matching GrTexture's - surfDesc.fFlags = (GrSurfaceFlags)flags; - surfDesc.fWidth = backendTex.width(); - surfDesc.fHeight = backendTex.height(); - surfDesc.fConfig = backendTex.config(); - surfDesc.fSampleCnt = SkTMin(sampleCnt, this->caps()->maxSampleCount()); - bool renderTarget = SkToBool(flags & kRenderTarget_GrBackendTextureFlag); + // next line relies on GrBackendTextureDesc's flags matching GrTexture's + surfDesc.fFlags = (GrSurfaceFlags)desc.fFlags; + surfDesc.fWidth = desc.fWidth; + surfDesc.fHeight = desc.fHeight; + surfDesc.fConfig = desc.fConfig; + surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); + bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag); SkASSERT(!renderTarget || kAdoptAndCache_GrWrapOwnership != ownership); // Not supported // In GL, Chrome assumes all textures are BottomLeft // In VK, we don't have this restriction - surfDesc.fOrigin = resolve_origin(origin); + surfDesc.fOrigin = resolve_origin(desc.fOrigin); if (!renderTarget) { return GrVkTexture::MakeWrappedTexture(this, surfDesc, ownership, info); @@ -847,23 +848,23 @@ sk_sp GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTa return tgt; } -sk_sp GrVkGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, - GrSurfaceOrigin origin, - int sampleCnt) { +sk_sp GrVkGpu::onWrapBackendTextureAsRenderTarget( + const GrBackendTextureDesc& wrapDesc){ - const GrVkImageInfo* info = tex.getVkImageInfo(); + const GrVkImageInfo* info = + reinterpret_cast(wrapDesc.fTextureHandle); if (VK_NULL_HANDLE == info->fImage) { return nullptr; } GrSurfaceDesc desc; - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fConfig = tex.config(); - desc.fWidth = tex.width(); - desc.fHeight = tex.height(); - desc.fSampleCnt = SkTMin(sampleCnt, this->caps()->maxSampleCount()); + desc.fFlags = (GrSurfaceFlags) wrapDesc.fFlags; + desc.fConfig = wrapDesc.fConfig; + desc.fWidth = wrapDesc.fWidth; + desc.fHeight = wrapDesc.fHeight; + desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()); - desc.fOrigin = resolve_origin(origin); + desc.fOrigin = resolve_origin(wrapDesc.fOrigin); sk_sp tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc, info); return tgt; diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h index d3e1555..8477271 100644 --- a/src/gpu/vk/GrVkGpu.h +++ b/src/gpu/vk/GrVkGpu.h @@ -175,16 +175,10 @@ private: GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted, const SkTArray&) override { return NULL; } - sk_sp onWrapBackendTexture(const GrBackendTexture&, - GrSurfaceOrigin, - GrBackendTextureFlags, - int sampleCnt, - GrWrapOwnership) override; - sk_sp onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override; + sk_sp onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override; - sk_sp onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, - GrSurfaceOrigin, - int sampleCnt) override; + sk_sp onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override; + sk_sp onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override; GrBuffer* onCreateBuffer(size_t size, GrBufferType type, GrAccessPattern, const void* data) override; diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index dd1b0c1..0e74f68 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -10,7 +10,6 @@ #include #include "SkAutoPixmapStorage.h" -#include "GrBackendSurface.h" #include "GrBitmapTextureMaker.h" #include "GrCaps.h" #include "GrContext.h" @@ -253,23 +252,16 @@ sk_sp SkImage_Gpu::onMakeSubset(const SkIRect& subset) const { /////////////////////////////////////////////////////////////////////////////////////////////////// -static sk_sp new_wrapped_texture_common(GrContext* ctx, - const GrBackendTexture& backendTex, - GrSurfaceOrigin origin, +static sk_sp new_wrapped_texture_common(GrContext* ctx, const GrBackendTextureDesc& desc, SkAlphaType at, sk_sp colorSpace, GrWrapOwnership ownership, SkImage::TextureReleaseProc releaseProc, SkImage::ReleaseContext releaseCtx) { - if (backendTex.width() <= 0 || backendTex.height() <= 0) { + if (desc.fWidth <= 0 || desc.fHeight <= 0) { return nullptr; } - GrBackendTextureFlags flags = kNone_GrBackendTextureFlag; - sk_sp tex = ctx->resourceProvider()->wrapBackendTexture(backendTex, - origin, - flags, - 0, - ownership); + sk_sp tex = ctx->resourceProvider()->wrapBackendTexture(desc, ownership); if (!tex) { return nullptr; } @@ -287,19 +279,13 @@ static sk_sp new_wrapped_texture_common(GrContext* ctx, sk_sp SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc, SkAlphaType at, sk_sp cs, TextureReleaseProc releaseP, ReleaseContext releaseC) { - SkASSERT(!(kRenderTarget_GrBackendTextureFlag & desc.fFlags)); - GrBackendTexture tex(desc, ctx->contextPriv().getBackend()); - return new_wrapped_texture_common(ctx, tex, desc.fOrigin, at, std::move(cs), - kBorrow_GrWrapOwnership, + return new_wrapped_texture_common(ctx, desc, at, std::move(cs), kBorrow_GrWrapOwnership, releaseP, releaseC); } sk_sp SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDesc& desc, SkAlphaType at, sk_sp cs) { - SkASSERT(!(kRenderTarget_GrBackendTextureFlag & desc.fFlags)); - GrBackendTexture tex(desc, ctx->contextPriv().getBackend()); - return new_wrapped_texture_common(ctx, tex, desc.fOrigin, at, std::move(cs), - kAdopt_GrWrapOwnership, + return new_wrapped_texture_common(ctx, desc, at, std::move(cs), kAdopt_GrWrapOwnership, nullptr, nullptr); } @@ -307,30 +293,17 @@ sk_sp SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTexture& tex, GrSurfaceOrigin origin, SkAlphaType at, sk_sp cs, TextureReleaseProc releaseP, ReleaseContext releaseC) { - return new_wrapped_texture_common(ctx, tex, origin, at, std::move(cs), kBorrow_GrWrapOwnership, - releaseP, releaseC); + // This function is not implemented yet + sk_throw(); + return nullptr; } sk_sp SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTexture& tex, GrSurfaceOrigin origin, SkAlphaType at, sk_sp cs) { - return new_wrapped_texture_common(ctx, tex, origin, at, std::move(cs), kAdopt_GrWrapOwnership, - nullptr, nullptr); -} - -static GrBackendTexture make_backend_texture_from_handle(GrBackend backend, - int width, int height, - GrPixelConfig config, - GrBackendObject handle) { - - if (kOpenGL_GrBackend == backend) { - GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle); - return GrBackendTexture(width, height, config, glInfo); - } else { - SkASSERT(kVulkan_GrBackend == backend); - GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle); - return GrBackendTexture(width, height, vkInfo); - } + // This function is not implemented yet + sk_throw(); + return nullptr; } static sk_sp make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpace colorSpace, @@ -351,31 +324,38 @@ static sk_sp make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac const GrPixelConfig kConfig = nv12 ? kRGBA_8888_GrPixelConfig : kAlpha_8_GrPixelConfig; - GrBackend backend = ctx->contextPriv().getBackend(); - GrBackendTexture yTex = make_backend_texture_from_handle(backend, - yuvSizes[0].fWidth, - yuvSizes[0].fHeight, - kConfig, - yuvTextureHandles[0]); - GrBackendTexture uTex = make_backend_texture_from_handle(backend, - yuvSizes[1].fWidth, - yuvSizes[1].fHeight, - kConfig, - yuvTextureHandles[1]); - - sk_sp yProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, yTex, origin); - sk_sp uProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, uTex, origin); - sk_sp vProxy; + GrBackendTextureDesc yDesc; + yDesc.fConfig = kConfig; + yDesc.fOrigin = origin; + yDesc.fSampleCnt = 0; + yDesc.fTextureHandle = yuvTextureHandles[0]; + yDesc.fWidth = yuvSizes[0].fWidth; + yDesc.fHeight = yuvSizes[0].fHeight; + + GrBackendTextureDesc uDesc; + uDesc.fConfig = kConfig; + uDesc.fOrigin = origin; + uDesc.fSampleCnt = 0; + uDesc.fTextureHandle = yuvTextureHandles[1]; + uDesc.fWidth = yuvSizes[1].fWidth; + uDesc.fHeight = yuvSizes[1].fHeight; + + sk_sp yProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, yDesc); + sk_sp uProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, uDesc); + sk_sp vProxy; if (nv12) { vProxy = uProxy; } else { - GrBackendTexture vTex = make_backend_texture_from_handle(backend, - yuvSizes[2].fWidth, - yuvSizes[2].fHeight, - kConfig, - yuvTextureHandles[2]); - vProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, vTex, origin); + GrBackendTextureDesc vDesc; + vDesc.fConfig = kConfig; + vDesc.fOrigin = origin; + vDesc.fSampleCnt = 0; + vDesc.fTextureHandle = yuvTextureHandles[2]; + vDesc.fWidth = yuvSizes[2].fWidth; + vDesc.fHeight = yuvSizes[2].fHeight; + + vProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, vDesc); } if (!yProxy || !uProxy || !vProxy) { return nullptr; @@ -400,8 +380,9 @@ static sk_sp make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.addColorFragmentProcessor( GrYUVEffect::MakeYUVToRGB(ctx->resourceProvider(), - yProxy, uProxy, vProxy, - yuvSizes, colorSpace, nv12)); + sk_ref_sp(yProxy->asTextureProxy()), + sk_ref_sp(uProxy->asTextureProxy()), + sk_ref_sp(vProxy->asTextureProxy()), yuvSizes, colorSpace, nv12)); const SkRect rect = SkRect::MakeIWH(width, height); @@ -495,21 +476,21 @@ std::unique_ptr SkCrossContextImageData::MakeFromEncode GrTexture* texture = as_IB(textureImage)->peekTexture(); SkASSERT(texture); + GrBackendTextureDesc desc; + desc.fFlags = kNone_GrBackendTextureFlag; + desc.fOrigin = texture->origin(); + desc.fWidth = texture->width(); + desc.fHeight = texture->height(); + desc.fConfig = texture->config(); + desc.fSampleCnt = 0; + context->contextPriv().prepareSurfaceForExternalIO(as_IB(textureImage)->peekProxy()); auto textureData = texture->texturePriv().detachBackendTexture(); SkASSERT(textureData); - GrBackend backend = context->contextPriv().getBackend(); - GrBackendTexture backendTex = make_backend_texture_from_handle(backend, - texture->width(), - texture->height(), - texture->config(), - textureData->getBackendObject()); - SkImageInfo info = as_IB(textureImage)->onImageInfo(); return std::unique_ptr(new SkCCIDBackendTexture( - backendTex, texture->origin(), std::move(textureData), - info.alphaType(), info.refColorSpace())); + desc, std::move(textureData), info.alphaType(), info.refColorSpace())); } sk_sp SkCCIDBackendTexture::makeImage(GrContext* context) { @@ -520,7 +501,7 @@ sk_sp SkCCIDBackendTexture::makeImage(GrContext* context) { // This texture was created by Ganesh on another thread (see MakeFromEncoded, above). // Thus, we can import it back into our cache and treat it as our own (again). GrWrapOwnership ownership = kAdoptAndCache_GrWrapOwnership; - return new_wrapped_texture_common(context, fBackendTex, fOrigin, fAlphaType, + return new_wrapped_texture_common(context, fDesc, fAlphaType, std::move(fColorSpace), ownership, nullptr, nullptr); } diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index 96ac31e..f024c41 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -7,7 +7,6 @@ #include "SkSurface_Gpu.h" -#include "GrBackendSurface.h" #include "GrContextPriv.h" #include "GrRenderTargetContextPriv.h" #include "GrResourceProvider.h" @@ -221,32 +220,22 @@ sk_sp SkSurface::MakeFromBackendTexture(GrContext* context, if (!context) { return nullptr; } - GrBackendTexture tex(desc, context->contextPriv().getBackend()); - return MakeFromBackendTexture(context, tex, desc.fOrigin, desc.fSampleCnt, colorSpace, props); -} - -sk_sp SkSurface::MakeFromBackendTexture(GrContext* context, const GrBackendTexture& tex, - GrSurfaceOrigin origin, int sampleCnt, - sk_sp colorSpace, - const SkSurfaceProps* props) { - if (!context) { + if (!SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) { return nullptr; } - if (!SkSurface_Gpu::Valid(context, tex.config(), colorSpace.get())) { + if (!SkSurface_Gpu::Valid(context, desc.fConfig, colorSpace.get())) { return nullptr; } sk_sp rtc(context->contextPriv().makeBackendTextureRenderTargetContext( - tex, - origin, - sampleCnt, + desc, std::move(colorSpace), props)); if (!rtc) { return nullptr; } - sk_sp device(SkGpuDevice::Make(context, std::move(rtc), tex.width(), tex.height(), + sk_sp device(SkGpuDevice::Make(context, std::move(rtc), desc.fWidth, desc.fHeight, SkGpuDevice::kUninit_InitContents)); if (!device) { return nullptr; @@ -254,6 +243,14 @@ sk_sp SkSurface::MakeFromBackendTexture(GrContext* context, const GrB return sk_make_sp(std::move(device)); } +sk_sp SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTexture&, + GrSurfaceOrigin origin, int sampleCnt, + sk_sp, const SkSurfaceProps*) { + // This function is not implemented yet + sk_throw(); + return nullptr; +} + sk_sp SkSurface::MakeFromBackendRenderTarget(GrContext* context, const GrBackendRenderTargetDesc& desc, sk_sp colorSpace, @@ -299,36 +296,20 @@ sk_sp SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont if (!context) { return nullptr; } - GrBackendTexture tex(desc, context->contextPriv().getBackend()); - return MakeFromBackendTextureAsRenderTarget(context, tex, desc.fOrigin, desc.fSampleCnt, - std::move(colorSpace), props); -} - -sk_sp SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context, - const GrBackendTexture& tex, - GrSurfaceOrigin origin, - int sampleCnt, - sk_sp colorSpace, - const SkSurfaceProps* props) { - if (!context) { - return nullptr; - } - if (!SkSurface_Gpu::Valid(context, tex.config(), colorSpace.get())) { + if (!SkSurface_Gpu::Valid(context, desc.fConfig, colorSpace.get())) { return nullptr; } sk_sp rtc( context->contextPriv().makeBackendTextureAsRenderTargetRenderTargetContext( - tex, - origin, - sampleCnt, + desc, std::move(colorSpace), props)); if (!rtc) { return nullptr; } - sk_sp device(SkGpuDevice::Make(context, std::move(rtc), tex.width(), tex.height(), + sk_sp device(SkGpuDevice::Make(context, std::move(rtc), desc.fWidth, desc.fHeight, SkGpuDevice::kUninit_InitContents)); if (!device) { return nullptr; @@ -336,4 +317,15 @@ sk_sp SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont return sk_make_sp(std::move(device)); } +sk_sp SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext*, + const GrBackendTexture&, + GrSurfaceOrigin origin, + int sampleCnt, + sk_sp, + const SkSurfaceProps*) { + // This function is not implemented yet + sk_throw(); + return nullptr; +} + #endif diff --git a/tests/BlendTest.cpp b/tests/BlendTest.cpp index 20ea6e0..0acbd07 100644 --- a/tests/BlendTest.cpp +++ b/tests/BlendTest.cpp @@ -21,7 +21,6 @@ #include "GrResourceProvider.h" #include "GrSurfaceContext.h" #include "GrSurfaceProxy.h" -#include "GrTest.h" #include "GrTexture.h" #endif @@ -100,16 +99,16 @@ static sk_sp create_gpu_surface_backend_texture_as_render_target( return nullptr; } - GrBackendTexture backendTex = - GrTest::CreateBackendTexture(context->contextPriv().getBackend(), - width, - height, - config, - (*backingSurface)->getTextureHandle()); + GrBackendTextureDesc desc; + desc.fFlags = kRenderTarget_GrBackendTextureFlag; + desc.fOrigin = origin; + desc.fWidth = width; + desc.fHeight = height; + desc.fConfig = config; + desc.fSampleCnt = sampleCnt; + desc.fTextureHandle = (*backingSurface)->getTextureHandle(); sk_sp surface = - SkSurface::MakeFromBackendTextureAsRenderTarget(context, backendTex, origin, - sampleCnt, nullptr, nullptr); - + SkSurface::MakeFromBackendTextureAsRenderTarget(context, desc, nullptr); return surface; } } diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp index 1b94a6e..998e339 100644 --- a/tests/EGLImageTest.cpp +++ b/tests/EGLImageTest.cpp @@ -13,7 +13,6 @@ #include "GrContextFactory.h" #include "GrShaderCaps.h" #include "GrSurfaceContext.h" -#include "GrTest.h" #include "gl/GrGLGpu.h" #include "gl/GrGLUtil.h" #include "gl/GLTestContext.h" @@ -130,12 +129,14 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { externalTexture.fID = glCtx0->eglImageToExternalTexture(image); // Wrap this texture ID in a GrTexture - GrBackendTexture backendTex(kSize, kSize, kRGBA_8888_GrPixelConfig, &externalTexture); + GrBackendTextureDesc externalDesc; + externalDesc.fConfig = kRGBA_8888_GrPixelConfig; + externalDesc.fWidth = kSize; + externalDesc.fHeight = kSize; + externalDesc.fTextureHandle = reinterpret_cast(&externalTexture); - // TODO: If I make this TopLeft origin to match resolve_origin calls for kDefault, this test - // fails on the Nexus5. Why? sk_sp surfaceContext = context0->contextPriv().makeBackendSurfaceContext( - backendTex, kBottomLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 0, nullptr); + externalDesc, nullptr); if (!surfaceContext) { ERRORF(reporter, "Error wrapping external texture in GrSurfaceContext."); @@ -145,21 +146,25 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { // Should not be able to wrap as a RT { + externalDesc.fFlags = kRenderTarget_GrBackendTextureFlag; + sk_sp temp = context0->contextPriv().makeBackendSurfaceContext( - backendTex, kBottomLeft_GrSurfaceOrigin, kRenderTarget_GrBackendTextureFlag, 0, - nullptr); + externalDesc, nullptr); if (temp) { ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture as a RT."); } + externalDesc.fFlags = kNone_GrBackendTextureFlag; } // Should not be able to wrap with a sample count { + externalDesc.fSampleCnt = 4; sk_sp temp = context0->contextPriv().makeBackendSurfaceContext( - backendTex, kBottomLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 4, nullptr); + externalDesc, nullptr); if (temp) { ERRORF(reporter, "Should not be able to wrap an EXTERNAL texture with MSAA."); } + externalDesc.fSampleCnt = 0; } test_read_pixels(reporter, surfaceContext.get(), pixels.get(), "EGLImageTest-read"); diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp index 780573d..f4b74c7 100644 --- a/tests/GrPorterDuffTest.cpp +++ b/tests/GrPorterDuffTest.cpp @@ -11,10 +11,8 @@ #include "GrContextFactory.h" #include "GrContextOptions.h" -#include "GrContextPriv.h" #include "GrGpu.h" #include "GrResourceProvider.h" -#include "GrTest.h" #include "GrXferProcessor.h" #include "effects/GrPorterDuffXferProcessor.h" #include "gl/GrGLCaps.h" @@ -1036,19 +1034,15 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) { return; } - GrBackendObject backendTexHandle = + GrBackendObject backendTex = ctx->getGpu()->createTestingOnlyBackendTexture(nullptr, 100, 100, kRGBA_8888_GrPixelConfig); - GrBackendTexture backendTex = GrTest::CreateBackendTexture(ctx->contextPriv().getBackend(), - 100, - 100, - kRGBA_8888_GrPixelConfig, - backendTexHandle); - + GrBackendTextureDesc fakeDesc; + fakeDesc.fConfig = kRGBA_8888_GrPixelConfig; + fakeDesc.fWidth = fakeDesc.fHeight = 100; + fakeDesc.fTextureHandle = backendTex; GrXferProcessor::DstTexture fakeDstTexture; fakeDstTexture.setTexture( - ctx->resourceProvider()->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin, - kNone_GrBackendTextureFlag, 0, - kBorrow_GrWrapOwnership)); + ctx->resourceProvider()->wrapBackendTexture(fakeDesc, kBorrow_GrWrapOwnership)); static const GrProcessorAnalysisColor colorInputs[] = { GrProcessorAnalysisColor::Opaque::kNo, GrProcessorAnalysisColor::Opaque::kYes, @@ -1071,7 +1065,7 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) { } } } - ctx->getGpu()->deleteTestingOnlyBackendTexture(backendTexHandle); + ctx->getGpu()->deleteTestingOnlyBackendTexture(backendTex); } #endif diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index 99c0bec..97700b1 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -10,11 +10,9 @@ #if SK_SUPPORT_GPU #include "GrContext.h" -#include "GrContextPriv.h" #include "GrGpu.h" #include "GrRenderTarget.h" #include "GrResourceProvider.h" -#include "GrTest.h" #include "GrTexture.h" #include "GrSurfacePriv.h" #include "Test.h" @@ -46,18 +44,18 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture()); REPORTER_ASSERT(reporter, static_cast(tex1.get()) == tex1->asTexture()); - GrBackendObject backendTexHandle = context->getGpu()->createTestingOnlyBackendTexture( + GrBackendObject backendTex = context->getGpu()->createTestingOnlyBackendTexture( nullptr, 256, 256, kRGBA_8888_GrPixelConfig); - GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(), - 256, - 256, - kRGBA_8888_GrPixelConfig, - backendTexHandle); + GrBackendTextureDesc backendDesc; + backendDesc.fConfig = kRGBA_8888_GrPixelConfig; + backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag; + backendDesc.fWidth = 256; + backendDesc.fHeight = 256; + backendDesc.fSampleCnt = 0; + backendDesc.fTextureHandle = backendTex; sk_sp texRT2 = context->resourceProvider()->wrapBackendTexture( - backendTex, kTopLeft_GrSurfaceOrigin, kRenderTarget_GrBackendTextureFlag, 0, - kBorrow_GrWrapOwnership); - + backendDesc, kBorrow_GrWrapOwnership); REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget()); REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture()); REPORTER_ASSERT(reporter, static_cast(texRT2->asRenderTarget()) == @@ -67,7 +65,7 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { REPORTER_ASSERT(reporter, static_cast(texRT2->asRenderTarget()) == static_cast(texRT2->asTexture())); - context->getGpu()->deleteTestingOnlyBackendTexture(backendTexHandle); + context->getGpu()->deleteTestingOnlyBackendTexture(backendTex); } #endif diff --git a/tests/ImageFilterCacheTest.cpp b/tests/ImageFilterCacheTest.cpp index 0dda42e..95ade04 100644 --- a/tests/ImageFilterCacheTest.cpp +++ b/tests/ImageFilterCacheTest.cpp @@ -179,9 +179,7 @@ DEF_TEST(ImageFilterCache_ImageBackedRaster, reporter) { #if SK_SUPPORT_GPU #include "GrContext.h" -#include "GrContextPriv.h" #include "GrResourceProvider.h" -#include "GrTest.h" static sk_sp create_proxy(GrResourceProvider* resourceProvider) { SkBitmap srcBM = create_bm(); @@ -211,16 +209,17 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ct return; } - GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(), - kFullSize, - kFullSize, - kRGBA_8888_GrPixelConfig, - tex->getTextureHandle()); - GrSurfaceOrigin texOrigin = kTopLeft_GrSurfaceOrigin; + GrBackendTextureDesc backendDesc; + backendDesc.fFlags = kNone_GrBackendTextureFlag; + backendDesc.fOrigin = kTopLeft_GrSurfaceOrigin; + backendDesc.fConfig = kRGBA_8888_GrPixelConfig; + backendDesc.fWidth = kFullSize; + backendDesc.fHeight = kFullSize; + backendDesc.fSampleCnt = 0; + backendDesc.fTextureHandle = tex->getTextureHandle(); sk_sp srcImage(SkImage::MakeFromTexture(context, - backendTex, - texOrigin, - kPremul_SkAlphaType, nullptr)); + backendDesc, + kPremul_SkAlphaType)); if (!srcImage) { return; } @@ -229,18 +228,18 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ct GrBackendObject readBackHandle = srcImage->getTextureHandle(false, &readBackOrigin); // TODO: Make it so we can check this (see skbug.com/5019) #if 0 - if (readBackHandle != tex->getTextureHandle()) { + if (readBackHandle != backendDesc.fTextureHandle) { ERRORF(reporter, "backend mismatch %d %d\n", - (int)readBackHandle, (int)tex->getTextureHandle()); + (int)readBackHandle, (int)backendDesc.fTextureHandle); } - REPORTER_ASSERT(reporter, readBackHandle == tex->getTextureHandle()); + REPORTER_ASSERT(reporter, readBackHandle == backendDesc.fTextureHandle); #else REPORTER_ASSERT(reporter, SkToBool(readBackHandle)); #endif - if (readBackOrigin != texOrigin) { - ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, texOrigin); + if (readBackOrigin != backendDesc.fOrigin) { + ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, backendDesc.fOrigin); } - REPORTER_ASSERT(reporter, readBackOrigin == texOrigin); + REPORTER_ASSERT(reporter, readBackOrigin == backendDesc.fOrigin); test_image_backed(reporter, srcImage); } diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 382a624..77017f3 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -32,9 +32,7 @@ #include "sk_tool_utils.h" #if SK_SUPPORT_GPU -#include "GrContextPriv.h" #include "GrGpu.h" -#include "GrTest.h" #endif using namespace sk_gpu_test; @@ -810,48 +808,44 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c const int kWidth = 10; const int kHeight = 10; std::unique_ptr pixels(new uint32_t[kWidth * kHeight]); - - GrContext* ctx = ctxInfo.grContext(); - - GrBackendObject backendTexHandle = - ctxInfo.grContext()->getGpu()->createTestingOnlyBackendTexture( - pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true); - - GrBackendTexture backendTex = GrTest::CreateBackendTexture(ctx->contextPriv().getBackend(), - kWidth, - kHeight, - kRGBA_8888_GrPixelConfig, - backendTexHandle); + GrBackendTextureDesc backendDesc; + backendDesc.fFlags = kRenderTarget_GrBackendTextureFlag; + backendDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; + backendDesc.fConfig = kRGBA_8888_GrPixelConfig; + backendDesc.fWidth = kWidth; + backendDesc.fHeight = kHeight; + backendDesc.fSampleCnt = 0; + backendDesc.fTextureHandle = ctxInfo.grContext()->getGpu()->createTestingOnlyBackendTexture( + pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true); TextureReleaseChecker releaseChecker; - GrSurfaceOrigin texOrigin = kBottomLeft_GrSurfaceOrigin; sk_sp refImg( - SkImage::MakeFromTexture(ctx, backendTex, texOrigin, kPremul_SkAlphaType, nullptr, + SkImage::MakeFromTexture(ctxInfo.grContext(), backendDesc, kPremul_SkAlphaType, TextureReleaseChecker::Release, &releaseChecker)); GrSurfaceOrigin readBackOrigin; GrBackendObject readBackHandle = refImg->getTextureHandle(false, &readBackOrigin); // TODO: Make it so we can check this (see skbug.com/5019) #if 0 - if (*readBackHandle != *(backendTexHandle)) { + if (*readBackHandle != *(backendDesc.fTextureHandle)) { ERRORF(reporter, "backend mismatch %d %d\n", - (int)readBackHandle, (int)backendTexHandle); + (int)readBackHandle, (int)backendDesc.fTextureHandle); } - REPORTER_ASSERT(reporter, readBackHandle == backendTexHandle); + REPORTER_ASSERT(reporter, readBackHandle == backendDesc.fTextureHandle); #else REPORTER_ASSERT(reporter, SkToBool(readBackHandle)); #endif - if (readBackOrigin != texOrigin) { - ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, texOrigin); + if (readBackOrigin != backendDesc.fOrigin) { + ERRORF(reporter, "origin mismatch %d %d\n", readBackOrigin, backendDesc.fOrigin); } - REPORTER_ASSERT(reporter, readBackOrigin == texOrigin); + REPORTER_ASSERT(reporter, readBackOrigin == backendDesc.fOrigin); // Now exercise the release proc REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); refImg.reset(nullptr); // force a release of the image REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); - ctxInfo.grContext()->getGpu()->deleteTestingOnlyBackendTexture(backendTexHandle); + ctxInfo.grContext()->getGpu()->deleteTestingOnlyBackendTexture(backendDesc.fTextureHandle); } static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, const SkImage* b) { diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp index 967d86c..41ee7b3 100644 --- a/tests/RectangleTextureTest.cpp +++ b/tests/RectangleTextureTest.cpp @@ -13,14 +13,13 @@ #include "GrContext.h" #include "GrContextPriv.h" #include "GrRenderTargetContext.h" -#include "GrTest.h" #include "gl/GLTestContext.h" #include "gl/GrGLGpu.h" #include "gl/GrGLUtil.h" // skbug.com/5932 static void test_basic_draw_as_src(skiatest::Reporter* reporter, GrContext* context, - sk_sp rectProxy, uint32_t expectedPixelValues[]) { + sk_sp rectProxy, uint32_t expectedPixelValues[]) { sk_sp rtContext( context->makeRenderTargetContext(SkBackingFit::kExact, rectProxy->width(), rectProxy->height(), rectProxy->config(), @@ -31,7 +30,7 @@ static void test_basic_draw_as_src(skiatest::Reporter* reporter, GrContext* cont rtContext->clear(nullptr, 0xDDCCBBAA, true); sk_sp fp(GrSimpleTextureEffect::Make( context->resourceProvider(), - rectProxy, + sk_ref_sp(rectProxy->asTextureProxy()), nullptr, SkMatrix::I(), filter)); GrPaint paint; @@ -100,9 +99,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) { } } - for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) { - bool useBLOrigin = kBottomLeft_GrSurfaceOrigin == origin; - + for (int origin = 0; origin < 2; ++origin) { GrGLuint rectTexID = glContext->createTextureRectangle(kWidth, kHeight, GR_GL_RGBA, GR_GL_RGBA, GR_GL_UNSIGNED_BYTE, pixels); @@ -119,19 +116,25 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) { rectangleInfo.fID = rectTexID; rectangleInfo.fTarget = GR_GL_TEXTURE_RECTANGLE; - GrBackendTexture rectangleTex(kWidth, kHeight, kRGBA_8888_GrPixelConfig, &rectangleInfo); + GrBackendTextureDesc rectangleDesc; + rectangleDesc.fFlags = kRenderTarget_GrBackendTextureFlag; + rectangleDesc.fConfig = kRGBA_8888_GrPixelConfig; + rectangleDesc.fWidth = kWidth; + rectangleDesc.fHeight = kHeight; + rectangleDesc.fOrigin = origin ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; + rectangleDesc.fTextureHandle = reinterpret_cast(&rectangleInfo); GrColor refPixels[kWidth * kHeight]; + bool flipRef = rectangleDesc.fOrigin == kBottomLeft_GrSurfaceOrigin; for (int y = 0; y < kHeight; ++y) { for (int x = 0; x < kWidth; ++x) { - int y0 = useBLOrigin ? kHeight - y - 1 : y; + int y0 = flipRef ? kHeight - y - 1 : y; refPixels[y * kWidth + x] = pixels[y0 * kWidth + x]; } } - sk_sp rectProxy = GrSurfaceProxy::MakeWrappedBackend(context, - rectangleTex, - origin); + 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)); diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 17e02ba..0736938 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -11,7 +11,6 @@ #if SK_SUPPORT_GPU #include #include "GrContext.h" -#include "GrContextPriv.h" #include "GrContextFactory.h" #include "GrGpu.h" #include "GrGpuResourceCacheAccess.h" @@ -219,32 +218,22 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxI context->resetContext(); - GrBackendTexture backendTex1 = GrTest::CreateBackendTexture(context->contextPriv().getBackend(), - kW, - kH, - kRGBA_8888_GrPixelConfig, - texHandles[0]); + GrBackendTextureDesc desc; + desc.fConfig = kBGRA_8888_GrPixelConfig; + desc.fWidth = kW; + desc.fHeight = kH; + + desc.fTextureHandle = texHandles[0]; sk_sp borrowed(context->resourceProvider()->wrapBackendTexture( - backendTex1, kTopLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 0, - kBorrow_GrWrapOwnership)); - - GrBackendTexture backendTex2 = GrTest::CreateBackendTexture(context->contextPriv().getBackend(), - kW, - kH, - kRGBA_8888_GrPixelConfig, - texHandles[1]); + desc, kBorrow_GrWrapOwnership)); + + desc.fTextureHandle = texHandles[1]; sk_sp adopted(context->resourceProvider()->wrapBackendTexture( - backendTex2, kTopLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 0, - kAdopt_GrWrapOwnership)); - - GrBackendTexture backendTex3 = GrTest::CreateBackendTexture(context->contextPriv().getBackend(), - kW, - kH, - kRGBA_8888_GrPixelConfig, - texHandles[2]); + desc, kAdopt_GrWrapOwnership)); + + desc.fTextureHandle = texHandles[2]; sk_sp adoptedAndCached(context->resourceProvider()->wrapBackendTexture( - backendTex3, kTopLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 0, - kAdoptAndCache_GrWrapOwnership)); + desc, kAdoptAndCache_GrWrapOwnership)); REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr && adoptedAndCached != nullptr); diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 58ced7e..e236928 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -25,7 +25,6 @@ #include "GrRenderTargetContext.h" #include "GrGpu.h" #include "GrResourceProvider.h" -#include "GrTest.h" #include #endif @@ -588,24 +587,20 @@ static sk_sp create_gpu_surface_backend_texture( const int kHeight = 10; std::unique_ptr pixels(new uint32_t[kWidth * kHeight]); sk_memset32(pixels.get(), color, kWidth * kHeight); - - GrBackendObject backendHandle = context->getGpu()->createTestingOnlyBackendTexture( + GrBackendTextureDesc desc; + desc.fConfig = kRGBA_8888_GrPixelConfig; + desc.fWidth = kWidth; + desc.fHeight = kHeight; + desc.fFlags = kRenderTarget_GrBackendTextureFlag; + desc.fTextureHandle = context->getGpu()->createTestingOnlyBackendTexture( pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true); - - GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(), - kWidth, - kHeight, - kRGBA_8888_GrPixelConfig, - backendHandle); - - sk_sp surface = SkSurface::MakeFromBackendTexture(context, backendTex, - kDefault_GrSurfaceOrigin, sampleCnt, - nullptr, nullptr); + desc.fSampleCnt = sampleCnt; + sk_sp surface = SkSurface::MakeFromBackendTexture(context, desc, nullptr); if (!surface) { - context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle); + context->getGpu()->deleteTestingOnlyBackendTexture(desc.fTextureHandle); return nullptr; } - *outTexture = backendHandle; + *outTexture = desc.fTextureHandle; return surface; } @@ -615,23 +610,21 @@ static sk_sp create_gpu_surface_backend_texture_as_render_target( const int kHeight = 10; std::unique_ptr pixels(new uint32_t[kWidth * kHeight]); sk_memset32(pixels.get(), color, kWidth * kHeight); - - GrBackendObject backendHandle = context->getGpu()->createTestingOnlyBackendTexture( + GrBackendTextureDesc desc; + desc.fConfig = kRGBA_8888_GrPixelConfig; + desc.fWidth = kWidth; + desc.fHeight = kHeight; + desc.fFlags = kRenderTarget_GrBackendTextureFlag; + desc.fTextureHandle = context->getGpu()->createTestingOnlyBackendTexture( pixels.get(), kWidth, kHeight, kRGBA_8888_GrPixelConfig, true); - - GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(), - kWidth, - kHeight, - kRGBA_8888_GrPixelConfig, - backendHandle); - sk_sp surface = SkSurface::MakeFromBackendTextureAsRenderTarget( - context, backendTex, kDefault_GrSurfaceOrigin, sampleCnt, nullptr, nullptr); - + desc.fSampleCnt = sampleCnt; + sk_sp surface = SkSurface::MakeFromBackendTextureAsRenderTarget(context, desc, + nullptr); if (!surface) { - context->getGpu()->deleteTestingOnlyBackendTexture(backendHandle); + context->getGpu()->deleteTestingOnlyBackendTexture(desc.fTextureHandle); return nullptr; } - *outTexture = backendHandle; + *outTexture = desc.fTextureHandle; return surface; } @@ -886,26 +879,21 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceCreationWithColorSpace_Gpu, reporter, std::vector textureHandles; auto wrappedSurfaceMaker = [context,&textureHandles](const SkImageInfo& info) { - static const int kSize = 10; - GrPixelConfig config = SkImageInfo2GrPixelConfig(info, *context->caps()); - - GrBackendObject backendHandle = context->getGpu()->createTestingOnlyBackendTexture( - nullptr, kSize, kSize, config, true); - - if (!backendHandle) { + GrBackendTextureDesc desc; + desc.fConfig = SkImageInfo2GrPixelConfig(info, *context->caps()); + desc.fWidth = 10; + desc.fHeight = 10; + desc.fFlags = kRenderTarget_GrBackendTextureFlag; + desc.fTextureHandle = context->getGpu()->createTestingOnlyBackendTexture( + nullptr, desc.fWidth, desc.fHeight, desc.fConfig, true); + + if (!desc.fTextureHandle) { return sk_sp(nullptr); } - textureHandles.push_back(backendHandle); - - GrBackendTexture backendTex = GrTest::CreateBackendTexture(context->contextPriv().getBackend(), - kSize, - kSize, - config, - backendHandle); + textureHandles.push_back(desc.fTextureHandle); - return SkSurface::MakeFromBackendTexture(context, backendTex, - kDefault_GrSurfaceOrigin, 0, - sk_ref_sp(info.colorSpace()), nullptr); + return SkSurface::MakeFromBackendTexture(context, desc, sk_ref_sp(info.colorSpace()), + nullptr); }; test_surface_creation_and_snapshot_with_color_space(reporter, "wrapped", f16Support, diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp index 44b5e72..9279ef6 100644 --- a/tests/VkWrapTests.cpp +++ b/tests/VkWrapTests.cpp @@ -31,56 +31,37 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, false); - const GrVkImageInfo* imageInfo = reinterpret_cast(backendObj); - - GrBackendTexture backendTex = GrBackendTexture(kW, kH, imageInfo); - sk_sp tex = gpu->wrapBackendTexture(backendTex, - kTopLeft_GrSurfaceOrigin, - kNone_GrBackendTextureFlag, - 0, - kBorrow_GrWrapOwnership); + const GrVkImageInfo* backendTex = reinterpret_cast(backendObj); + + // check basic borrowed creation + GrBackendTextureDesc desc; + desc.fConfig = kPixelConfig; + desc.fWidth = kW; + desc.fHeight = kH; + desc.fTextureHandle = backendObj; + sk_sp tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); REPORTER_ASSERT(reporter, tex); // image is null - GrVkImageInfo backendCopy = *imageInfo; + GrVkImageInfo backendCopy = *backendTex; backendCopy.fImage = VK_NULL_HANDLE; - backendTex = GrBackendTexture(kW, kH, &backendCopy); - tex = gpu->wrapBackendTexture(backendTex, - kTopLeft_GrSurfaceOrigin, - kNone_GrBackendTextureFlag, - 0, - kBorrow_GrWrapOwnership); + desc.fTextureHandle = (GrBackendObject) &backendCopy; + tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); REPORTER_ASSERT(reporter, !tex); - tex = gpu->wrapBackendTexture(backendTex, - kTopLeft_GrSurfaceOrigin, - kNone_GrBackendTextureFlag, - 0, - kAdopt_GrWrapOwnership); + tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); REPORTER_ASSERT(reporter, !tex); // alloc is null - backendCopy.fImage = imageInfo->fImage; + backendCopy.fImage = backendTex->fImage; backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; - tex = gpu->wrapBackendTexture(backendTex, - kTopLeft_GrSurfaceOrigin, - kNone_GrBackendTextureFlag, - 0, - kBorrow_GrWrapOwnership); + tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); REPORTER_ASSERT(reporter, !tex); - tex = gpu->wrapBackendTexture(backendTex, - kTopLeft_GrSurfaceOrigin, - kNone_GrBackendTextureFlag, - 0, - kAdopt_GrWrapOwnership); + tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); REPORTER_ASSERT(reporter, !tex); - // check adopt creation - backendCopy.fAlloc = imageInfo->fAlloc; - tex = gpu->wrapBackendTexture(backendTex, - kTopLeft_GrSurfaceOrigin, - kNone_GrBackendTextureFlag, - 0, - kAdopt_GrWrapOwnership); + // check adopt creation + backendCopy.fAlloc = backendTex->fAlloc; + tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); REPORTER_ASSERT(reporter, tex); gpu->deleteTestingOnlyBackendTexture(backendObj, true); @@ -129,56 +110,38 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { GrBackendObject backendObj = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kPixelConfig, true); - const GrVkImageInfo* imageInfo = reinterpret_cast(backendObj); - - GrBackendTexture backendTex = GrBackendTexture(kW, kH, imageInfo); - sk_sp tex = gpu->wrapBackendTexture(backendTex, - kTopLeft_GrSurfaceOrigin, - kRenderTarget_GrBackendTextureFlag, - 0, - kBorrow_GrWrapOwnership); + const GrVkImageInfo* backendTex = reinterpret_cast(backendObj); + + // check basic borrowed creation + GrBackendTextureDesc desc; + desc.fFlags = kRenderTarget_GrBackendTextureFlag; + desc.fConfig = kPixelConfig; + desc.fWidth = kW; + desc.fHeight = kH; + desc.fTextureHandle = backendObj; + sk_sp tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); REPORTER_ASSERT(reporter, tex); // image is null - GrVkImageInfo backendCopy = *imageInfo; + GrVkImageInfo backendCopy = *backendTex; backendCopy.fImage = VK_NULL_HANDLE; - backendTex = GrBackendTexture(kW, kH, &backendCopy); - tex = gpu->wrapBackendTexture(backendTex, - kTopLeft_GrSurfaceOrigin, - kRenderTarget_GrBackendTextureFlag, - 0, - kBorrow_GrWrapOwnership); + desc.fTextureHandle = (GrBackendObject)&backendCopy; + tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); REPORTER_ASSERT(reporter, !tex); - tex = gpu->wrapBackendTexture(backendTex, - kTopLeft_GrSurfaceOrigin, - kRenderTarget_GrBackendTextureFlag, - 0, - kAdopt_GrWrapOwnership); + tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); REPORTER_ASSERT(reporter, !tex); // alloc is null - backendCopy.fImage = imageInfo->fImage; + backendCopy.fImage = backendTex->fImage; backendCopy.fAlloc = { VK_NULL_HANDLE, 0, 0, 0 }; - tex = gpu->wrapBackendTexture(backendTex, - kTopLeft_GrSurfaceOrigin, - kRenderTarget_GrBackendTextureFlag, - 0, - kBorrow_GrWrapOwnership); + tex = gpu->wrapBackendTexture(desc, kBorrow_GrWrapOwnership); REPORTER_ASSERT(reporter, !tex); - tex = gpu->wrapBackendTexture(backendTex, - kTopLeft_GrSurfaceOrigin, - kRenderTarget_GrBackendTextureFlag, - 0, - kAdopt_GrWrapOwnership); + tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); REPORTER_ASSERT(reporter, !tex); // check adopt creation - backendCopy.fAlloc = imageInfo->fAlloc; - tex = gpu->wrapBackendTexture(backendTex, - kTopLeft_GrSurfaceOrigin, - kRenderTarget_GrBackendTextureFlag, - 0, - kAdopt_GrWrapOwnership); + backendCopy.fAlloc = backendTex->fAlloc; + tex = gpu->wrapBackendTexture(desc, kAdopt_GrWrapOwnership); REPORTER_ASSERT(reporter, tex); gpu->deleteTestingOnlyBackendTexture(backendObj, true); diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index 2e34d2f..30f7316 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -7,7 +7,6 @@ #include "GrTest.h" -#include "GrBackendSurface.h" #include "GrContextOptions.h" #include "GrDrawOpAtlas.h" #include "GrDrawingManager.h" @@ -55,18 +54,6 @@ void SetupAlwaysEvictAtlas(GrContext* context) { context->setTextContextAtlasSizes_ForTesting(configs); } - -GrBackendTexture CreateBackendTexture(GrBackend backend, int width, int height, - GrPixelConfig config, GrBackendObject handle) { - if (kOpenGL_GrBackend == backend) { - GrGLTextureInfo* glInfo = (GrGLTextureInfo*)(handle); - return GrBackendTexture(width, height, config, glInfo); - } else { - SkASSERT(kVulkan_GrBackend == backend); - GrVkImageInfo* vkInfo = (GrVkImageInfo*)(handle); - return GrBackendTexture(width, height, vkInfo); - } -} }; bool GrSurfaceProxy::isWrapped_ForTesting() const { @@ -351,11 +338,7 @@ private: return nullptr; } - sk_sp onWrapBackendTexture(const GrBackendTexture&, - GrSurfaceOrigin, - GrBackendTextureFlags, - int sampleCnt, - GrWrapOwnership) override { + sk_sp onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override { return nullptr; } @@ -363,9 +346,7 @@ private: return nullptr; } - sk_sp onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, - GrSurfaceOrigin, - int sampleCnt) override { + sk_sp onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override { return nullptr; } diff --git a/tools/gpu/GrTest.h b/tools/gpu/GrTest.h index d4a4c6d..db4c451 100644 --- a/tools/gpu/GrTest.h +++ b/tools/gpu/GrTest.h @@ -8,7 +8,6 @@ #ifndef GrTest_DEFINED #define GrTest_DEFINED -#include "GrBackendSurface.h" #include "GrContext.h" namespace GrTest { @@ -17,9 +16,6 @@ namespace GrTest { * constantly be evicting entries */ void SetupAlwaysEvictAtlas(GrContext*); - - GrBackendTexture CreateBackendTexture(GrBackend, int width, int height, - GrPixelConfig, GrBackendObject); }; #endif -- 2.7.4