Date: Sat, 23 Mar 2002 13:53:37 +0200
authorSam Lantinga <slouken@libsdl.org>
Sat, 23 Mar 2002 20:19:44 +0000
changeset 3153333b6e68289
parent 314 bff64eba7721
child 316 d85fc19bf840
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.
src/video/photon/SDL_ph_image.c
src/video/photon/SDL_ph_modes.c
src/video/photon/SDL_ph_modes_c.h
src/video/photon/SDL_ph_mouse.c
src/video/photon/SDL_ph_video.c
src/video/photon/SDL_ph_video.h
src/video/photon/SDL_ph_wm.c
     1.1 --- a/src/video/photon/SDL_ph_image.c	Fri Mar 22 18:11:56 2002 +0000
     1.2 +++ b/src/video/photon/SDL_ph_image.c	Sat Mar 23 20:19:44 2002 +0000
     1.3 @@ -33,9 +33,13 @@
     1.4  #include "SDL_endian.h"
     1.5  #include "SDL_ph_image_c.h"
     1.6  
     1.7 +/* remove this line, if photon headers updates */
     1.8 +int PgWaitHWIdle(void);
     1.9 +
    1.10  int ph_SetupImage(_THIS, SDL_Surface *screen)
    1.11  {
    1.12 -    int type = 0;
    1.13 +    int type=0;
    1.14 +    PgColor_t* palette=NULL;
    1.15  
    1.16      /* Determine image type */
    1.17      switch(screen->format->BitsPerPixel)
    1.18 @@ -69,11 +73,28 @@
    1.19          break;
    1.20      }
    1.21  
    1.22 -    /* using shared memory for speed (set last param to 1) */
    1.23 -    if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL)
    1.24 +    /* palette emulation code */
    1.25 +    if ((screen->format->BitsPerPixel==8) && (desktoppal==SDLPH_PAL_EMULATE))
    1.26      {
    1.27 -        fprintf(stderr,"error: PhCreateImage failed.\n");
    1.28 -        return -1;
    1.29 +        /* creating image palette */
    1.30 +        palette=malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t));
    1.31 +        PgGetPalette(palette);
    1.32 +
    1.33 +        /* using shared memory for speed (set last param to 1) */
    1.34 +        if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL)
    1.35 +        {
    1.36 +            fprintf(stderr,"ph_SetupImage: PhCreateImage failed for bpp=8.\n");
    1.37 +            return -1;
    1.38 +        }
    1.39 +    }
    1.40 +    else
    1.41 +    {
    1.42 +        /* using shared memory for speed (set last param to 1) */
    1.43 +        if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL)
    1.44 +        {
    1.45 +            fprintf(stderr,"ph_SetupImage: PhCreateImage failed.\n");
    1.46 +            return -1;
    1.47 +        }
    1.48      }
    1.49  
    1.50      screen->pixels = SDL_Image->image;
    1.51 @@ -83,7 +104,7 @@
    1.52      return 0;
    1.53  }
    1.54  
    1.55 -int ph_SetupOCImage(_THIS, SDL_Surface *screen) //Offscreen context
    1.56 +int ph_SetupOCImage(_THIS, SDL_Surface *screen)
    1.57  {
    1.58  	int type = 0;
    1.59  
    1.60 @@ -185,11 +206,18 @@
    1.61  
    1.62      if (SDL_Image)
    1.63      {
    1.64 +        /* if palette allocated, free it */
    1.65 +        if (SDL_Image->palette)
    1.66 +        {
    1.67 +            free(SDL_Image->palette);
    1.68 +        }
    1.69          PgShmemDestroy(SDL_Image->image);
    1.70          free(SDL_Image);
    1.71 -        SDL_Image = NULL;
    1.72      }
    1.73  
    1.74 +    /* Must be zeroed everytime */
    1.75 +    SDL_Image = NULL;
    1.76 +
    1.77      if (screen)
    1.78      {
    1.79          screen->pixels = NULL;
    1.80 @@ -200,14 +228,14 @@
    1.81  {
    1.82      ph_DestroyImage(this, screen);
    1.83      
    1.84 -    if(  flags & SDL_HWSURFACE)
    1.85 +    if (flags & SDL_HWSURFACE)
    1.86      {
    1.87          OCImage.flags = flags;  /* needed for SDL_DOUBLEBUF check */
    1.88          return ph_SetupOCImage(this, screen);
    1.89      }
    1.90 -    else if(flags & SDL_OPENGL)
    1.91 +    else if (flags & SDL_OPENGL)
    1.92      {
    1.93 -       return ph_SetupOpenGLImage(this, screen);
    1.94 +        return ph_SetupOpenGLImage(this, screen);
    1.95      } 
    1.96      else
    1.97      {
    1.98 @@ -217,32 +245,32 @@
    1.99  
   1.100  int ph_AllocHWSurface(_THIS, SDL_Surface *surface)
   1.101  {
   1.102 -        return(-1);
   1.103 +    return(-1);
   1.104  }
   1.105  
   1.106  void ph_FreeHWSurface(_THIS, SDL_Surface *surface)
   1.107  {
   1.108 -        return;
   1.109 +    return;
   1.110  }
   1.111  
   1.112  int ph_FlipHWSurface(_THIS, SDL_Surface *surface)
   1.113  {
   1.114 -        return(0);
   1.115 +    return(0);
   1.116  }
   1.117  
   1.118  int ph_LockHWSurface(_THIS, SDL_Surface *surface)
   1.119  {
   1.120 -        if ( (surface == SDL_VideoSurface) && blit_queued ) {
   1.121 -//                XSync(GFX_Display, False);
   1.122 -				PgFlush();
   1.123 -                blit_queued = 0;
   1.124 -        }
   1.125 -        return(0);
   1.126 +    if ((surface == SDL_VideoSurface) && blit_queued) {
   1.127 +	PgFlush();
   1.128 +        blit_queued = 0;
   1.129 +    }
   1.130 +
   1.131 +    return(0);
   1.132  }
   1.133  
   1.134  void ph_UnlockHWSurface(_THIS, SDL_Surface *surface)
   1.135  {
   1.136 -        return;
   1.137 +    return;
   1.138  }
   1.139  
   1.140  static PhPoint_t ph_pos;
   1.141 @@ -258,80 +286,80 @@
   1.142  
   1.143  void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
   1.144  {
   1.145 -
   1.146      for ( i=0; i<numrects; ++i ) 
   1.147 -	{
   1.148 -    	if ( rects[i].w == 0 ) { /* Clipped? */
   1.149 -                continue;
   1.150 +    {
   1.151 +    	if (rects[i].w==0) /* Clipped? */
   1.152 +        { 
   1.153 +            continue;
   1.154          }
   1.155  
   1.156 -		ph_pos.x = rects[i].x;
   1.157 -		ph_pos.y = rects[i].y;
   1.158 -		ph_rect.ul.x = rects[i].x;
   1.159 -		ph_rect.ul.y = rects[i].y;
   1.160 -		ph_rect.lr.x = rects[i].x + rects[i].w;
   1.161 -		ph_rect.lr.y = rects[i].y + rects[i].h;
   1.162 +        ph_pos.x = rects[i].x;
   1.163 +        ph_pos.y = rects[i].y;
   1.164 +        ph_rect.ul.x = rects[i].x;
   1.165 +        ph_rect.ul.y = rects[i].y;
   1.166 +        ph_rect.lr.x = rects[i].x + rects[i].w;
   1.167 +        ph_rect.lr.y = rects[i].y + rects[i].h;
   1.168  
   1.169 -		if (PgDrawPhImageRectmx( &ph_pos, SDL_Image, &ph_rect, 0 ) < 0)
   1.170 -		{
   1.171 -			fprintf(stderr,"error: PgDrawPhImageRectmx failed.\n");
   1.172 -		}
   1.173 -	}
   1.174 +        if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
   1.175 +        {
   1.176 +            fprintf(stderr,"ph_NormalUpdate: PgDrawPhImageRectmx failed.\n");
   1.177 +        }
   1.178 +    }
   1.179 +
   1.180      if (PgFlush() < 0)
   1.181      {
   1.182 -    	fprintf(stderr,"error: PgFlush failed.\n");
   1.183 +    	fprintf(stderr,"ph_NormalUpdate: PgFlush failed.\n");
   1.184      }
   1.185  }
   1.186  void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
   1.187  {
   1.188 -	PhPoint_t zero = {0};
   1.189 -	PhRect_t src_rect;
   1.190 -	PhRect_t dest_rect;
   1.191 +    PhPoint_t zero = {0};
   1.192 +    PhRect_t src_rect;
   1.193 +    PhRect_t dest_rect;
   1.194 +
   1.195 +    if(OCImage.direct_context == NULL)
   1.196 +    {
   1.197 +        return;
   1.198 +    }
   1.199  
   1.200 -	if(OCImage.direct_context == NULL)
   1.201 -	 {
   1.202 -	    return;
   1.203 -	 }   
   1.204 -	   		
   1.205 -	  PgSetRegion(PtWidgetRid(window));
   1.206 -	  PgSetClipping(0,NULL);
   1.207 -	  PgWaitHWIdle();
   1.208 - 		
   1.209 +    PgSetRegion(PtWidgetRid(window));
   1.210 +    PgSetClipping(0,NULL);
   1.211 +    PgWaitHWIdle();
   1.212  
   1.213 -    for ( i=0; i<numrects; ++i ) 
   1.214 -	{
   1.215 -    	if ( rects[i].w == 0 ) { /* Clipped? */
   1.216 -                continue;
   1.217 +    for (i=0; i<numrects; ++i)
   1.218 +    {
   1.219 +        if (rects[i].w == 0)  /* Clipped? */
   1.220 +        {
   1.221 +            continue;
   1.222          }
   1.223  
   1.224 -			src_rect.ul.x=rects[i].x;
   1.225 -			src_rect.ul.y=rects[i].y;
   1.226 -			dest_rect.ul.x=rects[i].x;
   1.227 -			dest_rect.ul.y=rects[i].y;
   1.228 -			
   1.229 -			dest_rect.lr.x=src_rect.lr.x= rects[i].x +rects[i].w;
   1.230 -			dest_rect.lr.y=src_rect.lr.y= rects[i].y +rects[i].h;
   1.231 -		
   1.232 -			zero.x = zero.y = 0;
   1.233 -	   		PgSetTranslation (&zero, 0);
   1.234 -	                PgSetRegion(PtWidgetRid(window));
   1.235 -			PgSetClipping(0,NULL);
   1.236 - 			PgContextBlitArea(OCImage.offscreen_context, (PhArea_t *)(&src_rect), NULL, (PhArea_t *)(&dest_rect));
   1.237 - 			
   1.238 -	}
   1.239 +        src_rect.ul.x=rects[i].x;
   1.240 +        src_rect.ul.y=rects[i].y;
   1.241 +        dest_rect.ul.x=rects[i].x;
   1.242 +        dest_rect.ul.y=rects[i].y;
   1.243 +
   1.244 +        dest_rect.lr.x=src_rect.lr.x= rects[i].x +rects[i].w;
   1.245 +        dest_rect.lr.y=src_rect.lr.y= rects[i].y +rects[i].h;
   1.246 +
   1.247 +        zero.x = zero.y = 0;
   1.248 +        PgSetTranslation (&zero, 0);
   1.249 +        PgSetRegion(PtWidgetRid(window));
   1.250 +        PgSetClipping(0,NULL);
   1.251 +        PgContextBlitArea(OCImage.offscreen_context, (PhArea_t *)(&src_rect), NULL, (PhArea_t *)(&dest_rect));
   1.252 +
   1.253 +    }
   1.254      if (PgFlush() < 0)
   1.255      {
   1.256 -    	fprintf(stderr,"error: PgFlush failed.\n");
   1.257 +        fprintf(stderr,"ph_OCUpdate: PgFlush failed.\n");
   1.258      }
   1.259      
   1.260 - //later used to toggling double buffer   
   1.261 -    if(OCImage.current == 0)
   1.262 -	{
   1.263 -		OCImage.CurrentFrameData = OCImage.FrameData0;
   1.264 -	}
   1.265 -	else
   1.266 -	{
   1.267 -		OCImage.CurrentFrameData = OCImage.FrameData1;
   1.268 -	}
   1.269 +    /* later used to toggling double buffer */
   1.270 +    if (OCImage.current == 0)
   1.271 +    {
   1.272 +        OCImage.CurrentFrameData = OCImage.FrameData0;
   1.273 +    }
   1.274 +    else
   1.275 +    {
   1.276 +        OCImage.CurrentFrameData = OCImage.FrameData1;
   1.277 +    }
   1.278  }
   1.279 -
     2.1 --- a/src/video/photon/SDL_ph_modes.c	Fri Mar 22 18:11:56 2002 +0000
     2.2 +++ b/src/video/photon/SDL_ph_modes.c	Sat Mar 23 20:19:44 2002 +0000
     2.3 @@ -62,97 +62,6 @@
     2.4  		return -1;
     2.5  }
     2.6  
     2.7 -/*
     2.8 -static int compare_modes_by_bpp(const void* mode1, const void* mode2)
     2.9 -{
    2.10 -
    2.11 -    if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode_info) < 0)
    2.12 -    {
    2.13 -        fprintf(stderr,"error: In compare_modes_by_bpp PgGetVideoModeInfo failed on mode: 0x%x\n",
    2.14 -                *(unsigned short*)mode1);
    2.15 -        return 0;
    2.16 -    }
    2.17 -    key1 = mode_info.bits_per_pixel;
    2.18 -
    2.19 -    if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0)
    2.20 -    {
    2.21 -        fprintf(stderr,"error: In compare_modes_by_bpp PgGetVideoModeInfo failed on mode: 0x%x\n",
    2.22 -                *(unsigned short*)mode2);
    2.23 -        return 0;
    2.24 -    }
    2.25 -    key2 = mode_info.bits_per_pixel;
    2.26 -
    2.27 -    if (key1 > key2)
    2.28 -        return 1;
    2.29 -    else if (key1 == key2)
    2.30 -        return 0;
    2.31 -    else
    2.32 -        return -1;
    2.33 -}
    2.34 -*/
    2.35 -
    2.36 -/*
    2.37 -int ph_GetVideoModes(_THIS)
    2.38 -{
    2.39 -	unsigned short *front;
    2.40 -	int i, bpp_group_size;
    2.41 -
    2.42 -	// TODO: add mode_list member to _THIS
    2.43 -	if (PgGetVideoModeList( &mode_list ) < 0)
    2.44 -	{
    2.45 -		fprintf(stderr,"error: PgGetVideoModeList failed\n");
    2.46 -		return -1;
    2.47 -	}
    2.48 -	
    2.49 -	// sort list first by bits per pixel (bpp), 
    2.50 -	// then sort groups with same bpp by resolution.
    2.51 -	qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_bpp);
    2.52 -	bpp_group_size = 1;
    2.53 -	front = &mode_list.modes[0];
    2.54 -	for(i=0;i<mode_list.num_modes-2;i++)
    2.55 -	{
    2.56 -		if (compare_modes_by_bpp(&mode_list.modes[i],&mode_list.modes[i+1]))
    2.57 -		{
    2.58 -			qsort(front, bpp_group_size, sizeof(unsigned short), compare_modes_by_res);
    2.59 -			front = &mode_list.modes[i+1];
    2.60 -			bpp_group_size = 1;
    2.61 -		}
    2.62 -		else
    2.63 -		{
    2.64 -			bpp_group_size++;
    2.65 -		}
    2.66 -	}
    2.67 -
    2.68 -	//SDL_modelist = (SDL_Rect **)malloc((mode_list.num_modes+1)*sizeof(SDL_Rect *));
    2.69 -	if ( SDL_modelist ) {
    2.70 -		for (i=0;i<mode_list.num_modes;i++) {
    2.71 -        //	SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
    2.72 -	     //   if ( SDL_modelist[i] == NULL ) {
    2.73 -    	  //      break;
    2.74 -	     //   }
    2.75 -		    if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
    2.76 -		    {
    2.77 -        		fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n",
    2.78 -                		mode_list.modes[i]);
    2.79 -		        return -1;
    2.80 -    		}
    2.81 -    	    SDL_modelist[i].x = 0;
    2.82 -	        SDL_modelist[i].y = 0;
    2.83 -    	    SDL_modelist[i].w = mode_info.height;
    2.84 -        	SDL_modelist[i].h = mode_info.width;
    2.85 -	    }
    2.86 -    	//SDL_modelist[i] = NULL;
    2.87 -	}
    2.88 -	else
    2.89 -	{
    2.90 -		fprintf(stderr,"error: malloc failed on SDL_modelist\n");
    2.91 -		return -1;
    2.92 -	}
    2.93 -	
    2.94 -	return 0;
    2.95 -}
    2.96 -*/
    2.97 -
    2.98  SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
    2.99  {
   2.100      int i = 0;
   2.101 @@ -208,9 +117,10 @@
   2.102     return;
   2.103  }
   2.104  
   2.105 +#if 0
   2.106  static void set_best_resolution(_THIS, int width, int height)
   2.107  {
   2.108 -
   2.109 +    /* warning ! dead variable use_vidmode ! */
   2.110      if ( use_vidmode ) {
   2.111  		PgDisplaySettings_t 	settings;
   2.112  		PgVideoModeInfo_t		current_mode_info;
   2.113 @@ -281,11 +191,14 @@
   2.114  
   2.115  int ph_ResizeFullScreen(_THIS)
   2.116  {
   2.117 -    if (currently_fullscreen) {
   2.118 +    if (currently_fullscreen)
   2.119 +    {
   2.120          set_best_resolution(this, current_w, current_h);
   2.121      }
   2.122 +
   2.123      return (1);
   2.124  }
   2.125 +#endif /* 0 */
   2.126  
   2.127  /* return the mode associated with width, height and bpp */
   2.128  /* if there is no mode then zero is returned             */
   2.129 @@ -354,7 +267,7 @@
   2.130  	}
   2.131  	if (i<mode_list.num_modes)
   2.132  	{
   2.133 -		// get closest bpp
   2.134 +		/* get closest bpp */
   2.135  		closest = i++;
   2.136  		if (mode_info.bits_per_pixel == bpp)
   2.137  			return mode_list.modes[ closest ];
   2.138 @@ -415,40 +328,35 @@
   2.139  {
   2.140      if (!currently_fullscreen)
   2.141      {
   2.142 -        if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
   2.143 +        if (this->screen)
   2.144          {
   2.145 +            if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
   2.146 +            {
   2.147  #ifdef HAVE_OPENGL
   2.148  #endif /* HAVE_OPENGL */
   2.149 -           return 0;
   2.150 +                return 0;
   2.151 +            }
   2.152          }
   2.153 -        else
   2.154 +
   2.155 +        if (OCImage.direct_context == NULL)
   2.156          {
   2.157 -            if (old_video_mode==-1)
   2.158 -            {
   2.159 -                PgGetGraphicsHWCaps(&graphics_card_caps);
   2.160 -                old_video_mode=graphics_card_caps.current_video_mode;
   2.161 -                old_refresh_rate=graphics_card_caps.current_rrate;
   2.162 -            }
   2.163 +            OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
   2.164 +        }
   2.165  
   2.166 -            if(OCImage.direct_context == NULL)
   2.167 -            {
   2.168 -                OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
   2.169 -            }
   2.170 -            if(!OCImage.direct_context)
   2.171 -            {
   2.172 -                fprintf(stderr, "error: Can't create direct context\n" );
   2.173 -            }
   2.174 +        if (!OCImage.direct_context)
   2.175 +        {
   2.176 +            fprintf(stderr, "ph_EnterFullScreen: Can't create direct context\n" );
   2.177 +        }
   2.178  
   2.179 -            PdDirectStart(OCImage.direct_context);
   2.180 +        PdDirectStart(OCImage.direct_context);
   2.181  
   2.182 -            currently_fullscreen = 1;
   2.183 -        }
   2.184 +        currently_fullscreen = 1;
   2.185      }
   2.186  
   2.187      return 1;
   2.188  }
   2.189  
   2.190 -int ph_LeaveFullScreen(_THIS )
   2.191 +int ph_LeaveFullScreen(_THIS)
   2.192  {
   2.193      PgDisplaySettings_t mymode_settings;
   2.194         
   2.195 @@ -464,13 +372,16 @@
   2.196          {
   2.197              PdDirectStop(OCImage.direct_context);
   2.198              PdReleaseDirectContext(OCImage.direct_context);
   2.199 +            
   2.200 +            currently_fullscreen=0;
   2.201  
   2.202              /* Restore old video mode */
   2.203              if (old_video_mode != -1)
   2.204              {
   2.205                  mymode_settings.mode= (unsigned short) old_video_mode;
   2.206                  mymode_settings.refresh= (unsigned short) old_refresh_rate;
   2.207 -                mymode_settings.flags = 0;
   2.208 +                mymode_settings.flags= 0;
   2.209 +                
   2.210                  if (PgSetVideoMode(&mymode_settings) < 0)
   2.211                  {
   2.212                      fprintf(stderr,"error: PgSetVideoMode failed\n");
   2.213 @@ -478,7 +389,7 @@
   2.214              }
   2.215  
   2.216              old_video_mode=-1;
   2.217 -            old_refresh_rate=-1;	
   2.218 +            old_refresh_rate=-1;
   2.219          }
   2.220  
   2.221      }
     3.1 --- a/src/video/photon/SDL_ph_modes_c.h	Fri Mar 22 18:11:56 2002 +0000
     3.2 +++ b/src/video/photon/SDL_ph_modes_c.h	Sat Mar 23 20:19:44 2002 +0000
     3.3 @@ -33,7 +33,6 @@
     3.4  
     3.5  #define PH_MAX_VIDEOMODES 127
     3.6  
     3.7 -//extern int ph_GetVideoModes(_THIS);
     3.8  extern SDL_Rect **ph_ListModes(_THIS,SDL_PixelFormat *format, Uint32 flags);
     3.9  extern void ph_FreeVideoModes(_THIS);
    3.10  extern int ph_ResizeFullScreen(_THIS);
     4.1 --- a/src/video/photon/SDL_ph_mouse.c	Fri Mar 22 18:11:56 2002 +0000
     4.2 +++ b/src/video/photon/SDL_ph_mouse.c	Sat Mar 23 20:19:44 2002 +0000
     4.3 @@ -36,25 +36,25 @@
     4.4  #include "SDL_ph_mouse_c.h"
     4.5  
     4.6  struct  WMcursor {
     4.7 -	PhCursorDef_t *ph_cursor ;
     4.8 +    PhCursorDef_t *ph_cursor ;
     4.9  };
    4.10  
    4.11  
    4.12  void ph_FreeWMCursor(_THIS, WMcursor *cursor)
    4.13  {
    4.14 +    if (window != NULL)
    4.15 +    {
    4.16 +        SDL_Lock_EventThread();
    4.17  
    4.18 -    if ( window != NULL ) {
    4.19 -		SDL_Lock_EventThread();
    4.20 -		
    4.21 -		if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0 ) < 0)
    4.22 -		{
    4.23 -			//TODO: output error msg
    4.24 -		}
    4.25 -		
    4.26 -		SDL_Unlock_EventThread();
    4.27 -	}	
    4.28 -	//free(cursor->ph_cursor.images);
    4.29 -	free(cursor);
    4.30 +        if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0 ) < 0)
    4.31 +        {
    4.32 +            /* TODO: output error msg */
    4.33 +        }
    4.34 +
    4.35 +        SDL_Unlock_EventThread();
    4.36 +    }	
    4.37 +    /* free(cursor->ph_cursor.images); */
    4.38 +    free(cursor);
    4.39  }
    4.40  
    4.41  WMcursor *ph_CreateWMCursor(_THIS,
    4.42 @@ -120,7 +120,7 @@
    4.43  
    4.44  PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor)
    4.45  {
    4.46 -	return(*cursor->ph_cursor);
    4.47 +    return(*cursor->ph_cursor);
    4.48  }
    4.49  
    4.50  int ph_ShowWMCursor(_THIS, WMcursor *cursor)
    4.51 @@ -170,22 +170,24 @@
    4.52  
    4.53  void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
    4.54  {
    4.55 -	short abs_x, abs_y;
    4.56 +    short abs_x, abs_y;
    4.57  
    4.58 -	SDL_Lock_EventThread();
    4.59 -	PtGetAbsPosition( window, &abs_x, &abs_y );
    4.60 -	PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y );
    4.61 -	SDL_Unlock_EventThread();
    4.62 +    SDL_Lock_EventThread();
    4.63 +    PtGetAbsPosition( window, &abs_x, &abs_y );
    4.64 +    PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y );
    4.65 +    SDL_Unlock_EventThread();
    4.66  }
    4.67  
    4.68  
    4.69  void ph_CheckMouseMode(_THIS)
    4.70  {
    4.71 -        /* If the mouse is hidden and input is grabbed, we use relative mode */
    4.72 -        if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
    4.73 -             (this->input_grab != SDL_GRAB_OFF) ) {
    4.74 -                mouse_relative = 1;
    4.75 -        } else {
    4.76 -                mouse_relative = 0;
    4.77 -        }
    4.78 +    /* If the mouse is hidden and input is grabbed, we use relative mode */
    4.79 +    if ( !(SDL_cursorstate & CURSOR_VISIBLE) && (this->input_grab != SDL_GRAB_OFF))
    4.80 +    {
    4.81 +        mouse_relative = 1;
    4.82 +    }
    4.83 +    else
    4.84 +    {
    4.85 +        mouse_relative = 0;
    4.86 +    }
    4.87  }
     5.1 --- a/src/video/photon/SDL_ph_video.c	Fri Mar 22 18:11:56 2002 +0000
     5.2 +++ b/src/video/photon/SDL_ph_video.c	Sat Mar 23 20:19:44 2002 +0000
     5.3 @@ -150,8 +150,8 @@
     5.4  }
     5.5  
     5.6  VideoBootStrap ph_bootstrap = {
     5.7 -        "photon", "QNX Photon video output",
     5.8 -	ph_Available, ph_CreateDevice
     5.9 +    "photon", "QNX Photon video output",
    5.10 +    ph_Available, ph_CreateDevice
    5.11  };
    5.12  
    5.13  static void ph_DeleteDevice(SDL_VideoDevice *device)
    5.14 @@ -175,7 +175,6 @@
    5.15  
    5.16  static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
    5.17  {
    5.18 -    PgColor_t ph_palette[_Pg_MAX_PALETTE];
    5.19      int i;
    5.20      unsigned long *tempptr;
    5.21      int rtnval;
    5.22 @@ -184,6 +183,11 @@
    5.23  
    5.24      window=NULL;
    5.25      oglctx=NULL;
    5.26 +    desktoppal=SDLPH_PAL_NONE;
    5.27 +    
    5.28 +    captionflag=0;
    5.29 +    old_video_mode=-1;
    5.30 +    old_refresh_rate=-1;
    5.31  	
    5.32      if (NULL == (event = malloc(EVENT_SIZE)))
    5.33      {
    5.34 @@ -213,6 +217,7 @@
    5.35      /* We need to return BytesPerPixel as it in used by CreateRGBsurface */
    5.36      vformat->BitsPerPixel = my_mode_info.bits_per_pixel;
    5.37      vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width;
    5.38 +    desktopbpp = my_mode_info.bits_per_pixel;
    5.39           
    5.40      /* return a palette if we are in 256 color mode */
    5.41      if (vformat->BitsPerPixel == 8)
    5.42 @@ -253,7 +258,6 @@
    5.43      PtArg_t arg[32];
    5.44      PhDim_t dim;
    5.45      int rtnval;
    5.46 -    PgColor_t ph_palette[_Pg_MAX_PALETTE];
    5.47      int i;
    5.48      unsigned long *tempptr;
    5.49      int pargc;
    5.50 @@ -281,7 +285,7 @@
    5.51  
    5.52          window=PtCreateWidget(PtWindow, NULL, pargc-1, arg);
    5.53          PtRealizeWidget(window);
    5.54 -
    5.55 +        
    5.56          PtFlush();
    5.57      }
    5.58  
    5.59 @@ -330,21 +334,30 @@
    5.60                      exit(1);
    5.61                  }
    5.62              }
    5.63 +            
    5.64 +            if (bpp==8)
    5.65 +            {
    5.66 +               desktoppal=SDLPH_PAL_SYSTEM;
    5.67 +            }
    5.68 +            
    5.69 +            /* save old video mode caps */
    5.70 +            PgGetVideoMode(&settings);
    5.71 +            old_video_mode=settings.mode;
    5.72 +            old_refresh_rate=settings.refresh;
    5.73 +
    5.74 +            /* setup new video mode */
    5.75              settings.mode = mode;
    5.76              settings.refresh = 0;
    5.77 -            settings.flags  = 0;       
    5.78 +            settings.flags = 0;
    5.79  
    5.80 -            if (PgSetVideoMode( &settings ) < 0)
    5.81 +            if (PgSetVideoMode(&settings) < 0)
    5.82              {
    5.83                  fprintf(stderr,"error: PgSetVideoMode failed\n");
    5.84              }
    5.85  
    5.86 -            /* Get the true height and width */
    5.87 -
    5.88              current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
    5.89  
    5.90              /* Begin direct mode */
    5.91 -
    5.92              ph_EnterFullScreen(this);
    5.93  
    5.94          } /* end fullscreen flag */
    5.95 @@ -359,6 +372,22 @@
    5.96              {
    5.97                  current->flags = (flags | SDL_RESIZABLE); /* yes we can resize as this is a software surface */
    5.98              }
    5.99 +            /* using palette emulation code in window mode */
   5.100 +            if (bpp==8)
   5.101 +            {
   5.102 +                if (desktopbpp>=15)
   5.103 +                {
   5.104 +                    desktoppal=SDLPH_PAL_EMULATE;
   5.105 +                }
   5.106 +                else
   5.107 +                {
   5.108 +                    desktoppal=SDLPH_PAL_SYSTEM;
   5.109 +                }
   5.110 +            }
   5.111 +            else
   5.112 +            {
   5.113 +               desktoppal=SDLPH_PAL_NONE;
   5.114 +            }
   5.115          }
   5.116  
   5.117  	/* If we are setting video to use the palette make sure we have allocated memory for it */
   5.118 @@ -390,10 +419,16 @@
   5.119      /* Must call at least once it setup image planes */
   5.120      ph_ResizeImage(this, current, flags);
   5.121  
   5.122 +    /* delayed set caption call */
   5.123 +    if (captionflag)
   5.124 +    {
   5.125 +        ph_SetCaption(this, this->wm_title, NULL);
   5.126 +    }
   5.127 +
   5.128      SDL_Unlock_EventThread();
   5.129  
   5.130      /* We're done! */
   5.131 -    return(current);
   5.132 +    return (current);
   5.133  }
   5.134  
   5.135  static void ph_VideoQuit(_THIS)
   5.136 @@ -404,19 +439,20 @@
   5.137  
   5.138      if (currently_fullscreen)
   5.139      {
   5.140 -        PdDirectStop(directContext);
   5.141 -        PdReleaseDirectContext(directContext);
   5.142 -        directContext=0;	
   5.143 -        currently_fullscreen=0;
   5.144 +        ph_LeaveFullScreen(this);
   5.145      }
   5.146  
   5.147  #ifdef HAVE_OPENGL
   5.148 -    if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) &&
   5.149 -        ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
   5.150 +    /* prevent double SEGFAULT with parachute mode */
   5.151 +    if (this->screen)
   5.152      {
   5.153 -        region_info.cursor_type=Ph_CURSOR_POINTER;
   5.154 -        region_info.rid=PtWidgetRid(window);
   5.155 -        PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);
   5.156 +        if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) &&
   5.157 +            ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
   5.158 +        {
   5.159 +            region_info.cursor_type=Ph_CURSOR_POINTER;
   5.160 +            region_info.rid=PtWidgetRid(window);
   5.161 +            PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);
   5.162 +        }
   5.163      }
   5.164  
   5.165      PtFlush();
   5.166 @@ -428,6 +464,12 @@
   5.167          PtDestroyWidget(window);
   5.168          window=NULL;
   5.169      }
   5.170 +    
   5.171 +    /* restore palette */
   5.172 +    if (desktoppal!=SDLPH_PAL_NONE)
   5.173 +    {
   5.174 +        PgSetPalette(ph_palette, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0);
   5.175 +    }
   5.176  
   5.177  #ifdef HAVE_OPENGL
   5.178      if (oglctx)
   5.179 @@ -441,60 +483,58 @@
   5.180  
   5.181  static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
   5.182  {
   5.183 -	PgColor_t *in, *out;
   5.184 -	int i, j;
   5.185 -	int alloct_all = 1;
   5.186 -
   5.187 -    	colors = this->screen->format->palette->colors;
   5.188 -
   5.189 -	in = alloca( ncolors*sizeof(PgColor_t)  );
   5.190 -	if ( in == NULL  ) {
   5.191 -		return 0;
   5.192 -	}
   5.193 -	memset(in,0,ncolors*sizeof(PgColor_t));
   5.194 -
   5.195 -    out = alloca( ncolors*sizeof(PgColor_t)  );
   5.196 -    if ( out == NULL  ) {
   5.197 -		return 0;
   5.198 -    }
   5.199 -	
   5.200 -	for (i=0,j=firstcolor;i<ncolors;i++,j++)
   5.201 -	{
   5.202 -		in[i] |= colors[j].r<<16 ;
   5.203 -		in[i] |= colors[j].g<<8 ;
   5.204 -		in[i] |= colors[j].b ; 
   5.205 -	}
   5.206 +    int i;
   5.207 +    PhPoint_t point={0, 0};
   5.208 +    PgColor_t syspalph[_Pg_MAX_PALETTE];
   5.209  
   5.210 -	if ( (this->screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) 
   5.211 -	{
   5.212 -		if( PgSetPalette( in, 0, 0, ncolors, Pg_PALSET_HARD, 0) < 0 )
   5.213 -		{
   5.214 -			fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_HARD)  failed\n");
   5.215 -			return 0;
   5.216 -		}  
   5.217 -	}
   5.218 -	else 
   5.219 -	{
   5.220 -		if ( PgColorMatch(ncolors, in, out) < 0 )
   5.221 +    /* palette emulation code, using palette of the PhImage_t struct */
   5.222 +    if (desktoppal==SDLPH_PAL_EMULATE)
   5.223 +    {
   5.224 +        if ((SDL_Image) && (SDL_Image->palette))
   5.225          {
   5.226 -            fprintf(stderr,"error: PgColorMatch failed\n");
   5.227 -            return 0;
   5.228 +            for (i=firstcolor; i<firstcolor+ncolors; i++)
   5.229 +            {
   5.230 +                SDL_Image->palette[i]  = 0x00000000UL;
   5.231 +                SDL_Image->palette[i] |= colors[i-firstcolor].r<<16;
   5.232 +                SDL_Image->palette[i] |= colors[i-firstcolor].g<<8;
   5.233 +                SDL_Image->palette[i] |= colors[i-firstcolor].b;
   5.234 +            }
   5.235          }
   5.236 -		for (i=0;i<ncolors;i++)
   5.237 -		{
   5.238 -			if (memcmp(&in[i],&out[i],sizeof(PgColor_t)))
   5.239 -			{
   5.240 -				alloct_all = 0;
   5.241 -				break;
   5.242 -			}
   5.243 -		}
   5.244 -        if( PgSetPalette( out, 0, 0, ncolors, Pg_PALSET_SOFT, 0) < 0 )
   5.245 +        /* image needs to be redrawed, very slow method */
   5.246 +        PgDrawPhImage(&point, SDL_Image, 0);
   5.247 +    }
   5.248 +    else
   5.249 +    {
   5.250 +        if (desktoppal==SDLPH_PAL_SYSTEM)
   5.251          {
   5.252 -            fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_SOFT) failed\n");
   5.253 -            return 0;
   5.254 +            for (i=firstcolor; i<firstcolor+ncolors; i++)
   5.255 +            {
   5.256 +                syspalph[i]  = 0x00000000UL;
   5.257 +                syspalph[i] |= colors[i-firstcolor].r<<16;
   5.258 +                syspalph[i] |= colors[i-firstcolor].g<<8;
   5.259 +                syspalph[i] |= colors[i-firstcolor].b;
   5.260 +            }
   5.261 +
   5.262 +            if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
   5.263 +            {
   5.264 +                /* window mode must use soft palette */
   5.265 +                PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0);
   5.266 +                /* image needs to be redrawed, very slow method */
   5.267 +                PgDrawPhImage(&point, SDL_Image, 0);
   5.268 +            }
   5.269 +            else
   5.270 +            {
   5.271 +                /* fullscreen mode must use hardware palette */
   5.272 +                PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
   5.273 +            }
   5.274          }
   5.275 -	}
   5.276 -	return alloct_all;
   5.277 +        else
   5.278 +        {
   5.279 +            /* SDLPH_PAL_NONE do nothing */
   5.280 +        }
   5.281 +    }
   5.282 +    
   5.283 +    return 1;
   5.284  }
   5.285  
   5.286  #ifdef HAVE_OPENGL
     6.1 --- a/src/video/photon/SDL_ph_video.h	Fri Mar 22 18:11:56 2002 +0000
     6.2 +++ b/src/video/photon/SDL_ph_video.h	Sat Mar 23 20:19:44 2002 +0000
     6.3 @@ -39,6 +39,10 @@
     6.4  
     6.5  #define PH_OGL_MAX_ATTRIBS 32
     6.6  
     6.7 +#define SDLPH_PAL_NONE    0x00000000L
     6.8 +#define SDLPH_PAL_EMULATE 0x00000001L
     6.9 +#define SDLPH_PAL_SYSTEM  0x00000002L
    6.10 +
    6.11  typedef union vidptr{
    6.12    uint8_t  *volatile ptr8;
    6.13    uint16_t *volatile ptr16;
    6.14 @@ -55,14 +59,13 @@
    6.15  
    6.16  /* Private display data */
    6.17  struct SDL_PrivateVideoData {
    6.18 -    int local_ph;		/* Flag: true if local display */
    6.19 -    PtAppContext_t app;
    6.20      PgDisplaySettings_t mode_settings;	
    6.21 -    PtWidget_t *Window;    /* used to handle input events */
    6.22 -    PhImage_t *image;	   /* used to display image */
    6.23 +    PtWidget_t *Window;                  /* used to handle input events */
    6.24 +    PhImage_t *image;	                 /* used to display image       */
    6.25  #ifdef HAVE_OPENGL
    6.26 -    PdOpenGLContext_t* OGLContext;
    6.27 +    PdOpenGLContext_t* OGLContext;       /* OpenGL context              */
    6.28  #endif /* HAVE_OPENGL */
    6.29 +    PgColor_t ph_palette[_Pg_MAX_PALETTE];
    6.30  
    6.31      struct {
    6.32          PdDirectContext_t *direct_context;
    6.33 @@ -76,16 +79,9 @@
    6.34          long flags;
    6.35      } ocimage;
    6.36  
    6.37 -    PhDrawContext_t *ScreenDC; //=NULL;
    6.38 -    signed short old_video_mode; //=-1;
    6.39 -    signed short old_refresh_rate; //=-1;
    6.40 -    PgHWCaps_t graphics_card_caps;
    6.41 -	
    6.42 -    PdDirectContext_t *directContext;
    6.43 -    PdOffscreenContext_t *Buff[2];
    6.44 -    struct _Ph_ctrl* ctrl_channel;
    6.45 -
    6.46 -    /* The variables used for displaying graphics */
    6.47 +    PgHWCaps_t graphics_card_caps;  /* Graphics card caps at the moment of start   */
    6.48 +    int old_video_mode;             /* Stored mode before fullscreen switch        */
    6.49 +    int old_refresh_rate;           /* Stored refresh rate befor fullscreen switch */
    6.50  
    6.51      /* The current width and height of the fullscreen mode */
    6.52      int current_w;
    6.53 @@ -106,7 +102,10 @@
    6.54      int mouse_relative;
    6.55      WMcursor* BlankCursor;
    6.56  
    6.57 -    int depth;			/* current visual depth (not bpp) */
    6.58 +    int depth;			/* current visual depth (not bpp)        */
    6.59 +    int desktopbpp;             /* bpp of desktop at the moment of start */
    6.60 +    int desktoppal;             /* palette mode emulation or system      */
    6.61 +    int captionflag;            /* caption setting flag                  */
    6.62  
    6.63      int use_vidmode;
    6.64      int currently_fullscreen;
    6.65 @@ -118,26 +117,22 @@
    6.66      /* Prevent too many XSync() calls */
    6.67      int blit_queued;
    6.68  
    6.69 -    short *iconcolors;		/* List of colors used by the icon */
    6.70      PhEvent_t* event;
    6.71  };
    6.72  
    6.73 -#define local_ph             (this->hidden->local_ph)
    6.74 -#define app                  (this->hidden->app)
    6.75  #define mode_settings        (this->hidden->mode_settings)
    6.76  #define window	             (this->hidden->Window)
    6.77  #define oglctx               (this->hidden->OGLContext)
    6.78 -#define directContext	     (this->hidden->directContext)
    6.79 -#define Buff                 (this->hidden->Buff)
    6.80 -#define ctrl_channel         (this->hidden->ctrl_channel)
    6.81  #define SDL_Image            (this->hidden->image)
    6.82  #define OCImage              (this->hidden->ocimage)
    6.83  #define old_video_mode       (this->hidden->old_video_mode)
    6.84  #define old_refresh_rate     (this->hidden->old_refresh_rate)
    6.85  #define graphics_card_caps   (this->hidden->graphics_card_caps)
    6.86 +#define desktopbpp           (this->hidden->desktopbpp)
    6.87 +#define desktoppal           (this->hidden->desktoppal)
    6.88 +#define ph_palette           (this->hidden->ph_palette)
    6.89  
    6.90  /* Old variable names */
    6.91 -#define swap_pixels          (this->hidden->swap_pixels)
    6.92  #define current_w            (this->hidden->current_w)
    6.93  #define current_h            (this->hidden->current_h)
    6.94  #define mouse_last           (this->hidden->mouse_last)
    6.95 @@ -150,8 +145,8 @@
    6.96  #define switch_waiting       (this->hidden->switch_waiting)
    6.97  #define switch_time          (this->hidden->switch_time)
    6.98  #define blit_queued          (this->hidden->blit_queued)
    6.99 -#define SDL_iconcolorIs      (this->hidden->iconcolors)
   6.100  #define event                (this->hidden->event)
   6.101  #define SDL_BlankCursor      (this->hidden->BlankCursor)
   6.102 +#define captionflag          (this->hidden->captionflag)
   6.103  
   6.104  #endif /* _SDL_x11video_h */
     7.1 --- a/src/video/photon/SDL_ph_wm.c	Fri Mar 22 18:11:56 2002 +0000
     7.2 +++ b/src/video/photon/SDL_ph_wm.c	Sat Mar 23 20:19:44 2002 +0000
     7.3 @@ -48,207 +48,47 @@
     7.4  
     7.5  void ph_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
     7.6  {
     7.7 -
     7.8 -#if 0 /*big*/
     7.9 -	int ncolors;
    7.10 -	PhImage_t *image;
    7.11 -	PgColor_t* palette;
    7.12 -
    7.13 -	image = PhCreateImage( image,
    7.14 -                          	icon->w,
    7.15 -                          	icon->h,
    7.16 -                          	Pg_IMAGE_DIRECT_888,
    7.17 -                          	NULL, 0, 0 );
    7.18 -
    7.19 -/* ---------------------------------------- */
    7.20 -	SDL_Surface *sicon;
    7.21 -//	XWMHints *wmhints;
    7.22 -//	XImage *icon_image;
    7.23 -//	Pixmap icon_pixmap;
    7.24 -//	Pixmap mask_pixmap;
    7.25 -//	GC GC;
    7.26 -//	XGCValues GCvalues;
    7.27 -	int i, b, dbpp;
    7.28 -	SDL_Rect bounds;
    7.29 -	Uint8 *LSBmask, *color_tried;
    7.30 -	Visual *dvis;
    7.31 -
    7.32 -	/* Lock the event thread, in multi-threading environments */
    7.33 -	SDL_Lock_EventThread();
    7.34 -
    7.35 -	/* The icon must use the default visual, depth and colormap of the
    7.36 -	   screen, so it might need a conversion */
    7.37 -// ?	dbpp = DefaultDepth(SDL_Display, SDL_Screen);
    7.38 -	switch(dbpp) {
    7.39 -	case 15:
    7.40 -	    dbpp = 16; break;
    7.41 -	case 24:
    7.42 -	    dbpp = 32; break;
    7.43 -	}
    7.44 -	dvis = DefaultVisual(SDL_Display, SDL_Screen);
    7.45 -
    7.46 -	/* The Visual struct is supposed to be opaque but we cheat a little */
    7.47 -	sicon = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h,
    7.48 -				     dbpp,
    7.49 -				     dvis->red_mask, dvis->green_mask,
    7.50 -				     dvis->blue_mask, 0);
    7.51 -
    7.52 -	if ( sicon == NULL ) {
    7.53 -		goto done;
    7.54 -	}
    7.55 -	/* If we already have allocated colours from the default colormap,
    7.56 -	   copy them */
    7.57 -	if(SDL_Visual == dvis && SDL_XColorMap == SDL_DisplayColormap
    7.58 -	   && this->screen->format->palette && sicon->format->palette) {
    7.59 -	    memcpy(sicon->format->palette->colors,
    7.60 -		   this->screen->format->palette->colors,
    7.61 -		   this->screen->format->palette->ncolors * sizeof(SDL_Color));
    7.62 -	}
    7.63 -
    7.64 -	bounds.x = 0;
    7.65 -	bounds.y = 0;
    7.66 -	bounds.w = icon->w;
    7.67 -	bounds.h = icon->h;
    7.68 -	if ( SDL_LowerBlit(icon, &bounds, sicon, &bounds) < 0 )
    7.69 -		goto done;
    7.70 -
    7.71 -	/* Lock down the colors used in the colormap */
    7.72 -	color_tried = NULL;
    7.73 -	if ( sicon->format->BitsPerPixel == 8 ) {
    7.74 -		SDL_Palette *palette;
    7.75 -		Uint8 *p;
    7.76 -		XColor wanted;
    7.77 -
    7.78 -		palette = sicon->format->palette;
    7.79 -		color_tried = malloc(palette->ncolors);
    7.80 -		if ( color_tried == NULL ) {
    7.81 -			goto done;
    7.82 -		}
    7.83 -		if ( SDL_iconcolors != NULL ) {
    7.84 -			free(SDL_iconcolors);
    7.85 -		}
    7.86 -		SDL_iconcolors = malloc(palette->ncolors
    7.87 -					* sizeof(*SDL_iconcolors));
    7.88 -		if ( SDL_iconcolors == NULL ) {
    7.89 -			free(color_tried);
    7.90 -			goto done;
    7.91 -		}
    7.92 -		memset(color_tried, 0, palette->ncolors);
    7.93 -		memset(SDL_iconcolors, 0,
    7.94 -		       palette->ncolors * sizeof(*SDL_iconcolors));
    7.95 -
    7.96 -		p = (Uint8 *)sicon->pixels; 
    7.97 -		for ( i = sicon->w*sicon->h; i > 0; --i, ++p ) {
    7.98 -			if ( ! color_tried[*p] ) {
    7.99 -				wanted.pixel = *p;
   7.100 -				wanted.red   = (palette->colors[*p].r<<8);
   7.101 -				wanted.green = (palette->colors[*p].g<<8);
   7.102 -				wanted.blue  = (palette->colors[*p].b<<8);
   7.103 -				wanted.flags = (DoRed|DoGreen|DoBlue);
   7.104 -				if (XAllocColor(SDL_Display,
   7.105 -						SDL_DisplayColormap, &wanted)) {
   7.106 -					++SDL_iconcolors[wanted.pixel];
   7.107 -				}
   7.108 -				color_tried[*p] = 1;
   7.109 -			}
   7.110 -		}
   7.111 -	}
   7.112 -	if ( color_tried != NULL ) {
   7.113 -		free(color_tried);
   7.114 -	}
   7.115 -
   7.116 -	/* Translate mask data to LSB order and set the icon mask */
   7.117 -	i = (sicon->w/8)*sicon->h;
   7.118 -	LSBmask = (Uint8 *)malloc(i);
   7.119 -	if ( LSBmask == NULL ) {
   7.120 -		goto done;
   7.121 -	}
   7.122 -	memset(LSBmask, 0, i);
   7.123 -	while ( --i >= 0 ) {
   7.124 -		for ( b=0; b<8; ++b )
   7.125 -			LSBmask[i] |= (((mask[i]>>b)&0x01)<<(7-b));
   7.126 -	}
   7.127 -	mask_pixmap = XCreatePixmapFromBitmapData(SDL_Display, WMwindow,
   7.128 -					LSBmask, sicon->w, sicon->h, 1L, 0L, 1);
   7.129 -
   7.130 -	/* Transfer the image to an X11 pixmap */
   7.131 -	icon_image = XCreateImage(SDL_Display,
   7.132 -			DefaultVisual(SDL_Display, SDL_Screen),
   7.133 -			DefaultDepth(SDL_Display, SDL_Screen),
   7.134 -			ZPixmap, 0, (char *)sicon->pixels, sicon->w, sicon->h,
   7.135 -			((sicon->format)->BytesPerPixel == 3) ? 32 :
   7.136 -				(sicon->format)->BytesPerPixel*8, 0);
   7.137 -	icon_pixmap = XCreatePixmap(SDL_Display, SDL_Root, sicon->w, sicon->h,
   7.138 -			DefaultDepth(SDL_Display, SDL_Screen));
   7.139 -	GC = XCreateGC(SDL_Display, icon_pixmap, 0, &GCvalues);
   7.140 -	XPutImage(SDL_Display, icon_pixmap, GC, icon_image,
   7.141 -					0, 0, 0, 0, sicon->w, sicon->h);
   7.142 -	XFreeGC(SDL_Display, GC);
   7.143 -	XDestroyImage(icon_image);
   7.144 -	free(LSBmask);
   7.145 -	sicon->pixels = NULL;
   7.146 -
   7.147 -#ifdef USE_ICON_WINDOW
   7.148 -	/* Create an icon window and set the pixmap as its background */
   7.149 -	icon_window = XCreateSimpleWindow(SDL_Display, SDL_Root,
   7.150 -					0, 0, sicon->w, sicon->h, 0,
   7.151 -					CopyFromParent, CopyFromParent);
   7.152 -	XSetWindowBackgroundPixmap(SDL_Display, icon_window, icon_pixmap);
   7.153 -	XClearWindow(SDL_Display, icon_window);
   7.154 -#endif
   7.155 -
   7.156 -	/* Set the window icon to the icon pixmap (and icon window) */
   7.157 -	wmhints = XAllocWMHints();
   7.158 -	wmhints->flags = (IconPixmapHint | IconMaskHint);
   7.159 -	wmhints->icon_pixmap = icon_pixmap;
   7.160 -	wmhints->icon_mask = mask_pixmap;
   7.161 -#ifdef USE_ICON_WINDOW
   7.162 -	wmhints->flags |= IconWindowHint;
   7.163 -	wmhints->icon_window = icon_window;
   7.164 -#endif
   7.165 -	XSetWMHints(SDL_Display, WMwindow, wmhints);
   7.166 -	XFree(wmhints);
   7.167 -	XSync(SDL_Display, False);
   7.168 -
   7.169 -  done:
   7.170 -	SDL_Unlock_EventThread();
   7.171 -	if ( sicon != NULL ) {
   7.172 -		SDL_FreeSurface(sicon);
   7.173 -	}
   7.174 -	
   7.175 -#endif /*big*/
   7.176 -	return;
   7.177 +    return;
   7.178  }
   7.179  
   7.180  /* Set window caption */
   7.181  void ph_SetCaption(_THIS, const char *title, const char *icon)
   7.182  {
   7.183 -	SDL_Lock_EventThread();
   7.184 -	if ( title != NULL ) {
   7.185 -		PtSetResource(window, Pt_ARG_WINDOW_TITLE, title, 0);
   7.186 -	}
   7.187 -	SDL_Unlock_EventThread();
   7.188 +    SDL_Lock_EventThread();
   7.189 +
   7.190 +    /* check for set caption call before window init */
   7.191 +    if (window!=NULL)
   7.192 +    {
   7.193 +        PtSetResource(window, Pt_ARG_WINDOW_TITLE, title, 0);
   7.194 +    }
   7.195 +    else
   7.196 +    {
   7.197 +        captionflag=1;
   7.198 +    }
   7.199 +
   7.200 +    SDL_Unlock_EventThread();
   7.201  }
   7.202  
   7.203  /* Iconify current window */
   7.204  int ph_IconifyWindow(_THIS)
   7.205  {
   7.206 -	PhWindowEvent_t windowevent;
   7.207 +    PhWindowEvent_t windowevent;
   7.208 +
   7.209 +    SDL_Lock_EventThread();
   7.210  
   7.211 -	SDL_Lock_EventThread();
   7.212 -	memset( &windowevent, 0, sizeof (event) );
   7.213 -	windowevent.event_f = Ph_WM_HIDE;
   7.214 -	windowevent.event_state = Ph_WM_EVSTATE_HIDE;
   7.215 -	windowevent.rid = PtWidgetRid( window );
   7.216 -	PtForwardWindowEvent( &windowevent );
   7.217 -	SDL_Unlock_EventThread();
   7.218 -        
   7.219 -        return 0;
   7.220 +    memset( &windowevent, 0, sizeof (event) );
   7.221 +    windowevent.event_f = Ph_WM_HIDE;
   7.222 +    windowevent.event_state = Ph_WM_EVSTATE_HIDE;
   7.223 +    windowevent.rid = PtWidgetRid( window );
   7.224 +    PtForwardWindowEvent( &windowevent );
   7.225 +    SDL_Unlock_EventThread();
   7.226 +
   7.227 +    return 0;
   7.228  }
   7.229  
   7.230  SDL_GrabMode ph_GrabInputNoLock(_THIS, SDL_GrabMode mode)
   7.231  {
   7.232 -   return(mode);
   7.233 +    return(mode);
   7.234  }
   7.235  
   7.236  SDL_GrabMode ph_GrabInput(_THIS, SDL_GrabMode mode)
   7.237 @@ -280,14 +120,14 @@
   7.238  
   7.239  int ph_GetWMInfo(_THIS, SDL_SysWMinfo *info)
   7.240  {
   7.241 -   if (info->version.major <= SDL_MAJOR_VERSION)
   7.242 -   {
   7.243 -      return 1;
   7.244 -   }
   7.245 -   else
   7.246 -   {
   7.247 -      SDL_SetError("Application not compiled with SDL %d.%d\n",
   7.248 -                    SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   7.249 -      return -1;
   7.250 -   }
   7.251 +    if (info->version.major <= SDL_MAJOR_VERSION)
   7.252 +    {
   7.253 +        return 1;
   7.254 +    }
   7.255 +    else
   7.256 +    {
   7.257 +        SDL_SetError("Application not compiled with SDL %d.%d\n",
   7.258 +                      SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   7.259 +        return -1;
   7.260 +    }
   7.261  }