From 7226c232d73356a37ec8cfef0ed55147e68dd2fd Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Mon, 30 Jul 2018 13:13:17 -0400 Subject: Make GrTextureProxy store a GrTextureType. Removes flag indicating rectangle or external as its now redundant. Bug: skia: Change-Id: Ia475b557390e7a6b0f19f6e189cf8c27090e397c Reviewed-on: https://skia-review.googlesource.com/144346 Reviewed-by: Greg Daniel Commit-Queue: Brian Salomon --- include/gpu/GrSurface.h | 8 ---- include/private/GrTextureProxy.h | 18 +++------ include/private/GrTypesPriv.h | 25 +++++++----- src/core/SkDeferredDisplayListRecorder.cpp | 9 ++++- src/gpu/GrBackendTextureImageGenerator.cpp | 11 +++-- src/gpu/GrGpu.cpp | 2 +- src/gpu/GrProxyProvider.cpp | 65 +++++++++++++++++------------- src/gpu/GrProxyProvider.h | 29 ++++++++----- src/gpu/GrSurfacePriv.h | 6 --- src/gpu/GrTexturePriv.h | 3 ++ src/gpu/GrTextureProxy.cpp | 26 ++++++------ src/gpu/GrTextureProxyPriv.h | 10 ++--- src/gpu/GrTextureRenderTargetProxy.cpp | 11 ++--- src/gpu/GrTextureRenderTargetProxy.h | 4 +- src/gpu/gl/GrGLCaps.cpp | 4 +- src/gpu/gl/GrGLTexture.cpp | 12 ++---- src/gpu/gl/GrGLTexture.h | 3 ++ src/image/SkImage_Gpu.cpp | 36 ++++++++--------- tests/DeferredDisplayListTest.cpp | 4 +- tests/EGLImageTest.cpp | 11 ++--- tests/LazyProxyTest.cpp | 12 +++--- tests/RectangleTextureTest.cpp | 9 +++-- 22 files changed, 162 insertions(+), 156 deletions(-) diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h index 3a7294b26e..a93cacf501 100644 --- a/include/gpu/GrSurface.h +++ b/include/gpu/GrSurface.h @@ -63,14 +63,6 @@ public: GrMipMapped, bool useNextPow2 = false); protected: - void setIsGLTextureRectangleOrExternal() { - SkASSERT(this->asTexture()); - fSurfaceFlags |= GrInternalSurfaceFlags::kIsGLTextureRectangleOrExternal; - } - bool isGLTextureRectangleOrExternal() const { - return fSurfaceFlags & GrInternalSurfaceFlags::kIsGLTextureRectangleOrExternal; - } - void setHasMixedSamples() { SkASSERT(this->asRenderTarget()); fSurfaceFlags |= GrInternalSurfaceFlags::kMixedSampled; diff --git a/include/private/GrTextureProxy.h b/include/private/GrTextureProxy.h index fc7f1c54a7..38469547d1 100644 --- a/include/private/GrTextureProxy.h +++ b/include/private/GrTextureProxy.h @@ -72,12 +72,12 @@ protected: friend class GrTextureProxyPriv; // Deferred version - when constructed with data the origin is always kTopLeft. - GrTextureProxy(const GrSurfaceDesc& srcDesc, GrMipMapped, SkBackingFit, SkBudgeted, - const void* srcData, size_t srcRowBytes, GrInternalSurfaceFlags); + GrTextureProxy(const GrSurfaceDesc& srcDesc, GrMipMapped, GrTextureType, SkBackingFit, + SkBudgeted, const void* srcData, size_t srcRowBytes, GrInternalSurfaceFlags); // Deferred version - no data. - GrTextureProxy(const GrSurfaceDesc& srcDesc, GrSurfaceOrigin, GrMipMapped, SkBackingFit, - SkBudgeted, GrInternalSurfaceFlags); + GrTextureProxy(const GrSurfaceDesc& srcDesc, GrSurfaceOrigin, GrMipMapped, GrTextureType, + SkBackingFit, SkBudgeted, GrInternalSurfaceFlags); // Lazy-callback version // There are two main use cases for lazily-instantiated proxies: @@ -90,7 +90,7 @@ protected: // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not // know the final size until flush time. GrTextureProxy(LazyInstantiateCallback&&, LazyInstantiationType, const GrSurfaceDesc& desc, - GrSurfaceOrigin, GrMipMapped, SkBackingFit, SkBudgeted, + GrSurfaceOrigin, GrMipMapped, GrTextureType, SkBackingFit, SkBudgeted, GrInternalSurfaceFlags); // Wrapped version @@ -100,15 +100,9 @@ protected: sk_sp createSurface(GrResourceProvider*) const override; - void setIsGLTextureRectangleOrExternal() { - fSurfaceFlags |= GrInternalSurfaceFlags::kIsGLTextureRectangleOrExternal; - } - bool isGLTextureRectangleOrExternal() const { - return fSurfaceFlags & GrInternalSurfaceFlags::kIsGLTextureRectangleOrExternal; - } - private: GrMipMapped fMipMapped; + GrTextureType fTextureType; GrUniqueKey fUniqueKey; GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h index db25236e3d..ef6fa54841 100644 --- a/include/private/GrTypesPriv.h +++ b/include/private/GrTypesPriv.h @@ -503,6 +503,20 @@ static inline GrSLType GrSLCombinedSamplerTypeForTextureType(GrTextureType type) return kTexture2DSampler_GrSLType; } +/** Rectangle and external textures ony support the clamp wrap mode and do not support MIP maps. */ +static inline bool GrTextureTypeHasRestrictedSampling(GrTextureType type) { + switch (type) { + case GrTextureType::k2D: + return false; + case GrTextureType::kRectangle: + return true; + case GrTextureType::kExternal: + return true; + } + SK_ABORT("Unexpected texture type"); + return false; +} + static inline bool GrSLTypeIsCombinedSamplerType(GrSLType type) { switch (type) { case kTexture2DSampler_GrSLType: @@ -851,17 +865,6 @@ enum class GrInternalSurfaceFlags { kSurfaceMask = kNoPendingIO, - // Texture-only flags - - // This flag is for GL only. It says that the GL texture we will use has a target which is - // either GL_TEXTURE_RECTANGLE or GL_GL_TEXTURE_EXTERNAL. We use this information to make - // decisions about various rendering capabilites (e.g. is clamp the only supported wrap mode). - // Note: Ganesh does not internally create these types of textures so they will only occur on - // resources passed into Ganesh. - kIsGLTextureRectangleOrExternal = 1 << 1, - - kTextureMask = kIsGLTextureRectangleOrExternal, - // RT-only // For internal resources: diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp index d13fd3915e..b6989846e3 100644 --- a/src/core/SkDeferredDisplayListRecorder.cpp +++ b/src/core/SkDeferredDisplayListRecorder.cpp @@ -113,6 +113,12 @@ bool SkDeferredDisplayListRecorder::init() { if (usesGLFBO0) { surfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0; } + static constexpr GrProxyProvider::TextureInfo kTextureInfo{GrMipMapped::kNo, + GrTextureType::k2D}; + const GrProxyProvider::TextureInfo* optionalTextureInfo = nullptr; + if (fCharacterization.isTextureable()) { + optionalTextureInfo = &kTextureInfo; + } sk_sp proxy = proxyProvider->createLazyRenderTargetProxy( [lazyProxyData](GrResourceProvider* resourceProvider) { @@ -128,8 +134,7 @@ bool SkDeferredDisplayListRecorder::init() { desc, fCharacterization.origin(), surfaceFlags, - GrProxyProvider::Textureable(fCharacterization.isTextureable()), - GrMipMapped::kNo, + optionalTextureInfo, SkBackingFit::kExact, SkBudgeted::kYes); diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp index 466a842f23..74722c66f4 100644 --- a/src/gpu/GrBackendTextureImageGenerator.cpp +++ b/src/gpu/GrBackendTextureImageGenerator.cpp @@ -6,7 +6,6 @@ */ #include "GrBackendTextureImageGenerator.h" - #include "GrContext.h" #include "GrContextPriv.h" #include "GrGpu.h" @@ -19,9 +18,9 @@ #include "GrTexture.h" #include "GrTexturePriv.h" #include "GrTextureProxyPriv.h" - #include "SkGr.h" #include "SkMessageBus.h" +#include "gl/GrGLTexture.h" GrBackendTextureImageGenerator::RefHelper::~RefHelper() { SkASSERT(nullptr == fBorrowedTexture); @@ -134,6 +133,11 @@ sk_sp GrBackendTextureImageGenerator::onGenerateTexture( GrBackendTexture backendTexture = fBackendTexture; RefHelper* refHelper = fRefHelper; + GrTextureType textureType = GrTextureType::k2D; + GrGLTextureInfo glInfo; + if (backendTexture.getGLTextureInfo(&glInfo)) { + textureType = GrGLTexture::TextureTypeFromTarget(glInfo.fTarget); + } sk_sp proxy = proxyProvider->createLazyProxy( [refHelper, releaseProcHelper, semaphore, backendTexture](GrResourceProvider* resourceProvider) { @@ -171,9 +175,8 @@ sk_sp GrBackendTextureImageGenerator::onGenerateTexture( } return tex; - }, - desc, fSurfaceOrigin, mipMapped, SkBackingFit::kExact, SkBudgeted::kNo); + desc, fSurfaceOrigin, mipMapped, textureType, SkBackingFit::kExact, SkBudgeted::kNo); if (!proxy) { return nullptr; diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index 4b7e786f87..62eef097a0 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -74,7 +74,7 @@ bool GrGpu::IsACopyNeededForRepeatWrapMode(const GrCaps* caps, GrTextureProxy* t if (texProxy) { // If the texture format itself doesn't support repeat wrap mode or mipmapping (and // those capabilities are required) force a copy. - if (texProxy->texPriv().isClampOnly()) { + if (texProxy->texPriv().hasRestrictedSampling()) { copyParams->fFilter = GrSamplerState::Filter::kNearest; copyParams->fWidth = texProxy->width(); copyParams->fHeight = texProxy->height(); diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp index df7b61e700..67643d7931 100644 --- a/src/gpu/GrProxyProvider.cpp +++ b/src/gpu/GrProxyProvider.cpp @@ -275,7 +275,8 @@ sk_sp GrProxyProvider::createTextureProxy(sk_sp srcImag return resourceProvider->createTexture(desc, budgeted, fit, mipLevel); }, - desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, surfaceFlags, fit, budgeted); + desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrTextureType::k2D, surfaceFlags, fit, + budgeted); if (!proxy) { return nullptr; @@ -373,8 +374,8 @@ sk_sp GrProxyProvider::createMipMapProxyFromBitmap(const SkBitma return resourceProvider->createTexture(desc, SkBudgeted::kYes, texels.get(), mipLevelCount); }, - desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kYes, SkBackingFit::kExact, - SkBudgeted::kYes); + desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kYes, GrTextureType::k2D, + SkBackingFit::kExact, SkBudgeted::kYes); if (!proxy) { return nullptr; @@ -416,12 +417,13 @@ sk_sp GrProxyProvider::createProxy(const GrSurfaceDesc& desc, if (copyDesc.fFlags & kRenderTarget_GrSurfaceFlag) { // We know anything we instantiate later from this deferred path will be // both texturable and renderable - return sk_sp(new GrTextureRenderTargetProxy( - *this->caps(), copyDesc, origin, mipMapped, fit, budgeted, surfaceFlags)); + return sk_sp(new GrTextureRenderTargetProxy(*this->caps(), copyDesc, origin, + mipMapped, GrTextureType::k2D, + fit, budgeted, surfaceFlags)); } - return sk_sp( - new GrTextureProxy(copyDesc, origin, mipMapped, fit, budgeted, surfaceFlags)); + return sk_sp(new GrTextureProxy(copyDesc, origin, mipMapped, GrTextureType::k2D, + fit, budgeted, surfaceFlags)); } sk_sp GrProxyProvider::wrapBackendTexture(const GrBackendTexture& backendTex, @@ -537,9 +539,11 @@ sk_sp GrProxyProvider::wrapBackendTextureAsRenderTarget( sk_sp GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback, const GrSurfaceDesc& desc, GrSurfaceOrigin origin, - GrMipMapped mipMapped, SkBackingFit fit, + GrMipMapped mipMapped, + GrTextureType textureType, + SkBackingFit fit, SkBudgeted budgeted) { - return this->createLazyProxy(std::move(callback), desc, origin, mipMapped, + return this->createLazyProxy(std::move(callback), desc, origin, mipMapped, textureType, GrInternalSurfaceFlags::kNone, fit, budgeted); } @@ -547,21 +551,25 @@ sk_sp GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& const GrSurfaceDesc& desc, GrSurfaceOrigin origin, GrMipMapped mipMapped, + GrTextureType textureType, GrInternalSurfaceFlags surfaceFlags, - SkBackingFit fit, SkBudgeted budgeted) { + SkBackingFit fit, + SkBudgeted budgeted) { // For non-ddl draws always make lazy proxy's single use. LazyInstantiationType lazyType = fResourceProvider ? LazyInstantiationType::kSingleUse : LazyInstantiationType::kMultipleUse; - return this->createLazyProxy(std::move(callback), desc, origin, mipMapped, surfaceFlags, - fit, budgeted, lazyType); + return this->createLazyProxy(std::move(callback), desc, origin, mipMapped, textureType, + surfaceFlags, fit, budgeted, lazyType); } sk_sp GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback, const GrSurfaceDesc& desc, GrSurfaceOrigin origin, GrMipMapped mipMapped, + GrTextureType textureType, GrInternalSurfaceFlags surfaceFlags, - SkBackingFit fit, SkBudgeted budgeted, + SkBackingFit fit, + SkBudgeted budgeted, LazyInstantiationType lazyType) { SkASSERT((desc.fWidth <= 0 && desc.fHeight <= 0) || (desc.fWidth > 0 && desc.fHeight > 0)); @@ -585,15 +593,16 @@ sk_sp GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& return sk_sp( SkToBool(kRenderTarget_GrSurfaceFlag & desc.fFlags) ? new GrTextureRenderTargetProxy(std::move(callback), lazyType, desc, origin, - mipMapped, fit, budgeted, surfaceFlags) + mipMapped, textureType, fit, budgeted, + surfaceFlags) : new GrTextureProxy(std::move(callback), lazyType, desc, origin, mipMapped, - fit, budgeted, surfaceFlags)); + textureType, fit, budgeted, surfaceFlags)); } sk_sp GrProxyProvider::createLazyRenderTargetProxy( LazyInstantiateCallback&& callback, const GrSurfaceDesc& desc, GrSurfaceOrigin origin, - GrInternalSurfaceFlags surfaceFlags, Textureable textureable, GrMipMapped mipMapped, - SkBackingFit fit, SkBudgeted budgeted) { + GrInternalSurfaceFlags surfaceFlags, const TextureInfo* textureInfo, SkBackingFit fit, + SkBudgeted budgeted) { SkASSERT((desc.fWidth <= 0 && desc.fHeight <= 0) || (desc.fWidth > 0 && desc.fHeight > 0)); @@ -617,10 +626,10 @@ sk_sp GrProxyProvider::createLazyRenderTargetProxy( LazyInstantiationType lazyType = fResourceProvider ? LazyInstantiationType::kSingleUse : LazyInstantiationType::kMultipleUse; - if (Textureable::kYes == textureable) { - return sk_sp( - new GrTextureRenderTargetProxy(std::move(callback), lazyType, desc, origin, - mipMapped, fit, budgeted, surfaceFlags)); + if (textureInfo) { + return sk_sp(new GrTextureRenderTargetProxy( + std::move(callback), lazyType, desc, origin, textureInfo->fMipMapped, + textureInfo->fTextureType, fit, budgeted, surfaceFlags)); } return sk_sp(new GrRenderTargetProxy( @@ -645,16 +654,16 @@ sk_sp GrProxyProvider::MakeFullyLazyProxy(LazyInstantiateCallbac desc.fConfig = config; desc.fSampleCnt = 1; + static constexpr auto kTextureType = GrTextureType::k2D; return sk_sp( (Renderable::kYes == renderable) - ? new GrTextureRenderTargetProxy(std::move(callback), - LazyInstantiationType::kSingleUse, desc, - origin, GrMipMapped::kNo, - SkBackingFit::kApprox, SkBudgeted::kYes, - surfaceFlags) + ? new GrTextureRenderTargetProxy( + std::move(callback), LazyInstantiationType::kSingleUse, desc, origin, + GrMipMapped::kNo, kTextureType, SkBackingFit::kApprox, + SkBudgeted::kYes, surfaceFlags) : new GrTextureProxy(std::move(callback), LazyInstantiationType::kSingleUse, - desc, origin, GrMipMapped::kNo, SkBackingFit::kApprox, - SkBudgeted::kYes, surfaceFlags)); + desc, origin, GrMipMapped::kNo, kTextureType, + SkBackingFit::kApprox, SkBudgeted::kYes, surfaceFlags)); } bool GrProxyProvider::IsFunctionallyExact(GrSurfaceProxy* proxy) { diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h index 89f9518e46..87d6f27de2 100644 --- a/src/gpu/GrProxyProvider.h +++ b/src/gpu/GrProxyProvider.h @@ -148,16 +148,17 @@ public: int sampleCnt); using LazyInstantiateCallback = std::function(GrResourceProvider*)>; - enum class Textureable : bool { - kNo = false, - kYes = true - }; enum class Renderable : bool { kNo = false, kYes = true }; + struct TextureInfo { + GrMipMapped fMipMapped; + GrTextureType fTextureType; + }; + using LazyInstantiationType = GrSurfaceProxy::LazyInstantiationType; /** * Creates a texture proxy that will be instantiated by a user-supplied callback during flush. @@ -170,20 +171,26 @@ public: * callback should cleanup any resources it captured and return an empty sk_sp. */ sk_sp createLazyProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&, - GrSurfaceOrigin, GrMipMapped, GrInternalSurfaceFlags, - SkBackingFit, SkBudgeted, LazyInstantiationType); + GrSurfaceOrigin, GrMipMapped, GrTextureType, + GrInternalSurfaceFlags, SkBackingFit, SkBudgeted, + LazyInstantiationType); sk_sp createLazyProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&, - GrSurfaceOrigin, GrMipMapped, GrInternalSurfaceFlags, - SkBackingFit, SkBudgeted); + GrSurfaceOrigin, GrMipMapped, GrTextureType, + GrInternalSurfaceFlags, SkBackingFit, SkBudgeted); sk_sp createLazyProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&, - GrSurfaceOrigin, GrMipMapped, SkBackingFit, SkBudgeted); + GrSurfaceOrigin, GrMipMapped, GrTextureType, SkBackingFit, + SkBudgeted); + + /** A null TextureInfo indicates a non-textureable render target. */ sk_sp createLazyRenderTargetProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&, GrSurfaceOrigin origin, - GrInternalSurfaceFlags, Textureable, - GrMipMapped, SkBackingFit, SkBudgeted); + GrInternalSurfaceFlags, + const TextureInfo*, + SkBackingFit, + SkBudgeted); /** * Fully lazy proxies have unspecified width and height. Methods that rely on those values diff --git a/src/gpu/GrSurfacePriv.h b/src/gpu/GrSurfacePriv.h index 45a097b780..4d61dca5ee 100644 --- a/src/gpu/GrSurfacePriv.h +++ b/src/gpu/GrSurfacePriv.h @@ -40,12 +40,6 @@ public: GrInternalSurfaceFlags flags() const { return fSurface->fSurfaceFlags; } - bool isGLTextureRectangleOrExternal() const { - return fSurface->isGLTextureRectangleOrExternal(); - } - // We only support the clamp wrap mode with gl rectangle or external textures. - bool isClampOnly() const { return fSurface->isGLTextureRectangleOrExternal(); } - private: explicit GrSurfacePriv(GrSurface* surface) : fSurface(surface) {} GrSurfacePriv(const GrSurfacePriv&); // unimpl diff --git a/src/gpu/GrTexturePriv.h b/src/gpu/GrTexturePriv.h index 316afbc4c4..47556e476a 100644 --- a/src/gpu/GrTexturePriv.h +++ b/src/gpu/GrTexturePriv.h @@ -41,6 +41,9 @@ public: } GrTextureType textureType() const { return fTexture->fTextureType; } + bool hasRestrictedSampling() const { + return GrTextureTypeHasRestrictedSampling(this->textureType()); + } /** The filter used is clamped to this value in GrProcessor::TextureSampler. */ GrSamplerState::Filter highestFilterMode() const { return fTexture->fHighestFilterMode; } diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp index b25efd95f5..fc6a2fae16 100644 --- a/src/gpu/GrTextureProxy.cpp +++ b/src/gpu/GrTextureProxy.cpp @@ -17,10 +17,12 @@ // Deferred version - with data GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, GrMipMapped mipMapped, - SkBackingFit fit, SkBudgeted budgeted, const void* srcData, - size_t /*rowBytes*/, GrInternalSurfaceFlags surfaceFlags) + GrTextureType textureType, SkBackingFit fit, SkBudgeted budgeted, + const void* srcData, size_t /*rowBytes*/, + GrInternalSurfaceFlags surfaceFlags) : INHERITED(srcDesc, kTopLeft_GrSurfaceOrigin, fit, budgeted, surfaceFlags) , fMipMapped(mipMapped) + , fTextureType(textureType) , fProxyProvider(nullptr) , fDeferredUploader(nullptr) { SkASSERT(!srcData); // currently handled in Make() @@ -28,28 +30,30 @@ GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, GrMipMapped mipMapp // Deferred version - no data GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, GrSurfaceOrigin origin, - GrMipMapped mipMapped, SkBackingFit fit, SkBudgeted budgeted, - GrInternalSurfaceFlags surfaceFlags) + GrMipMapped mipMapped, GrTextureType textureType, SkBackingFit fit, + SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags) : INHERITED(srcDesc, origin, fit, budgeted, surfaceFlags) , fMipMapped(mipMapped) + , fTextureType(textureType) , fProxyProvider(nullptr) , fDeferredUploader(nullptr) {} // Lazy-callback version GrTextureProxy::GrTextureProxy(LazyInstantiateCallback&& callback, LazyInstantiationType lazyType, const GrSurfaceDesc& desc, GrSurfaceOrigin origin, - GrMipMapped mipMapped, SkBackingFit fit, SkBudgeted budgeted, - GrInternalSurfaceFlags surfaceFlags) + GrMipMapped mipMapped, GrTextureType textureType, SkBackingFit fit, + SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags) : INHERITED(std::move(callback), lazyType, desc, origin, fit, budgeted, surfaceFlags) , fMipMapped(mipMapped) + , fTextureType(textureType) , fProxyProvider(nullptr) - , fDeferredUploader(nullptr) { -} + , fDeferredUploader(nullptr) {} // Wrapped version GrTextureProxy::GrTextureProxy(sk_sp surf, GrSurfaceOrigin origin) : INHERITED(std::move(surf), origin, SkBackingFit::kExact) , fMipMapped(fTarget->asTexture()->texturePriv().mipMapped()) + , fTextureType(fTarget->asTexture()->texturePriv().textureType()) , fProxyProvider(nullptr) , fDeferredUploader(nullptr) { if (fTarget->getUniqueKey().isValid()) { @@ -167,11 +171,7 @@ void GrTextureProxy::onValidateSurface(const GrSurface* surface) { SkASSERT(surface->asTexture()); SkASSERT(GrMipMapped::kNo == this->texPriv().proxyMipMapped() || GrMipMapped::kYes == surface->asTexture()->texturePriv().mipMapped()); - - GrInternalSurfaceFlags proxyFlags = fSurfaceFlags; - GrInternalSurfaceFlags surfaceFlags = surface->surfacePriv().flags(); - SkASSERT((proxyFlags & GrInternalSurfaceFlags::kTextureMask) == - (surfaceFlags & GrInternalSurfaceFlags::kTextureMask)); + SkASSERT(surface->asTexture()->texturePriv().textureType() == fTextureType); } #endif diff --git a/src/gpu/GrTextureProxyPriv.h b/src/gpu/GrTextureProxyPriv.h index 358369d516..519e96b497 100644 --- a/src/gpu/GrTextureProxyPriv.h +++ b/src/gpu/GrTextureProxyPriv.h @@ -31,14 +31,10 @@ public: // been instantiated or not. GrMipMapped proxyMipMapped() const { return fTextureProxy->fMipMapped; } - bool isGLTextureRectangleOrExternal() const { - return fTextureProxy->isGLTextureRectangleOrExternal(); + GrTextureType textureType() const { return fTextureProxy->fTextureType; } + bool hasRestrictedSampling() const { + return GrTextureTypeHasRestrictedSampling(this->textureType()); } - // We assume that if a texture is not a GL_TEXTURE_RECTANGLE or GL_TEXTURE_EXTERNAL then it is a - // GL_TEXTURE_2D - bool isGLTexture2D() const { return !fTextureProxy->isGLTextureRectangleOrExternal(); } - // We only support the clamp wrap mode with gl rectangle or external textures. - bool isClampOnly() const { return fTextureProxy->isGLTextureRectangleOrExternal(); } private: explicit GrTextureProxyPriv(GrTextureProxy* textureProxy) : fTextureProxy(textureProxy) {} diff --git a/src/gpu/GrTextureRenderTargetProxy.cpp b/src/gpu/GrTextureRenderTargetProxy.cpp index 95d5543bbf..5b87399daa 100644 --- a/src/gpu/GrTextureRenderTargetProxy.cpp +++ b/src/gpu/GrTextureRenderTargetProxy.cpp @@ -22,12 +22,13 @@ GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc, GrSurfaceOrigin origin, GrMipMapped mipMapped, + GrTextureType textureType, SkBackingFit fit, SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags) : GrSurfaceProxy(desc, origin, fit, budgeted, surfaceFlags) // for now textures w/ data are always wrapped - , GrTextureProxy(desc, origin, mipMapped, fit, budgeted, surfaceFlags) + , GrTextureProxy(desc, origin, mipMapped, textureType, fit, budgeted, surfaceFlags) , GrRenderTargetProxy(caps, desc, origin, fit, budgeted, surfaceFlags) {} // Lazy-callback version @@ -36,14 +37,15 @@ GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(LazyInstantiateCallback&& const GrSurfaceDesc& desc, GrSurfaceOrigin origin, GrMipMapped mipMapped, + GrTextureType textureType, SkBackingFit fit, SkBudgeted budgeted, GrInternalSurfaceFlags surfaceFlags) : GrSurfaceProxy(std::move(callback), lazyType, desc, origin, fit, budgeted, surfaceFlags) // Since we have virtual inheritance, we initialize GrSurfaceProxy directly. Send null // callbacks to the texture and RT proxies simply to route to the appropriate constructors. - , GrTextureProxy(LazyInstantiateCallback(), lazyType, desc, origin, mipMapped, fit, - budgeted, surfaceFlags) + , GrTextureProxy(LazyInstantiateCallback(), lazyType, desc, origin, mipMapped, textureType, + fit, budgeted, surfaceFlags) , GrRenderTargetProxy(LazyInstantiateCallback(), lazyType, desc, origin, fit, budgeted, surfaceFlags) {} @@ -123,10 +125,9 @@ void GrTextureRenderTargetProxy::onValidateSurface(const GrSurface* surface) { GrInternalSurfaceFlags proxyFlags = fSurfaceFlags; GrInternalSurfaceFlags surfaceFlags = surface->surfacePriv().flags(); - SkASSERT((proxyFlags & GrInternalSurfaceFlags::kTextureMask) == - (surfaceFlags & GrInternalSurfaceFlags::kTextureMask)); SkASSERT((proxyFlags & GrInternalSurfaceFlags::kRenderTargetMask) == (surfaceFlags & GrInternalSurfaceFlags::kRenderTargetMask)); + SkASSERT(surface->asTexture()->texturePriv().textureType() == this->texPriv().textureType()); } #endif diff --git a/src/gpu/GrTextureRenderTargetProxy.h b/src/gpu/GrTextureRenderTargetProxy.h index 141597ec76..f2f3edb41a 100644 --- a/src/gpu/GrTextureRenderTargetProxy.h +++ b/src/gpu/GrTextureRenderTargetProxy.h @@ -29,12 +29,12 @@ private: // Deferred version GrTextureRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&, GrSurfaceOrigin, GrMipMapped, - SkBackingFit, SkBudgeted, GrInternalSurfaceFlags); + GrTextureType, SkBackingFit, SkBudgeted, GrInternalSurfaceFlags); // Lazy-callback version GrTextureRenderTargetProxy(LazyInstantiateCallback&&, LazyInstantiationType, const GrSurfaceDesc& desc, GrSurfaceOrigin, GrMipMapped, - SkBackingFit, SkBudgeted, GrInternalSurfaceFlags); + GrTextureType, SkBackingFit, SkBudgeted, GrInternalSurfaceFlags); // Wrapped version GrTextureRenderTargetProxy(sk_sp, GrSurfaceOrigin); diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 5532e36bd0..0fc88437b0 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -2185,8 +2185,8 @@ bool GrGLCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* s const GrTextureProxy* dstTex = dst->asTextureProxy(); const GrTextureProxy* srcTex = src->asTextureProxy(); - bool dstIsTex2D = dstTex ? dstTex->texPriv().isGLTexture2D() : false; - bool srcIsTex2D = srcTex ? srcTex->texPriv().isGLTexture2D() : false; + bool dstIsTex2D = dstTex ? (dstTex->texPriv().textureType() == GrTextureType::k2D) : false; + bool srcIsTex2D = srcTex ? (srcTex->texPriv().textureType() == GrTextureType::k2D) : false; // One of the possible requirements for copy as blit is that the srcRect must match the bounds // of the src surface. If we have a approx fit surface we can't know for sure what the src diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp index f0fafabcba..200c8d22e8 100644 --- a/src/gpu/gl/GrGLTexture.cpp +++ b/src/gpu/gl/GrGLTexture.cpp @@ -15,7 +15,7 @@ #define GPUGL static_cast(this->getGpu()) #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) -static inline GrTextureType texture_type_from_target(GrGLenum target) { +GrTextureType GrGLTexture::TextureTypeFromTarget(GrGLenum target) { switch (target) { case GR_GL_TEXTURE_2D: return GrTextureType::k2D; @@ -55,7 +55,7 @@ static inline GrSamplerState::Filter highest_filter_mode(const GrGLTexture::IDDe GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, const IDDesc& idDesc, GrMipMapsStatus mipMapsStatus) : GrSurface(gpu, desc) - , INHERITED(gpu, desc, texture_type_from_target(idDesc.fInfo.fTarget), + , INHERITED(gpu, desc, TextureTypeFromTarget(idDesc.fInfo.fTarget), highest_filter_mode(idDesc, desc.fConfig), mipMapsStatus) { this->init(desc, idDesc); this->registerWithCache(budgeted); @@ -64,7 +64,7 @@ GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc, GrMipMapsStatus mipMapsStatus, const IDDesc& idDesc) : GrSurface(gpu, desc) - , INHERITED(gpu, desc, texture_type_from_target(idDesc.fInfo.fTarget), + , INHERITED(gpu, desc, TextureTypeFromTarget(idDesc.fInfo.fTarget), highest_filter_mode(idDesc, desc.fConfig), mipMapsStatus) { this->init(desc, idDesc); this->registerWithCacheWrapped(); @@ -73,7 +73,7 @@ GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc, GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& idDesc, GrMipMapsStatus mipMapsStatus) : GrSurface(gpu, desc) - , INHERITED(gpu, desc, texture_type_from_target(idDesc.fInfo.fTarget), + , INHERITED(gpu, desc, TextureTypeFromTarget(idDesc.fInfo.fTarget), highest_filter_mode(idDesc, desc.fConfig), mipMapsStatus) { this->init(desc, idDesc); } @@ -81,10 +81,6 @@ GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, const IDDesc& void GrGLTexture::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { SkASSERT(0 != idDesc.fInfo.fID); SkASSERT(0 != idDesc.fInfo.fFormat); - if (idDesc.fInfo.fTarget == GR_GL_TEXTURE_RECTANGLE || - idDesc.fInfo.fTarget == GR_GL_TEXTURE_EXTERNAL) { - this->setIsGLTextureRectangleOrExternal(); - } fTexParams.invalidate(); fTexParamsTimestamp = GrGpu::kExpiredTimestamp; fID = idDesc.fInfo.fID; diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h index 298f1faf11..cb029cca81 100644 --- a/src/gpu/gl/GrGLTexture.h +++ b/src/gpu/gl/GrGLTexture.h @@ -31,6 +31,9 @@ public: GrGLTextureInfo fInfo; GrBackendObjectOwnership fOwnership; }; + + static GrTextureType TextureTypeFromTarget(GrGLenum textureTarget); + GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus); ~GrGLTexture() override { diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 1dea80659a..58aa1bc86a 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -9,10 +9,9 @@ #include #include -#include "SkAutoPixmapStorage.h" +#include "GrAHardwareBufferImageGenerator.h" #include "GrBackendSurface.h" #include "GrBackendTextureImageGenerator.h" -#include "GrAHardwareBufferImageGenerator.h" #include "GrBitmapTextureMaker.h" #include "GrCaps.h" #include "GrColorSpaceXform.h" @@ -25,23 +24,24 @@ #include "GrResourceProvider.h" #include "GrSemaphore.h" #include "GrSurfacePriv.h" -#include "GrTextureAdjuster.h" #include "GrTexture.h" +#include "GrTextureAdjuster.h" #include "GrTexturePriv.h" #include "GrTextureProxy.h" #include "GrTextureProxyPriv.h" -#include "gl/GrGLDefines.h" -#include "effects/GrYUVtoRGBEffect.h" -#include "SkCanvas.h" +#include "SkAutoPixmapStorage.h" #include "SkBitmapCache.h" +#include "SkCanvas.h" #include "SkGr.h" -#include "SkImage_Gpu.h" #include "SkImageCacherator.h" #include "SkImageInfoPriv.h" +#include "SkImage_Gpu.h" #include "SkMipMap.h" #include "SkPixelRef.h" #include "SkReadPixelsRec.h" #include "SkTraceEvent.h" +#include "effects/GrYUVtoRGBEffect.h" +#include "gl/GrGLTexture.h" SkImage_Gpu::SkImage_Gpu(sk_sp context, uint32_t uniqueID, SkAlphaType at, sk_sp proxy, sk_sp colorSpace, @@ -651,14 +651,11 @@ private: sk_sp fDoneHelper; }; -static GrInternalSurfaceFlags get_flags_from_format(const GrBackendFormat& backendFormat) { +static GrTextureType TextureTypeFromBackendFormat(const GrBackendFormat& backendFormat) { if (const GrGLenum* target = backendFormat.getGLTarget()) { - if (GR_GL_TEXTURE_RECTANGLE == *target || GR_GL_TEXTURE_EXTERNAL == *target) { - return GrInternalSurfaceFlags::kIsGLTextureRectangleOrExternal; - } + return GrGLTexture::TextureTypeFromTarget(*target); } - - return GrInternalSurfaceFlags::kNone; + return GrTextureType::k2D; } sk_sp SkImage_Gpu::MakePromiseTexture(GrContext* context, @@ -696,10 +693,9 @@ sk_sp SkImage_Gpu::MakePromiseTexture(GrContext* context, return nullptr; } - GrInternalSurfaceFlags formatFlags = get_flags_from_format(backendFormat); + GrTextureType textureType = TextureTypeFromBackendFormat(backendFormat); - if (mipMapped == GrMipMapped::kYes && - SkToBool(formatFlags & GrInternalSurfaceFlags::kIsGLTextureRectangleOrExternal)) { + if (mipMapped == GrMipMapped::kYes && GrTextureTypeHasRestrictedSampling(textureType)) { // It is invalid to have a GL_TEXTURE_EXTERNAL or GL_TEXTURE_RECTANGLE and have mips as // well. return nullptr; @@ -716,15 +712,17 @@ sk_sp SkImage_Gpu::MakePromiseTexture(GrContext* context, textureContext); sk_sp proxy = proxyProvider->createLazyProxy( - [promiseHelper, config] (GrResourceProvider* resourceProvider) mutable { + [promiseHelper, config](GrResourceProvider* resourceProvider) mutable { if (!resourceProvider) { promiseHelper.reset(); return sk_sp(); } return promiseHelper.getTexture(resourceProvider, config); - }, desc, origin, mipMapped, formatFlags, SkBackingFit::kExact, - SkBudgeted::kNo, GrSurfaceProxy::LazyInstantiationType::kUninstantiate); + }, + desc, origin, mipMapped, textureType, GrInternalSurfaceFlags::kNone, + SkBackingFit::kExact, SkBudgeted::kNo, + GrSurfaceProxy::LazyInstantiationType::kUninstantiate); if (!proxy) { return nullptr; diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp index afe93ad61c..ff25d687c1 100644 --- a/tests/DeferredDisplayListTest.cpp +++ b/tests/DeferredDisplayListTest.cpp @@ -873,9 +873,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(DDLTextureFlagsTest, reporter, ctxInfo) { REPORTER_ASSERT(reporter, backingProxy->mipMapped() == mipMapped); if (GR_GL_TEXTURE_2D == target) { - REPORTER_ASSERT(reporter, !backingProxy->texPriv().isClampOnly()); + REPORTER_ASSERT(reporter, !backingProxy->texPriv().hasRestrictedSampling()); } else { - REPORTER_ASSERT(reporter, backingProxy->texPriv().isClampOnly()); + REPORTER_ASSERT(reporter, backingProxy->texPriv().hasRestrictedSampling()); } } } diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp index 51da718953..73dd761854 100644 --- a/tests/EGLImageTest.cpp +++ b/tests/EGLImageTest.cpp @@ -172,11 +172,12 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(EGLImageTest, reporter, ctxInfo) { REPORTER_ASSERT(reporter, proxy->priv().peekTexture()->texturePriv().mipMapped() == GrMipMapped::kNo); - REPORTER_ASSERT(reporter, proxy->texPriv().isGLTextureRectangleOrExternal()); - REPORTER_ASSERT(reporter, - proxy->priv().peekTexture()->surfacePriv().isGLTextureRectangleOrExternal()); - REPORTER_ASSERT(reporter, proxy->texPriv().isClampOnly()); - REPORTER_ASSERT(reporter, proxy->priv().peekTexture()->surfacePriv().isClampOnly()); + REPORTER_ASSERT(reporter, proxy->texPriv().textureType() == GrTextureType::kExternal); + REPORTER_ASSERT( + reporter, + proxy->priv().peekTexture()->texturePriv().textureType() == GrTextureType::kExternal); + REPORTER_ASSERT(reporter, proxy->texPriv().hasRestrictedSampling()); + REPORTER_ASSERT(reporter, proxy->priv().peekTexture()->texturePriv().hasRestrictedSampling()); // Should not be able to wrap as a RT { diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp index 7945ec6714..27321a7e74 100644 --- a/tests/LazyProxyTest.cpp +++ b/tests/LazyProxyTest.cpp @@ -242,8 +242,8 @@ DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) { *testCountPtr = 1; return sk_sp(); }, - desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrInternalSurfaceFlags::kNone, - SkBackingFit::kExact, SkBudgeted::kNo, lazyType); + desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrTextureType::k2D, + GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, SkBudgeted::kNo, lazyType); REPORTER_ASSERT(reporter, proxy.get()); REPORTER_ASSERT(reporter, 0 == testCount); @@ -309,8 +309,8 @@ private: } return rp->createTexture(desc, SkBudgeted::kNo); }, - desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, SkBackingFit::kExact, - SkBudgeted::kNo); + desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrTextureType::k2D, + SkBackingFit::kExact, SkBudgeted::kNo); SkASSERT(fLazyProxy.get()); @@ -453,8 +453,8 @@ DEF_GPUTEST(LazyProxyUninstantiateTest, reporter, /* options */) { texture->setRelease(UninstantiateReleaseProc, releasePtr); return texture; }, - desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrInternalSurfaceFlags::kNone, - SkBackingFit::kExact, SkBudgeted::kNo, lazyType); + desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrTextureType::k2D, + GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, SkBudgeted::kNo, lazyType); REPORTER_ASSERT(reporter, lazyProxy.get()); diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp index b3846a1bcb..68e4fea5a2 100644 --- a/tests/RectangleTextureTest.cpp +++ b/tests/RectangleTextureTest.cpp @@ -141,10 +141,11 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) { SkASSERT(rectProxy->mipMapped() == GrMipMapped::kNo); SkASSERT(rectProxy->priv().peekTexture()->texturePriv().mipMapped() == GrMipMapped::kNo); - SkASSERT(rectProxy->texPriv().isGLTextureRectangleOrExternal()); - SkASSERT(rectProxy->priv().peekTexture()->surfacePriv().isGLTextureRectangleOrExternal()); - SkASSERT(rectProxy->texPriv().isClampOnly()); - SkASSERT(rectProxy->priv().peekTexture()->surfacePriv().isClampOnly()); + SkASSERT(rectProxy->texPriv().textureType() == GrTextureType::kRectangle); + SkASSERT(rectProxy->priv().peekTexture()->texturePriv().textureType() == + GrTextureType::kRectangle); + SkASSERT(rectProxy->texPriv().hasRestrictedSampling()); + SkASSERT(rectProxy->priv().peekTexture()->texturePriv().hasRestrictedSampling()); test_basic_draw_as_src(reporter, context, rectProxy, refPixels); -- cgit v1.2.3