Mercurial > sdl-ios-xcode
annotate src/video/cybergfx/SDL_cgxmodes.c @ 1643:51038e80ae59
More general fix for bug #189
The clipping is done at a higher level, and the low level functions are
passed clipped rectangles. Drivers which don't support source clipping
have not been changed, so the image will be squished instead of clipped,
but at least they will no longer crash when the destination rect was out
of bounds.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 17 Apr 2006 06:47:23 +0000 |
parents | d910939febfa |
children | 782fd950bd46 c121d94672cb |
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 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* Utilities for getting and setting the X display mode */ | |
25 | |
26 #include "SDL_timer.h" | |
27 #include "SDL_events.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
28 #include "../../events/SDL_events_c.h" |
0 | 29 #include "SDL_cgxvideo.h" |
30 #include "SDL_cgxwm_c.h" | |
31 #include "SDL_cgxmodes_c.h" | |
32 | |
33 #define CGX_DEBUG | |
34 | |
35 static void set_best_resolution(_THIS, int width, int height) | |
36 { | |
37 Uint32 idok; | |
38 int depth=8; | |
39 | |
40 if(SDL_Display) | |
41 depth=GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH); | |
42 | |
43 idok=BestCModeIDTags(CYBRBIDTG_NominalWidth,width, | |
44 CYBRBIDTG_NominalHeight,height, | |
45 CYBRBIDTG_Depth,depth, | |
46 TAG_DONE); | |
47 | |
48 if(idok!=INVALID_ID) | |
49 { | |
50 if(SDL_Display) | |
51 { | |
52 if(currently_fullscreen) | |
53 CloseScreen(SDL_Display); | |
54 else | |
55 UnlockPubScreen(NULL,SDL_Display); | |
56 } | |
57 SDL_Display=GFX_Display=OpenScreenTags(NULL,SA_Width,width,SA_Height,height, | |
58 SA_Depth,depth,SA_DisplayID,idok, | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
59 SA_ShowTitle,FALSE, |
0 | 60 TAG_DONE); |
61 } | |
62 } | |
63 | |
64 static void get_real_resolution(_THIS, int* w, int* h) | |
65 { | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
66 *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
|
67 *h = /*SDL_Display->Height*/ SDL_Window->Height-SDL_Window->BorderBottom-SDL_Window->BorderTop; |
0 | 68 } |
69 | |
21
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
70 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
|
71 { |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
72 /* 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
|
73 |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
74 /* DA FARE! */ |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
75 } |
75a95f82bc1f
Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
76 |
0 | 77 static void add_visual(_THIS, int depth, int class) |
78 { | |
79 Uint32 tID; | |
80 | |
81 tID=BestCModeIDTags(CYBRBIDTG_Depth,depth, | |
82 CYBRBIDTG_NominalWidth,640, | |
83 CYBRBIDTG_NominalHeight,480, | |
84 TAG_DONE); | |
85 | |
86 if(tID!=INVALID_ID) | |
87 { | |
88 int n = this->hidden->nvisuals; | |
89 | |
90 this->hidden->visuals[n].depth = depth; | |
91 this->hidden->visuals[n].visual = tID; | |
92 this->hidden->visuals[n].bpp = GetCyberIDAttr(CYBRIDATTR_BPPIX,tID); | |
93 this->hidden->nvisuals++; | |
94 } | |
95 } | |
96 | |
97 #define TrueColor 1 | |
98 #define PseudoColor 2 | |
99 | |
100 int CGX_GetVideoModes(_THIS) | |
101 { | |
102 int i; | |
103 ULONG nextid; | |
104 int nmodes=0; | |
105 | |
106 SDL_modelist=NULL; | |
107 | |
108 nextid=NextDisplayInfo(INVALID_ID); | |
109 | |
110 while(nextid!=INVALID_ID) | |
111 { | |
112 if(IsCyberModeID(nextid)) | |
113 { | |
114 DisplayInfoHandle h; | |
115 | |
116 if(h=FindDisplayInfo(nextid)) | |
117 { | |
118 struct DimensionInfo info; | |
119 | |
120 if(GetDisplayInfoData(h,(char *)&info,sizeof(struct DimensionInfo),DTAG_DIMS,NULL)) | |
121 { | |
122 int ok=0; | |
123 | |
124 for(i=0;i<nmodes;i++) | |
125 { | |
126 if( SDL_modelist[i]->w == (info.Nominal.MaxX+1) && | |
127 SDL_modelist[i]->h == (info.Nominal.MaxY+1) ) | |
128 ok=1; | |
129 } | |
130 | |
131 if(!ok) | |
132 { | |
133 nmodes++; | |
134 | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
135 SDL_modelist = (SDL_Rect **)SDL_realloc(SDL_modelist,(nmodes+1)*sizeof(SDL_Rect *)); |
0 | 136 SDL_modelist[nmodes]=NULL; |
137 | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
138 if ( SDL_modelist ) |
0 | 139 { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
140 SDL_modelist[nmodes-1] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); |
0 | 141 |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
142 if ( SDL_modelist[nmodes-1] == NULL ) |
0 | 143 break; |
144 | |
145 SDL_modelist[nmodes-1]->x = 0; | |
146 SDL_modelist[nmodes-1]->y = 0; | |
147 SDL_modelist[nmodes-1]->w = info.Nominal.MaxX+1; | |
148 SDL_modelist[nmodes-1]->h = info.Nominal.MaxY+1; | |
149 } | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
150 } |
0 | 151 } |
152 } | |
153 } | |
154 nextid=NextDisplayInfo(nextid); | |
155 } | |
156 | |
157 | |
158 this->hidden->nvisuals = 0; | |
159 /* Search for the visuals in deepest-first order, so that the first | |
160 will be the richest one */ | |
161 add_visual(this, 32, TrueColor); | |
162 add_visual(this, 24, TrueColor); | |
163 add_visual(this, 16, TrueColor); | |
164 add_visual(this, 15, TrueColor); | |
165 add_visual(this, 8, PseudoColor); | |
166 | |
167 if(this->hidden->nvisuals == 0) { | |
168 SDL_SetError("Found no sufficiently capable CGX visuals"); | |
169 return -1; | |
170 } | |
171 | |
172 if ( SDL_modelist == NULL ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
173 SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *)); |
0 | 174 i = 0; |
175 if ( SDL_modelist ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
176 SDL_modelist[i] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); |
0 | 177 if ( SDL_modelist[i] ) { |
178 SDL_modelist[i]->x = 0; | |
179 SDL_modelist[i]->y = 0; | |
180 SDL_modelist[i]->w = SDL_Display->Width; | |
181 SDL_modelist[i]->h = SDL_Display->Height; | |
182 ++i; | |
183 } | |
184 SDL_modelist[i] = NULL; | |
185 } | |
186 } | |
187 | |
188 D( if ( SDL_modelist ) { | |
189 bug("CGX video mode list: (%ld)\n",nmodes); | |
190 for ( i=0; SDL_modelist[i]; ++i ) { | |
191 bug( "\t%ld x %ld\n", | |
192 SDL_modelist[i]->w, SDL_modelist[i]->h); | |
193 } | |
194 } | |
195 ); | |
196 | |
197 D( { bug("CGX visuals list: (%ld)\n",this->hidden->nvisuals); | |
198 | |
199 for(i=0;i<this->hidden->nvisuals;i++) | |
200 bug("\t%lx - depth: %ld bpp: %ld\n",this->hidden->visuals[i].visual,this->hidden->visuals[i].depth,this->hidden->visuals[i].bpp); | |
201 } | |
202 ); | |
203 return 0; | |
204 } | |
205 | |
206 int CGX_SupportedVisual(_THIS, SDL_PixelFormat *format) | |
207 { | |
208 int i; | |
209 for(i = 0; i < this->hidden->nvisuals; i++) | |
210 { | |
211 if(this->hidden->visuals[i].depth == format->BitsPerPixel) // Era bpp | |
212 return 1; | |
213 } | |
214 return 0; | |
215 } | |
216 | |
217 SDL_Rect **CGX_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
218 { | |
219 if ( CGX_SupportedVisual(this, format) ) { | |
220 if ( flags & SDL_FULLSCREEN ) { | |
221 return(SDL_modelist); | |
222 } else { | |
223 return((SDL_Rect **)-1); | |
224 } | |
225 } else { | |
226 return((SDL_Rect **)0); | |
227 } | |
228 } | |
229 | |
230 void CGX_FreeVideoModes(_THIS) | |
231 { | |
232 int i; | |
233 | |
234 if ( SDL_modelist ) { | |
235 for ( i=0; SDL_modelist[i]; ++i ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
236 SDL_free(SDL_modelist[i]); |
0 | 237 } |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
238 SDL_free(SDL_modelist); |
0 | 239 SDL_modelist = NULL; |
240 } | |
241 } | |
242 | |
243 int CGX_ResizeFullScreen(_THIS) | |
244 { | |
245 int x, y; | |
246 int real_w, real_h; | |
247 | |
248 if ( currently_fullscreen ) { | |
249 /* Per ora non faccio nulla qui */ | |
250 } | |
251 return(1); | |
252 } | |
253 | |
254 void _QueueEnterFullScreen(_THIS) | |
255 { | |
256 } | |
257 | |
258 int CGX_EnterFullScreen(_THIS) | |
259 { | |
260 int okay; | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
261 Uint32 saved_flags; |
0 | 262 |
263 okay = 1; | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
264 saved_flags = this->screen->flags; |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
265 |
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
266 if ( ! currently_fullscreen ) |
0 | 267 { |
268 int real_w, real_h; | |
269 | |
270 /* Map the fullscreen window to blank the screen */ | |
271 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
|
272 |
0 | 273 CGX_DestroyWindow(this,this->screen); |
274 set_best_resolution(this, real_w,real_h); | |
275 | |
276 currently_fullscreen = 1; | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
277 this->screen->flags = saved_flags; |
0 | 278 |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
279 CGX_CreateWindow(this,this->screen,real_w,real_h,GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH),this->screen->flags); |
0 | 280 |
281 /* Set the new resolution */ | |
282 okay = CGX_ResizeFullScreen(this); | |
283 if ( ! okay ) { | |
284 CGX_LeaveFullScreen(this); | |
285 } | |
286 /* Set the colormap */ | |
287 /* | |
288 if ( SDL_XColorMap ) { | |
289 XInstallColormap(SDL_Display, SDL_XColorMap); | |
290 } | |
291 */ | |
255
dcb5e869f8b5
Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
292 } |
0 | 293 // CGX_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN); |
294 return(okay); | |
295 } | |
296 | |
297 int CGX_LeaveFullScreen(_THIS) | |
298 { | |
299 if ( currently_fullscreen ) { | |
300 int width,height; | |
301 if ( SDL_Window ) { | |
302 CloseWindow(SDL_Window); | |
303 SDL_Window=NULL; | |
304 } | |
305 CloseScreen(SDL_Display); | |
306 | |
307 GFX_Display=SDL_Display=LockPubScreen(NULL); | |
308 | |
309 currently_fullscreen = 0; | |
310 | |
311 CGX_CreateWindow(this,this->screen,this->screen->w,this->screen->h,GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH),this->screen->flags); | |
312 CGX_ResizeImage(this,this->screen,0L); | |
313 } | |
314 | |
315 return(0); | |
316 } |