/ include / QuartzCore / CAPrivate.hpp
CAPrivate.hpp
  1  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
  2  //
  3  // QuartzCore/CAPrivate.hpp
  4  //
  5  // Copyright 2020-2024 Apple Inc.
  6  //
  7  // Licensed under the Apache License, Version 2.0 (the "License");
  8  // you may not use this file except in compliance with the License.
  9  // You may obtain a copy of the License at
 10  //
 11  //     http://www.apache.org/licenses/LICENSE-2.0
 12  //
 13  // Unless required by applicable law or agreed to in writing, software
 14  // distributed under the License is distributed on an "AS IS" BASIS,
 15  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 16  // See the License for the specific language governing permissions and
 17  // limitations under the License.
 18  //
 19  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
 20  
 21  #pragma once
 22  
 23  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
 24  
 25  #include "CADefines.hpp"
 26  
 27  #include <objc/runtime.h>
 28  
 29  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
 30  
 31  #define _CA_PRIVATE_CLS(symbol) (Private::Class::s_k##symbol)
 32  #define _CA_PRIVATE_SEL(accessor) (Private::Selector::s_k##accessor)
 33  
 34  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
 35  
 36  #if defined(CA_PRIVATE_IMPLEMENTATION)
 37  
 38  #ifdef METALCPP_SYMBOL_VISIBILITY_HIDDEN
 39  #define _CA_PRIVATE_VISIBILITY __attribute__((visibility("hidden")))
 40  #else
 41  #define _CA_PRIVATE_VISIBILITY __attribute__((visibility("default")))
 42  #endif // METALCPP_SYMBOL_VISIBILITY_HIDDEN
 43  
 44  #define _CA_PRIVATE_IMPORT __attribute__((weak_import))
 45  
 46  #ifdef __OBJC__
 47  #define _CA_PRIVATE_OBJC_LOOKUP_CLASS(symbol) ((__bridge void*)objc_lookUpClass(#symbol))
 48  #define _CA_PRIVATE_OBJC_GET_PROTOCOL(symbol) ((__bridge void*)objc_getProtocol(#symbol))
 49  #else
 50  #define _CA_PRIVATE_OBJC_LOOKUP_CLASS(symbol) objc_lookUpClass(#symbol)
 51  #define _CA_PRIVATE_OBJC_GET_PROTOCOL(symbol) objc_getProtocol(#symbol)
 52  #endif // __OBJC__
 53  
 54  #define _CA_PRIVATE_DEF_CLS(symbol) void* s_k##symbol _CA_PRIVATE_VISIBILITY = _CA_PRIVATE_OBJC_LOOKUP_CLASS(symbol)
 55  #define _CA_PRIVATE_DEF_PRO(symbol) void* s_k##symbol _CA_PRIVATE_VISIBILITY = _CA_PRIVATE_OBJC_GET_PROTOCOL(symbol)
 56  #define _CA_PRIVATE_DEF_SEL(accessor, symbol) SEL s_k##accessor _CA_PRIVATE_VISIBILITY = sel_registerName(symbol)
 57  #define _CA_PRIVATE_DEF_STR(type, symbol)                \
 58      _CA_EXTERN type const CA##symbol _CA_PRIVATE_IMPORT; \
 59      type const                       CA::symbol = (nullptr != &CA##symbol) ? CA##symbol : nullptr
 60  
 61  #else
 62  
 63  #define _CA_PRIVATE_DEF_CLS(symbol) extern void* s_k##symbol
 64  #define _CA_PRIVATE_DEF_PRO(symbol) extern void* s_k##symbol
 65  #define _CA_PRIVATE_DEF_SEL(accessor, symbol) extern SEL s_k##accessor
 66  #define _CA_PRIVATE_DEF_STR(type, symbol) extern type const CA::symbol
 67  
 68  #endif // CA_PRIVATE_IMPLEMENTATION
 69  
 70  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
 71  
 72  namespace CA
 73  {
 74  namespace Private
 75  {
 76      namespace Class
 77      {
 78          _CA_PRIVATE_DEF_CLS(CAMetalLayer);
 79      } // Class
 80  } // Private
 81  } // CA
 82  
 83  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
 84  
 85  namespace CA
 86  {
 87  namespace Private
 88  {
 89      namespace Protocol
 90      {
 91  
 92          _CA_PRIVATE_DEF_PRO(CAMetalDrawable);
 93  
 94      } // Protocol
 95  } // Private
 96  } // CA
 97  
 98  //-------------------------------------------------------------------------------------------------------------------------------------------------------------
 99  
100  namespace CA
101  {
102  namespace Private
103  {
104      namespace Selector
105      {
106          _CA_PRIVATE_DEF_SEL(device,
107              "device");
108          _CA_PRIVATE_DEF_SEL(drawableSize,
109              "drawableSize");
110          _CA_PRIVATE_DEF_SEL(framebufferOnly,
111              "framebufferOnly");
112          _CA_PRIVATE_DEF_SEL(layer,
113              "layer");
114          _CA_PRIVATE_DEF_SEL(nextDrawable,
115              "nextDrawable");
116          _CA_PRIVATE_DEF_SEL(pixelFormat,
117              "pixelFormat");
118          _CA_PRIVATE_DEF_SEL(setDevice_,
119              "setDevice:");
120          _CA_PRIVATE_DEF_SEL(setDrawableSize_,
121              "setDrawableSize:");
122          _CA_PRIVATE_DEF_SEL(setFramebufferOnly_,
123              "setFramebufferOnly:");
124          _CA_PRIVATE_DEF_SEL(setPixelFormat_,
125              "setPixelFormat:");
126          _CA_PRIVATE_DEF_SEL(texture,
127              "texture");
128      } // Class
129  } // Private
130  } // CA
131  
132  //-------------------------------------------------------------------------------------------------------------------------------------------------------------