Revert "Make SkImageCacherator be deferred"
authorRobert Phillips <robertphillips@google.com>
Wed, 22 Mar 2017 18:13:37 +0000 (18:13 +0000)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 22 Mar 2017 18:13:42 +0000 (18:13 +0000)
This reverts commit 801f8b824fee6397422e47537f0f13034ac54ce6.

Reason for revert: Failures on Tegra3-based Android devices (so, npot issues)

Original change's description:
> Make SkImageCacherator be deferred
>
> Split out of: https://skia-review.googlesource.com/c/8823/ (Remove GrFragmentProcessor-derived class' GrTexture-based ctors)
>
> Change-Id: I16cf0aea9d887e5ebe053e9b5c94a970dc254beb
> Reviewed-on: https://skia-review.googlesource.com/9945
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Robert Phillips <robertphillips@google.com>
>

TBR=bsalomon@google.com,robertphillips@google.com,reviews@skia.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Change-Id: Ib143ef86cfad4a221e25145679ba7e48f6f7f3ba
Reviewed-on: https://skia-review.googlesource.com/9949
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>

gm/image_pict.cpp
src/core/SkImageCacherator.cpp
src/core/SkImageCacherator.h
src/gpu/GrImageTextureMaker.cpp
src/gpu/GrTextureMaker.cpp
src/image/SkImage_Generator.cpp

