forked from RavEngine/RavEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppleUtilities.mm
58 lines (52 loc) · 1.47 KB
/
AppleUtilities.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "AppleUtilities.h"
#import <QuartzCore/CAMetalLayer.h>
#import <Metal/Metal.h>
#import <MetalKit/MetalKit.h>
#include <bx/bx.h>
#include <SDL_syswm.h>
#include "Debug.hpp"
#if BX_PLATFORM_OSX
#import <Cocoa/Cocoa.h>
#elif BX_PLATFORM_IOS
#import <UIKit/UIKit.h>
#endif
/**
Workaround for deadlock on metal
*/
void *cbSetupMetalLayer(void *wnd) {
#if BX_PLATFORM_OSX
NSWindow *window = (NSWindow*)wnd;
NSView *contentView = [window contentView];
[contentView setWantsLayer:YES];
CAMetalLayer *res = [CAMetalLayer layer];
[contentView setLayer:res];
return res;
#elif BX_PLATFORM_IOS
UIWindow* window = (UIWindow*)wnd;
UIView* contentView = [[window subviews] lastObject];
CAMetalLayer *res = [CAMetalLayer layer];
res.frame = window.bounds;
[contentView.layer addSublayer:res];
return res;
#endif
}
void resizeMetalLayer(void* ptr, int width, int height){
CAMetalLayer* layer = (CAMetalLayer*)ptr;
layer.frame = CGRectMake(0, 0, width, height);
}
float GetWindowScaleFactor(void* window){
SDL_SysWMinfo wmi;
SDL_VERSION(&wmi.version);
if (!SDL_GetWindowWMInfo((SDL_Window*)window, &wmi)) {
RavEngine::Debug::Fatal("Cannot get native window information");
}
#if BX_PLATFORM_OSX
NSWindow *nswin = (NSWindow*)wmi.info.cocoa.window;
return [nswin backingScaleFactor];
#elif BX_PLATFORM_IOS
return wmi.info.uikit.window.screen.scale;
#endif
}
void enableSmoothScrolling(){
[[NSUserDefaults standardUserDefaults] setBool: YES forKey: @"AppleMomentumScrollSupported"];
}