diff src/video/photon/SDL_ph_image.c @ 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 3333b6e68289
children bce7171e7a85
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 */