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 <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/include/gpu/GrSurface.h b/include/gpu/GrSurface.h
index 3a7294b..a93cacf 100644
--- a/include/gpu/GrSurface.h
+++ b/include/gpu/GrSurface.h
@@ -63,14 +63,6 @@
                               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 fc7f1c5..3846954 100644
--- a/include/private/GrTextureProxy.h
+++ b/include/private/GrTextureProxy.h
@@ -72,12 +72,12 @@
     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 @@
     // 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 @@
 
     sk_sp<GrSurface> 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 db25236..ef6fa54 100644
--- a/include/private/GrTypesPriv.h
+++ b/include/private/GrTypesPriv.h
@@ -503,6 +503,20 @@
     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 @@
 
     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 d13fd39..b698984 100644
--- a/src/core/SkDeferredDisplayListRecorder.cpp
+++ b/src/core/SkDeferredDisplayListRecorder.cpp
@@ -113,6 +113,12 @@
     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<GrRenderTargetProxy> proxy = proxyProvider->createLazyRenderTargetProxy(
             [lazyProxyData](GrResourceProvider* resourceProvider) {
@@ -128,8 +134,7 @@
             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 466a842..74722c6 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 @@
     GrBackendTexture backendTexture = fBackendTexture;
     RefHelper* refHelper = fRefHelper;
 
+    GrTextureType textureType = GrTextureType::k2D;
+    GrGLTextureInfo glInfo;
+    if (backendTexture.getGLTextureInfo(&glInfo)) {
+        textureType = GrGLTexture::TextureTypeFromTarget(glInfo.fTarget);
+    }
     sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
             [refHelper, releaseProcHelper, semaphore,
              backendTexture](GrResourceProvider* resourceProvider) {
@@ -171,9 +175,8 @@
                 }
 
                 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 4b7e786..62eef09 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -74,7 +74,7 @@
     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 df7b61e..67643d7 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -275,7 +275,8 @@
 
                 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 @@
                 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 @@
     if (copyDesc.fFlags & kRenderTarget_GrSurfaceFlag) {
         // We know anything we instantiate later from this deferred path will be
         // both texturable and renderable
-        return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(
-                *this->caps(), copyDesc, origin, mipMapped, fit, budgeted, surfaceFlags));
+        return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(*this->caps(), copyDesc, origin,
+                                                                    mipMapped, GrTextureType::k2D,
+                                                                    fit, budgeted, surfaceFlags));
     }
 
-    return sk_sp<GrTextureProxy>(
-            new GrTextureProxy(copyDesc, origin, mipMapped, fit, budgeted, surfaceFlags));
+    return sk_sp<GrTextureProxy>(new GrTextureProxy(copyDesc, origin, mipMapped, GrTextureType::k2D,
+                                                    fit, budgeted, surfaceFlags));
 }
 
 sk_sp<GrTextureProxy> GrProxyProvider::wrapBackendTexture(const GrBackendTexture& backendTex,
@@ -537,9 +539,11 @@
 sk_sp<GrTextureProxy> 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 @@
                                                        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<GrTextureProxy> 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 @@
     return sk_sp<GrTextureProxy>(
             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<GrRenderTargetProxy> 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 @@
     LazyInstantiationType lazyType = fResourceProvider ? LazyInstantiationType::kSingleUse
                                                        : LazyInstantiationType::kMultipleUse;
 
-    if (Textureable::kYes == textureable) {
-        return sk_sp<GrRenderTargetProxy>(
-                new GrTextureRenderTargetProxy(std::move(callback), lazyType, desc, origin,
-                                               mipMapped, fit, budgeted, surfaceFlags));
+    if (textureInfo) {
+        return sk_sp<GrRenderTargetProxy>(new GrTextureRenderTargetProxy(
+                std::move(callback), lazyType, desc, origin, textureInfo->fMipMapped,
+                textureInfo->fTextureType, fit, budgeted, surfaceFlags));
     }
 
     return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(
@@ -645,16 +654,16 @@
     desc.fConfig = config;
     desc.fSampleCnt = 1;
 
+    static constexpr auto kTextureType = GrTextureType::k2D;
     return sk_sp<GrTextureProxy>(
             (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 89f9518..87d6f27 100644
--- a/src/gpu/GrProxyProvider.h
+++ b/src/gpu/GrProxyProvider.h
@@ -148,16 +148,17 @@
                                                            int sampleCnt);
 
     using LazyInstantiateCallback = std::function<sk_sp<GrSurface>(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 @@
      * callback should cleanup any resources it captured and return an empty sk_sp<GrTextureProxy>.
      */
     sk_sp<GrTextureProxy> createLazyProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&,
-                                          GrSurfaceOrigin, GrMipMapped, GrInternalSurfaceFlags,
-                                          SkBackingFit, SkBudgeted, LazyInstantiationType);
+                                          GrSurfaceOrigin, GrMipMapped, GrTextureType,
+                                          GrInternalSurfaceFlags, SkBackingFit, SkBudgeted,
+                                          LazyInstantiationType);
 
     sk_sp<GrTextureProxy> createLazyProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&,
-                                          GrSurfaceOrigin, GrMipMapped, GrInternalSurfaceFlags,
-                                          SkBackingFit, SkBudgeted);
+                                          GrSurfaceOrigin, GrMipMapped, GrTextureType,
+                                          GrInternalSurfaceFlags, SkBackingFit, SkBudgeted);
 
     sk_sp<GrTextureProxy> createLazyProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&,
-                                          GrSurfaceOrigin, GrMipMapped, SkBackingFit, SkBudgeted);
+                                          GrSurfaceOrigin, GrMipMapped, GrTextureType, SkBackingFit,
+                                          SkBudgeted);
+
+    /** A null TextureInfo indicates a non-textureable render target. */
     sk_sp<GrRenderTargetProxy> 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 45a097b..4d61dca 100644
