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_endian.h"
#include "SDL_ph_image_c.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 ph_SetupImage(_THIS, SDL_Surface *screen)
{ {
int type = 0; int type=0;
PgColor_t* palette=NULL;
/* Determine image type */ /* Determine image type */
switch(screen->format->BitsPerPixel) switch(screen->format->BitsPerPixel)
@ -69,11 +73,28 @@ int ph_SetupImage(_THIS, SDL_Surface *screen)
break; break;
} }
/* using shared memory for speed (set last param to 1) */ /* palette emulation code */
if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL) if ((screen->format->BitsPerPixel==8) && (desktoppal==SDLPH_PAL_EMULATE))
{ {
fprintf(stderr,"error: PhCreateImage failed.\n"); /* creating image palette */
return -1; 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,"ph_SetupImage: PhCreateImage failed.\n");
return -1;
}
} }
screen->pixels = SDL_Image->image; screen->pixels = SDL_Image->image;
@ -83,7 +104,7 @@ int ph_SetupImage(_THIS, SDL_Surface *screen)
return 0; return 0;
} }
int ph_SetupOCImage(_THIS, SDL_Surface *screen) //Offscreen context int ph_SetupOCImage(_THIS, SDL_Surface *screen)
{ {
int type = 0; int type = 0;
@ -185,11 +206,18 @@ void ph_DestroyImage(_THIS, SDL_Surface *screen)
if (SDL_Image) if (SDL_Image)
{ {
/* if palette allocated, free it */
if (SDL_Image->palette)
{
free(SDL_Image->palette);
}
PgShmemDestroy(SDL_Image->image); PgShmemDestroy(SDL_Image->image);
free(SDL_Image); free(SDL_Image);
SDL_Image = NULL;
} }
/* Must be zeroed everytime */
SDL_Image = NULL;
if (screen) if (screen)
{ {
screen->pixels = NULL; screen->pixels = NULL;
@ -200,14 +228,14 @@ int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags)
{ {
ph_DestroyImage(this, screen); ph_DestroyImage(this, screen);
if( flags & SDL_HWSURFACE) if (flags & SDL_HWSURFACE)
{ {
OCImage.flags = flags; /* needed for SDL_DOUBLEBUF check */ OCImage.flags = flags; /* needed for SDL_DOUBLEBUF check */
return ph_SetupOCImage(this, screen); 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 else
{ {
@ -217,32 +245,32 @@ int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags)
int ph_AllocHWSurface(_THIS, SDL_Surface *surface) int ph_AllocHWSurface(_THIS, SDL_Surface *surface)
{ {
return(-1); return(-1);
} }
void ph_FreeHWSurface(_THIS, SDL_Surface *surface) void ph_FreeHWSurface(_THIS, SDL_Surface *surface)
{ {
return; return;
} }
int ph_FlipHWSurface(_THIS, SDL_Surface *surface) int ph_FlipHWSurface(_THIS, SDL_Surface *surface)
{ {
return(0); return(0);
} }
int ph_LockHWSurface(_THIS, SDL_Surface *surface) int ph_LockHWSurface(_THIS, SDL_Surface *surface)
{ {
if ( (surface == SDL_VideoSurface) && blit_queued ) { if ((surface == SDL_VideoSurface) && blit_queued) {
// XSync(GFX_Display, False); PgFlush();
PgFlush(); blit_queued = 0;
blit_queued = 0; }
}
return(0); return(0);
} }
void ph_UnlockHWSurface(_THIS, SDL_Surface *surface) void ph_UnlockHWSurface(_THIS, SDL_Surface *surface)
{ {
return; return;
} }
static PhPoint_t ph_pos; 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) void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
{ {
for ( i=0; i<numrects; ++i ) for ( i=0; i<numrects; ++i )
{ {
if ( rects[i].w == 0 ) { /* Clipped? */ if (rects[i].w==0) /* Clipped? */
continue; {
continue;
} }
ph_pos.x = rects[i].x; ph_pos.x = rects[i].x;
ph_pos.y = rects[i].y; ph_pos.y = rects[i].y;
ph_rect.ul.x = rects[i].x; ph_rect.ul.x = rects[i].x;
ph_rect.ul.y = rects[i].y; ph_rect.ul.y = rects[i].y;
ph_rect.lr.x = rects[i].x + rects[i].w; ph_rect.lr.x = rects[i].x + rects[i].w;
ph_rect.lr.y = rects[i].y + rects[i].h; ph_rect.lr.y = rects[i].y + rects[i].h;
if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
{
fprintf(stderr,"ph_NormalUpdate: PgDrawPhImageRectmx failed.\n");
}
}
if (PgDrawPhImageRectmx( &ph_pos, SDL_Image, &ph_rect, 0 ) < 0)
{
fprintf(stderr,"error: PgDrawPhImageRectmx failed.\n");
}
}
if (PgFlush() < 0) 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) void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
{ {
PhPoint_t zero = {0}; PhPoint_t zero = {0};
PhRect_t src_rect; PhRect_t src_rect;
PhRect_t dest_rect; PhRect_t dest_rect;
if(OCImage.direct_context == NULL) if(OCImage.direct_context == NULL)
{ {
return; return;
} }
PgSetRegion(PtWidgetRid(window));
PgSetClipping(0,NULL);
PgWaitHWIdle();
for ( i=0; i<numrects; ++i ) PgSetRegion(PtWidgetRid(window));
{ PgSetClipping(0,NULL);
if ( rects[i].w == 0 ) { /* Clipped? */ PgWaitHWIdle();
continue;
for (i=0; i<numrects; ++i)
{
if (rects[i].w == 0) /* Clipped? */
{
continue;
} }
src_rect.ul.x=rects[i].x; src_rect.ul.x=rects[i].x;
src_rect.ul.y=rects[i].y; src_rect.ul.y=rects[i].y;
dest_rect.ul.x=rects[i].x; dest_rect.ul.x=rects[i].x;
dest_rect.ul.y=rects[i].y; dest_rect.ul.y=rects[i].y;
dest_rect.lr.x=src_rect.lr.x= rects[i].x +rects[i].w; dest_rect.lr.x=src_rect.lr.x= rects[i].x +rects[i].w;
dest_rect.lr.y=src_rect.lr.y= rects[i].y +rects[i].h; dest_rect.lr.y=src_rect.lr.y= rects[i].y +rects[i].h;
zero.x = zero.y = 0; zero.x = zero.y = 0;
PgSetTranslation (&zero, 0); PgSetTranslation (&zero, 0);
PgSetRegion(PtWidgetRid(window)); PgSetRegion(PtWidgetRid(window));
PgSetClipping(0,NULL); PgSetClipping(0,NULL);
PgContextBlitArea(OCImage.offscreen_context, (PhArea_t *)(&src_rect), NULL, (PhArea_t *)(&dest_rect)); PgContextBlitArea(OCImage.offscreen_context, (PhArea_t *)(&src_rect), NULL, (PhArea_t *)(&dest_rect));
} }
if (PgFlush() < 0) 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) if (OCImage.current == 0)
{ {
OCImage.CurrentFrameData = OCImage.FrameData0; OCImage.CurrentFrameData = OCImage.FrameData0;
} }
else else
{ {
OCImage.CurrentFrameData = OCImage.FrameData1; OCImage.CurrentFrameData = OCImage.FrameData1;
} }
} }

View file

@ -62,97 +62,6 @@ static int compare_modes_by_res(const void* mode1, const void* mode2)
return -1; 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) SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{ {
int i = 0; int i = 0;
@ -208,9 +117,10 @@ void ph_FreeVideoModes(_THIS)
return; return;
} }
#if 0
static void set_best_resolution(_THIS, int width, int height) static void set_best_resolution(_THIS, int width, int height)
{ {
/* warning ! dead variable use_vidmode ! */
if ( use_vidmode ) { if ( use_vidmode ) {
PgDisplaySettings_t settings; PgDisplaySettings_t settings;
PgVideoModeInfo_t current_mode_info; PgVideoModeInfo_t current_mode_info;
@ -281,11 +191,14 @@ static void set_best_resolution(_THIS, int width, int height)
int ph_ResizeFullScreen(_THIS) int ph_ResizeFullScreen(_THIS)
{ {
if (currently_fullscreen) { if (currently_fullscreen)
{
set_best_resolution(this, current_w, current_h); set_best_resolution(this, current_w, current_h);
} }
return (1); return (1);
} }
#endif /* 0 */
/* return the mode associated with width, height and bpp */ /* return the mode associated with width, height and bpp */
/* if there is no mode then zero is returned */ /* 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) if (i<mode_list.num_modes)
{ {
// get closest bpp /* get closest bpp */
closest = i++; closest = i++;
if (mode_info.bits_per_pixel == bpp) if (mode_info.bits_per_pixel == bpp)
return mode_list.modes[ closest ]; return mode_list.modes[ closest ];
@ -415,40 +328,35 @@ int ph_EnterFullScreen(_THIS)
{ {
if (!currently_fullscreen) if (!currently_fullscreen)
{ {
if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL) if (this->screen)
{ {
if ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)
{
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
#endif /* HAVE_OPENGL */ #endif /* HAVE_OPENGL */
return 0; return 0;
}
} }
else
if (OCImage.direct_context == NULL)
{ {
if (old_video_mode==-1) OCImage.direct_context=(PdDirectContext_t*)PdCreateDirectContext();
{
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" );
}
PdDirectStart(OCImage.direct_context);
currently_fullscreen = 1;
} }
if (!OCImage.direct_context)
{
fprintf(stderr, "ph_EnterFullScreen: Can't create direct context\n" );
}
PdDirectStart(OCImage.direct_context);
currently_fullscreen = 1;
} }
return 1; return 1;
} }
int ph_LeaveFullScreen(_THIS ) int ph_LeaveFullScreen(_THIS)
{ {
PgDisplaySettings_t mymode_settings; PgDisplaySettings_t mymode_settings;
@ -464,13 +372,16 @@ int ph_LeaveFullScreen(_THIS )
{ {
PdDirectStop(OCImage.direct_context); PdDirectStop(OCImage.direct_context);
PdReleaseDirectContext(OCImage.direct_context); PdReleaseDirectContext(OCImage.direct_context);
currently_fullscreen=0;
/* Restore old video mode */ /* Restore old video mode */
if (old_video_mode != -1) if (old_video_mode != -1)
{ {
mymode_settings.mode= (unsigned short) old_video_mode; mymode_settings.mode= (unsigned short) old_video_mode;
mymode_settings.refresh= (unsigned short) old_refresh_rate; mymode_settings.refresh= (unsigned short) old_refresh_rate;
mymode_settings.flags = 0; mymode_settings.flags= 0;
if (PgSetVideoMode(&mymode_settings) < 0) if (PgSetVideoMode(&mymode_settings) < 0)
{ {
fprintf(stderr,"error: PgSetVideoMode failed\n"); fprintf(stderr,"error: PgSetVideoMode failed\n");
@ -478,7 +389,7 @@ int ph_LeaveFullScreen(_THIS )
} }
old_video_mode=-1; old_video_mode=-1;
old_refresh_rate=-1; old_refresh_rate=-1;
} }
} }

View file

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

View file

@ -36,25 +36,25 @@ static char rcsid =
#include "SDL_ph_mouse_c.h" #include "SDL_ph_mouse_c.h"
struct WMcursor { struct WMcursor {
PhCursorDef_t *ph_cursor ; PhCursorDef_t *ph_cursor ;
}; };
void ph_FreeWMCursor(_THIS, WMcursor *cursor) void ph_FreeWMCursor(_THIS, WMcursor *cursor)
{ {
if (window != NULL)
{
SDL_Lock_EventThread();
if ( window != NULL ) { if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0 ) < 0)
SDL_Lock_EventThread(); {
/* TODO: output error msg */
if (PtSetResource( window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_INHERIT, 0 ) < 0) }
{
//TODO: output error msg SDL_Unlock_EventThread();
} }
/* free(cursor->ph_cursor.images); */
SDL_Unlock_EventThread(); free(cursor);
}
//free(cursor->ph_cursor.images);
free(cursor);
} }
WMcursor *ph_CreateWMCursor(_THIS, WMcursor *ph_CreateWMCursor(_THIS,
@ -120,7 +120,7 @@ WMcursor *ph_CreateWMCursor(_THIS,
PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor) PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor)
{ {
return(*cursor->ph_cursor); return(*cursor->ph_cursor);
} }
int ph_ShowWMCursor(_THIS, WMcursor *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) void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
{ {
short abs_x, abs_y; short abs_x, abs_y;
SDL_Lock_EventThread(); SDL_Lock_EventThread();
PtGetAbsPosition( window, &abs_x, &abs_y ); PtGetAbsPosition( window, &abs_x, &abs_y );
PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y ); PhMoveCursorAbs( PhInputGroup(NULL), x + abs_x, y + abs_y );
SDL_Unlock_EventThread(); SDL_Unlock_EventThread();
} }
void ph_CheckMouseMode(_THIS) void ph_CheckMouseMode(_THIS)
{ {
/* If the mouse is hidden and input is grabbed, we use relative mode */ /* If the mouse is hidden and input is grabbed, we use relative mode */
if ( !(SDL_cursorstate & CURSOR_VISIBLE) && if ( !(SDL_cursorstate & CURSOR_VISIBLE) && (this->input_grab != SDL_GRAB_OFF))
(this->input_grab != SDL_GRAB_OFF) ) { {
mouse_relative = 1; mouse_relative = 1;
} else { }
mouse_relative = 0; else
} {
mouse_relative = 0;
}
} }

View file

@ -150,8 +150,8 @@ static SDL_VideoDevice *ph_CreateDevice(int devindex)
} }
VideoBootStrap ph_bootstrap = { VideoBootStrap ph_bootstrap = {
"photon", "QNX Photon video output", "photon", "QNX Photon video output",
ph_Available, ph_CreateDevice ph_Available, ph_CreateDevice
}; };
static void ph_DeleteDevice(SDL_VideoDevice *device) 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) static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
{ {
PgColor_t ph_palette[_Pg_MAX_PALETTE];
int i; int i;
unsigned long *tempptr; unsigned long *tempptr;
int rtnval; int rtnval;
@ -184,6 +183,11 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
window=NULL; window=NULL;
oglctx=NULL; oglctx=NULL;
desktoppal=SDLPH_PAL_NONE;
captionflag=0;
old_video_mode=-1;
old_refresh_rate=-1;
if (NULL == (event = malloc(EVENT_SIZE))) 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 */ /* We need to return BytesPerPixel as it in used by CreateRGBsurface */
vformat->BitsPerPixel = my_mode_info.bits_per_pixel; vformat->BitsPerPixel = my_mode_info.bits_per_pixel;
vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width; 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 */ /* return a palette if we are in 256 color mode */
if (vformat->BitsPerPixel == 8) if (vformat->BitsPerPixel == 8)
@ -253,7 +258,6 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
PtArg_t arg[32]; PtArg_t arg[32];
PhDim_t dim; PhDim_t dim;
int rtnval; int rtnval;
PgColor_t ph_palette[_Pg_MAX_PALETTE];
int i; int i;
unsigned long *tempptr; unsigned long *tempptr;
int pargc; int pargc;
@ -281,7 +285,7 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
window=PtCreateWidget(PtWindow, NULL, pargc-1, arg); window=PtCreateWidget(PtWindow, NULL, pargc-1, arg);
PtRealizeWidget(window); PtRealizeWidget(window);
PtFlush(); PtFlush();
} }
@ -330,21 +334,30 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
exit(1); 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.mode = mode;
settings.refresh = 0; settings.refresh = 0;
settings.flags = 0; settings.flags = 0;
if (PgSetVideoMode( &settings ) < 0) if (PgSetVideoMode(&settings) < 0)
{ {
fprintf(stderr,"error: PgSetVideoMode failed\n"); fprintf(stderr,"error: PgSetVideoMode failed\n");
} }
/* Get the true height and width */
current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */ current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
/* Begin direct mode */ /* Begin direct mode */
ph_EnterFullScreen(this); ph_EnterFullScreen(this);
} /* end fullscreen flag */ } /* 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 */ 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 */ /* 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 */ /* Must call at least once it setup image planes */
ph_ResizeImage(this, current, flags); ph_ResizeImage(this, current, flags);
/* delayed set caption call */
if (captionflag)
{
ph_SetCaption(this, this->wm_title, NULL);
}
SDL_Unlock_EventThread(); SDL_Unlock_EventThread();
/* We're done! */ /* We're done! */
return(current); return (current);
} }
static void ph_VideoQuit(_THIS) static void ph_VideoQuit(_THIS)
@ -404,19 +439,20 @@ static void ph_VideoQuit(_THIS)
if (currently_fullscreen) if (currently_fullscreen)
{ {
PdDirectStop(directContext); ph_LeaveFullScreen(this);
PdReleaseDirectContext(directContext);
directContext=0;
currently_fullscreen=0;
} }
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL
if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) && /* prevent double SEGFAULT with parachute mode */
((this->screen->flags & SDL_OPENGL)==SDL_OPENGL)) if (this->screen)
{ {
region_info.cursor_type=Ph_CURSOR_POINTER; if (((this->screen->flags & SDL_FULLSCREEN)==SDL_FULLSCREEN) &&
region_info.rid=PtWidgetRid(window); ((this->screen->flags & SDL_OPENGL)==SDL_OPENGL))
PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL); {
region_info.cursor_type=Ph_CURSOR_POINTER;
region_info.rid=PtWidgetRid(window);
PhRegionChange(Ph_REGION_CURSOR, 0, &region_info, NULL, NULL);
}
} }
PtFlush(); PtFlush();
@ -428,6 +464,12 @@ static void ph_VideoQuit(_THIS)
PtDestroyWidget(window); PtDestroyWidget(window);
window=NULL; 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 #ifdef HAVE_OPENGL
if (oglctx) if (oglctx)
@ -441,60 +483,58 @@ static void ph_VideoQuit(_THIS)
static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{ {
PgColor_t *in, *out; int i;
int i, j; PhPoint_t point={0, 0};
int alloct_all = 1; PgColor_t syspalph[_Pg_MAX_PALETTE];
colors = this->screen->format->palette->colors; /* palette emulation code, using palette of the PhImage_t struct */
if (desktoppal==SDLPH_PAL_EMULATE)
in = alloca( ncolors*sizeof(PgColor_t) ); {
if ( in == NULL ) { if ((SDL_Image) && (SDL_Image->palette))
return 0; {
} for (i=firstcolor; i<firstcolor+ncolors; i++)
memset(in,0,ncolors*sizeof(PgColor_t)); {
SDL_Image->palette[i] = 0x00000000UL;
out = alloca( ncolors*sizeof(PgColor_t) ); SDL_Image->palette[i] |= colors[i-firstcolor].r<<16;
if ( out == NULL ) { SDL_Image->palette[i] |= colors[i-firstcolor].g<<8;
return 0; SDL_Image->palette[i] |= colors[i-firstcolor].b;
}
}
/* image needs to be redrawed, very slow method */
PgDrawPhImage(&point, SDL_Image, 0);
} }
else
for (i=0,j=firstcolor;i<ncolors;i++,j++) {
{ if (desktoppal==SDLPH_PAL_SYSTEM)
in[i] |= colors[j].r<<16 ; {
in[i] |= colors[j].g<<8 ; for (i=firstcolor; i<firstcolor+ncolors; i++)
in[i] |= colors[j].b ; {
} syspalph[i] = 0x00000000UL;
syspalph[i] |= colors[i-firstcolor].r<<16;
syspalph[i] |= colors[i-firstcolor].g<<8;
syspalph[i] |= colors[i-firstcolor].b;
}
if ( (this->screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN)
{ {
if( PgSetPalette( in, 0, 0, ncolors, Pg_PALSET_HARD, 0) < 0 ) /* window mode must use soft palette */
{ PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0);
fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_HARD) failed\n"); /* image needs to be redrawed, very slow method */
return 0; PgDrawPhImage(&point, SDL_Image, 0);
} }
} else
else {
{ /* fullscreen mode must use hardware palette */
if ( PgColorMatch(ncolors, in, out) < 0 ) PgSetPalette((PgColor_t*)&syspalph, 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0);
{ }
fprintf(stderr,"error: PgColorMatch failed\n");
return 0;
} }
for (i=0;i<ncolors;i++) else
{
if (memcmp(&in[i],&out[i],sizeof(PgColor_t)))
{
alloct_all = 0;
break;
}
}
if( PgSetPalette( out, 0, 0, ncolors, Pg_PALSET_SOFT, 0) < 0 )
{ {
fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_SOFT) failed\n"); /* SDLPH_PAL_NONE do nothing */
return 0;
} }
} }
return alloct_all;
return 1;
} }
#ifdef HAVE_OPENGL #ifdef HAVE_OPENGL

