diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrBackendSurface.cpp | 83 | ||||
-rw-r--r-- | src/gpu/GrDirectContext.cpp | 2 | ||||
-rw-r--r-- | src/gpu/mtl/GrMtlCaps.mm | 7 | ||||
-rw-r--r-- | src/gpu/mtl/GrMtlUtil.h | 6 | ||||
-rw-r--r-- | src/gpu/mtl/GrMtlUtil.mm | 9 |
5 files changed, 104 insertions, 3 deletions
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp index d68b42a9ba..9977555093 100644 --- a/src/gpu/GrBackendSurface.cpp +++ b/src/gpu/GrBackendSurface.cpp @@ -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; } diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp index d0406dd6f6..83e2194003 100644 --- a/src/gpu/GrDirectContext.cpp +++ b/src/gpu/GrDirectContext.cpp @@ -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; } diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm index a1ecf08c35..1bb3fb26bf 100644 --- a/src/gpu/mtl/GrMtlCaps.mm +++ b/src/gpu/mtl/GrMtlCaps.mm @@ -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 diff --git a/src/gpu/mtl/GrMtlUtil.h b/src/gpu/mtl/GrMtlUtil.h index e53a8f5ee8..656b65cd6d 100644 --- a/src/gpu/mtl/GrMtlUtil.h +++ b/src/gpu/mtl/GrMtlUtil.h @@ -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 diff --git a/src/gpu/mtl/GrMtlUtil.mm b/src/gpu/mtl/GrMtlUtil.mm index 3c5df209c4..3bd3b280a5 100644 --- a/src/gpu/mtl/GrMtlUtil.mm +++ b/src/gpu/mtl/GrMtlUtil.mm @@ -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; + } +} + |