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.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40316
This commit is contained in:
Sam Lantinga 2002-03-23 20:19:44 +00:00
parent 42e7ceb763
commit b553c23e28
7 changed files with 327 additions and 512 deletions

View file

@ -33,9 +33,13 @@ static char rcsid =
#include "SDL_endian.h"
#include "SDL_ph_image_c.h"
/* remove this line, if photon headers updates */
int PgWaitHWIdle(void);
int ph_SetupImage(_THIS, SDL_Surface *screen)
{
int type=0;
PgColor_t* palette=NULL;
/* Determine image type */
switch(screen->format->BitsPerPixel)
@ -69,12 +73,29 @@ int ph_SetupImage(_THIS, SDL_Surface *screen)
break;
}
/* palette emulation code */
if ((screen->format->BitsPerPixel==8) && (desktoppal==SDLPH_PAL_EMULATE))
{
/* creating image palette */
palette=malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t));
PgGetPalette(palette);
/* using shared memory for speed (set last param to 1) */
if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL)
{
fprintf(stderr,"ph_SetupImage: PhCreateImage failed for bpp=8.\n");
return -1;
}
}
else
{
/* using shared memory for speed (set last param to 1) */
if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL)
{
fprintf(stderr,"error: PhCreateImage failed.\n");
fprintf(stderr,"ph_SetupImage: PhCreateImage failed.\n");
return -1;
}
}
screen->pixels = SDL_Image->image;
@ -83,7 +104,7 @@ int ph_SetupImage(_THIS, SDL_Surface *screen)
return 0;
}
int ph_SetupOCImage(_THIS, SDL_Surface *screen) //Offscreen context
int ph_SetupOCImage(_THIS, SDL_Surface *screen)
{
int type = 0;
@ -185,11 +206,18 @@ void ph_DestroyImage(_THIS, SDL_Surface *screen)
if (SDL_Image)
{
/* if palette allocated, free it */
if (SDL_Image->palette)
{
free(SDL_Image->palette);
}
PgShmemDestroy(SDL_Image->image);
free(SDL_Image);
SDL_Image = NULL;
}
/* Must be zeroed everytime */
SDL_Image = NULL;
if (screen)
{
screen->pixels = NULL;
@ -233,10 +261,10 @@ int ph_FlipHWSurface(_THIS, SDL_Surface *surface)
int ph_LockHWSurface(_THIS, SDL_Surface *surface)
{
if ((surface == SDL_VideoSurface) && blit_queued) {
// XSync(GFX_Display, False);
PgFlush();
blit_queued = 0;
}
return(0);
}
@ -258,10 +286,10 @@ void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects)
void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
{
for ( i=0; i<numrects; ++i )
{
if ( rects[i].w == 0 ) { /* Clipped? */
if (rects[i].w==0) /* Clipped? */
{
continue;
}
@ -274,12 +302,13 @@ void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
{
fprintf(stderr,"error: PgDrawPhImageRectmx failed.\n");
fprintf(stderr,"ph_NormalUpdate: PgDrawPhImageRectmx failed.\n");
}
}
if (PgFlush() < 0)
{
fprintf(stderr,"error: PgFlush failed.\n");
fprintf(stderr,"ph_NormalUpdate: PgFlush failed.\n");
}
}
void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
@ -297,10 +326,10 @@ void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
PgSetClipping(0,NULL);
PgWaitHWIdle();
for (i=0; i<numrects; ++i)
{
if ( rects[i].w == 0 ) { /* Clipped? */
if (rects[i].w == 0) /* Clipped? */
{
continue;
}
@ -321,10 +350,10 @@ void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
}
if (PgFlush() < 0)
{
fprintf(stderr,"error: PgFlush failed.\n");
fprintf(stderr,"ph_OCUpdate: PgFlush failed.\n");
}
//later used to toggling double buffer
/* later used to toggling double buffer */
if (OCImage.current == 0)
{
OCImage.CurrentFrameData = OCImage.FrameData0;
@ -334,4 +363,3 @@ void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
OCImage.CurrentFrameData = OCImage.FrameData1;
}
}

View file

@ -62,97 +62,6 @@ static int compare_modes_by_res(const void* mode1, const void* mode2)
return -1;
}
/*
static int compare_modes_by_bpp(const void* mode1, const void* mode2)
{
if (PgGetVideoModeInfo(*(unsigned short*)mode1, &mode_info) < 0)
{
fprintf(stderr,"error: In compare_modes_by_bpp PgGetVideoModeInfo failed on mode: 0x%x\n",
*(unsigned short*)mode1);
return 0;
}
key1 = mode_info.bits_per_pixel;
if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0)
{
fprintf(stderr,"error: In compare_modes_by_bpp PgGetVideoModeInfo failed on mode: 0x%x\n",
*(unsigned short*)mode2);
return 0;
}
key2 = mode_info.bits_per_pixel;
if (key1 > key2)
return 1;
else if (key1 == key2)
return 0;
else
return -1;
}
*/
/*
int ph_GetVideoModes(_THIS)
{
unsigned short *front;
int i, bpp_group_size;
// TODO: add mode_list member to _THIS
if (PgGetVideoModeList( &mode_list ) < 0)
{
fprintf(stderr,"error: PgGetVideoModeList failed\n");
return -1;
}
// sort list first by bits per pixel (bpp),
// then sort groups with same bpp by resolution.
qsort(mode_list.modes, mode_list.num_modes, sizeof(unsigned short), compare_modes_by_bpp);
bpp_group_size = 1;
front = &mode_list.modes[0];
for(i=0;i<mode_list.num_modes-2;i++)
{
if (compare_modes_by_bpp(&mode_list.modes[i],&mode_list.modes[i+1]))
{
qsort(front, bpp_group_size, sizeof(unsigned short), compare_modes_by_res);
front = &mode_list.modes[i+1];
bpp_group_size = 1;
}
else
{
bpp_group_size++;
}
}
//SDL_modelist = (SDL_Rect **)malloc((mode_list.num_modes+1)*sizeof(SDL_Rect *));
if ( SDL_modelist ) {
for (i=0;i<mode_list.num_modes;i++) {
// SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect));
// if ( SDL_modelist[i] == NULL ) {
// break;
// }
if (PgGetVideoModeInfo(mode_list.modes[i], &mode_info) < 0)
{
fprintf(stderr,"error: PgGetVideoModeInfo failed on mode: 0x%x\n",
mode_list.modes[i]);
return -1;
}
SDL_modelist[i].x = 0;
SDL_modelist[i].y = 0;
SDL_modelist[i].w = mode_info.height;
SDL_modelist[i].h = mode_info.width;
}
//SDL_modelist[i] = NULL;
}
else
{
fprintf(stderr,"error: malloc failed on SDL_modelist\n");
return -1;
}
return 0;
}
*/
SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
int i = 0;
@ -208,9 +117,10 @@ void ph_FreeVideoModes(_THIS)
return;
}
#if 0
static void set_best_resolution(_THIS, int width, int height)
{
/* warning ! dead variable use_vidmode ! */
if ( use_vidmode ) {
PgDisplaySettings_t settings;
PgVideoModeInfo_t current_mode_info;
@ -281,11 +191,14 @@ static void set_best_resolution(_THIS, int width, int height)
int ph_ResizeFullScreen(_THIS)
{
if (currently_fullscreen) {
if (currently_fullscreen)
{
set_best_resolution(this, current_w, current_h);
}
return (1);
}
#endif /* 0 */
/* return the mode associated with width, height and bpp */
/* if there is no mode then zero is returned */
@ -354,7 +267,7 @@ int get_mode_any_format(int width, int height, int bpp)
}
if (i<mode_list.num_modes)
{
// get closest bpp
/* get closest bpp */
closest = i++;
if (mode_info.bits_per_pixel == bpp)
return mode_list.modes[ closest ];
@ -414,6 +327,8 @@ int ph_ToggleFullScreen(_THIS, int on)
int ph_EnterFullScreen(_THIS)
{
if (!currently_fullscreen)
{
if (this->screen)
{
if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
{
@ -421,29 +336,22 @@ int ph_EnterFullScreen(_THIS)
#endif /* HAVE_OPENGL */
return 0;
}
else
{
if (old_video_mode==-1)
{
PgGetGraphicsHWCaps(&graphics_card_caps);
old_video_mode=graphics_card_caps.current_video_mode;
old_refresh_rate=graphics_card_caps.current_rrate;
}
if (OCImage.direct_context == NULL)
{
OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
}
if (!OCImage.direct_context)
{
fprintf(stderr, "error: Can't create direct context\n" );
fprintf(stderr, "ph_EnterFullScreen: Can't create direct context\n" );
}
PdDirectStart(OCImage.direct_context);
currently_fullscreen = 1;
}
}
return 1;
}
@ -465,12 +373,15 @@ int ph_LeaveFullScreen(_THIS )
PdDirectStop(OCImage.direct_context);
PdReleaseDirectContext(OCImage.direct_context);
currently_fullscreen=0;
/* Restore old video mode */
if (old_video_mode != -1)
{
mymode_settings.mode= (unsigned short) old_video_mode;
mymode_settings.refresh= (unsigned short) old_refresh_rate;
mymode_settings.flags= 0;
if (PgSetVideoMode(&mymode_settings) < 0)
{
fprintf(stderr,"error: PgSetVideoMode failed\n");

View file

@ -33,7 +33,6 @@ static char rcsid =
#define PH_MAX_VIDEOMODES 127
//extern int ph_GetVideoModes(_THIS);
extern SDL_Rect **ph_ListModes(_THIS,SDL_PixelFormat *format, Uint32 flags);
extern void ph_FreeVideoModes(_THIS);
extern int ph_ResizeFullScreen(_THIS);

View file

@ -42,18 +42,18 @@ struct WMcursor {
void ph_FreeWMCursor(_THIS, WMcursor *cursor)
{
if ( window != NULL ) {
if (window != NULL)
{
SDL_Lock_EventThread();
if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0 ) < 0)
{
//TODO: output error msg
/* TODO: output error msg */
}
SDL_Unlock_EventThread();
}
//free(cursor->ph_cursor.images);
/* free(cursor->ph_cursor.images); */
free(cursor);
}
@ -182,10 +182,12 @@ void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
void ph_CheckMouseMode(_THIS)
{
/* If the mouse is hidden and input is grabbed, we use relative mode */
if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
(this->input_grab != SDL_GRAB_OFF) ) {
if ( !(SDL_cursorstate & CURSOR_VISIBLE) && (this->input_grab != SDL_GRAB_OFF))
{
mouse_relative = 1;
} else {
}
else
{
mouse_relative = 0;
}
}

View file

@ -175,7 +175,6 @@ static void ph_DeleteDevice(SDL_VideoDevice *device)
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 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
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 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* 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 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
PtArg_t arg[32];
PhDim_t dim;
int rtnval;
PgColor_t ph_palette[_Pg_MAX_PALETTE];
int i;
unsigned long *tempptr;
int pargc;
@ -330,6 +334,18 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
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;
@ -339,12 +355,9 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
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 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
{
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,6 +419,12 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
/* 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! */
@ -404,13 +439,13 @@ static void ph_VideoQuit(_THIS)
if (currently_fullscreen)
{
PdDirectStop(directContext);
PdReleaseDirectContext(directContext);
directContext=0;
currently_fullscreen=0;
ph_LeaveFullScreen(this);
}
#ifdef HAVE_OPENGL
/* prevent double SEGFAULT with parachute mode */
if (this->screen)
{
if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) &&
((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
{
@ -418,6 +453,7 @@ static void ph_VideoQuit(_THIS)
region_info.rid=PtWidgetRid(window);
PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);
}
}
PtFlush();
#endif /* HAVE_OPENGL */
@ -429,6 +465,12 @@ static void ph_VideoQuit(_THIS)
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 void ph_VideoQuit(_THIS)
static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
PgColor_t *in, *out;
int i, j;
int alloct_all = 1;
int i;
PhPoint_t point={0, 0};
PgColor_t syspalph[_Pg_MAX_PALETTE];
colors = this->screen->format->palette->colors;
in = alloca( ncolors*sizeof(PgColor_t) );
if ( in == NULL ) {
return 0;
/* palette emulation code, using palette of the PhImage_t struct */
if (desktoppal==SDLPH_PAL_EMULATE)
{
if ((SDL_Image) && (SDL_Image->palette))
{
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;
}
memset(in,0,ncolors*sizeof(PgColor_t));
out = alloca( ncolors*sizeof(PgColor_t) );
if ( out == NULL ) {
return 0;
}
/* image needs to be redrawed, very slow method */
PgDrawPhImage(&point, SDL_Image, 0);
}
else
{
if (desktoppal==SDLPH_PAL_SYSTEM)
{
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;
}
for (i=0,j=firstcolor;i<ncolors;i++,j++)
if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
{
in[i] |= colors[j].r<<16 ;
in[i] |= colors[j].g<<8 ;
in[i] |= colors[j].b ;
/* 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);
}
if ( (this->screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE )
else
{
if( PgSetPalette( in, 0, 0, ncolors, Pg_PALSET_HARD, 0) < 0 )
{
fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_HARD) failed\n");
return 0;
/* fullscreen mode must use hardware palette */
PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
}
}
else
{
if ( PgColorMatch(ncolors, in, out) < 0 )
{
fprintf(stderr,"error: PgColorMatch failed\n");
return 0;
}
for (i=0;i<ncolors;i++)
{
if (memcmp(&in[i],&out[i],sizeof(PgColor_t)))
{
alloct_all = 0;
break;
/* SDLPH_PAL_NONE do nothing */
}
}
if( PgSetPalette( out, 0, 0, ncolors, Pg_PALSET_SOFT, 0) < 0 )
{
fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_SOFT) failed\n");
return 0;
}
}
return alloct_all;
return 1;
}
#ifdef HAVE_OPENGL

View file

@ -39,6 +39,10 @@
#define PH_OGL_MAX_ATTRIBS 32
#define SDLPH_PAL_NONE 0x00000000L
#define SDLPH_PAL_EMULATE 0x00000001L
#define SDLPH_PAL_SYSTEM 0x00000002L
typedef union vidptr{
uint8_t *volatile ptr8;
uint16_t *volatile ptr16;
@ -55,14 +59,13 @@ typedef struct {
/* Private display data */
struct SDL_PrivateVideoData {
int local_ph; /* Flag: true if local display */
PtAppContext_t app;
PgDisplaySettings_t mode_settings;
PtWidget_t *Window; /* used to handle input events */
PhImage_t *image; /* used to display image */
#ifdef HAVE_OPENGL
PdOpenGLContext_t* OGLContext;
PdOpenGLContext_t* OGLContext; /* OpenGL context */
#endif /* HAVE_OPENGL */
PgColor_t ph_palette[_Pg_MAX_PALETTE];
struct {
PdDirectContext_t *direct_context;
@ -76,16 +79,9 @@ struct SDL_PrivateVideoData {
long flags;
} ocimage;
PhDrawContext_t *ScreenDC; //=NULL;
signed short old_video_mode; //=-1;
signed short old_refresh_rate; //=-1;
PgHWCaps_t graphics_card_caps;
PdDirectContext_t *directContext;
PdOffscreenContext_t *Buff[2];
struct _Ph_ctrl* ctrl_channel;
/* The variables used for displaying graphics */
PgHWCaps_t graphics_card_caps; /* Graphics card caps at the moment of start */
int old_video_mode; /* Stored mode before fullscreen switch */
int old_refresh_rate; /* Stored refresh rate befor fullscreen switch */
/* The current width and height of the fullscreen mode */
int current_w;
@ -107,6 +103,9 @@ struct SDL_PrivateVideoData {
WMcursor* BlankCursor;
int depth; /* current visual depth (not bpp) */
int desktopbpp; /* bpp of desktop at the moment of start */
int desktoppal; /* palette mode emulation or system */
int captionflag; /* caption setting flag */
int use_vidmode;
int currently_fullscreen;
@ -118,26 +117,22 @@ struct SDL_PrivateVideoData {
/* Prevent too many XSync() calls */
int blit_queued;
short *iconcolors; /* List of colors used by the icon */
PhEvent_t* event;
};
#define local_ph (this->hidden->local_ph)
#define app (this->hidden->app)
#define mode_settings (this->hidden->mode_settings)
#define window (this->hidden->Window)
#define oglctx (this->hidden->OGLContext)
#define directContext (this->hidden->directContext)
#define Buff (this->hidden->Buff)
#define ctrl_channel (this->hidden->ctrl_channel)
#define SDL_Image (this->hidden->image)
#define OCImage (this->hidden->ocimage)
#define old_video_mode (this->hidden->old_video_mode)
#define old_refresh_rate (this->hidden->old_refresh_rate)
#define graphics_card_caps (this->hidden->graphics_card_caps)
#define desktopbpp (this->hidden->desktopbpp)
#define desktoppal (this->hidden->desktoppal)
#define ph_palette (this->hidden->ph_palette)
/* Old variable names */
#define swap_pixels (this->hidden->swap_pixels)
#define current_w (this->hidden->current_w)
#define current_h (this->hidden->current_h)
#define mouse_last (this->hidden->mouse_last)
@ -150,8 +145,8 @@ struct SDL_PrivateVideoData {
#define switch_waiting (this->hidden->switch_waiting)
#define switch_time (this->hidden->switch_time)
#define blit_queued (this->hidden->blit_queued)
#define SDL_iconcolorIs (this->hidden->iconcolors)
#define event (this->hidden->event)
#define SDL_BlankCursor (this->hidden->BlankCursor)
#define captionflag (this->hidden->captionflag)
#endif /* _SDL_x11video_h */

View file

@ -48,175 +48,6 @@ static char rcsid =
void ph_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
{
#if 0 /*big*/
int ncolors;
PhImage_t *image;
PgColor_t* palette;
image = PhCreateImage( image,
icon->w,
icon->h,
Pg_IMAGE_DIRECT_888,
NULL, 0, 0 );
/* ---------------------------------------- */
SDL_Surface *sicon;
// XWMHints *wmhints;
// XImage *icon_image;
// Pixmap icon_pixmap;
// Pixmap mask_pixmap;
// GC GC;
// XGCValues GCvalues;
int i, b, dbpp;
SDL_Rect bounds;
Uint8 *LSBmask, *color_tried;
Visual *dvis;
/* Lock the event thread, in multi-threading environments */
SDL_Lock_EventThread();
/* The icon must use the default visual, depth and colormap of the
screen, so it might need a conversion */
// ? dbpp = DefaultDepth(SDL_Display, SDL_Screen);
switch(dbpp) {
case 15:
dbpp = 16; break;
case 24:
dbpp = 32; break;
}
dvis = DefaultVisual(SDL_Display, SDL_Screen);
/* The Visual struct is supposed to be opaque but we cheat a little */
sicon = SDL_CreateRGBSurface(SDL_SWSURFACE, icon->w, icon->h,
dbpp,
dvis->red_mask, dvis->green_mask,
dvis->blue_mask, 0);
if ( sicon == NULL ) {
goto done;
}
/* If we already have allocated colours from the default colormap,
copy them */
if(SDL_Visual == dvis && SDL_XColorMap == SDL_DisplayColormap
&& this->screen->format->palette && sicon->format->palette) {
memcpy(sicon->format->palette->colors,
this->screen->format->palette->colors,
this->screen->format->palette->ncolors * sizeof(SDL_Color));
}
bounds.x = 0;
bounds.y = 0;
bounds.w = icon->w;
bounds.h = icon->h;
if ( SDL_LowerBlit(icon, &bounds, sicon, &bounds) < 0 )
goto done;
/* Lock down the colors used in the colormap */
color_tried = NULL;
if ( sicon->format->BitsPerPixel == 8 ) {
SDL_Palette *palette;
Uint8 *p;
XColor wanted;
palette = sicon->format->palette;
color_tried = malloc(palette->ncolors);
if ( color_tried == NULL ) {
goto done;
}
if ( SDL_iconcolors != NULL ) {
free(SDL_iconcolors);
}
SDL_iconcolors = malloc(palette->ncolors
* sizeof(*SDL_iconcolors));
if ( SDL_iconcolors == NULL ) {
free(color_tried);
goto done;
}
memset(color_tried, 0, palette->ncolors);
memset(SDL_iconcolors, 0,
palette->ncolors * sizeof(*SDL_iconcolors));
p = (Uint8 *)sicon->pixels;
for ( i = sicon->w*sicon->h; i > 0; --i, ++p ) {
if ( ! color_tried[*p] ) {
wanted.pixel = *p;
wanted.red = (palette->colors[*p].r<<8);
wanted.green = (palette->colors[*p].g<<8);
wanted.blue = (palette->colors[*p].b<<8);
wanted.flags = (DoRed|DoGreen|DoBlue);
if (XAllocColor(SDL_Display,
SDL_DisplayColormap, &wanted)) {
++SDL_iconcolors[wanted.pixel];
}
color_tried[*p] = 1;
}
}
}
if ( color_tried != NULL ) {
free(color_tried);
}
/* Translate mask data to LSB order and set the icon mask */
i = (sicon->w/8)*sicon->h;
LSBmask = (Uint8 *)malloc(i);
if ( LSBmask == NULL ) {
goto done;
}
memset(LSBmask, 0, i);
while ( --i >= 0 ) {
for ( b=0; b<8; ++b )
LSBmask[i] |= (((mask[i]>>b)&0x01)<<(7-b));
}
mask_pixmap = XCreatePixmapFromBitmapData(SDL_Display, WMwindow,
LSBmask, sicon->w, sicon->h, 1L, 0L, 1);
/* Transfer the image to an X11 pixmap */
icon_image = XCreateImage(SDL_Display,
DefaultVisual(SDL_Display, SDL_Screen),
DefaultDepth(SDL_Display, SDL_Screen),
ZPixmap, 0, (char *)sicon->pixels, sicon->w, sicon->h,
((sicon->format)->BytesPerPixel == 3) ? 32 :
(sicon->format)->BytesPerPixel*8, 0);
icon_pixmap = XCreatePixmap(SDL_Display, SDL_Root, sicon->w, sicon->h,
DefaultDepth(SDL_Display, SDL_Screen));
GC = XCreateGC(SDL_Display, icon_pixmap, 0, &GCvalues);
XPutImage(SDL_Display, icon_pixmap, GC, icon_image,
0, 0, 0, 0, sicon->w, sicon->h);
XFreeGC(SDL_Display, GC);
XDestroyImage(icon_image);
free(LSBmask);
sicon->pixels = NULL;
#ifdef USE_ICON_WINDOW
/* Create an icon window and set the pixmap as its background */
icon_window = XCreateSimpleWindow(SDL_Display, SDL_Root,
0, 0, sicon->w, sicon->h, 0,
CopyFromParent, CopyFromParent);
XSetWindowBackgroundPixmap(SDL_Display, icon_window, icon_pixmap);
XClearWindow(SDL_Display, icon_window);
#endif
/* Set the window icon to the icon pixmap (and icon window) */
wmhints = XAllocWMHints();
wmhints->flags = (IconPixmapHint | IconMaskHint);
wmhints->icon_pixmap = icon_pixmap;
wmhints->icon_mask = mask_pixmap;
#ifdef USE_ICON_WINDOW
wmhints->flags |= IconWindowHint;
wmhints->icon_window = icon_window;
#endif
XSetWMHints(SDL_Display, WMwindow, wmhints);
XFree(wmhints);
XSync(SDL_Display, False);
done:
SDL_Unlock_EventThread();
if ( sicon != NULL ) {
SDL_FreeSurface(sicon);
}
#endif /*big*/
return;
}
@ -224,9 +55,17 @@ void ph_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
void ph_SetCaption(_THIS, const char *title, const char *icon)
{
SDL_Lock_EventThread();
if ( title != NULL ) {
/* check for set caption call before window init */
if (window!=NULL)
{
PtSetResource(window, Pt_ARG_WINDOW_TITLE, title, 0);
}
else
{
captionflag=1;
}
SDL_Unlock_EventThread();
}
@ -236,6 +75,7 @@ int ph_IconifyWindow(_THIS)
PhWindowEvent_t windowevent;
SDL_Lock_EventThread();
memset( &windowevent, 0, sizeof (event) );
windowevent.event_f = Ph_WM_HIDE;
windowevent.event_state = Ph_WM_EVSTATE_HIDE;