View file

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

View file

@ -48,207 +48,47 @@ static char rcsid =
void ph_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask) void ph_SetIcon(_THIS, SDL_Surface *icon, Uint8 *mask)
{ {
return;
#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;
} }
/* Set window caption */ /* Set window caption */
void ph_SetCaption(_THIS, const char *title, const char *icon) void ph_SetCaption(_THIS, const char *title, const char *icon)
{ {
SDL_Lock_EventThread(); SDL_Lock_EventThread();
if ( title != NULL ) {
PtSetResource(window, Pt_ARG_WINDOW_TITLE, title, 0); /* check for set caption call before window init */
} if (window!=NULL)
SDL_Unlock_EventThread(); {
PtSetResource(window, Pt_ARG_WINDOW_TITLE, title, 0);
}
else
{
captionflag=1;
}
SDL_Unlock_EventThread();
} }
/* Iconify current window */ /* Iconify current window */
int ph_IconifyWindow(_THIS) int ph_IconifyWindow(_THIS)
{ {
PhWindowEvent_t windowevent; PhWindowEvent_t windowevent;
SDL_Lock_EventThread(); SDL_Lock_EventThread();
memset( &windowevent, 0, sizeof (event) );
windowevent.event_f = Ph_WM_HIDE; memset( &windowevent, 0, sizeof (event) );
windowevent.event_state = Ph_WM_EVSTATE_HIDE; windowevent.event_f = Ph_WM_HIDE;
windowevent.rid = PtWidgetRid( window ); windowevent.event_state = Ph_WM_EVSTATE_HIDE;
PtForwardWindowEvent( &windowevent ); windowevent.rid = PtWidgetRid( window );
SDL_Unlock_EventThread(); PtForwardWindowEvent( &windowevent );
SDL_Unlock_EventThread();
return 0;
return 0;
} }
SDL_GrabMode ph_GrabInputNoLock(_THIS, SDL_GrabMode mode) SDL_GrabMode ph_GrabInputNoLock(_THIS, SDL_GrabMode mode)
{ {
return(mode); return(mode);
} }
SDL_GrabMode ph_GrabInput(_THIS, SDL_GrabMode 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) int ph_GetWMInfo(_THIS, SDL_SysWMinfo *info)
{ {
if (info->version.major <= SDL_MAJOR_VERSION) if (info->version.major <= SDL_MAJOR_VERSION)
{ {
return 1; return 1;
} }
else else
{ {
SDL_SetError("Application not compiled with SDL %d.%d\n", SDL_SetError("Application not compiled with SDL %d.%d\n",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION); SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
return -1; return -1;
} }
} }