From d65ffefc67b7e3b676448ad6aedea4ffe577553f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 23 Mar 2002 20:19:44 +0000 Subject: [PATCH] Date: Sat, 23 Mar 2002 13:53:37 +0200 From: "Mike Gorchak" 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 | 184 ++++++++++++++---------- src/video/photon/SDL_ph_modes.c | 145 ++++--------------- src/video/photon/SDL_ph_modes_c.h | 1 - src/video/photon/SDL_ph_mouse.c | 54 +++---- src/video/photon/SDL_ph_video.c | 176 ++++++++++++++--------- src/video/photon/SDL_ph_video.h | 43 +++--- src/video/photon/SDL_ph_wm.c | 232 +++++------------------------- 7 files changed, 325 insertions(+), 510 deletions(-) diff --git a/src/video/photon/SDL_ph_image.c b/src/video/photon/SDL_ph_image.c index 7a3ff46bf..86f846606 100644 --- a/src/video/photon/SDL_ph_image.c +++ b/src/video/photon/SDL_ph_image.c @@ -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; + int type=0; + PgColor_t* palette=NULL; /* Determine image type */ switch(screen->format->BitsPerPixel) @@ -69,11 +73,28 @@ int ph_SetupImage(_THIS, SDL_Surface *screen) break; } - /* using shared memory for speed (set last param to 1) */ - if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL) + /* 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 { - fprintf(stderr,"error: PhCreateImage failed.\n"); - return -1; + /* 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,"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; @@ -200,14 +228,14 @@ int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags) { ph_DestroyImage(this, screen); - if( flags & SDL_HWSURFACE) + if (flags & SDL_HWSURFACE) { OCImage.flags = flags; /* needed for SDL_DOUBLEBUF check */ return ph_SetupOCImage(this, screen); } - else if(flags & SDL_OPENGL) + else if (flags & SDL_OPENGL) { - return ph_SetupOpenGLImage(this, screen); + return ph_SetupOpenGLImage(this, screen); } else { @@ -217,32 +245,32 @@ int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags) int ph_AllocHWSurface(_THIS, SDL_Surface *surface) { - return(-1); + return(-1); } void ph_FreeHWSurface(_THIS, SDL_Surface *surface) { - return; + return; } int ph_FlipHWSurface(_THIS, SDL_Surface *surface) { - return(0); + return(0); } int ph_LockHWSurface(_THIS, SDL_Surface *surface) { - if ( (surface == SDL_VideoSurface) && blit_queued ) { -// XSync(GFX_Display, False); - PgFlush(); - blit_queued = 0; - } - return(0); + if ((surface == SDL_VideoSurface) && blit_queued) { + PgFlush(); + blit_queued = 0; + } + + return(0); } void ph_UnlockHWSurface(_THIS, SDL_Surface *surface) { - return; + return; } static PhPoint_t ph_pos; @@ -258,80 +286,80 @@ void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects) void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) { - for ( i=0; i 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;iscreen->flags & SDL_OPENGL)==SDL_OPENGL) + if (this->screen) { + if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL) + { #ifdef HAVE_OPENGL #endif /* HAVE_OPENGL */ - return 0; + return 0; + } } - else + + if (OCImage.direct_context == NULL) { - 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; - } + OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext(); + } - if(OCImage.direct_context == NULL) - { - OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext(); - } - if(!OCImage.direct_context) - { - fprintf(stderr, "error: Can't create direct context\n" ); - } + if (!OCImage.direct_context) + { + fprintf(stderr, "ph_EnterFullScreen: Can't create direct context\n" ); + } - PdDirectStart(OCImage.direct_context); + PdDirectStart(OCImage.direct_context); - currently_fullscreen = 1; - } + currently_fullscreen = 1; } return 1; } -int ph_LeaveFullScreen(_THIS ) +int ph_LeaveFullScreen(_THIS) { PgDisplaySettings_t mymode_settings; @@ -464,13 +372,16 @@ 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; + mymode_settings.flags= 0; + if (PgSetVideoMode(&mymode_settings) < 0) { fprintf(stderr,"error: PgSetVideoMode failed\n"); @@ -478,7 +389,7 @@ int ph_LeaveFullScreen(_THIS ) } old_video_mode=-1; - old_refresh_rate=-1; + old_refresh_rate=-1; } } diff --git a/src/video/photon/SDL_ph_modes_c.h b/src/video/photon/SDL_ph_modes_c.h index dee76b714..d1579ffdd 100644 --- a/src/video/photon/SDL_ph_modes_c.h +++ b/src/video/photon/SDL_ph_modes_c.h @@ -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); diff --git a/src/video/photon/SDL_ph_mouse.c b/src/video/photon/SDL_ph_mouse.c index 39fa9a244..34a2f6ba3 100644 --- a/src/video/photon/SDL_ph_mouse.c +++ b/src/video/photon/SDL_ph_mouse.c @@ -36,25 +36,25 @@ static char rcsid = #include "SDL_ph_mouse_c.h" struct WMcursor { - PhCursorDef_t *ph_cursor ; + PhCursorDef_t *ph_cursor ; }; void ph_FreeWMCursor(_THIS, WMcursor *cursor) { + if (window != NULL) + { + SDL_Lock_EventThread(); - if ( window != NULL ) { - SDL_Lock_EventThread(); - - if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0 ) < 0) - { - //TODO: output error msg - } - - SDL_Unlock_EventThread(); - } - //free(cursor->ph_cursor.images); - free(cursor); + if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0 ) < 0) + { + /* TODO: output error msg */ + } + + SDL_Unlock_EventThread(); + } + /* free(cursor->ph_cursor.images); */ + free(cursor); } WMcursor *ph_CreateWMCursor(_THIS, @@ -120,7 +120,7 @@ WMcursor *ph_CreateWMCursor(_THIS, PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor) { - return(*cursor->ph_cursor); + return(*cursor->ph_cursor); } int ph_ShowWMCursor(_THIS, WMcursor *cursor) @@ -170,22 +170,24 @@ int ph_ShowWMCursor(_THIS, WMcursor *cursor) void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y) { - short abs_x, abs_y; + short abs_x, abs_y; - SDL_Lock_EventThread(); - PtGetAbsPosition( window, &abs_x, &abs_y ); - PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y ); - SDL_Unlock_EventThread(); + SDL_Lock_EventThread(); + PtGetAbsPosition( window, &abs_x, &abs_y ); + PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y ); + SDL_Unlock_EventThread(); } 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) ) { - mouse_relative = 1; - } else { - mouse_relative = 0; - } + /* If the mouse is hidden and input is grabbed, we use relative mode */ + if ( !(SDL_cursorstate & CURSOR_VISIBLE) && (this->input_grab != SDL_GRAB_OFF)) + { + mouse_relative = 1; + } + else + { + mouse_relative = 0; + } } diff --git a/src/video/photon/SDL_ph_video.c b/src/video/photon/SDL_ph_video.c index 99cb27030..db9e708a5 100644 --- a/src/video/photon/SDL_ph_video.c +++ b/src/video/photon/SDL_ph_video.c @@ -150,8 +150,8 @@ static SDL_VideoDevice *ph_CreateDevice(int devindex) } 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 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; @@ -281,7 +285,7 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, window=PtCreateWidget(PtWindow, NULL, pargc-1, arg); PtRealizeWidget(window); - + PtFlush(); } @@ -330,21 +334,30 @@ 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; + 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 @@ 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,10 +419,16 @@ 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! */ - return(current); + return (current); } static void ph_VideoQuit(_THIS) @@ -404,19 +439,20 @@ static void ph_VideoQuit(_THIS) 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, ®ion_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, ®ion_info, NULL, NULL); + } } PtFlush(); @@ -428,6 +464,12 @@ static void ph_VideoQuit(_THIS) 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 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; - - colors = this->screen->format->palette->colors; - - in = alloca( ncolors*sizeof(PgColor_t) ); - if ( in == NULL ) { - return 0; - } - memset(in,0,ncolors*sizeof(PgColor_t)); + int i; + PhPoint_t point={0, 0}; + PgColor_t syspalph[_Pg_MAX_PALETTE]; - out = alloca( ncolors*sizeof(PgColor_t) ); - if ( out == 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; ipalette[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; + } + } + /* image needs to be redrawed, very slow method */ + PgDrawPhImage(&point, SDL_Image, 0); } - - for (i=0,j=firstcolor;iscreen->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 ) + else + { + if (desktoppal==SDLPH_PAL_SYSTEM) { - fprintf(stderr,"error: PgColorMatch failed\n"); - return 0; + for (i=firstcolor; iscreen->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); + } } - for (i=0;ihidden->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 */ diff --git a/src/video/photon/SDL_ph_wm.c b/src/video/photon/SDL_ph_wm.c index 4698f68c4..36967a6cd 100644 --- a/src/video/photon/SDL_ph_wm.c +++ b/src/video/photon/SDL_ph_wm.c @@ -48,207 +48,47 @@ 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; + return; } /* Set window caption */ void ph_SetCaption(_THIS, const char *title, const char *icon) { - SDL_Lock_EventThread(); - if ( title != NULL ) { - PtSetResource(window, Pt_ARG_WINDOW_TITLE, title, 0); - } - SDL_Unlock_EventThread(); + SDL_Lock_EventThread(); + + /* 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(); } /* Iconify current window */ int ph_IconifyWindow(_THIS) { - PhWindowEvent_t windowevent; + PhWindowEvent_t windowevent; - SDL_Lock_EventThread(); - memset( &windowevent, 0, sizeof (event) ); - windowevent.event_f = Ph_WM_HIDE; - windowevent.event_state = Ph_WM_EVSTATE_HIDE; - windowevent.rid = PtWidgetRid( window ); - PtForwardWindowEvent( &windowevent ); - SDL_Unlock_EventThread(); - - return 0; + SDL_Lock_EventThread(); + + memset( &windowevent, 0, sizeof (event) ); + windowevent.event_f = Ph_WM_HIDE; + windowevent.event_state = Ph_WM_EVSTATE_HIDE; + windowevent.rid = PtWidgetRid( window ); + PtForwardWindowEvent( &windowevent ); + SDL_Unlock_EventThread(); + + return 0; } SDL_GrabMode ph_GrabInputNoLock(_THIS, SDL_GrabMode mode) { - return(mode); + return(mode); } SDL_GrabMode ph_GrabInput(_THIS, SDL_GrabMode mode) @@ -280,14 +120,14 @@ SDL_GrabMode ph_GrabInput(_THIS, SDL_GrabMode mode) int ph_GetWMInfo(_THIS, SDL_SysWMinfo *info) { - if (info->version.major <= SDL_MAJOR_VERSION) - { - return 1; - } - else - { - SDL_SetError("Application not compiled with SDL %d.%d\n", - SDL_MAJOR_VERSION, SDL_MINOR_VERSION); - return -1; - } + if (info->version.major <= SDL_MAJOR_VERSION) + { + return 1; + } + else + { + SDL_SetError("Application not compiled with SDL %d.%d\n", + SDL_MAJOR_VERSION, SDL_MINOR_VERSION); + return -1; + } }