diff src/video/photon/SDL_ph_video.c @ 315:3333b6e68289

Date: Sat, 23 Mar 2002 13:53:37 +0200 From: "Mike Gorchak" <mike@malva.ua> Subject: Big QNX patch again. Added 8bit palette emulation code for window mode with bpp>=15. Added store/restore original palette for 8bit modes. Added more information about photon API call fails. Rewroten change palette code, slow but works. Fixed bug with set caption before window was inited. Fixed bugs with some initial state of variables. Fixed bug with storing old video mode settings. Fixed bug with switching to fullscreen mode and back. Fixed few double SEGFAULTS during parachute mode. Removed compilation warning with no PgWaitHWIdle prototype. Removed pack of dead unusable code. Cleanups SDL_PrivateVideoData structure, some headers. Some code formatting.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 23 Mar 2002 20:19:44 +0000
parents 2de77f7b7a28
children 66f815c147ed
line wrap: on
line diff
--- a/src/video/photon/SDL_ph_video.c	Fri Mar 22 18:11:56 2002 +0000
+++ b/src/video/photon/SDL_ph_video.c	Sat Mar 23 20:19:44 2002 +0000
@@ -150,8 +150,8 @@
 }
 
 VideoBootStrap ph_bootstrap = {
-        "photon", "QNX Photon video output",
-	ph_Available, ph_CreateDevice
+    "photon", "QNX Photon video output",
+    ph_Available, ph_CreateDevice
 };
 
 static void ph_DeleteDevice(SDL_VideoDevice *device)
@@ -175,7 +175,6 @@
 
 static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
 {
-    PgColor_t ph_palette[_Pg_MAX_PALETTE];
     int i;
     unsigned long *tempptr;
     int rtnval;
@@ -184,6 +183,11 @@
 
     window=NULL;
     oglctx=NULL;
+    desktoppal=SDLPH_PAL_NONE;
+    
+    captionflag=0;
+    old_video_mode=-1;
+    old_refresh_rate=-1;
 	
     if (NULL == (event = malloc(EVENT_SIZE)))
     {
@@ -213,6 +217,7 @@
     /* We need to return BytesPerPixel as it in used by CreateRGBsurface */
     vformat->BitsPerPixel = my_mode_info.bits_per_pixel;
     vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width;
+    desktopbpp = my_mode_info.bits_per_pixel;
          
     /* return a palette if we are in 256 color mode */
     if (vformat->BitsPerPixel == 8)
@@ -253,7 +258,6 @@
     PtArg_t arg[32];
     PhDim_t dim;
     int rtnval;
-    PgColor_t ph_palette[_Pg_MAX_PALETTE];
     int i;
     unsigned long *tempptr;
     int pargc;
@@ -281,7 +285,7 @@
 
         window=PtCreateWidget(PtWindow, NULL, pargc-1, arg);
         PtRealizeWidget(window);
-
+        
         PtFlush();
     }
 
@@ -330,21 +334,30 @@
                     exit(1);
                 }
             }
+            
+            if (bpp==8)
+            {
+               desktoppal=SDLPH_PAL_SYSTEM;
+            }
+            
+            /* save old video mode caps */
+            PgGetVideoMode(&settings);
+            old_video_mode=settings.mode;
+            old_refresh_rate=settings.refresh;
+
+            /* setup new video mode */
             settings.mode = mode;
             settings.refresh = 0;
-            settings.flags  = 0;       
+            settings.flags = 0;
 
-            if (PgSetVideoMode( &settings ) < 0)
+            if (PgSetVideoMode(&settings) < 0)
             {
                 fprintf(stderr,"error: PgSetVideoMode failed\n");
             }
 
-            /* Get the true height and width */
-
             current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
 
             /* Begin direct mode */
-
             ph_EnterFullScreen(this);
 
         } /* end fullscreen flag */
@@ -359,6 +372,22 @@
             {
                 current->flags = (flags | SDL_RESIZABLE); /* yes we can resize as this is a software surface */
             }
+            /* using palette emulation code in window mode */
+            if (bpp==8)
+            {
+                if (desktopbpp>=15)
+                {
+                    desktoppal=SDLPH_PAL_EMULATE;
+                }
+                else
+                {
+                    desktoppal=SDLPH_PAL_SYSTEM;
+                }
+            }
+            else
+            {
+               desktoppal=SDLPH_PAL_NONE;
+            }
         }
 
 	/* If we are setting video to use the palette make sure we have allocated memory for it */
@@ -390,10 +419,16 @@
     /* Must call at least once it setup image planes */
     ph_ResizeImage(this, current, flags);
 
+    /* delayed set caption call */
+    if (captionflag)
+    {
+        ph_SetCaption(this, this->wm_title, NULL);
+    }
+
     SDL_Unlock_EventThread();
 
     /* We're done! */
