Skip to content

Commit

Permalink
Date: Sat, 18 May 2002 17:40:53 +0300
Browse files Browse the repository at this point in the history
From: Mike Gorchak <mike@malva.ua>
Subject: New QNX patches

- Added more error check to avoid SEGFAULTS;
- Fixed bug in update function for SDL_HWSURFACE. BTW: update is much
faster than before.
- Added checks for SDL_HWSURFACE flag, chosen bpp must be equal to
desktop bpp for SDL_HWSURFACE.
- Fixed overlay bug, no more SEGFAULTS.
  • Loading branch information
slouken committed May 19, 2002
1 parent 6f9798e commit 6eff731
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 151 deletions.
188 changes: 94 additions & 94 deletions src/video/photon/SDL_ph_image.c
Expand Up @@ -65,9 +65,7 @@ int ph_SetupImage(_THIS, SDL_Surface *screen)
}
break;
default:{
/* should never get here */
fprintf(stderr,"error: unsupported bbp = %d\n",
screen->format->BitsPerPixel);
fprintf(stderr,"ph_SetupImage(): unsupported bbp = %d\n", screen->format->BitsPerPixel);
return -1;
}
break;
Expand Down Expand Up @@ -106,83 +104,82 @@ int ph_SetupImage(_THIS, SDL_Surface *screen)

int ph_SetupOCImage(_THIS, SDL_Surface *screen)
{
int type = 0;
int type = 0;

/* Determine image type */
switch(screen->format->BitsPerPixel)
{
case 8:{
type = Pg_IMAGE_PALETTE_BYTE;
}
break;
case 15:{
type = Pg_IMAGE_DIRECT_555;
}
break;
case 16:{
type = Pg_IMAGE_DIRECT_565;
/* Determine image type */
switch(screen->format->BitsPerPixel)
{
case 8: {
type = Pg_IMAGE_PALETTE_BYTE;
}
break;
case 15:{
type = Pg_IMAGE_DIRECT_555;
}
break;
case 16:{
type = Pg_IMAGE_DIRECT_565;
}
break;
case 24:{
type = Pg_IMAGE_DIRECT_888;
}
break;
case 32:{
type = Pg_IMAGE_DIRECT_8888;
}
break;
default:{
fprintf(stderr,"ph_SetupOCImage(): unsupported bpp = %d\n", screen->format->BitsPerPixel);
return -1;
}
break;
}

case 24:{
type = Pg_IMAGE_DIRECT_888;
}
break;

case 32:{
type = Pg_IMAGE_DIRECT_8888;
}
break;
default:{
/* should never get here */
fprintf(stderr,"error: unsupported bbp = %d\n",
screen->format->BitsPerPixel);
return -1;
}
break;
}

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.offscreen_context = PdCreateOffscreenContext(0,screen->w,screen->h, Pg_OSC_MEM_PAGE_ALIGN);

if (OCImage.offscreen_context == NULL)
{
printf("PdCreateOffscreenContext failed\n");
return -1;
}

OCImage.Stride = OCImage.offscreen_context->pitch;

if (OCImage.flags & SDL_DOUBLEBUF)
printf("hardware flag for doublebuf offscreen context\n");


OCImage.dc_ptr.ptr8 = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context);

OCImage.CurrentFrameData = OCImage.FrameData0;
OCImage.CurrentFrameData->Y = OCImage.dc_ptr.ptr8;
OCImage.CurrentFrameData->U = NULL;
OCImage.CurrentFrameData->V = NULL;
OCImage.current = 0;

if(OCImage.dc_ptr.ptr8 == NULL)
{
printf("PdGetOffscreenContextPtr failed\n");
return -1;
}

PhDCSetCurrent(OCImage.offscreen_context);

screen->pixels = OCImage.CurrentFrameData->Y;

this->UpdateRects = ph_OCUpdate;

return 0;
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.offscreen_context = PdCreateOffscreenContext(0, screen->w, screen->h, Pg_OSC_MEM_PAGE_ALIGN);

if (OCImage.offscreen_context == NULL)
{
fprintf(stderr, "ph_SetupOCImage(): PdCreateOffscreenContext failed !\n");
return -1;
}

OCImage.Stride = OCImage.offscreen_context->pitch;

if (OCImage.flags & SDL_DOUBLEBUF)
{
fprintf(stderr, "ph_SetupOCImage(): Hardware flag for doublebuf offscreen context\n");
}

OCImage.dc_ptr.ptr8 = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context);

if (OCImage.dc_ptr.ptr8 == NULL)
{
fprintf(stderr, "ph_SetupOCImage(): PdGetOffscreenContextPtr failed !\n");
return -1;
}

OCImage.CurrentFrameData = OCImage.FrameData0;
OCImage.CurrentFrameData->Y = OCImage.dc_ptr.ptr8;
OCImage.CurrentFrameData->U = NULL;
OCImage.CurrentFrameData->V = NULL;
OCImage.current = 0;

PhDCSetCurrent(OCImage.offscreen_context);

screen->pixels = OCImage.CurrentFrameData->Y;

this->UpdateRects = ph_OCUpdate;

return 0;
}

int ph_SetupOpenGLImage(_THIS, SDL_Surface* screen)
Expand Down Expand Up @@ -242,7 +239,6 @@ int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags)
return ph_SetupImage(this, screen);
}
}

int ph_AllocHWSurface(_THIS, SDL_Surface *surface)
{
return(-1);
Expand Down Expand Up @@ -302,28 +298,29 @@ void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)

if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
{
fprintf(stderr,"ph_NormalUpdate: PgDrawPhImageRectmx failed.\n");
fprintf(stderr,"ph_NormalUpdate(): PgDrawPhImageRectmx failed.\n");
}
}

