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>
This commit is contained in:
parent
8664a1d7d7
commit
4e85e80a5a
@ -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; }
|
||||
@ -216,6 +253,9 @@ private:
|
||||
GrGLTextureInfo fGLInfo;
|
||||
#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
|
||||
@ -336,6 +390,9 @@ private:
|
||||
GrGLFramebufferInfo fGLInfo;
|
||||
#ifdef SK_VULKAN
|
||||
GrVkBackendSurfaceInfo fVkInfo;
|
||||
#endif
|
||||
#ifdef SK_METAL
|
||||
GrMtlTextureInfo fMtlInfo;
|
||||
#endif
|
||||
GrMockRenderTargetInfo fMockInfo;
|
||||
};
|
||||
|
@ -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
|
||||
|
@ -14,6 +14,9 @@
|
||||
#include "vk/GrVkTypes.h"
|
||||
#include "vk/GrVkUtil.h"
|
||||
#endif
|
||||
#ifdef SK_METAL
|
||||
#include "mtl/GrMtlTypes.h"
|
||||
#endif
|
||||
|
||||
GrBackendFormat::GrBackendFormat(GrGLenum format, GrGLenum target)
|
||||
: fBackend(kOpenGL_GrBackend)
|
||||
@ -51,6 +54,21 @@ const VkFormat* GrBackendFormat::getVkFormat() const {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SK_METAL
|
||||
GrBackendFormat::GrBackendFormat(GrMTLPixelFormat mtlFormat)
|
||||
: fBackend(kMetal_GrBackend)
|
||||
, fValid(true)
|
||||
, fMtlFormat(mtlFormat) {
|
||||
}
|
||||
|
||||
const GrMTLPixelFormat* GrBackendFormat::getMtlFormat() const {
|
||||
if (this->isValid() && kMetal_GrBackend == fBackend) {
|
||||
return &fMtlFormat;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
GrBackendFormat::GrBackendFormat(GrPixelConfig config)
|
||||
: fBackend(kMock_GrBackend)
|
||||
, fValid(true)
|
||||
@ -85,6 +103,20 @@ GrBackendTexture::GrBackendTexture(int width,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SK_METAL
|
||||
GrBackendTexture::GrBackendTexture(int width,
|
||||
int height,
|
||||
GrMipMapped mipMapped,
|
||||
const GrMtlTextureInfo& mtlInfo)
|
||||
: fIsValid(true)
|
||||
, fWidth(width)
|
||||
, fHeight(height)
|
||||
, fConfig(GrPixelConfig::kUnknown_GrPixelConfig)
|
||||
, fMipMapped(mipMapped)
|
||||
, fBackend(kMetal_GrBackend)
|
||||
, fMtlInfo(mtlInfo) {}
|
||||
#endif
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
|
||||
GrBackendTexture::GrBackendTexture(int width,
|
||||
@ -170,6 +202,7 @@ GrBackendTexture& GrBackendTexture::operator=(const GrBackendTexture& that) {
|
||||
#endif
|
||||
#ifdef SK_METAL
|
||||
case kMetal_GrBackend:
|
||||
fMtlInfo = that.fMtlInfo;
|
||||
break;
|
||||
#endif
|
||||
case kMock_GrBackend:
|
||||
@ -205,6 +238,16 @@ sk_sp<GrVkImageLayout> GrBackendTexture::getGrVkImageLayout() const {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SK_METAL
|
||||
bool GrBackendTexture::getMtlTextureInfo(GrMtlTextureInfo* outInfo) const {
|
||||
if (this->isValid() && kMetal_GrBackend == fBackend) {
|
||||
*outInfo = fMtlInfo;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool GrBackendTexture::getGLTextureInfo(GrGLTextureInfo* outInfo) const {
|
||||
if (this->isValid() && kOpenGL_GrBackend == fBackend) {
|
||||
*outInfo = fGLInfo;
|
||||
@ -246,7 +289,12 @@ bool GrBackendTexture::TestingOnly_Equals(const GrBackendTexture& t0, const GrBa
|
||||
#else
|
||||
// fall through
|
||||
#endif
|
||||
case kMetal_GrBackend: // fall through
|
||||
case kMetal_GrBackend:
|
||||
#ifdef SK_METAL
|
||||
return t0.fMtlInfo == t1.fMtlInfo;
|
||||
#else
|
||||
// fall through
|
||||
#endif
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@ -291,6 +339,21 @@ GrBackendRenderTarget::GrBackendRenderTarget(int width,
|
||||
, fVkInfo(vkInfo, layout.release()) {}
|
||||
#endif
|
||||
|
||||
#ifdef SK_METAL
|
||||
GrBackendRenderTarget::GrBackendRenderTarget(int width,
|
||||
int height,
|
||||
int sampleCnt,
|
||||
const GrMtlTextureInfo& mtlInfo)
|
||||
: fIsValid(true)
|
||||
, fWidth(width)
|
||||
, fHeight(height)
|
||||
, fSampleCnt(SkTMax(1, sampleCnt))
|
||||
, fStencilBits(0)
|
||||
, fConfig(GrPixelConfig::kUnknown_GrPixelConfig)
|
||||
, fBackend(kMetal_GrBackend)
|
||||
, fMtlInfo(mtlInfo) {}
|
||||
#endif
|
||||
|
||||
#if GR_TEST_UTILS
|
||||
|
||||
GrBackendRenderTarget::GrBackendRenderTarget(int width,
|
||||
@ -376,6 +439,7 @@ GrBackendRenderTarget& GrBackendRenderTarget::operator=(const GrBackendRenderTar
|
||||
#endif
|
||||
#ifdef SK_METAL
|
||||
case kMetal_GrBackend:
|
||||
fMtlInfo = that.fMtlInfo;
|
||||
break;
|
||||
#endif
|
||||
case kMock_GrBackend:
|
||||
@ -411,6 +475,16 @@ sk_sp<GrVkImageLayout> GrBackendRenderTarget::getGrVkImageLayout() const {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SK_METAL
|
||||
bool GrBackendRenderTarget::getMtlTextureInfo(GrMtlTextureInfo* outInfo) const {
|
||||
if (this->isValid() && kMetal_GrBackend == fBackend) {
|
||||
*outInfo = fMtlInfo;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool GrBackendRenderTarget::getGLFramebufferInfo(GrGLFramebufferInfo* outInfo) const {
|
||||
if (this->isValid() && kOpenGL_GrBackend == fBackend) {
|
||||
*outInfo = fGLInfo;
|
||||
@ -454,7 +528,12 @@ bool GrBackendRenderTarget::TestingOnly_Equals(const GrBackendRenderTarget& r0,
|
||||
#else
|
||||
// fall through
|
||||
#endif
|
||||
case kMetal_GrBackend: // fall through
|
||||
case kMetal_GrBackend:
|
||||
#ifdef SK_METAL
|
||||
return r0.fMtlInfo == r1.fMtlInfo;
|
||||
#else
|
||||
// fall through
|
||||
#endif
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -218,6 +218,8 @@ sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue, const GrContext
|
||||
if (!context->fGpu) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
context->fCaps = context->fGpu->refCaps();
|
||||
if (!context->init(options)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "GrMtlCaps.h"
|
||||
|
||||
#include "GrBackendSurface.h"
|
||||
#include "GrMtlUtil.h"
|
||||
#include "GrShaderCaps.h"
|
||||
|
||||
GrMtlCaps::GrMtlCaps(const GrContextOptions& contextOptions, const id<MTLDevice> device,
|
||||
@ -319,7 +320,11 @@ void GrMtlCaps::initConfigTable() {
|
||||
#ifdef GR_TEST_UTILS
|
||||
GrBackendFormat GrMtlCaps::onCreateFormatFromBackendTexture(
|
||||
const GrBackendTexture& backendTex) const {
|
||||
return GrBackendFormat(); // Metal BackendFormat not yet implemented.
|
||||
GrMtlTextureInfo mtlInfo;
|
||||
SkAssertResult(backendTex.getMtlTextureInfo(&mtlInfo));
|
||||
id<MTLTexture> mtlTexture = GrGetMTLTexture(mtlInfo.fTexture,
|
||||
GrWrapOwnership::kBorrow_GrWrapOwnership);
|
||||
return GrBackendFormat::MakeMtl(mtlTexture.pixelFormat);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -23,4 +23,10 @@ bool GrPixelConfigToMTLFormat(GrPixelConfig config, MTLPixelFormat* format);
|
||||
*/
|
||||
GrPixelConfig GrMTLFormatToPixelConfig(MTLPixelFormat format);
|
||||
|
||||
/**
|
||||
* Returns a id<MTLTexture> to the MTLTexture pointed at by the const void*. Will use
|
||||
* __bridge_transfer if we are adopting ownership.
|
||||
*/
|
||||
id<MTLTexture> GrGetMTLTexture(const void* mtlTexture, GrWrapOwnership);
|
||||
|
||||
#endif
|
||||
|
@ -113,3 +113,12 @@ GrPixelConfig GrMTLFormatToPixelConfig(MTLPixelFormat format) {
|
||||
return kUnknown_GrPixelConfig;
|
||||
}
|
||||
}
|
||||
|
||||
id<MTLTexture> GrGetMTLTexture(const void* mtlTexture, GrWrapOwnership wrapOwnership) {
|
||||
if (GrWrapOwnership::kAdopt_GrWrapOwnership == wrapOwnership) {
|
||||
return (__bridge_transfer id<MTLTexture>)mtlTexture;
|
||||
} else {
|
||||
return (__bridge id<MTLTexture>)mtlTexture;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user