Remove compressed texture support from cacherator

All variants of (on)?[rR]efEncoded(Data)? no longer need a GrContext
parameter.

Bug: skia:5485 skia:4971
Change-Id: If4f5e785718d5522eb3df8588318ccb8a02a5749
Reviewed-on: https://skia-review.googlesource.com/14269
Reviewed-by: Leon Scroggins <scroggo@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h
index 846c380..3e23963 100644
--- a/include/core/SkImageGenerator.h
+++ b/include/core/SkImageGenerator.h
@@ -35,16 +35,19 @@
     uint32_t uniqueID() const { return fUniqueID; }
 
     /**
-     *  Return a ref to the encoded (i.e. compressed) representation,
-     *  of this data. If the GrContext is non-null, then the caller is only interested in
-     *  gpu-specific formats, so the impl may return null even if they have encoded data,
-     *  assuming they know it is not suitable for the gpu.
+     *  Return a ref to the encoded (i.e. compressed) representation
+     *  of this data.
      *
      *  If non-NULL is returned, the caller is responsible for calling
      *  unref() on the data when it is finished.
      */
-    SkData* refEncodedData(GrContext* ctx = nullptr) {
+    SkData* refEncodedData() {
+#ifdef SK_SUPPORT_GPU_REF_ENCODED_DATA
+        GrContext* ctx = nullptr;
         return this->onRefEncodedData(ctx);
+#else
+        return this->onRefEncodedData();
+#endif
     }
 
     /**
@@ -163,7 +166,11 @@
 
     SkImageGenerator(const SkImageInfo& info, uint32_t uniqueId = kNeedNewImageUniqueID);
 
-    virtual SkData* onRefEncodedData(GrContext* ctx);
+    virtual SkData* onRefEncodedData(
+#ifdef SK_SUPPORT_GPU_REF_ENCODED_DATA
+        GrContext* ctx
+#endif
+    );
 
     virtual bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes,
                              SkPMColor ctable[], int* ctableCount);
diff --git a/src/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp
index 6467033..d1bb43f 100644
--- a/src/codec/SkCodecImageGenerator.cpp
+++ b/src/codec/SkCodecImageGenerator.cpp
@@ -31,7 +31,11 @@
     , fData(std::move(data))
 {}
 
-SkData* SkCodecImageGenerator::onRefEncodedData(GrContext* ctx) {
+SkData* SkCodecImageGenerator::onRefEncodedData(
+#ifdef SK_SUPPORT_GPU_REF_ENCODED_DATA
+        GrContext* ctx
+#endif
+        ) {
     return SkRef(fData.get());
 }
 
diff --git a/src/codec/SkCodecImageGenerator.h b/src/codec/SkCodecImageGenerator.h
index a435205..2332164 100644
--- a/src/codec/SkCodecImageGenerator.h
+++ b/src/codec/SkCodecImageGenerator.h
@@ -21,7 +21,11 @@
     static std::unique_ptr<SkImageGenerator> MakeFromEncodedCodec(sk_sp<SkData>);
 
 protected:
-    SkData* onRefEncodedData(GrContext* ctx) override;
+    SkData* onRefEncodedData(
+#ifdef SK_SUPPORT_GPU_REF_ENCODED_DATA
+        GrContext* ctx
+#endif
+    ) override;
 
     bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[],
                      int* ctableCount) override;
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index 808fdd4..9ef9f79 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -127,9 +127,9 @@
     return rec->fUniqueID;
 }
 
-SkData* SkImageCacherator::refEncoded(GrContext* ctx) {
+SkData* SkImageCacherator::refEncoded() {
     ScopedGenerator generator(fSharedGenerator);
-    return generator->refEncodedData(ctx);
+    return generator->refEncodedData();
 }
 
 static bool check_output_bitmap(const SkBitmap& bitmap, uint32_t expectedID) {
@@ -425,20 +425,6 @@
     }
 }
 
-#ifdef SK_SUPPORT_COMPRESSED_TEXTURES_IN_CACHERATOR
-static GrTexture* load_compressed_into_texture(GrContext* ctx, SkData* data, GrSurfaceDesc desc) {
-    const void* rawStart;
-    GrPixelConfig config = GrIsCompressedTextureDataSupported(ctx, data, desc.fWidth, desc.fHeight,
-                                                              &rawStart);
-    if (kUnknown_GrPixelConfig == config) {
-        return nullptr;
-    }
-
-    desc.fConfig = config;
-    return ctx->resourceProvider()->createTexture(desc, SkBudgeted::kYes, rawStart, 0);
-}
-#endif
-
 class Generator_GrYUVProvider : public GrYUVProvider {
     SkImageGenerator* fGen;
 
@@ -471,13 +457,12 @@
 }
 
 /*
- *  We have a 5 ways to try to return a texture (in sorted order)
+ *  We have 4 ways to try to return a texture (in sorted order)
  *
  *  1. Check the cache for a pre-existing one
  *  2. Ask the generator to natively create one
- *  3. Ask the generator to return a compressed form that the GPU might support
- *  4. Ask the generator to return YUV planes, which the GPU can convert
- *  5. Ask the generator to return RGB(A) data, which the GPU can convert
+ *  3. Ask the generator to return YUV planes, which the GPU can convert
+ *  4. Ask the generator to return RGB(A) data, which the GPU can convert
  */
 sk_sp<GrTextureProxy> SkImageCacherator::lockTextureProxy(GrContext* ctx,
                                                           const GrUniqueKey& origKey,
@@ -491,7 +476,7 @@
         kFailure_LockTexturePath,
         kPreExisting_LockTexturePath,
         kNative_LockTexturePath,
-        kCompressed_LockTexturePath,
+        kCompressed_LockTexturePath, // Deprecated
         kYUV_LockTexturePath,
         kRGBA_LockTexturePath,
     };
@@ -531,23 +516,9 @@
         }
     }
 