--- a/src/gpu/GrSurfacePriv.h
+++ b/src/gpu/GrSurfacePriv.h
@@ -40,12 +40,6 @@
 
     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 316afbc..47556e4 100644
--- a/src/gpu/GrTexturePriv.h
+++ b/src/gpu/GrTexturePriv.h
@@ -41,6 +41,9 @@
     }
 
     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 b25efd9..fc6a2fa 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 @@
 
 // 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<GrSurface> 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 @@
     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 358369d..519e96b 100644
--- a/src/gpu/GrTextureProxyPriv.h
+++ b/src/gpu/GrTextureProxyPriv.h
@@ -31,14 +31,10 @@
     // 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 95d5543..5b87399 100644
--- a/src/gpu/GrTextureRenderTargetProxy.cpp
+++ b/src/gpu/GrTextureRenderTargetProxy.cpp
@@ -22,12 +22,13 @@
                                                        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 @@
                                                        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 @@
 
     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 141597e..f2f3edb 100644
--- a/src/gpu/GrTextureRenderTargetProxy.h
+++ b/src/gpu/GrTextureRenderTargetProxy.h
@@ -29,12 +29,12 @@
 
     // 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<GrSurface>, GrSurfaceOrigin);
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 5532e36..0fc8843 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -2185,8 +2185,8 @@
     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 f0fafab..200c8d2 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -15,7 +15,7 @@
 #define GPUGL static_cast<GrGLGpu*>(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 @@
 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, 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, 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 @@
 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 298f1fa..cb029cc 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -31,6 +31,9 @@
         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 1dea806..58aa1bc 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -9,10 +9,9 @@
 #include <cstring>
 #include <type_traits>
 
-#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<GrContext> context, uint32_t uniqueID, SkAlphaType at,
                          sk_sp<GrTextureProxy> proxy, sk_sp<SkColorSpace> colorSpace,
@@ -651,14 +651,11 @@
     sk_sp<GrReleaseProcHelper> 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> SkImage_Gpu::MakePromiseTexture(GrContext* context,
@@ -696,10 +693,9 @@
         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 @@
                                      textureContext);
 
     sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
-            [promiseHelper, config] (GrResourceProvider* resourceProvider) mutable {
+            [promiseHelper, config](GrResourceProvider* resourceProvider) mutable {
                 if (!resourceProvider) {
                     promiseHelper.reset();
                     return sk_sp<GrTexture>();
                 }
 
                 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 afe93ad..ff25d68 100644
--- a/tests/DeferredDisplayListTest.cpp
+++ b/tests/DeferredDisplayListTest.cpp
@@ -873,9 +873,9 @@
 
             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 51da718..73dd761 100644
--- a/tests/EGLImageTest.cpp
+++ b/tests/EGLImageTest.cpp
@@ -172,11 +172,12 @@
     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 7945ec6..27321a7 100644
--- a/tests/LazyProxyTest.cpp
+++ b/tests/LazyProxyTest.cpp
@@ -242,8 +242,8 @@
                         *testCountPtr = 1;
                         return sk_sp<GrTexture>();
                     },
-                    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 @@
                     }
                     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 @@
                     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 b3846a1..68e4fea 100644
--- a/tests/RectangleTextureTest.cpp
+++ b/tests/RectangleTextureTest.cpp
@@ -141,10 +141,11 @@
         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);