comparison src/video/riscos/SDL_riscosvideo.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 066236f0cbf0
children e1da92da346c
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
46 #include "swis.h" 46 #include "swis.h"
47 47
48 #define RISCOSVID_DRIVER_NAME "riscos" 48 #define RISCOSVID_DRIVER_NAME "riscos"
49 49
50 /* Initialization/Query functions */ 50 /* Initialization/Query functions */
51 static int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat); 51 static int RISCOS_VideoInit(_THIS, SDL_PixelFormat * vformat);
52 static void RISCOS_VideoQuit(_THIS); 52 static void RISCOS_VideoQuit(_THIS);
53 53
54 static SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 54 static SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat * format,
55 static SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 55 Uint32 flags);
56 56 static SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface * current,
57 int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info); 57 int width, int height, int bpp,
58 Uint32 flags);
59
60 int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo * info);
58 61
59 int RISCOS_ToggleFullScreen(_THIS, int fullscreen); 62 int RISCOS_ToggleFullScreen(_THIS, int fullscreen);
60 /* Mouse checking */ 63 /* Mouse checking */
61 void RISCOS_CheckMouseMode(_THIS); 64 void RISCOS_CheckMouseMode(_THIS);
62 extern SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode); 65 extern SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode);
63 66
64 /* Fullscreen mode functions */ 67 /* Fullscreen mode functions */
65 extern SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 68 extern SDL_Surface *FULLSCREEN_SetVideoMode(_THIS, SDL_Surface * current,
69 int width, int height, int bpp,
70 Uint32 flags);
66 extern void FULLSCREEN_BuildModeList(_THIS); 71 extern void FULLSCREEN_BuildModeList(_THIS);
67 extern void FULLSCREEN_SetDeviceMode(_THIS); 72 extern void FULLSCREEN_SetDeviceMode(_THIS);
68 extern int FULLSCREEN_ToggleFromWimp(_THIS); 73 extern int FULLSCREEN_ToggleFromWimp(_THIS);
69 74
70 /* Wimp mode functions */ 75 /* Wimp mode functions */
71 extern SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 76 extern SDL_Surface *WIMP_SetVideoMode(_THIS, SDL_Surface * current,
77 int width, int height, int bpp,
78 Uint32 flags);
72 extern void WIMP_DeleteWindow(_THIS); 79 extern void WIMP_DeleteWindow(_THIS);
73 extern int WIMP_ToggleFromFullScreen(_THIS); 80 extern int WIMP_ToggleFromFullScreen(_THIS);
74 81
75 /* Hardware surface functions - common to WIMP and FULLSCREEN */ 82 /* Hardware surface functions - common to WIMP and FULLSCREEN */
76 static int RISCOS_AllocHWSurface(_THIS, SDL_Surface *surface); 83 static int RISCOS_AllocHWSurface(_THIS, SDL_Surface * surface);
77 static int RISCOS_LockHWSurface(_THIS, SDL_Surface *surface); 84 static int RISCOS_LockHWSurface(_THIS, SDL_Surface * surface);
78 static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface *surface); 85 static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface * surface);
79 static void RISCOS_FreeHWSurface(_THIS, SDL_Surface *surface); 86 static void RISCOS_FreeHWSurface(_THIS, SDL_Surface * surface);
80 87
81 /* RISC OS driver bootstrap functions */ 88 /* RISC OS driver bootstrap functions */
82 89
83 static int RISCOS_Available(void) 90 static int
84 { 91 RISCOS_Available(void)
85 return(1); 92 {
86 } 93 return (1);
87 94 }
88 static void RISCOS_DeleteDevice(SDL_VideoDevice *device) 95
89 { 96 static void
90 SDL_free(device->hidden); 97 RISCOS_DeleteDevice(SDL_VideoDevice * device)
91 SDL_free(device); 98 {
92 } 99 SDL_free(device->hidden);
93 100 SDL_free(device);
94 static SDL_VideoDevice *RISCOS_CreateDevice(int devindex) 101 }
95 { 102
96 SDL_VideoDevice *device; 103 static SDL_VideoDevice *
97 104 RISCOS_CreateDevice(int devindex)
98 /* Initialize all variables that we clean on shutdown */ 105 {
99 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 106 SDL_VideoDevice *device;
100 if ( device ) { 107
101 SDL_memset(device, 0, (sizeof *device)); 108 /* Initialize all variables that we clean on shutdown */
102 device->hidden = (struct SDL_PrivateVideoData *) 109 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
103 SDL_malloc((sizeof *device->hidden)); 110 if (device) {
104 } 111 SDL_memset(device, 0, (sizeof *device));
105 if ( (device == NULL) || (device->hidden == NULL) ) { 112 device->hidden = (struct SDL_PrivateVideoData *)
106 SDL_OutOfMemory(); 113 SDL_malloc((sizeof *device->hidden));
107 if ( device ) { 114 }
108 SDL_free(device); 115 if ((device == NULL) || (device->hidden == NULL)) {
109 } 116 SDL_OutOfMemory();
110 return(0); 117 if (device) {
111 } 118 SDL_free(device);
112 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); 119 }
113 120 return (0);
114 /* Set the function pointers */ 121 }
115 device->VideoInit = RISCOS_VideoInit; 122 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
116 device->VideoQuit = RISCOS_VideoQuit; 123
117 124 /* Set the function pointers */
118 device->ListModes = RISCOS_ListModes; 125 device->VideoInit = RISCOS_VideoInit;
119 device->SetVideoMode = RISCOS_SetVideoMode; 126 device->VideoQuit = RISCOS_VideoQuit;
120 device->CreateYUVOverlay = NULL; 127
121 device->AllocHWSurface = RISCOS_AllocHWSurface; 128 device->ListModes = RISCOS_ListModes;
122 device->CheckHWBlit = NULL; 129 device->SetVideoMode = RISCOS_SetVideoMode;
123 device->FillHWRect = NULL; 130 device->CreateYUVOverlay = NULL;
124 device->SetHWColorKey = NULL; 131 device->AllocHWSurface = RISCOS_AllocHWSurface;
125 device->SetHWAlpha = NULL; 132 device->CheckHWBlit = NULL;
126 device->LockHWSurface = RISCOS_LockHWSurface; 133 device->FillHWRect = NULL;
127 device->UnlockHWSurface = RISCOS_UnlockHWSurface; 134 device->SetHWColorKey = NULL;
128 device->FreeHWSurface = RISCOS_FreeHWSurface; 135 device->SetHWAlpha = NULL;
129 136 device->LockHWSurface = RISCOS_LockHWSurface;
130 device->FreeWMCursor = RISCOS_FreeWMCursor; 137 device->UnlockHWSurface = RISCOS_UnlockHWSurface;
131 device->CreateWMCursor = RISCOS_CreateWMCursor; 138 device->FreeHWSurface = RISCOS_FreeHWSurface;
132 device->CheckMouseMode = RISCOS_CheckMouseMode; 139
140 device->FreeWMCursor = RISCOS_FreeWMCursor;
141 device->CreateWMCursor = RISCOS_CreateWMCursor;
142 device->CheckMouseMode = RISCOS_CheckMouseMode;
133 device->GrabInput = RISCOS_GrabInput; 143 device->GrabInput = RISCOS_GrabInput;
134 144
135 device->InitOSKeymap = RISCOS_InitOSKeymap; 145 device->InitOSKeymap = RISCOS_InitOSKeymap;
136 146
137 device->GetWMInfo = RISCOS_GetWmInfo; 147 device->GetWMInfo = RISCOS_GetWmInfo;
138 148
139 device->free = RISCOS_DeleteDevice; 149 device->free = RISCOS_DeleteDevice;
140 150
141 /* Can't get Toggle screen to work if program starts up in Full screen mode so 151 /* Can't get Toggle screen to work if program starts up in Full screen mode so
142 disable it here and re-enable it when a wimp screen is chosen */ 152 disable it here and re-enable it when a wimp screen is chosen */
143 device->ToggleFullScreen = NULL; /*RISCOS_ToggleFullScreen;*/ 153 device->ToggleFullScreen = NULL; /*RISCOS_ToggleFullScreen; */
144 154
145 /* Set other entries for fullscreen mode */ 155 /* Set other entries for fullscreen mode */
146 FULLSCREEN_SetDeviceMode(device); 156 FULLSCREEN_SetDeviceMode(device);
147 157
148 /* Mouse pointer needs to use the WIMP ShowCursor version so 158 /* Mouse pointer needs to use the WIMP ShowCursor version so
149 that it doesn't modify the pointer until the SDL Window is 159 that it doesn't modify the pointer until the SDL Window is
150 entered or the application goes full screen */ 160 entered or the application goes full screen */
151 device->ShowWMCursor = WIMP_ShowWMCursor; 161 device->ShowWMCursor = WIMP_ShowWMCursor;
152 162
153 return device; 163 return device;
154 } 164 }
155 165
156 VideoBootStrap RISCOS_bootstrap = { 166 VideoBootStrap RISCOS_bootstrap = {
157 RISCOSVID_DRIVER_NAME, "RISC OS video driver", 167 RISCOSVID_DRIVER_NAME, "RISC OS video driver",
158 RISCOS_Available, RISCOS_CreateDevice 168 RISCOS_Available, RISCOS_CreateDevice
159 }; 169 };
160 170
161 171
162 int RISCOS_VideoInit(_THIS, SDL_PixelFormat *vformat) 172 int
163 { 173 RISCOS_VideoInit(_THIS, SDL_PixelFormat * vformat)
164 _kernel_swi_regs regs; 174 {
165 int vars[4], vals[3]; 175 _kernel_swi_regs regs;
166 176 int vars[4], vals[3];
167 if (RISCOS_InitTask() == 0) 177
168 { 178 if (RISCOS_InitTask() == 0) {
169 SDL_SetError("Unable to start task"); 179 SDL_SetError("Unable to start task");
170 return 0; 180 return 0;
171 } 181 }
172 182
173 vars[0] = 9; /* Log base 2 bpp */ 183 vars[0] = 9; /* Log base 2 bpp */
174 vars[1] = 11; /* XWndLimit - num x pixels -1 */ 184 vars[1] = 11; /* XWndLimit - num x pixels -1 */
175 vars[2] = 12; /* YWndLimit - num y pixels -1 */ 185 vars[2] = 12; /* YWndLimit - num y pixels -1 */
176 vars[3] = -1; /* Terminate list */ 186 vars[3] = -1; /* Terminate list */
177 regs.r[0] = (int)vars; 187 regs.r[0] = (int) vars;
178 regs.r[1] = (int)vals; 188 regs.r[1] = (int) vals;
179 189
180 _kernel_swi(OS_ReadVduVariables, &regs, &regs); 190 _kernel_swi(OS_ReadVduVariables, &regs, &regs);
181 vformat->BitsPerPixel = (1 << vals[0]); 191 vformat->BitsPerPixel = (1 << vals[0]);
182 192
183 /* Determine the current screen size */ 193 /* Determine the current screen size */
184 this->info.current_w = vals[1] + 1; 194 this->info.current_w = vals[1] + 1;
185 this->info.current_h = vals[2] + 1; 195 this->info.current_h = vals[2] + 1;
186 196
187 /* Minimum bpp for SDL is 8 */ 197 /* Minimum bpp for SDL is 8 */
188 if (vformat->BitsPerPixel < 8) vformat->BitsPerPixel = 8; 198 if (vformat->BitsPerPixel < 8)
189 199 vformat->BitsPerPixel = 8;
190 200
191 switch (vformat->BitsPerPixel) 201
192 { 202 switch (vformat->BitsPerPixel) {
193 case 15: 203 case 15:
194 case 16: 204 case 16:
195 vformat->Bmask = 0x00007c00; 205 vformat->Bmask = 0x00007c00;
196 vformat->Gmask = 0x000003e0; 206 vformat->Gmask = 0x000003e0;
197 vformat->Rmask = 0x0000001f; 207 vformat->Rmask = 0x0000001f;
198 vformat->BitsPerPixel = 16; /* SDL wants actual number of bits used */ 208 vformat->BitsPerPixel = 16; /* SDL wants actual number of bits used */
199 vformat->BytesPerPixel = 2; 209 vformat->BytesPerPixel = 2;
200 break; 210 break;
201 211
202 case 24: 212 case 24:
203 case 32: 213 case 32:
204 vformat->Bmask = 0x00ff0000; 214 vformat->Bmask = 0x00ff0000;
205 vformat->Gmask = 0x0000ff00; 215 vformat->Gmask = 0x0000ff00;
206 vformat->Rmask = 0x000000ff; 216 vformat->Rmask = 0x000000ff;
207 vformat->BytesPerPixel = 4; 217 vformat->BytesPerPixel = 4;
208 break; 218 break;
209 219
210 default: 220 default:
211 vformat->Bmask = 0; 221 vformat->Bmask = 0;
212 vformat->Gmask = 0; 222 vformat->Gmask = 0;
213 vformat->Rmask = 0; 223 vformat->Rmask = 0;
214 vformat->BytesPerPixel = 1; 224 vformat->BytesPerPixel = 1;
215 break; 225 break;
216 } 226 }
217 227
218 /* Fill in some window manager capabilities */ 228 /* Fill in some window manager capabilities */
219 this->info.wm_available = 1; 229 this->info.wm_available = 1;
220 230
221 /* We're done! */ 231 /* We're done! */
222 return(0); 232 return (0);
223 } 233 }
224 234
225 /* Note: If we are terminated, this could be called in the middle of 235 /* Note: If we are terminated, this could be called in the middle of
226 another SDL video routine -- notably UpdateRects. 236 another SDL video routine -- notably UpdateRects.
227 */ 237 */
228 void RISCOS_VideoQuit(_THIS) 238 void
229 { 239 RISCOS_VideoQuit(_THIS)
230 RISCOS_ExitTask(); 240 {
231 241 RISCOS_ExitTask();
232 if (this->hidden->alloc_bank) SDL_free(this->hidden->alloc_bank); 242
233 this->hidden->alloc_bank = 0; 243 if (this->hidden->alloc_bank)
234 } 244 SDL_free(this->hidden->alloc_bank);
235 245 this->hidden->alloc_bank = 0;
236 246 }
237 SDL_Rect **RISCOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 247
238 { 248
239 if (flags & SDL_FULLSCREEN) 249 SDL_Rect **
240 { 250 RISCOS_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
241 /* Build mode list when first required. */ 251 {
242 if (SDL_nummodes[0] == 0) FULLSCREEN_BuildModeList(this); 252 if (flags & SDL_FULLSCREEN) {
243 253 /* Build mode list when first required. */
244 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); 254 if (SDL_nummodes[0] == 0)
245 } else 255 FULLSCREEN_BuildModeList(this);
246 return (SDL_Rect **)-1; 256
257 return (SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]);
258 } else
259 return (SDL_Rect **) - 1;
247 } 260 }
248 261
249 262
250 /* Set up video mode */ 263 /* Set up video mode */
251 SDL_Surface *RISCOS_SetVideoMode(_THIS, SDL_Surface *current, 264 SDL_Surface *
252 int width, int height, int bpp, Uint32 flags) 265 RISCOS_SetVideoMode(_THIS, SDL_Surface * current,
253 { 266 int width, int height, int bpp, Uint32 flags)
254 if (flags & SDL_FULLSCREEN) 267 {
255 { 268 if (flags & SDL_FULLSCREEN) {
256 RISCOS_StoreWimpMode(); 269 RISCOS_StoreWimpMode();
257 /* Dump wimp window on switch to full screen */ 270 /* Dump wimp window on switch to full screen */
258 if (this->hidden->window_handle) WIMP_DeleteWindow(this); 271 if (this->hidden->window_handle)
259 272 WIMP_DeleteWindow(this);
260 return FULLSCREEN_SetVideoMode(this, current, width, height, bpp, flags); 273
261 } else 274 return FULLSCREEN_SetVideoMode(this, current, width, height, bpp,
262 { 275 flags);
263 RISCOS_RestoreWimpMode(); 276 } else {
264 return WIMP_SetVideoMode(this, current, width, height, bpp, flags); 277 RISCOS_RestoreWimpMode();
265 } 278 return WIMP_SetVideoMode(this, current, width, height, bpp, flags);
279 }
266 } 280 }
267 281
268 282
269 /* We don't actually allow hardware surfaces other than the main one */ 283 /* We don't actually allow hardware surfaces other than the main one */
270 static int RISCOS_AllocHWSurface(_THIS, SDL_Surface *surface) 284 static int
271 { 285 RISCOS_AllocHWSurface(_THIS, SDL_Surface * surface)
272 return(-1); 286 {
273 } 287 return (-1);
274 static void RISCOS_FreeHWSurface(_THIS, SDL_Surface *surface) 288 }
275 { 289 static void
276 return; 290 RISCOS_FreeHWSurface(_THIS, SDL_Surface * surface)
291 {
292 return;
277 } 293 }
278 294
279 /* We need to wait for vertical retrace on page flipped displays */ 295 /* We need to wait for vertical retrace on page flipped displays */
280 static int RISCOS_LockHWSurface(_THIS, SDL_Surface *surface) 296 static int
281 { 297 RISCOS_LockHWSurface(_THIS, SDL_Surface * surface)
282 return(0); 298 {
283 } 299 return (0);
284 300 }
285 static void RISCOS_UnlockHWSurface(_THIS, SDL_Surface *surface) 301
286 { 302 static void
287 return; 303 RISCOS_UnlockHWSurface(_THIS, SDL_Surface * surface)
288 } 304 {
289 305 return;
290 306 }
291 int RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo *info) 307
292 { 308
293 SDL_VERSION(&(info->version)); 309 int
294 info->wimpVersion = RISCOS_GetWimpVersion(); 310 RISCOS_GetWmInfo(_THIS, SDL_SysWMinfo * info)
295 info->taskHandle = RISCOS_GetTaskHandle(); 311 {
296 info->window = this->hidden->window_handle; 312 SDL_VERSION(&(info->version));
297 313 info->wimpVersion = RISCOS_GetWimpVersion();
298 return 1; 314 info->taskHandle = RISCOS_GetTaskHandle();
299 } 315 info->window = this->hidden->window_handle;
316
317 return 1;
318 }
319
300 /* Toggle full screen mode. 320 /* Toggle full screen mode.
301 Returns 1 if successful otherwise 0 321 Returns 1 if successful otherwise 0
302 */ 322 */
303 323
304 int RISCOS_ToggleFullScreen(_THIS, int fullscreen) 324 int
305 { 325 RISCOS_ToggleFullScreen(_THIS, int fullscreen)
306 if (fullscreen) 326 {
307 { 327 if (fullscreen) {
308 return FULLSCREEN_ToggleFromWimp(this); 328 return FULLSCREEN_ToggleFromWimp(this);
309 } else 329 } else {
310 { 330 return WIMP_ToggleFromFullScreen(this);
311 return WIMP_ToggleFromFullScreen(this); 331 }
312 } 332
313 333 return 0;
314 return 0; 334 }
315 } 335
316 336 /* vi: set ts=4 sw=4 expandtab: */