-    const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(cacheInfo, *ctx->caps());
-
-#ifdef SK_SUPPORT_COMPRESSED_TEXTURES_IN_CACHERATOR
-    // 3. Ask the generator to return a compressed form that the GPU might support
-    sk_sp<SkData> data(this->refEncoded(ctx));
-    if (data) {
-        GrTexture* tex = load_compressed_into_texture(ctx, data, desc);
-        if (tex) {
-            SK_HISTOGRAM_ENUMERATION("LockTexturePath", kCompressed_LockTexturePath,
-                                     kLockTexturePathCount);
-            return set_key_and_return(tex, key);
-        }
-    }
-#endif
-
-    // 4. Ask the generator to return YUV planes, which the GPU can convert
+    // 3. Ask the generator to return YUV planes, which the GPU can convert
     if (!ctx->contextPriv().disableGpuYUVConversion()) {
+        const GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(cacheInfo, *ctx->caps());
         ScopedGenerator generator(fSharedGenerator);
         Generator_GrYUVProvider provider(generator);
         if (sk_sp<GrTextureProxy> proxy = provider.refAsTextureProxy(ctx, desc, true)) {
@@ -558,7 +529,7 @@
         }
     }
 
-    // 5. Ask the generator to return RGB(A) data, which the GPU can convert
+    // 4. Ask the generator to return RGB(A) data, which the GPU can convert
     SkBitmap bitmap;
     if (this->lockAsBitmap(&bitmap, client, chint, format, cacheInfo)) {
         sk_sp<GrTextureProxy> proxy;
diff --git a/src/core/SkImageCacherator.h b/src/core/SkImageCacherator.h
index c3b0bcc..fb07b76 100644
--- a/src/core/SkImageCacherator.h
+++ b/src/core/SkImageCacherator.h
@@ -68,11 +68,8 @@
     /**
      *  If the underlying src naturally is represented by an encoded blob (in SkData), this returns
      *  a ref to that data. If not, it returns null.
-     *
-     *  If a GrContext is specified, then the caller is only interested in gpu-specific encoded
-     *  formats, so others (e.g. PNG) can just return nullptr.
      */
-    SkData* refEncoded(GrContext*);
+    SkData* refEncoded();
 
     // Only return true if the generate has already been cached.
     bool lockAsBitmapOnlyIfAlreadyCached(SkBitmap*, CachedFormat);
diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp
index f47bb1d..59619a9 100644
--- a/src/core/SkImageGenerator.cpp
+++ b/src/core/SkImageGenerator.cpp
@@ -106,7 +106,11 @@
 
 /////////////////////////////////////////////////////////////////////////////////////////////
 
-SkData* SkImageGenerator::onRefEncodedData(GrContext* ctx) {
+SkData* SkImageGenerator::onRefEncodedData(
+#ifdef SK_SUPPORT_GPU_REF_ENCODED_DATA
+        GrContext* ctx
+#endif
+        ) {
     return nullptr;
 }
 
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index 9866acf..6e4d32e 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -130,8 +130,7 @@
 }
 
 SkData* SkImage::refEncoded() const {
-    GrContext* ctx = nullptr;   // should we allow the caller to pass in a ctx?
-    return as_IB(this)->onRefEncoded(ctx);
+    return as_IB(this)->onRefEncoded();
 }
 
 sk_sp<SkImage> SkImage::MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* subset) {
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index 062d785..96fd6e6 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -73,8 +73,7 @@
 
     virtual sk_sp<SkImage> onMakeSubset(const SkIRect&) const = 0;
 
-    // If a ctx is specified, then only gpu-specific formats are requested.
-    virtual SkData* onRefEncoded(GrContext*) const { return nullptr; }
+    virtual SkData* onRefEncoded() const { return nullptr; }
 
     virtual bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const;
 
diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp
index 5fd0f61..99995d1 100644
--- a/src/image/SkImage_Lazy.cpp
+++ b/src/image/SkImage_Lazy.cpp
@@ -34,7 +34,7 @@
                                             SkScalar scaleAdjust[2]) const override;
 #endif
     SkImageCacherator* peekCacherator() const override { return &fCache; }
