diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrBackendSurface.cpp | 37 | ||||
-rw-r--r-- | src/gpu/GrContext.cpp | 27 | ||||
-rw-r--r-- | src/gpu/GrContextPriv.h | 13 | ||||
-rw-r--r-- | src/gpu/GrGpu.cpp | 30 | ||||
-rw-r--r-- | src/gpu/GrGpu.h | 17 | ||||
-rw-r--r-- | src/gpu/GrResourceProvider.cpp | 11 | ||||
-rw-r--r-- | src/gpu/GrResourceProvider.h | 9 | ||||
-rw-r--r-- | src/gpu/GrSurfaceProxy.cpp | 8 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 48 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.h | 11 | ||||
-rw-r--r-- | src/gpu/vk/GrVkGpu.cpp | 57 | ||||
-rw-r--r-- | src/gpu/vk/GrVkGpu.h | 12 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 123 | ||||
-rw-r--r-- | src/image/SkSurface_Gpu.cpp | 60 |
14 files changed, 280 insertions, 183 deletions
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp index 9bf85cb7db..97b3b6ee03 100644 --- a/src/gpu/GrBackendSurface.cpp +++ b/src/gpu/GrBackendSurface.cpp @@ -10,20 +10,27 @@ #ifdef SK_VULKAN #include "vk/GrVkTypes.h" #include "vk/GrVkUtil.h" +#endif + GrBackendTexture::GrBackendTexture(int width, int height, - GrVkImageInfo* vkInfo) + const GrVkImageInfo* vkInfo) : fWidth(width) , fHeight(height) - , fConfig(GrVkFormatToPixelConfig(vkInfo->fFormat)) + , fConfig( +#ifdef SK_VULKAN + GrVkFormatToPixelConfig(vkInfo->fFormat) +#else + kUnknown_GrPixelConfig +#endif + ) , fBackend(kVulkan_GrBackend) , fVkInfo(vkInfo) {} -#endif // SK_VULKAN GrBackendTexture::GrBackendTexture(int width, int height, GrPixelConfig config, - GrGLTextureInfo* glInfo) + const GrGLTextureInfo* glInfo) : fWidth(width) , fHeight(height) , fConfig(config) @@ -43,14 +50,14 @@ GrBackendTexture::GrBackendTexture(const GrBackendTextureDesc& desc, GrBackend b , fBackend(backend) , fHandle(desc.fTextureHandle) {} -GrVkImageInfo* GrBackendTexture::getVkImageInfo() { +const GrVkImageInfo* GrBackendTexture::getVkImageInfo() const { if (kVulkan_GrBackend == fBackend) { return fVkInfo; } return nullptr; } -GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() { +const GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() const { if (kOpenGL_GrBackend == fBackend) { return fGLInfo; } @@ -59,27 +66,31 @@ GrGLTextureInfo* GrBackendTexture::getGLTextureInfo() { //////////////////////////////////////////////////////////////////////////////////////////////////// -#ifdef SK_VULKAN GrBackendRenderTarget::GrBackendRenderTarget(int width, int height, int sampleCnt, int stencilBits, - GrVkImageInfo* vkInfo) + const GrVkImageInfo* vkInfo) : fWidth(width) , fHeight(height) , fSampleCnt(sampleCnt) , fStencilBits(stencilBits) - , fConfig(GrVkFormatToPixelConfig(vkInfo->fFormat)) + , fConfig( +#ifdef SK_VULKAN + GrVkFormatToPixelConfig(vkInfo->fFormat) +#else + kUnknown_GrPixelConfig +#endif + ) , fBackend(kVulkan_GrBackend) , fVkInfo(vkInfo) {} -#endif // SK_VULKAN GrBackendRenderTarget::GrBackendRenderTarget(int width, int height, int sampleCnt, int stencilBits, GrPixelConfig config, - GrGLTextureInfo* glInfo) + const GrGLTextureInfo* glInfo) : fWidth(width) , fHeight(height) , fSampleCnt(sampleCnt) @@ -104,14 +115,14 @@ GrBackendRenderTarget::GrBackendRenderTarget(const GrBackendRenderTargetDesc& de , fBackend(backend) , fHandle(desc.fRenderTargetHandle) {} -GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() { +const GrVkImageInfo* GrBackendRenderTarget::getVkImageInfo() const { if (kVulkan_GrBackend == fBackend) { return fVkInfo; } return nullptr; } -GrGLTextureInfo* GrBackendRenderTarget::getGLTextureInfo() { +const GrGLTextureInfo* GrBackendRenderTarget::getGLTextureInfo() const { if (kOpenGL_GrBackend == fBackend) { return fGLInfo; } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 02ffe3c8a4..7d6a90a44d 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -658,11 +658,15 @@ sk_sp<GrSurfaceContext> GrContextPriv::makeDeferredSurfaceContext(const GrSurfac return this->makeWrappedSurfaceContext(std::move(proxy), nullptr); } -sk_sp<GrSurfaceContext> GrContextPriv::makeBackendSurfaceContext(const GrBackendTextureDesc& desc, +sk_sp<GrSurfaceContext> GrContextPriv::makeBackendSurfaceContext(const GrBackendTexture& tex, + GrSurfaceOrigin origin, + GrBackendTextureFlags flags, + int sampleCnt, sk_sp<SkColorSpace> colorSpace) { ASSERT_SINGLE_OWNER_PRIV - sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTexture(desc)); + sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTexture(tex, origin, + flags, sampleCnt)); if (!surface) { return nullptr; } @@ -676,13 +680,16 @@ sk_sp<GrSurfaceContext> GrContextPriv::makeBackendSurfaceContext(const GrBackend } sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContext( - const GrBackendTextureDesc& desc, + const GrBackendTexture& tex, + GrSurfaceOrigin origin, + int sampleCnt, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* props) { ASSERT_SINGLE_OWNER_PRIV - SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag); - sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTexture(desc)); + static const GrBackendTextureFlags kForceRT = kRenderTarget_GrBackendTextureFlag; + sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTexture(tex, origin, kForceRT, + sampleCnt)); if (!surface) { return nullptr; } @@ -718,13 +725,17 @@ sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendRenderTargetRenderTargetC } sk_sp<GrRenderTargetContext> GrContextPriv::makeBackendTextureAsRenderTargetRenderTargetContext( - const GrBackendTextureDesc& desc, + const GrBackendTexture& tex, + GrSurfaceOrigin origin, + int sampleCnt, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* surfaceProps) { ASSERT_SINGLE_OWNER_PRIV - SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag); - sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTextureAsRenderTarget(desc)); + sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTextureAsRenderTarget( + tex, + origin, + sampleCnt)); if (!surface) { return nullptr; } diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h index 9fa1077009..c85ac2c9b6 100644 --- a/src/gpu/GrContextPriv.h +++ b/src/gpu/GrContextPriv.h @@ -38,11 +38,16 @@ public: // TODO: Maybe add a 'surfaceProps' param (that is ignored for non-RTs) and remove // makeBackendTextureRenderTargetContext & makeBackendTextureAsRenderTargetRenderTargetContext - sk_sp<GrSurfaceContext> makeBackendSurfaceContext(const GrBackendTextureDesc& desc, + sk_sp<GrSurfaceContext> makeBackendSurfaceContext(const GrBackendTexture& tex, + GrSurfaceOrigin origin, + GrBackendTextureFlags flags, + int sampleCnt, sk_sp<SkColorSpace> colorSpace); sk_sp<GrRenderTargetContext> makeBackendTextureRenderTargetContext( - const GrBackendTextureDesc& desc, + const GrBackendTexture& tex, + GrSurfaceOrigin origin, + int sampleCnt, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* = nullptr); @@ -52,7 +57,9 @@ public: const SkSurfaceProps* = nullptr); sk_sp<GrRenderTargetContext> makeBackendTextureAsRenderTargetRenderTargetContext( - const GrBackendTextureDesc& desc, + const GrBackendTexture& tex, + GrSurfaceOrigin origin, + int sampleCnt, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* = nullptr); diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index d4fdb1960b..940bfea194 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -8,6 +8,7 @@ #include "GrGpu.h" +#include "GrBackendSurface.h" #include "GrBuffer.h" #include "GrCaps.h" #include "GrContext.h" @@ -192,21 +193,25 @@ GrTexture* GrGpu::createTexture(const GrSurfaceDesc& origDesc, SkBudgeted budget return tex; } -sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, +sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, + GrSurfaceOrigin origin, + GrBackendTextureFlags flags, + int sampleCnt, GrWrapOwnership ownership) { this->handleDirtyContext(); - if (!this->caps()->isConfigTexturable(desc.fConfig)) { + if (!this->caps()->isConfigTexturable(backendTex.config())) { return nullptr; } - if ((desc.fFlags & kRenderTarget_GrBackendTextureFlag) && - !this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { + if ((flags & kRenderTarget_GrBackendTextureFlag) && + !this->caps()->isConfigRenderable(backendTex.config(), sampleCnt > 0)) { return nullptr; } int maxSize = this->caps()->maxTextureSize(); - if (desc.fWidth > maxSize || desc.fHeight > maxSize) { + if (backendTex.width() > maxSize || backendTex.height() > maxSize) { return nullptr; } - sk_sp<GrTexture> tex = this->onWrapBackendTexture(desc, ownership); + sk_sp<GrTexture> tex = this->onWrapBackendTexture(backendTex, origin, flags, sampleCnt, + ownership); if (!tex) { return nullptr; } @@ -226,19 +231,18 @@ sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTarget return this->onWrapBackendRenderTarget(desc); } -sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc) { +sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, + GrSurfaceOrigin origin, + int sampleCnt) { this->handleDirtyContext(); - if (!(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) { - return nullptr; - } - if (!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) { + if (!this->caps()->isConfigRenderable(tex.config(), sampleCnt > 0)) { return nullptr; } int maxSize = this->caps()->maxTextureSize(); - if (desc.fWidth > maxSize || desc.fHeight > maxSize) { + if (tex.width() > maxSize || tex.height() > maxSize) { return nullptr; } - return this->onWrapBackendTextureAsRenderTarget(desc); + return this->onWrapBackendTextureAsRenderTarget(tex, origin, sampleCnt); } GrBuffer* GrGpu::createBuffer(size_t size, GrBufferType intendedType, diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index df8cb080a4..ad1b199e83 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -124,7 +124,8 @@ public: /** * Implements GrResourceProvider::wrapBackendTexture */ - sk_sp<GrTexture> wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership); + sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture&, GrSurfaceOrigin, + GrBackendTextureFlags, int sampleCnt, GrWrapOwnership); /** * Implements GrResourceProvider::wrapBackendRenderTarget @@ -134,7 +135,9 @@ public: /** * Implements GrResourceProvider::wrapBackendTextureAsRenderTarget */ - sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&); + sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&, + GrSurfaceOrigin, + int sampleCnt); /** * Creates a buffer in GPU memory. For a client-side buffer use GrBuffer::CreateCPUBacked. @@ -542,9 +545,15 @@ private: SkBudgeted budgeted, const SkTArray<GrMipLevel>& texels) = 0; - virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0; + virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, + GrSurfaceOrigin, + GrBackendTextureFlags, + int sampleCnt, + GrWrapOwnership) = 0; virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) = 0; - virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&)=0; + virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, + GrSurfaceOrigin, + int sampleCnt)=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 1226f9b9f6..e7252dec3d 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -240,13 +240,16 @@ GrTexture* GrResourceProvider::refScratchTexture(const GrSurfaceDesc& inDesc, return nullptr; } -sk_sp<GrTexture> GrResourceProvider::wrapBackendTexture(const GrBackendTextureDesc& desc, +sk_sp<GrTexture> GrResourceProvider::wrapBackendTexture(const GrBackendTexture& tex, + GrSurfaceOrigin origin, + GrBackendTextureFlags flags, + int sampleCnt, GrWrapOwnership ownership) { ASSERT_SINGLE_OWNER if (this->isAbandoned()) { return nullptr; } - return fGpu->wrapBackendTexture(desc, ownership); + return fGpu->wrapBackendTexture(tex, origin, flags, sampleCnt, ownership); } sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendRenderTarget( @@ -466,12 +469,12 @@ GrStencilAttachment* GrResourceProvider::attachStencilAttachment(GrRenderTarget* } sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendTextureAsRenderTarget( - const GrBackendTextureDesc& desc) + const GrBackendTexture& tex, GrSurfaceOrigin origin, int sampleCnt) { if (this->isAbandoned()) { return nullptr; } - return this->gpu()->wrapBackendTextureAsRenderTarget(desc); + return this->gpu()->wrapBackendTextureAsRenderTarget(tex, origin, sampleCnt); } sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT GrResourceProvider::makeSemaphore() { diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h index 676d82febc..c3d96ff803 100644 --- a/src/gpu/GrResourceProvider.h +++ b/src/gpu/GrResourceProvider.h @@ -85,7 +85,10 @@ public: * * @return GrTexture object or NULL on failure. */ - sk_sp<GrTexture> wrapBackendTexture(const GrBackendTextureDesc& desc, + sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture& tex, + GrSurfaceOrigin origin, + GrBackendTextureFlags flags, + int sampleCnt, GrWrapOwnership = kBorrow_GrWrapOwnership); /** @@ -199,7 +202,9 @@ public: * * @return GrRenderTarget object or NULL on failure. */ - sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc); + sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTexture&, + GrSurfaceOrigin origin, + int sampleCnt); /** * 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 f2a90ebab6..b55d12a124 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -222,9 +222,11 @@ sk_sp<GrTextureProxy> GrSurfaceProxy::MakeDeferred(GrResourceProvider* resourceP return GrSurfaceProxy::MakeDeferred(resourceProvider, desc, SkBackingFit::kExact, budgeted); } -sk_sp<GrSurfaceProxy> GrSurfaceProxy::MakeWrappedBackend(GrContext* context, - GrBackendTextureDesc& desc) { - sk_sp<GrTexture> tex(context->resourceProvider()->wrapBackendTexture(desc)); +sk_sp<GrTextureProxy> GrSurfaceProxy::MakeWrappedBackend(GrContext* context, + GrBackendTexture& backendTex, + GrSurfaceOrigin origin) { + sk_sp<GrTexture> tex(context->resourceProvider()->wrapBackendTexture( + backendTex, origin, kNone_GrBackendTextureFlag, 0)); return GrSurfaceProxy::MakeWrapped(std::move(tex)); } diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 7665c2a4ee..10fbabbe60 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -8,6 +8,7 @@ #include "GrGLGpu.h" #include "../private/GrGLSL.h" +#include "GrBackendSurface.h" #include "GrFixedClip.h" #include "GrGLBuffer.h" #include "GrGLGpuCommandBuffer.h" @@ -511,15 +512,18 @@ static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) } } -sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, +sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTex, + GrSurfaceOrigin origin, + GrBackendTextureFlags flags, + int sampleCnt, GrWrapOwnership ownership) { - const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle); + const GrGLTextureInfo* info = backendTex.getGLTextureInfo(); if (!info || !info->fID) { return nullptr; } - // next line relies on GrBackendTextureDesc's flags matching GrTexture's - bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag); + // next line relies on GrBackendTextureFlags matching GrTexture's + bool renderTarget = SkToBool(flags & kRenderTarget_GrBackendTextureFlag); SkASSERT(!renderTarget || kAdoptAndCache_GrWrapOwnership != ownership); // Not supported GrGLTexture::IDDesc idDesc; @@ -543,7 +547,7 @@ sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, // 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 (desc.fSampleCnt && !renderTarget) { + if (sampleCnt && !renderTarget) { return nullptr; } @@ -554,19 +558,19 @@ sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, } GrSurfaceDesc surfDesc; - 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()); + surfDesc.fFlags = (GrSurfaceFlags) flags; + surfDesc.fWidth = backendTex.width(); + surfDesc.fHeight = backendTex.height(); + surfDesc.fConfig = backendTex.config(); + surfDesc.fSampleCnt = SkTMin(sampleCnt, 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 == desc.fOrigin) { + if (kDefault_GrSurfaceOrigin == origin) { surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; } else { - surfDesc.fOrigin = desc.fOrigin; + surfDesc.fOrigin = origin; } if (renderTarget) { @@ -603,8 +607,10 @@ sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTa return GrGLRenderTarget::MakeWrapped(this, desc, idDesc, wrapDesc.fStencilBits); } -sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc){ - const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle); +sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, + GrSurfaceOrigin origin, + int sampleCnt) { + const GrGLTextureInfo* info = tex.getGLTextureInfo(); if (!info || !info->fID) { return nullptr; } @@ -621,19 +627,19 @@ sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBacken } GrSurfaceDesc surfDesc; - 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()); + surfDesc.fFlags = kRenderTarget_GrSurfaceFlag; + surfDesc.fWidth = tex.width(); + surfDesc.fHeight = tex.height(); + surfDesc.fConfig = tex.config(); + surfDesc.fSampleCnt = SkTMin(sampleCnt, 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 == desc.fOrigin) { + if (kDefault_GrSurfaceOrigin == origin) { surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; } else { - surfDesc.fOrigin = desc.fOrigin; + surfDesc.fOrigin = origin; } GrGLRenderTarget::IDDesc rtIDDesc; diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index 1fc25576fe..9bfe099d0d 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -170,9 +170,16 @@ private: GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, const void* data) override; - sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override; + + sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, + GrSurfaceOrigin, + GrBackendTextureFlags, + int sampleCnt, + GrWrapOwnership) override; sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override; - sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override; + sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, + GrSurfaceOrigin, + int sampleCnt) override; gr_instanced::InstancedRendering* onCreateInstancedRendering() override; diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index 71a866874c..12d98769cf 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -7,6 +7,7 @@ #include "GrVkGpu.h" +#include "GrBackendSurface.h" #include "GrContextOptions.h" #include "GrGeometryProcessor.h" #include "GrGpuResourceCacheAccess.h" @@ -780,41 +781,39 @@ static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin) { } } -sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc, +sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTexture& backendTex, + GrSurfaceOrigin origin, + GrBackendTextureFlags flags, + int sampleCnt, GrWrapOwnership ownership) { - if (0 == desc.fTextureHandle) { + const GrVkImageInfo* info = backendTex.getVkImageInfo(); + if (!info) { return nullptr; } int maxSize = this->caps()->maxTextureSize(); - if (desc.fWidth > maxSize || desc.fHeight > maxSize) { + if (backendTex.width() > maxSize || backendTex.height() > maxSize) { return nullptr; } - const GrVkImageInfo* info = reinterpret_cast<const GrVkImageInfo*>(desc.fTextureHandle); if (VK_NULL_HANDLE == info->fImage || VK_NULL_HANDLE == info->fAlloc.fMemory) { return nullptr; } -#ifdef SK_DEBUG - VkFormat format; - if (!GrPixelConfigToVkFormat(desc.fConfig, &format)) { - return nullptr; - } - SkASSERT(format == info->fFormat); -#endif + + SkASSERT(backendTex.config() == GrVkFormatToPixelConfig(info->fFormat)); GrSurfaceDesc surfDesc; - // 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); + // 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); 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(desc.fOrigin); + surfDesc.fOrigin = resolve_origin(origin); if (!renderTarget) { return GrVkTexture::MakeWrappedTexture(this, surfDesc, ownership, info); @@ -848,23 +847,23 @@ sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTa return tgt; } -sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendTextureAsRenderTarget( - const GrBackendTextureDesc& wrapDesc){ +sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, + GrSurfaceOrigin origin, + int sampleCnt) { - const GrVkImageInfo* info = - reinterpret_cast<const GrVkImageInfo*>(wrapDesc.fTextureHandle); + const GrVkImageInfo* info = tex.getVkImageInfo(); if (VK_NULL_HANDLE == info->fImage) { return nullptr; } GrSurfaceDesc desc; - 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.fFlags = kRenderTarget_GrSurfaceFlag; + desc.fConfig = tex.config(); + desc.fWidth = tex.width(); + desc.fHeight = tex.height(); + desc.fSampleCnt = SkTMin(sampleCnt, this->caps()->maxSampleCount()); - desc.fOrigin = resolve_origin(wrapDesc.fOrigin); + desc.fOrigin = resolve_origin(origin); sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc, info); return tgt; diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h index 84772713a9..d3e155581e 100644 --- a/src/gpu/vk/GrVkGpu.h +++ b/src/gpu/vk/GrVkGpu.h @@ -175,10 +175,16 @@ private: GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted, const SkTArray<GrMipLevel>&) override { return NULL; } - sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override; - + sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, + GrSurfaceOrigin, + GrBackendTextureFlags, + int sampleCnt, + GrWrapOwnership) override; sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&) override; - sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override; + + sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, + GrSurfaceOrigin, + int sampleCnt) 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 0e74f68577..dd1b0c166e 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -10,6 +10,7 @@ #include <type_traits> #include "SkAutoPixmapStorage.h" +#include "GrBackendSurface.h" #include "GrBitmapTextureMaker.h" #include "GrCaps.h" #include "GrContext.h" @@ -252,16 +253,23 @@ sk_sp<SkImage> SkImage_Gpu::onMakeSubset(const SkIRect& subset) const { /////////////////////////////////////////////////////////////////////////////////////////////////// -static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackendTextureDesc& desc, +static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, + const GrBackendTexture& backendTex, + GrSurfaceOrigin origin, SkAlphaType at, sk_sp<SkColorSpace> colorSpace, GrWrapOwnership ownership, SkImage::TextureReleaseProc releaseProc, SkImage::ReleaseContext releaseCtx) { - if (desc.fWidth <= 0 || desc.fHeight <= 0) { + if (backendTex.width() <= 0 || backendTex.height() <= 0) { return nullptr; } - sk_sp<GrTexture> tex = ctx->resourceProvider()->wrapBackendTexture(desc, ownership); + GrBackendTextureFlags flags = kNone_GrBackendTextureFlag; + sk_sp<GrTexture> tex = ctx->resourceProvider()->wrapBackendTexture(backendTex, + origin, + flags, + 0, + ownership); if (!tex) { return nullptr; } @@ -279,13 +287,19 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx, const GrBackend sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTextureDesc& desc, SkAlphaType at, sk_sp<SkColorSpace> cs, TextureReleaseProc releaseP, ReleaseContext releaseC) { - return new_wrapped_texture_common(ctx, desc, at, std::move(cs), kBorrow_GrWrapOwnership, + 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, releaseP, releaseC); } sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDesc& desc, SkAlphaType at, sk_sp<SkColorSpace> cs) { - return new_wrapped_texture_common(ctx, desc, at, std::move(cs), kAdopt_GrWrapOwnership, + 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, nullptr, nullptr); } @@ -293,17 +307,30 @@ sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx, const GrBackendTexture& tex, GrSurfaceOrigin origin, SkAlphaType at, sk_sp<SkColorSpace> cs, TextureReleaseProc releaseP, ReleaseContext releaseC) { - // This function is not implemented yet - sk_throw(); - return nullptr; + return new_wrapped_texture_common(ctx, tex, origin, at, std::move(cs), kBorrow_GrWrapOwnership, + releaseP, releaseC); } sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext* ctx, const GrBackendTexture& tex, GrSurfaceOrigin origin, SkAlphaType at, sk_sp<SkColorSpace> cs) { - // This function is not implemented yet - sk_throw(); - return nullptr; + 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); + } } static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpace colorSpace, @@ -324,38 +351,31 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac const GrPixelConfig kConfig = nv12 ? kRGBA_8888_GrPixelConfig : kAlpha_8_GrPixelConfig; - 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<GrSurfaceProxy> yProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, yDesc); - sk_sp<GrSurfaceProxy> uProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, uDesc); - sk_sp<GrSurfaceProxy> vProxy; + 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<GrTextureProxy> yProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, yTex, origin); + sk_sp<GrTextureProxy> uProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, uTex, origin); + sk_sp<GrTextureProxy> vProxy; if (nv12) { vProxy = uProxy; } else { - 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); + GrBackendTexture vTex = make_backend_texture_from_handle(backend, + yuvSizes[2].fWidth, + yuvSizes[2].fHeight, + kConfig, + yuvTextureHandles[2]); + vProxy = GrSurfaceProxy::MakeWrappedBackend(ctx, vTex, origin); } if (!yProxy || !uProxy || !vProxy) { return nullptr; @@ -380,9 +400,8 @@ static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac paint.setPorterDuffXPFactory(SkBlendMode::kSrc); paint.addColorFragmentProcessor( GrYUVEffect::MakeYUVToRGB(ctx->resourceProvider(), - sk_ref_sp(yProxy->asTextureProxy()), - sk_ref_sp(uProxy->asTextureProxy()), - sk_ref_sp(vProxy->asTextureProxy()), yuvSizes, colorSpace, nv12)); + yProxy, uProxy, vProxy, + yuvSizes, colorSpace, nv12)); const SkRect rect = SkRect::MakeIWH(width, height); @@ -476,21 +495,21 @@ std::unique_ptr<SkCrossContextImageData> 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<SkCrossContextImageData>(new SkCCIDBackendTexture( - desc, std::move(textureData), info.alphaType(), info.refColorSpace())); + backendTex, texture->origin(), std::move(textureData), + info.alphaType(), info.refColorSpace())); } sk_sp<SkImage> SkCCIDBackendTexture::makeImage(GrContext* context) { @@ -501,7 +520,7 @@ sk_sp<SkImage> 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, fDesc, fAlphaType, + return new_wrapped_texture_common(context, fBackendTex, fOrigin, fAlphaType, std::move(fColorSpace), ownership, nullptr, nullptr); } diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index f024c41b38..96ac31e16c 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -7,6 +7,7 @@ #include "SkSurface_Gpu.h" +#include "GrBackendSurface.h" #include "GrContextPriv.h" #include "GrRenderTargetContextPriv.h" #include "GrResourceProvider.h" @@ -220,22 +221,32 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, if (!context) { return nullptr; } - if (!SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) { + GrBackendTexture tex(desc, context->contextPriv().getBackend()); + return MakeFromBackendTexture(context, tex, desc.fOrigin, desc.fSampleCnt, colorSpace, props); +} + +sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, const GrBackendTexture& tex, + GrSurfaceOrigin origin, int sampleCnt, + sk_sp<SkColorSpace> colorSpace, + const SkSurfaceProps* props) { + if (!context) { return nullptr; } - if (!SkSurface_Gpu::Valid(context, desc.fConfig, colorSpace.get())) { + if (!SkSurface_Gpu::Valid(context, tex.config(), colorSpace.get())) { return nullptr; } sk_sp<GrRenderTargetContext> rtc(context->contextPriv().makeBackendTextureRenderTargetContext( - desc, + tex, + origin, + sampleCnt, std::move(colorSpace), props)); if (!rtc) { return nullptr; } - sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), desc.fWidth, desc.fHeight, + sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), tex.width(), tex.height(), SkGpuDevice::kUninit_InitContents)); if (!device) { return nullptr; @@ -243,14 +254,6 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, return sk_make_sp<SkSurface_Gpu>(std::move(device)); } -sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTexture&, - GrSurfaceOrigin origin, int sampleCnt, - sk_sp<SkColorSpace>, const SkSurfaceProps*) { - // This function is not implemented yet - sk_throw(); - return nullptr; -} - sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context, const GrBackendRenderTargetDesc& desc, sk_sp<SkColorSpace> colorSpace, @@ -296,20 +299,36 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont if (!context) { return nullptr; } - if (!SkSurface_Gpu::Valid(context, desc.fConfig, colorSpace.get())) { + GrBackendTexture tex(desc, context->contextPriv().getBackend()); + return MakeFromBackendTextureAsRenderTarget(context, tex, desc.fOrigin, desc.fSampleCnt, + std::move(colorSpace), props); +} + +sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context, + const GrBackendTexture& tex, + GrSurfaceOrigin origin, + int sampleCnt, + sk_sp<SkColorSpace> colorSpace, + const SkSurfaceProps* props) { + if (!context) { + return nullptr; + } + if (!SkSurface_Gpu::Valid(context, tex.config(), colorSpace.get())) { return nullptr; } sk_sp<GrRenderTargetContext> rtc( context->contextPriv().makeBackendTextureAsRenderTargetRenderTargetContext( - desc, + tex, + origin, + sampleCnt, std::move(colorSpace), props)); if (!rtc) { return nullptr; } - sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), desc.fWidth, desc.fHeight, + sk_sp<SkGpuDevice> device(SkGpuDevice::Make(context, std::move(rtc), tex.width(), tex.height(), SkGpuDevice::kUninit_InitContents)); if (!device) { return nullptr; @@ -317,15 +336,4 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont return sk_make_sp<SkSurface_Gpu>(std::move(device)); } -sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext*, - const GrBackendTexture&, - GrSurfaceOrigin origin, - int sampleCnt, - sk_sp<SkColorSpace>, - const SkSurfaceProps*) { - // This function is not implemented yet - sk_throw(); - return nullptr; -} - #endif |