-    return(current);
+    return (current);
 }
 
 static void ph_VideoQuit(_THIS)
@@ -404,19 +439,20 @@
 
     if (currently_fullscreen)
     {
-        PdDirectStop(directContext);
-        PdReleaseDirectContext(directContext);
-        directContext=0;	
-        currently_fullscreen=0;
+        ph_LeaveFullScreen(this);
     }
 
 #ifdef HAVE_OPENGL
-    if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) &&
-        ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
+    /* prevent double SEGFAULT with parachute mode */
+    if (this->screen)
     {
-        region_info.cursor_type=Ph_CURSOR_POINTER;
-        region_info.rid=PtWidgetRid(window);
-        PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);
+        if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) &&
+            ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
+        {
+            region_info.cursor_type=Ph_CURSOR_POINTER;
+            region_info.rid=PtWidgetRid(window);
+            PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);
+        }
     }
 
     PtFlush();
@@ -428,6 +464,12 @@
         PtDestroyWidget(window);
         window=NULL;
     }
+    
+    /* restore palette */
+    if (desktoppal!=SDLPH_PAL_NONE)
+    {
+        PgSetPalette(ph_palette, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
+    }
 
 #ifdef HAVE_OPENGL
     if (oglctx)
@@ -441,60 +483,58 @@
 
 static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
 {
-	PgColor_t *in, *out;
-	int i, j;
-	int alloct_all = 1;
-
-    	colors = this->screen->format->palette->colors;
-
-	in = alloca( ncolors*sizeof(PgColor_t)  );
-	if ( in == NULL  ) {
-		return 0;
-	}
-	memset(in,0,ncolors*sizeof(PgColor_t));
-
-    out = alloca( ncolors*sizeof(PgColor_t)  );
-    if ( out == NULL  ) {
-		return 0;
-    }
-	
-	for (i=0,j=firstcolor;i<ncolors;i++,j++)
-	{
-		in[i] |= colors[j].r<<16 ;
-		in[i] |= colors[j].g<<8 ;
-		in[i] |= colors[j].b ; 
-	}
+    int i;
+    PhPoint_t point={0, 0};
+    PgColor_t syspalph[_Pg_MAX_PALETTE];
 
-	if ( (this->screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) 
-	{
-		if( PgSetPalette( in, 0, 0, ncolors, Pg_PALSET_HARD, 0) < 0 )
-		{
-			fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_HARD)  failed\n");
-			return 0;
-		}  
-	}
-	else 
-	{
-		if ( PgColorMatch(ncolors, in, out) < 0 )
+    /* palette emulation code, using palette of the PhImage_t struct */
+    if (desktoppal==SDLPH_PAL_EMULATE)
+    {
+        if ((SDL_Image) && (SDL_Image->palette))
         {
-            fprintf(stderr,"error: PgColorMatch failed\n");
-            return 0;
+            for (i=firstcolor; i<firstcolor+ncolors; i++)
+            {
+                SDL_Image->palette[i]  = 0x00000000UL;
+                SDL_Image->palette[i] |= colors[i-firstcolor].r<<16;
+                SDL_Image->palette[i] |= colors[i-firstcolor].g<<8;
+                SDL_Image->palette[i] |= colors[i-firstcolor].b;
+            }
         }
-		for (i=0;i<ncolors;i++)
-		{
-			if (memcmp(&in[i],&out[i],sizeof(PgColor_t)))
-			{
-				alloct_all = 0;
-				break;
-			}
-		}
-        if( PgSetPalette( out, 0, 0, ncolors, Pg_PALSET_SOFT, 0) < 0 )
+        /* image needs to be redrawed, very slow method */
+        PgDrawPhImage(&point, SDL_Image, 0);
+    }
+    else
+    {
+        if (desktoppal==SDLPH_PAL_SYSTEM)
         {
-            fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_SOFT) failed\n");
-            return 0;
+            for (i=firstcolor; i<firstcolor+ncolors; i++)
+            {
+                syspalph[i]  = 0x00000000UL;
+                syspalph[i] |= colors[i-firstcolor].r<<16;
+                syspalph[i] |= colors[i-firstcolor].g<<8;
+                syspalph[i] |= colors[i-firstcolor].b;
+            }
+
+            if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
+            {
+                /* window mode must use soft palette */
+                PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0);
+                /* image needs to be redrawed, very slow method */
+                PgDrawPhImage(&point, SDL_Image, 0);
+            }
+            else
+            {
+                /* fullscreen mode must use hardware palette */
+                PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
+            }
         }
-	}
-	return alloct_all;
+        else
+        {
+            /* SDLPH_PAL_NONE do nothing */
+        }
+    }
+    
+    return 1;
 }
 
 #ifdef HAVE_OPENGL