diff options
author | Timothy Liang <timliang@google.com> | 2018-06-28 16:37:18 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-06-29 13:32:17 +0000 |
commit | 4e85e80a5a32f11b850830f7bf6ee45ca195d137 (patch) | |
tree | 1b64d8594d3836b578bf1aead7101257cb8b1117 /include | |
parent | 8664a1d7d719153e8e854ff0112519d92916cfe2 (diff) |
added Metal support to GrBackendSurface
Bug: skia:
Change-Id: I58c7307f41df4694b0b46014bedd681adefed265
Reviewed-on: https://skia-review.googlesource.com/137891
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Timothy Liang <timliang@google.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/gpu/GrBackendSurface.h | 61 | ||||
-rw-r--r-- | include/gpu/mtl/GrMtlTypes.h | 20 |
2 files changed, 77 insertions, 4 deletions
diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h index 65ed6d086a..7f05bb50ee 100644 --- a/include/gpu/GrBackendSurface.h +++ b/include/gpu/GrBackendSurface.h @@ -19,6 +19,10 @@ class GrVkImageLayout; #endif +#ifdef SK_METAL +#include "mtl/GrMtlTypes.h" +#endif + #if !SK_SUPPORT_GPU // SkSurface and SkImage rely on a minimal version of these always being available @@ -52,6 +56,12 @@ public: } #endif +#ifdef SK_METAL + static GrBackendFormat MakeMtl(GrMTLPixelFormat format) { + return GrBackendFormat(format); + } +#endif + static GrBackendFormat MakeMock(GrPixelConfig config) { return GrBackendFormat(config); } @@ -69,6 +79,12 @@ public: const VkFormat* getVkFormat() const; #endif +#ifdef SK_METAL + // If the backend API is Metal, this returns a pointer to a GrMTLPixelFormat. Otherwise + // it returns nullptr + const GrMTLPixelFormat* getMtlFormat() const; +#endif + // If the backend API is Mock, this returns a pointer to a GrPixelConfig. Otherwise // it returns nullptr. const GrPixelConfig* getMockFormat() const; @@ -83,6 +99,10 @@ private: GrBackendFormat(const VkFormat vkFormat); #endif +#ifdef SK_METAL + GrBackendFormat(const GrMTLPixelFormat mtlFormat); +#endif + GrBackendFormat(const GrPixelConfig config); GrBackend fBackend; @@ -94,9 +114,12 @@ private: GrGLenum fFormat; // the sized, internal format of the GL resource } fGL; #ifdef SK_VULKAN - VkFormat fVkFormat; + VkFormat fVkFormat; #endif - GrPixelConfig fMockFormat; +#ifdef SK_METAL + GrMTLPixelFormat fMtlFormat; +#endif + GrPixelConfig fMockFormat; }; }; @@ -134,6 +157,13 @@ public: const GrVkImageInfo& vkInfo); #endif +#ifdef SK_METAL + GrBackendTexture(int width, + int height, + GrMipMapped, + const GrMtlTextureInfo& mtlInfo); +#endif + GrBackendTexture(int width, int height, GrMipMapped, @@ -165,6 +195,12 @@ public: void setVkImageLayout(VkImageLayout); #endif +#ifdef SK_METAL + // If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed + // in pointer and returns true. Otherwise returns false if the backend API is not Metal. + bool getMtlTextureInfo(GrMtlTextureInfo*) const; +#endif + // If the backend API is Mock, copies a snapshot of the GrMockTextureInfo struct into the passed // in pointer and returns true. Otherwise returns false if the backend API is not Mock. bool getMockTextureInfo(GrMockTextureInfo*) const; @@ -187,6 +223,7 @@ private: friend class GrGpu; friend class GrGLGpu; friend class GrVkGpu; + friend class GrMtlGpu; friend class PromiseImageHelper; GrPixelConfig config() const { return fConfig; } @@ -217,6 +254,9 @@ private: #ifdef SK_VULKAN GrVkBackendSurfaceInfo fVkInfo; #endif +#ifdef SK_METAL + GrMtlTextureInfo fMtlInfo; +#endif GrMockTextureInfo fMockInfo; }; }; @@ -254,6 +294,13 @@ public: GrBackendRenderTarget(int width, int height, int sampleCnt, const GrVkImageInfo& vkInfo); #endif +#ifdef SK_METAL + GrBackendRenderTarget(int width, + int height, + int sampleCnt, + const GrMtlTextureInfo& mtlInfo); +#endif + GrBackendRenderTarget(int width, int height, int sampleCnt, @@ -286,6 +333,12 @@ public: void setVkImageLayout(VkImageLayout); #endif +#ifdef SK_METAL + // If the backend API is Metal, copies a snapshot of the GrMtlTextureInfo struct into the passed + // in pointer and returns true. Otherwise returns false if the backend API is not Metal. + bool getMtlTextureInfo(GrMtlTextureInfo*) const; +#endif + // If the backend API is Mock, copies a snapshot of the GrMockTextureInfo struct into the passed // in pointer and returns true. Otherwise returns false if the backend API is not Mock. bool getMockRenderTargetInfo(GrMockRenderTargetInfo*) const; @@ -308,6 +361,7 @@ private: friend class GrGLGpu; friend class GrProxyProvider; friend class GrVkGpu; + friend class GrMtlGpu; GrPixelConfig config() const { return fConfig; } #ifdef SK_VULKAN @@ -337,6 +391,9 @@ private: #ifdef SK_VULKAN GrVkBackendSurfaceInfo fVkInfo; #endif +#ifdef SK_METAL + GrMtlTextureInfo fMtlInfo; +#endif GrMockRenderTargetInfo fMockInfo; }; }; diff --git a/include/gpu/mtl/GrMtlTypes.h b/include/gpu/mtl/GrMtlTypes.h index fa88cf06f0..8b973f717e 100644 --- a/include/gpu/mtl/GrMtlTypes.h +++ b/include/gpu/mtl/GrMtlTypes.h @@ -10,7 +10,23 @@ #include "GrTypes.h" -// This is a placeholder class until we fill it out. This is needed so we can have the mtl include -// path in our BUILD.gn +/** + * Declares typedefs for Metal types used in Ganesh cpp code + */ +typedef unsigned int GrMTLPixelFormat; + +/////////////////////////////////////////////////////////////////////////////// +/** + * Types for interacting with Metal resources created externally to Skia. Holds the MTLTexture as a + * const void*. This is used by GrBackendObjects. + */ +struct GrMtlTextureInfo { +public: + const void* fTexture; // Pointer to MTLTexture + + bool operator==(const GrMtlTextureInfo& that) const { + return fTexture == that.fTexture; + } +}; #endif |