Mercurial > sdl-ios-xcode
changeset 370:ba72f259bc88
Date: Sat, 18 May 2002 17:40:53 +0300
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.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 19 May 2002 19:54:01 +0000 |
parents | e405cf8bf580 |
children | db0cc6034336 |
files | src/video/photon/SDL_ph_image.c src/video/photon/SDL_ph_video.c src/video/photon/SDL_phyuv.c |
diffstat | 3 files changed, 151 insertions(+), 142 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/photon/SDL_ph_image.c Sun May 19 19:52:32 2002 +0000 +++ b/src/video/photon/SDL_ph_image.c Sun May 19 19:54:01 2002 +0000 @@ -65,9 +65,7 @@ } 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; @@ -106,83 +104,82 @@ 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; - } - 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; + /* Determine image type */ + switch(screen->format->BitsPerPixel) + { + case 8: { + type = Pg_IMAGE_PALETTE_BYTE; + } + break; + case 15:{ + type = Pg_IMAGE_DIRECT_555; } 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(); + 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; + } - 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.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA))); + OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA))); - OCImage.Stride = OCImage.offscreen_context->pitch; + if(OCImage.direct_context == NULL) + { + OCImage.direct_context = PdCreateDirectContext(); + } - if (OCImage.flags & SDL_DOUBLEBUF) - printf("hardware flag for doublebuf offscreen context\n"); + OCImage.offscreen_context = PdCreateOffscreenContext(0, screen->w, screen->h, Pg_OSC_MEM_PAGE_ALIGN); - - 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); + 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); - screen->pixels = OCImage.CurrentFrameData->Y; - - this->UpdateRects = ph_OCUpdate; + if (OCImage.dc_ptr.ptr8 == NULL) + { + fprintf(stderr, "ph_SetupOCImage(): PdGetOffscreenContextPtr failed !\n"); + return -1; + } - return 0; + 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) @@ -242,7 +239,6 @@ return ph_SetupImage(this, screen); } } - int ph_AllocHWSurface(_THIS, SDL_Surface *surface) { return(-1); @@ -302,20 +298,21 @@ 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) { @@ -323,7 +320,7 @@ } PgSetRegion(PtWidgetRid(window)); - PgSetClipping(0,NULL); + PgSetClipping(0, NULL); PgWaitHWIdle(); for (i=0; i<numrects; ++i) @@ -333,24 +330,27 @@ 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; - - 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.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; - zero.x = zero.y = 0; - PgSetTranslation (&zero, 0); + 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 = 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 */
--- a/src/video/photon/SDL_ph_video.c Sun May 19 19:52:32 2002 +0000 +++ b/src/video/photon/SDL_ph_video.c Sun May 19 19:54:01 2002 +0000 @@ -255,6 +255,16 @@ 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); @@ -317,7 +327,7 @@ #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 */ @@ -332,7 +342,7 @@ { 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); } } @@ -340,7 +350,7 @@ { 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); } } @@ -362,7 +372,7 @@ 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 */ @@ -424,8 +434,15 @@ 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) @@ -512,9 +529,10 @@ 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 { @@ -533,7 +551,10 @@ /* 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 { @@ -602,7 +623,7 @@ if (oglctx==NULL) { - fprintf(stderr,"ph_SetupOpenGLContext: cannot create OpenGL context.\n"); + fprintf(stderr,"ph_SetupOpenGLContext(): cannot create OpenGL context.\n"); return (-1); }
--- a/src/video/photon/SDL_phyuv.c Sun May 19 19:52:32 2002 +0000 +++ b/src/video/photon/SDL_phyuv.c Sun May 19 19:54:01 2002 +0000 @@ -29,7 +29,6 @@ #include <stdlib.h> #include <string.h> -//#include <ncurses.h> //only for bool #ifndef bool #define bool char #define TRUE 1 @@ -104,7 +103,7 @@ FRAMEDATA *FrameData0; FRAMEDATA *FrameData1; PgScalerProps_t props; - PgScalerCaps_t caps; + PgScalerCaps_t caps; PgVideoChannel_t *channel; SDL_Rect CurrentWindow; long format; @@ -142,7 +141,7 @@ } -SDL_Overlay *ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display) +SDL_Overlay* ph_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display) { SDL_Overlay *overlay; struct private_yuvhwdata *hwdata; @@ -162,7 +161,8 @@ PhDCSetCurrent(0); //Need to set draw context to window esp. if we we in Offscreeen mode /* Create the overlay structure */ - overlay = (SDL_Overlay *)malloc(sizeof *overlay); + overlay = (SDL_Overlay *)malloc(sizeof(SDL_Overlay)); + memset(overlay, 0x00, sizeof(SDL_Overlay)); if ( overlay == NULL ) { SDL_OutOfMemory(); return(NULL); @@ -178,7 +178,8 @@ overlay->hwfuncs = &ph_yuvfuncs; /* Create the pixel data and lookup tables */ - hwdata = (struct private_yuvhwdata *)malloc(sizeof *hwdata); + hwdata = (struct private_yuvhwdata *)malloc(sizeof(struct private_yuvhwdata)); + memset(hwdata, 0x00, sizeof(struct private_yuvhwdata)); overlay->hwdata = hwdata; if ( hwdata == NULL ) { SDL_OutOfMemory(); @@ -186,54 +187,41 @@ return(NULL); } - if (overlay->hwdata->channel == NULL) - { - - - if ((overlay->hwdata->channel = PgCreateVideoChannel(Pg_VIDEO_CHANNEL_SCALER,0)) == NULL) - { - SDL_SetError("Create channel failed:%s\n", strerror( errno )); - free(overlay->hwdata); - free(overlay); - return(NULL); - } -#if 0 - overlay->hwdata->caps.size = sizeof (overlay->hwdata->caps); - PgGetScalerCapabilities(overlay->hwdata->channel, 0, &(overlay->hwdata->caps)); - if (overlay->hwdata->caps.flags & Pg_SCALER_CAP_DOUBLE_BUFFER) - overlay->hwdata->props.flags |= Pg_SCALER_PROP_DOUBLE_BUFFER; -#endif - } + if (overlay->hwdata->channel == NULL) + { + if ((overlay->hwdata->channel = PgCreateVideoChannel(Pg_VIDEO_CHANNEL_SCALER,0)) == NULL) + { + SDL_SetError("ph_CreateYUVOverlay(): Create channel failed: %s\n", strerror( errno )); + free(overlay->hwdata); + free(overlay); + return (NULL); + } + } -overlay->hwdata->CurrentWindow.x = 0; -overlay->hwdata->CurrentWindow.y = 0; -overlay->hwdata->CurrentWindow.w = 320; -overlay->hwdata->CurrentWindow.h = 240; + overlay->hwdata->CurrentWindow.x = 0; + overlay->hwdata->CurrentWindow.y = 0; + overlay->hwdata->CurrentWindow.w = 320; + overlay->hwdata->CurrentWindow.h = 240; - - -overlay->hwdata->State = OVERLAY_STATE_UNINIT; + overlay->hwdata->State = OVERLAY_STATE_UNINIT; -overlay->hwdata->screen_bpp = 2; -overlay->hwdata->scaler_on = FALSE; - -overlay->hwdata->screen_width = 1024; -overlay->hwdata->screen_height = 768; + overlay->hwdata->screen_bpp = 2; + overlay->hwdata->scaler_on = FALSE; + overlay->hwdata->screen_width = 1024; + overlay->hwdata->screen_height = 768; -overlay->hwdata->FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA))); -overlay->hwdata->FrameData1 = (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->caps.size = sizeof(overlay->hwdata->caps); - + overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps); //Note you really don't need to do this for SDL as you are given a format, but this is a good example -xv_port = -1; -i=0; - + xv_port = -1; + i=0; + while(PgGetScalerCapabilities(overlay->hwdata->channel, i++, &(overlay->hwdata->caps)) == 0) { - if(overlay->hwdata->caps.format == Pg_VIDEO_FORMAT_YV12) //in SDL {