Revert "Treat cross context images as Ganesh-created resources"

This reverts commit cccda60aca592d2320d79e2871e057778b2688ab.

Reason for revert: Android and Windows bot failures.

Original change's description:
> Treat cross context images as Ganesh-created resources
> 
> Always create them budgeted, and register them with the cache (not as
> wrapped resources).
> 
> BUG=skia:
> 
> Change-Id: Id18ecf6e9e512db4be21b4f2bfd8e8c060bbe805
> Reviewed-on: https://skia-review.googlesource.com/9497
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> 

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

Change-Id: Ib7bebcad33037dd206c9b06b5cb6c503b00accba
Reviewed-on: https://skia-review.googlesource.com/9541
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index 62e8a79..654febd 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -676,9 +676,6 @@
 
     /** Skia will assume ownership of the resource and free it. */
     kAdopt_GrWrapOwnership,
-
-    /** Skia will assume ownership of the resource, free it, and reuse it within the cache. */
-    kAdoptAndCache_GrWrapOwnership,
 };
 
 /**
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 3924a5a..d7af9de 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -520,7 +520,6 @@
 
     // next line relies on GrBackendTextureDesc's flags matching GrTexture's
     bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag);
-    SkASSERT(!renderTarget || kAdoptAndCache_GrWrapOwnership != ownership);  // Not supported
 
     GrGLTexture::IDDesc idDesc;
     idDesc.fInfo = *info;
@@ -547,10 +546,10 @@
         return nullptr;
     }
 
-    if (kBorrow_GrWrapOwnership == ownership) {
-        idDesc.fOwnership = GrBackendObjectOwnership::kBorrowed;
-    } else {
+    if (kAdopt_GrWrapOwnership == ownership) {
         idDesc.fOwnership = GrBackendObjectOwnership::kOwned;
+    } else {
+        idDesc.fOwnership = GrBackendObjectOwnership::kBorrowed;
     }
 
     GrSurfaceDesc surfDesc;
@@ -576,12 +575,7 @@
         }
         return GrGLTextureRenderTarget::MakeWrapped(this, surfDesc, idDesc, rtIDDesc);
     }
-
-    if (kAdoptAndCache_GrWrapOwnership == ownership) {
-        return sk_sp<GrTexture>(new GrGLTexture(this, SkBudgeted::kYes, surfDesc, idDesc));
-    } else {
-        return GrGLTexture::MakeWrapped(this, surfDesc, idDesc);
-    }
+    return GrGLTexture::MakeWrapped(this, surfDesc, idDesc);
 }
 
 sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc){
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 6412a55..81fb089 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -779,7 +779,6 @@
     surfDesc.fConfig = desc.fConfig;
     surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount());
     bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag);
-    SkASSERT(!renderTarget || kAdoptAndCache_GrWrapOwnership != ownership);  // Not supported
     // In GL, Chrome assumes all textures are BottomLeft
     // In VK, we don't have this restriction
     surfDesc.fOrigin = resolve_origin(desc.fOrigin);
diff --git a/src/gpu/vk/GrVkTexture.cpp b/src/gpu/vk/GrVkTexture.cpp
index fb6b94f..a8f1bf0 100644
--- a/src/gpu/vk/GrVkTexture.cpp
+++ b/src/gpu/vk/GrVkTexture.cpp
@@ -96,13 +96,10 @@
         return nullptr;
     }
 
-    if (kAdoptAndCache_GrWrapOwnership == ownership) {
-        return sk_sp<GrVkTexture>(new GrVkTexture(gpu, SkBudgeted::kYes, desc, *info, imageView));
-    } else {
-        GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership
-                ? GrVkImage::kBorrowed_Wrapped : GrVkImage::kAdopted_Wrapped;
-        return sk_sp<GrVkTexture>(new GrVkTexture(gpu, kWrapped, desc, *info, imageView, wrapped));
-    }
+    GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership ? GrVkImage::kBorrowed_Wrapped
+                                                                      : GrVkImage::kAdopted_Wrapped;
+
+    return sk_sp<GrVkTexture>(new GrVkTexture(gpu, kWrapped, desc, *info, imageView, wrapped));
 }
 
 GrVkTexture::~GrVkTexture() {
diff --git a/src/gpu/vk/GrVkTextureRenderTarget.cpp b/src/gpu/vk/GrVkTextureRenderTarget.cpp
index 1d7d756..cfa63be 100644
--- a/src/gpu/vk/GrVkTextureRenderTarget.cpp
+++ b/src/gpu/vk/GrVkTextureRenderTarget.cpp
@@ -143,7 +143,6 @@
     SkASSERT(info);
     // Wrapped textures require both image and allocation (because they can be mapped)
     SkASSERT(VK_NULL_HANDLE != info->fImage && VK_NULL_HANDLE != info->fAlloc.fMemory);
-    SkASSERT(kAdoptAndCache_GrWrapOwnership != ownership);  // Not supported
 
     GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership ? GrVkImage::kBorrowed_Wrapped
                                                                       : GrVkImage::kAdopted_Wrapped;
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index ffa7d9e..a3649ac 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -264,8 +264,7 @@
         tex->setRelease(releaseProc, releaseCtx);
     }
 
-    const SkBudgeted budgeted = (kAdoptAndCache_GrWrapOwnership == ownership)
-            ? SkBudgeted::kYes : SkBudgeted::kNo;
+    const SkBudgeted budgeted = SkBudgeted::kNo;
     return sk_make_sp<SkImage_Gpu>(kNeedNewImageUniqueID,
                                    at, std::move(tex), std::move(colorSpace), budgeted);
 }
@@ -477,11 +476,8 @@
         ccid->fTextureData->attachToContext(context);
     }
 
-    // This texture was created by Ganesh on another thread (see MakeFromEncoded, above).
-    // Thus, we can import it back into our cache and treat it as our own (again).
-    GrWrapOwnership ownership = kAdoptAndCache_GrWrapOwnership;
-    return new_wrapped_texture_common(context, ccid->fDesc, ccid->fAlphaType,
-                                      std::move(ccid->fColorSpace), ownership, nullptr, nullptr);
+    return MakeFromAdoptedTexture(context, ccid->fDesc, ccid->fAlphaType,
+                                  std::move(ccid->fColorSpace));
 }
 
 sk_sp<SkImage> SkImage::makeNonTextureImage() const {
diff --git a/tests/CrossContextImageTest.cpp b/tests/CrossContextImageTest.cpp
index 82eb2d5..e37b095 100644
--- a/tests/CrossContextImageTest.cpp
+++ b/tests/CrossContextImageTest.cpp
@@ -140,24 +140,9 @@
             REPORTER_ASSERT(reporter, ccid != nullptr);
 
             ContextInfo info2 = factory.getSharedContextInfo(info.grContext());
-            GrContext* ctx2 = info2.grContext();
-            int resourceCountBefore = 0, resourceCountAfter = 0;
-            size_t resourceBytesBefore = 0, resourceBytesAfter = 0;
-            if (ctx2) {
-                ctx2->getResourceCacheUsage(&resourceCountBefore, &resourceBytesBefore);
-            }
-
-            auto image = SkImage::MakeFromCrossContextImageData(ctx2, std::move(ccid));
+            auto image = SkImage::MakeFromCrossContextImageData(info2.grContext(), std::move(ccid));
             REPORTER_ASSERT(reporter, image != nullptr);
 
-            if (ctx2) {
-                // MakeFromCrossContextImageData should have imported the texture back into our
-                // cache, so we should see an uptick.
-                ctx2->getResourceCacheUsage(&resourceCountAfter, &resourceBytesAfter);
-                REPORTER_ASSERT(reporter, resourceCountAfter == resourceCountBefore + 1);
-                REPORTER_ASSERT(reporter, resourceBytesAfter > resourceBytesBefore);
-            }
-
             // JPEG encode -> decode won't round trip the image perfectly
             assert_equal(reporter, testImage.get(), image.get(),
                          SkEncodedImageFormat::kJPEG == format ? 2 : 0);
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 2454536..a2064ae 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -208,13 +208,12 @@
         return;
     }
 
-    GrBackendObject texHandles[3];
+    GrBackendObject texHandles[2];
     static const int kW = 100;
     static const int kH = 100;
 
     texHandles[0] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888_GrPixelConfig);
     texHandles[1] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888_GrPixelConfig);
-    texHandles[2] = gpu->createTestingOnlyBackendTexture(nullptr, kW, kH, kRGBA_8888_GrPixelConfig);
 
     context->resetContext();
 
@@ -231,40 +230,26 @@
     sk_sp<GrTexture> adopted(context->resourceProvider()->wrapBackendTexture(
                              desc, kAdopt_GrWrapOwnership));
 
-    desc.fTextureHandle = texHandles[2];
-    sk_sp<GrTexture> adoptedAndCached(context->resourceProvider()->wrapBackendTexture(
-                                      desc, kAdoptAndCache_GrWrapOwnership));
-
-    REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr &&
-                              adoptedAndCached != nullptr);
-    if (!borrowed || !adopted || !adoptedAndCached) {
+    REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr);
+    if (!borrowed || !adopted) {
         return;
     }
 
     borrowed.reset(nullptr);
     adopted.reset(nullptr);
-    adoptedAndCached.reset(nullptr);
 
     context->flush();
 
     bool borrowedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[0]);
     bool adoptedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[1]);
-    bool adoptedAndCachedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[2]);
 
     REPORTER_ASSERT(reporter, borrowedIsAlive);
     REPORTER_ASSERT(reporter, !adoptedIsAlive);
-    REPORTER_ASSERT(reporter, adoptedAndCachedIsAlive); // Still alive because it's in the cache
 
     gpu->deleteTestingOnlyBackendTexture(texHandles[0], !borrowedIsAlive);
     gpu->deleteTestingOnlyBackendTexture(texHandles[1], !adoptedIsAlive);
-    // We can't delete texHandles[2] - we've given control of the lifetime to the context/cache
 
     context->resetContext();
-
-    // Purge the cache. This should force texHandles[2] to be deleted
-    context->getResourceCache()->purgeAllUnlocked();
-    adoptedAndCachedIsAlive = gpu->isTestingOnlyBackendTexture(texHandles[2]);
-    REPORTER_ASSERT(reporter, !adoptedAndCachedIsAlive);
 }
 
 class TestResource : public GrGpuResource {