annotate src/video/uikit/SDL_uikitvideo.m @ 4796:e8caf178d082

Added in Visual Studio patch.
author Eli Gottlieb <eligottlieb@gmail.com>
date Thu, 15 Jul 2010 01:41:38 -0400
parents 8b03a20b320f
children 8b7988f42fcb
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
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #include "SDL_renderer_sw.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #include "SDL_renderer_gles.h"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
41 #include "SDL_assert.h"
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
42
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 #define UIKITVID_DRIVER_NAME "uikit"
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 /* Initialization/Query functions */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 static int UIKit_VideoInit(_THIS);
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
47 static void UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display);
3643
41253c0fa9b3 Fixed function prototype
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
48 static int UIKit_SetDisplayMode(_THIS, SDL_VideoDisplay * display,
41253c0fa9b3 Fixed function prototype
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
49 SDL_DisplayMode * mode);
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 static void UIKit_VideoQuit(_THIS);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
52 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
53
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 /* DUMMY driver bootstrap functions */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 static int
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 UIKit_Available(void)
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 return (1);
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
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 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
63 {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 SDL_free(device);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 }
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 static SDL_VideoDevice *
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 UIKit_CreateDevice(int devindex)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 SDL_VideoDevice *device;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 /* 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
73 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
74 if (!device) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 SDL_OutOfMemory();
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 if (device) {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 SDL_free(device);
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 return (0);
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 /* Set the function pointers */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 device->VideoInit = UIKit_VideoInit;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 device->VideoQuit = UIKit_VideoQuit;
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
85 device->GetDisplayModes = UIKit_GetDisplayModes;
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 device->SetDisplayMode = UIKit_SetDisplayMode;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 device->PumpEvents = UIKit_PumpEvents;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 device->CreateWindow = UIKit_CreateWindow;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 device->DestroyWindow = UIKit_DestroyWindow;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 /* OpenGL (ES) functions */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 device->GL_MakeCurrent = UIKit_GL_MakeCurrent;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 device->GL_SwapWindow = UIKit_GL_SwapWindow;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 device->GL_CreateContext = UIKit_GL_CreateContext;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 device->GL_DeleteContext = UIKit_GL_DeleteContext;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 device->GL_GetProcAddress = UIKit_GL_GetProcAddress;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 device->GL_LoadLibrary = UIKit_GL_LoadLibrary;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 device->free = UIKit_DeleteDevice;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 device->gl_config.accelerated = 1;
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 return device;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 VideoBootStrap UIKIT_bootstrap = {
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 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
108 UIKit_Available, UIKit_CreateDevice
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 };
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111
4443
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 !!! FIXME:
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
114
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
115 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
116 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
117 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
118 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
119
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
120 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
121
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
122 */
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
123
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
124 static void
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
125 UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
126 {
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
127 UIScreen *uiscreen = (UIScreen *) display->driverdata;
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
128 SDL_DisplayMode mode;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
129 SDL_zero(mode);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
130
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
131 // 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
132 // 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
133 if (!SDL_UIKit_supports_multiple_displays) {
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
134 const CGRect rect = [uiscreen bounds];
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
135 mode.format = SDL_PIXELFORMAT_ABGR8888;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
136 mode.w = (int) rect.size.width;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
137 mode.h = (int) rect.size.height;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
138 mode.refresh_rate = 0;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
139 mode.driverdata = NULL;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
140 SDL_AddDisplayMode(display, &mode);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
141 return;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
142 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
143
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
144 const NSArray *modes = [uiscreen availableModes];
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
145 const NSUInteger mode_count = [modes count];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
146 NSUInteger i;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
147 for (i = 0; i < mode_count; i++) {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
148 UIScreenMode *uimode = (UIScreenMode *) [modes objectAtIndex:i];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
149 const CGSize size = [uimode size];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
150 mode.format = SDL_PIXELFORMAT_ABGR8888;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
151 mode.w = (int) size.width;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
152 mode.h = (int) size.height;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
153 mode.refresh_rate = 0;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
154 mode.driverdata = uimode;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
155 [uimode retain];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
156 SDL_AddDisplayMode(display, &mode);
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
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
160
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
161 static void
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
162 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
163 {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
164 SDL_VideoDisplay display;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
165 SDL_DisplayMode mode;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
166 SDL_zero(mode);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
167 mode.format = SDL_PIXELFORMAT_ABGR8888;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
168 mode.w = w;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
169 mode.h = h;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
170 mode.refresh_rate = 0;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
171
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
172 SDL_zero(display);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
173 display.desktop_mode = mode;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
174 display.current_mode = mode;
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
175
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
176 [uiscreen retain];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
177 display.driverdata = uiscreen;
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
178 SDL_AddVideoDisplay(&display);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
179 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
180
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
181
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 int
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 UIKit_VideoInit(_THIS)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 {
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
185 _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
186
4445
06becafcac89 Test for system version in the Apple Recommended way.
Ryan C. Gordon <icculus@icculus.org>
parents: 4443
diff changeset
187 NSString *reqSysVer = @"3.2";
06becafcac89 Test for system version in the Apple Recommended way.
Ryan C. Gordon <icculus@icculus.org>
parents: 4443
diff changeset
188 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
189 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
190 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
191
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
192 // 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
193 // 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
194 // external displays.
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
195 if (!SDL_UIKit_supports_multiple_displays) {
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
196 // 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
197 UIScreen *uiscreen = [UIScreen mainScreen];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
198 const CGRect rect = [uiscreen bounds];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
199 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
200 } else {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
201 const NSArray *screens = [UIScreen screens];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
202 const NSUInteger screen_count = [screens count];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
203 NSUInteger i;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
204 for (i = 0; i < screen_count; i++) {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
205 // 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
206 UIScreen *uiscreen = (UIScreen *) [screens objectAtIndex:i];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
207 const CGSize size = [[uiscreen currentMode] size];
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
208 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
209 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
210 }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 /* We're done! */
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 static int
3643
41253c0fa9b3 Fixed function prototype
Sam Lantinga <slouken@libsdl.org>
parents: 3547
diff changeset
217 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
218 {
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
219 UIScreen *uiscreen = (UIScreen *) display->driverdata;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
220 if (!SDL_UIKit_supports_multiple_displays) {
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
221 // 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
222 SDL_assert(mode->driverdata == NULL);
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
223 } else {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
224 UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
4446
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
225 [uiscreen setCurrentMode:uimode];
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
226 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
227
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 return 0;
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 void
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 UIKit_VideoQuit(_THIS)
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 {
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
234 // 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
235 int i, j;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
236 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
237 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
238 UIScreen *uiscreen = (UIScreen *) display->driverdata;
8b03a20b320f Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents: 4445
diff changeset
239 [uiscreen release];
4443
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
240 display->driverdata = NULL;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
241 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
242 SDL_DisplayMode *mode = &display->display_modes[j];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
243 UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
244 if (uimode) {
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
245 [uimode release];
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
246 mode->driverdata = NULL;
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
247 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
248 }
c598e440c87c Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents: 3643
diff changeset
249 }
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 }
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 /* vi: set ts=4 sw=4 expandtab: */