Remove SkCrossContextImageData and all support code
Bug: skia:
Change-Id: I8eb8cef5456c05a8e314d8404698893c7af82d13
Reviewed-on: https://skia-review.googlesource.com/16368
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/gn/core.gni b/gn/core.gni
index 10104ff..da92020 100644
--- a/gn/core.gni
+++ b/gn/core.gni
@@ -390,7 +390,6 @@
"$_include/core/SkColor.h",
"$_include/core/SkColorFilter.h",
"$_include/core/SkColorPriv.h",
- "$_include/core/SkCrossContextImageData.h",
"$_include/core/SkData.h",
"$_include/core/SkDeque.h",
"$_include/core/SkDrawable.h",
diff --git a/gn/gpu.gni b/gn/gpu.gni
index b2515f0..006267f 100644
--- a/gn/gpu.gni
+++ b/gn/gpu.gni
@@ -15,7 +15,6 @@
"$_include/gpu/GrConfig.h",
"$_include/gpu/GrContextOptions.h",
"$_include/gpu/GrContext.h",
- "$_include/gpu/GrExternalTextureData.h",
"$_include/gpu/GrGpuResource.h",
"$_include/gpu/GrGpuResourceRef.h",
"$_include/gpu/GrRenderTarget.h",
@@ -388,7 +387,6 @@
"$_src/gpu/gl/GrGLGpuCommandBuffer.h",
"$_src/gpu/gl/GrGLGpuProgramCache.cpp",
"$_src/gpu/gl/GrGLExtensions.cpp",
- "$_src/gpu/gl/GrGLExternalTextureData.cpp",
"$_src/gpu/gl/GrGLInterface.cpp",
"$_src/gpu/gl/GrGLIRect.h",
"$_src/gpu/gl/GrGLPath.cpp",
diff --git a/gn/tests.gni b/gn/tests.gni
index f486629..f63fb75 100644
--- a/gn/tests.gni
+++ b/gn/tests.gni
@@ -45,7 +45,6 @@
"$_tests/ColorTest.cpp",
"$_tests/CopySurfaceTest.cpp",
"$_tests/CPlusPlusEleven.cpp",
- "$_tests/CrossContextImageTest.cpp",
"$_tests/CTest.cpp",
"$_tests/DashPathEffectTest.cpp",
"$_tests/DataRefTest.cpp",
diff --git a/include/core/SkCrossContextImageData.h b/include/core/SkCrossContextImageData.h
deleted file mode 100644
index a408f71..0000000
--- a/include/core/SkCrossContextImageData.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef SkCrossContextImageData_DEFINED
-#define SkCrossContextImageData_DEFINED
-
-#include "SkImage.h"
-
-#if SK_SUPPORT_GPU
-#include "GrBackendSurface.h"
-#include "GrExternalTextureData.h"
-#endif
-
-class SK_API SkCrossContextImageData : SkNoncopyable {
-public:
- /**
- * Decodes and uploads the encoded data to a texture using the supplied GrContext, then
- * returns an instance of SkCrossContextImageData that can be used to transport that texture
- * to a different GrContext, across thread boundaries. The GrContext used here, and the one
- * used to reconstruct the texture-backed image later must be in the same GL share group,
- * or otherwise be able to share resources. After calling this, you *must* construct exactly
- * one SkImage from the returned value, using SkImage::MakeFromCrossContextImageData.
- *
- * The texture will be decoded and uploaded to be suitable for use with surfaces that have the
- * supplied destination color space. The color space of the texture itself will be determined
- * from the encoded data.
- */
- static std::unique_ptr<SkCrossContextImageData> MakeFromEncoded(
- GrContext*, sk_sp<SkData>, SkColorSpace* dstColorSpace);
-
- virtual ~SkCrossContextImageData() {}
-
-protected:
- SkCrossContextImageData() {}
-
-private:
- virtual sk_sp<SkImage> makeImage(GrContext*) = 0;
-
- friend class SkImage;
-};
-
-class SkCCIDImage : public SkCrossContextImageData {
-public:
- ~SkCCIDImage() override {}
-
-private:
- SkCCIDImage(sk_sp<SkImage> image) : fImage(std::move(image)) {
- SkASSERT(!fImage->isTextureBacked());
- }
-
- sk_sp<SkImage> makeImage(GrContext*) override {
- return fImage;
- }
-
- sk_sp<SkImage> fImage;
-
- friend class SkCrossContextImageData;
- friend class SkImage;
-};
-
-#if SK_SUPPORT_GPU
-class SkCCIDBackendTexture : public SkCrossContextImageData {
-public:
- ~SkCCIDBackendTexture() override {}
-
-private:
- SkCCIDBackendTexture(const GrBackendTexture& backendTex,
- GrSurfaceOrigin origin,
- std::unique_ptr<GrExternalTextureData> textureData,
- SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace)
- : fAlphaType(alphaType)
- , fColorSpace(std::move(colorSpace))
- , fBackendTex(backendTex)
- , fOrigin(origin)
- , fTextureData(std::move(textureData)) {}
-
- sk_sp<SkImage> makeImage(GrContext*) override;
-
- // GPU-backed images store some generic information (needed to reconstruct the SkImage),
- // and some backend-specific info (to reconstruct the texture).
- SkAlphaType fAlphaType;
- sk_sp<SkColorSpace> fColorSpace;
- GrBackendTexture fBackendTex;
- GrSurfaceOrigin fOrigin;
- std::unique_ptr<GrExternalTextureData> fTextureData;
-
- friend class SkCrossContextImageData;
-};
-#endif
-
-#endif
diff --git a/include/core/SkImage.h b/include/core/SkImage.h
index 2ba6761..729e43d 100644
--- a/include/core/SkImage.h
+++ b/include/core/SkImage.h
@@ -18,7 +18,6 @@
class SkData;
class SkCanvas;
class SkColorTable;
-class SkCrossContextImageData;
class SkImageGenerator;
class SkPaint;
class SkPicture;
@@ -406,14 +405,6 @@
sk_sp<SkImage> makeTextureImage(GrContext*, SkColorSpace* dstColorSpace) const;
/**
- * Constructs a texture backed image from data that was previously uploaded on another thread
- * and GrContext. The GrContext used to upload the data must be in the same GL share group as
- * the one passed in here, or otherwise be able to share resources with the passed in context.
- */
- static sk_sp<SkImage> MakeFromCrossContextImageData(GrContext*,
- std::unique_ptr<SkCrossContextImageData>);
-
- /**
* If the image is texture-backed this will make a raster copy of it (or nullptr if reading back
* the pixels fails). Otherwise, it returns the original image.
*/
diff --git a/include/gpu/GrExternalTextureData.h b/include/gpu/GrExternalTextureData.h
deleted file mode 100644
index b3b0594..0000000
--- a/include/gpu/GrExternalTextureData.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef GrExternalTextureData_DEFINED
-#define GrExternalTextureData_DEFINED
-
-#include "GrTypes.h"
-
-class GrContext;
-
-class SK_API GrExternalTextureData : SkNoncopyable {
-public:
- virtual ~GrExternalTextureData() {}
- virtual GrBackend getBackend() const = 0;
-protected:
- virtual GrBackendObject getBackendObject() const = 0;
- virtual void attachToContext(GrContext*) = 0;
-
- friend class SkCrossContextImageData;
- friend class SkCCIDBackendTexture;
- friend class SkImage;
-};
-
-#endif
diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h
index 2d84c63..1ed64ad 100644
--- a/include/gpu/GrGpuResource.h
+++ b/include/gpu/GrGpuResource.h
@@ -260,11 +260,6 @@
// final class).
void registerWithCacheWrapped();
- // This is only called by resources that are being exported from Ganesh to client code. It
- // ensures that the cache can no longer reach this resource, and that it no longer counts
- // against the budget.
- void detachFromCache();
-
GrGpuResource(GrGpu*);
virtual ~GrGpuResource();
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index ba7d506..0edcbd0 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -14,7 +14,6 @@
#include "SkPoint.h"
#include "SkRefCnt.h"
-class GrExternalTextureData;
class GrTexturePriv;
class GrTexture : virtual public GrSurface {
@@ -56,7 +55,6 @@
GrSamplerParams::FilterMode highestFilterMode, bool wasMipMapDataProvided);
void validateDesc() const;
- virtual std::unique_ptr<GrExternalTextureData> detachBackendTexture() = 0;
private:
void computeScratchKey(GrScratchKey*) const override;
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/include/gpu/gl/GrGLTypes.h b/include/gpu/gl/GrGLTypes.h
index 345364b..a615888 100644
--- a/include/gpu/gl/GrGLTypes.h
+++ b/include/gpu/gl/GrGLTypes.h
@@ -9,7 +9,6 @@
#ifndef GrGLTypes_DEFINED
#define GrGLTypes_DEFINED
-#include "GrExternalTextureData.h"
#include "GrGLConfig.h"
#include "SkRefCnt.h"
@@ -114,25 +113,6 @@
GrGLuint fID;
};
-class GrSemaphore;
-
-class GrGLExternalTextureData : public GrExternalTextureData {
-public:
- GrGLExternalTextureData(const GrGLTextureInfo& info, sk_sp<GrSemaphore> semaphore, GrContext*);
- GrBackend getBackend() const override { return kOpenGL_GrBackend; }
-
-protected:
- GrBackendObject getBackendObject() const override {
- return reinterpret_cast<GrBackendObject>(&fInfo);
- }
- void attachToContext(GrContext*) override;
-
- GrGLTextureInfo fInfo;
- sk_sp<GrSemaphore> fSemaphore;
-
- typedef GrExternalTextureData INHERITED;
-};
-
GR_STATIC_ASSERT(sizeof(GrBackendObject) >= sizeof(const GrGLTextureInfo*));
struct GrGLFramebufferInfo {
diff --git a/include/gpu/vk/GrVkTypes.h b/include/gpu/vk/GrVkTypes.h
index c98a94a..aa1334a 100644
--- a/include/gpu/vk/GrVkTypes.h
+++ b/include/gpu/vk/GrVkTypes.h
@@ -9,7 +9,6 @@
#ifndef GrVkTypes_DEFINED
#define GrVkTypes_DEFINED
-#include "GrExternalTextureData.h"
#include "GrTypes.h"
#include "vk/GrVkDefines.h"
@@ -60,24 +59,6 @@
void updateImageLayout(VkImageLayout layout) { fImageLayout = layout; }
};
-class GrVkExternalTextureData : public GrExternalTextureData {
-public:
- GrVkExternalTextureData(const GrVkImageInfo& info) : fInfo(info) {}
- GrBackend getBackend() const override { return kVulkan_GrBackend; }
-
-protected:
- GrBackendObject getBackendObject() const override {
- return reinterpret_cast<GrBackendObject>(&fInfo);
- }
- void attachToContext(GrContext*) override {
- // TODO: Implement this
- }
-
- GrVkImageInfo fInfo;
-
- typedef GrExternalTextureData INHERITED;
-};
-
GR_STATIC_ASSERT(sizeof(GrBackendObject) >= sizeof(const GrVkImageInfo*));
#endif
diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp
index c7df663..872bbbb 100644
--- a/src/gpu/GrGpuResource.cpp
+++ b/src/gpu/GrGpuResource.cpp
@@ -43,17 +43,6 @@
get_resource_cache(fGpu)->resourceAccess().insertResource(this);
}
-void GrGpuResource::detachFromCache() {
- if (this->wasDestroyed()) {
- return;
- }
- if (fUniqueKey.isValid()) {
- this->removeUniqueKey();
- }
- this->removeScratchKey();
- this->makeUnbudgeted();
-}
-
GrGpuResource::~GrGpuResource() {
// The cache should have released or destroyed this resource.
SkASSERT(this->wasDestroyed());
diff --git a/src/gpu/GrTexturePriv.h b/src/gpu/GrTexturePriv.h
index cc0a05e..0420611 100644
--- a/src/gpu/GrTexturePriv.h
+++ b/src/gpu/GrTexturePriv.h
@@ -8,7 +8,6 @@
#ifndef GrTexturePriv_DEFINED
#define GrTexturePriv_DEFINED
-#include "GrExternalTextureData.h"
#include "GrTexture.h"
/** Class that adds methods to GrTexture that are only intended for use internal to Skia.
@@ -68,15 +67,6 @@
}
SkDestinationSurfaceColorMode mipColorMode() const { return fTexture->fMipColorMode; }
- /**
- * Return the native bookkeeping data for this texture, and detach the backend object from
- * this GrTexture. It's lifetime will no longer be managed by Ganesh, and this GrTexture will
- * no longer refer to it. Leaves this GrTexture in an orphan state.
- */
- std::unique_ptr<GrExternalTextureData> detachBackendTexture() {
- return fTexture->detachBackendTexture();
- }
-
static void ComputeScratchKey(const GrSurfaceDesc&, GrScratchKey*);
private:
diff --git a/src/gpu/gl/GrGLExternalTextureData.cpp b/src/gpu/gl/GrGLExternalTextureData.cpp
deleted file mode 100644
index 1087830..0000000
--- a/src/gpu/gl/GrGLExternalTextureData.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrContext.h"
-#include "GrContextPriv.h"
-#include "GrGpu.h"
-#include "GrResourceProvider.h"
-#include "GrSemaphore.h"
-#include "gl/GrGLTypes.h"
-
-GrGLExternalTextureData::GrGLExternalTextureData(const GrGLTextureInfo& info,
- sk_sp<GrSemaphore> semaphore,
- GrContext* context)
- : fInfo(info)
- , fSemaphore(std::move(semaphore)) {
- SkASSERT(fSemaphore->unique());
- context->resourceProvider()->releaseOwnershipOfSemaphore(fSemaphore);
-}
-
-void GrGLExternalTextureData::attachToContext(GrContext* context) {
- context->resourceProvider()->takeOwnershipOfSemaphore(fSemaphore);
- // Ideally we don't want to get the Gpu off of the context here. However, eventually this
- // semaphore will live on a GrTexture object and the wait will be called from there. At that
- // point we can use the GrGpu already stored directly on the GrTexture.
- context->getGpu()->waitSemaphore(fSemaphore);
-}
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 9b507a4..c3e0a0c 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -529,7 +529,6 @@
// next line relies on GrBackendTextureFlags matching GrTexture's
bool renderTarget = SkToBool(flags & kRenderTarget_GrBackendTextureFlag);
- SkASSERT(!renderTarget || kAdoptAndCache_GrWrapOwnership != ownership); // Not supported
GrGLTexture::IDDesc idDesc;
idDesc.fInfo = *info;
@@ -586,11 +585,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 GrBackendRenderTarget& backendRT,
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index d722f38..ccbd1a6 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -5,13 +5,11 @@
* found in the LICENSE file.
*/
-#include "GrContext.h"
#include "GrGLTexture.h"
#include "GrGLGpu.h"
#include "GrResourceProvider.h"
#include "GrSemaphore.h"
#include "GrShaderCaps.h"
-#include "SkMakeUnique.h"
#include "SkTraceMemoryDump.h"
#define GPUGL static_cast<GrGLGpu*>(this->getGpu())
@@ -117,27 +115,6 @@
return reinterpret_cast<GrBackendObject>(&fInfo);
}
-std::unique_ptr<GrExternalTextureData> GrGLTexture::detachBackendTexture() {
- SkASSERT(!this->hasPendingIO());
-
- // Set up a semaphore to be signaled once the data is ready, and flush GL
- sk_sp<GrSemaphore> semaphore = this->getContext()->resourceProvider()->makeSemaphore();
- this->getGpu()->insertSemaphore(semaphore, true);
-
- // Make a copy of our GL-specific information
- auto data = skstd::make_unique<GrGLExternalTextureData>(fInfo, std::move(semaphore),
- this->getContext());
-
- // Ensure the cache can't reach this texture anymore
- this->detachFromCache();
-
- // Detach from the GL object, so we don't use it (or try to delete it when we're freed)
- fInfo.fTarget = 0;
- fInfo.fID = 0;
-
- return std::move(data);
-}
-
void GrGLTexture::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
const SkString& dumpName) const {
SkString texture_id;
diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h
index 7ba8058..7435891 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -81,7 +81,6 @@
void onRelease() override;
void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
const SkString& dumpName) const override;
- std::unique_ptr<GrExternalTextureData> detachBackendTexture() override;
private:
void invokeReleaseProc() {
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 9dd3688..107e46a 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -851,7 +851,6 @@
surfDesc.fConfig = backendTex.config();
surfDesc.fSampleCnt = SkTMin(sampleCnt, this->caps()->maxSampleCount());
bool renderTarget = SkToBool(flags & 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(origin);
diff --git a/src/gpu/vk/GrVkTexture.cpp b/src/gpu/vk/GrVkTexture.cpp
index defbe13..4857db6 100644
--- a/src/gpu/vk/GrVkTexture.cpp
+++ b/src/gpu/vk/GrVkTexture.cpp
@@ -105,13 +105,9 @@
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() {
@@ -156,12 +152,6 @@
return (GrBackendObject)&fInfo;
}
-std::unique_ptr<GrExternalTextureData> GrVkTexture::detachBackendTexture() {
- // Not supported on Vulkan yet
- // TODO: Add thread-safe memory pools, and implement this.
- return nullptr;
-}
-
GrVkGpu* GrVkTexture::getVkGpu() const {
SkASSERT(!this->wasDestroyed());
return static_cast<GrVkGpu*>(this->getGpu());
diff --git a/src/gpu/vk/GrVkTexture.h b/src/gpu/vk/GrVkTexture.h
index a866748..febd7ad 100644
--- a/src/gpu/vk/GrVkTexture.h
+++ b/src/gpu/vk/GrVkTexture.h
@@ -49,7 +49,6 @@
void onAbandon() override;
void onRelease() override;
- std::unique_ptr<GrExternalTextureData> detachBackendTexture() override;
private:
enum Wrapped { kWrapped };
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.cpp b/src/image/SkImage.cpp
index efa16c9..3e525b39 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -9,7 +9,6 @@
#include "SkBitmapCache.h"
#include "SkCanvas.h"
#include "SkColorSpace_Base.h"
-#include "SkCrossContextImageData.h"
#include "SkData.h"
#include "SkImageEncoder.h"
#include "SkImageFilter.h"
@@ -381,21 +380,6 @@
return nullptr;
}
-std::unique_ptr<SkCrossContextImageData> SkCrossContextImageData::MakeFromEncoded(
- GrContext*, sk_sp<SkData> encoded, SkColorSpace* dstColorSpace) {
- sk_sp<SkImage> image = SkImage::MakeFromEncoded(std::move(encoded));
- if (!image) {
- return nullptr;
- }
- // TODO: Force decode to raster here?
- return std::unique_ptr<SkCrossContextImageData>(new SkCCIDImage(std::move(image)));
-}
-
-sk_sp<SkImage> SkImage::MakeFromCrossContextImageData(
- GrContext*, std::unique_ptr<SkCrossContextImageData> ccid) {
- return ccid->makeImage(nullptr);
-}
-
sk_sp<SkImage> SkImage::makeNonTextureImage() const {
return sk_ref_sp(const_cast<SkImage*>(this));
}
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 9bb98fb..4740543 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -27,7 +27,6 @@
#include "effects/GrNonlinearColorSpaceXformEffect.h"
#include "effects/GrYUVEffect.h"
#include "SkCanvas.h"
-#include "SkCrossContextImageData.h"
#include "SkBitmapCache.h"
#include "SkGr.h"
#include "SkImage_Gpu.h"
@@ -268,8 +267,7 @@
tex->setRelease(releaseProc, releaseCtx);
}
- const SkBudgeted budgeted = (kAdoptAndCache_GrWrapOwnership == ownership)
- ? SkBudgeted::kYes : SkBudgeted::kNo;
+ const SkBudgeted budgeted = SkBudgeted::kNo;
sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(tex)));
return sk_make_sp<SkImage_Gpu>(ctx, kNeedNewImageUniqueID,
at, std::move(proxy), std::move(colorSpace), budgeted);
@@ -502,64 +500,6 @@
return SkImage::MakeFromGenerator(std::move(gen));
}
-std::unique_ptr<SkCrossContextImageData> SkCrossContextImageData::MakeFromEncoded(
- GrContext* context, sk_sp<SkData> encoded, SkColorSpace* dstColorSpace) {
- sk_sp<SkImage> codecImage = SkImage::MakeFromEncoded(std::move(encoded));
- if (!codecImage) {
- return nullptr;
- }
-
- // Some backends or drivers don't support (safely) moving resources between contexts
- if (!context->caps()->crossContextTextureSupport()) {
- return std::unique_ptr<SkCrossContextImageData>(
- new SkCCIDImage(std::move(codecImage)));
- }
-
- sk_sp<SkImage> textureImage = codecImage->makeTextureImage(context, dstColorSpace);
- if (!textureImage) {
- // TODO: Force decode to raster here? Do mip-mapping, like getDeferredTextureImageData?
- return std::unique_ptr<SkCrossContextImageData>(
- new SkCCIDImage(std::move(codecImage)));
- }
-
- // Crack open the gpu image, extract the backend data, stick it in the SkCCID
- GrTexture* texture = as_IB(textureImage)->peekTexture();
- SkASSERT(texture);
-
- context->contextPriv().prepareSurfaceForExternalIO(as_IB(textureImage)->peekProxy());
- auto textureData = texture->texturePriv().detachBackendTexture();
- SkASSERT(textureData);
-
- GrBackend backend = context->contextPriv().getBackend();
- GrBackendTexture backendTex = make_backend_texture_from_handle(backend,
- texture->width(),
- texture->height(),
- texture->config(),
- textureData->getBackendObject());
-
- SkImageInfo info = as_IB(textureImage)->onImageInfo();
- return std::unique_ptr<SkCrossContextImageData>(new SkCCIDBackendTexture(
- backendTex, texture->origin(), std::move(textureData),
- info.alphaType(), info.refColorSpace()));
-}
-
-sk_sp<SkImage> SkCCIDBackendTexture::makeImage(GrContext* context) {
- if (fTextureData) {
- 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, fBackendTex, fOrigin, fAlphaType,
- std::move(fColorSpace), ownership, nullptr, nullptr);
-}
-
-sk_sp<SkImage> SkImage::MakeFromCrossContextImageData(
- GrContext* context, std::unique_ptr<SkCrossContextImageData> ccid) {
- return ccid->makeImage(context);
-}
-
sk_sp<SkImage> SkImage::makeNonTextureImage() const {
if (!this->isTextureBacked()) {
return sk_ref_sp(const_cast<SkImage*>(this));
diff --git a/tests/CrossContextImageTest.cpp b/tests/CrossContextImageTest.cpp
deleted file mode 100644
index 5c8b21e..0000000
--- a/tests/CrossContextImageTest.cpp
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Copyright 2017 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkTypes.h"
-
-#if SK_SUPPORT_GPU
-
-#include "GrContextFactory.h"
-#include "Resources.h"
-#include "SkAutoPixmapStorage.h"
-#include "SkBitmap.h"
-#include "SkCanvas.h"
-#include "SkCrossContextImageData.h"
-#include "SkSemaphore.h"
-#include "SkSurface.h"
-#include "SkThreadUtils.h"
-#include "Test.h"
-
-using namespace sk_gpu_test;
-
-static SkImageInfo read_pixels_info(SkImage* image) {
- return SkImageInfo::MakeN32(image->width(), image->height(), image->alphaType());
-}
-
-static bool colors_are_close(SkColor a, SkColor b, int error) {
- return SkTAbs((int)SkColorGetR(a) - (int)SkColorGetR(b)) <= error &&
- SkTAbs((int)SkColorGetG(a) - (int)SkColorGetG(b)) <= error &&
- SkTAbs((int)SkColorGetB(a) - (int)SkColorGetB(b)) <= error;
-}
-
-static void assert_equal(skiatest::Reporter* reporter, SkImage* a, SkImage* b, int error) {
- REPORTER_ASSERT(reporter, a->width() == b->width());
- REPORTER_ASSERT(reporter, a->height() == b->height());
-
- SkAutoPixmapStorage pmapA, pmapB;
- pmapA.alloc(read_pixels_info(a));
- pmapB.alloc(read_pixels_info(b));
-
- REPORTER_ASSERT(reporter, a->readPixels(pmapA, 0, 0));
- REPORTER_ASSERT(reporter, b->readPixels(pmapB, 0, 0));
-
- for (int y = 0; y < a->height(); ++y) {
- for (int x = 0; x < a->width(); ++x) {
- SkColor ca = pmapA.getColor(x, y);
- SkColor cb = pmapB.getColor(x, y);
- if (!error) {
- if (ca != cb) {
- ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d)", ca, cb, x, y);
- return;
- }
- } else {
- if (!colors_are_close(ca, cb, error)) {
- ERRORF(reporter, "Expected 0x%08x +-%d but got 0x%08x at (%d, %d)",
- ca, error, cb, x, y);
- return;
- }
- }
- }
- }
-}
-
-static void draw_image_test_pattern(SkCanvas* canvas) {
- canvas->clear(SK_ColorWHITE);
- SkPaint paint;
- paint.setColor(SK_ColorBLACK);
- canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint);
-}
-
-static sk_sp<SkImage> create_test_image() {
- SkBitmap bm;
- bm.allocN32Pixels(20, 20, true);
- SkCanvas canvas(bm);
- draw_image_test_pattern(&canvas);
-
- return SkImage::MakeFromBitmap(bm);
-}
-
-static sk_sp<SkData> create_test_data(SkEncodedImageFormat format) {
- auto image = create_test_image();
- return sk_sp<SkData>(image->encode(format, 100));
-}
-
-DEF_GPUTEST(CrossContextImage_SameContext, reporter, /*factory*/) {
- GrContextFactory factory;
- sk_sp<SkImage> testImage = create_test_image();
-
- // Test both PNG and JPG, to exercise GPU YUV conversion
- for (auto format : { SkEncodedImageFormat::kPNG, SkEncodedImageFormat::kJPEG }) {
- sk_sp<SkData> encoded = create_test_data(format);
-
- for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
- GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
- if (!sk_gpu_test::GrContextFactory::IsRenderingContext(ctxType)) {
- continue;
- }
-
- ContextInfo info = factory.getContextInfo(ctxType);
- if (!info.grContext()) {
- continue;
- }
-
- auto ccid = SkCrossContextImageData::MakeFromEncoded(info.grContext(), encoded,
- nullptr);
- REPORTER_ASSERT(reporter, ccid != nullptr);
-
- auto image = SkImage::MakeFromCrossContextImageData(info.grContext(), std::move(ccid));
- REPORTER_ASSERT(reporter, image != nullptr);
-
- // JPEG encode -> decode won't round trip the image perfectly
- assert_equal(reporter, testImage.get(), image.get(),
- SkEncodedImageFormat::kJPEG == format ? 2 : 0);
- }
- }
-}
-
-DEF_GPUTEST(CrossContextImage_SharedContextSameThread, reporter, /*factory*/) {
- GrContextFactory factory;
- sk_sp<SkImage> testImage = create_test_image();
-
- // Test both PNG and JPG, to exercise GPU YUV conversion
- for (auto format : { SkEncodedImageFormat::kPNG, SkEncodedImageFormat::kJPEG }) {
- sk_sp<SkData> encoded = create_test_data(format);
-
- for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
- GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
- if (!sk_gpu_test::GrContextFactory::IsRenderingContext(ctxType)) {
- continue;
- }
-
- ContextInfo info = factory.getContextInfo(ctxType);
- if (!info.grContext()) {
- continue;
- }
- auto ccid = SkCrossContextImageData::MakeFromEncoded(info.grContext(), encoded,
- nullptr);
- 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 && info.grContext()->caps()->crossContextTextureSupport()) {
- ctx2->getResourceCacheUsage(&resourceCountBefore, &resourceBytesBefore);
- }
-
- auto image = SkImage::MakeFromCrossContextImageData(ctx2, std::move(ccid));
- REPORTER_ASSERT(reporter, image != nullptr);
-
- if (ctx2 && info.grContext()->caps()->crossContextTextureSupport()) {
- // MakeFromCrossContextImageData should have imported the texture back into our
- // cache, so we should see an uptick. (If we have crossContextTextureSupport,
- // otherwise we're just handing around a CPU or codec-backed image, so no cache
- // impact will occur).
- 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);
- }
- }
-}
-
-namespace {
-struct CrossContextImage_ThreadContext {
- GrContext* fGrContext;
- sk_gpu_test::TestContext* fTestContext;
- SkSemaphore fSemaphore;
- std::unique_ptr<SkCrossContextImageData> fCCID;
- sk_sp<SkData> fEncoded;
-};
-}
-
-static void upload_image_thread_proc(void* data) {
- CrossContextImage_ThreadContext* ctx = static_cast<CrossContextImage_ThreadContext*>(data);
- ctx->fTestContext->makeCurrent();
- ctx->fCCID = SkCrossContextImageData::MakeFromEncoded(ctx->fGrContext, ctx->fEncoded, nullptr);
- ctx->fSemaphore.signal();
-}
-
-DEF_GPUTEST(CrossContextImage_SharedContextOtherThread, reporter, /*factory*/) {
- sk_sp<SkImage> testImage = create_test_image();
-
- // Test both PNG and JPG, to exercise GPU YUV conversion
- for (auto format : { SkEncodedImageFormat::kPNG, SkEncodedImageFormat::kJPEG }) {
- // Use a new factory for each batch of tests. Otherwise the shared context will still be
- // current on the upload thread when we do the second iteration, and we get undefined
- // behavior.
- GrContextFactory factory;
- sk_sp<SkData> encoded = create_test_data(format);
-
- for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) {
- GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::ContextType>(i);
- if (!sk_gpu_test::GrContextFactory::IsRenderingContext(ctxType)) {
- continue;
- }
-
- // Create two GrContexts in a share group
- ContextInfo info = factory.getContextInfo(ctxType);
- if (!info.grContext()) {
- continue;
- }
- ContextInfo info2 = factory.getSharedContextInfo(info.grContext());
- if (!info2.grContext()) {
- continue;
- }
-
- // Make the first one current (on this thread) again
- info.testContext()->makeCurrent();
-
- // Bundle up data for the worker thread
- CrossContextImage_ThreadContext ctx;
- ctx.fGrContext = info2.grContext();
- ctx.fTestContext = info2.testContext();
- ctx.fEncoded = encoded;
-
- SkThread uploadThread(upload_image_thread_proc, &ctx);
- SkAssertResult(uploadThread.start());
-
- ctx.fSemaphore.wait();
- auto image = SkImage::MakeFromCrossContextImageData(info.grContext(),
- std::move(ctx.fCCID));
- REPORTER_ASSERT(reporter, image != nullptr);
-
- // JPEG encode -> decode won't round trip the image perfectly
- assert_equal(reporter, testImage.get(), image.get(),
- SkEncodedImageFormat::kJPEG == format ? 2 : 0);
-
- uploadThread.join();
- }
- }
-}
-
-#endif
diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp
index 3a11bb9..45946cf 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -212,13 +212,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();
@@ -240,46 +239,26 @@
backendTex2, kTopLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 0,
kAdopt_GrWrapOwnership));
- GrBackendTexture backendTex3 = GrTest::CreateBackendTexture(context->contextPriv().getBackend(),
- kW,
- kH,
- kRGBA_8888_GrPixelConfig,
- texHandles[2]);
- sk_sp<GrTexture> adoptedAndCached(context->resourceProvider()->wrapBackendTexture(
- backendTex3, kTopLeft_GrSurfaceOrigin, kNone_GrBackendTextureFlag, 0,
- 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);
- gpu->deleteTestingOnlyBackendTexture(texHandles[2], !adoptedAndCachedIsAlive);
}
class TestResource : public GrGpuResource {