| 1 |
/**************************************************************************/ |
| 2 |
/* godot_view_ios.mm */ |
| 3 |
/**************************************************************************/ |
| 4 |
/* This file is part of: */ |
| 5 |
/* GODOT ENGINE */ |
| 6 |
/* https://godotengine.org */ |
| 7 |
/**************************************************************************/ |
| 8 |
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 |
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 |
/* */ |
| 11 |
/* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 |
/* a copy of this software and associated documentation files (the */ |
| 13 |
/* "Software"), to deal in the Software without restriction, including */ |
| 14 |
/* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 |
/* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 |
/* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 |
/* the following conditions: */ |
| 18 |
/* */ |
| 19 |
/* The above copyright notice and this permission notice shall be */ |
| 20 |
/* included in all copies or substantial portions of the Software. */ |
| 21 |
/* */ |
| 22 |
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 |
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 |
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 |
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 |
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 |
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 |
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 |
/**************************************************************************/ |
| 30 |
|
| 31 |
#import "godot_view_ios.h" |
| 32 |
|
| 33 |
#import "display_layer_ios.h" |
| 34 |
|
| 35 |
#include "core/config/project_settings.h" |
| 36 |
#include "core/error/error_macros.h" |
| 37 |
|
| 38 |
@interface GDTViewIOS () |
| 39 |
|
| 40 |
GODOT_CLANG_WARNING_PUSH_AND_IGNORE("-Wobjc-property-synthesis") |
| 41 |
@property(strong, nonatomic) CALayer<GDTDisplayLayer> *renderingLayer; |
| 42 |
GODOT_CLANG_WARNING_POP |
| 43 |
|
| 44 |
@end |
| 45 |
|
| 46 |
@implementation GDTViewIOS |
| 47 |
|
| 48 |
- (CALayer<GDTDisplayLayer> *)initializeRenderingForDriver:(NSString *)driverName { |
| 49 |
if (self.renderingLayer) { |
| 50 |
return self.renderingLayer; |
| 51 |
} |
| 52 |
|
| 53 |
CALayer<GDTDisplayLayer> *layer; |
| 54 |
|
| 55 |
if ([driverName isEqualToString:@"vulkan"] || [driverName isEqualToString:@"metal"]) { |
| 56 |
#if defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR |
| 57 |
if (@available(iOS 13, *)) { |
| 58 |
layer = [GDTMetalLayer layer]; |
| 59 |
} else { |
| 60 |
return nil; |
| 61 |
} |
| 62 |
#else |
| 63 |
layer = [GDTMetalLayer layer]; |
| 64 |
#endif |
| 65 |
} else if ([driverName isEqualToString:@"opengl3"]) { |
| 66 |
GODOT_CLANG_WARNING_PUSH_AND_IGNORE("-Wdeprecated-declarations") // OpenGL is deprecated in iOS 12.0. |
| 67 |
layer = [GDTOpenGLLayer layer]; |
| 68 |
GODOT_CLANG_WARNING_POP |
| 69 |
} else { |
| 70 |
return nil; |
| 71 |
} |
| 72 |
|
| 73 |
layer.frame = self.bounds; |
| 74 |
layer.contentsScale = self.contentScaleFactor; |
| 75 |
|
| 76 |
[self.layer addSublayer:layer]; |
| 77 |
self.renderingLayer = layer; |
| 78 |
|
| 79 |
[layer initializeDisplayLayer]; |
| 80 |
|
| 81 |
return self.renderingLayer; |
| 82 |
} |
| 83 |
|
| 84 |
@end |
| 85 |
|
| 86 |
GDTView *GDTViewCreate() { |
| 87 |
GDTViewIOS *view = [GDTViewIOS new]; |
| 88 |
if (GLOBAL_GET("display/window/ios/allow_high_refresh_rate")) { |
| 89 |
view.preferredFrameRate = 120; |
| 90 |
} else { |
| 91 |
view.preferredFrameRate = 60; |
| 92 |
} |
| 93 |
return view; |
| 94 |
} |