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