1 2 /* 3 * Copyright 2016 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 #ifndef WindowContextFactory_mac_DEFINED 10 #define WindowContextFactory_mac_DEFINED 11 12 #include "tools/sk_app/WindowContext.h" 13 14 #include <Cocoa/Cocoa.h> 15 16 #include <memory> 17 18 namespace sk_app { 19 20 struct DisplayParams; 21 GetBackingScaleFactor(NSView * view)22static inline CGFloat GetBackingScaleFactor(NSView* view) { 23 #ifdef SK_BUILD_FOR_IOS 24 UIScreen* screen = view.window.screen ?: [UIScreen mainScreen]; 25 return screen.nativeScale; 26 #else 27 NSScreen* screen = view.window.screen ?: [NSScreen mainScreen]; 28 return screen.backingScaleFactor; 29 #endif 30 } 31 32 namespace window_context_factory { 33 34 struct MacWindowInfo { 35 NSView* fMainView; 36 }; 37 38 #ifdef SK_VULKAN MakeVulkanForMac(const MacWindowInfo &,const DisplayParams &)39inline std::unique_ptr<WindowContext> MakeVulkanForMac(const MacWindowInfo&, const DisplayParams&) { 40 // No Vulkan support on Mac. 41 return nullptr; 42 } 43 #endif 44 45 #ifdef SK_GL 46 std::unique_ptr<WindowContext> MakeRasterForMac(const MacWindowInfo&, const DisplayParams&); 47 std::unique_ptr<WindowContext> MakeGLForMac(const MacWindowInfo&, const DisplayParams&); 48 #endif 49 50 #ifdef SK_DAWN 51 std::unique_ptr<WindowContext> MakeDawnMTLForMac(const MacWindowInfo&, const DisplayParams&); 52 #endif 53 54 #ifdef SK_METAL 55 std::unique_ptr<WindowContext> MakeMetalForMac(const MacWindowInfo&, const DisplayParams&); 56 #endif 57 58 } // namespace window_context_factory 59 60 } // namespace sk_app 61 62 #endif 63