Skip to content

Latest commit

 

History

History
299 lines (251 loc) · 9.84 KB

SDL_uikitvideo.m

File metadata and controls

299 lines (251 loc) · 9.84 KB
 
1
2
/*
Simple DirectMedia Layer
Jan 17, 2020
Jan 17, 2020
3
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
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
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_UIKIT
#import <UIKit/UIKit.h>
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_hints.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
#include "SDL_uikitvideo.h"
#include "SDL_uikitevents.h"
#include "SDL_uikitmodes.h"
#include "SDL_uikitwindow.h"
#include "SDL_uikitopengles.h"
Feb 4, 2016
Feb 4, 2016
39
#include "SDL_uikitclipboard.h"
Aug 28, 2017
Aug 28, 2017
40
#include "SDL_uikitvulkan.h"
Aug 5, 2019
Aug 5, 2019
41
#include "SDL_uikitmetalview.h"
42
43
44
#define UIKITVID_DRIVER_NAME "uikit"
Feb 4, 2016
Feb 4, 2016
45
46
47
48
@implementation SDL_VideoData
@end
49
50
51
52
53
54
55
56
/* Initialization/Query functions */
static int UIKit_VideoInit(_THIS);
static void UIKit_VideoQuit(_THIS);
/* DUMMY driver bootstrap functions */
static void UIKit_DeleteDevice(SDL_VideoDevice * device)
{
Feb 4, 2016
Feb 4, 2016
57
58
59
60
@autoreleasepool {
CFRelease(device->driverdata);
SDL_free(device);
}
61
62
63
64
65
}
static SDL_VideoDevice *
UIKit_CreateDevice(int devindex)
{
Feb 4, 2016
Feb 4, 2016
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
@autoreleasepool {
SDL_VideoDevice *device;
SDL_VideoData *data;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (device) {
data = [SDL_VideoData new];
} else {
SDL_free(device);
SDL_OutOfMemory();
return (0);
}
device->driverdata = (void *) CFBridgingRetain(data);
/* Set the function pointers */
device->VideoInit = UIKit_VideoInit;
device->VideoQuit = UIKit_VideoQuit;
device->GetDisplayModes = UIKit_GetDisplayModes;
device->SetDisplayMode = UIKit_SetDisplayMode;
device->PumpEvents = UIKit_PumpEvents;
device->SuspendScreenSaver = UIKit_SuspendScreenSaver;
Aug 28, 2017
Aug 28, 2017
89
device->CreateSDLWindow = UIKit_CreateWindow;
Feb 4, 2016
Feb 4, 2016
90
91
92
93
94
95
96
97
98
device->SetWindowTitle = UIKit_SetWindowTitle;
device->ShowWindow = UIKit_ShowWindow;
device->HideWindow = UIKit_HideWindow;
device->RaiseWindow = UIKit_RaiseWindow;
device->SetWindowBordered = UIKit_SetWindowBordered;
device->SetWindowFullscreen = UIKit_SetWindowFullscreen;
device->DestroyWindow = UIKit_DestroyWindow;
device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
device->GetDisplayUsableBounds = UIKit_GetDisplayUsableBounds;
Mar 28, 2020
Mar 28, 2020
99
device->GetDisplayDPI = UIKit_GetDisplayDPI;
Feb 4, 2016
Feb 4, 2016
100
Aug 28, 2017
Aug 28, 2017
101
#if SDL_IPHONE_KEYBOARD
Feb 4, 2016
Feb 4, 2016
102
103
104
105
106
device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
device->ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
device->HideScreenKeyboard = UIKit_HideScreenKeyboard;
device->IsScreenKeyboardShown = UIKit_IsScreenKeyboardShown;
device->SetTextInputRect = UIKit_SetTextInputRect;
Aug 28, 2017
Aug 28, 2017
107
#endif
Feb 4, 2016
Feb 4, 2016
108
109
110
111
112
113
device->SetClipboardText = UIKit_SetClipboardText;
device->GetClipboardText = UIKit_GetClipboardText;
device->HasClipboardText = UIKit_HasClipboardText;
/* OpenGL (ES) functions */
Dec 4, 2019
Dec 4, 2019
114
#if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
Feb 4, 2016
Feb 4, 2016
115
116
117
118
119
120
121
device->GL_MakeCurrent = UIKit_GL_MakeCurrent;
device->GL_GetDrawableSize = UIKit_GL_GetDrawableSize;
device->GL_SwapWindow = UIKit_GL_SwapWindow;
device->GL_CreateContext = UIKit_GL_CreateContext;
device->GL_DeleteContext = UIKit_GL_DeleteContext;
device->GL_GetProcAddress = UIKit_GL_GetProcAddress;
device->GL_LoadLibrary = UIKit_GL_LoadLibrary;
Dec 4, 2019
Dec 4, 2019
122
#endif
Feb 4, 2016
Feb 4, 2016
123
124
device->free = UIKit_DeleteDevice;
Aug 28, 2017
Aug 28, 2017
125
#if SDL_VIDEO_VULKAN
Aug 28, 2017
Aug 28, 2017
126
127
128
129
130
131
device->Vulkan_LoadLibrary = UIKit_Vulkan_LoadLibrary;
device->Vulkan_UnloadLibrary = UIKit_Vulkan_UnloadLibrary;
device->Vulkan_GetInstanceExtensions
= UIKit_Vulkan_GetInstanceExtensions;
device->Vulkan_CreateSurface = UIKit_Vulkan_CreateSurface;
device->Vulkan_GetDrawableSize = UIKit_Vulkan_GetDrawableSize;
Aug 28, 2017
Aug 28, 2017
132
#endif
Aug 28, 2017
Aug 28, 2017
133
Aug 5, 2019
Aug 5, 2019
134
135
136
#if SDL_VIDEO_METAL
device->Metal_CreateView = UIKit_Metal_CreateView;
device->Metal_DestroyView = UIKit_Metal_DestroyView;
Apr 10, 2020
Apr 10, 2020
137
138
device->Metal_GetLayer = UIKit_Metal_GetLayer;
device->Metal_GetDrawableSize = UIKit_Metal_GetDrawableSize;
Aug 5, 2019
Aug 5, 2019
139
140
#endif
Feb 4, 2016
Feb 4, 2016
141
142
143
device->gl_config.accelerated = 1;
return device;
144
145
146
147
148
}
}
VideoBootStrap UIKIT_bootstrap = {
UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
Jul 12, 2020
Jul 12, 2020
149
UIKit_CreateDevice
150
151
152
153
154
155
156
157
158
159
160
};
int
UIKit_VideoInit(_THIS)
{
_this->gl_config.driver_loaded = 1;
if (UIKit_InitModes(_this) < 0) {
return -1;
}
Oct 15, 2020
Oct 15, 2020
161
162
163
164
SDL_InitGCKeyboard();
SDL_InitGCMouse();
165
166
167
168
169
170
return 0;
}
void
UIKit_VideoQuit(_THIS)
{
Oct 15, 2020
Oct 15, 2020
171
172
173
SDL_QuitGCKeyboard();
SDL_QuitGCMouse();
174
175
176
177
178
179
180
181
182
UIKit_QuitModes(_this);
}
void
UIKit_SuspendScreenSaver(_THIS)
{
@autoreleasepool {
/* Ignore ScreenSaver API calls if the idle timer hint has been set. */
/* FIXME: The idle timer hint should be deprecated for SDL 2.1. */
Oct 8, 2016
Oct 8, 2016
183
if (!SDL_GetHintBoolean(SDL_HINT_IDLE_TIMER_DISABLED, SDL_FALSE)) {
184
185
186
187
188
189
190
191
UIApplication *app = [UIApplication sharedApplication];
/* Prevent the display from dimming and going to sleep. */
app.idleTimerDisabled = (_this->suspend_screensaver != SDL_FALSE);
}
}
}
Sep 25, 2016
Sep 25, 2016
192
SDL_bool
193
194
195
196
197
198
199
200
UIKit_IsSystemVersionAtLeast(double version)
{
return [[UIDevice currentDevice].systemVersion doubleValue] >= version;
}
CGRect
UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
{
Aug 15, 2019
Aug 15, 2019
201
SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
Aug 19, 2017
Aug 19, 2017
202
203
CGRect frame = screen.bounds;
Aug 15, 2019
Aug 15, 2019
204
205
206
207
208
209
210
/* Use the UIWindow bounds instead of the UIScreen bounds, when possible.
* The uiwindow bounds may be smaller than the screen bounds when Split View
* is used on an iPad. */
if (data != nil && data.uiwindow != nil) {
frame = data.uiwindow.bounds;
}
Sep 14, 2016
Sep 14, 2016
211
#if !TARGET_OS_TV && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0)
212
213
BOOL hasiOS7 = UIKit_IsSystemVersionAtLeast(7.0);
Aug 16, 2017
Aug 16, 2017
214
215
/* The view should always show behind the status bar in iOS 7+. */
if (!hasiOS7 && !(window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN))) {
Aug 19, 2017
Aug 19, 2017
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
frame = screen.applicationFrame;
}
#endif
#if !TARGET_OS_TV
/* iOS 10 seems to have a bug where, in certain conditions, putting the
* device to sleep with the a landscape-only app open, re-orienting the
* device to portrait, and turning it back on will result in the screen
* bounds returning portrait orientation despite the app being in landscape.
* This is a workaround until a better solution can be found.
* https://bugzilla.libsdl.org/show_bug.cgi?id=3505
* https://bugzilla.libsdl.org/show_bug.cgi?id=3465
* https://forums.developer.apple.com/thread/65337 */
if (UIKit_IsSystemVersionAtLeast(8.0)) {
UIInterfaceOrientation orient = [UIApplication sharedApplication].statusBarOrientation;
Aug 15, 2019
Aug 15, 2019
231
232
BOOL landscape = UIInterfaceOrientationIsLandscape(orient);
BOOL fullscreen = CGRectEqualToRect(screen.bounds, frame);
Aug 19, 2017
Aug 19, 2017
233
Aug 15, 2019
Aug 15, 2019
234
235
236
/* The orientation flip doesn't make sense when the window is smaller
* than the screen (iPad Split View, for example). */
if (fullscreen && (landscape != (frame.size.width > frame.size.height))) {
Aug 19, 2017
Aug 19, 2017
237
238
239
240
float height = frame.size.width;
frame.size.width = frame.size.height;
frame.size.height = height;
}
Sep 14, 2016
Sep 14, 2016
242
#endif
Aug 16, 2017
Aug 16, 2017
243
Aug 19, 2017
Aug 19, 2017
244
return frame;
Jun 9, 2019
Jun 9, 2019
247
248
249
250
251
252
253
254
255
void
UIKit_ForceUpdateHomeIndicator()
{
#if !TARGET_OS_TV
/* Force the main SDL window to re-evaluate home indicator state */
SDL_Window *focus = SDL_GetFocusWindow();
if (focus) {
SDL_WindowData *data = (__bridge SDL_WindowData *) focus->driverdata;
if (data != nil) {
Jun 14, 2019
Jun 14, 2019
256
257
258
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
if ([data.viewcontroller respondsToSelector:@selector(setNeedsUpdateOfHomeIndicatorAutoHidden)]) {
Jun 9, 2019
Jun 9, 2019
259
260
261
[data.viewcontroller performSelectorOnMainThread:@selector(setNeedsUpdateOfHomeIndicatorAutoHidden) withObject:nil waitUntilDone:NO];
[data.viewcontroller performSelectorOnMainThread:@selector(setNeedsUpdateOfScreenEdgesDeferringSystemGestures) withObject:nil waitUntilDone:NO];
}
Jun 14, 2019
Jun 14, 2019
262
#pragma clang diagnostic pop
Jun 9, 2019
Jun 9, 2019
263
264
265
266
267
}
}
#endif /* !TARGET_OS_TV */
}
268
269
270
271
272
/*
* iOS log support.
*
* This doesn't really have aything to do with the interfaces of the SDL video
* subsystem, but we need to stuff this into an Objective-C source code file.
Jul 18, 2019
Jul 18, 2019
273
274
275
276
*
* NOTE: This is copypasted from src/video/cocoa/SDL_cocoavideo.m! Thus, if
* Cocoa is supported, we use that one instead. Be sure both versions remain
* identical!
Jul 18, 2019
Jul 18, 2019
279
#if !defined(SDL_VIDEO_DRIVER_COCOA)
280
281
282
283
void SDL_NSLog(const char *text)
{
NSLog(@"%s", text);
}
Jul 18, 2019
Jul 18, 2019
284
#endif /* SDL_VIDEO_DRIVER_COCOA */
Aug 21, 2018
Aug 21, 2018
286
287
288
289
/*
* iOS Tablet detection
*
* This doesn't really have aything to do with the interfaces of the SDL video
Aug 22, 2018
Aug 22, 2018
290
* subsystem, but we need to stuff this into an Objective-C source code file.
Aug 21, 2018
Aug 21, 2018
291
*/
Aug 22, 2018
Aug 22, 2018
292
SDL_bool SDL_IsIPad(void)
Aug 21, 2018
Aug 21, 2018
293
{
Oct 27, 2019
Oct 27, 2019
294
return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
Aug 21, 2018
Aug 21, 2018
295
296
}
297
298
299
#endif /* SDL_VIDEO_DRIVER_UIKIT */
/* vi: set ts=4 sw=4 expandtab: */