Mercurial > sdl-ios-xcode
comparison src/video/cybergfx/SDL_cgxmodes.c @ 0:74212992fb08
Initial revision
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Thu, 26 Apr 2001 16:45:43 +0000 |
parents | |
children | 75a95f82bc1f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:74212992fb08 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@devolution.com | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* Utilities for getting and setting the X display mode */ | |
29 | |
30 /* | |
31 #include <stdlib.h> | |
32 #include <string.h> | |
33 */ | |
34 | |
35 #include "SDL_timer.h" | |
36 #include "SDL_error.h" | |
37 #include "SDL_events.h" | |
38 #include "SDL_events_c.h" | |
39 #include "SDL_cgxvideo.h" | |
40 #include "SDL_cgxwm_c.h" | |
41 #include "SDL_cgxmodes_c.h" | |
42 | |
43 #define CGX_DEBUG | |
44 | |
45 static void set_best_resolution(_THIS, int width, int height) | |
46 { | |
47 Uint32 idok; | |
48 int depth=8; | |
49 | |
50 if(SDL_Display) | |
51 depth=GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH); | |
52 | |
53 idok=BestCModeIDTags(CYBRBIDTG_NominalWidth,width, | |
54 CYBRBIDTG_NominalHeight,height, | |
55 CYBRBIDTG_Depth,depth, | |
56 TAG_DONE); | |
57 | |
58 if(idok!=INVALID_ID) | |
59 { | |
60 if(SDL_Display) | |
61 { | |
62 if(currently_fullscreen) | |
63 CloseScreen(SDL_Display); | |
64 else | |
65 UnlockPubScreen(NULL,SDL_Display); | |
66 } | |
67 SDL_Display=GFX_Display=OpenScreenTags(NULL,SA_Width,width,SA_Height,height, | |
68 SA_Depth,depth,SA_DisplayID,idok, | |
69 TAG_DONE); | |
70 } | |
71 } | |
72 | |
73 static void get_real_resolution(_THIS, int* w, int* h) | |
74 { | |
75 *w = SDL_Display->Width; | |
76 *h = SDL_Display->Height; | |
77 } | |
78 | |
79 static void add_visual(_THIS, int depth, int class) | |
80 { | |
81 Uint32 tID; | |
82 | |
83 tID=BestCModeIDTags(CYBRBIDTG_Depth,depth, | |
84 CYBRBIDTG_NominalWidth,640, | |
85 CYBRBIDTG_NominalHeight,480, | |
86 TAG_DONE); | |
87 | |
88 if(tID!=INVALID_ID) | |
89 { | |
90 int n = this->hidden->nvisuals; | |
91 | |
92 this->hidden->visuals[n].depth = depth; | |
93 this->hidden->visuals[n].visual = tID; | |
94 this->hidden->visuals[n].bpp = GetCyberIDAttr(CYBRIDATTR_BPPIX,tID); | |
95 this->hidden->nvisuals++; | |
96 } | |
97 } | |
98 | |
99 #define TrueColor 1 | |
100 #define PseudoColor 2 | |
101 | |
102 int CGX_GetVideoModes(_THIS) | |
103 { | |
104 int i; | |
105 ULONG nextid; | |
106 int nmodes=0; | |
107 | |
108 SDL_modelist=NULL; | |
109 | |
110 nextid=NextDisplayInfo(INVALID_ID); | |
111 | |
112 while(nextid!=INVALID_ID) | |
113 { | |
114 if(IsCyberModeID(nextid)) | |
115 { | |
116 DisplayInfoHandle h; | |
117 | |
118 if(h=FindDisplayInfo(nextid)) | |
119 { | |
120 struct DimensionInfo info; | |
121 | |
122 if(GetDisplayInfoData(h,(char *)&info,sizeof(struct DimensionInfo),DTAG_DIMS,NULL)) | |
123 { | |
124 int ok=0; | |
125 | |
126 for(i=0;i<nmodes;i++) | |
127 { | |
128 if( SDL_modelist[i]->w == (info.Nominal.MaxX+1) && | |
129 SDL_modelist[i]->h == (info.Nominal.MaxY+1) ) | |
130 ok=1; | |
131 } | |
132 | |
133 if(!ok) | |
134 { | |
135 nmodes++; | |
136 | |
137 SDL_modelist = (SDL_Rect **)realloc(SDL_modelist,(nmodes+1)*sizeof(SDL_Rect *)); | |
138 SDL_modelist[nmodes]=NULL; | |
139 | |
140 if ( SDL_modelist ) | |
141 { | |
142 SDL_modelist[nmodes-1] = (SDL_Rect *)malloc(sizeof(SDL_Rect)); | |
143 | |
144 if ( SDL_modelist[nmodes-1] == NULL ) | |
145 break; | |
146 | |
147 SDL_modelist[nmodes-1]->x = 0; | |
148 SDL_modelist[nmodes-1]->y = 0; | |
149 SDL_modelist[nmodes-1]->w = info.Nominal.MaxX+1; | |
150 SDL_modelist[nmodes-1]->h = info.Nominal.MaxY+1; | |
151 } | |
152 } | |
153 } | |
154 } | |
155 } | |
156 nextid=NextDisplayInfo(nextid); | |
157 } | |
158 | |
159 | |
160 this->hidden->nvisuals = 0; | |
161 /* Search for the visuals in deepest-first order, so that the first | |
162 will be the richest one */ | |
163 add_visual(this, 32, TrueColor); | |
164 add_visual(this, 24, TrueColor); | |
165 add_visual(this, 16, TrueColor); | |
166 add_visual(this, 15, TrueColor); | |
167 add_visual(this, 8, PseudoColor); | |
168 | |
169 if(this->hidden->nvisuals == 0) { | |
170 SDL_SetError("Found no sufficiently capable CGX visuals"); | |
171 return -1; | |
172 } | |
173 | |
174 if ( SDL_modelist == NULL ) { | |
175 SDL_modelist = (SDL_Rect **)malloc((1+1)*sizeof(SDL_Rect *)); | |
176 i = 0; | |
177 if ( SDL_modelist ) { | |
178 SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect)); | |
179 if ( SDL_modelist[i] ) { | |
180 SDL_modelist[i]->x = 0; | |
181 SDL_modelist[i]->y = 0; | |
182 SDL_modelist[i]->w = SDL_Display->Width; | |
183 SDL_modelist[i]->h = SDL_Display->Height; | |
184 ++i; | |
185 } | |
186 SDL_modelist[i] = NULL; | |
187 } | |
188 } | |
189 | |
190 D( if ( SDL_modelist ) { | |
191 bug("CGX video mode list: (%ld)\n",nmodes); | |
192 for ( i=0; SDL_modelist[i]; ++i ) { | |
193 bug( "\t%ld x %ld\n", | |
194 SDL_modelist[i]->w, SDL_modelist[i]->h); | |
195 } | |
196 } | |
197 ); | |
198 | |
199 D( { bug("CGX visuals list: (%ld)\n",this->hidden->nvisuals); | |
200 | |
201 for(i=0;i<this->hidden->nvisuals;i++) | |
202 bug("\t%lx - depth: %ld bpp: %ld\n",this->hidden->visuals[i].visual,this->hidden->visuals[i].depth,this->hidden->visuals[i].bpp); | |
203 } | |
204 ); | |
205 return 0; | |
206 } | |
207 | |
208 int CGX_SupportedVisual(_THIS, SDL_PixelFormat *format) | |
209 { | |
210 int i; | |
211 for(i = 0; i < this->hidden->nvisuals; i++) | |
212 { | |
213 if(this->hidden->visuals[i].depth == format->BitsPerPixel) // Era bpp | |
214 return 1; | |
215 } | |
216 return 0; | |
217 } | |
218 | |
219 SDL_Rect **CGX_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
220 { | |
221 if ( CGX_SupportedVisual(this, format) ) { | |
222 if ( flags & SDL_FULLSCREEN ) { | |
223 return(SDL_modelist); | |
224 } else { | |
225 return((SDL_Rect **)-1); | |
226 } | |
227 } else { | |
228 return((SDL_Rect **)0); | |
229 } | |
230 } | |
231 | |
232 void CGX_FreeVideoModes(_THIS) | |
233 { | |
234 int i; | |
235 | |
236 if ( SDL_modelist ) { | |
237 for ( i=0; SDL_modelist[i]; ++i ) { | |
238 free(SDL_modelist[i]); | |
239 } | |
240 free(SDL_modelist); | |
241 SDL_modelist = NULL; | |
242 } | |
243 } | |
244 | |
245 int CGX_ResizeFullScreen(_THIS) | |
246 { | |
247 int x, y; | |
248 int real_w, real_h; | |
249 | |
250 if ( currently_fullscreen ) { | |
251 /* Per ora non faccio nulla qui */ | |
252 } | |
253 return(1); | |
254 } | |
255 | |
256 void _QueueEnterFullScreen(_THIS) | |
257 { | |
258 } | |
259 | |
260 int CGX_EnterFullScreen(_THIS) | |
261 { | |
262 int okay; | |
263 | |
264 okay = 1; | |
265 if ( ! currently_fullscreen ) | |
266 { | |
267 int real_w, real_h; | |
268 | |
269 /* Map the fullscreen window to blank the screen */ | |
270 get_real_resolution(this, &real_w, &real_h); | |
271 | |
272 CGX_DestroyWindow(this,this->screen); | |
273 set_best_resolution(this, real_w,real_h); | |
274 | |
275 /* Grab the mouse on the fullscreen window | |
276 The event handling will know when we become active, and then | |
277 enter fullscreen mode if we can't grab the mouse this time. | |
278 */ | |
279 #if 0 | |
280 if ( (XGrabPointer(SDL_Display, FSwindow, True, 0, | |
281 GrabModeAsync, GrabModeAsync, | |
282 FSwindow, None, CurrentTime) != GrabSuccess) || | |
283 (XGrabKeyboard(SDL_Display, WMwindow, True, | |
284 GrabModeAsync, GrabModeAsync, CurrentTime) != 0) ) { | |
285 XUnmapWindow(SDL_Display, FSwindow); | |
286 X11_WaitUnmapped(this, FSwindow); | |
287 X11_QueueEnterFullScreen(this); | |
288 return(0); | |
289 } | |
290 #endif | |
291 | |
292 currently_fullscreen = 1; | |
293 | |
294 CGX_CreateWindow(this,this->screen,real_w,real_h,GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH),this->screen->flags); | |
295 | |
296 /* Set the new resolution */ | |
297 okay = CGX_ResizeFullScreen(this); | |
298 if ( ! okay ) { | |
299 CGX_LeaveFullScreen(this); | |
300 } | |
301 /* Set the colormap */ | |
302 /* | |
303 if ( SDL_XColorMap ) { | |
304 XInstallColormap(SDL_Display, SDL_XColorMap); | |
305 } | |
306 */ | |
307 } | |
308 // CGX_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN); | |
309 return(okay); | |
310 } | |
311 | |
312 int CGX_LeaveFullScreen(_THIS) | |
313 { | |
314 if ( currently_fullscreen ) { | |
315 int width,height; | |
316 if ( SDL_Window ) { | |
317 CloseWindow(SDL_Window); | |
318 SDL_Window=NULL; | |
319 } | |
320 CloseScreen(SDL_Display); | |
321 | |
322 GFX_Display=SDL_Display=LockPubScreen(NULL); | |
323 | |
324 currently_fullscreen = 0; | |
325 | |
326 CGX_CreateWindow(this,this->screen,this->screen->w,this->screen->h,GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH),this->screen->flags); | |
327 CGX_ResizeImage(this,this->screen,0L); | |
328 } | |
329 | |
330 return(0); | |
331 } |