Paolo Bonzini | 1 May 08:34
Picon
Gravatar

Re: SDL 1.2 CoreGraphics renderer?

Sam Lantinga wrote:
>> Since Leopard deprecated QuickDraw and actually makes it unaccessible in 
>> 64-bit mode, is a overhaul of the Quartz renderer (using CoreGraphics) 
>> going to happen anytime?
> 
> It's done, SDL 1.3 PRERELEASE:
> http://www.libsdl.org/tmp/SDL-1.3.zip

Unfortunately, it's still buggy.  testsprite does not work (the 
transparent parts are white, I'll make a bugzilla entry).  The bug is 
still there in the svn trunk.

The attached prototype patch against the 1.2 branch improves the frame 
rate by ~50%, even though it's still far from OpenGL (1.3) speed.

Paolo
Index: src/video/quartz/SDL_QuartzVideo.h
===================================================================
--- src/video/quartz/SDL_QuartzVideo.h	(revision 3618)
+++ src/video/quartz/SDL_QuartzVideo.h	(working copy)
@@ -93,7 +93,8 @@ typedef struct SDL_PrivateVideoData {
     Uint32             warp_flag;          /* boolean; notify to event loop that a warp just occured */
     Uint32             warp_ticks;         /* timestamp when the warp occured */
     NSWindow           *window;            /* Cocoa window to implement the SDL window */
-    NSQuickDrawView    *view;              /* the window's view; draw 2D and OpenGL into this view */
+    NSView             *view;              /* the window's view; draw 2D and OpenGL into this view */
+    CGContextRef       cg_context;         /* CoreGraphics rendering context */
     SDL_Surface        *resize_icon;       /* icon for the resize badge, we have to draw it by hand */
     SDL_GrabMode       current_grab_mode;  /* default value is SDL_GRAB_OFF */
     SDL_Rect           **client_mode_list; /* resolution list to pass back to client */
@@ -139,6 +140,7 @@ typedef struct SDL_PrivateVideoData {
 #define mode_flags (this->hidden->flags)
 #define qz_window (this->hidden->window)
 #define window_view (this->hidden->view)
+#define cg_context (this->hidden->cg_context)
 #define video_set (this->hidden->video_set)
 #define warp_ticks (this->hidden->warp_ticks)
 #define warp_flag (this->hidden->warp_flag)
@@ -156,6 +158,7 @@ typedef struct SDL_PrivateVideoData {
 #define cursor_should_be_visible (this->hidden->cursor_should_be_visible)
 #define cursor_visible (this->hidden->cursor_visible)
 #define sw_buffers (this->hidden->sw_buffers)
+#define sw_contexts (this->hidden->sw_contexts)
 #define thread (this->hidden->thread)
 #define sem1 (this->hidden->sem1)
 #define sem2 (this->hidden->sem2)
Index: src/video/quartz/SDL_QuartzWM.m
===================================================================
--- src/video/quartz/SDL_QuartzWM.m	(revision 3618)
+++ src/video/quartz/SDL_QuartzWM.m	(working copy)
@@ -171,11 +171,7 @@ void QZ_PrivateSDLToCocoa (_THIS, NSPoin
     else {

         *p = [ window_view convertPoint:*p toView: nil ];
-        
-        /* We need a workaround in OpenGL mode */
-        if ( SDL_VideoSurface->flags & SDL_OPENGL ) {
-            p->y = [window_view frame].size.height - p->y;
-        }
+        p->y = [window_view frame].size.height - p->y;
     }
 }

@@ -189,11 +185,7 @@ void QZ_PrivateCocoaToSDL (_THIS, NSPoin
     else {

         *p = [ window_view convertPoint:*p fromView: nil ];
-        
-        /* We need a workaround in OpenGL mode */
-        if ( SDL_VideoSurface != NULL && (SDL_VideoSurface->flags & SDL_OPENGL) ) {
-            p->y = [window_view frame].size.height - p->y;
-        }
+        p->y = [window_view frame].size.height - p->y;
     }
 }

Index: src/video/quartz/SDL_QuartzYUV.m
===================================================================
--- src/video/quartz/SDL_QuartzYUV.m	(revision 3618)
+++ src/video/quartz/SDL_QuartzYUV.m	(working copy)
@@ -51,6 +51,11 @@ static int QZ_DisplayYUV (_THIS, SDL_Ove

     OSErr err;
     CodecFlags flags;
+    int h;
+    char *p_dst, *p_src;
+    PixMapHandle           hPixMap;
+    long                   theRowBytes;
+

     if (dst->x != 0 || dst->y != 0) {

@@ -81,25 +86,36 @@ static int QZ_DisplayYUV (_THIS, SDL_Ove
                                          codecFlagUseImageBuffer, &flags, nil ) != noErr ) )
     {
         SDL_SetError ("DecompressSequenceFrameS failed");
+        return TRUE;
     }

-    return err != noErr;
+    /* TODO: use CGContextDrawImage here too!  Create two CGContextRefs the same way we
+       create two buffers, replace current_buffer with current_context and set it
+       appropriately in QZ_FlipDoubleBuffer.  Use CTM instead of the above
+       SetIdentityMatrix thing.  */
+    hPixMap     = GetGWorldPixMap(yuv_port);
+    p_src       = GetPixBaseAddr(hPixMap);
+    theRowBytes = QTGetPixMapHandleRowBytes(hPixMap);
+    p_dst       = SDL_VideoSurface->pixels + SDL_VideoSurface->offset;
+    for (h = dst->h; h--; ) {
+        SDL_memcpy (p_dst, p_src, dst->w * 4);
+        p_src += theRowBytes;
+        p_dst += SDL_VideoSurface->pitch;
+    }
+    SDL_Flip (SDL_VideoSurface);
+    return FALSE;
 }

 static void QZ_FreeHWYUV (_THIS, SDL_Overlay *overlay) {

     CDSequenceEnd (yuv_seq);
     ExitMovies();
+    DisposeGWorld(yuv_port);

     SDL_free (overlay->hwfuncs);
     SDL_free (overlay->pitches);
     SDL_free (overlay->pixels);

-    if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
-        [ qz_window close ];
-        qz_window = nil;
-    }
-
     SDL_free (yuv_matrix);
     DisposeHandle ((Handle)yuv_idh);
 }
@@ -117,6 +133,7 @@ SDL_Overlay* QZ_CreateYUVOverlay (_THIS,
     OSStatus err;
     CGrafPtr port;
     SDL_Overlay *overlay;
+    Rect  theBounds = {0, 0};

     if (format == SDL_YV12_OVERLAY ||
         format == SDL_IYUV_OVERLAY) {
@@ -151,48 +168,19 @@ SDL_Overlay* QZ_CreateYUVOverlay (_THIS,
         return NULL;
     }

-    if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
-
-        /*
-          Acceleration requires a window to be present.
-          A CGrafPtr that points to the screen isn't good enough
-        */
-        NSRect content = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
-
-        qz_window = [ [ SDL_QuartzWindow alloc ]
-                            initWithContentRect:content
-                            styleMask:NSBorderlessWindowMask
-                            backing:NSBackingStoreBuffered defer:NO ];
+    theBounds.right  = width;
+    theBounds.bottom = height;
+    yuv_port = NULL;

-        if (qz_window == nil) {
-            SDL_SetError ("Could not create the Cocoa window");
-            return NULL;
-        }
+    err = QTNewGWorld(&yuv_port, k32ARGBPixelFormat, &theBounds,
+                      NULL, NULL, 0);

-        [ qz_window setContentView:[ [ NSQuickDrawView alloc ] init ] ];
-        [ qz_window setReleasedWhenClosed:YES ];
-        [ qz_window center ];
-        [ qz_window setAcceptsMouseMovedEvents:YES ];
-        [ qz_window setLevel:CGShieldingWindowLevel() ];
-        [ qz_window makeKeyAndOrderFront:nil ];
-
-        port = [ [ qz_window contentView ] qdPort ];
-        SetPort (port);
-        
-        /*
-            BUG: would like to remove white flash when window kicks in
-            {
-                Rect r;
-                SetRect (&r, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
-                PaintRect (&r);
-                QDFlushPortBuffer (port, nil);
-            }
-        */
-    }
-    else {
-        port = [ window_view qdPort ];
-        SetPort (port);
+    if (err != noErr) {
+        SDL_SetError ("Could not init QuickTime world");
+        return NULL;
     }
+
+    LockPixels(GetGWorldPixMap(yuv_port));

     SetIdentityMatrix (yuv_matrix);

@@ -219,7 +207,7 @@ SDL_Overlay* QZ_CreateYUVOverlay (_THIS,
                                     yuv_idh,
                                     NULL,
                                     0,
-                                    port,
+                                    yuv_port,
                                     NULL,
                                     NULL,
                                     yuv_matrix,
@@ -231,11 +219,13 @@ SDL_Overlay* QZ_CreateYUVOverlay (_THIS,

     if (err != noErr) {
         SDL_SetError ("Error trying to start YUV codec.");
+	DisposeGWorld(yuv_port);
         return NULL;
     }

     overlay = (SDL_Overlay*) SDL_malloc (sizeof(*overlay));
     if (overlay == NULL) {
+	DisposeGWorld(yuv_port);
         SDL_OutOfMemory();
         return NULL;
     }
@@ -263,6 +253,7 @@ SDL_Overlay* QZ_CreateYUVOverlay (_THIS,
             plane3 = 1; /* V plane maps to plane 2 */
         }
         else {
+	    DisposeGWorld(yuv_port);
             SDL_SetError("Unsupported YUV format");
             return NULL;
         }
@@ -270,6 +261,7 @@ SDL_Overlay* QZ_CreateYUVOverlay (_THIS,
         pixels = (Uint8**) SDL_malloc (sizeof(*pixels) * 3);
         pitches = (Uint16*) SDL_malloc (sizeof(*pitches) * 3);
         if (pixels == NULL || pitches == NULL) {
+	    DisposeGWorld(yuv_port);
             SDL_OutOfMemory();
             return NULL;
         }
@@ -280,6 +272,7 @@ SDL_Overlay* QZ_CreateYUVOverlay (_THIS,
             SDL_malloc (sizeof(PlanarPixmapInfoYUV420) +
                     (width * height * 2));
         if (yuv_pixmap == NULL) {
+	    DisposeGWorld(yuv_port);
             SDL_OutOfMemory ();
             return NULL;
         }
@@ -314,6 +307,7 @@ SDL_Overlay* QZ_CreateYUVOverlay (_THIS,

     overlay->hwfuncs = SDL_malloc (sizeof(*overlay->hwfuncs));
     if (overlay->hwfuncs == NULL) {
+	DisposeGWorld(yuv_port);
         SDL_OutOfMemory();
         return NULL;
     }
Index: src/video/quartz/SDL_QuartzVideo.m
===================================================================
--- src/video/quartz/SDL_QuartzVideo.m	(revision 3618)
+++ src/video/quartz/SDL_QuartzVideo.m	(working copy)
@@ -52,6 +52,8 @@
 - (void) doCommandBySelector:(SEL) myselector {}
 @end

+/* absent in 10.3.9.  */
+CG_EXTERN CGImageRef CGBitmapContextCreateImage (CGContextRef);

 /* Bootstrap functions */
 static int              QZ_Available ();
@@ -79,8 +81,6 @@ static int          QZ_FlipDoubleBuffer 
 static void         QZ_DoubleBufferUpdate (_THIS, int num_rects, SDL_Rect *rects);

 static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
-static int          QZ_LockWindow       (_THIS, SDL_Surface *surface);
-static void         QZ_UnlockWindow     (_THIS, SDL_Surface *surface);
 static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
 static void         QZ_VideoQuit        (_THIS);

@@ -371,6 +371,13 @@ static void QZ_UnsetVideoMode (_THIS, BO
     this->LockHWSurface   = NULL;
     this->UnlockHWSurface = NULL;

+
+    if (cg_context) {
+	CGContextFlush (cg_context);
+	CGContextRelease (cg_context);
+        cg_context = nil;
+    }
+
     /* Release fullscreen resources */
     if ( mode_flags & SDL_FULLSCREEN ) {

@@ -487,7 +494,8 @@ static SDL_Surface* QZ_SetVideoFullScree
     current->flags |= SDL_FULLSCREEN;
     current->flags |= SDL_HWSURFACE;
     current->flags |= SDL_PREALLOC;
-    
+    /* current->hwdata = (void *) CGDisplayGetDrawingContext (display_id); */
+
     this->UpdateRects     = QZ_DirectUpdate;
     this->LockHWSurface   = QZ_LockHWSurface;
     this->UnlockHWSurface = QZ_UnlockHWSurface;
@@ -809,46 +817,34 @@ static SDL_Surface* QZ_SetVideoWindowed 
     }
     /* For 2D, we set the subview to an NSQuickDrawView */
     else {
-        short qdbpp = 0;
+	CGColorSpaceRef cgColorspace;

         /* Only recreate the view if it doesn't already exist */
         if (window_view == nil) {

-            window_view = [ [ NSQuickDrawView alloc ] initWithFrame:contentRect ];
+            window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
             [ window_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable ];
             [ [ qz_window contentView ] addSubview:window_view ];
             [ window_view release ];
             [ qz_window makeKeyAndOrderFront:nil ];
         }

-        LockPortBits ( [ window_view qdPort ] );
-        current->pixels = GetPixBaseAddr ( GetPortPixMap ( [ window_view qdPort ] ) );
-        current->pitch  = GetPixRowBytes ( GetPortPixMap ( [ window_view qdPort ] ) );
-        qdbpp           = GetPixDepth ( GetPortPixMap ( [ window_view qdPort ] ) );
-        UnlockPortBits ( [ window_view qdPort ] );
-
-        /* QuickDraw may give a 16-bit shadow surface on 8-bit displays! */
-        *bpp = qdbpp;
+	cgColorspace = CGColorSpaceCreateDeviceRGB();
+	current->pitch = 4 * current->w;
+	current->pixels = SDL_malloc (current->h * current->pitch);
+
+	cg_context = CGBitmapContextCreate (current->pixels, current->w, current->h,
+					    8, current->pitch, cgColorspace,
+					    kCGImageAlphaNoneSkipFirst);
+	CGColorSpaceRelease (cgColorspace);

         current->flags |= SDL_SWSURFACE;
-        current->flags |= SDL_PREALLOC;
         current->flags |= SDL_ASYNCBLIT;
+	current->hwdata = (void *) cg_context;

-        /* 
-            current->pixels now points to the window's pixels
-            We want it to point to the *view's* pixels 
-        */
-        { 
-            int vOffset = [ qz_window frame ].size.height - 
-                [ window_view frame ].size.height - [ window_view frame ].origin.y;
-            
-            int hOffset = [ window_view frame ].origin.x;
-                    
-            current->pixels = (Uint8 *)current->pixels + (vOffset * current->pitch) + hOffset * (qdbpp/8);
-        }
         this->UpdateRects     = QZ_UpdateRects;
-        this->LockHWSurface   = QZ_LockWindow;
-        this->UnlockHWSurface = QZ_UnlockWindow;
+        this->LockHWSurface   = QZ_LockHWSurface;
+        this->UnlockHWSurface = QZ_UnlockHWSurface;
     }

     /* Save flags to ensure correct teardown */
@@ -877,8 +873,8 @@ static SDL_Surface* QZ_SetVideoMode (_TH
     }
     /* Setup windowed video */
     else {
-        /* Force bpp to the device's bpp */
-        bpp = device_bpp;
+        /* Force bpp to 32 */
+        bpp = 32;
         current = QZ_SetVideoWindowed (this, current, width, height, &bpp, flags);
         if (current == NULL)
             return NULL;
@@ -1062,6 +1058,9 @@ static int QZ_ThreadFlip (_THIS) {
         /* On error, skip VBL delay */
         ERROR:

+	/* TODO: use CGContextDrawImage here too!  Create two CGContextRefs the same way we
+	   create two buffers, replace current_buffer with current_context and set it
+	   appropriately in QZ_FlipDoubleBuffer.  */
         while ( h-- ) {

             SDL_memcpy (dst, src, len);
@@ -1105,253 +1104,6 @@ static void QZ_DirectUpdate (_THIS, int 
 #pragma unused(this,num_rects,rects)
 }

-/*
-    The obscured code is based on work by Matt Slot fprefect <at> ambrosiasw.com,
-    who supplied sample code for Carbon.
-*/
-
-/*#define TEST_OBSCURED 1*/
-
-#if TEST_OBSCURED
-#include "CGS.h"
-#endif
-
-static int QZ_IsWindowObscured (NSWindow *window) {
-
-
-#if TEST_OBSCURED
-
-    /*  
-        In order to determine if a direct copy to the screen is possible,
-        we must figure out if there are any windows covering ours (including shadows).
-        This can be done by querying the window server about the on screen
-        windows for their screen rectangle and window level.
-        The procedure used below is puts accuracy before speed; however, it aims to call
-        the window server the fewest number of times possible to keep things reasonable.
-        In my testing on a 300mhz G3, this routine typically takes < 2 ms. -DW
-    
-    Notes:
-        -Calls into the Window Server involve IPC which is slow.
-        -Getting a rectangle seems slower than getting the window level
-        -The window list we get back is in sorted order, top to bottom
-        -On average, I suspect, most windows above ours are dock icon windows (hence optimization)
-        -Some windows above ours are always there, and cannot move or obscure us (menu bar)
-    
-    Bugs:
-        -no way (yet) to deactivate direct drawing when a window is dragged,
-        or suddenly obscured, so drawing continues and can produce garbage
-        We need some kind of locking mechanism on window movement to prevent this
-    
-        -deactivated normal windows use activated normal
-        window shadows (slight inaccuraccy)
-    */
-
-    /* Cache the connection to the window server */
-    static CGSConnectionID    cgsConnection = (CGSConnectionID) -1;
-
-    /* Cache the dock icon windows */
-    static CGSWindowID          dockIcons[kMaxWindows];
-    static int                  numCachedDockIcons = 0;
-
-    CGSWindowID                windows[kMaxWindows];
-    CGSWindowCount             i, count;
-    CGSWindowLevel             winLevel;
-    CGSRect                    winRect;
-
-    CGSRect contentRect;
-    int     windowNumber;
-    int     firstDockIcon;
-    int     dockIconCacheMiss;
-    int     windowContentOffset;
-
-    int     obscured = SDL_TRUE;
-
-    if ( [ window isVisible ] ) {
-
-        /*  
-            walk the window list looking for windows over top of
-            (or casting a shadow on) ours 
-        */
-
-        /* 
-           Get a connection to the window server
-           Should probably be moved out into SetVideoMode() or InitVideo()
-        */
-        if (cgsConnection == (CGSConnectionID) -1) {
-            cgsConnection = (CGSConnectionID) 0;
-            cgsConnection = _CGSDefaultConnection ();
-        }
-
-        if (cgsConnection) {
-
-            if ( ! [ window styleMask ] & NSBorderlessWindowMask )
-                windowContentOffset = 22;
-            else
-                windowContentOffset = 0;
-
-            windowNumber = [ window windowNumber ];
-
-            /* The window list is sorted according to order on the screen */
-            count = 0;
-            CGSGetOnScreenWindowList (cgsConnection, 0, kMaxWindows, windows, &count);
-            CGSGetScreenRectForWindow (cgsConnection, windowNumber, &contentRect);
-
-            /* adjust rect for window title bar (if present) */
-            contentRect.origin.y    += windowContentOffset;
-            contentRect.size.height -= windowContentOffset;
-
-            firstDockIcon = -1;
-            dockIconCacheMiss = SDL_FALSE;
-
-            /* 
-                The first window is always an empty window with level kCGSWindowLevelTop
-                so start at index 1
-            */
-            for (i = 1; i < count; i++) {
-
-                /* If we reach our window in the list, it cannot be obscured */
-                if (windows[i] == windowNumber) {
-
-                    obscured = SDL_FALSE;
-                    break;
-                }
-                else {
-
-                    float shadowSide;
-                    float shadowTop;
-                    float shadowBottom;
-
-                    CGSGetWindowLevel (cgsConnection, windows[i], &winLevel);
-
-                    if (winLevel == kCGSWindowLevelDockIcon) {
-
-                        int j;
-
-                        if (firstDockIcon < 0) {
-
-                            firstDockIcon = i;
-
-                            if (numCachedDockIcons > 0) {
-
-                                for (j = 0; j < numCachedDockIcons; j++) {
-
-                                    if (windows[i] == dockIcons[j])
-                                        i++;
-                                    else
-                                        break;
-                                }
-
-                                if (j != 0) {
-
-                                    i--;
-
-                                    if (j < numCachedDockIcons) {
-
-                                        dockIconCacheMiss = SDL_TRUE;
-                                    }
-                                }
-
-                            }
-                        }
-
-                        continue;
-                    }
-                    else if (winLevel == kCGSWindowLevelMenuIgnore
-                             /* winLevel == kCGSWindowLevelTop */) {
-
-                        continue; /* cannot obscure window */
-                    }
-                    else if (winLevel == kCGSWindowLevelDockMenu ||
-                             winLevel == kCGSWindowLevelMenu) {
-
-                        shadowSide = 18;
-                        shadowTop = 4;
-                        shadowBottom = 22;
-                    }
-                    else if (winLevel == kCGSWindowLevelUtility) {
-
-                        shadowSide = 8;
-                        shadowTop = 4;
-                        shadowBottom = 12;
-                    }
-                    else if (winLevel == kCGSWindowLevelNormal) {
-
-                        /* 
-                            These numbers are for foreground windows,
-                            they are too big (but will work) for background windows 
-                        */
-                        shadowSide = 20;
-                        shadowTop = 10;
-                        shadowBottom = 24;
-                    }
-                    else if (winLevel == kCGSWindowLevelDock) {
-
-                        /* Create dock icon cache */
-                        if (numCachedDockIcons != (i-firstDockIcon) ||
-                            dockIconCacheMiss) {
-
-                            numCachedDockIcons = i - firstDockIcon;
-                            SDL_memcpy (dockIcons, &(windows[firstDockIcon]),
-                                    numCachedDockIcons * sizeof(*windows));
-                        }
-
-                        /* no shadow */
-                        shadowSide = 0;
-                        shadowTop = 0;
-                        shadowBottom = 0;
-                    }
-                    else {
-
-                        /*
-                            kCGSWindowLevelDockLabel,
-                            kCGSWindowLevelDock,
-                            kOther???
-                        */
-
-                        /* no shadow */
-                        shadowSide = 0;
-                        shadowTop = 0;
-                        shadowBottom = 0;
-                    }
-
-                    CGSGetScreenRectForWindow (cgsConnection, windows[i], &winRect);
-
-                    winRect.origin.x -= shadowSide;
-                    winRect.origin.y -= shadowTop;
-                    winRect.size.width += shadowSide;
-                    winRect.size.height += shadowBottom;
-
-                    if (NSIntersectsRect (contentRect, winRect)) {
-
-                        obscured = SDL_TRUE;
-                        break;
-                    }
-
-                } /* window was not our window */
-
-            } /* iterate over windows */
-
-        } /* get cgsConnection */
-
-    } /* window is visible */
-    
-    return obscured;
-#else
-    return SDL_TRUE;
-#endif
-}
-
-
-/* Locking functions for the software window buffer */
-static int QZ_LockWindow (_THIS, SDL_Surface *surface) {
-    
-    return LockPortBits ( [ window_view qdPort ] );
-}
-
-static void QZ_UnlockWindow (_THIS, SDL_Surface *surface) {
-
-    UnlockPortBits ( [ window_view qdPort ] );
-}

 /* Resize icon, BMP format */
 static const unsigned char QZ_ResizeIcon[] = {
@@ -1393,41 +1145,34 @@ static const unsigned char QZ_ResizeIcon
     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b
 };

-static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) {
+static void QZ_DrawResizeIcon (_THIS) {

     /* Check if we should draw the resize icon */
     if (SDL_VideoSurface->flags & SDL_RESIZABLE) {

-        Rect    icon;
-        SetRect (&icon, SDL_VideoSurface->w - 13, SDL_VideoSurface->h - 13, 
-                    SDL_VideoSurface->w, SDL_VideoSurface->h);
-                    
-        if (RectInRgn (&icon, dirtyRegion)) {
-        
-            SDL_Rect icon_rect;
+        SDL_Rect icon_rect;

-            /* Create the icon image */
-            if (resize_icon == NULL) {
+        /* Create the icon image */
+        if (resize_icon == NULL) {

-                SDL_RWops *rw;
-                SDL_Surface *tmp;
+            SDL_RWops *rw;
+            SDL_Surface *tmp;

-                rw = SDL_RWFromConstMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon));
-                tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);
+            rw = SDL_RWFromConstMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon));
+            tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);

-                resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY);
-                SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF);
-                
-                SDL_FreeSurface (tmp);
-            }
-            
-            icon_rect.x = SDL_VideoSurface->w - 13;
-            icon_rect.y = SDL_VideoSurface->h - 13;
-            icon_rect.w = 13;
-            icon_rect.h = 13;
+            resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY);
+            SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF);

-            SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect);
+            SDL_FreeSurface (tmp);
         }
+            
+        icon_rect.x = SDL_VideoSurface->w - 13;
+        icon_rect.y = SDL_VideoSurface->h - 13;
+        icon_rect.w = 13;
+        icon_rect.h = 13;
+            
+        SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect);
     }
 }

@@ -1441,75 +1186,19 @@ static void QZ_UpdateRects (_THIS, int n
         /* Do nothing if miniaturized */
     }

-    else if ( ! QZ_IsWindowObscured (qz_window) ) {
-
-        /* Use direct copy to flush contents to the display */
-        CGrafPtr savePort;
-        CGrafPtr dstPort, srcPort;
-        const BitMap  *dstBits, *srcBits;
-        Rect     dstRect, srcRect;
-        Point    offset;
-        int i;
-
-        GetPort (&savePort);
-
-        dstPort = CreateNewPortForCGDisplayID ((UInt32)display_id);
-        srcPort = [ window_view qdPort ];
-
-        offset.h = 0;
-        offset.v = 0;
-        SetPort (srcPort);
-        LocalToGlobal (&offset);
-
-        SetPort (dstPort);
-
-        LockPortBits (dstPort);
-        LockPortBits (srcPort);
-
-        dstBits = GetPortBitMapForCopyBits (dstPort);
-        srcBits = GetPortBitMapForCopyBits (srcPort);
-
-        for (i = 0; i < numRects; i++) {
-
-            SetRect (&srcRect, rects[i].x, rects[i].y,
-                     rects[i].x + rects[i].w,
-                     rects[i].y + rects[i].h);
-
-            SetRect (&dstRect,
-                     rects[i].x + offset.h,
-                     rects[i].y + offset.v,
-                     rects[i].x + rects[i].w + offset.h,
-                     rects[i].y + rects[i].h + offset.v);
-
-            CopyBits (srcBits, dstBits,
-                      &srcRect, &dstRect, srcCopy, NULL);
-
-        }
-
-        SetPort (savePort);
-    }
     else {
-        /* Use QDFlushPortBuffer() to flush content to display */
-        int i;
-        RgnHandle dirty = NewRgn ();
-        RgnHandle temp  = NewRgn ();
-
-        SetEmptyRgn (dirty);
-
-        /* Build the region of dirty rectangles */
-        for (i = 0; i < numRects; i++) {
-
-            MacSetRectRgn (temp, rects[i].x, rects[i].y,
-                        rects[i].x + rects[i].w, rects[i].y + rects[i].h);
-            MacUnionRgn (dirty, temp, dirty);
-        }
-
-        QZ_DrawResizeIcon (this, dirty);
-        
-        /* Flush the dirty region */
-        QDFlushPortBuffer ( [ window_view qdPort ], dirty );
-        DisposeRgn (dirty);
-        DisposeRgn (temp);
+	CGContextRef cgc = (CGContextRef)
+		[[NSGraphicsContext graphicsContextWithWindow: qz_window]
+			graphicsPort];
+	QZ_DrawResizeIcon (this);
+	CGContextFlush (cg_context);
+	CGImageRef image = CGBitmapContextCreateImage (cg_context);
+	CGRect rectangle = CGRectMake (0,0,[window_view frame].size.width,[window_view frame].size.height);
+
+	CGContextDrawImage (cgc, rectangle, image);
+	CGImageRelease(image);
+	CGContextFlush (cgc);
+	CGContextRelease (cgc);
     }
 }

