diff options
author | Greg Daniel <egdaniel@google.com> | 2017-12-19 13:15:02 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-19 18:41:36 +0000 |
commit | faa095e9842b924c20de84dce1bcc1adad7fe2e4 (patch) | |
tree | 9651cd2720ae39bad1c364338540902b7910655c /include | |
parent | 040238bded7b932b916c84912cbaec1207aa29c0 (diff) |
Update SkSurface MakeFromBackend* factories to take an SkColorType.
Bug: skia:
Change-Id: Ib1b03b1181ec937843eac2e8d8cb03ebe53e32c1
Reviewed-on: https://skia-review.googlesource.com/86760
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkImage.h | 6 | ||||
-rw-r--r-- | include/core/SkSurface.h | 54 | ||||
-rw-r--r-- | include/gpu/GrBackendSurface.h | 18 | ||||
-rw-r--r-- | include/gpu/GrCaps.h | 11 | ||||
-rw-r--r-- | include/gpu/gl/GrGLTypes.h | 1 |
5 files changed, 77 insertions, 13 deletions
diff --git a/include/core/SkImage.h b/include/core/SkImage.h index 2a196aac41..9ebddc5c45 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -131,7 +131,7 @@ public: * 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, + * The GrBackendTexture must have a valid backend 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 @@ -152,7 +152,7 @@ public: * 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, + * The GrBackendTexture must have a valid backend 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 @@ -218,7 +218,7 @@ public: * 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, + * The GrBackendTexture must have a valid backend 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 diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index f70db73fe5..b4df88c8cf 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -99,9 +99,42 @@ public: sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* surfaceProps); + /** + * Used to wrap a pre-existing backend 3D API texture as a SkSurface. Skia will not assume + * ownership of the texture and the client must ensure the texture is valid for the lifetime + * of the SkSurface. If sampleCnt > 0, then we will create an intermediate mssa surface which + * we will use for rendering. We then resolve into the passed in texture. + * + * The GrBackendTexture must have a valid backend 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 sampleCnt, SkColorType, and SkColorSpace we + * will return nullptr. + */ + static sk_sp<SkSurface> MakeFromBackendTexture(GrContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin origin, int sampleCnt, + SkColorType colorType, + sk_sp<SkColorSpace> colorSpace, + const SkSurfaceProps* surfaceProps); + + static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext* context, + const GrBackendRenderTarget& backendRenderTarget, + GrSurfaceOrigin origin, + sk_sp<SkColorSpace> colorSpace, + const SkSurfaceProps* surfaceProps); + + /** + * The GrBackendRenderTarget must have a valid backend format set (GrGLTextureInfo::fFormat, + * GrVkImageInfo::fFormat, etc.) in it. The passed in SkColorType informs skia how it should + * interpret the backend format supplied by the GrBackendRenderTarget. If the format in the + * GrBackendRenderTarget is not compitable with the sampleCnt, SkColorType, and SkColorSpace + * we will return nullptr. + */ static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext* context, const GrBackendRenderTarget& backendRenderTarget, GrSurfaceOrigin origin, + SkColorType colorType, sk_sp<SkColorSpace> colorSpace, const SkSurfaceProps* surfaceProps); @@ -120,6 +153,27 @@ public: const SkSurfaceProps* surfaceProps); /** + * Used to wrap a pre-existing 3D API texture as a SkSurface. Skia will treat the texture as + * a rendering target only, but unlike NewFromBackendRenderTarget, Skia will manage and own + * the associated render target objects (but not the provided texture). Skia will not assume + * ownership of the texture and the client must ensure the texture is valid for the lifetime + * of the SkSurface. + * + * The GrBackendTexture must have a valid backend 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 sampleCnt, SkColorType, and SkColorSpace we + * will return nullptr. + */ + static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext* context, + const GrBackendTexture& backendTexture, + GrSurfaceOrigin origin, + int sampleCnt, + SkColorType, + sk_sp<SkColorSpace> colorSpace, + const SkSurfaceProps* surfaceProps); + + /** * Return a new surface whose contents will be drawn to an offscreen * render target, allocated by the surface. The optional shouldCreateWithMips flag is a hint * that this surface may be snapped to an SkImage which will be used with mip maps so we should diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h index 9f77155e39..f2381c2d0d 100644 --- a/include/gpu/GrBackendSurface.h +++ b/include/gpu/GrBackendSurface.h @@ -83,12 +83,10 @@ public: private: // Friending for access to the GrPixelConfig + friend class SkImage; 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; } @@ -112,6 +110,8 @@ public: // Creates an invalid backend texture. GrBackendRenderTarget() : fConfig(kUnknown_GrPixelConfig) {} + // GrGLTextureInfo::fFormat is ignored + // Deprecated: Should use version that does not take a GrPixelConfig instead GrBackendRenderTarget(int width, int height, int sampleCnt, @@ -119,6 +119,13 @@ public: GrPixelConfig config, const GrGLFramebufferInfo& glInfo); + // The GrGLTextureInfo must have a valid fFormat. + GrBackendRenderTarget(int width, + int height, + int sampleCnt, + int stencilBits, + const GrGLFramebufferInfo& glInfo); + #ifdef SK_VULKAN GrBackendRenderTarget(int width, int height, @@ -149,11 +156,10 @@ public: private: // Friending for access to the GrPixelConfig friend class SkSurface; - friend class GrCaps; + friend class SkSurface_Gpu; + friend class SkImage_Gpu; 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 59e0528a23..0d5b3403cd 100644 --- a/include/gpu/GrCaps.h +++ b/include/gpu/GrCaps.h @@ -15,6 +15,7 @@ #include "SkRefCnt.h" #include "SkString.h" +class GrBackendRenderTarget; class GrBackendTexture; struct GrContextOptions; class GrRenderTargetProxy; @@ -174,10 +175,13 @@ public: /** * 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. + * compatible, the passed in GrPixelConfig will be set to a config that matches the backend + * format and requested SkColorType. */ - bool validateBackendTexture(GrBackendTexture* tex, SkColorType ct) const; + virtual bool validateBackendTexture(const GrBackendTexture& tex, SkColorType ct, + GrPixelConfig*) const = 0; + virtual bool validateBackendRenderTarget(const GrBackendRenderTarget&, SkColorType, + GrPixelConfig*) const = 0; protected: /** Subclasses must call this at the end of their constructors in order to apply caps @@ -238,7 +242,6 @@ protected: int fMaxClipAnalyticFPs; private: - virtual bool onValidateBackendTexture(GrBackendTexture* tex, SkColorType ct) const = 0; virtual void onApplyOptionsOverrides(const GrContextOptions&) {} virtual void onDumpJSON(SkJSONWriter*) const {} diff --git a/include/gpu/gl/GrGLTypes.h b/include/gpu/gl/GrGLTypes.h index 24e50d833e..aecba3cb8e 100644 --- a/include/gpu/gl/GrGLTypes.h +++ b/include/gpu/gl/GrGLTypes.h @@ -119,6 +119,7 @@ GR_STATIC_ASSERT(sizeof(GrBackendObject) >= sizeof(const GrGLTextureInfo*)); struct GrGLFramebufferInfo { GrGLuint fFBOID; + GrGLenum fFormat = 0; }; GR_STATIC_ASSERT(sizeof(GrBackendObject) >= sizeof(const GrGLFramebufferInfo*)); |