comparison src/video/cybergfx/SDL_cgxvideo.c @ 255:dcb5e869f8b5

Updated Amiga port by Gabriele Greco
author Sam Lantinga <slouken@libsdl.org>
date Sun, 16 Dec 2001 20:00:27 +0000
parents e8157fcb3114
children c9b51268668f
comparison
equal deleted inserted replaced
254:4fc12b8edf74 255:dcb5e869f8b5
1 /* 1 /*
2 SDL - Simple DirectMedia Layer 2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga 3 Copyright (C) 1997, 1998, 1999, 2000 Sam Lantinga
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
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 /* CGX based SDL video driver implementation. 28 /*
29 */ 29 * CGX based SDL video driver implementation by Gabriele Greco
30 * gabriele.greco@aruba.it
31 */
30 32
31 /* 33 /*
32 #include <stdlib.h> 34 #include <stdlib.h>
33 #include <stdio.h> 35 #include <stdio.h>
34 #include <unistd.h> 36 #include <unistd.h>
48 #include "SDL_mouse.h" 50 #include "SDL_mouse.h"
49 #include "SDL_endian.h" 51 #include "SDL_endian.h"
50 #include "SDL_sysvideo.h" 52 #include "SDL_sysvideo.h"
51 #include "SDL_pixels_c.h" 53 #include "SDL_pixels_c.h"
52 #include "SDL_events_c.h" 54 #include "SDL_events_c.h"
55 #include "SDL_cgxgl_c.h"
53 #include "SDL_cgxvideo.h" 56 #include "SDL_cgxvideo.h"
54 #include "SDL_cgxwm_c.h" 57 #include "SDL_cgxwm_c.h"
55 #include "SDL_amigamouse_c.h" 58 #include "SDL_amigamouse_c.h"
56 #include "SDL_amigaevents_c.h" 59 #include "SDL_amigaevents_c.h"
57 #include "SDL_cgxmodes_c.h" 60 #include "SDL_cgxmodes_c.h"
58 #include "SDL_cgximage_c.h" 61 #include "SDL_cgximage_c.h"
59 #include "SDL_cgxyuv_c.h" 62 #include "SDL_cgxyuv_c.h"
60 #include "SDL_cgxgl_c.h"
61 63
62 /* Initialization/Query functions */ 64 /* Initialization/Query functions */
63 static int CGX_VideoInit(_THIS, SDL_PixelFormat *vformat); 65 static int CGX_VideoInit(_THIS, SDL_PixelFormat *vformat);
64 static SDL_Surface *CGX_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 66 static SDL_Surface *CGX_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
65 static int CGX_ToggleFullScreen(_THIS, int on); 67 static int CGX_ToggleFullScreen(_THIS, int on);
71 73
72 struct Library *CyberGfxBase=NULL; 74 struct Library *CyberGfxBase=NULL;
73 struct IntuitionBase *IntuitionBase=NULL; 75 struct IntuitionBase *IntuitionBase=NULL;
74 struct GfxBase *GfxBase=NULL; 76 struct GfxBase *GfxBase=NULL;
75 77
78 int CGX_SetGamma(_THIS, float red, float green, float blue)
79 {
80 SDL_SetError("Gamma correction not supported");
81 return -1;
82 }
83
84 int CGX_GetGamma(_THIS, float red, float green, float blue)
85 {
86 SDL_SetError("Gamma correction not supported");
87 return -1;
88 }
89
90 int CGX_SetGammaRamp(_THIS, Uint16 *ramp)
91 {
92 #if 0
93 Int i, ncolors;
94 XColor xcmap[256];
95
96 /* See if actually setting the gamma is supported */
97 if ( SDL_Visual->class != DirectColor ) {
98 SDL_SetError("Gamma correction not supported on this visual");
99 return(-1);
100 }
101
102 /* Calculate the appropriate palette for the given gamma ramp */
103 ncolors = SDL_Visual->map_entries;
104 for ( i=0; i<ncolors; ++i ) {
105 Uint8 c = (256 * i / ncolors);
106 xcmap[i].pixel = SDL_MapRGB(this->screen->format, c, c, c);
107 xcmap[i].red = ramp[0*256+c];
108 xcmap[i].green = ramp[1*256+c];
109 xcmap[i].blue = ramp[2*256+c];
110 xcmap[i].flags = (DoRed|DoGreen|DoBlue);
111 }
112 XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors);
113 XSync(GFX_Display, False);
114
115 return(0);
116
117 #else
118 SDL_SetError("Gamma correction not supported on this visual");
119 return(-1);
120
121 #endif
122 }
123
76 static void DestroyScreen(_THIS) 124 static void DestroyScreen(_THIS)
77 { 125 {
78 if(currently_fullscreen) 126 if(currently_fullscreen)
79 { 127 {
80 if(this->hidden->dbuffer) 128 if(this->hidden->dbuffer)
96 144
97 this->hidden->SB[0]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=this->hidden->SB[0]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL; 145 this->hidden->SB[0]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=this->hidden->SB[0]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
98 this->hidden->SB[1]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=this->hidden->SB[1]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL; 146 this->hidden->SB[1]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=this->hidden->SB[1]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=NULL;
99 147
100 if(this->hidden->SB[1]) 148 if(this->hidden->SB[1])
149 FreeScreenBuffer(SDL_Display,this->hidden->SB[1]);
150 if(this->hidden->SB[0])
101 FreeScreenBuffer(SDL_Display,this->hidden->SB[0]); 151 FreeScreenBuffer(SDL_Display,this->hidden->SB[0]);
102 if(this->hidden->SB[0])
103 FreeScreenBuffer(SDL_Display,this->hidden->SB[1]);
104 152
105 153
106 this->hidden->SB[0]=this->hidden->SB[1]=NULL; 154 this->hidden->SB[0]=this->hidden->SB[1]=NULL;
107 free(SDL_RastPort); 155
156 if(SDL_RastPort && SDL_RastPort != &SDL_Display->RastPort)
157 free(SDL_RastPort);
158
108 SDL_RastPort=NULL; 159 SDL_RastPort=NULL;
109 this->hidden->dbuffer=0;
110 } 160 }
111 CloseScreen(GFX_Display); 161 CloseScreen(GFX_Display);
112 currently_fullscreen=0; 162 currently_fullscreen=0;
113 } 163 }
114 else 164 else if(GFX_Display)
115 UnlockPubScreen(NULL,GFX_Display); 165 UnlockPubScreen(NULL,GFX_Display);
116 166
117 GFX_Display = NULL; 167 GFX_Display = NULL;
118 } 168 }
119 169
120 static int CGX_Available(void) 170 static int CGX_Available(void)
121 { 171 {
122 struct Library *l; 172 struct Library *l;
123 173
124 l = OpenLibrary("cybergraphics.library",NULL); 174 l = OpenLibrary("cybergraphics.library",0L);
125 175
126 if ( l != NULL ) { 176 if ( l != NULL ) {
177 D(bug("CGX video device AVAILABLE\n"));
127 CloseLibrary(l); 178 CloseLibrary(l);
128 } 179 }
180 D(else bug("**CGX video device UNAVAILABLE\n"));
181
129 return(l != NULL); 182 return(l != NULL);
130 } 183 }
131 184
132 static void CGX_DeleteDevice(SDL_VideoDevice *device) 185 static void CGX_DeleteDevice(SDL_VideoDevice *device)
133 { 186 {
155 device->gl_data = (struct SDL_PrivateGLData *) 208 device->gl_data = (struct SDL_PrivateGLData *)
156 malloc((sizeof *device->gl_data)); 209 malloc((sizeof *device->gl_data));
157 } 210 }
158 if ( (device == NULL) || (device->hidden == NULL) || 211 if ( (device == NULL) || (device->hidden == NULL) ||
159 (device->gl_data == NULL) ) { 212 (device->gl_data == NULL) ) {
213 D(bug("Unable to create video device!\n"));
160 SDL_OutOfMemory(); 214 SDL_OutOfMemory();
161 CGX_DeleteDevice(device); 215 CGX_DeleteDevice(device);
162 return(0); 216 return(0);
163 } 217 }
164 memset(device->hidden, 0, (sizeof *device->hidden)); 218 memset(device->hidden, 0, sizeof(*device->hidden));
165 memset(device->gl_data, 0, (sizeof *device->gl_data)); 219 memset(device->gl_data, 0, sizeof(*device->gl_data));
166 220
167 /* Set the driver flags */ 221 /* Set the driver flags */
168 device->handles_any_size = 1; 222 device->handles_any_size = 1;
169 223
170 /* Set the function pointers */ 224 /* Set the function pointers */
186 device->SetHWAlpha = NULL; 240 device->SetHWAlpha = NULL;
187 device->LockHWSurface = CGX_LockHWSurface; 241 device->LockHWSurface = CGX_LockHWSurface;
188 device->UnlockHWSurface = CGX_UnlockHWSurface; 242 device->UnlockHWSurface = CGX_UnlockHWSurface;
189 device->FlipHWSurface = CGX_FlipHWSurface; 243 device->FlipHWSurface = CGX_FlipHWSurface;
190 device->FreeHWSurface = CGX_FreeHWSurface; 244 device->FreeHWSurface = CGX_FreeHWSurface;
245 device->SetGamma = CGX_SetGamma;
246 device->GetGamma = CGX_GetGamma;
247 device->SetGammaRamp = CGX_SetGammaRamp;
248 device->GetGammaRamp = NULL;
191 #ifdef HAVE_OPENGL 249 #ifdef HAVE_OPENGL
192 device->GL_LoadLibrary = X11_GL_LoadLibrary; 250 device->GL_LoadLibrary = CGX_GL_LoadLibrary;
193 device->GL_GetProcAddress = X11_GL_GetProcAddress; 251 device->GL_GetProcAddress = CGX_GL_GetProcAddress;
194 device->GL_GetAttribute = X11_GL_GetAttribute; 252 device->GL_GetAttribute = CGX_GL_GetAttribute;
195 device->GL_MakeCurrent = X11_GL_MakeCurrent; 253 device->GL_MakeCurrent = CGX_GL_MakeCurrent;
196 device->GL_SwapBuffers = X11_GL_SwapBuffers; 254 device->GL_SwapBuffers = CGX_GL_SwapBuffers;
197 #endif 255 #endif
198 device->SetIcon = CGX_SetIcon; 256 device->SetIcon = CGX_SetIcon;
199 device->SetCaption = CGX_SetCaption; 257 device->SetCaption = CGX_SetCaption;
200 device->IconifyWindow = NULL; /* CGX_IconifyWindow; */ 258 device->IconifyWindow = NULL; /* CGX_IconifyWindow; */
201 device->GrabInput = NULL /* CGX_GrabInput*/; 259 device->GrabInput = NULL /* CGX_GrabInput*/;
202 device->GetWMInfo = CGX_GetWMInfo; 260 device->GetWMInfo = CGX_GetWMInfo;
203 device->FreeWMCursor = amiga_FreeWMCursor; 261 device->FreeWMCursor = amiga_FreeWMCursor;
204 device->CreateWMCursor = amiga_CreateWMCursor; 262 device->CreateWMCursor = amiga_CreateWMCursor;
205 device->ShowWMCursor = amiga_ShowWMCursor; 263 device->ShowWMCursor = amiga_ShowWMCursor;
206 device->WarpWMCursor = amiga_WarpWMCursor; 264 device->WarpWMCursor = amiga_WarpWMCursor;
215 273
216 VideoBootStrap CGX_bootstrap = { 274 VideoBootStrap CGX_bootstrap = {
217 "CGX", "AmigaOS CyberGraphics", CGX_Available, CGX_CreateDevice 275 "CGX", "AmigaOS CyberGraphics", CGX_Available, CGX_CreateDevice
218 }; 276 };
219 277
220 #if 0
221
222 /* Create auxiliary (toplevel) windows with the current visual */
223 static void create_aux_windows(_THIS)
224 {
225 XSetWindowAttributes xattr;
226 XWMHints *hints;
227 XTextProperty titleprop, iconprop;
228 int def_vis = (SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen));
229
230 /* Don't create any extra windows if we are being managed */
231 if ( SDL_windowid ) {
232 FSwindow = 0;
233 WMwindow = strtol(SDL_windowid, NULL, 0);
234 return;
235 }
236
237 if(FSwindow)
238 XDestroyWindow(SDL_Display, FSwindow);
239
240 xattr.override_redirect = True;
241 xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0;
242 xattr.border_pixel = 0;
243 xattr.colormap = SDL_XColorMap;
244
245 FSwindow = XCreateWindow(SDL_Display, SDL_Root, 0, 0, 32, 32, 0,
246 this->hidden->depth, InputOutput, SDL_Visual,
247 CWOverrideRedirect | CWBackPixel | CWBorderPixel
248 | CWColormap,
249 &xattr);
250
251 XSelectInput(SDL_Display, FSwindow, StructureNotifyMask);
252
253 /* Tell KDE to keep the fullscreen window on top */
254 {
255 XEvent ev;
256 long mask;
257
258 memset(&ev, 0, sizeof(ev));
259 ev.xclient.type = ClientMessage;
260 ev.xclient.window = SDL_Root;
261 ev.xclient.message_type = XInternAtom(SDL_Display,
262 "KWM_KEEP_ON_TOP", False);
263 ev.xclient.format = 32;
264 ev.xclient.data.l[0] = FSwindow;
265 ev.xclient.data.l[1] = CurrentTime;
266 mask = SubstructureRedirectMask;
267 XSendEvent(SDL_Display, SDL_Root, False, mask, &ev);
268 }
269
270 hints = NULL;
271 titleprop.value = iconprop.value = NULL;
272 if(WMwindow) {
273 /* All window attributes must survive the recreation */
274 hints = XGetWMHints(SDL_Display, WMwindow);
275 XGetWMName(SDL_Display, WMwindow, &titleprop);
276 XGetWMIconName(SDL_Display, WMwindow, &iconprop);
277 XDestroyWindow(SDL_Display, WMwindow);
278 }
279
280 /* Create the window for windowed management */
281 /* (reusing the xattr structure above) */
282 WMwindow = XCreateWindow(SDL_Display, SDL_Root, 0, 0, 32, 32, 0,
283 this->hidden->depth, InputOutput, SDL_Visual,
284 CWBackPixel | CWBorderPixel | CWColormap,
285 &xattr);
286
287 /* Set the input hints so we get keyboard input */
288 if(!hints) {
289 hints = XAllocWMHints();
290 hints->input = True;
291 hints->flags = InputHint;
292 }
293 XSetWMHints(SDL_Display, WMwindow, hints);
294 XFree(hints);
295 if(titleprop.value) {
296 XSetWMName(SDL_Display, WMwindow, &titleprop);
297 XFree(titleprop.value);
298 }
299 if(iconprop.value) {
300 XSetWMIconName(SDL_Display, WMwindow, &iconprop);
301 XFree(iconprop.value);
302 }
303
304 XSelectInput(SDL_Display, WMwindow,
305 FocusChangeMask | KeyPressMask | KeyReleaseMask
306 | PropertyChangeMask | StructureNotifyMask);
307
308 /* Set the class hints so we can get an icon (AfterStep) */
309 {
310 XClassHint *classhints;
311 classhints = XAllocClassHint();
312 if(classhints != NULL) {
313 classhints->res_name = "SDL_App";
314 classhints->res_class = "SDL_App";
315 XSetClassHint(SDL_Display, WMwindow, classhints);
316 XFree(classhints);
317 }
318 }
319
320 /* Allow the window to be deleted by the window manager */
321 WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False);
322 XSetWMProtocols(SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1);
323 }
324 #endif
325
326 Uint32 MakeBitMask(_THIS,int type,int format,int *bpp) 278 Uint32 MakeBitMask(_THIS,int type,int format,int *bpp)
327 { 279 {
328 D(if(type==0)bug("REAL pixel format: ")); 280 D(if(type==0)bug("REAL pixel format: "));
329 281
330 if(this->hidden->depth==*bpp) 282 if(this->hidden->depth==*bpp)
331 { 283 {
332 284
333 switch(format) 285 switch(format)
334 { 286 {
335 case PIXFMT_LUT8: 287 case PIXFMT_LUT8:
336 D(if(type==0)bug("LUT8\n")); 288 D(if(type==0)bug("LUT8\n"));
337 return 0; 289 return 0;
445 } 397 }
446 } 398 }
447 else 399 else
448 { 400 {
449 D(if(type==0)bug("DIFFERENT from screen.\nAllocated screen format: ")); 401 D(if(type==0)bug("DIFFERENT from screen.\nAllocated screen format: "));
450 402
451 switch(*bpp) 403 switch(*bpp)
452 { 404 {
453 case 32: 405 case 32:
454 D(if(type==0) bug("RGBA32\n")); 406 D(if(type==0) bug("RGBA32\n"));
455 switch(type) 407 switch(type)
477 case 16: 429 case 16:
478 case 15: 430 case 15:
479 D(if(type==0) bug("Not supported, switching to 24bit!\n")); 431 D(if(type==0) bug("Not supported, switching to 24bit!\n"));
480 *bpp=24; 432 *bpp=24;
481 goto use_truecolor; 433 goto use_truecolor;
482 break; 434 break;
483 default: 435 default:
484 D(if(type==0)bug("This is a chunky display\n")); 436 D(if(type==0)bug("This is a chunky display\n"));
485 // For chunky display mask is always 0; 437 // For chunky display mask is always 0;
486 return 0; 438 return 0;
487 } 439 }
488 } 440 }
489 return 0; 441 return 0;
490 } 442 }
491 443
492 static int CGX_VideoInit(_THIS, SDL_PixelFormat *vformat) 444 static int CGX_VideoInit(_THIS, SDL_PixelFormat *vformat)
493 { 445 {
494 int i; 446 int i;
495 447 struct Library *RTGBase;
496 if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",39L))) 448
497 { 449 D(bug("VideoInit... Opening libraries\n"));
498 SDL_SetError("Couldn't open intuition V39+"); 450
499 return -1; 451 if(!IntuitionBase) {
500 } 452 if( !(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",39L))) {
501 if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",39L))) 453 SDL_SetError("Couldn't open intuition V39+");
502 { 454 return -1;
503 SDL_SetError("Couldn't open graphics V39+"); 455 }
504 return -1; 456 }
505 } 457
506 if(!(CyberGfxBase=OpenLibrary("cybergraphics.library",40L))) 458 if(!GfxBase) {
507 { 459 if( !(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",39L))) {
508 SDL_SetError("Couldn't open cybergraphics."); 460 SDL_SetError("Couldn't open graphics V39+");
509 return(-1); 461 return -1;
510 } 462 }
463 }
464
465 if(!CyberGfxBase) {
466 if( !(CyberGfxBase=OpenLibrary("cybergraphics.library",40L))) {
467 SDL_SetError("Couldn't open cybergraphics.");
468 return(-1);
469 }
470 }
471
472 if(RTGBase=OpenLibrary("libs:picasso96/rtg.library",0L)) {
473 extern int use_picasso96;
474
475 CloseLibrary(RTGBase);
476 use_picasso96=1;
477 }
478
479 D(bug("Library intialized, locking screen...\n"));
511 480
512 SDL_Display = LockPubScreen(NULL); 481 SDL_Display = LockPubScreen(NULL);
513 482
514 if ( SDL_Display == NULL ) { 483 if ( SDL_Display == NULL ) {
484 D(bug("Cannot lock display...\n"));
515 SDL_SetError("Couldn't lock the display"); 485 SDL_SetError("Couldn't lock the display");
516 return(-1); 486 return(-1);
517 } 487 }
488
489 D(bug("Checking if we are using a CGX native display...\n"));
518 490
519 if(!IsCyberModeID(GetVPModeID(&SDL_Display->ViewPort))) 491 if(!IsCyberModeID(GetVPModeID(&SDL_Display->ViewPort)))
520 { 492 {
521 Uint32 okid=BestCModeIDTags(CYBRBIDTG_NominalWidth,SDL_Display->Width, 493 Uint32 okid=BestCModeIDTags(CYBRBIDTG_NominalWidth,SDL_Display->Width,
522 CYBRBIDTG_NominalHeight,SDL_Display->Height, 494 CYBRBIDTG_NominalHeight,SDL_Display->Height,
523 CYBRBIDTG_Depth,8, 495 CYBRBIDTG_Depth,8,
524 TAG_DONE); 496 TAG_DONE);
497
498 D(bug("Default visual is not CGX native!\n"));
525 499
526 UnlockPubScreen(NULL,SDL_Display); 500 UnlockPubScreen(NULL,SDL_Display);
527 501
528 GFX_Display=NULL; 502 GFX_Display=NULL;
529 503
554 swap_pixels = 0; 528 swap_pixels = 0;
555 529
556 // Non e' detto che sia cosi' pero', alcune schede potrebbero gestire i modi in modo differente 530 // Non e' detto che sia cosi' pero', alcune schede potrebbero gestire i modi in modo differente
557 531
558 if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) { 532 if ( SDL_BYTEORDER == SDL_LIL_ENDIAN ) {
559 swap_pixels = 1; 533 swap_pixels = 1;
560 } 534 }
535
536 D(bug("Before GetVideoModes....\n"));
561 537
562 /* Get the available video modes */ 538 /* Get the available video modes */
563 if(CGX_GetVideoModes(this) < 0) 539 if(CGX_GetVideoModes(this) < 0)
564 return -1; 540 return -1;
565 541
576 SDL_Visual = this->hidden->visuals[i].visual; 552 SDL_Visual = this->hidden->visuals[i].visual;
577 553
578 // SDL_XColorMap = SDL_DisplayColormap; 554 // SDL_XColorMap = SDL_DisplayColormap;
579 555
580 this->hidden->depth = this->hidden->visuals[i].depth; 556 this->hidden->depth = this->hidden->visuals[i].depth;
581 D(bug("Setto la profiondita' dello schermo a: %ld\n",this->hidden->depth)); 557 D(bug("Init: Setting screen depth to: %ld\n",this->hidden->depth));
582 vformat->BitsPerPixel = this->hidden->visuals[i].depth; /* this->hidden->visuals[i].bpp; */ 558 vformat->BitsPerPixel = this->hidden->visuals[i].depth; /* this->hidden->visuals[i].bpp; */
583 559
584 { 560 {
585 int form; 561 int form;
586 APTR handle; 562 APTR handle;
587 struct DisplayInfo info; 563 struct DisplayInfo info;
588 564
589 if(!(handle=FindDisplayInfo(this->hidden->visuals[i].visual))) 565 if(!(handle=FindDisplayInfo(this->hidden->visuals[i].visual)))
566 {
567 D(bug("Unable to get visual info...\n"));
590 return -1; 568 return -1;
591 569 }
592 if(!GetDisplayInfoData(handle,(char *)&info,sizeof(struct DisplayInfo),DTAG_DISP,NULL)) 570
571 if(!GetDisplayInfoData(handle,(char *)&info,sizeof(struct DisplayInfo),DTAG_DISP,NULL)) {
572 D(bug("Unable to get visual info data...\n"));
593 return -1; 573 return -1;
574 }
594 575
595 form=GetCyberIDAttr(CYBRIDATTR_PIXFMT,SDL_Visual); 576 form=GetCyberIDAttr(CYBRIDATTR_PIXFMT,SDL_Visual);
596 577
597 // In this case I use makebitmask in a way that I'm sure I'll get PIXFMT pixel mask 578 // In this case I use makebitmask in a way that I'm sure I'll get PIXFMT pixel mask
598 579
599 if ( vformat->BitsPerPixel > 8 ) 580 if ( vformat->BitsPerPixel > 8 )
600 { 581 {
601 vformat->Rmask = MakeBitMask(this,0,form,&this->hidden->depth); 582 vformat->Rmask = MakeBitMask(this,0,form,&this->hidden->depth);
602 vformat->Gmask = MakeBitMask(this,1,form,&this->hidden->depth); 583 vformat->Gmask = MakeBitMask(this,1,form,&this->hidden->depth);
603 vformat->Bmask = MakeBitMask(this,2,form,&this->hidden->depth); 584 vformat->Bmask = MakeBitMask(this,2,form,&this->hidden->depth);
604 } 585 }
605 } 586 }
606 587
607 /* See if we have been passed a window to use */ 588 /* See if we have been passed a window to use */
608 /* SDL_windowid = getenv("SDL_WINDOWID"); */ 589 /* SDL_windowid = getenv("SDL_WINDOWID"); */
609 SDL_windowid=NULL; 590 SDL_windowid=NULL;
610
611 /* Create the fullscreen and managed windows */
612 // create_aux_windows(this);
613 591
614 /* Create the blank cursor */ 592 /* Create the blank cursor */
615 SDL_BlankCursor = AllocMem(16,MEMF_CHIP|MEMF_CLEAR); 593 SDL_BlankCursor = AllocMem(16,MEMF_CHIP|MEMF_CLEAR);
616 594
617 /* Fill in some window manager capabilities */ 595 /* Fill in some window manager capabilities */
623 this->info.video_mem=2000000; // Not always true but almost any Amiga card has this memory! 601 this->info.video_mem=2000000; // Not always true but almost any Amiga card has this memory!
624 602
625 this->hidden->same_format=0; 603 this->hidden->same_format=0;
626 SDL_RastPort=&SDL_Display->RastPort; 604 SDL_RastPort=&SDL_Display->RastPort;
627 /* We're done! */ 605 /* We're done! */
606 D(bug("End of CGX_VideoInit\n"));
607
628 return(0); 608 return(0);
629 } 609 }
630 610
631 void CGX_DestroyWindow(_THIS, SDL_Surface *screen) 611 void CGX_DestroyWindow(_THIS, SDL_Surface *screen)
632 { 612 {
613 D(bug("Destroy Window...\n"));
614
633 if ( ! SDL_windowid ) { 615 if ( ! SDL_windowid ) {
634 /* Hide the managed window */ 616 /* Hide the managed window */
635 int was_fullscreen=0; 617 int was_fullscreen=0;
636 618
637 if ( screen && (screen->flags & SDL_FULLSCREEN) ) { 619 /* Clean up OpenGL */
620 if ( screen ) {
621 screen->flags &= ~(SDL_OPENGL|SDL_OPENGLBLIT);
622 }
623
624 if ( screen && (screen->flags & SDL_FULLSCREEN) ) {
638 was_fullscreen=1; 625 was_fullscreen=1;
639 screen->flags &= ~SDL_FULLSCREEN; 626 screen->flags &= ~SDL_FULLSCREEN;
640 // CGX_LeaveFullScreen(this); tolto x crash 627 // CGX_LeaveFullScreen(this); tolto x crash
641 } 628 }
642 629
658 if(numcolors>256) 645 if(numcolors>256)
659 numcolors=256; 646 numcolors=256;
660 647
661 if(!was_fullscreen&&this->hidden->depth==8) 648 if(!was_fullscreen&&this->hidden->depth==8)
662 { 649 {
663 for ( pixel=0; pixel<numcolors; pixel++ ) 650 for ( pixel=0; pixel<numcolors; pixel++ )
664 { 651 {
665 if(SDL_XPixels[pixel]>=0) 652 if(SDL_XPixels[pixel]>=0)
666 ReleasePen(GFX_Display->ViewPort.ColorMap,SDL_XPixels[pixel]); 653 ReleasePen(GFX_Display->ViewPort.ColorMap,SDL_XPixels[pixel]);
667 } 654 }
668 } 655 }
669 } 656 }
670 free(SDL_XPixels); 657 free(SDL_XPixels);
671 SDL_XPixels = NULL; 658 SDL_XPixels = NULL;
672 } 659 }
673 } 660 }
674 } 661 }
675 662
676 static void CGX_SetSizeHints(_THIS, int w, int h, Uint32 flags) 663 static void CGX_SetSizeHints(_THIS, int w, int h, Uint32 flags)
677 { 664 {
699 { 686 {
700 #if 0 687 #if 0
701 int i, depth; 688 int i, depth;
702 Uint32 vis; 689 Uint32 vis;
703 #endif 690 #endif
691 D(bug("CGX_CreateWindow\n"));
692
704 /* If a window is already present, destroy it and start fresh */ 693 /* If a window is already present, destroy it and start fresh */
705 if ( SDL_Window ) { 694 if ( SDL_Window ) {
706 CGX_DestroyWindow(this, screen); 695 CGX_DestroyWindow(this, screen);
707 } 696 }
708 697
716 /* find out which visual we are going to use */ 705 /* find out which visual we are going to use */
717 #if 0 706 #if 0
718 /* questo l'ho spostato nell'apertura dello schermo, in quanto su Amiga le finestre 707 /* questo l'ho spostato nell'apertura dello schermo, in quanto su Amiga le finestre
719 hanno il pixel mode degli schermi. 708 hanno il pixel mode degli schermi.
720 */ 709 */
721 if ( flags & SDL_OPENGL ) { 710 /*if ( flags & SDL_OPENGL ) {
722 SDL_SetError("OpenGL not supported by the Amiga SDL!"); 711 SDL_SetError("OpenGL not supported by the Amiga SDL!");
723 return -1; 712 return -1;
724 } 713 }
725 else { 714 else {*/
726 for ( i = 0; i < this->hidden->nvisuals; i++ ) { 715 for ( i = 0; i < this->hidden->nvisuals; i++ ) {
727 if ( this->hidden->visuals[i].depth == bpp ) /* era .depth */ 716 if ( this->hidden->visuals[i].depth == bpp ) /* era .depth */
728 break; 717 break;
729 } 718 }
730 if ( i == this->hidden->nvisuals ) { 719 if ( i == this->hidden->nvisuals ) {
731 SDL_SetError("No matching visual for requested depth"); 720 SDL_SetError("No matching visual for requested depth");
732 return -1; /* should never happen */ 721 return -1; /* should never happen */
733 } 722 }
734 vis = this->hidden->visuals[i].visual; 723 vis = this->hidden->visuals[i].visual;
735 depth = this->hidden->visuals[i].depth; 724 depth = this->hidden->visuals[i].depth;
736 } 725 // }
737 SDL_Visual = vis; 726 SDL_Visual = vis;
738 this->hidden->depth = depth; 727 this->hidden->depth = depth;
739 D(bug("Setto la profiondita' dello schermo a: %ld\n",this->hidden->depth)); 728 D(bug("Setting screen depth to: %ld\n",this->hidden->depth));
740 #endif 729 #endif
741 730
742 /* Allocate the new pixel format for this video mode */ 731 /* Allocate the new pixel format for this video mode */
743 { 732 {
744 Uint32 form; 733 Uint32 form;
764 753
765 D(bug("BEFORE screen allocation: bpp:%ld (real:%ld)\n",bpp,this->hidden->depth)); 754 D(bug("BEFORE screen allocation: bpp:%ld (real:%ld)\n",bpp,this->hidden->depth));
766 755
767 /* With this call if needed I'll revert the wanted bpp to a bpp best suited for the display, actually occurs 756 /* With this call if needed I'll revert the wanted bpp to a bpp best suited for the display, actually occurs
768 only with requested format 15/16bit and display format != 15/16bit 757 only with requested format 15/16bit and display format != 15/16bit
769 */ 758 */
770 759
771 if ( ! SDL_ReallocFormat(screen, bpp, 760 if ( ! SDL_ReallocFormat(screen, bpp,
772 MakeBitMask(this,0,form,&bpp), MakeBitMask(this,1,form,&bpp), MakeBitMask(this,2,form,&bpp), 0) ) 761 MakeBitMask(this,0,form,&bpp), MakeBitMask(this,1,form,&bpp), MakeBitMask(this,2,form,&bpp), 0) )
773 return -1; 762 return -1;
774 763
781 if ( SDL_XColorMap != SDL_DisplayColormap ) { 770 if ( SDL_XColorMap != SDL_DisplayColormap ) {
782 XFreeColormap(SDL_Display, SDL_XColorMap); 771 XFreeColormap(SDL_Display, SDL_XColorMap);
783 } 772 }
784 */ 773 */
785 if ( GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_PIXFMT)==PIXFMT_LUT8 || bpp==8 ) { 774 if ( GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_PIXFMT)==PIXFMT_LUT8 || bpp==8 ) {
786 int ncolors; 775 int ncolors,i;
787 D(bug("Alloco XPixels x la palette...\n")); 776 D(bug("XPixels palette allocation...\n"));
788 777
789 /* Allocate the pixel flags */ 778 /* Allocate the pixel flags */
790 779
791 if(bpp==8) 780 if(bpp==8)
792 ncolors=256; 781 ncolors=256;
793 else 782 else
794 ncolors = 1 << screen->format->BitsPerPixel; 783 ncolors = 1 << screen->format->BitsPerPixel;
795 784
796 SDL_XPixels = (Sint32 *)malloc(ncolors * sizeof(Sint32)); 785 SDL_XPixels = (Sint32 *)malloc(ncolors * sizeof(Sint32));
797 786
798 if(SDL_XPixels == NULL) { 787 if(SDL_XPixels == NULL) {
799 SDL_OutOfMemory(); 788 SDL_OutOfMemory();
800 return -1; 789 return -1;
801 } 790 }
802 791
803 memset(SDL_XPixels, -1, ncolors * sizeof(Sint32)); 792
793 for(i=0;i<ncolors;i++)
794 SDL_XPixels[i]=-1;
804 795
805 /* always allocate a private colormap on non-default visuals */ 796 /* always allocate a private colormap on non-default visuals */
806 if(bpp==8) 797 if(bpp==8)
807 flags |= SDL_HWPALETTE; 798 flags |= SDL_HWPALETTE;
808 799
809 if ( flags & SDL_HWPALETTE ) { 800 if ( flags & SDL_HWPALETTE )
810 screen->flags |= SDL_HWPALETTE; 801 screen->flags |= SDL_HWPALETTE;
811 /* 802 }
812 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
813 SDL_Visual, AllocAll);
814 */
815 } else {
816 /*
817 SDL_XColorMap = SDL_DisplayColormap;
818 */
819 }
820 } else {
821 /*
822 SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
823 SDL_Visual, AllocNone);
824 */
825 }
826
827 /* Recreate the auxiliary windows, if needed (required for GL) */
828 /*
829 if ( vis_change )
830 create_aux_windows(this);
831 */
832 803
833 /* resize the (possibly new) window manager window */ 804 /* resize the (possibly new) window manager window */
834 805
835 /* Create (or use) the X11 display window */ 806 /* Create (or use) the X11 display window */
807
836 if ( !SDL_windowid ) { 808 if ( !SDL_windowid ) {
837 if ( flags & SDL_OPENGL ) { 809 if( flags & SDL_FULLSCREEN )
838 return(-1);
839 }
840 else
841 {
842 if(flags & SDL_FULLSCREEN)
843 { 810 {
844 SDL_Window = OpenWindowTags(NULL,WA_Width,w,WA_Height,h, 811 SDL_Window = OpenWindowTags(NULL,WA_Width,w,WA_Height,h,
845 WA_Flags,WFLG_ACTIVATE|WFLG_RMBTRAP|WFLG_BORDERLESS|WFLG_BACKDROP|WFLG_REPORTMOUSE, 812 WA_Flags,WFLG_ACTIVATE|WFLG_RMBTRAP|WFLG_BORDERLESS|WFLG_BACKDROP|WFLG_REPORTMOUSE,
846 WA_IDCMP,IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE, 813 WA_IDCMP,IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE,
847 WA_CustomScreen,(ULONG)SDL_Display, 814 WA_CustomScreen,(ULONG)SDL_Display,
848 TAG_DONE); 815 TAG_DONE);
849 816
850 D(bug("Apro finestra backdrop %ldx%ld su %lx!\n",w,h,SDL_Display)); 817 D(bug("Opening backdrop window %ldx%ld on display %lx!\n",w,h,SDL_Display));
851 } 818 }
852 else 819 else
853 { 820 {
821 /* Create GimmeZeroZero window when OpenGL is used */
822 unsigned long gzz = FALSE;
823 if( flags & SDL_OPENGL ) {
824 gzz = TRUE;
825 }
826
854 SDL_Window = OpenWindowTags(NULL,WA_InnerWidth,w,WA_InnerHeight,h, 827 SDL_Window = OpenWindowTags(NULL,WA_InnerWidth,w,WA_InnerHeight,h,
855 WA_Flags,WFLG_REPORTMOUSE|WFLG_ACTIVATE|WFLG_RMBTRAP | ((flags&SDL_NOFRAME) ? 0 : (WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_DRAGBAR | ((flags&SDL_RESIZABLE) ? WFLG_SIZEGADGET|WFLG_SIZEBBOTTOM : 0))), 828 WA_Flags,WFLG_REPORTMOUSE|WFLG_ACTIVATE|WFLG_RMBTRAP | ((flags&SDL_NOFRAME) ? 0 : (WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_DRAGBAR | ((flags&SDL_RESIZABLE) ? WFLG_SIZEGADGET|WFLG_SIZEBBOTTOM : 0))),
856 WA_IDCMP,IDCMP_RAWKEY|IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_NEWSIZE|IDCMP_MOUSEMOVE, 829 WA_IDCMP,IDCMP_RAWKEY|IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS|IDCMP_NEWSIZE|IDCMP_MOUSEMOVE,
857 WA_PubScreen,(ULONG)SDL_Display, 830 WA_PubScreen,(ULONG)SDL_Display,
831 WA_GimmeZeroZero, gzz,
858 TAG_DONE); 832 TAG_DONE);
859 D(bug("Apro finestra %ldx%ld sul wb!\n",w,h)); 833 D(bug("Opening WB window of size: %ldx%ld!\n",w,h));
860 } 834 }
861
862 }
863 /* Only manage our input if we own the window */
864 /*
865 XSelectInput(SDL_Display, SDL_Window,
866 ( EnterWindowMask | LeaveWindowMask
867 | ButtonPressMask | ButtonReleaseMask
868 | PointerMotionMask | ExposureMask ));
869 */
870 835
871 if(!SDL_Window) 836 if(!SDL_Window)
872 return -1; 837 return -1;
873 } 838 }
874 839
883 } 848 }
884 else 849 else
885 return -1; 850 return -1;
886 } 851 }
887 else SDL_RastPort=SDL_Window->RPort; 852 else SDL_RastPort=SDL_Window->RPort;
888 #if 0
889
890 if(screen->flags & SDL_HWPALETTE) {
891 /* Since the full-screen window might have got a nonzero background
892 colour (0 is white on some displays), we should reset the
893 background to 0 here since that is what the user expects
894 with a private colormap */
895 SetAPen(SDL_Window->RPort,0);
896 RectFill(SDL_Window->RPort,SDL_Window->BorderLeft,SDL_Window->BorderTop,w+SDL_Window->BorderLeft,h+SDL_Window->BorderTop);
897 }
898 #endif
899 853
900 if(flags&SDL_HWSURFACE) 854 if(flags&SDL_HWSURFACE)
901 screen->flags|=SDL_HWSURFACE; 855 screen->flags|=SDL_HWSURFACE;
902 856
903 if( !SDL_windowid ) { 857 if( !SDL_windowid ) {
926 screen->w = w; 880 screen->w = w;
927 screen->h = h; 881 screen->h = h;
928 screen->pitch = SDL_CalculatePitch(screen); 882 screen->pitch = SDL_CalculatePitch(screen);
929 CGX_ResizeImage(this, screen, flags); 883 CGX_ResizeImage(this, screen, flags);
930 884
931 return(0); 885 /* Make OpenGL Context if needed*/
886 if(flags & SDL_OPENGL) {
887 if(this->gl_data->gl_active == 0) {
888 if(CGX_GL_Init(this) < 0)
889 return -1;
890 else
891 screen->flags |= SDL_OPENGL;
892 }
893 else {
894 if(CGX_GL_Update(this) < 0)
895 return -1;
896 else
897 screen->flags |= SDL_OPENGL;
898 }
899 }
932 } 900 }
933 901
934 int CGX_ResizeWindow(_THIS, 902 int CGX_ResizeWindow(_THIS,
935 SDL_Surface *screen, int w, int h, Uint32 flags) 903 SDL_Surface *screen, int w, int h, Uint32 flags)
936 { 904 {
905 D(bug("CGX_ResizeWindow\n"));
906
937 if ( ! SDL_windowid ) { 907 if ( ! SDL_windowid ) {
938 /* Resize the window manager window */ 908 /* Resize the window manager window */
939 CGX_SetSizeHints(this, w, h, flags); 909 CGX_SetSizeHints(this, w, h, flags);
940 current_w = w; 910 current_w = w;
941 current_h = h; 911 current_h = h;
942 912
943 ChangeWindowBox(SDL_Window,SDL_Window->LeftEdge,SDL_Window->TopEdge, w+SDL_Window->BorderLeft+SDL_Window->BorderRight, 913 ChangeWindowBox(SDL_Window,SDL_Window->LeftEdge,SDL_Window->TopEdge, w+SDL_Window->BorderLeft+SDL_Window->BorderRight,
944 h+SDL_Window->BorderTop+SDL_Window->BorderBottom); 914 h+SDL_Window->BorderTop+SDL_Window->BorderBottom);
945 915
946 /* Resize the fullscreen and display windows */
947 /*
948 if ( flags & SDL_FULLSCREEN ) {
949 if ( screen->flags & SDL_FULLSCREEN ) {
950 CGX_ResizeFullScreen(this);
951 } else {
952 screen->flags |= SDL_FULLSCREEN;
953 CGX_EnterFullScreen(this);
954 }
955 } else {
956 if ( screen->flags & SDL_FULLSCREEN ) {
957 screen->flags &= ~SDL_FULLSCREEN;
958 CGX_LeaveFullScreen(this);
959 }
960 }
961 */
962 screen->w = w; 916 screen->w = w;
963 screen->h = h; 917 screen->h = h;
964 screen->pitch = SDL_CalculatePitch(screen); 918 screen->pitch = SDL_CalculatePitch(screen);
965 CGX_ResizeImage(this, screen, flags); 919 CGX_ResizeImage(this, screen, flags);
966 } 920 }
971 int width, int height, int bpp, Uint32 flags) 925 int width, int height, int bpp, Uint32 flags)
972 { 926 {
973 Uint32 saved_flags; 927 Uint32 saved_flags;
974 int needcreate=0; 928 int needcreate=0;
975 929
930 D(bug("CGX_SetVideoMode current:%lx\n",current));
931
976 /* Lock the event thread, in multi-threading environments */ 932 /* Lock the event thread, in multi-threading environments */
977 SDL_Lock_EventThread(); 933 SDL_Lock_EventThread();
978 934
979 // Check if the window needs to be closed or can be resized 935 // Check if the window needs to be closed or can be resized
980 936
981 if( (flags&SDL_FULLSCREEN) || (current->flags&SDL_FULLSCREEN && !(flags&SDL_FULLSCREEN))) 937 if( (flags&SDL_FULLSCREEN) || (current && current->flags&SDL_FULLSCREEN && !(flags&SDL_FULLSCREEN)))
982 needcreate=1; 938 needcreate=1;
983 939
984 // Check if we need to close an already existing videomode... 940 // Check if we need to close an already existing videomode...
985 941
986 if(current->flags&SDL_FULLSCREEN && !(flags&SDL_FULLSCREEN)) 942 if(current && current->flags&SDL_FULLSCREEN && !(flags&SDL_FULLSCREEN)) {
987 {
988 unsigned long i; 943 unsigned long i;
944 D(bug("Destroying image, window & screen!\n"));
945
989 CGX_DestroyImage(this,current); 946 CGX_DestroyImage(this,current);
990 CGX_DestroyWindow(this,current); 947 CGX_DestroyWindow(this,current);
991 DestroyScreen(this); 948 DestroyScreen(this);
992 D(bug("Distrutte immagine, finestra e schermo!\n"));
993 GFX_Display=SDL_Display=LockPubScreen(NULL); 949 GFX_Display=SDL_Display=LockPubScreen(NULL);
994 950
995 bpp=this->hidden->depth=GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH); 951 bpp=this->hidden->depth=GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH);
996 952
997 for ( i = 0; i < this->hidden->nvisuals; i++ ) { 953 for ( i = 0; i < this->hidden->nvisuals; i++ ) {
1002 SDL_SetError("No matching visual for requested depth"); 958 SDL_SetError("No matching visual for requested depth");
1003 return NULL; /* should never happen */ 959 return NULL; /* should never happen */
1004 } 960 }
1005 SDL_Visual = this->hidden->visuals[i].visual; 961 SDL_Visual = this->hidden->visuals[i].visual;
1006 962
1007 D(bug("Setto la profiondita' dello schermo a: %ld\n",this->hidden->depth)); 963 D(bug("Setting screen depth to: %ld\n",this->hidden->depth));
1008 964
1009 } 965 }
1010 /* Check the combination of flags we were passed */ 966 /* Check the combination of flags we were passed */
1011 if ( flags & SDL_FULLSCREEN ) { 967 if ( flags & SDL_FULLSCREEN ) {
1012 int i; 968 int i;
1013 969
1014 /* Clear fullscreen flag if not supported */ 970 /* Clear fullscreen flag if not supported */
1015 if ( SDL_windowid ) { 971 if ( SDL_windowid ) {
1016 flags &= ~SDL_FULLSCREEN; 972 flags &= ~SDL_FULLSCREEN;
1017 } 973 }
1018 else if(current->flags&SDL_FULLSCREEN ) 974 else if(current && current->flags&SDL_FULLSCREEN ) {
1019 {
1020 if(current->w!=width || 975 if(current->w!=width ||
1021 current->h!=height || 976 current->h!=height ||
1022 this->hidden->depth!=bpp) 977 (this->hidden && this->hidden->depth!=bpp))
1023 { 978 {
979 D(bug("Deleting previous window...\n"));
1024 CGX_DestroyImage(this,current); 980 CGX_DestroyImage(this,current);
1025 CGX_DestroyWindow(this,current); 981 CGX_DestroyWindow(this,current);
1026 DestroyScreen(this); 982 DestroyScreen(this);
1027 goto buildnewscreen; 983 goto buildnewscreen;
1028 } 984 }
1035 CYBRBIDTG_Depth,bpp, 991 CYBRBIDTG_Depth,bpp,
1036 TAG_DONE); 992 TAG_DONE);
1037 993
1038 GFX_Display=NULL; 994 GFX_Display=NULL;
1039 995
996 D(bug("Opening screen...\n"));
997
1040 if(okid!=INVALID_ID) 998 if(okid!=INVALID_ID)
1041 {
1042 GFX_Display=OpenScreenTags(NULL, 999 GFX_Display=OpenScreenTags(NULL,
1043 SA_Width,width, 1000 SA_Width,width,
1044 SA_Height,height, 1001 SA_Height,height,
1045 SA_Quiet,TRUE,SA_ShowTitle,FALSE, 1002 SA_Quiet,TRUE,SA_ShowTitle,FALSE,
1046 SA_Depth,bpp, 1003 SA_Depth,bpp,
1047 SA_DisplayID,okid, 1004 SA_DisplayID,okid,
1048 TAG_DONE); 1005 TAG_DONE);
1049 } 1006
1050 1007 if(!GFX_Display) {
1051
1052 if(!GFX_Display)
1053 {
1054 GFX_Display=SDL_Display; 1008 GFX_Display=SDL_Display;
1055 flags &= ~SDL_FULLSCREEN; 1009 flags &= ~SDL_FULLSCREEN;
1056 flags &= ~SDL_DOUBLEBUF; 1010 flags &= ~SDL_DOUBLEBUF;
1057 } 1011 }
1058 else 1012 else {
1059 {
1060 UnlockPubScreen(NULL,SDL_Display); 1013 UnlockPubScreen(NULL,SDL_Display);
1061 SDL_Display=GFX_Display; 1014 SDL_Display=GFX_Display;
1062 1015
1063 if(flags&SDL_DOUBLEBUF) 1016 D(bug("Screen opened.\n"));
1064 { 1017
1018 if(flags&SDL_DOUBLEBUF) {
1065 int ok=0; 1019 int ok=0;
1066 1020 D(bug("Start of DBuffering allocations...\n"));
1067 if(this->hidden->SB[0]=AllocScreenBuffer(SDL_Display,NULL,SB_SCREEN_BITMAP)) 1021
1068 { 1022 if(this->hidden->SB[0]=AllocScreenBuffer(SDL_Display,NULL,SB_SCREEN_BITMAP)) {
1069 if(this->hidden->SB[1]=AllocScreenBuffer(SDL_Display,NULL,0L)) 1023
1070 { 1024 if(this->hidden->SB[1]=AllocScreenBuffer(SDL_Display,NULL,0L)) {
1071 extern struct MsgPort *safeport,*dispport; 1025 extern struct MsgPort *safeport,*dispport;
1072 1026
1073 safeport=CreateMsgPort(); 1027 safeport=CreateMsgPort();
1074 dispport=CreateMsgPort(); 1028 dispport=CreateMsgPort();
1075 1029
1076 if(!safeport || !dispport) 1030 if(!safeport || !dispport) {
1077 { 1031 if(safeport) {
1078 if(safeport)
1079 {
1080 DeleteMsgPort(safeport); 1032 DeleteMsgPort(safeport);
1081 safeport=NULL; 1033 safeport=NULL;
1082 } 1034 }
1083 if(dispport) 1035 if(dispport) {
1084 {
1085 DeleteMsgPort(dispport); 1036 DeleteMsgPort(dispport);
1086 dispport=NULL; 1037 dispport=NULL;
1087 } 1038 }
1088 FreeScreenBuffer(SDL_Display,this->hidden->SB[0]); 1039 FreeScreenBuffer(SDL_Display,this->hidden->SB[0]);
1089 FreeScreenBuffer(SDL_Display,this->hidden->SB[1]); 1040 FreeScreenBuffer(SDL_Display,this->hidden->SB[1]);
1090 } 1041 }
1091 else 1042 else {
1092 {
1093 extern ULONG safe_sigbit,disp_sigbit; 1043 extern ULONG safe_sigbit,disp_sigbit;
1094 int i; 1044 int i;
1095 1045
1096 safe_sigbit=1L<< safeport->mp_SigBit; 1046 safe_sigbit=1L<< safeport->mp_SigBit;
1097 disp_sigbit=1L<< dispport->mp_SigBit; 1047 disp_sigbit=1L<< dispport->mp_SigBit;
1098 1048
1099 for(i=0;i<2;i++) 1049 for(i=0;i<2;i++) {
1100 {
1101 this->hidden->SB[i]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=safeport; 1050 this->hidden->SB[i]->sb_DBufInfo->dbi_SafeMessage.mn_ReplyPort=safeport;
1102 this->hidden->SB[i]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=dispport; 1051 this->hidden->SB[i]->sb_DBufInfo->dbi_DispMessage.mn_ReplyPort=dispport;
1103 } 1052 }
1104 1053
1105 ok=1; 1054 ok=1;
1106 D(bug("Dbuffering enabled!\n")); 1055 D(bug("Dbuffering enabled!\n"));
1107 this->hidden->dbuffer=1; 1056 this->hidden->dbuffer=1;
1108 current->flags|=SDL_DOUBLEBUF; 1057 current->flags|=SDL_DOUBLEBUF;
1109 } 1058 }
1110 } 1059 }
1111 else 1060 else {
1112 {
1113 FreeScreenBuffer(SDL_Display,this->hidden->SB[1]); 1061 FreeScreenBuffer(SDL_Display,this->hidden->SB[1]);
1114 this->hidden->SB[0]=NULL; 1062 this->hidden->SB[0]=NULL;
1115 } 1063 }
1116 } 1064 }
1117 1065
1118 if(!ok) 1066 if(!ok)
1119 {
1120 flags&=~SDL_DOUBLEBUF; 1067 flags&=~SDL_DOUBLEBUF;
1121 }
1122 } 1068 }
1123 } 1069 }
1124 1070
1125 if(GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH)==bpp) 1071 if(GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH)==bpp)
1126 this->hidden->same_format=1; 1072 this->hidden->same_format=1;
1127 } 1073 }
1128 1074
1129 bpp=this->hidden->depth=GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH); 1075 bpp=this->hidden->depth=GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_DEPTH);
1130 D(bug("Setto la profiondita' dello schermo a: %ld\n",this->hidden->depth)); 1076 D(bug("Setting screen depth to: %ld\n",this->hidden->depth));
1131 1077
1132 for ( i = 0; i < this->hidden->nvisuals; i++ ) { 1078 for ( i = 0; i < this->hidden->nvisuals; i++ )
1133 if ( this->hidden->visuals[i].depth == bpp ) /* era .depth */ 1079 if ( this->hidden->visuals[i].depth == bpp ) /* era .depth */
1134 break; 1080 break;
1135 } 1081
1136 if ( i == this->hidden->nvisuals ) { 1082 if ( i == this->hidden->nvisuals ) {
1137 SDL_SetError("No matching visual for requested depth"); 1083 SDL_SetError("No matching visual for requested depth");
1138 return NULL; /* should never happen */ 1084 return NULL; /* should never happen */
1139 } 1085 }
1140 SDL_Visual = this->hidden->visuals[i].visual; 1086 SDL_Visual = this->hidden->visuals[i].visual;
1200 CGX_EnterFullScreen(this); 1146 CGX_EnterFullScreen(this);
1201 } else { 1147 } else {
1202 this->screen->flags &= ~SDL_FULLSCREEN; 1148 this->screen->flags &= ~SDL_FULLSCREEN;
1203 CGX_LeaveFullScreen(this); 1149 CGX_LeaveFullScreen(this);
1204 } 1150 }
1151
1205 CGX_RefreshDisplay(this); 1152 CGX_RefreshDisplay(this);
1206 if ( event_thread ) { 1153 if ( event_thread ) {
1207 SDL_Unlock_EventThread(); 1154 SDL_Unlock_EventThread();
1208 } 1155 }
1156
1209 SDL_ResetKeyboard(); 1157 SDL_ResetKeyboard();
1158
1210 return(1); 1159 return(1);
1211 } 1160 }
1212 1161
1213 static void SetSingleColor(Uint32 fmt, unsigned char r, unsigned char g, unsigned char b, unsigned char *c) 1162 static void SetSingleColor(Uint32 fmt, unsigned char r, unsigned char g, unsigned char b, unsigned char *c)
1214 { 1163 {
1272 c[2]=b; 1221 c[2]=b;
1273 c[3]=0; 1222 c[3]=0;
1274 break; 1223 break;
1275 1224
1276 default: 1225 default:
1277 D(bug("Errore, SetSingleColor con PIXFMT %ld!\n",fmt)); 1226 D(bug("Error, SetSingleColor with PIXFMT %ld!\n",fmt));
1278 } 1227 }
1279 } 1228 }
1280 1229
1281 /* Update the current mouse state and position */ 1230 /* Update the current mouse state and position */
1282 static void CGX_UpdateMouse(_THIS) 1231 static void CGX_UpdateMouse(_THIS)
1290 SDL_PrivateMouseMotion(0, 0, SDL_Display->MouseX, SDL_Display->MouseY); 1239 SDL_PrivateMouseMotion(0, 0, SDL_Display->MouseX, SDL_Display->MouseY);
1291 } 1240 }
1292 else 1241 else
1293 { 1242 {
1294 if( SDL_Display->MouseX>=(SDL_Window->LeftEdge+SDL_Window->BorderLeft) && SDL_Display->MouseX<(SDL_Window->LeftEdge+SDL_Window->Width-SDL_Window->BorderRight) && 1243 if( SDL_Display->MouseX>=(SDL_Window->LeftEdge+SDL_Window->BorderLeft) && SDL_Display->MouseX<(SDL_Window->LeftEdge+SDL_Window->Width-SDL_Window->BorderRight) &&
1295 SDL_Display->MouseY>=(SDL_Window->TopEdge+SDL_Window->BorderLeft) && SDL_Display->MouseY<(SDL_Window->TopEdge+SDL_Window->Height-SDL_Window->BorderBottom) 1244 SDL_Display->MouseY>=(SDL_Window->TopEdge+SDL_Window->BorderLeft) && SDL_Display->MouseY<(SDL_Window->TopEdge+SDL_Window->Height-SDL_Window->BorderBottom)
1296 ) 1245 )
1297 { 1246 {
1298 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS); 1247 SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
1299 SDL_PrivateMouseMotion(0, 0, SDL_Display->MouseX-SDL_Window->LeftEdge-SDL_Window->BorderLeft, 1248 SDL_PrivateMouseMotion(0, 0, SDL_Display->MouseX-SDL_Window->LeftEdge-SDL_Window->BorderLeft,
1300 SDL_Display->MouseY-SDL_Window->TopEdge-SDL_Window->BorderTop); 1249 SDL_Display->MouseY-SDL_Window->TopEdge-SDL_Window->BorderTop);
1301 } 1250 }
1302 else 1251 else
1303 { 1252 {
1304 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS); 1253 SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
1312 int i; 1261 int i;
1313 1262
1314 /* Check to make sure we have a colormap allocated */ 1263 /* Check to make sure we have a colormap allocated */
1315 1264
1316 /* It's easy if we have a hidden colormap */ 1265 /* It's easy if we have a hidden colormap */
1317 if ( (this->screen->flags & SDL_HWPALETTE) && currently_fullscreen ) 1266 if ( (this->screen->flags & SDL_HWPALETTE) && currently_fullscreen )
1318 { 1267 {
1319 ULONG xcmap[256*3+2]; 1268 ULONG xcmap[256*3+2];
1320 1269
1321 xcmap[0]=(ncolors<<16); 1270 xcmap[0]=(ncolors<<16);
1322 xcmap[0]+=firstcolor; 1271 xcmap[0]+=firstcolor;
1341 1290
1342 if(this->hidden->depth==8) 1291 if(this->hidden->depth==8)
1343 { 1292 {
1344 // In this case I have to unalloc and realloc the full palette 1293 // In this case I have to unalloc and realloc the full palette
1345 D(bug("Obtaining %ld colors on the screen\n",ncolors)); 1294 D(bug("Obtaining %ld colors on the screen\n",ncolors));
1346 1295
1347 /* Free existing allocated colors */ 1296 /* Free existing allocated colors */
1348 for ( pixel=0; pixel<this->screen->format->palette->ncolors; ++pixel ) { 1297 for ( pixel=0; pixel<this->screen->format->palette->ncolors; ++pixel ) {
1349 if(SDL_XPixels[pixel]>=0) 1298 if(SDL_XPixels[pixel]>=0)
1350 ReleasePen(GFX_Display->ViewPort.ColorMap,SDL_XPixels[pixel]); 1299 ReleasePen(GFX_Display->ViewPort.ColorMap,SDL_XPixels[pixel]);
1351 } 1300 }
1354 for ( i=0; i<this->screen->format->palette->ncolors; ++i ) { 1303 for ( i=0; i<this->screen->format->palette->ncolors; ++i ) {
1355 SDL_XPixels[i]=ObtainBestPenA(GFX_Display->ViewPort.ColorMap,colors[i].r<<24,colors[i].g<<24,colors[i].b<<24,NULL); 1304 SDL_XPixels[i]=ObtainBestPenA(GFX_Display->ViewPort.ColorMap,colors[i].r<<24,colors[i].g<<24,colors[i].b<<24,NULL);
1356 } 1305 }
1357 } 1306 }
1358 else 1307 else
1359 { 1308 {
1360 #ifndef USE_CGX_WRITELUTPIXEL 1309 #ifndef USE_CGX_WRITELUTPIXEL
1361 Uint32 fmt; 1310 Uint32 fmt;
1362 D(bug("Preparing a conversion pixel table...\n")); 1311 D(bug("Preparing a conversion pixel table...\n"));
1363 1312
1364 fmt=GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_PIXFMT); 1313 fmt=GetCyberMapAttr(SDL_Display->RastPort.BitMap,CYBRMATTR_PIXFMT);
1366 for(i=0;i<ncolors;i++) 1315 for(i=0;i<ncolors;i++)
1367 { 1316 {
1368 SetSingleColor(fmt,colors[firstcolor+i].r,colors[firstcolor+i].g,colors[firstcolor+i].b,(unsigned char *)&SDL_XPixels[firstcolor+i]); 1317 SetSingleColor(fmt,colors[firstcolor+i].r,colors[firstcolor+i].g,colors[firstcolor+i].b,(unsigned char *)&SDL_XPixels[firstcolor+i]);
1369 } 1318 }
1370 #else 1319 #else
1371 // D(bug("Eseguo remap degli XPixel(%lx): (da %ld, %ld colori) primo: r%ld g%ld b%ld\n",SDL_XPixels,firstcolor,ncolors,colors[firstcolor].r,colors[firstcolor].g,colors[firstcolor].b)); 1320 // D(bug("Executing XPixel(%lx) remapping: (from %ld, %ld colors) first: r%ld g%ld b%ld\n",SDL_XPixels,firstcolor,ncolors,colors[firstcolor].r,colors[firstcolor].g,colors[firstcolor].b));
1372 for(i=0;i<ncolors;i++) 1321 for(i=0;i<ncolors;i++)
1373 SDL_XPixels[i+firstcolor]=(colors[firstcolor+i].r<<16)+(colors[firstcolor+i].g<<8)+colors[firstcolor+i].b; 1322 SDL_XPixels[i+firstcolor]=(colors[firstcolor+i].r<<16)+(colors[firstcolor+i].g<<8)+colors[firstcolor+i].b;
1374 #endif 1323 #endif
1375 } 1324 }
1376 } 1325 }
1385 */ 1334 */
1386 static void CGX_VideoQuit(_THIS) 1335 static void CGX_VideoQuit(_THIS)
1387 { 1336 {
1388 /* Shutdown everything that's still up */ 1337 /* Shutdown everything that's still up */
1389 /* The event thread should be done, so we can touch SDL_Display */ 1338 /* The event thread should be done, so we can touch SDL_Display */
1339 D(bug("CGX_VideoQuit\n"));
1340
1390 if ( SDL_Display != NULL ) { 1341 if ( SDL_Display != NULL ) {
1391 /* Clean up OpenGL */ 1342 /* Clean up OpenGL */
1392 1343 if(this->gl_data->gl_active == 1) {
1344 CGX_GL_Quit(this);
1345 }
1393 /* Start shutting down the windows */ 1346 /* Start shutting down the windows */
1347 D(bug("Destroying image...\n"));
1394 CGX_DestroyImage(this, this->screen); 1348 CGX_DestroyImage(this, this->screen);
1349 D(bug("Destroying window...\n"));
1395 CGX_DestroyWindow(this, this->screen); 1350 CGX_DestroyWindow(this, this->screen);
1396 // Otherwise SDL_VideoQuit will try to free it! 1351 // Otherwise SDL_VideoQuit will try to free it!
1397 SDL_VideoSurface=NULL; 1352 SDL_VideoSurface=NULL;
1353
1398 CGX_FreeVideoModes(this); 1354 CGX_FreeVideoModes(this);
1399 1355
1400 /*
1401 if ( SDL_iconcolors ) {
1402 unsigned long pixel;
1403 int numcolors =
1404 ((this->screen->format)->palette)->ncolors;
1405 for ( pixel=0; pixel<numcolors; ++pixel ) {
1406 while ( SDL_iconcolors[pixel] > 0 ) {
1407 XFreeColors(SDL_Display,
1408 SDL_DisplayColormap,&pixel,1,0);
1409 --SDL_iconcolors[pixel];
1410 }
1411 }
1412 free(SDL_iconcolors);
1413 SDL_iconcolors = NULL;
1414 }
1415 */
1416 /* Free that blank cursor */ 1356 /* Free that blank cursor */
1417 if ( SDL_BlankCursor != NULL ) { 1357 if ( SDL_BlankCursor != NULL ) {
1418 FreeMem(SDL_BlankCursor,16); 1358 FreeMem(SDL_BlankCursor,16);
1419 SDL_BlankCursor = NULL; 1359 SDL_BlankCursor = NULL;
1420 } 1360 }
1421 1361
1422 /* Close the X11 graphics connection */ 1362 /* Close the X11 graphics connection */
1423 this->hidden->same_format=0; 1363 this->hidden->same_format=0;
1424 1364
1365 D(bug("Destroying screen...\n"));
1366
1425 if ( GFX_Display != NULL ) 1367 if ( GFX_Display != NULL )
1426 DestroyScreen(this); 1368 DestroyScreen(this);
1427 1369
1428 /* Close the X11 display connection */ 1370 /* Close the X11 display connection */
1429 SDL_Display = NULL; 1371 SDL_Display = NULL;
1430 1372
1431 /* Unload GL library after X11 shuts down */ 1373 /* Unload GL library after X11 shuts down */
1432 } 1374 }
1433 1375
1434 if( CyberGfxBase) 1376 D(bug("Closing libraries...\n"));
1435 { 1377
1378 if( CyberGfxBase) {
1436 CloseLibrary(CyberGfxBase); 1379 CloseLibrary(CyberGfxBase);
1437 CyberGfxBase=NULL; 1380 CyberGfxBase=NULL;
1438 } 1381 }
1439 1382
1440 if (IntuitionBase) 1383 if (IntuitionBase) {
1441 {
1442 CloseLibrary((struct Library *)IntuitionBase); 1384 CloseLibrary((struct Library *)IntuitionBase);
1443 IntuitionBase=NULL; 1385 IntuitionBase=NULL;
1444 } 1386 }
1445 if (GfxBase) 1387 if (GfxBase) {
1446 {
1447 CloseLibrary((struct Library *)GfxBase); 1388 CloseLibrary((struct Library *)GfxBase);
1448 GfxBase=NULL; 1389 GfxBase=NULL;
1449 } 1390 }
1450 1391
1451 if ( this->screen && (this->screen->flags & SDL_HWSURFACE) ) { 1392 if ( this->screen && (this->screen->flags & SDL_HWSURFACE) ) {
1452 /* Direct screen access, no memory buffer */ 1393 /* Direct screen access, no memory buffer */
1453 this->screen->pixels = NULL; 1394 this->screen->pixels = NULL;
1454 } 1395 }
1455 } 1396 D(bug("End of CGX_VideoQuit.\n"));
1456 1397
1398 }
1399