Index: src/video/quartz/SDL_QuartzWindow.m
===================================================================
--- src/video/quartz/SDL_QuartzWindow.m	(revision 3618)
+++ src/video/quartz/SDL_QuartzWindow.m	(working copy)
@@ -125,31 +125,6 @@ static void QZ_SetPortAlphaOpaque () {
         newViewFrame = [ window_view frame ];

         SDL_PrivateResize (newViewFrame.size.width, newViewFrame.size.height);
-
-        /* If not OpenGL, we have to update the pixels and pitch */
-        if ( ! ( SDL_VideoSurface->flags & SDL_OPENGL ) ) {
-            
-            CGrafPtr thePort = [ window_view qdPort ];
-            LockPortBits ( thePort );
-            
-            SDL_VideoSurface->pixels = GetPixBaseAddr ( GetPortPixMap ( thePort ) );
-            SDL_VideoSurface->pitch  = GetPixRowBytes ( GetPortPixMap ( thePort ) );
-                        
-            /* 
-                SDL_VideoSurface->pixels now points to the window's pixels
-                We want it to point to the *view's* pixels 
-            */
-            { 
-                int vOffset = [ qz_window frame ].size.height - 
-                    newViewFrame.size.height - newViewFrame.origin.y;
-                
-                int hOffset = newViewFrame.origin.x;
-                        
-                SDL_VideoSurface->pixels = (Uint8 *)SDL_VideoSurface->pixels + (vOffset *
SDL_VideoSurface->pitch) + hOffset * (device_bpp/8);
-            }
-            
-            UnlockPortBits ( thePort );
-        }
     }
 }

_______________________________________________
SDL mailing list
SDL <at> lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Gmane