index 792173ce66022f9f9d4598c5a371166a74ad6d56..883fd347258adafc1adbdd84f761e164e9d79516 100644 (file)
@@ -344,11 +344,12 @@ protected:
     static void draw_as_tex(SkCanvas* canvas, SkImageCacherator* cache, SkScalar x, SkScalar y) {
 #if SK_SUPPORT_GPU
         sk_sp<SkColorSpace> texColorSpace;
-        sk_sp<GrTextureProxy> proxy(
-            cache->lockAsTextureProxy(canvas->getGrContext(), GrSamplerParams::ClampBilerp(),
-                                      canvas->imageInfo().colorSpace(), &texColorSpace,
-                                      nullptr, nullptr));
-        if (!proxy) {
+        // MDB TODO: this should be lockAsTextureRef
+        sk_sp<GrTexture> texture(
+            cache->lockAsTexture(canvas->getGrContext(), GrSamplerParams::ClampBilerp(),
+                                 canvas->imageInfo().colorSpace(), &texColorSpace,
+                                 nullptr, nullptr));
+        if (!texture) {
             // show placeholder if we have no texture
             SkPaint paint;
             paint.setStyle(SkPaint::kStroke_Style);
@@ -360,6 +361,8 @@ protected:
             return;
         }
 
+        sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(std::move(texture));
+
         // No API to draw a GrTexture directly, so we cheat and create a private image subclass
         sk_sp<SkImage> image(new SkImage_Gpu(canvas->getGrContext(),
                                              cache->uniqueID(), kPremul_SkAlphaType,
index f0bc9973a6f78a2c88dba6ad31d547254cbfff8c..64b2e62a33f0e11ec3779aa64bd6518faa9f9d0c 100644 (file)
@@ -485,12 +485,22 @@ public:
     }
 };
 
+static GrTexture* set_key_and_return(GrResourceProvider* resourceProvider,
+                                     GrTexture* tex, const GrUniqueKey& key) {
+    if (key.isValid()) {
+        resourceProvider->assignUniqueKeyToTexture(key, tex);
+    }
+    return tex;
+}
+
+#if 0
 static void set_key_on_proxy(GrResourceProvider* resourceProvider,
                              GrTextureProxy* proxy, const GrUniqueKey& key) {
     if (key.isValid()) {
         resourceProvider->assignUniqueKeyToProxy(key, proxy);
     }
 }
+#endif
 
 sk_sp<SkColorSpace> SkImageCacherator::getColorSpace(GrContext* ctx, SkColorSpace* dstColorSpace) {
     // TODO: This isn't always correct. Picture generator currently produces textures in N32,
@@ -510,12 +520,9 @@ sk_sp<SkColorSpace> SkImageCacherator::getColorSpace(GrContext* ctx, SkColorSpac
  *  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
  */
-sk_sp<GrTextureProxy> SkImageCacherator::lockTextureProxy(GrContext* ctx,
-                                                          const GrUniqueKey& origKey,
-                                                          const SkImage* client,
-                                                          SkImage::CachingHint chint,
-                                                          bool willBeMipped,
-                                                          SkColorSpace* dstColorSpace) {
+GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& origKey,
+                                          const SkImage* client, SkImage::CachingHint chint,
+                                          bool willBeMipped, SkColorSpace* dstColorSpace) {
     // Values representing the various texture lock paths we can take. Used for logging the path
     // taken to a histogram.
     enum LockTexturePath {
@@ -539,10 +546,10 @@ sk_sp<GrTextureProxy> SkImageCacherator::lockTextureProxy(GrContext* ctx,
 
     // 1. Check the cache for a pre-existing one
     if (key.isValid()) {
-        if (sk_sp<GrTextureProxy> proxy = ctx->resourceProvider()->findProxyByUniqueKey(key)) {
+        if (GrTexture* tex = ctx->resourceProvider()->findAndRefTextureByUniqueKey(key)) {
             SK_HISTOGRAM_ENUMERATION("LockTexturePath", kPreExisting_LockTexturePath,
                                      kLockTexturePathCount);
-            return proxy;
+            return tex;
         }
     }
 
@@ -557,8 +564,10 @@ sk_sp<GrTextureProxy> SkImageCacherator::lockTextureProxy(GrContext* ctx,
         if (sk_sp<GrTextureProxy> proxy = generator->generateTexture(ctx, cacheInfo, fOrigin)) {
             SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath,
                                      kLockTexturePathCount);
-            set_key_on_proxy(ctx->resourceProvider(), proxy.get(), key);
-            return proxy;
+            GrTexture* tex2 = proxy->instantiate(ctx->resourceProvider());
+            if (tex2) {
+                return set_key_and_return(ctx->resourceProvider(), SkRef(tex2), key);
+            }
         }
     }
 
@@ -584,26 +593,27 @@ sk_sp<GrTextureProxy> SkImageCacherator::lockTextureProxy(GrContext* ctx,
         if (sk_sp<GrTextureProxy> proxy = provider.refAsTextureProxy(ctx, desc, true)) {
             SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath,
                                      kLockTexturePathCount);
-            set_key_on_proxy(ctx->resourceProvider(), proxy.get(), key);
-            return proxy;
+            GrTexture* tex2 = proxy->instantiate(ctx->resourceProvider());
+            if (tex2) {
+                return set_key_and_return(ctx->resourceProvider(), SkRef(tex2), key);
+            }
         }
     }
 
     // 5. Ask the generator to return RGB(A) data, which the GPU can convert
     SkBitmap bitmap;
     if (this->tryLockAsBitmap(&bitmap, client, chint, format, cacheInfo)) {
-        sk_sp<GrTextureProxy> proxy;
+        GrTexture* tex = nullptr;
         if (willBeMipped) {
-            proxy = GrGenerateMipMapsAndUploadToTextureProxy(ctx, bitmap, dstColorSpace);
+            tex = GrGenerateMipMapsAndUploadToTexture(ctx, bitmap, dstColorSpace);
         }
-        if (!proxy) {
-            proxy = GrUploadBitmapToTextureProxy(ctx->resourceProvider(), bitmap);
+        if (!tex) {
+            tex = GrUploadBitmapToTexture(ctx, bitmap);
         }
-        if (proxy) {
+        if (tex) {
             SK_HISTOGRAM_ENUMERATION("LockTexturePath", kRGBA_LockTexturePath,
                                      kLockTexturePathCount);
-            set_key_on_proxy(ctx->resourceProvider(), proxy.get(), key);
-            return proxy;
+            return set_key_and_return(ctx->resourceProvider(), tex, key);
         }
     }
     SK_HISTOGRAM_ENUMERATION("LockTexturePath", kFailure_LockTexturePath,
@@ -613,23 +623,29 @@ sk_sp<GrTextureProxy> SkImageCacherator::lockTextureProxy(GrContext* ctx,
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-sk_sp<GrTextureProxy> SkImageCacherator::lockAsTextureProxy(GrContext* ctx,
-                                                            const GrSamplerParams& params,
-                                                            SkColorSpace* dstColorSpace,
-                                                            sk_sp<SkColorSpace>* texColorSpace,
-                                                            const SkImage* client,
-                                                            SkScalar scaleAdjust[2],
-                                                            SkImage::CachingHint chint) {
+GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrSamplerParams& params,
+                                            SkColorSpace* dstColorSpace,
+                                            sk_sp<SkColorSpace>* texColorSpace,
+                                            const SkImage* client,
+                                            SkScalar scaleAdjust[2],
+                                            SkImage::CachingHint chint) {
     if (!ctx) {
         return nullptr;
     }
 
-    sk_sp<GrTexture> tex(GrImageTextureMaker(ctx, this, client, chint).refTextureForParams(
-                                                                                  params,
-                                                                                  dstColorSpace,
-                                                                                  texColorSpace,
-                                                                                  scaleAdjust));
-    return GrSurfaceProxy::MakeWrapped(std::move(tex));
+    return GrImageTextureMaker(ctx, this, client, chint).refTextureForParams(params, dstColorSpace,
+                                                                             texColorSpace,
+                                                                             scaleAdjust);
+}
+
+#else
+
+GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrSamplerParams&,
+                                            SkColorSpace* dstColorSpace,
+                                            sk_sp<SkColorSpace>* texColorSpace,
+                                            const SkImage* client,
+                                            SkScalar scaleAdjust[2], SkImage::CachingHint) {
+    return nullptr;
 }
 
 #endif
index e1792367484ce1df9db9fde2e2ae8c6a98a46399..38d14d06ec7f13f854240fbfd6483b40373b794c 100644 (file)
@@ -15,7 +15,6 @@
 class GrCaps;
 class GrContext;
 class GrSamplerParams;
-class GrTextureProxy;
 class GrUniqueKey;
 class SkBitmap;
 class SkImage;
@@ -52,7 +51,6 @@ public:
     bool lockAsBitmap(GrContext*, SkBitmap*, const SkImage* client, SkColorSpace* dstColorSpace,
                       SkImage::CachingHint = SkImage::kAllow_CachingHint);
 
-#if SK_SUPPORT_GPU
     /**
      *  Returns a ref() on the texture produced by this generator. The caller must call unref()
      *  when it is done. Will return nullptr on failure.
@@ -60,20 +58,17 @@ public:
      *  If not NULL, the client will be notified (->notifyAddedToCache()) when resources are
      *  added to the cache on its behalf.
      *
-     *  The caller is responsible for calling proxy->unref() when they are done.
+     *  The caller is responsible for calling texture->unref() when they are done.
      *
      *  The scaleAdjust in/out parameter will return any scale adjustment that needs
      *  to be applied to the absolute texture coordinates in the case where the image
      *  was resized to meet the sampling requirements (e.g., resized out to the next power of 2).
      *  It can be null if the caller knows resizing will not be required.
      */
-    sk_sp<GrTextureProxy> lockAsTextureProxy(GrContext*, const GrSamplerParams&,
-                                             SkColorSpace* dstColorSpace,
-                                             sk_sp<SkColorSpace>* texColorSpace,
-                                             const SkImage* client,
-                                             SkScalar scaleAdjust[2],
-                                             SkImage::CachingHint = SkImage::kAllow_CachingHint);
-#endif
+    GrTexture* lockAsTexture(GrContext*, const GrSamplerParams&, SkColorSpace* dstColorSpace,
+                             sk_sp<SkColorSpace>* texColorSpace, const SkImage* client,
+                             SkScalar scaleAdjust[2],
+                             SkImage::CachingHint = SkImage::kAllow_CachingHint);
 
     /**
      *  If the underlying src naturally is represented by an encoded blob (in SkData), this returns
@@ -134,14 +129,10 @@ private:
     bool tryLockAsBitmap(SkBitmap*, const SkImage*, SkImage::CachingHint, CachedFormat,
                          const SkImageInfo&);
 #if SK_SUPPORT_GPU
-    // Returns the texture proxy. If the cacherator is generating the texture and wants to cache it,
+    // Returns the texture. If the cacherator is generating the texture and wants to cache it,
     // it should use the passed in key (if the key is valid).
-    sk_sp<GrTextureProxy> lockTextureProxy(GrContext*,
-                                           const GrUniqueKey& key,
-                                           const SkImage* client,
-                                           SkImage::CachingHint,
-                                           bool willBeMipped,
-                                           SkColorSpace* dstColorSpace);
+    GrTexture* lockTexture(GrContext*, const GrUniqueKey& key, const SkImage* client,
+                           SkImage::CachingHint, bool willBeMipped, SkColorSpace* dstColorSpace);
     // Returns the color space of the texture that would be returned if you called lockTexture.
     // Separate code path to allow querying of the color space for textures that cached (even
     // externally).
index 47a2f4f14c3a6b756bb8f36b05a771a22b7ec64e..a7fc1a353cd64df543722ace65f4c959c5de1a12 100644 (file)
@@ -32,21 +32,16 @@ GrImageTextureMaker::GrImageTextureMaker(GrContext* context, SkImageCacherator*
 }
 
 GrTexture* GrImageTextureMaker::refOriginalTexture(bool willBeMipped, SkColorSpace* dstColorSpace) {
-    sk_sp<GrTextureProxy> proxy = fCacher->lockTextureProxy(this->context(), fOriginalKey,
-                                                            fClient, fCachingHint, willBeMipped,
-                                                            dstColorSpace);
-    if (!proxy) {
-        return nullptr;
-    }
-
-    sk_sp<GrTexture> tex(SkSafeRef(proxy->instantiate(this->context()->resourceProvider())));
-    return tex.release();
+    return fCacher->lockTexture(this->context(), fOriginalKey, fClient, fCachingHint, willBeMipped,
+                                dstColorSpace);
 }
 
 sk_sp<GrTextureProxy> GrImageTextureMaker::refOriginalTextureProxy(bool willBeMipped,
                                                                    SkColorSpace* dstColorSpace) {
-    return fCacher->lockTextureProxy(this->context(), fOriginalKey, fClient, fCachingHint,
-                                     willBeMipped, dstColorSpace);
+    sk_sp<GrTexture> tex(fCacher->lockTexture(this->context(), fOriginalKey, fClient, fCachingHint,
+                                              willBeMipped, dstColorSpace));
+
+    return GrSurfaceProxy::MakeWrapped(std::move(tex));
 }
 
 void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey,
index f5ee4d3b6830bf0fcfec83e1e26a1cecdf24bb4f..06a8f276399eb2877e5d923db68092803b166e2f 100644 (file)
@@ -102,16 +102,9 @@ sk_sp<GrFragmentProcessor> GrTextureMaker::createFragmentProcessor(
 
 GrTexture* GrTextureMaker::generateTextureForParams(const CopyParams& copyParams, bool willBeMipped,
                                                     SkColorSpace* dstColorSpace) {
-    sk_sp<GrTextureProxy> original(this->refOriginalTextureProxy(willBeMipped, dstColorSpace));
+    sk_sp<GrTexture> original(this->refOriginalTexture(willBeMipped, dstColorSpace));
     if (!original) {
         return nullptr;
     }
-
-    sk_sp<GrTextureProxy> copy = CopyOnGpu(fContext, std::move(original), nullptr, copyParams);
-    if (!copy) {
-        return nullptr;
-    }
-
-    sk_sp<GrTexture> tex(SkSafeRef(copy->instantiate(fContext->resourceProvider())));
-    return tex.release();
+    return CopyOnGpu(original.get(), nullptr, copyParams);
 }
index 72ef87735926e1edb48735d16b6202bc89af1510..c8bf732aa37641dcc2d431a7373993531f610145 100644 (file)
@@ -88,8 +88,13 @@ sk_sp<GrTextureProxy> SkImage_Generator::asTextureProxyRef(GrContext* context,
                                                            SkColorSpace* dstColorSpace,
                                                            sk_sp<SkColorSpace>* texColorSpace,
                                                            SkScalar scaleAdjust[2]) const {
-    return fCache.lockAsTextureProxy(context, params, dstColorSpace,
-                                     texColorSpace, this, scaleAdjust);
+    sk_sp<GrTexture> tex(fCache.lockAsTexture(context, params, dstColorSpace,
+                                              texColorSpace, this, scaleAdjust));
+    if (!tex) {
+        return nullptr;
+    }
+
+    return GrSurfaceProxy::MakeWrapped(std::move(tex));
 }
 #endif