Commit 3a8a4d7b authored by Sam Lantinga's avatar Sam Lantinga

Added QNX cleanups by Mike Gorchak (thanks!)

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40267
parent 86a83938
README by Mike Gorchak <mike@malva.com.ua>
Experimentally added OpenGL support in window mode (in fullscreen
mode not yet). If you have QNX RtP v6.1.0 w/ or w/o Patch A you need
to download new Photon3D runtime from http://developers.qnx.com. The
versions of OS before 6.1.0 is not supported. OpenGL support is very
raw. It is often fail.
Some building issues:
Run configure script without x11 support, e.g.:
./configure --prefix=/usr/local --disable-video-x11
In test directory also run ./configure script without x11 support, e.g.:
./configure --with-sdl-prefix=/usr/local \
--with-sdl-exec-prefix=/usr/local \
--prefix=/usr/local --without-x
......@@ -1391,7 +1391,9 @@ void SDL_GL_SwapBuffers(void)
SDL_VideoDevice *this = current_video;
if ( video->screen->flags & SDL_OPENGL ) {
video->GL_SwapBuffers( this );
video->GL_SwapBuffers(this);
} else {
SDL_SetError("OpenGL video mode has not been set");
}
}
......
......@@ -55,9 +55,10 @@ SDL_keysym *ph_TranslateKey(PhKeyEvent_t *key, SDL_keysym *keysym);
(idea shamelessly lifted from GII -- thanks guys! :)
*/
/*
static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent)
{
PhEvent_t* peekevent;
// PhEvent_t* peekevent;
PhKeyEvent_t* keyEvent;
int repeated;
......@@ -84,11 +85,13 @@ static int ph_KeyRepeat(_THIS, PhKeyEvent_t* keyevent)
}
break;
default: /* no events pending */
default: // no events pending
}
return(repeated);
}
*/
/* Note: The X server buffers and accumulates mouse motion events, so
the motion event generated by the warp may not appear exactly as we
expect it to. We work around this (and improve performance) by only
......@@ -118,7 +121,7 @@ static inline int X11_WarpedMotion(_THIS, XEvent *xevent)
(xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) ||
(xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
(xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
/* Get the events that have accumulated */
// Get the events that have accumulated
/* while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
deltax = xevent->xmotion.x - mouse_last.x;
deltay = xevent->xmotion.y - mouse_last.y;
......@@ -161,6 +164,7 @@ static inline int X11_WarpedMotion(_THIS, XEvent *xevent)
/* Control which motion flags the window has set, a flags value of -1 sets
* MOTION_BUTTON and MOTION_NOBUTTON */
static void set_motion_sensitivity(_THIS, unsigned int flags)
{
int rid, fields = Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
......
......@@ -129,24 +129,24 @@ int ph_SetupOCImage(_THIS, SDL_Surface *screen) //Offscreen context
break;
}
OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA)));
OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA)));
OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA)));
OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA)));
if(OCImage.direct_context == NULL)
OCImage.direct_context = PdCreateDirectContext();
OCImage.direct_context = PdCreateDirectContext();
OCImage.offscreen_context = PdCreateOffscreenContext(0,screen->w,screen->h, Pg_OSC_MEM_PAGE_ALIGN);
OCImage.offscreen_context = PdCreateOffscreenContext(0,screen->w,screen->h, Pg_OSC_MEM_PAGE_ALIGN);
if (OCImage.offscreen_context == NULL)
{
printf("PdCreateOffscreenContext failed\n");
return -1;
}
if (OCImage.offscreen_context == NULL)
{
printf("PdCreateOffscreenContext failed\n");
return -1;
}
OCImage.Stride = OCImage.offscreen_context->pitch;
OCImage.Stride = OCImage.offscreen_context->pitch;
if (OCImage.flags & SDL_DOUBLEBUF)
printf("hardware flag for doublebuf offscreen context\n");
if (OCImage.flags & SDL_DOUBLEBUF)
printf("hardware flag for doublebuf offscreen context\n");
OCImage.dc_ptr.ptr8 = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context);
......@@ -175,21 +175,18 @@ int ph_SetupOCImage(_THIS, SDL_Surface *screen) //Offscreen context
void ph_DestroyImage(_THIS, SDL_Surface *screen)
{
if(SDL_Image == NULL)
return;
if (OCImage.offscreen_context != NULL)
{
PhDCRelease(OCImage.offscreen_context);
OCImage.offscreen_context = NULL;
free(OCImage.FrameData0);
OCImage.FrameData0 = NULL;
free(OCImage.FrameData1);
OCImage.FrameData1 = NULL;
}
if (OCImage.offscreen_context != NULL)
{
PhDCRelease(OCImage.offscreen_context);
OCImage.offscreen_context = NULL;
free(OCImage.FrameData0);
OCImage.FrameData0 = NULL;
free(OCImage.FrameData1);
OCImage.FrameData1 = NULL;
}
if (SDL_Image->image)
{
......@@ -210,7 +207,6 @@ void ph_DestroyImage(_THIS, SDL_Surface *screen)
int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags)
{
ph_DestroyImage(this, screen);
if( flags & SDL_HWSURFACE)
......@@ -226,30 +222,25 @@ int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags)
{
return ph_SetupImage(this, screen);
}
}
int ph_AllocHWSurface(_THIS, SDL_Surface *surface)
{
return(-1);
}
void ph_FreeHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
int ph_FlipHWSurface(_THIS, SDL_Surface *surface)
{
return(0);
}
int ph_LockHWSurface(_THIS, SDL_Surface *surface)
{
if ( (surface == SDL_VideoSurface) && blit_queued ) {
// XSync(GFX_Display, False);
PgFlush();
......@@ -260,7 +251,6 @@ int ph_LockHWSurface(_THIS, SDL_Surface *surface)
void ph_UnlockHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
......@@ -290,7 +280,7 @@ void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
}
}
if (PgFlush() < 0)
{
{
fprintf(stderr,"error: PgFlush failed.\n");
}
}
......@@ -326,13 +316,13 @@ void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
zero.x = zero.y = 0;
PgSetTranslation (&zero, 0);
PgSetRegion(PtWidgetRid(window));
PgSetRegion(PtWidgetRid(window));
PgSetClipping(0,NULL);
PgContextBlitArea(OCImage.offscreen_context, (PhArea_t *)(&src_rect), NULL, (PhArea_t *)(&dest_rect));
}
if (PgFlush() < 0)
{
{
fprintf(stderr,"error: PgFlush failed.\n");
}
......
......@@ -25,16 +25,15 @@ static char rcsid =
"@(#) $Id$";
#endif
#include "SDL_ph_modes_c.h"
static unsigned long key1, key2;
static PgVideoModeInfo_t mode_info;
static PgVideoModes_t mode_list;
/* The current list of available video modes */
SDL_Rect SDL_modelist[127];
SDL_Rect *SDLmod_ptr;
SDL_Rect **SDLmod_ptrptr ;
SDL_Rect SDL_modelist[PH_MAX_VIDEOMODES];
SDL_Rect* SDL_modearray[PH_MAX_VIDEOMODES];
static int compare_modes_by_res(const void* mode1, const void* mode2)
{
......@@ -43,17 +42,17 @@ static int compare_modes_by_res(const void* mode1, const void* mode2)
{
fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
*(unsigned short*)mode1);
return 0;
return 0;
}
key1 = mode_info.width * mode_info.height;
if (PgGetVideoModeInfo(*(unsigned short*)mode2, &mode_info) < 0)
{
fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
fprintf(stderr,"error: In compare_modes_by_res PgGetVideoModeInfo failed on mode: 0x%x\n",
*(unsigned short*)mode2);
return 0;
}
key2 = mode_info.width * mode_info.height;
key2 = mode_info.width * mode_info.height;
if (key1 > key2)
return 1;
......@@ -63,6 +62,7 @@ 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)
{
......@@ -89,7 +89,9 @@ static int compare_modes_by_bpp(const void* mode1, const void* mode2)
else
return -1;
}
*/
/*
int ph_GetVideoModes(_THIS)
{
unsigned short *front;
......@@ -149,19 +151,24 @@ int ph_GetVideoModes(_THIS)
return 0;
}
*/
static SDL_Rect** ph_SupportedVisual( SDL_PixelFormat *format)
SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
int i = 0;
int j = 0;
SDL_Rect Amodelist[127];
SDL_Rect Amodelist[PH_MAX_VIDEOMODES];
for (i=0; i<PH_MAX_VIDEOMODES; i++)
{
SDL_modearray[i]=&SDL_modelist[i];
}
if (PgGetVideoModeList( &mode_list ) < 0)
{
fprintf(stderr,"error: PgGetVideoModeList failed\n");
return NULL;
}
{
fprintf(stderr,"error: PgGetVideoModeList failed\n");
return NULL;
}
mode_info.bits_per_pixel = 0;
......@@ -173,47 +180,34 @@ static SDL_Rect** ph_SupportedVisual( SDL_PixelFormat *format)
mode_list.modes[i]);
return NULL;
}
if(mode_info.bits_per_pixel == format->BitsPerPixel)
{
Amodelist[j].w = mode_info.width;
Amodelist[j].h = mode_info.height;
Amodelist[j].x = 0;
Amodelist[j].y = 0;
j++;
}
Amodelist[j].w = mode_info.width;
Amodelist[j].h = mode_info.height;
Amodelist[j].x = 0;
Amodelist[j].y = 0;
j++;
}
}
//reorder biggest for smallest , assume width dominates
for(i=0; i< j ; i++)
{
SDL_modelist[i].w = Amodelist[j - i -1].w;
SDL_modelist[i].h = Amodelist[j - i -1].h;
SDL_modelist[i].x = Amodelist[j - i -1].x;
SDL_modelist[i].y = Amodelist[j - i -1].y;
}
SDLmod_ptr = SDL_modelist;
SDLmod_ptrptr = &SDLmod_ptr;
return SDLmod_ptrptr;
}
//reorder biggest for smallest, assume width dominates
SDL_Rect **ph_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
return ph_SupportedVisual( format);
for(i=0; i< j ; i++)
{
SDL_modelist[i].w = Amodelist[j - i -1].w;
SDL_modelist[i].h = Amodelist[j - i -1].h;
SDL_modelist[i].x = Amodelist[j - i -1].x;
SDL_modelist[i].y = Amodelist[j - i -1].y;
}
SDL_modearray[j]=NULL;
return SDL_modearray;
}
void ph_FreeVideoModes(_THIS)
{
// int i;
// if ( SDL_modelist ) {
// for ( i=0; SDL_modelist[i]; ++i ) {
// free(SDL_modelist[i]);
// }
// free(SDL_modelist);
// SDL_modelist = NULL;
// }
return;
}
static void set_best_resolution(_THIS, int width, int height)
......@@ -287,6 +281,7 @@ static void set_best_resolution(_THIS, int width, int height)
}
}
/*
static void get_real_resolution(_THIS, int* w, int* h)
{
......@@ -294,13 +289,13 @@ static void get_real_resolution(_THIS, int* w, int* h)
//PgDisplaySettings_t settings;
PgVideoModeInfo_t current_mode_info;
PgHWCaps_t my_hwcaps;
int unused;
/*
if (PgGetVideoMode( &settings ) >= 0) {
*w = settings.xres;
*h = settings.yres;
return;
}*/
// int unused;
// if (PgGetVideoMode( &settings ) >= 0) {
// *w = settings.xres;
// *h = settings.yres;
// return;
// }
if (PgGetGraphicsHWCaps(&my_hwcaps) >= 0)
{
if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &current_mode_info) < 0)
......@@ -314,6 +309,7 @@ static void get_real_resolution(_THIS, int* w, int* h)
// *w = DisplayWidth(SDL_Display, SDL_Screen);
// *h = DisplayHeight(SDL_Display, SDL_Screen);
}
*/
int ph_ResizeFullScreen(_THIS)
{
......@@ -496,9 +492,9 @@ int ph_LeaveFullScreen(_THIS )
mymode_settings.refresh= (unsigned short) old_refresh_rate;
mymode_settings.flags = 0;
if(PgSetVideoMode(&mymode_settings) < 0)
{
fprintf(stderr,"error: PgSetVideoMode failed\n");
}
{
fprintf(stderr,"error: PgSetVideoMode failed\n");
}
}
old_video_mode=-1;
......
......@@ -31,7 +31,9 @@ static char rcsid =
#include "SDL_ph_video.h"
extern int ph_GetVideoModes(_THIS);
#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);
......
......@@ -85,22 +85,23 @@ WMcursor *ph_CreateWMCursor(_THIS,
cursor->ph_cursor->bytesperline1 = (char)w/8;
cursor->ph_cursor->color1 = Pg_WHITE;
cursor->ph_cursor->size2.x = (short)w;
cursor->ph_cursor->size2.y = (short)h;
cursor->ph_cursor->offset2.x = (short)hot_x;
cursor->ph_cursor->offset2.y = (short)hot_y;
cursor->ph_cursor->bytesperline2 = (char)w/8;
cursor->ph_cursor->color2 = Pg_BLACK;
cursor->ph_cursor->size2.y = (short)h;
cursor->ph_cursor->offset2.x = (short)hot_x;
cursor->ph_cursor->offset2.y = (short)hot_y;
cursor->ph_cursor->bytesperline2 = (char)w/8;
cursor->ph_cursor->color2 = Pg_BLACK;
clen = (w/8)*h;
/* Copy the mask and the data to different
bitmap planes */
for ( i=0; i<clen; ++i ) {
cursor->ph_cursor->images[i] = data[i];
cursor->ph_cursor->images[i+clen] = mask[i];
}
for ( i=0; i<clen; ++i )
{
cursor->ph_cursor->images[i] = data[i];
cursor->ph_cursor->images[i+clen] = mask[i];
}
//#bytes following the hdr struct
//#bytes following the hdr struct
cursor->ph_cursor->hdr.len =sizeof(PhCursorDef_t) + clen*2 - sizeof(PhRegionDataHdr_t);
return (cursor);
......@@ -109,7 +110,6 @@ WMcursor *ph_CreateWMCursor(_THIS,
PhCursorDef_t ph_GetWMPhCursor(WMcursor *cursor)
{
return(*cursor->ph_cursor);
}
......@@ -120,8 +120,6 @@ int ph_ShowWMCursor(_THIS, WMcursor *cursor)
int nargs = 0;
short cursor_is_defined = 0;
/* Don't do anything if the display is gone */
if ( window == NULL ) {
return(0);
......@@ -145,8 +143,8 @@ int ph_ShowWMCursor(_THIS, WMcursor *cursor)
cursor_is_defined = 1;
}
if (cursor_is_defined)
{
SDL_Lock_EventThread();
{
SDL_Lock_EventThread();
if (PtSetResources( window, nargs, args ) < 0 )
{
......@@ -163,15 +161,13 @@ int ph_ShowWMCursor(_THIS, WMcursor *cursor)
void ph_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
{
SDL_Lock_EventThread();
PhMoveCursorRel( PhInputGroup(NULL), x, y );
SDL_Unlock_EventThread();
SDL_Lock_EventThread();
PhMoveCursorRel( PhInputGroup(NULL), x, y );
SDL_Unlock_EventThread();
}
void ph_CheckMouseMode(_THIS)
{
mouse_relative = 1;
mouse_relative = 1;
}
......@@ -56,10 +56,12 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
static void ph_VideoQuit(_THIS);
static void ph_DeleteDevice(SDL_VideoDevice *device);
static void ph_GL_SwapBuffers(_THIS);
PdOpenGLContext_t* OGLContext=NULL;
static int ph_Available(void)
{
return 1;
}
......@@ -86,7 +88,7 @@ static SDL_VideoDevice *ph_CreateDevice(int devindex)
device->handles_any_size = 1; //JB not true for fullscreen
/* Set the function pointers */
device->CreateYUVOverlay = ph_CreateYUVOverlay;
device->CreateYUVOverlay = ph_CreateYUVOverlay;
device->VideoInit = ph_VideoInit;
device->ListModes = ph_ListModes;
device->SetVideoMode = ph_SetVideoMode;
......@@ -117,6 +119,13 @@ static SDL_VideoDevice *ph_CreateDevice(int devindex)
device->InitOSKeymap = ph_InitOSKeymap;
device->PumpEvents = ph_PumpEvents;
// OpenGL support.
device->GL_LoadLibrary = NULL;
device->GL_GetProcAddress = NULL;
device->GL_GetAttribute = NULL;
device->GL_MakeCurrent = NULL;
device->GL_SwapBuffers = ph_GL_SwapBuffers;
device->free = ph_DeleteDevice;
return device;
......@@ -147,17 +156,17 @@ static void ph_DeleteDevice(SDL_VideoDevice *device)
static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
PtArg_t arg[1];
PhDim_t dim;
PhDim_t dim;
PgColor_t ph_palette[_Pg_MAX_PALETTE];
int i;
unsigned long *tempptr;
int rtnval;
PgDisplaySettings_t mysettings;
// PgDisplaySettings_t mysettings;
PgVideoModeInfo_t my_mode_info;
PgHWCaps_t my_hwcaps;
if( NULL == ( event = malloc( EVENT_SIZE ) ) )
exit( EXIT_FAILURE );
if( NULL == ( event = malloc( EVENT_SIZE ) ) )
exit( EXIT_FAILURE );
/* Create a widget 'window' to capture events */
dim.w=0; //JB test320;
......@@ -190,10 +199,10 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
// PtExit(EXIT_FAILURE); // Got SEGFAULT.
}
//PgSetDrawBufferSize(16 *1024);
PgSetRegion(PtWidgetRid(window));
PgSetClipping(0,NULL);
PtRealizeWidget(window);
//PgSetDrawBufferSize(16 *1024);
PgSetRegion(PtWidgetRid(window));
PgSetClipping(0,NULL);
PtRealizeWidget(window);
/* Get the available video modes */
......@@ -216,14 +225,15 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
}
*/
if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
{
{
fprintf(stderr,"ph_VideoInit: GetGraphicsHWCaps failed!! \n");
//that HAVE to work
}
}
if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0)
{
{
fprintf(stderr,"ph_VideoInit: PgGetVideoModeInfo failed\n");
}
}
//We need to return BytesPerPixel as it in used by CreateRGBsurface
vformat->BitsPerPixel = my_mode_info.bits_per_pixel;
vformat->BytesPerPixel = vformat->BitsPerPixel/8;
......@@ -263,32 +273,31 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags)
{
PhRegion_t region_info;
// PhRegion_t region_info;
PgDisplaySettings_t settings;
PgHWCaps_t my_hwcaps;
PgVideoModeInfo_t mode_info;
PgVideoModeInfo_t mode_info;
int mode, actual_width, actual_height;
PtArg_t arg[5];
PhDim_t dim;
int rtnval;
SDL_Rect ** mymodelist;
SDL_PixelFormat myformat;
PgColor_t ph_palette[_Pg_MAX_PALETTE];
int i;
unsigned long *tempptr;
PtArg_t arg[5];
PhDim_t dim;
int rtnval;
PgColor_t ph_palette[_Pg_MAX_PALETTE];
int i;
unsigned long *tempptr;
uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
actual_width = width;
actual_height = height;
actual_width = width;
actual_height = height;
dim.w=width;
dim.h=height;
/* Lock the event thread, in multi-threading environments */
SDL_Lock_EventThread();
/* Initialize the window */
if (flags & SDL_FULLSCREEN) //Direct Context , assume SDL_HWSURFACE also set
{
/*
if (old_video_mode==-1)
{
......@@ -297,9 +306,7 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
old_refresh_rate=graphics_card_caps.current_rrate;
}
*/
/* Get the video mode and set it */
if (bpp == 0)
{
......@@ -309,15 +316,15 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
fprintf(stderr,"error: PgGetVideoMode failed\n");
}
*/
if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
{
fprintf(stderr,"ph_SetVideoMode: GetGraphicsHWCaps failed!! \n");
//that HAVE to work
}
if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &mode_info) < 0)
{
fprintf(stderr,"ph_SetVideoMode: PgGetVideoModeInfo failed\n");
}
if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
{
fprintf(stderr,"ph_SetVideoMode: GetGraphicsHWCaps failed!! \n");
//that HAVE to work
}
if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &mode_info) < 0)
{
fprintf(stderr,"ph_SetVideoMode: PgGetVideoModeInfo failed\n");
}
bpp = mode_info.bits_per_pixel;
}
if (flags & SDL_ANYFORMAT)
......@@ -341,8 +348,7 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
settings.mode = mode;
settings.refresh = 0;
settings.flags = 0;
if (PgSetVideoMode( &settings ) < 0)
{
fprintf(stderr,"error: PgSetVideoMode failed\n");
......@@ -358,16 +364,33 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
} //end fullscreen flag
else if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */
else
{
// Hardware surface is Offsceen Context. ph_ResizeImage handles the switch
current->flags = (flags|(~SDL_RESIZABLE)); //no stretch blit in offscreen context
if (flags & SDL_HWSURFACE) /* Use offscreen memory iff SDL_HWSURFACE flag is set */
{
// Hardware surface is Offsceen Context. ph_ResizeImage handles the switch
current->flags = (flags|(~SDL_RESIZABLE)); //no stretch blit in offscreen context
}
else // must be SDL_SWSURFACE
{
current->flags = (flags|SDL_RESIZABLE); //yes we can resize as this is a software surface
}
if (flags & SDL_OPENGL) // for now support OpenGL in window mode only
{
OGLAttrib[0]=PHOGL_ATTRIB_DEPTH_BITS;
OGLAttrib[1]=bpp;
OGLAttrib[2]=PHOGL_ATTRIB_NONE;
OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
if (OGLContext==NULL)
{
fprintf(stderr,"error: cannot create OpenGL context\n");
exit(1);
}
PhDCSetCurrent(OGLContext);
}
}
else // must be SDL_SWSURFACE
{
current->flags = (flags|SDL_RESIZABLE); //yes we can resize as this is a software surface
}
//If we are setting video to use the palette make sure we have allocated memory for it
if(bpp == 8)
......@@ -379,7 +402,7 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
//fill the palette
rtnval = PgGetPalette(ph_palette);
tempptr = (unsigned long *)current->format->palette->colors;
tempptr = (unsigned long *)current->format->palette->colors;
for(i=0;i<256; i++)
{
......@@ -397,17 +420,17 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
if((dim.w != width)||(dim.h != height))
{
dim.w=width;
dim.h=height;
PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0);
PtSetResources( window, 1, arg );
current->w = width;
current->h = height;
current->format->BitsPerPixel = bpp;
current->format->BytesPerPixel = bpp/8;
current->pitch = SDL_CalculatePitch(current);
//Must call at least once it setup image planes
ph_ResizeImage(this, current, flags);
}
dim.h=height;
PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0);
PtSetResources( window, 1, arg );
current->w = width;
current->h = height;
current->format->BitsPerPixel = bpp;
current->format->BytesPerPixel = bpp/8;
current->pitch = SDL_CalculatePitch(current);
//Must call at least once it setup image planes
ph_ResizeImage(this, current, flags);
}
SDL_Unlock_EventThread();
......@@ -421,8 +444,7 @@ static void ph_VideoQuit(_THIS)
if(SDL_Image != NULL)
{
ph_DestroyImage(this, SDL_VideoSurface);
ph_DestroyImage(this, SDL_VideoSurface);
}
if (currently_fullscreen)
......@@ -494,6 +516,13 @@ static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
return alloct_all;
}
void ph_GL_SwapBuffers(_THIS)
{
PgSetRegion(PtWidgetRid(window));
PdOpenGLContextSwapBuffers(OGLContext);
}
/*
static int ph_ResizeWindow(_THIS,
SDL_Surface *screen, int w, int h, Uint32 flags)
{
......@@ -512,5 +541,4 @@ static int ph_ResizeWindow(_THIS,
current_h = h;
return(0);
}
*/
......@@ -50,10 +50,13 @@ static unsigned TranslatedFillColor;
#include "Pt.h"
#include <photon/Pg.h>
#include <photon/PdDirect.h>
#include <photon/PdGL.h>
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_VideoDevice *this
#define PH_OGL_MAX_ATTRIBS 32
typedef union vidptr{
uint8_t *volatile ptr8;
uint16_t *volatile ptr16;
......
......@@ -230,168 +230,44 @@ void ph_SetCaption(_THIS, const char *title, const char *icon)
SDL_Unlock_EventThread();
}
/* Iconify the window (stolen from PhHotKey sources by phearbear ;-) */
/* Iconify current window */
int ph_IconifyWindow(_THIS)
{
#if 1 /* Code submitted by Luca <barbato_luca@yahoo.com> */
WmApiContext_t context=WmCreateContext();
WmWindowDefinition_t
**wininfo=malloc(sizeof(WmWindowDefinition_t)*2);
int num;
SDL_Lock_EventThread();
WmGetFocusList(context,2,&num,wininfo);
WmPerformFrameAction(context, wininfo[0]->rid,Pt_ACTION_MIN);
WmDestroyContext (context);
SDL_Unlock_EventThread();
free(wininfo);
return (0);
#else
int result=0;
int myerr;
int num;
PtConnectionClient_t *Client=0;
WmMsg_t* Message=malloc(sizeof(WmMsg_t));
WmReply_t *Reply=malloc(sizeof(WmReply_t));
WmApiContext_t MsgStruct=malloc(sizeof(WmApiContext_t));
WmWindowDefinition_t **WNDDEF=malloc(sizeof(WmWindowDefinition_t)*2);
SDL_Lock_EventThread();
PtInit("/dev/photon");
Client=PtConnectionFindName("pwm",0,0);
if(!Client)
{
return result;
}
WmApiContext_t context=WmCreateContext();
WmWindowDefinition_t **wininfo=malloc(sizeof(WmWindowDefinition_t)*2);
int num;
MsgStruct->input_group=PhInputGroup(0);
MsgStruct->connection=PtConnectionFindName("pwm",0,0);
myerr=WmGetFocusList(MsgStruct,2,&num,WNDDEF);
SDL_Lock_EventThread();
WmGetFocusList(context,2,&num,wininfo);
WmPerformFrameAction(context, wininfo[0]->rid,Pt_ACTION_MIN);
Message->hdr.type=WM_REQUEST_WIN_ACTION;
Message->hdr.subtype=Pt_ACTION_MIN;
Message->hdr.rid=WNDDEF[0]->rid;
myerr=WmSendMessage(Client,Message,Reply,0);
WmDestroyContext (context);
SDL_Unlock_EventThread();
free(wininfo);
free(Message);
free(Reply);
SDL_Unlock_EventThread();
return(result);
#endif /* 1 */
return (0);
}
SDL_GrabMode ph_GrabInputNoLock(_THIS, SDL_GrabMode mode)
{
#if 0 /*big*/
int numtries, result;
if ( this->screen == NULL ) {
return(SDL_GRAB_OFF);
}
if ( ! SDL_Window ) {
return(mode); /* Will be set later on mode switch */
}
if ( mode == SDL_GRAB_OFF ) {
XUngrabPointer(SDL_Display, CurrentTime);
if ( this->screen->flags & SDL_FULLSCREEN ) {
/* Rebind the mouse to the fullscreen window */
for ( numtries = 0; numtries < 10; ++numtries ) {
result = XGrabPointer(SDL_Display, FSwindow,
True, 0,
GrabModeAsync, GrabModeAsync,
FSwindow, None, CurrentTime);
if ( result == AlreadyGrabbed ) {
break;
}
SDL_Delay(100);
}
}
#ifdef GRAB_FULLSCREEN
if ( !(this->screen->flags & SDL_FULLSCREEN) )
#endif
XUngrabKeyboard(SDL_Display, CurrentTime);
} else {
if ( this->screen->flags & SDL_FULLSCREEN ) {
/* Unbind the mouse from the fullscreen window */
XUngrabPointer(SDL_Display, CurrentTime);
}
/* Try to grab the mouse */
for ( numtries = 0; numtries < 10; ++numtries ) {
result = XGrabPointer(SDL_Display, SDL_Window, True, 0,
GrabModeAsync, GrabModeAsync,
SDL_Window, None, CurrentTime);
if ( result != AlreadyGrabbed ) {
break;
}
SDL_Delay(100);
}
#ifdef GRAB_FULLSCREEN
if ( !(this->screen->flags & SDL_FULLSCREEN) )
#endif
XGrabKeyboard(SDL_Display, WMwindow, True,
GrabModeAsync, GrabModeAsync, CurrentTime);
}
XSync(SDL_Display, False);
#endif /*big*/
return(mode);
return(mode);
}
SDL_GrabMode ph_GrabInput(_THIS, SDL_GrabMode mode)
{
#if 0
SDL_Lock_EventThread();
mode = X11_GrabInputNoLock(this, mode);
SDL_Unlock_EventThread();
#endif
return(mode);
return(mode);
}
/* If 'info' is the right version, this function fills it and returns 1.
Otherwise, in case of a version mismatch, it returns -1.
*/
static void lock_display(void)
{
SDL_Lock_EventThread();
}
static void unlock_display(void)
{
#if 0
/* Make sure any X11 transactions are completed */
SDL_VideoDevice *this = current_video;
XSync(SDL_Display, False);
#endif
SDL_Unlock_EventThread();
}
int ph_GetWMInfo(_THIS, SDL_SysWMinfo *info)
{
#if 0
if ( info->version.major <= SDL_MAJOR_VERSION ) {
info->subsystem = SDL_SYSWM_X11;
info->info.x11.display = SDL_Display;
info->info.x11.window = SDL_Window;
if ( SDL_VERSIONNUM(info->version.major,
info->version.minor,
info->version.patch) >= 1002 ) {
info->info.x11.fswindow = FSwindow;
info->info.x11.wmwindow = WMwindow;
}
info->info.x11.lock_func = lock_display;
info->info.x11.unlock_func = unlock_display;
return(1);
} else {
SDL_SetError("Application not compiled with SDL %d.%d\n",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
return(-1);
}
#endif
return -1; // for now ...
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;
}
}
......@@ -35,7 +35,7 @@ int main(int argc, char *argv[])
} else {
printf("Fullscreen video modes:\n");
for ( i=0; modes[i]; ++i ) {
printf("\t%dx%d\n", modes[i]->w, modes[i]->h);
printf("\t%dx%dx%d\n", modes[i]->w, modes[i]->h, info->vfmt->BitsPerPixel);
}
}
if ( info->wm_available ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment