Mercurial > sdl-ios-xcode
annotate src/video/uikit/SDL_uikitvideo.m @ 5134:7b7da52e8775
Fixed spacing
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 01 Feb 2011 08:59:22 -0800 |
parents | 8b7988f42fcb |
children | fb424691cfc7 |
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 | 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 { |
5134 | 59 return (1); |
2765
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; |
5134 | 88 device->CreateWindow = UIKit_CreateWindow; |
89 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
|
90 device->GetWindowWMInfo = UIKit_GetWindowWMInfo; |
5134 | 91 |
92 | |
93 /* OpenGL (ES) functions */ | |
94 device->GL_MakeCurrent = UIKit_GL_MakeCurrent; | |
95 device->GL_SwapWindow = UIKit_GL_SwapWindow; | |
96 device->GL_CreateContext = UIKit_GL_CreateContext; | |
97 device->GL_DeleteContext = UIKit_GL_DeleteContext; | |
98 device->GL_GetProcAddress = UIKit_GL_GetProcAddress; | |
99 device->GL_LoadLibrary = UIKit_GL_LoadLibrary; | |
100 device->free = UIKit_DeleteDevice; | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 |
5134 | 102 device->gl_config.accelerated = 1; |
103 | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 return device; |
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 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 VideoBootStrap UIKIT_bootstrap = { |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 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
|
109 UIKit_Available, UIKit_CreateDevice |
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 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 |
4443
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
113 /* |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
114 !!! FIXME: |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
115 |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
116 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
|
117 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
|
118 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
|
119 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
|
120 |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
121 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
|
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 |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
125 static void |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
126 UIKit_GetDisplayModes(_THIS, SDL_VideoDisplay * display) |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
127 { |
4446
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
128 UIScreen *uiscreen = (UIScreen *) display->driverdata; |
4443
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
129 SDL_DisplayMode mode; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
130 SDL_zero(mode); |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
131 |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
132 // 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
|
133 // 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
|
134 if (!SDL_UIKit_supports_multiple_displays) { |
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
135 const CGRect rect = [uiscreen bounds]; |
4443
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
136 mode.format = SDL_PIXELFORMAT_ABGR8888; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
137 mode.w = (int) rect.size.width; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
138 mode.h = (int) rect.size.height; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
139 mode.refresh_rate = 0; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
140 mode.driverdata = NULL; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
141 SDL_AddDisplayMode(display, &mode); |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
142 return; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
143 } |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
144 |
4446
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
145 const NSArray *modes = [uiscreen availableModes]; |
4443
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
146 const NSUInteger mode_count = [modes count]; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
147 NSUInteger i; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
148 for (i = 0; i < mode_count; i++) { |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
149 UIScreenMode *uimode = (UIScreenMode *) [modes objectAtIndex:i]; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
150 const CGSize size = [uimode size]; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
151 mode.format = SDL_PIXELFORMAT_ABGR8888; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
152 mode.w = (int) size.width; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
153 mode.h = (int) size.height; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
154 mode.refresh_rate = 0; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
155 mode.driverdata = uimode; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
156 [uimode retain]; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
157 SDL_AddDisplayMode(display, &mode); |
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 |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
162 static void |
4446
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
163 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
|
164 { |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
165 SDL_VideoDisplay display; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
166 SDL_DisplayMode mode; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
167 SDL_zero(mode); |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
168 mode.format = SDL_PIXELFORMAT_ABGR8888; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
169 mode.w = w; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
170 mode.h = h; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
171 mode.refresh_rate = 0; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
172 |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
173 SDL_zero(display); |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
174 display.desktop_mode = mode; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
175 display.current_mode = mode; |
4446
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
176 |
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
177 [uiscreen retain]; |
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
178 display.driverdata = uiscreen; |
4443
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
179 SDL_AddVideoDisplay(&display); |
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 |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
182 |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 int |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 UIKit_VideoInit(_THIS) |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 { |
4443
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
186 _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
|
187 |
4445
06becafcac89
Test for system version in the Apple Recommended way.
Ryan C. Gordon <icculus@icculus.org>
parents:
4443
diff
changeset
|
188 NSString *reqSysVer = @"3.2"; |
06becafcac89
Test for system version in the Apple Recommended way.
Ryan C. Gordon <icculus@icculus.org>
parents:
4443
diff
changeset
|
189 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
|
190 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
|
191 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
|
192 |
4443
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
193 // 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
|
194 // 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
|
195 // external displays. |
4446
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
196 if (!SDL_UIKit_supports_multiple_displays) { |
4443
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
197 // 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
|
198 UIScreen *uiscreen = [UIScreen mainScreen]; |
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
199 const CGRect rect = [uiscreen bounds]; |
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
200 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
|
201 } else { |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
202 const NSArray *screens = [UIScreen screens]; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
203 const NSUInteger screen_count = [screens count]; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
204 NSUInteger i; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
205 for (i = 0; i < screen_count; i++) { |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
206 // 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
|
207 UIScreen *uiscreen = (UIScreen *) [screens objectAtIndex:i]; |
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
208 const CGSize size = [[uiscreen currentMode] size]; |
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
209 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
|
210 } |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
211 } |
2765
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 /* We're done! */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 return 0; |
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 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 static int |
3643
41253c0fa9b3
Fixed function prototype
Sam Lantinga <slouken@libsdl.org>
parents:
3547
diff
changeset
|
218 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
|
219 { |
4446
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
220 UIScreen *uiscreen = (UIScreen *) display->driverdata; |
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
221 if (!SDL_UIKit_supports_multiple_displays) { |
4443
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
222 // 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
|
223 SDL_assert(mode->driverdata == NULL); |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
224 } else { |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
225 UIScreenMode *uimode = (UIScreenMode *) mode->driverdata; |
4446
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
226 [uiscreen setCurrentMode:uimode]; |
4443
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
227 } |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
228 |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 return 0; |
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 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 void |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 UIKit_VideoQuit(_THIS) |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 { |
4443
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
235 // 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
|
236 int i, j; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
237 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
|
238 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
|
239 UIScreen *uiscreen = (UIScreen *) display->driverdata; |
8b03a20b320f
Much improved multi-display support for iPad.
Ryan C. Gordon <icculus@icculus.org>
parents:
4445
diff
changeset
|
240 [uiscreen release]; |
4443
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
241 display->driverdata = NULL; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
242 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
|
243 SDL_DisplayMode *mode = &display->display_modes[j]; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
244 UIScreenMode *uimode = (UIScreenMode *) mode->driverdata; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
245 if (uimode) { |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
246 [uimode release]; |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
247 mode->driverdata = NULL; |
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 } |
c598e440c87c
Implemented display mode functionality for UIKit.
Ryan C. Gordon <icculus@icculus.org>
parents:
3643
diff
changeset
|
250 } |
2765
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 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 /* vi: set ts=4 sw=4 expandtab: */ |