From 78381ee5e0d326a6fe3e77da6e9eb5d28a3426f5 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Wed, 24 Mar 2021 11:38:56 -0400 Subject: [PATCH] Use objc_externally_retained to cut down retain/release in Metal Until we get off of ARC, these extra retains and releases can really add up in previous profiling of Metal, especially on iOS. Change-Id: Ib3aaa0b863c4469bdb6ad930395a170719c0293d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/381110 Commit-Queue: Adlai Holler Reviewed-by: Jim Van Verth Reviewed-by: Brian Salomon --- gn/gpu.gni | 1 + include/gpu/mtl/GrMtlTypes.h | 22 -------- include/private/GrMtlTypesPriv.h | 54 ++++++++++++++++++++ src/gpu/mtl/GrMtlAttachment.h | 2 +- src/gpu/mtl/GrMtlAttachment.mm | 6 ++- src/gpu/mtl/GrMtlBuffer.mm | 4 ++ src/gpu/mtl/GrMtlCaps.h | 4 +- src/gpu/mtl/GrMtlCaps.mm | 6 ++- src/gpu/mtl/GrMtlCommandBuffer.h | 4 ++ src/gpu/mtl/GrMtlCommandBuffer.mm | 3 ++ src/gpu/mtl/GrMtlDepthStencil.mm | 4 ++ src/gpu/mtl/GrMtlGpu.mm | 8 ++- src/gpu/mtl/GrMtlOpsRenderPass.mm | 4 ++ src/gpu/mtl/GrMtlPipelineState.mm | 4 ++ src/gpu/mtl/GrMtlPipelineStateBuilder.mm | 4 ++ src/gpu/mtl/GrMtlPipelineStateDataManager.mm | 4 ++ src/gpu/mtl/GrMtlRenderTarget.mm | 3 ++ src/gpu/mtl/GrMtlResourceProvider.mm | 4 ++ src/gpu/mtl/GrMtlSampler.mm | 4 ++ src/gpu/mtl/GrMtlSemaphore.mm | 4 ++ src/gpu/mtl/GrMtlTexture.mm | 3 ++ src/gpu/mtl/GrMtlTextureRenderTarget.mm | 4 ++ src/gpu/mtl/GrMtlTrampoline.mm | 4 ++ src/gpu/mtl/GrMtlUniformHandler.mm | 8 ++- src/gpu/mtl/GrMtlUtil.h | 17 +++--- src/gpu/mtl/GrMtlUtil.mm | 5 +- src/gpu/mtl/GrMtlVaryingHandler.mm | 6 +++ 27 files changed, 153 insertions(+), 43 deletions(-) create mode 100644 include/private/GrMtlTypesPriv.h diff --git a/gn/gpu.gni b/gn/gpu.gni index 98aa15b8f0..47d5a6da54 100644 --- a/gn/gpu.gni +++ b/gn/gpu.gni @@ -25,6 +25,7 @@ skia_gpu_sources = [ "$_include/private/GrContext_Base.h", "$_include/private/GrGLTypesPriv.h", "$_include/private/GrImageContext.h", + "$_include/private/GrMtlTypesPriv.h", "$_include/private/GrResourceKey.h", "$_include/private/GrSingleOwner.h", "$_include/private/GrTypesPriv.h", diff --git a/include/gpu/mtl/GrMtlTypes.h b/include/gpu/mtl/GrMtlTypes.h index 6ad2656ed8..ce00a81692 100644 --- a/include/gpu/mtl/GrMtlTypes.h +++ b/include/gpu/mtl/GrMtlTypes.h @@ -29,28 +29,6 @@ typedef const void* GrMTLHandle; #define SK_API_AVAILABLE_CA_METAL_LAYER SK_API_AVAILABLE(macos(10.11), ios(8.0)) #endif // TARGET_OS_SIMULATOR -#if defined(SK_BUILD_FOR_MAC) -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 110000 -#define GR_METAL_SDK_VERSION 230 -#elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500 -#define GR_METAL_SDK_VERSION 220 -#elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 -#define GR_METAL_SDK_VERSION 210 -#else -#error Must use at least 10.14 SDK to build Metal backend for MacOS -#endif -#else -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 || __TV_OS_VERSION_MAX_ALLOWED >= 140000 -#define GR_METAL_SDK_VERSION 230 -#elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 || __TV_OS_VERSION_MAX_ALLOWED >= 130000 -#define GR_METAL_SDK_VERSION 220 -#elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 120000 || __TV_OS_VERSION_MAX_ALLOWED >= 120000 -#define GR_METAL_SDK_VERSION 210 -#else -#error Must use at least 12.00 SDK to build Metal backend for iOS -#endif -#endif - /** * Types for interacting with Metal resources created externally to Skia. * This is used by GrBackendObjects. diff --git a/include/private/GrMtlTypesPriv.h b/include/private/GrMtlTypesPriv.h new file mode 100644 index 0000000000..ed294ba4ad --- /dev/null +++ b/include/private/GrMtlTypesPriv.h @@ -0,0 +1,54 @@ +/* + * Copyright 2021 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrMtlTypesPriv_DEFINED +#define GrMtlTypesPriv_DEFINED + +#include "include/gpu/GrTypes.h" + +/////////////////////////////////////////////////////////////////////////////// + +#ifdef __APPLE__ + +#include + +#if defined(SK_BUILD_FOR_MAC) +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 110000 +#define GR_METAL_SDK_VERSION 230 +#elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500 +#define GR_METAL_SDK_VERSION 220 +#elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 +#define GR_METAL_SDK_VERSION 210 +#else +#error Must use at least 10.14 SDK to build Metal backend for MacOS +#endif +#else +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 || __TV_OS_VERSION_MAX_ALLOWED >= 140000 +#define GR_METAL_SDK_VERSION 230 +#elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 || __TV_OS_VERSION_MAX_ALLOWED >= 130000 +#define GR_METAL_SDK_VERSION 220 +#elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 120000 || __TV_OS_VERSION_MAX_ALLOWED >= 120000 +#define GR_METAL_SDK_VERSION 210 +#else +#error Must use at least 12.00 SDK to build Metal backend for iOS +#endif +#endif + +#if __has_attribute(objc_externally_retained) +#define GR_EXTERNALLY_RETAINED __attribute__((objc_externally_retained)) +#define GR_EXTERNALLY_RETAINED_BEGIN \ + _Pragma("clang attribute push (__attribute__((objc_externally_retained)), apply_to=any(function,objc_method))") +#define GR_EXTERNALLY_RETAINED_END _Pragma("clang attribute pop") +#else +#define GR_EXTERNALLY_RETAINED +#define GR_EXTERNALLY_RETAINED_BEGIN +#define GR_EXTERNALLY_RETAINED_END +#endif + +#endif + +#endif diff --git a/src/gpu/mtl/GrMtlAttachment.h b/src/gpu/mtl/GrMtlAttachment.h index ae31e1e47c..a6a5ee1874 100644 --- a/src/gpu/mtl/GrMtlAttachment.h +++ b/src/gpu/mtl/GrMtlAttachment.h @@ -40,7 +40,7 @@ private: GrMtlAttachment(GrMtlGpu* gpu, SkISize dimensions, UsageFlags supportedUsages, - const id View); + id view); GrMtlGpu* getMtlGpu() const; diff --git a/src/gpu/mtl/GrMtlAttachment.mm b/src/gpu/mtl/GrMtlAttachment.mm index ff7f4ff1c1..6a7a67a54b 100644 --- a/src/gpu/mtl/GrMtlAttachment.mm +++ b/src/gpu/mtl/GrMtlAttachment.mm @@ -14,10 +14,12 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + GrMtlAttachment::GrMtlAttachment(GrMtlGpu* gpu, SkISize dimensions, UsageFlags supportedUsages, - const id view) + id view) : GrAttachment(gpu, dimensions, supportedUsages, view.sampleCount, GrMipmapped::kNo, GrProtected::kNo) , fView(view) { @@ -64,3 +66,5 @@ GrMtlGpu* GrMtlAttachment::getMtlGpu() const { SkASSERT(!this->wasDestroyed()); return static_cast(this->getGpu()); } + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlBuffer.mm b/src/gpu/mtl/GrMtlBuffer.mm index 293113ba9b..0180875e7b 100644 --- a/src/gpu/mtl/GrMtlBuffer.mm +++ b/src/gpu/mtl/GrMtlBuffer.mm @@ -21,6 +21,8 @@ #define VALIDATE() do {} while(false) #endif +GR_EXTERNALLY_RETAINED_BEGIN + sk_sp GrMtlBuffer::Make(GrMtlGpu* gpu, size_t size, GrGpuBufferType intendedType, GrAccessPattern accessPattern, const void* data) { sk_sp buffer(new GrMtlBuffer(gpu, size, intendedType, accessPattern)); @@ -197,3 +199,5 @@ void GrMtlBuffer::validate() const { fMappedBuffer.length <= fMtlBuffer.length); } #endif + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h index 249b0c37e7..46698c248c 100644 --- a/src/gpu/mtl/GrMtlCaps.h +++ b/src/gpu/mtl/GrMtlCaps.h @@ -104,9 +104,9 @@ public: private: void initFeatureSet(MTLFeatureSet featureSet); - void initStencilFormat(const id device); + void initStencilFormat(id device); - void initGrCaps(const id device); + void initGrCaps(id device); void initShaderCaps(); void applyDriverCorrectnessWorkarounds(const GrContextOptions&, const id); diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm index f475fa4fff..c330031877 100644 --- a/src/gpu/mtl/GrMtlCaps.mm +++ b/src/gpu/mtl/GrMtlCaps.mm @@ -26,6 +26,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + GrMtlCaps::GrMtlCaps(const GrContextOptions& contextOptions, const id device, MTLFeatureSet featureSet) : INHERITED(contextOptions) { @@ -263,7 +265,7 @@ bool GrMtlCaps::onCanCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy dst == src); } -void GrMtlCaps::initGrCaps(const id device) { +void GrMtlCaps::initGrCaps(id device) { // Max vertex attribs is the same on all devices fMaxVertexAttributes = 31; @@ -1212,3 +1214,5 @@ void GrMtlCaps::onDumpJSON(SkJSONWriter* writer) const { #else void GrMtlCaps::onDumpJSON(SkJSONWriter* writer) const { } #endif + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlCommandBuffer.h b/src/gpu/mtl/GrMtlCommandBuffer.h index 39814e79cf..10b0af8479 100644 --- a/src/gpu/mtl/GrMtlCommandBuffer.h +++ b/src/gpu/mtl/GrMtlCommandBuffer.h @@ -19,6 +19,8 @@ class GrMtlGpu; class GrMtlPipelineState; class GrMtlOpsRenderPass; +GR_EXTERNALLY_RETAINED_BEGIN + class GrMtlCommandBuffer : public SkRefCnt { public: static sk_sp Make(id queue); @@ -79,4 +81,6 @@ private: SkSTArray> fTrackedGrBuffers; }; +GR_EXTERNALLY_RETAINED_END + #endif diff --git a/src/gpu/mtl/GrMtlCommandBuffer.mm b/src/gpu/mtl/GrMtlCommandBuffer.mm index 072daf7129..0a787a7cd6 100644 --- a/src/gpu/mtl/GrMtlCommandBuffer.mm +++ b/src/gpu/mtl/GrMtlCommandBuffer.mm @@ -15,6 +15,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + sk_sp GrMtlCommandBuffer::Make(id queue) { id mtlCommandBuffer; mtlCommandBuffer = [queue commandBuffer]; @@ -140,3 +142,4 @@ void GrMtlCommandBuffer::encodeWaitForEvent(id event, uint64_t eventVa fHasWork = true; } +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlDepthStencil.mm b/src/gpu/mtl/GrMtlDepthStencil.mm index 8cb584d654..1788a4402a 100644 --- a/src/gpu/mtl/GrMtlDepthStencil.mm +++ b/src/gpu/mtl/GrMtlDepthStencil.mm @@ -13,6 +13,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + MTLStencilOperation skia_stencil_op_to_mtl(GrStencilOp op) { switch (op) { case GrStencilOp::kKeep: @@ -124,3 +126,5 @@ GrMtlDepthStencil::Key GrMtlDepthStencil::GenerateKey(const GrStencilSettings& s return depthStencilKey; } + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm index c462a6ce62..337d4369ea 100644 --- a/src/gpu/mtl/GrMtlGpu.mm +++ b/src/gpu/mtl/GrMtlGpu.mm @@ -31,6 +31,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + static bool get_feature_set(id device, MTLFeatureSet* featureSet) { // Mac OSX #ifdef SK_BUILD_FOR_MAC @@ -943,7 +945,7 @@ bool GrMtlGpu::onUpdateBackendTexture(const GrBackendTexture& backendTexture, GrMtlTextureInfo info; SkAssertResult(backendTexture.getMtlTextureInfo(&info)); - id mtlTexture = GrGetMTLTexture(info.fTexture.get()); + GR_EXTERNALLY_RETAINED id mtlTexture = GrGetMTLTexture(info.fTexture.get()); const MTLPixelFormat mtlFormat = mtlTexture.pixelFormat; @@ -1021,7 +1023,7 @@ bool GrMtlGpu::onUpdateBackendTexture(const GrBackendTexture& backendTexture, MTLOrigin origin = MTLOriginMake(0, 0, 0); GrMtlCommandBuffer* cmdBuffer = this->commandBuffer(); - id blitCmdEncoder = cmdBuffer->getBlitCommandEncoder(); + GR_EXTERNALLY_RETAINED auto blitCmdEncoder = cmdBuffer->getBlitCommandEncoder(); GrMtlBuffer* mtlBuffer = static_cast(slice.fBuffer); SkISize levelDimensions(backendTexture.dimensions()); @@ -1629,3 +1631,5 @@ void GrMtlGpu::onDumpJSON(SkJSONWriter* writer) const { writer->endObject(); } #endif + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlOpsRenderPass.mm b/src/gpu/mtl/GrMtlOpsRenderPass.mm index b4306bece2..825008fbab 100644 --- a/src/gpu/mtl/GrMtlOpsRenderPass.mm +++ b/src/gpu/mtl/GrMtlOpsRenderPass.mm @@ -20,6 +20,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + GrMtlOpsRenderPass::GrMtlOpsRenderPass(GrMtlGpu* gpu, GrRenderTarget* rt, GrSurfaceOrigin origin, const GrOpsRenderPass::LoadAndStoreInfo& colorInfo, const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo) @@ -446,3 +448,5 @@ void GrMtlOpsRenderPass::resetBufferBindings() { fBufferBindings[i].fBuffer = nil; } } + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlPipelineState.mm b/src/gpu/mtl/GrMtlPipelineState.mm index 8a07edfb54..ca33cec77f 100644 --- a/src/gpu/mtl/GrMtlPipelineState.mm +++ b/src/gpu/mtl/GrMtlPipelineState.mm @@ -21,6 +21,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + GrMtlPipelineState::SamplerBindings::SamplerBindings(GrSamplerState state, GrTexture* texture, GrMtlGpu* gpu) @@ -227,3 +229,5 @@ bool GrMtlPipelineState::doesntSampleAttachment( } return true; } + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlPipelineStateBuilder.mm b/src/gpu/mtl/GrMtlPipelineStateBuilder.mm index 0ca0d91874..714cbdc9b3 100644 --- a/src/gpu/mtl/GrMtlPipelineStateBuilder.mm +++ b/src/gpu/mtl/GrMtlPipelineStateBuilder.mm @@ -27,6 +27,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + GrMtlPipelineState* GrMtlPipelineStateBuilder::CreatePipelineState( GrMtlGpu* gpu, const GrProgramDesc& desc, const GrProgramInfo& programInfo, const GrMtlPrecompiledLibraries* precompiledLibs) { @@ -841,3 +843,5 @@ bool GrMtlPipelineStateBuilder::PrecompileShaders(GrMtlGpu* gpu, const SkData& c precompiledLibs->fRTHeight = inputs[kFragment_GrShaderType].fRTHeight; return true; } + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlPipelineStateDataManager.mm b/src/gpu/mtl/GrMtlPipelineStateDataManager.mm index 4bf27656e5..a5095ecc75 100644 --- a/src/gpu/mtl/GrMtlPipelineStateDataManager.mm +++ b/src/gpu/mtl/GrMtlPipelineStateDataManager.mm @@ -14,6 +14,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + GrMtlPipelineStateDataManager::GrMtlPipelineStateDataManager(const UniformInfoArray& uniforms, uint32_t uniformSize) : INHERITED(uniforms.count(), uniformSize) { @@ -125,3 +127,5 @@ void GrMtlPipelineStateDataManager::uploadAndBindUniformBuffers( void GrMtlPipelineStateDataManager::resetDirtyBits() { fUniformsDirty = true; } + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlRenderTarget.mm b/src/gpu/mtl/GrMtlRenderTarget.mm index d07884640b..1aa06b7e31 100644 --- a/src/gpu/mtl/GrMtlRenderTarget.mm +++ b/src/gpu/mtl/GrMtlRenderTarget.mm @@ -14,6 +14,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + // Called for wrapped non-texture render targets. GrMtlRenderTarget::GrMtlRenderTarget(GrMtlGpu* gpu, SkISize dimensions, @@ -147,3 +149,4 @@ bool GrMtlRenderTarget::completeStencilAttachment() { return true; } +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlResourceProvider.mm b/src/gpu/mtl/GrMtlResourceProvider.mm index c2a8c8f389..fd065020ca 100644 --- a/src/gpu/mtl/GrMtlResourceProvider.mm +++ b/src/gpu/mtl/GrMtlResourceProvider.mm @@ -22,6 +22,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + GrMtlResourceProvider::GrMtlResourceProvider(GrMtlGpu* gpu) : fGpu(gpu) { fPipelineStateCache.reset(new PipelineStateCache(gpu)); @@ -183,3 +185,5 @@ bool GrMtlResourceProvider::PipelineStateCache::precompileShader(const SkData& k return true; } + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlSampler.mm b/src/gpu/mtl/GrMtlSampler.mm index 33539f7752..468b986f07 100644 --- a/src/gpu/mtl/GrMtlSampler.mm +++ b/src/gpu/mtl/GrMtlSampler.mm @@ -13,6 +13,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + static inline MTLSamplerAddressMode wrap_mode_to_mtl_sampler_address( GrSamplerState::WrapMode wrapMode, const GrCaps& caps) { switch (wrapMode) { @@ -82,3 +84,5 @@ GrMtlSampler* GrMtlSampler::Create(const GrMtlGpu* gpu, GrSamplerState samplerSt GrMtlSampler::Key GrMtlSampler::GenerateKey(GrSamplerState samplerState) { return samplerState.asIndex(); } + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlSemaphore.mm b/src/gpu/mtl/GrMtlSemaphore.mm index 775752013b..e48fd61160 100644 --- a/src/gpu/mtl/GrMtlSemaphore.mm +++ b/src/gpu/mtl/GrMtlSemaphore.mm @@ -13,6 +13,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + std::unique_ptr GrMtlSemaphore::Make(GrMtlGpu* gpu) { if (@available(macOS 10.14, iOS 12.0, *)) { id event = [gpu->device() newEvent]; @@ -49,3 +51,5 @@ GrBackendSemaphore GrMtlSemaphore::backendSemaphore() const { } return backendSemaphore; } + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlTexture.mm b/src/gpu/mtl/GrMtlTexture.mm index f58fed45b5..56a9c7aea4 100644 --- a/src/gpu/mtl/GrMtlTexture.mm +++ b/src/gpu/mtl/GrMtlTexture.mm @@ -15,6 +15,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + GrMtlTexture::GrMtlTexture(GrMtlGpu* gpu, SkBudgeted budgeted, SkISize dimensions, @@ -120,3 +122,4 @@ GrBackendFormat GrMtlTexture::backendFormat() const { return GrBackendFormat::MakeMtl(fTexture.pixelFormat); } +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlTextureRenderTarget.mm b/src/gpu/mtl/GrMtlTextureRenderTarget.mm index 7d1b148887..fb41055476 100644 --- a/src/gpu/mtl/GrMtlTextureRenderTarget.mm +++ b/src/gpu/mtl/GrMtlTextureRenderTarget.mm @@ -13,6 +13,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + GrMtlTextureRenderTarget::GrMtlTextureRenderTarget(GrMtlGpu* gpu, SkBudgeted budgeted, SkISize dimensions, @@ -144,3 +146,5 @@ sk_sp GrMtlTextureRenderTarget::MakeWrappedTextureRend new GrMtlTextureRenderTarget(gpu, dimensions, texture, mipmapStatus, cacheable)); } } + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlTrampoline.mm b/src/gpu/mtl/GrMtlTrampoline.mm index 590c7a3219..6d1b67c0b8 100644 --- a/src/gpu/mtl/GrMtlTrampoline.mm +++ b/src/gpu/mtl/GrMtlTrampoline.mm @@ -13,8 +13,12 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + sk_sp GrMtlTrampoline::MakeGpu(const GrMtlBackendContext& backendContext, const GrContextOptions& options, GrDirectContext* direct) { return GrMtlGpu::Make(backendContext, options, direct); } + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlUniformHandler.mm b/src/gpu/mtl/GrMtlUniformHandler.mm index 70aaed976a..e9b6dbfa04 100644 --- a/src/gpu/mtl/GrMtlUniformHandler.mm +++ b/src/gpu/mtl/GrMtlUniformHandler.mm @@ -5,14 +5,18 @@ * found in the LICENSE file. */ +#include "src/gpu/mtl/GrMtlUniformHandler.h" + +#include "include/private/GrMtlTypesPriv.h" #include "src/gpu/GrTexture.h" #include "src/gpu/glsl/GrGLSLProgramBuilder.h" -#include "src/gpu/mtl/GrMtlUniformHandler.h" #if !__has_feature(objc_arc) #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + // TODO: this class is basically copy and pasted from GrVklUniformHandler so that we can have // some shaders working. The SkSL Metal code generator was written to work with GLSL generated for // the Ganesh Vulkan backend, so it should all work. There might be better ways to do things in @@ -316,3 +320,5 @@ void GrMtlUniformHandler::appendUniformDecls(GrShaderFlags visibility, SkString* out->appendf("%s\n};\n", uniformsString.c_str()); } } + +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlUtil.h b/src/gpu/mtl/GrMtlUtil.h index fd92ebec84..b911410aa8 100644 --- a/src/gpu/mtl/GrMtlUtil.h +++ b/src/gpu/mtl/GrMtlUtil.h @@ -11,30 +11,23 @@ #import #include "include/gpu/GrBackendSurface.h" +#include "include/private/GrMtlTypesPriv.h" #include "include/private/GrTypesPriv.h" #include "src/sksl/ir/SkSLProgram.h" -#if defined(SK_BUILD_FOR_MAC) -#if __MAC_OS_X_VERSION_MAX_ALLOWED < 101400 -#error Must use at least 10.14 SDK to build Metal backend for MacOS -#endif -#else -#if __IPHONE_OS_VERSION_MAX_ALLOWED < 120000 && __TV_OS_VERSION_MAX_ALLOWED < 120000 -#error Must use at least 12.00 SDK to build Metal backend for iOS -#endif -#endif - class GrMtlGpu; class GrSurface; +GR_EXTERNALLY_RETAINED_BEGIN + /** * Returns a id to the MTLTexture pointed at by the const void*. */ SK_ALWAYS_INLINE id GrGetMTLTexture(const void* mtlTexture) { #if __has_feature(objc_arc) + // ARC will retain when bridging from a CoreFoundation to an ObjC object return (__bridge id)mtlTexture; #else - // ARC will retain when bridging from a CoreFoundation to an ObjC object return (id) CFRetain(mtlTexture); #endif } @@ -130,4 +123,6 @@ size_t GrMtlFormatBytesPerBlock(MTLPixelFormat); int GrMtlFormatStencilBits(MTLPixelFormat); +GR_EXTERNALLY_RETAINED_END + #endif diff --git a/src/gpu/mtl/GrMtlUtil.mm b/src/gpu/mtl/GrMtlUtil.mm index 7edf111d07..10fd57f5f3 100644 --- a/src/gpu/mtl/GrMtlUtil.mm +++ b/src/gpu/mtl/GrMtlUtil.mm @@ -24,6 +24,8 @@ #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + NSError* GrCreateMtlError(NSString* description, GrMtlErrorCode errorCode) { NSDictionary* userInfo = [NSDictionary dictionaryWithObject:description forKey:NSLocalizedDescriptionKey]; @@ -430,5 +432,4 @@ const char* GrMtlFormatToStr(GrMTLPixelFormat mtlFormat) { #endif - - +GR_EXTERNALLY_RETAINED_END diff --git a/src/gpu/mtl/GrMtlVaryingHandler.mm b/src/gpu/mtl/GrMtlVaryingHandler.mm index 4a72045094..7ff95bb1b3 100644 --- a/src/gpu/mtl/GrMtlVaryingHandler.mm +++ b/src/gpu/mtl/GrMtlVaryingHandler.mm @@ -7,10 +7,14 @@ #include "src/gpu/mtl/GrMtlVaryingHandler.h" +#include "include/private/GrMtlTypesPriv.h" + #if !__has_feature(objc_arc) #error This file must be compiled with Arc. Use -fobjc-arc flag #endif +GR_EXTERNALLY_RETAINED_BEGIN + static void finalize_helper(GrMtlVaryingHandler::VarArray& vars) { int locationIndex = 0; int componentCount = 0; @@ -40,3 +44,5 @@ void GrMtlVaryingHandler::onFinalize() { finalize_helper(fFragInputs); finalize_helper(fFragOutputs); } + +GR_EXTERNALLY_RETAINED_END