-    SkData* onRefEncoded(GrContext*) const override;
+    SkData* onRefEncoded() const override;
     sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
     bool getROPixels(SkBitmap*, SkColorSpace* dstColorSpace, CachingHint) const override;
     bool onIsLazyGenerated() const override { return true; }
@@ -74,8 +74,8 @@
     return false;
 }
 
-SkData* SkImage_Lazy::onRefEncoded(GrContext* ctx) const {
-    return fCache.refEncoded(ctx);
+SkData* SkImage_Lazy::onRefEncoded() const {
+    return fCache.refEncoded();
 }
 
 bool SkImage_Lazy::getROPixels(SkBitmap* bitmap, SkColorSpace* dstColorSpace,
diff --git a/src/ports/SkImageGeneratorCG.cpp b/src/ports/SkImageGeneratorCG.cpp
index d2e6436..7d1c44d 100644
--- a/src/ports/SkImageGeneratorCG.cpp
+++ b/src/ports/SkImageGeneratorCG.cpp
@@ -75,7 +75,11 @@
     , fData(SkRef(data))
 {}
 
-SkData* SkImageGeneratorCG::onRefEncodedData(GrContext* ctx) {
+SkData* SkImageGeneratorCG::onRefEncodedData(
+#ifdef SK_SUPPORT_GPU_REF_ENCODED_DATA
+        GrContext* ctx
+#endif
+        ) {
     return SkRef(fData.get());
 }
 
diff --git a/src/ports/SkImageGeneratorCG.h b/src/ports/SkImageGeneratorCG.h
index 9ecfe1b..c675e85 100644
--- a/src/ports/SkImageGeneratorCG.h
+++ b/src/ports/SkImageGeneratorCG.h
@@ -22,7 +22,11 @@
     static SkImageGenerator* NewFromEncodedCG(SkData* data);
 
 protected:
-    SkData* onRefEncodedData(GrContext* ctx) override;
+    SkData* onRefEncodedData(
+#ifdef SK_SUPPORT_GPU_REF_ENCODED_DATA
+        GrContext* ctx
+#endif
+    ) override;
 
     bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[],
             int* ctableCount) override;
diff --git a/src/ports/SkImageGeneratorWIC.cpp b/src/ports/SkImageGeneratorWIC.cpp
index 7a36785..4195886 100644
--- a/src/ports/SkImageGeneratorWIC.cpp
+++ b/src/ports/SkImageGeneratorWIC.cpp
@@ -132,7 +132,11 @@
     , fData(SkRef(data))
 {}
 
-SkData* SkImageGeneratorWIC::onRefEncodedData(GrContext* ctx) {
+SkData* SkImageGeneratorWIC::onRefEncodedData(
+#ifdef SK_SUPPORT_GPU_REF_ENCODED_DATA
+        GrContext* ctx
+#endif
+        ) {
     return SkRef(fData.get());
 }
 
diff --git a/src/ports/SkImageGeneratorWIC.h b/src/ports/SkImageGeneratorWIC.h
index eb65e0b..d20d493 100644
--- a/src/ports/SkImageGeneratorWIC.h
+++ b/src/ports/SkImageGeneratorWIC.h
@@ -39,7 +39,11 @@
     static SkImageGenerator* NewFromEncodedWIC(SkData* data);
 
 protected:
-    SkData* onRefEncodedData(GrContext* ctx) override;
+    SkData* onRefEncodedData(
+#ifdef SK_SUPPORT_GPU_REF_ENCODED_DATA
+        GrContext* ctx
+#endif
+    ) override;
 
     bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[],
             int* ctableCount) override;