From 0cf45f607cfc5d22ef9e6fbe0c7480a409349704 Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Mon, 17 Apr 2017 10:46:51 -0400 Subject: [PATCH] Split SkCrossContextImageData into Image and BackendTexture subclasses This is needed for a follow up CL where we switch from using GrBackendTextureDesc to GrBackendTexture. Bug: skia: Change-Id: Id12d3357af1cc7f30c7f9196e614089779dc0715 Reviewed-on: https://skia-review.googlesource.com/13588 Reviewed-by: Brian Osman Commit-Queue: Greg Daniel --- include/core/SkCrossContextImageData.h | 47 ++++++++++++++++++++++++++-------- include/gpu/GrExternalTextureData.h | 2 +- src/image/SkImage.cpp | 4 +-- src/image/SkImage_Gpu.cpp | 28 ++++++++++---------- 4 files changed, 53 insertions(+), 28 deletions(-) diff --git a/include/core/SkCrossContextImageData.h b/include/core/SkCrossContextImageData.h index bbee6e7..beaaaa6 100644 --- a/include/core/SkCrossContextImageData.h +++ b/include/core/SkCrossContextImageData.h @@ -32,15 +32,45 @@ public: static std::unique_ptr MakeFromEncoded( GrContext*, sk_sp, SkColorSpace* dstColorSpace); + virtual ~SkCrossContextImageData() {} + +protected: + SkCrossContextImageData() {} + private: - SkCrossContextImageData(sk_sp image) : fImage(std::move(image)) { + virtual sk_sp makeImage(GrContext*) = 0; + + friend class SkImage; +}; + +class SkCCIDImage : public SkCrossContextImageData { +public: + ~SkCCIDImage() override {} + +private: + SkCCIDImage(sk_sp image) : fImage(std::move(image)) { SkASSERT(!fImage->isTextureBacked()); } + sk_sp makeImage(GrContext*) override { + return fImage; + } + + sk_sp fImage; + + friend class SkCrossContextImageData; + friend class SkImage; +}; + #if SK_SUPPORT_GPU - SkCrossContextImageData(const GrBackendTextureDesc& desc, - std::unique_ptr textureData, - SkAlphaType alphaType, sk_sp colorSpace) +class SkCCIDBackendTexture : public SkCrossContextImageData { +public: + ~SkCCIDBackendTexture() override {} + +private: + SkCCIDBackendTexture(const GrBackendTextureDesc& desc, + std::unique_ptr textureData, + SkAlphaType alphaType, sk_sp colorSpace) : fAlphaType(alphaType) , fColorSpace(std::move(colorSpace)) , fDesc(desc) @@ -48,21 +78,18 @@ private: // Point our texture desc at our copy of the backend information fDesc.fTextureHandle = fTextureData->getBackendObject(); } -#endif - // For non-GPU backed images - sk_sp fImage; + sk_sp makeImage(GrContext*) override; -#if SK_SUPPORT_GPU // 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 fColorSpace; GrBackendTextureDesc fDesc; std::unique_ptr fTextureData; -#endif - friend class SkImage; + friend class SkCrossContextImageData; }; +#endif #endif diff --git a/include/gpu/GrExternalTextureData.h b/include/gpu/GrExternalTextureData.h index 5943fd8..0ebc053 100644 --- a/include/gpu/GrExternalTextureData.h +++ b/include/gpu/GrExternalTextureData.h @@ -21,7 +21,7 @@ protected: virtual GrBackendObject getBackendObject() const = 0; virtual void attachToContext(GrContext*) = 0; - friend class SkCrossContextImageData; + friend class SkCCIDBackendTexture; friend class SkImage; }; diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index bbe1754..9db4ed1 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -375,12 +375,12 @@ std::unique_ptr SkCrossContextImageData::MakeFromEncode return nullptr; } // TODO: Force decode to raster here? - return std::unique_ptr(new SkCrossContextImageData(std::move(image))); + return std::unique_ptr(new SkCCIDImage(std::move(image))); } sk_sp SkImage::MakeFromCrossContextImageData( GrContext*, std::unique_ptr ccid) { - return ccid->fImage; + return ccid->makeImage(nullptr); } sk_sp SkImage::makeNonTextureImage() const { diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 97a657a..932bb38 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -445,14 +445,14 @@ std::unique_ptr SkCrossContextImageData::MakeFromEncode // Some backends or drivers don't support (safely) moving resources between contexts if (!context->caps()->crossContextTextureSupport()) { return std::unique_ptr( - new SkCrossContextImageData(std::move(codecImage))); + new SkCCIDImage(std::move(codecImage))); } sk_sp textureImage = codecImage->makeTextureImage(context, dstColorSpace); if (!textureImage) { // TODO: Force decode to raster here? Do mip-mapping, like getDeferredTextureImageData? return std::unique_ptr( - new SkCrossContextImageData(std::move(codecImage))); + new SkCCIDImage(std::move(codecImage))); } // Crack open the gpu image, extract the backend data, stick it in the SkCCID @@ -472,27 +472,25 @@ std::unique_ptr SkCrossContextImageData::MakeFromEncode SkASSERT(textureData); SkImageInfo info = as_IB(textureImage)->onImageInfo(); - return std::unique_ptr(new SkCrossContextImageData( + return std::unique_ptr(new SkCCIDBackendTexture( desc, std::move(textureData), info.alphaType(), info.refColorSpace())); } -sk_sp SkImage::MakeFromCrossContextImageData( - GrContext* context, std::unique_ptr ccid) { - if (ccid->fImage) { - // No pre-existing GPU resource. We could upload it now (with makeTextureImage), - // but we'd need a dstColorSpace. - return ccid->fImage; - } - - if (ccid->fTextureData) { - ccid->fTextureData->attachToContext(context); +sk_sp 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, ccid->fDesc, ccid->fAlphaType, - std::move(ccid->fColorSpace), ownership, nullptr, nullptr); + return new_wrapped_texture_common(context, fDesc, fAlphaType, + std::move(fColorSpace), ownership, nullptr, nullptr); +} + +sk_sp SkImage::MakeFromCrossContextImageData( + GrContext* context, std::unique_ptr ccid) { + return ccid->makeImage(context); } sk_sp SkImage::makeNonTextureImage() const { -- 2.7.4