comparison src/video/photon/SDL_ph_modes.c @ 663:8bedd6d61642

Date: Sat, 2 Aug 2003 16:22:51 +0300 From: "Mike Gorchak" Subject: New patches for QNX6 Here my patches for the SDL/QNX: QNXSDL.diff - diff to non-QNX related sources: - updated BUGS file, I think QNX6 is now will be officially supported - configure.in - added shared library support for QNX, and removed dependency between the ALSA and QNX6. - SDL_audio.c - added QNX NTO sound bootstrap insted of ALSA's. - SDL_sysaudio.h - the same. - SDL_nto_audio.c - the same. - SDL_video.c - right now, QNX doesn't offer any method to obtain pointers to the OpenGL functions by function name, so they must be hardcoded in library, otherwise OpenGL will not be supported. - testsprite.c - fixed: do not draw vertical red line if we are in non-double-buffered mode. sdlqnxph.tar.gz - archive of the ./src/video/photon/* . Too many changes in code to make diffs :) : + Added stub for support hide/unhide window event + Added full YUV overlays support. + Added window maximize support. + Added mouse wheel events. + Added support for some specific key codes in Unicode mode (like ESC). + Added more checks to the all memory allocation code. + Added SDL_DOUBLEBUF support in all fullscreen modes. + Added fallback to window mode, if desired fullscreen mode is not supported. + Added stub support for the GL_LoadLibrary and GL_GetProcAddress functions. + Added resizable window support without caption. ! Fixed bug in the Ph_EV_EXPOSE event handler, when rectangles to update is 0 and when width or height of the rectangle is 0. ! Fixed bug in the event handler code. Events has not been passed to the window widget handler. ! Fixed codes for Win keys (Super/Hyper/Menu). ! Fixed memory leak, when deallocation palette. ! Fixed palette emulation code bugs. ! Fixed fullscreen and hwsurface handling. ! Fixed CLOSE button bug. First event was passed to the handler, but second terminated the application. Now all events passed to the application correctly. - Removed all printfs in code, now SDL_SetError used instead of them. - Disabled ToggleFullScreen function. README.QNX - updated README.QNX file. Added much more issues.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 04 Aug 2003 00:52:42 +0000
parents 8e3ce997621c
children 04dd6c6d7c30
comparison
equal deleted inserted replaced
662:66c02f83f5bf 663:8bedd6d61642
23 #ifdef SAVE_RCSID 23 #ifdef SAVE_RCSID
24 static char rcsid = 24 static char rcsid =
25 "@(#) $Id$"; 25 "@(#) $Id$";
26 #endif 26 #endif
27 27
28 #include "SDL_error.h"
28 #include "SDL_ph_modes_c.h" 29 #include "SDL_ph_modes_c.h"
29 30
30 static unsigned long key1, key2; 31 static unsigned long key1, key2;
31 static PgVideoModeInfo_t mode_info; 32 static PgVideoModeInfo_t mode_info;
32 static PgVideoModes_t mode_list; 33 static PgVideoModes_t mode_list;
37 38
38 static int compare_modes_by_res(const void* mode1, const void* mode2) 39 static int compare_modes_by_res(const void* mode1, const void* mode2)
39 { 40 {
40 if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode_info) < 0) 41 if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode_info) < 0)
41 { 42 {
42 fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
43 *(unsigned short*)mode1);
44 return 0; 43 return 0;
45 } 44 }
46 45
47 key1 = mode_info.width * mode_info.height; 46 key1 = mode_info.width * mode_info.height;
48 47
49 if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0) 48 if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0)
50 { 49 {
51 fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
52 *(unsigned short*)mode2);
53 return 0; 50 return 0;
54 } 51 }
55 52
56 key2 = mode_info.width * mode_info.height; 53 key2 = mode_info.width * mode_info.height;
57 54
58 if (key1 > key2) 55 if (key1 > key2)
56 {
59 return 1; 57 return 1;
60 else if (key1 == key2) 58 }
61 return 0;
62 else 59 else
63 return -1; 60 {
61 if (key1 == key2)
62 {
63 return 0;
64 }
65 else
66 {
67 return -1;
68 }
69 }
64 } 70 }
65 71
66 SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 72 SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
67 { 73 {
68 int i = 0; 74 int i = 0;
74 SDL_modearray[i]=&SDL_modelist[i]; 80 SDL_modearray[i]=&SDL_modelist[i];
75 } 81 }
76 82
77 if (PgGetVideoModeList( &mode_list ) < 0) 83 if (PgGetVideoModeList( &mode_list ) < 0)
78 { 84 {
79 fprintf(stderr,"error: PgGetVideoModeList failed\n"); 85 SDL_SetError("ph_ListModes(): PgGetVideoModeList() function failed !\n");
80 return NULL; 86 return NULL;
81 } 87 }
82 88
83 mode_info.bits_per_pixel = 0; 89 mode_info.bits_per_pixel = 0;
84 90
85 for (i=0; i < mode_list.num_modes; i++) 91 for (i=0; i < mode_list.num_modes; i++)
86 { 92 {
87 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) 93 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
88 { 94 {
89 fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n", mode_list.modes[i]); 95 SDL_SetError("ph_ListModes(): PgGetVideoModeInfo() function failed on mode: 0x%X.\n", mode_list.modes[i]);
90 return NULL; 96 return NULL;
91 } 97 }
92 if(mode_info.bits_per_pixel == format->BitsPerPixel) 98 if(mode_info.bits_per_pixel == format->BitsPerPixel)
93 { 99 {
94 Amodelist[j].w = mode_info.width; 100 Amodelist[j].w = mode_info.width;
118 return; 124 return;
119 } 125 }
120 126
121 /* return the mode associated with width, height and bpp */ 127 /* return the mode associated with width, height and bpp */
122 /* if there is no mode then zero is returned */ 128 /* if there is no mode then zero is returned */
123 int get_mode(int width, int height, int bpp) 129 int ph_GetVideoMode(int width, int height, int bpp)
124 { 130 {
125 int i; 131 int i;
126 132
127 if(width<640)
128 {
129 width=640;
130 }
131 if(height<480)
132 {
133 height=480;
134 }
135
136 if (PgGetVideoModeList(&mode_list) < 0) 133 if (PgGetVideoModeList(&mode_list) < 0)
137 { 134 {
138 fprintf(stderr,"error: PgGetVideoModeList failed\n");
139 return -1; 135 return -1;
140 } 136 }
141 137
142 /* search list for exact match */ 138 /* search list for exact match */
143 for (i=0;i<mode_list.num_modes;i++) 139 for (i=0;i<mode_list.num_modes;i++)
144 { 140 {
145 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) 141 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
146 { 142 {
147 fprintf(stderr,"error: PgGetVideoModeInfo failed\n");
148 return 0; 143 return 0;
149 } 144 }
150 145
151 if ((mode_info.width == width) && 146 if ((mode_info.width == width) &&
152 (mode_info.height == height) && 147 (mode_info.height == height) &&
157 } 152 }
158 153
159 return (i == mode_list.num_modes) ? 0 : mode_list.modes[i]; 154 return (i == mode_list.num_modes) ? 0 : mode_list.modes[i];
160 } 155 }
161 156
162 int get_mode_any_format(int width, int height, int bpp)
163 /* return the mode associated with width, height and bpp */ 157 /* return the mode associated with width, height and bpp */
164 /* if requested bpp is not found the mode with closest bpp is returned */ 158 /* if requested bpp is not found the mode with closest bpp is returned */
159 int get_mode_any_format(int width, int height, int bpp)
165 { 160 {
166 int i, closest, delta, min_delta; 161 int i, closest, delta, min_delta;
167 162
168 if (PgGetVideoModeList( &mode_list ) < 0) 163 if (PgGetVideoModeList(&mode_list) < 0)
169 { 164 {
170 fprintf(stderr,"error: PgGetVideoModeList failed\n"); 165 return -1;
171 return -1; 166 }
172 } 167
173 168 qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res);
174 qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_res); 169
175 for(i=0;i<mode_list.num_modes;i++) 170 for(i=0;i<mode_list.num_modes;i++)
176 { 171 {
177 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) 172 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
178 { 173 {
179 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); 174 return 0;
180 return 0; 175 }
181 } 176 if ((mode_info.width == width) && (mode_info.height == height))
182 if ((mode_info.width == width) && 177 {
183 (mode_info.height == height))
184 break; 178 break;
185 } 179 }
186 if (i<mode_list.num_modes) 180 }
187 { 181
188 /* get closest bpp */ 182 if (i<mode_list.num_modes)
189 closest = i++; 183 {
190 if (mode_info.bits_per_pixel == bpp) 184 /* get closest bpp */
191 return mode_list.modes[closest]; 185 closest = i++;
192 186 if (mode_info.bits_per_pixel == bpp)
193 min_delta = abs(mode_info.bits_per_pixel - bpp); 187 {
194 while(1) 188 return mode_list.modes[closest];
195 { 189 }
196 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0) 190
197 { 191 min_delta = abs(mode_info.bits_per_pixel - bpp);
198 fprintf(stderr,"error: PgGetVideoModeInfo failed\n"); 192
199 return 0; 193 while(1)
200 } 194 {
201 195 if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
202 if ((mode_info.width != width) || 196 {
203 (mode_info.height != height)) 197 return 0;
204 break; 198 }
205 else if (mode_info.bits_per_pixel == bpp) 199
206 { 200 if ((mode_info.width != width) || (mode_info.height != height))
207 closest = i; 201 {
208 break; 202 break;
209 } 203 }
210 else 204 else
211 { 205 {
212 delta = abs(mode_info.bits_per_pixel - bpp); 206 if (mode_info.bits_per_pixel == bpp)
213 if (delta < min_delta) 207 {
214 { 208 closest = i;
215 closest = i; 209 break;
216 min_delta = delta; 210 }
217 } 211 else
218 i++; 212 {
219 } 213 delta = abs(mode_info.bits_per_pixel - bpp);
220 } 214 if (delta < min_delta)
221 return mode_list.modes[closest]; 215 {
222 } 216 closest = i;
223 else 217 min_delta = delta;
218 }
219 i++;
220 }
221 }
222 }
223 return mode_list.modes[closest];
224 }
225
224 return 0; 226 return 0;
225 } 227 }
226 228
227 int ph_ToggleFullScreen(_THIS, int on) 229 int ph_ToggleFullScreen(_THIS, int on)
228 { 230 {
229 if (currently_fullscreen) 231 return -1;
230 { 232 }
231 return ph_LeaveFullScreen(this); 233
232 } 234 int ph_EnterFullScreen(_THIS, SDL_Surface* screen)
233 else 235 {
234 { 236 PgDisplaySettings_t settings;
235 return ph_EnterFullScreen(this); 237 int mode;
236 } 238
237
238 return 0;
239 }
240
241 int ph_EnterFullScreen(_THIS)
242 {
243 if (!currently_fullscreen) 239 if (!currently_fullscreen)
244 { 240 {
241 /* Get the video mode and set it */
242 if (screen->flags & SDL_ANYFORMAT)
243 {
244 if ((mode = get_mode_any_format(screen->w, screen->h, screen->format->BitsPerPixel)) == 0)
245 {
246 SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n");
247 return 0;
248 }
249 }
250 else
251 {
252 if ((mode = ph_GetVideoMode(screen->w, screen->h, screen->format->BitsPerPixel)) == 0)
253 {
254 SDL_SetError("ph_EnterFullScreen(): can't find appropriate video mode !\n");
255 return 0;
256 }
257 }
258
259 /* save old video mode caps */
260 PgGetVideoMode(&settings);
261 old_video_mode=settings.mode;
262 old_refresh_rate=settings.refresh;
263
264 /* setup new video mode */
265 settings.mode = mode;
266 settings.refresh = 0;
267 settings.flags = 0;
268
269 if (PgSetVideoMode(&settings) < 0)
270 {
271 SDL_SetError("ph_EnterFullScreen(): PgSetVideoMode() call failed !\n");
272 return 0;
273 }
274
245 if (this->screen) 275 if (this->screen)
246 { 276 {
247 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL) 277 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
248 { 278 {
249 #ifdef HAVE_OPENGL 279 #ifdef HAVE_OPENGL
253 } 283 }
254 284
255 if (OCImage.direct_context==NULL) 285 if (OCImage.direct_context==NULL)
256 { 286 {
257 OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext(); 287 OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
258 } 288 if (!OCImage.direct_context)
259 289 {
260 if (!OCImage.direct_context) 290 SDL_SetError("ph_EnterFullScreen(): Can't create direct context !\n");
261 { 291 ph_LeaveFullScreen(this);
262 fprintf(stderr, "ph_EnterFullScreen(): Can't create direct context !\n"); 292 return 0;
263 return 0; 293 }
264 } 294 }
265 295
266 OCImage.oldDC=PdDirectStart(OCImage.direct_context); 296 OCImage.oldDC=PdDirectStart(OCImage.direct_context);
267 297
268 currently_fullscreen = 1; 298 currently_fullscreen = 1;
275 { 305 {
276 PgDisplaySettings_t mymode_settings; 306 PgDisplaySettings_t mymode_settings;
277 307
278 if (currently_fullscreen) 308 if (currently_fullscreen)
279 { 309 {
280 if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL) 310 if ((this->screen) && ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
281 { 311 {
282 #ifdef HAVE_OPENGL 312 #ifdef HAVE_OPENGL
283 #endif /* HAVE_OPENGL */ 313 #endif /* HAVE_OPENGL */
284 return 0; 314 return 0;
285 } 315 }
286 else 316 else
287 { 317 {
288 PdDirectStop(OCImage.direct_context); 318 if (OCImage.direct_context)
289 PdReleaseDirectContext(OCImage.direct_context); 319 {
290 PhDCSetCurrent(OCImage.oldDC); 320 PdDirectStop(OCImage.direct_context);
321 PdReleaseDirectContext(OCImage.direct_context);
322 OCImage.direct_context=NULL;
323 }
324 if (OCImage.oldDC)
325 {
326 PhDCSetCurrent(OCImage.oldDC);
327 OCImage.oldDC=NULL;
328 }
291 329
292 currently_fullscreen=0; 330 currently_fullscreen=0;
293 331
294 /* Restore old video mode */ 332 /* Restore old video mode */
295 if (old_video_mode != -1) 333 if (old_video_mode != -1)
296 { 334 {
297 mymode_settings.mode= (unsigned short) old_video_mode; 335 mymode_settings.mode = (unsigned short) old_video_mode;
298 mymode_settings.refresh= (unsigned short) old_refresh_rate; 336 mymode_settings.refresh = (unsigned short) old_refresh_rate;
299 mymode_settings.flags= 0; 337 mymode_settings.flags = 0;
300 338
301 if (PgSetVideoMode(&mymode_settings) < 0) 339 if (PgSetVideoMode(&mymode_settings) < 0)
302 { 340 {
303 fprintf(stderr, "Ph_LeaveFullScreen(): PgSetVideoMode failed !\n"); 341 SDL_SetError("Ph_LeaveFullScreen(): PgSetVideoMode() function failed !\n");
304 return 0; 342 return 0;
305 } 343 }
306 } 344 }
307 345
308 old_video_mode=-1; 346 old_video_mode=-1;
309 old_refresh_rate=-1; 347 old_refresh_rate=-1;
310 } 348 }
311
312 } 349 }
313 return 1; 350 return 1;
314 } 351 }