annotate src/video/uikit/SDL_uikitvideo.m @ 5212:115fff0641ee

Prefer the OpenGL ES 2.0 context when it's available, make it possible to create an OpenGL 2.0 context on iPhoneOS
author Sam Lantinga <slouken@libsdl.org>
date Sun, 06 Feb 2011 10:22:25 -0800
parents fb424691cfc7
children b530ef003506
rev   line source
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
2859
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
3 Copyright (C) 1997-2009 Sam Lantinga
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
22
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
23 #import <UIKit/UIKit.h>
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
24
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #include "SDL_config.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 #include "SDL_video.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include "SDL_mouse.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include "../SDL_sysvideo.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include "../SDL_pixels_c.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #include "../../events/SDL_events_c.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 #include "SDL_uikitvideo.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include "SDL_uikitevents.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include "SDL_uikitwindow.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 #include "SDL_uikitopengles.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
38 #include "SDL_assert.h"
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
39
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #define UIKITVID_DRIVER_NAME "uikit"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 /* Initialization/Query functions */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 static int UIKit_VideoInit(_THIS);
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
44 static void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display);
3643
41253c0fa9b3 Fixed function prototype
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
45 static int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display,
41253c0fa9b3 Fixed function prototype
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
46 SDL_DisplayMode * mode);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 static void UIKit_VideoQuit(_THIS);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
49 BOOL SDL_UIKit_supports_multiple_displays = NO;
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
50
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 /* DUMMY driver bootstrap functions */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 static int
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 UIKit_Available(void)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 {
5134
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
56 return (1);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 static void UIKit_DeleteDevice(SDL_VideoDevice * device)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 SDL_free(device);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 static SDL_VideoDevice *
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 UIKit_CreateDevice(int devindex)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 SDL_VideoDevice *device;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 /* Initialize all variables that we clean on shutdown */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 if (!device) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 SDL_OutOfMemory();
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 if (device) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 SDL_free(device);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 return (0);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 /* Set the function pointers */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 device->VideoInit = UIKit_VideoInit;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 device->VideoQuit = UIKit_VideoQuit;
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
82 device->GetDisplayModes = UIKit_GetDisplayModes;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 device->SetDisplayMode = UIKit_SetDisplayMode;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 device->PumpEvents = UIKit_PumpEvents;
5134
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
85 device->CreateWindow = UIKit_CreateWindow;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
86 device->DestroyWindow = UIKit_DestroyWindow;
5056
8b7988f42fcb Added the ability to get the UIKit window through the SDL API.
Sam Lantinga <slouken@libsdl.org>
parents: 4446
diff changeset
87 device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
5134
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
88
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
89
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
90 /* OpenGL (ES) functions */
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
91 device->GL_MakeCurrent = UIKit_GL_MakeCurrent;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
92 device->GL_SwapWindow = UIKit_GL_SwapWindow;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
93 device->GL_CreateContext = UIKit_GL_CreateContext;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
94 device->GL_DeleteContext = UIKit_GL_DeleteContext;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
95 device->GL_GetProcAddress = UIKit_GL_GetProcAddress;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
96 device->GL_LoadLibrary = UIKit_GL_LoadLibrary;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
97 device->free = UIKit_DeleteDevice;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98
5134
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
99 device->gl_config.accelerated = 1;
7b7da52e8775 Fixed spacing
Sam Lantinga <slouken@libsdl.org>
parents: 5056
diff changeset
100
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 return device;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 VideoBootStrap UIKIT_bootstrap = {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 UIKITVID_DRIVER_NAME, "SDL UIKit video driver",
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 UIKit_Available, UIKit_CreateDevice
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 };
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
110 /*
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
111 !!! FIXME:
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
112
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
113 The main screen should list a AxB mode for portrait orientation, and then
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
114 also list BxA for landscape mode. When setting a given resolution, we should
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
115 rotate the view's transform appropriately (extra credit if you check the
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
116 accelerometer and rotate the display so it's never upside down).
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
117
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
118 http://iphonedevelopment.blogspot.com/2008/10/starting-in-landscape-mode-without.html
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
119
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
120 */
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
121
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
122 static void
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
123 UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
124 {
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
125 UIScreen *uiscreen = (UIScreen *) display->driverdata;
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
126 SDL_DisplayMode mode;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
127 SDL_zero(mode);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
128
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
129 // availableModes showed up in 3.2 (the iPad and later). We should only
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
130 // land here for at least that version of the OS.
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
131 if (!SDL_UIKit_supports_multiple_displays) {
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
132 const CGRect rect = [uiscreen bounds];
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
133 mode.format = SDL_PIXELFORMAT_ABGR8888;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
134 mode.w = (int) rect.size.width;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
135 mode.h = (int) rect.size.height;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
136 mode.refresh_rate = 0;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
137 mode.driverdata = NULL;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
138 SDL_AddDisplayMode(display, &mode);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
139 return;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
140 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
141
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
142 const NSArray *modes = [uiscreen availableModes];
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
143 const NSUInteger mode_count = [modes count];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
144 NSUInteger i;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
145 for (i = 0; i < mode_count; i++) {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
146 UIScreenMode *uimode = (UIScreenMode *) [modes objectAtIndex:i];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
147 const CGSize size = [uimode size];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
148 mode.format = SDL_PIXELFORMAT_ABGR8888;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
149 mode.w = (int) size.width;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
150 mode.h = (int) size.height;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
151 mode.refresh_rate = 0;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
152 mode.driverdata = uimode;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
153 [uimode retain];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
154 SDL_AddDisplayMode(display, &mode);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
155 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
156 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
157
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
158
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
159 static void
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
160 UIKit_AddDisplay(UIScreen *uiscreen, int w, int h)
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
161 {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
162 SDL_VideoDisplay display;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
163 SDL_DisplayMode mode;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
164 SDL_zero(mode);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
165 mode.format = SDL_PIXELFORMAT_ABGR8888;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
166 mode.w = w;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
167 mode.h = h;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
168 mode.refresh_rate = 0;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
169
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
170 SDL_zero(display);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
171 display.desktop_mode = mode;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
172 display.current_mode = mode;
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
173
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
174 [uiscreen retain];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
175 display.driverdata = uiscreen;
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
176 SDL_AddVideoDisplay(&display);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
177 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
178
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
179
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 int
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 UIKit_VideoInit(_THIS)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 {
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
183 _this->gl_config.driver_loaded = 1;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184
4445
06becafcac89 Test for system version in the Apple Recommended way.
Ryan C. Gordon <icculus@icculus.org>
parents: 4443
diff changeset
185 NSString *reqSysVer = @"3.2";
06becafcac89 Test for system version in the Apple Recommended way.
Ryan C. Gordon <icculus@icculus.org>
parents: 4443
diff changeset
186 NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
06becafcac89 Test for system version in the Apple Recommended way.
Ryan C. Gordon <icculus@icculus.org>
parents: 4443
diff changeset
187 if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
188 SDL_UIKit_supports_multiple_displays = YES;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
190 // If this is iPhoneOS < 3.2, all devices are one screen, 320x480 pixels.
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
191 // The iPad added both a larger main screen and the ability to use
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
192 // external displays.
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
193 if (!SDL_UIKit_supports_multiple_displays) {
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
194 // Just give 'em the whole main screen.
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
195 UIScreen *uiscreen = [UIScreen mainScreen];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
196 const CGRect rect = [uiscreen bounds];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
197 UIKit_AddDisplay(uiscreen, (int)rect.size.width, (int)rect.size.height);
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
198 } else {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
199 const NSArray *screens = [UIScreen screens];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
200 const NSUInteger screen_count = [screens count];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
201 NSUInteger i;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
202 for (i = 0; i < screen_count; i++) {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
203 // the main screen is the first element in the array.
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
204 UIScreen *uiscreen = (UIScreen *) [screens objectAtIndex:i];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
205 const CGSize size = [[uiscreen currentMode] size];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
206 UIKit_AddDisplay(uiscreen, (int) size.width, (int) size.height);
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
207 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
208 }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 /* We're done! */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 static int
3643
41253c0fa9b3 Fixed function prototype
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
215 UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 {
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
217 UIScreen *uiscreen = (UIScreen *) display->driverdata;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
218 if (!SDL_UIKit_supports_multiple_displays) {
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
219 // Not on at least iPhoneOS 3.2 (versions prior to iPad).
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
220 SDL_assert(mode->driverdata == NULL);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
221 } else {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
222 UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
223 [uiscreen setCurrentMode:uimode];
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
224 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
225
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 void
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 UIKit_VideoQuit(_THIS)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 {
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
232 // Release Objective-C objects, so higher level doesn't free() them.
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
233 int i, j;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
234 for (i = 0; i < _this->num_displays; i++) {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
235 SDL_VideoDisplay *display = &_this->displays[i];
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
236 UIScreen *uiscreen = (UIScreen *) display->driverdata;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
237 [uiscreen release];
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
238 display->driverdata = NULL;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
239 for (j = 0; j < display->num_display_modes; j++) {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
240 SDL_DisplayMode *mode = &display->display_modes[j];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
241 UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
242 if (uimode) {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
243 [uimode release];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
244 mode->driverdata = NULL;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
245 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
246 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
247 }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 /* vi: set ts=4 sw=4 expandtab: */