MetalKitPrivate.hpp
1 /* 2 * 3 * Copyright 2020-2021 Apple Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 19 // 20 // MetalKit/MetalKitPrivate.hpp 21 // 22 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 23 24 #pragma once 25 26 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 27 28 #include <objc/runtime.h> 29 30 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 31 32 #define _MTK_PRIVATE_CLS( symbol ) ( Private::Class::s_k ## symbol ) 33 #define _MTK_PRIVATE_SEL( accessor ) ( Private::Selector::s_k ## accessor ) 34 35 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 36 37 #if defined( MTK_PRIVATE_IMPLEMENTATION ) 38 39 #define _MTK_PRIVATE_VISIBILITY __attribute__( ( visibility( "default" ) ) ) 40 #define _MTK_PRIVATE_IMPORT __attribute__( ( weak_import ) ) 41 42 #if __OBJC__ 43 #define _MTK_PRIVATE_OBJC_LOOKUP_CLASS( symbol ) ( ( __bridge void* ) objc_lookUpClass( # symbol ) ) 44 #else 45 #define _MTK_PRIVATE_OBJC_LOOKUP_CLASS( symbol ) objc_lookUpClass( # symbol ) 46 #endif // __OBJC__ 47 48 #define _MTK_PRIVATE_DEF_CLS( symbol ) void* s_k ## symbol _MTK_PRIVATE_VISIBILITY = _MTK_PRIVATE_OBJC_LOOKUP_CLASS( symbol ); 49 #define _MTK_PRIVATE_DEF_SEL( accessor, symbol ) SEL s_k ## accessor _MTK_PRIVATE_VISIBILITY = sel_registerName( symbol ); 50 #define _MTK_PRIVATE_DEF_CONST( type, symbol ) _NS_EXTERN type const MTK ## symbo _MTK_PRIVATE_IMPORT; \ 51 type const MTK::symbol = ( nullptr != &MTK ## symbol ) ? MTK ## symbol : nullptr; 52 53 54 #else 55 56 #define _MTK_PRIVATE_DEF_CLS( symbol ) extern void* s_k ## symbol; 57 #define _MTK_PRIVATE_DEF_SEL( accessor, symbol ) extern SEL s_k ## accessor; 58 #define _MTK_PRIVATE_DEF_CONST( type, symbol ) 59 60 61 #endif // MTK_PRIVATE_IMPLEMENTATION 62 63 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 64 65 namespace MTK::Private::Class { 66 67 _MTK_PRIVATE_DEF_CLS( MTKView ); 68 69 } // Class 70 71 //------------------------------------------------------------------------------------------------------------------------------------------------------------- 72 73 namespace MTK::Private::Selector 74 { 75 76 _MTK_PRIVATE_DEF_SEL( autoresizeDrawable, 77 "autoresizeDrawable" ); 78 79 _MTK_PRIVATE_DEF_SEL( clearColor, 80 "clearColor" ); 81 82 _MTK_PRIVATE_DEF_SEL( clearDepth, 83 "clearDepth" ); 84 85 _MTK_PRIVATE_DEF_SEL( clearStencil, 86 "clearStencil" ); 87 88 _MTK_PRIVATE_DEF_SEL( colorPixelFormat, 89 "colorPixelFormat" ); 90 91 _MTK_PRIVATE_DEF_SEL( colorspace, 92 "colorspace" ); 93 94 _MTK_PRIVATE_DEF_SEL( currentDrawable, 95 "currentDrawable" ); 96 97 _MTK_PRIVATE_DEF_SEL( currentRenderPassDescriptor, 98 "currentRenderPassDescriptor" ); 99 100 _MTK_PRIVATE_DEF_SEL( device, 101 "device" ); 102 103 _MTK_PRIVATE_DEF_SEL( delegate, 104 "delegate" ); 105 106 _MTK_PRIVATE_DEF_SEL( depthStencilAttachmentTextureUsage, 107 "depthStencilAttachmentTextureUsage" ); 108 109 _MTK_PRIVATE_DEF_SEL( depthStencilPixelFormat, 110 "depthStencilPixelFormat" ); 111 112 _MTK_PRIVATE_DEF_SEL( depthStencilTexture, 113 "depthStencilTexture" ); 114 115 _MTK_PRIVATE_DEF_SEL( draw, 116 "draw" ); 117 118 _MTK_PRIVATE_DEF_SEL( drawableSize, 119 "drawableSize" ); 120 121 _MTK_PRIVATE_DEF_SEL( drawInMTKView_, 122 "drawInMTKView:" ); 123 124 _MTK_PRIVATE_DEF_SEL( enableSetNeedsDisplay, 125 "enableSetNeedsDisplay" ); 126 127 _MTK_PRIVATE_DEF_SEL( framebufferOnly, 128 "framebufferOnly" ); 129 130 _MTK_PRIVATE_DEF_SEL( initWithCoder_, 131 "initWithCoder:" ); 132 133 _MTK_PRIVATE_DEF_SEL( initWithFrame_device_, 134 "initWithFrame:device:" ); 135 136 _MTK_PRIVATE_DEF_SEL( multisampleColorAttachmentTextureUsage, 137 "multisampleColorAttachmentTextureUsage" ); 138 139 _MTK_PRIVATE_DEF_SEL( multisampleColorTexture, 140 "multisampleColorTexture" ); 141 142 _MTK_PRIVATE_DEF_SEL( isPaused, 143 "isPaused" ); 144 145 _MTK_PRIVATE_DEF_SEL( preferredFramesPerSecond, 146 "preferredFramesPerSecond" ); 147 148 _MTK_PRIVATE_DEF_SEL( preferredDevice, 149 "preferredDevice" ); 150 151 _MTK_PRIVATE_DEF_SEL( preferredDrawableSize, 152 "preferredDrawableSize" ); 153 154 _MTK_PRIVATE_DEF_SEL( presentsWithTransaction, 155 "presentsWithTransaction" ); 156 157 _MTK_PRIVATE_DEF_SEL( sampleCount, 158 "sampleCount" ); 159 160 _MTK_PRIVATE_DEF_SEL( setAutoresizeDrawable_, 161 "setAutoresizeDrawable:" ); 162 163 _MTK_PRIVATE_DEF_SEL( setClearColor_, 164 "setClearColor:" ); 165 166 _MTK_PRIVATE_DEF_SEL( setClearDepth_, 167 "setClearDepth:" ); 168 169 _MTK_PRIVATE_DEF_SEL( setClearStencil_, 170 "setClearStencil:" ); 171 172 _MTK_PRIVATE_DEF_SEL( setColorPixelFormat_, 173 "setColorPixelFormat:" ); 174 175 _MTK_PRIVATE_DEF_SEL( setColorspace_, 176 "setColorspace:" ); 177 178 _MTK_PRIVATE_DEF_SEL( setDelegate_, 179 "setDelegate:" ); 180 181 _MTK_PRIVATE_DEF_SEL( setDepthStencilAttachmentTextureUsage_, 182 "setDepthStencilAttachmentTextureUsage:" ); 183 184 _MTK_PRIVATE_DEF_SEL( setDepthStencilPixelFormat_, 185 "setDepthStencilPixelFormat:" ); 186 187 _MTK_PRIVATE_DEF_SEL( setDevice_, 188 "setDevice:" ); 189 190 _MTK_PRIVATE_DEF_SEL( setDrawableSize_, 191 "setDrawableSize:" ); 192 193 _MTK_PRIVATE_DEF_SEL( setEnableSetNeedsDisplay_, 194 "setEnableSetNeedsDisplay:" ); 195 196 _MTK_PRIVATE_DEF_SEL( setFramebufferOnly_, 197 "setFramebufferOnly:" ); 198 199 _MTK_PRIVATE_DEF_SEL( setMultisampleColorAttachmentTextureUsage_, 200 "setMultisampleColorAttachmentTextureUsage:" ) 201 202 _MTK_PRIVATE_DEF_SEL( setPaused_, 203 "setPaused:" ); 204 205 _MTK_PRIVATE_DEF_SEL( setPreferredFramesPerSecond_, 206 "setPreferredFramesPerSecond:" ); 207 208 _MTK_PRIVATE_DEF_SEL( setPresentsWithTransaction_, 209 "setPresentsWithTransaction:" ); 210 211 _MTK_PRIVATE_DEF_SEL( setSampleCount_, 212 "setSampleCount:" ); 213 214 _MTK_PRIVATE_DEF_SEL( releaseDrawables, 215 "releaseDrawables" ); 216 217 } 218 219 //--------- 220