diff src/video/photon/SDL_ph_image.c @ 571:8e3ce997621c

Date: Thu, 16 Jan 2003 13:48:31 +0200 From: "Mike Gorchak" Subject: All QNX patches whole patches concerning QNX. Almost all code has been rewritten by Julian and me. Added initial support for hw overlays in QNX and many many others fixes. P.S. This patches has been reviewed by Dave Rempel from QSSL and included in SDL 1.2.5 distribution, which coming on 3rd party CD for newest 6.2.1 version of QNX, which will be available soon.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 20 Jan 2003 01:38:37 +0000
parents bce7171e7a85
children 8bedd6d61642
line wrap: on
line diff
--- a/src/video/photon/SDL_ph_image.c	Mon Jan 20 01:37:07 2003 +0000
+++ b/src/video/photon/SDL_ph_image.c	Mon Jan 20 01:38:37 2003 +0000
@@ -29,16 +29,60 @@
 #include <Ph.h>
 #include <photon/Pg.h>
 
+#include "SDL.h"
 #include "SDL_error.h"
 #include "SDL_endian.h"
+#include "SDL_video.h"
+#include "SDL_pixels_c.h"
 #include "SDL_ph_image_c.h"
 
-/* remove this line, if photon headers updates */
-int PgWaitHWIdle(void);
+/* Mask values for SDL_ReallocFormat() */
+struct ColourMasks
+{
+    Uint32 red;
+    Uint32 green;
+    Uint32 blue;
+    Uint32 alpha;
+    Uint32 bpp;
+};
+
+static const struct ColourMasks *ph_GetColourMasks( int format )
+{
+    /* The alpha mask doesn't appear to be needed */
+    static const struct ColourMasks phColorMasks[5] = {
+        /*  8 bit      */  {0, 0, 0, 0, 8},
+        /* 15 bit ARGB */  {0x7C00, 0x03E0, 0x001F, 0x8000, 16},
+        /* 16 bit  RGB */  {0xF800, 0x07E0, 0x001F, 0x0000, 16},
+        /* 24 bit  RGB */  {0xFF0000, 0x00FF00, 0x0000FF, 0x000000, 24},
+        /* 32 bit ARGB */  {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 32},
+    };
+
+    switch( format )
+    {
+        case Pg_IMAGE_PALETTE_BYTE:
+             return &phColorMasks[0];
+             break;
+        case Pg_IMAGE_DIRECT_1555:
+        case Pg_IMAGE_DIRECT_555:
+             return &phColorMasks[1];
+             break;
+        case Pg_IMAGE_DIRECT_565:
+             return &phColorMasks[2];
+             break;
+        case Pg_IMAGE_DIRECT_888:
+             return &phColorMasks[3];
+             break;
+        case Pg_IMAGE_DIRECT_8888:
+             return &phColorMasks[4];
+             break;
+    }
+    return NULL;
+}
 
 int ph_SetupImage(_THIS, SDL_Surface *screen)
 {
     PgColor_t* palette=NULL;
+    const struct ColourMasks* mask;
     int type=0;
     int bpp;
     
@@ -68,7 +112,7 @@
         }
         break;
         default:{
-            fprintf(stderr,"ph_SetupImage(): unsupported bbp = %d\n", bpp);
+            fprintf(stderr,"ph_SetupImage(): unsupported bpp=%d !\n", bpp);
             return -1;
         }
         break;
@@ -84,7 +128,7 @@
         /* 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)
         {
-            fprintf(stderr,"ph_SetupImage(): PhCreateImage failed for bpp=8.\n");
+            fprintf(stderr,"ph_SetupImage(): PhCreateImage failed for bpp=8 !\n");
             return -1;
         }
     }
@@ -93,14 +137,20 @@
         /* using shared memory for speed (set last param to 1) */
         if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, NULL, 0, 1)) == NULL)
         {
-            fprintf(stderr,"ph_SetupImage: PhCreateImage failed.\n");
+            fprintf(stderr,"ph_SetupImage: PhCreateImage failed !\n");
             return -1;
         }
     }
-    
+
     screen->pixels = SDL_Image->image;
     screen->pitch = SDL_Image->bpl; /* Recalculated pitch, created by PhCreateImage */
 
+    mask = ph_GetColourMasks(type);
+    if (mask != NULL)
+    {
+        SDL_ReallocFormat(screen, mask->bpp, mask->red, mask->green, mask->blue, 0);
+    }
+
     this->UpdateRects = ph_NormalUpdate;
 
     return 0;
@@ -108,8 +158,12 @@
 
 int ph_SetupOCImage(_THIS, SDL_Surface *screen)
 {
+    const struct ColourMasks *mask;
     int type = 0;
     int bpp;
+
+    screen->flags &= ~SDL_DOUBLEBUF;
+    OCImage.flags = screen->flags;
     
     bpp=screen->format->BitsPerPixel;
 
@@ -137,22 +191,14 @@
                 }
                 break;
         default:{
-                    fprintf(stderr,"ph_SetupOCImage(): unsupported bpp = %d\n", bpp);
+                    fprintf(stderr,"ph_SetupOCImage(): unsupported bpp=%d !\n", bpp);
                     return -1;
                 }
                 break;
     }
 
-    OCImage.FrameData0 = (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)
-    {
-        OCImage.direct_context = PdCreateDirectContext();
-    }
-
+    /* Currently only offscreen contexts with the same bit depth as the
+     * display can be created. */
     OCImage.offscreen_context = PdCreateOffscreenContext(0, screen->w, screen->h, Pg_OSC_MEM_PAGE_ALIGN);
 
     if (OCImage.offscreen_context == NULL)
