From f5d8758f29390fd5c135df12bc8a5e196854eda2 Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Mon, 18 Dec 2017 14:48:15 -0500 Subject: Add new SkImage factory to create from GrBackendTexture with SkColorType Bug: skia: Change-Id: I46bdc54b6d9cdacc8f5a06644aa6b110837879f0 Reviewed-on: https://skia-review.googlesource.com/84342 Commit-Queue: Greg Daniel Reviewed-by: Brian Salomon --- include/core/SkImage.h | 66 ++++++++++++++++++++++++++++++++++++++++++ include/gpu/GrBackendSurface.h | 6 ++++ include/gpu/GrCaps.h | 10 +++++++ 3 files changed, 82 insertions(+) (limited to 'include') diff --git a/include/core/SkImage.h b/include/core/SkImage.h index 03d463d098..2a196aac41 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -96,6 +96,9 @@ public: * managing the lifetime of the underlying platform texture. * * Will return NULL if the specified backend texture is unsupported. + * + * DEPRECATED: This factory is deprecated and clients should use the factory below which takes + * an SkColorType. */ static sk_sp MakeFromTexture(GrContext* context, const GrBackendTexture& backendTexture, @@ -112,10 +115,53 @@ public: * no longer is holding a reference to it. * * Will return NULL if the specified backend texture is unsupported. + * + * DEPRECATED: This factory is deprecated and clients should use the factory below which takes + * an SkColorType. + */ + static sk_sp MakeFromTexture(GrContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin origin, + SkAlphaType alphaType, + sk_sp colorSpace, + TextureReleaseProc textureReleaseProc, + ReleaseContext releaseContext); + + /** + * Create a new image from the specified descriptor. Note - the caller is responsible for + * managing the lifetime of the underlying platform texture. + * + * The GrBackendTexture mush have a valid backed format supplied (GrGLTextureInfo::fFormat, + * GrVkImageInfo::fFormat, etc.) in it. The passed in SkColorType informs skia how it should + * interpret the backend format supplied by the GrBackendTexture. If the format in the + * GrBackendTexture is not compitable with the SkColorType, SkAlphaType, and SkColorSpace we + * will return nullptr. + */ + static sk_sp MakeFromTexture(GrContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin origin, + SkColorType colorType, + SkAlphaType alphaType, + sk_sp colorSpace) { + return MakeFromTexture(context, backendTexture, origin, colorType, alphaType, colorSpace, + nullptr, nullptr); + } + + /** + * Create a new image from the GrBackendTexture. The underlying platform texture must stay + * valid and unaltered until the specified release-proc is invoked, indicating that Skia + * no longer is holding a reference to it. + * + * The GrBackendTexture mush have a valid backed format supplied (GrGLTextureInfo::fFormat, + * GrVkImageInfo::fFormat, etc.) in it. The passed in SkColorType informs skia how it should + * interpret the backend format supplied by the GrBackendTexture. If the format in the + * GrBackendTexture is not compitable with the SkColorType, SkAlphaType, and SkColorSpace we + * will return nullptr. */ static sk_sp MakeFromTexture(GrContext* context, const GrBackendTexture& backendTexture, GrSurfaceOrigin origin, + SkColorType colorType, SkAlphaType alphaType, sk_sp colorSpace, TextureReleaseProc textureReleaseProc, @@ -158,10 +204,30 @@ public: * texture when the image is released. * * Will return NULL if the specified backend texture is unsupported. + * + * DEPRECATED: This factory is deprecated and clients should use the factory below which takes + * an SkColorType. + */ + static sk_sp MakeFromAdoptedTexture(GrContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin surfaceOrigin, + SkAlphaType alphaType = kPremul_SkAlphaType, + sk_sp colorSpace = nullptr); + + /** + * Create a new image from the specified descriptor. Note - Skia will delete or recycle the + * texture when the image is released. + * + * The GrBackendTexture mush have a valid backed format supplied (GrGLTextureInfo::fFormat, + * GrVkImageInfo::fFormat, etc.) in it. The passed in SkColorType informs skia how it should + * interpret the backend format supplied by the GrBackendTexture. If the format in the + * GrBackendTexture is not compitable with the SkColorType, SkAlphaType, and SkColorSpace we + * will return nullptr. */ static sk_sp MakeFromAdoptedTexture(GrContext* context, const GrBackendTexture& backendTexture, GrSurfaceOrigin surfaceOrigin, + SkColorType colorType, SkAlphaType alphaType = kPremul_SkAlphaType, sk_sp colorSpace = nullptr); diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h index 1eab3577b1..9f77155e39 100644 --- a/include/gpu/GrBackendSurface.h +++ b/include/gpu/GrBackendSurface.h @@ -84,8 +84,11 @@ public: private: // Friending for access to the GrPixelConfig friend class SkSurface; + friend class GrCaps; friend class GrGpu; + friend class GrGLCaps; friend class GrGLGpu; + friend class GrVkCaps; friend class GrVkGpu; GrPixelConfig config() const { return fConfig; } @@ -146,8 +149,11 @@ public: private: // Friending for access to the GrPixelConfig friend class SkSurface; + friend class GrCaps; friend class GrGpu; + friend class GrGLCaps; friend class GrGLGpu; + friend class GrVkCaps; friend class GrVkGpu; GrPixelConfig config() const { return fConfig; } diff --git a/include/gpu/GrCaps.h b/include/gpu/GrCaps.h index 6cdc0e3ff6..59e0528a23 100644 --- a/include/gpu/GrCaps.h +++ b/include/gpu/GrCaps.h @@ -11,9 +11,11 @@ #include "../private/GrTypesPriv.h" #include "GrBlend.h" #include "GrShaderCaps.h" +#include "SkImageInfo.h" #include "SkRefCnt.h" #include "SkString.h" +class GrBackendTexture; struct GrContextOptions; class GrRenderTargetProxy; class SkJSONWriter; @@ -170,6 +172,13 @@ public: virtual bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, bool* rectsMustMatch, bool* disallowSubrect) const = 0; + /** + * Returns true if the GrBackendTexutre can we used with the supplied SkColorType. If it is + * compatible, the GrPixelConfig on the GrBackendTexture will be set to a config that matches + * the backend format and requested SkColorType. + */ + bool validateBackendTexture(GrBackendTexture* tex, SkColorType ct) const; + protected: /** Subclasses must call this at the end of their constructors in order to apply caps overrides requested by the client. Note that overrides will only reduce the caps never @@ -229,6 +238,7 @@ protected: int fMaxClipAnalyticFPs; private: + virtual bool onValidateBackendTexture(GrBackendTexture* tex, SkColorType ct) const = 0; virtual void onApplyOptionsOverrides(const GrContextOptions&) {} virtual void onDumpJSON(SkJSONWriter*) const {} -- cgit v1.2.3