if (PgFlush() < 0)
{
fprintf(stderr,"ph_NormalUpdate: PgFlush failed.\n");
fprintf(stderr,"ph_NormalUpdate(): PgFlush failed.\n");
}
}

void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
{
PhPoint_t zero = {0};
PhRect_t src_rect;
PhRect_t dest_rect;
PhArea_t src_rect;
PhArea_t dest_rect;

if(OCImage.direct_context == NULL)
{
return;
}

PgSetRegion(PtWidgetRid(window));
PgSetClipping(0,NULL);
PgSetClipping(0, NULL);
PgWaitHWIdle();

for (i=0; i<numrects; ++i)
Expand All @@ -333,24 +330,27 @@ void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
continue;
}

src_rect.ul.x=rects[i].x;
src_rect.ul.y=rects[i].y;
dest_rect.ul.x=rects[i].x;
dest_rect.ul.y=rects[i].y;
src_rect.pos.x=rects[i].x;
src_rect.pos.y=rects[i].y;
dest_rect.pos.x=rects[i].x;
dest_rect.pos.y=rects[i].y;

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;
src_rect.size.w=rects[i].w;
src_rect.size.h=rects[i].h;
dest_rect.size.w=rects[i].w;
dest_rect.size.h=rects[i].h;

zero.x = zero.y = 0;
PgSetTranslation (&zero, 0);
zero.x = 0;
zero.y = 0;
PgSetTranslation(&zero, 0);
PgSetRegion(PtWidgetRid(window));
PgSetClipping(0,NULL);
PgContextBlitArea(OCImage.offscreen_context, (PhArea_t *)(&src_rect), NULL, (PhArea_t *)(&dest_rect));

PgSetClipping(0, NULL);
PgContextBlitArea(OCImage.offscreen_context, &src_rect, NULL, &dest_rect);
}

if (PgFlush() < 0)
{
fprintf(stderr,"ph_OCUpdate: PgFlush failed.\n");
fprintf(stderr,"ph_OCUpdate(): PgFlush failed.\n");
}

/* later used to toggling double buffer */
Expand Down
39 changes: 30 additions & 9 deletions src/video/photon/SDL_ph_video.c
Expand Up @@ -255,6 +255,16 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
if ((flags & SDL_OPENGL)!=SDL_OPENGL)
{
pargc=0;

// prevent using HWSURFACE in window mode if desktop bpp != chosen bpp
if ((flags & SDL_HWSURFACE) && (!(flags & SDL_FULLSCREEN)))
{
if (desktopbpp!=bpp)
{
fprintf(stderr, "ph_SetVideoMode(): SDL_HWSURFACE available only with chosen bpp equal desktop bpp !\n");
return NULL;
}
}

PtSetArg(&arg[pargc++], Pt_ARG_DIM, &dim, 0);
PtSetArg(&arg[pargc++], Pt_ARG_RESIZE_FLAGS, Pt_FALSE, Pt_RESIZE_XY_AS_REQUIRED);
Expand Down Expand Up @@ -317,7 +327,7 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
#else
if (flags & SDL_OPENGL) /* if no built-in OpenGL support */
{
fprintf(stderr, "error: no OpenGL support, try to recompile library.\n");
fprintf(stderr, "ph_SetVideoMode(): no OpenGL support, try to recompile library.\n");
current->flags=(flags & (~SDL_OPENGL));
return NULL;
#endif /* HAVE_OPENGL */
Expand All @@ -332,15 +342,15 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
{
if ((mode = get_mode_any_format(width, height, bpp)) == 0)
{
fprintf(stderr,"error: get_mode_any_format failed\n");
fprintf(stderr,"ph_SetVideoMode(): get_mode_any_format failed !\n");
exit(1);
}
}
else
{
if ((mode = get_mode(width, height, bpp)) == 0)
{
fprintf(stderr,"error: get_mode failed\n");
fprintf(stderr,"ph_SetVideoMode(): get_mode failed !\n");
exit(1);
}
}
Expand All @@ -362,7 +372,7 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,

if (PgSetVideoMode(&settings) < 0)
{
fprintf(stderr,"error: PgSetVideoMode failed\n");
fprintf(stderr,"ph_SetVideoMode(): PgSetVideoMode failed !\n");
}

current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
Expand Down Expand Up @@ -424,8 +434,15 @@ static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
current->format->BitsPerPixel = bpp;
current->format->BytesPerPixel = (bpp+7)/8;
current->pitch = SDL_CalculatePitch(current);

/* Must call at least once it setup image planes */
ph_ResizeImage(this, current, flags);
rtnval = ph_ResizeImage(this, current, flags);

if (rtnval==-1)
{
fprintf(stderr,"ph_SetVideoMode(): ph_ResizeImage failed !\n");
return NULL;
}

/* delayed set caption call */
if (captionflag)
Expand Down Expand Up @@ -512,9 +529,10 @@ static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
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);
}
/* image needs to be redrawed, very slow method */
PgDrawPhImage(&point, SDL_Image, 0);
}
else
{
Expand All @@ -533,7 +551,10 @@ static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
/* window mode must use soft palette */
PgSetPalette((PgColor_t*)&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_SOFT, 0);
/* image needs to be redrawed, very slow method */
PgDrawPhImage(&point, SDL_Image, 0);
if (SDL_Image)
{
PgDrawPhImage(&point, SDL_Image, 0);
}
}
else
{
Expand Down Expand Up @@ -602,7 +623,7 @@ int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags)

if (oglctx==NULL)
{
fprintf(stderr,"ph_SetupOpenGLContext: cannot create OpenGL context.\n");
fprintf(stderr,"ph_SetupOpenGLContext(): cannot create OpenGL context.\n");
return (-1);
}

Expand Down

0 comments on commit 6eff731

Please sign in to comment.