Mercurial > sdl-ios-xcode
annotate src/video/photon/SDL_ph_video.c @ 266:c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 18 Jan 2002 18:14:03 +0000 |
parents | e8157fcb3114 |
children | 04351f59b051 |
rev | line source |
---|---|
0 | 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 | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
204
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include <stdlib.h> | |
29 #include <stdio.h> | |
30 #include <unistd.h> | |
31 #include <string.h> | |
32 #include <sys/ioctl.h> | |
33 | |
34 #include "SDL.h" | |
35 #include "SDL_error.h" | |
36 #include "SDL_timer.h" | |
37 #include "SDL_thread.h" | |
38 #include "SDL_video.h" | |
39 #include "SDL_mouse.h" | |
40 #include "SDL_endian.h" | |
41 #include "SDL_sysvideo.h" | |
42 #include "SDL_pixels_c.h" | |
43 #include "SDL_events_c.h" | |
44 #include "SDL_ph_video.h" | |
45 #include "SDL_ph_modes_c.h" | |
46 #include "SDL_ph_image_c.h" | |
47 #include "SDL_ph_events_c.h" | |
48 #include "SDL_ph_mouse_c.h" | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
49 #include "SDL_ph_wm_c.h" |
0 | 50 #include "SDL_phyuv_c.h" |
51 #include "blank_cursor.h" | |
52 | |
53 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
54 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, | |
55 int width, int height, int bpp, Uint32 flags); | |
56 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | |
57 static void ph_VideoQuit(_THIS); | |
58 static void ph_DeleteDevice(SDL_VideoDevice *device); | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
59 static void ph_GL_SwapBuffers(_THIS); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
60 |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
61 PdOpenGLContext_t* OGLContext=NULL; |
0 | 62 |
63 static int ph_Available(void) | |
64 { | |
65 return 1; | |
66 } | |
67 | |
68 static SDL_VideoDevice *ph_CreateDevice(int devindex) | |
69 { | |
70 SDL_VideoDevice *device; | |
71 | |
72 /* Initialize all variables that we clean on shutdown */ | |
73 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); | |
74 if ( device ) { | |
75 memset(device, 0, (sizeof *device)); | |
76 device->hidden = (struct SDL_PrivateVideoData *) | |
77 malloc((sizeof *device->hidden)); | |
78 device->gl_data = NULL; | |
79 } | |
80 if ( (device == NULL) || (device->hidden == NULL) ) { | |
81 SDL_OutOfMemory(); | |
82 ph_DeleteDevice(device); | |
83 return(0); | |
84 } | |
85 memset(device->hidden, 0, (sizeof *device->hidden)); | |
86 | |
87 /* Set the driver flags */ | |
88 device->handles_any_size = 1; //JB not true for fullscreen | |
89 | |
90 /* Set the function pointers */ | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
91 device->CreateYUVOverlay = ph_CreateYUVOverlay; |
0 | 92 device->VideoInit = ph_VideoInit; |
93 device->ListModes = ph_ListModes; | |
94 device->SetVideoMode = ph_SetVideoMode; | |
95 device->ToggleFullScreen = ph_ToggleFullScreen; | |
96 device->UpdateMouse = NULL; | |
97 device->SetColors = ph_SetColors; | |
98 device->UpdateRects = NULL; //set in ph_ResizeImage | |
99 device->VideoQuit = ph_VideoQuit; | |
100 device->AllocHWSurface = ph_AllocHWSurface; | |
101 device->CheckHWBlit = NULL; | |
102 device->FillHWRect = NULL; | |
103 device->SetHWColorKey = NULL; | |
104 device->SetHWAlpha = NULL; | |
105 device->LockHWSurface = ph_LockHWSurface; | |
106 device->UnlockHWSurface = ph_UnlockHWSurface; | |
107 device->FlipHWSurface = ph_FlipHWSurface; | |
108 device->FreeHWSurface = ph_FreeHWSurface; | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
109 device->SetCaption = ph_SetCaption; |
0 | 110 device->SetIcon = NULL; |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
111 device->IconifyWindow = ph_IconifyWindow; |
0 | 112 device->GrabInput = NULL; |
113 device->GetWMInfo = NULL; | |
114 device->FreeWMCursor = ph_FreeWMCursor; | |
115 device->CreateWMCursor = ph_CreateWMCursor; | |
116 device->ShowWMCursor = ph_ShowWMCursor; | |
117 device->WarpWMCursor = ph_WarpWMCursor; | |
118 device->CheckMouseMode = ph_CheckMouseMode; | |
119 device->InitOSKeymap = ph_InitOSKeymap; | |
120 device->PumpEvents = ph_PumpEvents; | |
121 | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
122 // OpenGL support. |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
123 device->GL_LoadLibrary = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
124 device->GL_GetProcAddress = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
125 device->GL_GetAttribute = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
126 device->GL_MakeCurrent = NULL; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
127 device->GL_SwapBuffers = ph_GL_SwapBuffers; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
128 |
0 | 129 device->free = ph_DeleteDevice; |
130 | |
131 return device; | |
132 } | |
133 | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
134 VideoBootStrap ph_bootstrap = { |
0 | 135 "photon", "QNX Photon video output", |
136 ph_Available, ph_CreateDevice | |
137 }; | |
138 | |
139 static void ph_DeleteDevice(SDL_VideoDevice *device) | |
140 { | |
141 | |
142 if ( device ) { | |
143 if ( device->hidden ) { | |
144 free(device->hidden); | |
145 device->hidden = NULL; | |
146 } | |
147 if ( device->gl_data ) { | |
148 free(device->gl_data); | |
149 device->gl_data = NULL; | |
150 } | |
151 free(device); | |
152 device = NULL; | |
153 } | |
154 } | |
155 | |
156 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
157 { | |
158 PtArg_t arg[1]; | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
159 PhDim_t dim; |
0 | 160 PgColor_t ph_palette[_Pg_MAX_PALETTE]; |
161 int i; | |
162 unsigned long *tempptr; | |
163 int rtnval; | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
164 // PgDisplaySettings_t mysettings; |
0 | 165 PgVideoModeInfo_t my_mode_info; |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
166 PgHWCaps_t my_hwcaps; |
0 | 167 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
168 if( NULL == ( event = malloc( EVENT_SIZE ) ) ) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
169 exit( EXIT_FAILURE ); |
0 | 170 |
171 /* Create a widget 'window' to capture events */ | |
172 dim.w=0; //JB test320; | |
173 dim.h=0; //JB test240; | |
174 //We need to return BytesPerPixel as it in used by CreateRGBsurface | |
175 | |
176 PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0); | |
177 | |
178 /* | |
179 PtSetArg(&arg[1], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED); | |
180 PtSetArg(&arg[2], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT | | |
181 Ph_WM_STATE_ISMAX | | |
182 Ph_WM_STATE_ISFOCUS); | |
183 | |
184 PtSetArg(&arg[3], Pt_ARG_WINDOW_RENDER_FLAGS,Pt_FALSE,~0); | |
185 PtSetArg(&arg[4], Pt_ARG_WINDOW_MANAGED_FLAGS,Pt_TRUE, | |
186 Ph_WM_FFRONT | | |
187 Ph_WM_CLOSE | | |
188 Ph_WM_TOFRONT | | |
189 Ph_WM_CONSWITCH); | |
190 */ | |
191 | |
192 | |
193 window=PtAppInit(NULL, NULL, NULL, 1, arg); | |
194 | |
195 if(window == NULL) | |
196 { | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
197 printf("Photon application init failed, probably Photon is not running.\n"); |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
198 exit( EXIT_FAILURE ); |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
199 // PtExit(EXIT_FAILURE); // Got SEGFAULT. |
0 | 200 } |
201 | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
202 //PgSetDrawBufferSize(16 *1024); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
203 PgSetRegion(PtWidgetRid(window)); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
204 PgSetClipping(0,NULL); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
205 PtRealizeWidget(window); |
0 | 206 |
207 | |
208 /* Get the available video modes */ | |
209 // if(ph_GetVideoModes(this) < 0) | |
210 // return -1; | |
211 | |
212 /* Create the blank cursor */ | |
213 SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask, | |
214 (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT, | |
215 (int)BLANK_CHOTX, (int)BLANK_CHOTY); | |
216 | |
217 if(SDL_BlankCursor == NULL) | |
218 printf("could not create blank cursor\n"); | |
219 /* Get the video mode */ | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
220 /* |
0 | 221 if (PgGetVideoMode( &mysettings ) < 0) |
222 { | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
223 fprintf(stderr,"ph_VideoInit: PgGetVideoMode failed patch A?? \n"); |
0 | 224 //QNX6/Patch A always fails return code even though call succeeds. fixed Patch B |
225 } | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
226 */ |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
227 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
228 { |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
229 fprintf(stderr,"ph_VideoInit: GetGraphicsHWCaps failed!! \n"); |
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
230 //that HAVE to work |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
231 } |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
232 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0) |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
233 { |
0 | 234 fprintf(stderr,"ph_VideoInit: PgGetVideoModeInfo failed\n"); |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
235 } |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
236 |
0 | 237 //We need to return BytesPerPixel as it in used by CreateRGBsurface |
238 vformat->BitsPerPixel = my_mode_info.bits_per_pixel; | |
239 vformat->BytesPerPixel = vformat->BitsPerPixel/8; | |
240 | |
241 //return a palette if we are in 256 color mode | |
242 if(vformat->BitsPerPixel == 8) | |
243 { | |
244 vformat->palette = malloc(sizeof(SDL_Palette)); | |
245 memset(vformat->palette, 0, sizeof(SDL_Palette)); | |
246 vformat->palette->ncolors = 256; | |
247 vformat->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color)); | |
248 | |
249 //fill the palette | |
250 rtnval = PgGetPalette(ph_palette); | |
251 if(rtnval < 0) | |
252 printf("ph_VideoInit: PgGetPalette failed\n"); | |
253 | |
254 tempptr = (unsigned long *)vformat->palette->colors; | |
255 | |
256 for(i=0;i<256; i++) | |
257 { | |
258 *tempptr = (((unsigned long)ph_palette[i]) << 8); | |
259 tempptr++; | |
260 | |
261 } | |
262 | |
263 } | |
264 | |
265 | |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
266 currently_fullscreen = 0; |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
267 |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
268 this->info.wm_available = 1; |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
269 |
0 | 270 return 0; |
271 } | |
272 | |
273 static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, | |
274 int width, int height, int bpp, Uint32 flags) | |
275 { | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
276 // PhRegion_t region_info; |
0 | 277 PgDisplaySettings_t settings; |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
278 PgHWCaps_t my_hwcaps; |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
279 PgVideoModeInfo_t mode_info; |
0 | 280 int mode, actual_width, actual_height; |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
281 PtArg_t arg[5]; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
282 PhDim_t dim; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
283 int rtnval; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
284 PgColor_t ph_palette[_Pg_MAX_PALETTE]; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
285 int i; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
286 unsigned long *tempptr; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
287 uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; |
0 | 288 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
289 actual_width = width; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
290 actual_height = height; |
0 | 291 |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
292 dim.w=width; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
293 dim.h=height; |
0 | 294 |
295 /* Lock the event thread, in multi-threading environments */ | |
296 SDL_Lock_EventThread(); | |
297 | |
298 /* Initialize the window */ | |
299 if (flags & SDL_FULLSCREEN) //Direct Context , assume SDL_HWSURFACE also set | |
300 { | |
301 /* | |
302 if (old_video_mode==-1) | |
303 { | |
304 PgGetGraphicsHWCaps(&graphics_card_caps); | |
305 old_video_mode=graphics_card_caps.current_video_mode; | |
306 old_refresh_rate=graphics_card_caps.current_rrate; | |
307 } | |
308 */ | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
309 |
0 | 310 /* Get the video mode and set it */ |
311 if (bpp == 0) | |
312 { | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
313 /*again same issue, same solution |
0 | 314 if (PgGetVideoMode( &settings ) < 0) |
315 { | |
316 fprintf(stderr,"error: PgGetVideoMode failed\n"); | |
317 } | |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
318 */ |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
319 if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
320 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
321 fprintf(stderr,"ph_SetVideoMode: GetGraphicsHWCaps failed!! \n"); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
322 //that HAVE to work |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
323 } |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
324 if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &mode_info) < 0) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
325 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
326 fprintf(stderr,"ph_SetVideoMode: PgGetVideoModeInfo failed\n"); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
327 } |
204
62bad9a82022
Added photon fixes submitted by Luca Barbato
Sam Lantinga <slouken@libsdl.org>
parents:
19
diff
changeset
|
328 bpp = mode_info.bits_per_pixel; |
0 | 329 } |
330 if (flags & SDL_ANYFORMAT) | |
331 { | |
332 if ((mode = get_mode_any_format(width, height, bpp)) == 0) | |
333 { | |
334 fprintf(stderr,"error: get_mode_any_format failed\n"); | |
335 exit(1); | |
336 } | |
337 } | |
338 else | |
339 { | |
340 if ((mode = get_mode(width, height, bpp)) == 0) | |
341 { | |
342 fprintf(stderr,"error: get_mode failed\n"); | |
343 exit(1); | |
344 } | |
345 | |
346 | |
347 } | |
348 settings.mode = mode; | |
349 settings.refresh = 0; | |
350 settings.flags = 0; | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
351 |
0 | 352 if (PgSetVideoMode( &settings ) < 0) |
353 { | |
354 fprintf(stderr,"error: PgSetVideoMode failed\n"); | |
355 } | |
356 | |
357 /* Get the true height and width */ | |
358 | |
359 current->flags = (flags|(~SDL_RESIZABLE)); //no resize for Direct Context | |
360 | |
361 /* Begin direct mode */ | |
362 ph_EnterFullScreen(this); | |
363 | |
364 | |
365 | |
366 } //end fullscreen flag | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
367 else |
0 | 368 { |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
369 if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */ |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
370 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
371 // Hardware surface is Offsceen Context. ph_ResizeImage handles the switch |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
372 current->flags = (flags|(~SDL_RESIZABLE)); //no stretch blit in offscreen context |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
373 } |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
374 else // must be SDL_SWSURFACE |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
375 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
376 current->flags = (flags|SDL_RESIZABLE); //yes we can resize as this is a software surface |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
377 } |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
378 |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
379 if (flags & SDL_OPENGL) // for now support OpenGL in window mode only |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
380 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
381 OGLAttrib[0]=PHOGL_ATTRIB_DEPTH_BITS; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
382 OGLAttrib[1]=bpp; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
383 OGLAttrib[2]=PHOGL_ATTRIB_NONE; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
384 OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
385 if (OGLContext==NULL) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
386 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
387 fprintf(stderr,"error: cannot create OpenGL context\n"); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
388 exit(1); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
389 } |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
390 PhDCSetCurrent(OGLContext); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
391 } |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
392 |
0 | 393 } |
394 | |
395 //If we are setting video to use the palette make sure we have allocated memory for it | |
396 if(bpp == 8) | |
397 { | |
398 current->format->palette = malloc(sizeof(SDL_Palette)); | |
399 memset(current->format->palette, 0, sizeof(SDL_Palette)); | |
400 current->format->palette->ncolors = 256; | |
401 current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color)); | |
402 //fill the palette | |
403 rtnval = PgGetPalette(ph_palette); | |
404 | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
405 tempptr = (unsigned long *)current->format->palette->colors; |
0 | 406 |
407 for(i=0;i<256; i++) | |
408 { | |
409 *tempptr = (((unsigned long)ph_palette[i]) << 8); | |
410 tempptr++; | |
411 | |
412 } | |
413 } | |
414 | |
415 | |
416 //Current window dimensions | |
417 PtGetResource( window, Pt_ARG_DIM, &dim, 0 ); | |
418 | |
419 //If we need to resize the window | |
420 if((dim.w != width)||(dim.h != height)) | |
421 { | |
422 dim.w=width; | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
423 dim.h=height; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
424 PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
425 PtSetResources( window, 1, arg ); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
426 current->w = width; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
427 current->h = height; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
428 current->format->BitsPerPixel = bpp; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
429 current->format->BytesPerPixel = bpp/8; |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
430 current->pitch = SDL_CalculatePitch(current); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
431 //Must call at least once it setup image planes |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
432 ph_ResizeImage(this, current, flags); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
433 } |
0 | 434 |
435 | |
436 SDL_Unlock_EventThread(); | |
437 | |
438 /* We're done! */ | |
439 return(current); | |
440 } | |
441 | |
442 static void ph_VideoQuit(_THIS) | |
443 { | |
444 | |
445 if(SDL_Image != NULL) | |
446 { | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
447 ph_DestroyImage(this, SDL_VideoSurface); |
0 | 448 } |
449 | |
450 if (currently_fullscreen) | |
451 { | |
452 PdDirectStop( directContext ); | |
453 PdReleaseDirectContext( directContext ); | |
454 directContext=0; | |
455 currently_fullscreen = 0; | |
456 } | |
457 | |
458 } | |
459 | |
460 | |
461 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
462 { | |
463 PgColor_t *in, *out; | |
464 int i, j; | |
465 int alloct_all = 1; | |
466 | |
467 colors = this->screen->format->palette->colors; | |
468 | |
469 in = alloca( ncolors*sizeof(PgColor_t) ); | |
470 if ( in == NULL ) { | |
471 return 0; | |
472 } | |
473 memset(in,0,ncolors*sizeof(PgColor_t)); | |
474 | |
475 out = alloca( ncolors*sizeof(PgColor_t) ); | |
476 if ( out == NULL ) { | |
477 return 0; | |
478 } | |
479 | |
480 for (i=0,j=firstcolor;i<ncolors;i++,j++) | |
481 { | |
482 in[i] |= colors[j].r<<16 ; | |
483 in[i] |= colors[j].g<<8 ; | |
484 in[i] |= colors[j].b ; | |
485 } | |
486 | |
487 if ( (this->screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) | |
488 { | |
489 if( PgSetPalette( in, 0, 0, ncolors, Pg_PALSET_HARD, 0) < 0 ) | |
490 { | |
491 fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_HARD) failed\n"); | |
492 return 0; | |
493 } | |
494 } | |
495 else | |
496 { | |
497 if ( PgColorMatch(ncolors, in, out) < 0 ) | |
498 { | |
499 fprintf(stderr,"error: PgColorMatch failed\n"); | |
500 return 0; | |
501 } | |
502 for (i=0;i<ncolors;i++) | |
503 { | |
504 if (memcmp(&in[i],&out[i],sizeof(PgColor_t))) | |
505 { | |
506 alloct_all = 0; | |
507 break; | |
508 } | |
509 } | |
510 if( PgSetPalette( out, 0, 0, ncolors, Pg_PALSET_SOFT, 0) < 0 ) | |
511 { | |
512 fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_SOFT) failed\n"); | |
513 return 0; | |
514 } | |
515 } | |
516 return alloct_all; | |
517 } | |
518 | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
519 void ph_GL_SwapBuffers(_THIS) |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
520 { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
521 PgSetRegion(PtWidgetRid(window)); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
522 PdOpenGLContextSwapBuffers(OGLContext); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
523 } |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
524 |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
525 /* |
0 | 526 static int ph_ResizeWindow(_THIS, |
527 SDL_Surface *screen, int w, int h, Uint32 flags) | |
528 { | |
529 PhWindowEvent_t winevent; | |
530 | |
531 memset( &winevent, 0, sizeof(winevent) ); | |
532 winevent.event_f = Ph_WM_RESIZE; | |
533 winevent.size.w = w; | |
534 winevent.size.h = h; | |
535 winevent.rid = PtWidgetRid( window ); | |
536 if (PtForwardWindowEvent( &winevent ) < 0) | |
537 { | |
538 fprintf(stderr,"error: PtForwardWindowEvent failed.\n"); | |
539 } | |
540 current_w = w; | |
541 current_h = h; | |
542 return(0); | |
543 } | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
544 */ |