@@ -161,13 +207,22 @@
         return -1;
     }
 
-    screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */
+    /* If the bit depth of the context is different than was requested,
+     * these values need to be updated accordingly.  SDL will
+     * allocate a shadow surface if it needs to. */
+    mask = ph_GetColourMasks(OCImage.offscreen_context->format);
+    if (mask != NULL)
+    {
+        SDL_ReallocFormat(screen, mask->bpp, mask->red, mask->green, mask->blue, 0);
 
-    if (OCImage.flags & SDL_DOUBLEBUF)
-    {
-        fprintf(stderr, "ph_SetupOCImage(): Hardware flag for doublebuf offscreen context\n");
+        if (mask->bpp > 8)
+        {
+            screen->flags &= ~SDL_HWPALETTE;
+        }
     }
 
+    screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */
+
     OCImage.dc_ptr.ptr8 = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context);
 
     if (OCImage.dc_ptr.ptr8 == NULL)
@@ -176,15 +231,13 @@
         return -1;
     }
 
+    OCImage.FrameData0 = OCImage.dc_ptr.ptr8;
     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;
+    screen->pixels = OCImage.CurrentFrameData;
 
     this->UpdateRects = ph_OCUpdate;
 
@@ -198,15 +251,67 @@
    return 0;
 }
 
+int ph_SetupFullScreenImage(_THIS, SDL_Surface* screen)
+{
+    const struct ColourMasks *mask;
+    screen->flags &= ~SDL_DOUBLEBUF;
+    OCImage.flags = screen->flags;
+
+    OCImage.offscreen_context = PdCreateOffscreenContext(0, 0, 0, Pg_OSC_MAIN_DISPLAY);
+
+    if (OCImage.offscreen_context == NULL)
+    {
+        fprintf(stderr, "ph_SetupFullScreenImage(): PdCreateOffscreenContext failed !\n");
+        return -1;
+    }
+
+    /* If the bit depth of the context is different than was requested,
+     * these values need to be updated accordingly.  SDL will
+     * allocate a shadow surface if it needs to. */
+    mask = ph_GetColourMasks(OCImage.offscreen_context->format);
+    if (mask != NULL)
+    {
+        SDL_ReallocFormat(screen, mask->bpp, mask->red, mask->green, mask->blue, 0);
+
+        if (mask->bpp > 8)
+        {
+            screen->flags &= ~SDL_HWPALETTE;
+        }
+    }
+
+    screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */
+
+    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;
+    }
+
+    /* wait for hw */
+    PgWaitHWIdle();
+
+    OCImage.FrameData0 = OCImage.dc_ptr.ptr8;
+    OCImage.CurrentFrameData = OCImage.FrameData0;
+    OCImage.current = 0;
+
+    PhDCSetCurrent(OCImage.offscreen_context);
+
+    screen->pixels = OCImage.CurrentFrameData;
+
+    this->UpdateRects = ph_OCUpdate;
+
+    return 0;
+}
+
 void ph_DestroyImage(_THIS, SDL_Surface *screen)
 {
     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;
     }
 
@@ -230,23 +335,24 @@
     }
 }
 
-int ph_ResizeImage(_THIS, SDL_Surface *screen, Uint32 flags)
+int ph_SetupUpdateFunction(_THIS, SDL_Surface *screen, Uint32 flags)
 {
     ph_DestroyImage(this, screen);
     
-    if (flags & SDL_HWSURFACE)
+    if ((flags & SDL_FULLSCREEN)==SDL_FULLSCREEN)
     {
-        OCImage.flags = flags;  /* needed for SDL_DOUBLEBUF check */
+        return ph_SetupFullScreenImage(this, screen);
+    }
+    if ((flags & SDL_HWSURFACE)==SDL_HWSURFACE)
+    {
         return ph_SetupOCImage(this, screen);
     }
-    else if (flags & SDL_OPENGL)
+    if ((flags & SDL_OPENGL)==SDL_OPENGL)
     {
         return ph_SetupOpenGLImage(this, screen);
     } 
-    else
-    {
-        return ph_SetupImage(this, screen);
-    }      
+
+    return ph_SetupImage(this, screen);
 }
 int ph_AllocHWSurface(_THIS, SDL_Surface *surface)
 {
@@ -265,11 +371,6 @@
 
 int ph_LockHWSurface(_THIS, SDL_Surface *surface)
 {
-    if ((surface == SDL_VideoSurface) && blit_queued) {
-	PgFlush();
-        blit_queued = 0;
-    }
-
     return(0);
 }
 
@@ -307,7 +408,7 @@
 
         if (PgDrawPhImageRectmx(&ph_pos, SDL_Image, &ph_rect, 0) < 0)
         {
-            fprintf(stderr,"ph_NormalUpdate(): PgDrawPhImageRectmx failed.\n");
+            fprintf(stderr,"ph_NormalUpdate(): PgDrawPhImageRectmx failed !\n");
         }
     }
 
@@ -325,11 +426,6 @@
     PhArea_t src_rect;
     PhArea_t dest_rect;
 
-    if(OCImage.direct_context == NULL)
-    {
-        return;
-    }
-
     PgSetRegion(PtWidgetRid(window));
     PgSetClipping(0, NULL);
     PgWaitHWIdle();