Commit 26d1c3e5 authored by Sam Lantinga's avatar Sam Lantinga

Date: Wed, 22 May 2002 22:30:58 +0300

From: "Mike Gorchak" <mike@malva.com.ua>
Subject: One more QNX patch

Hi !

- Fixed graywin test application. Added properly support for
  window size not equal to 640x480.
- Added support for not aligned pitch of image in SDL_SWSURFACE
  and SDL_HWSURFACE. Using Photon builtin alignes.
- Added memory clear after each malloc to avoid problems in the
  future :)
- Removed unused variables and static variables, fixed some warnings.
- Updated readme.QNX file.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40381
parent 5e5d89d8
README by Mike Gorchak <mike@malva.ua> README by Mike Gorchak <mike@malva.ua>, <lestat@i.com.ua>
OpenGL in window mode works well and stable, in fullscreen OpenGL in window mode works well and stable, in fullscreen
mode too, but fullscreen mode has not been heavily tested. mode too, but fullscreen mode has not been heavily tested.
...@@ -16,6 +16,9 @@ Problems: ...@@ -16,6 +16,9 @@ Problems:
videomode has. videomode has.
3. No shared libraries yet. We need manually set flag to 3. No shared libraries yet. We need manually set flag to
'configure' --disable-shared. 'configure' --disable-shared.
4. Due to Photon API limitation, flag SDL_HWSURFACE supported on-
ly in case of desktop bpp is equal requested bpp in window mo-
de.
Some building issues: Some building issues:
......
...@@ -38,11 +38,14 @@ int PgWaitHWIdle(void); ...@@ -38,11 +38,14 @@ int PgWaitHWIdle(void);
int ph_SetupImage(_THIS, SDL_Surface *screen) int ph_SetupImage(_THIS, SDL_Surface *screen)
{ {
int type=0;
PgColor_t* palette=NULL; PgColor_t* palette=NULL;
int type=0;
int bpp;
bpp=screen->format->BitsPerPixel;
/* Determine image type */ /* Determine image type */
switch(screen->format->BitsPerPixel) switch(bpp)
{ {
case 8:{ case 8:{
type = Pg_IMAGE_PALETTE_BYTE; type = Pg_IMAGE_PALETTE_BYTE;
...@@ -65,14 +68,14 @@ int ph_SetupImage(_THIS, SDL_Surface *screen) ...@@ -65,14 +68,14 @@ int ph_SetupImage(_THIS, SDL_Surface *screen)
} }
break; break;
default:{ default:{
fprintf(stderr,"ph_SetupImage(): unsupported bbp = %d\n", screen->format->BitsPerPixel); fprintf(stderr,"ph_SetupImage(): unsupported bbp = %d\n", bpp);
return -1; return -1;
} }
break; break;
} }
/* palette emulation code */ /* palette emulation code */
if ((screen->format->BitsPerPixel==8) && (desktoppal==SDLPH_PAL_EMULATE)) if ((bpp==8) && (desktoppal==SDLPH_PAL_EMULATE))
{ {
/* creating image palette */ /* creating image palette */
palette=malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t)); palette=malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t));
...@@ -81,7 +84,7 @@ int ph_SetupImage(_THIS, SDL_Surface *screen) ...@@ -81,7 +84,7 @@ int ph_SetupImage(_THIS, SDL_Surface *screen)
/* using shared memory for speed (set last param to 1) */ /* 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) 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"); fprintf(stderr,"ph_SetupImage(): PhCreateImage failed for bpp=8.\n");
return -1; return -1;
} }
} }
...@@ -96,6 +99,7 @@ int ph_SetupImage(_THIS, SDL_Surface *screen) ...@@ -96,6 +99,7 @@ int ph_SetupImage(_THIS, SDL_Surface *screen)
} }
screen->pixels = SDL_Image->image; screen->pixels = SDL_Image->image;
screen->pitch = SDL_Image->bpl; /* Recalculated pitch, created by PhCreateImage */
this->UpdateRects = ph_NormalUpdate; this->UpdateRects = ph_NormalUpdate;
...@@ -105,9 +109,12 @@ int ph_SetupImage(_THIS, SDL_Surface *screen) ...@@ -105,9 +109,12 @@ int ph_SetupImage(_THIS, SDL_Surface *screen)
int ph_SetupOCImage(_THIS, SDL_Surface *screen) int ph_SetupOCImage(_THIS, SDL_Surface *screen)
{ {
int type = 0; int type = 0;
int bpp;
bpp=screen->format->BitsPerPixel;
/* Determine image type */ /* Determine image type */
switch(screen->format->BitsPerPixel) switch(bpp)
{ {
case 8: { case 8: {
type = Pg_IMAGE_PALETTE_BYTE; type = Pg_IMAGE_PALETTE_BYTE;
...@@ -130,7 +137,7 @@ int ph_SetupOCImage(_THIS, SDL_Surface *screen) ...@@ -130,7 +137,7 @@ int ph_SetupOCImage(_THIS, SDL_Surface *screen)
} }
break; break;
default:{ default:{
fprintf(stderr,"ph_SetupOCImage(): unsupported bpp = %d\n", screen->format->BitsPerPixel); fprintf(stderr,"ph_SetupOCImage(): unsupported bpp = %d\n", bpp);
return -1; return -1;
} }
break; break;
...@@ -138,6 +145,8 @@ int ph_SetupOCImage(_THIS, SDL_Surface *screen) ...@@ -138,6 +145,8 @@ int ph_SetupOCImage(_THIS, SDL_Surface *screen)
OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA))); OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA))); OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
memset(OCImage.FrameData0, 0x00, (size_t)(sizeof(FRAMEDATA)));
memset(OCImage.FrameData1, 0x00, (size_t)(sizeof(FRAMEDATA)));
if(OCImage.direct_context == NULL) if(OCImage.direct_context == NULL)
{ {
...@@ -152,7 +161,7 @@ int ph_SetupOCImage(_THIS, SDL_Surface *screen) ...@@ -152,7 +161,7 @@ int ph_SetupOCImage(_THIS, SDL_Surface *screen)
return -1; return -1;
} }
OCImage.Stride = OCImage.offscreen_context->pitch; screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */
if (OCImage.flags & SDL_DOUBLEBUF) if (OCImage.flags & SDL_DOUBLEBUF)
{ {
...@@ -269,10 +278,6 @@ void ph_UnlockHWSurface(_THIS, SDL_Surface *surface) ...@@ -269,10 +278,6 @@ void ph_UnlockHWSurface(_THIS, SDL_Surface *surface)
return; return;
} }
static PhPoint_t ph_pos;
static PhRect_t ph_rect;
static int i;
void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects) void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects)
{ {
this->GL_SwapBuffers(this); this->GL_SwapBuffers(this);
...@@ -282,7 +287,11 @@ void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects) ...@@ -282,7 +287,11 @@ 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 ) PhPoint_t ph_pos;
PhRect_t ph_rect;
int i;
for (i=0; i<numrects; ++i)
{ {
if (rects[i].w==0) /* Clipped? */ if (rects[i].w==0) /* Clipped? */
{ {
...@@ -310,6 +319,8 @@ void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) ...@@ -310,6 +319,8 @@ void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects) void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
{ {
int i;
PhPoint_t zero = {0}; PhPoint_t zero = {0};
PhArea_t src_rect; PhArea_t src_rect;
PhArea_t dest_rect; PhArea_t dest_rect;
......
...@@ -192,6 +192,7 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) ...@@ -192,6 +192,7 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
{ {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(event, 0x00, EVENT_SIZE);
/* Create the blank cursor */ /* Create the blank cursor */
SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask, SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
...@@ -200,17 +201,17 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat) ...@@ -200,17 +201,17 @@ static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
if (SDL_BlankCursor == NULL) if (SDL_BlankCursor == NULL)
{ {
printf("ph_VideoInit: could not create blank cursor\n"); printf("ph_VideoInit(): could not create blank cursor !\n");
} }
if (PgGetGraphicsHWCaps(&my_hwcaps) < 0) if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
{ {
fprintf(stderr,"ph_VideoInit: GetGraphicsHWCaps failed!! \n"); fprintf(stderr,"ph_VideoInit(): GetGraphicsHWCaps failed !\n");
} }
if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0) if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0)
{ {
fprintf(stderr,"ph_VideoInit: PgGetVideoModeInfo failed\n"); fprintf(stderr,"ph_VideoInit(): PgGetVideoModeInfo failed !\n");
} }
/* We need to return BytesPerPixel as it in used by CreateRGBsurface */ /* We need to return BytesPerPixel as it in used by CreateRGBsurface */
......
...@@ -75,7 +75,6 @@ struct SDL_PrivateVideoData { ...@@ -75,7 +75,6 @@ struct SDL_PrivateVideoData {
FRAMEDATA *FrameData0; FRAMEDATA *FrameData0;
FRAMEDATA *FrameData1; FRAMEDATA *FrameData1;
int current; int current;
long Stride;
long flags; long flags;
} ocimage; } ocimage;
......
...@@ -210,8 +210,10 @@ SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SD ...@@ -210,8 +210,10 @@ SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SD
overlay->hwdata->screen_width = 1024; overlay->hwdata->screen_width = 1024;
overlay->hwdata->screen_height = 768; overlay->hwdata->screen_height = 768;
overlay->hwdata->FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA))); overlay->hwdata->FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
overlay->hwdata->FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA))); overlay->hwdata->FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
memset(overlay->hwdata->FrameData0, 0x00, (size_t)(sizeof(FRAMEDATA)));
memset(overlay->hwdata->FrameData1, 0x00, (size_t)(sizeof(FRAMEDATA)));
overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps); overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps);
...@@ -493,7 +495,7 @@ if(overlay == NULL) ...@@ -493,7 +495,7 @@ if(overlay == NULL)
//Lock gets the pointer and passes it to the app. The app writes all yuv data into overlay->pixels //Lock gets the pointer and passes it to the app. The app writes all yuv data into overlay->pixels
//Note this is defined as Uint8 **pixels; /* Read-write */ //Note this is defined as Uint8 **pixels; /* Read-write */
overlay->pixels = &overlay->hwdata->CurrentFrameData->Y; overlay->pixels = &overlay->hwdata->CurrentFrameData->Y;
overlay->pitches = &overlay->hwdata->YStride; overlay->pitches = (Uint16*) &(overlay->hwdata->YStride);
return(0); return(0);
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#endif #endif
/* Draw a randomly sized and colored box centered about (X,Y) */ /* Draw a randomly sized and colored box centered about (X,Y) */
void DrawBox(SDL_Surface *screen, int X, int Y) void DrawBox(SDL_Surface *screen, int X, int Y, int width, int height)
{ {
static unsigned int seeded = 0; static unsigned int seeded = 0;
SDL_Rect area; SDL_Rect area;
...@@ -28,8 +28,8 @@ void DrawBox(SDL_Surface *screen, int X, int Y) ...@@ -28,8 +28,8 @@ void DrawBox(SDL_Surface *screen, int X, int Y)
} }
/* Get the bounds of the rectangle */ /* Get the bounds of the rectangle */
area.w = (rand()%640); area.w = (rand()%width);
area.h = (rand()%480); area.h = (rand()%height);
area.x = X-(area.w/2); area.x = X-(area.w/2);
area.y = Y-(area.h/2); area.y = Y-(area.h/2);
color = (rand()%NUM_COLORS); color = (rand()%NUM_COLORS);
...@@ -72,7 +72,7 @@ SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags) ...@@ -72,7 +72,7 @@ SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags)
} }
buffer = (Uint8 *)screen->pixels; buffer = (Uint8 *)screen->pixels;
for ( i=0; i<screen->h; ++i ) { for ( i=0; i<screen->h; ++i ) {
memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w); memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
buffer += screen->pitch; buffer += screen->pitch;
} }
SDL_UnlockSurface(screen); SDL_UnlockSurface(screen);
...@@ -126,7 +126,7 @@ int main(int argc, char *argv[]) ...@@ -126,7 +126,7 @@ int main(int argc, char *argv[])
if ( argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0) ) { if ( argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0) ) {
videoflags |= SDL_FULLSCREEN; videoflags |= SDL_FULLSCREEN;
} else { } else {
fprintf(stderr, "Usage: %s [-warp] [-fullscreen]\n", fprintf(stderr, "Usage: %s [-width] [-height] [-bpp] [-hw] [-hwpalette] [-noframe] [-fullscreen]\n",
argv[0]); argv[0]);
exit(1); exit(1);
} }
...@@ -143,7 +143,7 @@ int main(int argc, char *argv[]) ...@@ -143,7 +143,7 @@ int main(int argc, char *argv[])
while ( !done && SDL_WaitEvent(&event) ) { while ( !done && SDL_WaitEvent(&event) ) {
switch (event.type) { switch (event.type) {
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
DrawBox(screen, event.button.x, event.button.y); DrawBox(screen, event.button.x, event.button.y, width, height);
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
/* Ignore ALT-TAB for windows */ /* Ignore ALT-TAB for windows */
...@@ -153,7 +153,7 @@ int main(int argc, char *argv[]) ...@@ -153,7 +153,7 @@ int main(int argc, char *argv[])
} }
/* Center the mouse on <SPACE> */ /* Center the mouse on <SPACE> */
if ( event.key.keysym.sym == SDLK_SPACE ) { if ( event.key.keysym.sym == SDLK_SPACE ) {
SDL_WarpMouse(640/2, 480/2); SDL_WarpMouse(width/2, height/2);
break; break;
} }
/* Toggle fullscreen mode on <RETURN> */ /* Toggle fullscreen mode on <RETURN> */
......
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