Date: Wed, 31 Dec 2003 21:55:30 +0100
authorSam Lantinga <slouken@libsdl.org>
Sun, 04 Jan 2004 14:55:35 +0000
changeset 761c5b2b6d2d1fe
parent 760 cf9dd3aa6756
child 762 c4965af1d0e0
Date: Wed, 31 Dec 2003 21:55:30 +0100
From: Max Horn
Subject: SDL: video/quartz cleanup

while doing some experimental changes in the quartz code, I was annoyed
by having to recompile that one big .o file over and over again. So I
decided to finally realize one TODO: properly splitting the code over
multiple files :-).

With two exceptions, I didn't make code changes, only rearranged files
and added new headers. Since there are several new files, making a
patch didn't work out so well, so I decided to just send you all the
new & modified files.

The one source change I made is related to showing/hiding the mouse. I
renamed cursor_visible to cursor_should_be_visible and cursor_hidden to
cursor_visible; I think that makes reading the code easier.
Then I added two new functions: QZ_ShowMouse and QZ_HideMouse. They
help manage cursor_visible (the former 'cursor_hidden'). Finally I
replaced the Carbon ShowCursor/HiderCuror calls by [NSCursor hide] and
[NSCursor unhide]. The API docs are not conclusive, but it might be
that with those the "cursor_visible" (former 'cursor_hidden') hack may
not be necessary anymore; however so far I didn't test this hypothesis,
so I left that in.

The other change was to remove in_foreground and use [NSApp isActive]
instead: Manually keeping track of whether we are in the foreground is
error prone. This should work better in some corner cases.
src/video/quartz/CGS.h
src/video/quartz/Makefile.am
src/video/quartz/SDL_QuartzEvents.m
src/video/quartz/SDL_QuartzGL.m
src/video/quartz/SDL_QuartzKeys.h
src/video/quartz/SDL_QuartzVideo.h
src/video/quartz/SDL_QuartzVideo.m
src/video/quartz/SDL_QuartzWM.m
src/video/quartz/SDL_QuartzWindow.h
src/video/quartz/SDL_QuartzWindow.m
src/video/quartz/SDL_QuartzYUV.m
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/quartz/CGS.h	Sun Jan 04 14:55:35 2004 +0000
     1.3 @@ -0,0 +1,83 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2003  Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Library General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Library General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Library General Public
    1.19 +    License along with this library; if not, write to the Free
    1.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +
    1.26 +/* 
    1.27 +    Obscuring code: maximum number of windows above ours (inclusive) 
    1.28 +    
    1.29 +    Note: this doesn't work too well in practice and should be
    1.30 +    phased out when we add OpenGL 2D acceleration. It was never
    1.31 +    enabled in the first place, so this shouldn't be a problem ;-)
    1.32 +*/
    1.33 +#define kMaxWindows 256
    1.34 +
    1.35 +/* Some of the Core Graphics Server API for obscuring code */
    1.36 +#define kCGSWindowLevelTop          2147483632
    1.37 +#define kCGSWindowLevelDockIconDrag 500
    1.38 +#define kCGSWindowLevelDockMenu     101
    1.39 +#define kCGSWindowLevelMenuIgnore    21
    1.40 +#define kCGSWindowLevelMenu          20
    1.41 +#define kCGSWindowLevelDockLabel     12
    1.42 +#define kCGSWindowLevelDockIcon      11
    1.43 +#define kCGSWindowLevelDock          10
    1.44 +#define kCGSWindowLevelUtility        3
    1.45 +#define kCGSWindowLevelNormal         0
    1.46 +
    1.47 +/* 
    1.48 +    For completeness; We never use these window levels, they are always below us
    1.49 +    #define kCGSWindowLevelMBarShadow -20
    1.50 +    #define kCGSWindowLevelDesktopPicture -2147483647
    1.51 +    #define kCGSWindowLevelDesktop        -2147483648
    1.52 +*/
    1.53 +
    1.54 +typedef CGError       CGSError;
    1.55 +typedef long          CGSWindowCount;
    1.56 +typedef void *        CGSConnectionID;
    1.57 +typedef int           CGSWindowID;
    1.58 +typedef CGSWindowID*  CGSWindowIDList;
    1.59 +typedef CGWindowLevel CGSWindowLevel;
    1.60 +typedef NSRect        CGSRect;
    1.61 +
    1.62 +extern CGSConnectionID _CGSDefaultConnection ();
    1.63 +
    1.64 +extern CGSError CGSGetOnScreenWindowList (CGSConnectionID cid,
    1.65 +                                          CGSConnectionID owner,
    1.66 +                                          CGSWindowCount listCapacity,
    1.67 +                                          CGSWindowIDList list,
    1.68 +                                          CGSWindowCount *listCount);
    1.69 +
    1.70 +extern CGSError CGSGetScreenRectForWindow (CGSConnectionID cid,
    1.71 +                                           CGSWindowID wid,
    1.72 +                                           CGSRect *rect);
    1.73 +
    1.74 +extern CGWindowLevel CGSGetWindowLevel (CGSConnectionID cid,
    1.75 +                                        CGSWindowID wid,
    1.76 +                                        CGSWindowLevel *level);
    1.77 +
    1.78 +extern CGSError CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y,
    1.79 +                                  unsigned int w, unsigned int h, unsigned int color);
    1.80 +
    1.81 +extern CGSError CGSDisplayCanHWFill (CGDirectDisplayID id);
    1.82 +
    1.83 +extern CGSError CGSGetMouseEnabledFlags (CGSConnectionID cid, CGSWindowID wid, int *flags);
    1.84 +
    1.85 +int CGSDisplayHWSync (CGDirectDisplayID id);
    1.86 +
     2.1 --- a/src/video/quartz/Makefile.am	Wed Dec 31 04:48:38 2003 +0000
     2.2 +++ b/src/video/quartz/Makefile.am	Sun Jan 04 14:55:35 2004 +0000
     2.3 @@ -6,12 +6,13 @@
     2.4  
     2.5  # The SDL MacOS X Quartz video driver sources
     2.6  QUARTZ_SRCS = 			\
     2.7 +	CGS.h				\
     2.8 +	SDL_QuartzEvents.m	\
     2.9 +	SDL_QuartzGL.m		\
    2.10  	SDL_QuartzKeys.h	\
    2.11  	SDL_QuartzVideo.h	\
    2.12 -	SDL_QuartzVideo.m
    2.13 -
    2.14 -# These files are included by SDL_QuartzVideo.m (is that right??)
    2.15 -noinst_HEADERS =		\
    2.16 -	SDL_QuartzEvents.m	\
    2.17 +	SDL_QuartzVideo.m	\
    2.18 +	SDL_QuartzWindow.h	\
    2.19 +	SDL_QuartzWindow.m	\
    2.20  	SDL_QuartzWM.m		\
    2.21 -	SDL_QuartzWindow.m
    2.22 +	SDL_QuartzYUV.m
     3.1 --- a/src/video/quartz/SDL_QuartzEvents.m	Wed Dec 31 04:48:38 2003 +0000
     3.2 +++ b/src/video/quartz/SDL_QuartzEvents.m	Sun Jan 04 14:55:35 2004 +0000
     3.3 @@ -1,6 +1,6 @@
     3.4  /*
     3.5      SDL - Simple DirectMedia Layer
     3.6 -    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002    Sam Lantinga
     3.7 +    Copyright (C) 1997-2003  Sam Lantinga
     3.8  
     3.9      This library is free software; you can redistribute it and/or
    3.10      modify it under the terms of the GNU Library General Public
    3.11 @@ -19,12 +19,15 @@
    3.12      Sam Lantinga
    3.13      slouken@libsdl.org
    3.14  */
    3.15 -#include <stdlib.h>	// For getenv()
    3.16 +
    3.17 +#include "SDL_QuartzVideo.h"
    3.18 +
    3.19 +#include <stdlib.h> // For getenv()
    3.20  #include <IOKit/IOMessage.h> // For wake from sleep detection
    3.21  #include <IOKit/pwr_mgt/IOPMLib.h> // For wake from sleep detection
    3.22  #include "SDL_QuartzKeys.h"
    3.23  
    3.24 -static void     QZ_InitOSKeymap (_THIS) {
    3.25 +void     QZ_InitOSKeymap (_THIS) {
    3.26      const void *KCHRPtr;
    3.27      UInt32 state;
    3.28      UInt32 value;
    3.29 @@ -283,7 +286,7 @@
    3.30               key.sym = mapping[i];
    3.31               /* If this was Caps Lock, we need some additional voodoo to make SDL happy */
    3.32               if (bit == NSAlphaShiftKeyMask)
    3.33 -             SDL_PrivateKeyboard (SDL_PRESSED, &key);
    3.34 +                  SDL_PrivateKeyboard (SDL_PRESSED, &key);
    3.35               SDL_PrivateKeyboard (SDL_RELEASED, &key);
    3.36          }
    3.37          else if ( newMask &&
    3.38 @@ -302,13 +305,9 @@
    3.39  
    3.40  static void QZ_DoActivate (_THIS)
    3.41  {
    3.42 -    in_foreground = YES;
    3.43 -    
    3.44      /* Hide the cursor if it was hidden by SDL_ShowCursor() */
    3.45 -    if (!cursor_visible && !cursor_hidden) {
    3.46 -        HideCursor ();
    3.47 -        cursor_hidden = YES;
    3.48 -    }
    3.49 +    if (!cursor_should_be_visible)
    3.50 +        QZ_HideMouse (this);
    3.51  
    3.52      /* Regrab input, only if it was previously grabbed */
    3.53      if ( current_grab_mode == SDL_GRAB_ON ) {
    3.54 @@ -323,8 +322,6 @@
    3.55  
    3.56  static void QZ_DoDeactivate (_THIS) {
    3.57  
    3.58 -    in_foreground = NO;
    3.59 -
    3.60      /* Get the current cursor location, for restore on activate */
    3.61      cursor_loc = [ NSEvent mouseLocation ]; /* global coordinates */
    3.62      if (qz_window)
    3.63 @@ -335,10 +332,8 @@
    3.64      CGAssociateMouseAndMouseCursorPosition (1);
    3.65  
    3.66      /* Show the cursor if it was hidden by SDL_ShowCursor() */
    3.67 -    if (!cursor_visible && cursor_hidden) {
    3.68 -        ShowCursor ();
    3.69 -        cursor_hidden = NO;
    3.70 -    }
    3.71 +    if (!cursor_should_be_visible)
    3.72 +        QZ_ShowMouse (this);
    3.73  
    3.74      SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
    3.75  }
    3.76 @@ -359,13 +354,13 @@
    3.77               IOAllowPowerChange(power_connection, (long) messageArgument);
    3.78               break;
    3.79           case kIOMessageSystemHasPoweredOn:
    3.80 -			/* awake */
    3.81 +            /* awake */
    3.82              SDL_PrivateExpose();
    3.83              break;
    3.84       }
    3.85  }
    3.86  
    3.87 -static void QZ_RegisterForSleepNotifications (_THIS)
    3.88 +void QZ_RegisterForSleepNotifications (_THIS)
    3.89  {
    3.90       CFRunLoopSourceRef rls;
    3.91       IONotificationPortRef thePortRef;
    3.92 @@ -400,7 +395,7 @@
    3.93  }
    3.94  
    3.95  
    3.96 -static void QZ_PumpEvents (_THIS)
    3.97 +void QZ_PumpEvents (_THIS)
    3.98  {
    3.99      int firstMouseEvent;
   3.100      CGMouseDelta dx, dy;
   3.101 @@ -445,7 +440,7 @@
   3.102              BOOL isInGameWin;
   3.103              
   3.104              #define DO_MOUSE_DOWN(button) do {                                               \
   3.105 -                            if ( in_foreground ) {                                           \
   3.106 +                            if ( [ NSApp isActive ] ) {                                      \
   3.107                                  if ( isInGameWin ) {                                         \
   3.108                                      SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0);      \
   3.109                                      expect_mouse_up |= 1<<button;                            \
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/video/quartz/SDL_QuartzGL.m	Sun Jan 04 14:55:35 2004 +0000
     4.3 @@ -0,0 +1,228 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997-2003  Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Library General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Library General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Library General Public
    4.19 +    License along with this library; if not, write to the Free
    4.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@libsdl.org
    4.24 +*/
    4.25 +
    4.26 +#include "SDL_QuartzVideo.h"
    4.27 +
    4.28 +/* 
    4.29 +    This is a workaround to directly access NSOpenGLContext's CGL context
    4.30 +    We need this to check for errors NSOpenGLContext doesn't support
    4.31 +*/
    4.32 +@interface NSOpenGLContext (CGLContextAccess)
    4.33 +- (CGLContextObj) cglContext;
    4.34 +@end
    4.35 +
    4.36 +@implementation NSOpenGLContext (CGLContextAccess)
    4.37 +- (CGLContextObj) cglContext;
    4.38 +{
    4.39 +    return _contextAuxiliary;
    4.40 +}
    4.41 +@end
    4.42 +
    4.43 +/* OpenGL helper functions (used internally) */
    4.44 +
    4.45 +int QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags) {
    4.46 +
    4.47 +    NSOpenGLPixelFormatAttribute attr[32];
    4.48 +    NSOpenGLPixelFormat *fmt;
    4.49 +    int i = 0;
    4.50 +    int colorBits = bpp;
    4.51 +
    4.52 +    if ( flags & SDL_FULLSCREEN ) {
    4.53 +
    4.54 +        attr[i++] = NSOpenGLPFAFullScreen;
    4.55 +    }
    4.56 +    /* In windowed mode, the OpenGL pixel depth must match device pixel depth */
    4.57 +    else if ( colorBits != device_bpp ) {
    4.58 +
    4.59 +        colorBits = device_bpp;
    4.60 +    }
    4.61 +
    4.62 +    attr[i++] = NSOpenGLPFAColorSize;
    4.63 +    attr[i++] = colorBits;
    4.64 +
    4.65 +    attr[i++] = NSOpenGLPFADepthSize;
    4.66 +    attr[i++] = this->gl_config.depth_size;
    4.67 +
    4.68 +    if ( this->gl_config.double_buffer ) {
    4.69 +        attr[i++] = NSOpenGLPFADoubleBuffer;
    4.70 +    }
    4.71 +
    4.72 +    if ( this->gl_config.stereo ) {
    4.73 +        attr[i++] = NSOpenGLPFAStereo;
    4.74 +    }
    4.75 +
    4.76 +    if ( this->gl_config.stencil_size != 0 ) {
    4.77 +        attr[i++] = NSOpenGLPFAStencilSize;
    4.78 +        attr[i++] = this->gl_config.stencil_size;
    4.79 +    }
    4.80 +
    4.81 +#if NSOPENGL_CURRENT_VERSION > 1  /* What version should this be? */
    4.82 +    if ( this->gl_config.multisamplebuffers != 0 ) {
    4.83 +        attr[i++] = NSOpenGLPFASampleBuffers;
    4.84 +        attr[i++] = this->gl_config.multisamplebuffers;
    4.85 +    }
    4.86 +
    4.87 +    if ( this->gl_config.multisamplesamples != 0 ) {
    4.88 +        attr[i++] = NSOpenGLPFASamples;
    4.89 +        attr[i++] = this->gl_config.multisamplesamples;
    4.90 +    }
    4.91 +#endif
    4.92 +
    4.93 +    attr[i++] = NSOpenGLPFAScreenMask;
    4.94 +    attr[i++] = CGDisplayIDToOpenGLDisplayMask (display_id);
    4.95 +    attr[i] = 0;
    4.96 +
    4.97 +    fmt = [ [ NSOpenGLPixelFormat alloc ] initWithAttributes:attr ];
    4.98 +    if (fmt == nil) {
    4.99 +        SDL_SetError ("Failed creating OpenGL pixel format");
   4.100 +        return 0;
   4.101 +    }
   4.102 +
   4.103 +    gl_context = [ [ NSOpenGLContext alloc ] initWithFormat:fmt
   4.104 +                                               shareContext:nil];
   4.105 +
   4.106 +    if (gl_context == nil) {
   4.107 +        SDL_SetError ("Failed creating OpenGL context");
   4.108 +        return 0;
   4.109 +    }
   4.110 +
   4.111 +    /*
   4.112 +     * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
   4.113 +     *  "You are blowing a couple of the internal OpenGL function caches. This
   4.114 +     *  appears to be happening in the VAO case.  You can tell OpenGL to up
   4.115 +     *  the cache size by issuing the following calls right after you create
   4.116 +     *  the OpenGL context.  The default cache size is 16."    --ryan.
   4.117 +     */
   4.118 +
   4.119 +    #ifndef GLI_ARRAY_FUNC_CACHE_MAX
   4.120 +    #define GLI_ARRAY_FUNC_CACHE_MAX 284
   4.121 +    #endif
   4.122 +
   4.123 +    #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
   4.124 +    #define GLI_SUBMIT_FUNC_CACHE_MAX 280
   4.125 +    #endif
   4.126 +
   4.127 +    {
   4.128 +        long cache_max = 64;
   4.129 +        CGLContextObj ctx = [ gl_context cglContext ];
   4.130 +        CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
   4.131 +        CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
   4.132 +    }
   4.133 +
   4.134 +    /* End Wisdom from Apple Engineer section. --ryan. */
   4.135 +
   4.136 +    /* Convince SDL that the GL "driver" is loaded */
   4.137 +    this->gl_config.driver_loaded = 1;
   4.138 +
   4.139 +    [ fmt release ];
   4.140 +
   4.141 +    return 1;
   4.142 +}
   4.143 +
   4.144 +void QZ_TearDownOpenGL (_THIS) {
   4.145 +
   4.146 +    [ NSOpenGLContext clearCurrentContext ];
   4.147 +    [ gl_context clearDrawable ];
   4.148 +    [ gl_context release ];
   4.149 +}
   4.150 +
   4.151 +
   4.152 +/* SDL OpenGL functions */
   4.153 +
   4.154 +int    QZ_GL_LoadLibrary    (_THIS, const char *location) {
   4.155 +    this->gl_config.driver_loaded = 1;
   4.156 +    return 1;
   4.157 +}
   4.158 +
   4.159 +void*  QZ_GL_GetProcAddress (_THIS, const char *proc) {
   4.160 +
   4.161 +    /* We may want to cache the bundleRef at some point */
   4.162 +    CFBundleRef bundle;
   4.163 +    CFURLRef bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
   4.164 +                                                        CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, true);
   4.165 +
   4.166 +    CFStringRef functionName = CFStringCreateWithCString
   4.167 +        (kCFAllocatorDefault, proc, kCFStringEncodingASCII);
   4.168 +
   4.169 +    void *function;
   4.170 +
   4.171 +    bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL);
   4.172 +    assert (bundle != NULL);
   4.173 +
   4.174 +    function = CFBundleGetFunctionPointerForName (bundle, functionName);
   4.175 +
   4.176 +    CFRelease ( bundleURL );
   4.177 +    CFRelease ( functionName );
   4.178 +    CFRelease ( bundle );
   4.179 +
   4.180 +    return function;
   4.181 +}
   4.182 +
   4.183 +int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value) {
   4.184 +
   4.185 +    GLenum attr = 0;
   4.186 +
   4.187 +    QZ_GL_MakeCurrent (this);
   4.188 +
   4.189 +    switch (attrib) {
   4.190 +        case SDL_GL_RED_SIZE: attr = GL_RED_BITS;   break;
   4.191 +        case SDL_GL_BLUE_SIZE: attr = GL_BLUE_BITS;  break;
   4.192 +        case SDL_GL_GREEN_SIZE: attr = GL_GREEN_BITS; break;
   4.193 +        case SDL_GL_ALPHA_SIZE: attr = GL_ALPHA_BITS; break;
   4.194 +        case SDL_GL_DOUBLEBUFFER: attr = GL_DOUBLEBUFFER; break;
   4.195 +        case SDL_GL_DEPTH_SIZE: attr = GL_DEPTH_BITS;  break;
   4.196 +        case SDL_GL_STENCIL_SIZE: attr = GL_STENCIL_BITS; break;
   4.197 +        case SDL_GL_ACCUM_RED_SIZE: attr = GL_ACCUM_RED_BITS; break;
   4.198 +        case SDL_GL_ACCUM_GREEN_SIZE: attr = GL_ACCUM_GREEN_BITS; break;
   4.199 +        case SDL_GL_ACCUM_BLUE_SIZE: attr = GL_ACCUM_BLUE_BITS; break;
   4.200 +        case SDL_GL_ACCUM_ALPHA_SIZE: attr = GL_ACCUM_ALPHA_BITS; break;
   4.201 +        case SDL_GL_STEREO: attr = GL_STEREO; break;
   4.202 +        case SDL_GL_MULTISAMPLEBUFFERS: attr = GL_SAMPLE_BUFFERS_ARB; break;
   4.203 +        case SDL_GL_MULTISAMPLESAMPLES: attr = GL_SAMPLES_ARB; break;
   4.204 +        case SDL_GL_BUFFER_SIZE:
   4.205 +        {
   4.206 +            GLint bits = 0;
   4.207 +            GLint component;
   4.208 +
   4.209 +            /* there doesn't seem to be a single flag in OpenGL for this! */
   4.210 +            glGetIntegerv (GL_RED_BITS, &component);   bits += component;
   4.211 +            glGetIntegerv (GL_GREEN_BITS,&component);  bits += component;
   4.212 +            glGetIntegerv (GL_BLUE_BITS, &component);  bits += component;
   4.213 +            glGetIntegerv (GL_ALPHA_BITS, &component); bits += component;
   4.214 +
   4.215 +            *value = bits;
   4.216 +        }
   4.217 +        return 0;
   4.218 +    }
   4.219 +
   4.220 +    glGetIntegerv (attr, (GLint *)value);
   4.221 +    return 0;
   4.222 +}
   4.223 +
   4.224 +int    QZ_GL_MakeCurrent    (_THIS) {
   4.225 +    [ gl_context makeCurrentContext ];
   4.226 +    return 0;
   4.227 +}
   4.228 +
   4.229 +void   QZ_GL_SwapBuffers    (_THIS) {
   4.230 +    [ gl_context flushBuffer ];
   4.231 +}
     5.1 --- a/src/video/quartz/SDL_QuartzKeys.h	Wed Dec 31 04:48:38 2003 +0000
     5.2 +++ b/src/video/quartz/SDL_QuartzKeys.h	Sun Jan 04 14:55:35 2004 +0000
     5.3 @@ -1,24 +1,24 @@
     5.4  /*
     5.5      SDL - Simple DirectMedia Layer
     5.6 -    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     5.7 -    
     5.8 +    Copyright (C) 1997-2003  Sam Lantinga
     5.9 +
    5.10      This library is free software; you can redistribute it and/or
    5.11      modify it under the terms of the GNU Library General Public
    5.12      License as published by the Free Software Foundation; either
    5.13      version 2 of the License, or (at your option) any later version.
    5.14 -    
    5.15 +
    5.16      This library is distributed in the hope that it will be useful,
    5.17      but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.18      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.19      Library General Public License for more details.
    5.20 -    
    5.21 +
    5.22      You should have received a copy of the GNU Library General Public
    5.23      License along with this library; if not, write to the Free
    5.24      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.25 -    
    5.26 +
    5.27      Sam Lantinga
    5.28      slouken@libsdl.org
    5.29 - */
    5.30 +*/
    5.31  
    5.32  /* These are the Macintosh key scancode constants -- from Inside Macintosh */
    5.33  
     6.1 --- a/src/video/quartz/SDL_QuartzVideo.h	Wed Dec 31 04:48:38 2003 +0000
     6.2 +++ b/src/video/quartz/SDL_QuartzVideo.h	Sun Jan 04 14:55:35 2004 +0000
     6.3 @@ -1,6 +1,6 @@
     6.4  /*
     6.5      SDL - Simple DirectMedia Layer
     6.6 -    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     6.7 +    Copyright (C) 1997-2003  Sam Lantinga
     6.8  
     6.9      This library is free software; you can redistribute it and/or
    6.10      modify it under the terms of the GNU Library General Public
    6.11 @@ -54,7 +54,7 @@
    6.12  #include <OpenGL/glext.h>
    6.13  #include <Carbon/Carbon.h>
    6.14  #include <QuickTime/QuickTime.h>
    6.15 -#include <IOKit/IOKitLib.h>	/* For powersave handling */
    6.16 +#include <IOKit/IOKitLib.h> /* For powersave handling */
    6.17  #include <pthread.h>
    6.18  
    6.19  #include "SDL_thread.h"
    6.20 @@ -66,53 +66,6 @@
    6.21  #include "SDL_pixels_c.h"
    6.22  #include "SDL_events_c.h"
    6.23  
    6.24 -/* 
    6.25 -    Add methods to get at private members of NSScreen. 
    6.26 -    Since there is a bug in Apple's screen switching code
    6.27 -    that does not update this variable when switching
    6.28 -    to fullscreen, we'll set it manually (but only for the
    6.29 -    main screen).
    6.30 -*/
    6.31 -@interface NSScreen (NSScreenAccess)
    6.32 -- (void) setFrame:(NSRect)frame;
    6.33 -@end
    6.34 -
    6.35 -@implementation NSScreen (NSScreenAccess)
    6.36 -- (void) setFrame:(NSRect)frame;
    6.37 -{
    6.38 -    _frame = frame;
    6.39 -}
    6.40 -@end
    6.41 -
    6.42 -/* 
    6.43 -    This is a workaround to directly access NSOpenGLContext's CGL context
    6.44 -    We need this to check for errors NSOpenGLContext doesn't support
    6.45 -*/
    6.46 -@interface NSOpenGLContext (CGLContextAccess)
    6.47 -- (CGLContextObj) cglContext;
    6.48 -@end
    6.49 -
    6.50 -@implementation NSOpenGLContext (CGLContextAccess)
    6.51 -- (CGLContextObj) cglContext;
    6.52 -{
    6.53 -    return _contextAuxiliary;
    6.54 -}
    6.55 -@end
    6.56 -
    6.57 -/* 
    6.58 -    Structure for rez switch gamma fades
    6.59 -    We can hide the monitor flicker by setting the gamma tables to 0
    6.60 -*/
    6.61 -#define QZ_GAMMA_TABLE_SIZE 256
    6.62 -
    6.63 -typedef struct {
    6.64 -
    6.65 -    CGGammaValue red[QZ_GAMMA_TABLE_SIZE];
    6.66 -    CGGammaValue green[QZ_GAMMA_TABLE_SIZE];
    6.67 -    CGGammaValue blue[QZ_GAMMA_TABLE_SIZE];
    6.68 -
    6.69 -} SDL_QuartzGammaTable;
    6.70 -
    6.71  /* Main driver structure to store required state information */
    6.72  typedef struct SDL_PrivateVideoData {
    6.73  
    6.74 @@ -131,7 +84,6 @@
    6.75      NSQuickDrawView    *view;              /* the window's view; draw 2D and OpenGL into this view */
    6.76      SDL_Surface        *resize_icon;       /* icon for the resize badge, we have to draw it by hand */
    6.77      SDL_GrabMode       current_grab_mode;  /* default value is SDL_GRAB_OFF */
    6.78 -    BOOL               in_foreground;      /* boolean; indicate if app is in foreground or not */
    6.79      SDL_Rect           **client_mode_list; /* resolution list to pass back to client */
    6.80      SDLKey             keymap[256];        /* Mac OS X to SDL key mapping */
    6.81      Uint32             current_mods;       /* current keyboard modifiers, to track modifier state */
    6.82 @@ -140,8 +92,8 @@
    6.83      Uint8              expect_mouse_up;    /* used to determine when to send mouse up events */
    6.84      Uint8              grab_state;         /* used to manage grab behavior */
    6.85      NSPoint            cursor_loc;         /* saved cursor coords, for activate/deactivate when grabbed */
    6.86 -    BOOL          	   cursor_visible;     /* tells if cursor was instructed to be hidden or not (SDL_ShowCursor) */
    6.87 -    BOOL               cursor_hidden;      /* tells if cursor is *actually* hidden or not */
    6.88 +    BOOL               cursor_should_be_visible;     /* tells if cursor is supposed to be visible (SDL_ShowCursor) */
    6.89 +    BOOL               cursor_visible;     /* tells if cursor is *actually* visible or not */
    6.90      Uint8*             sw_buffers[2];      /* pointers to the two software buffers for double-buffer emulation */
    6.91      SDL_Thread         *thread;            /* thread for async updates to the screen */
    6.92      SDL_sem            *sem1, *sem2;       /* synchronization for async screen updates */
    6.93 @@ -156,7 +108,7 @@
    6.94      Sint16                  yuv_width, yuv_height;
    6.95      CGrafPtr                yuv_port;
    6.96  
    6.97 -} SDL_PrivateVideoData ;
    6.98 +} SDL_PrivateVideoData;
    6.99  
   6.100  #define _THIS    SDL_VideoDevice *this
   6.101  #define display_id (this->hidden->display)
   6.102 @@ -176,7 +128,6 @@
   6.103  #define warp_flag (this->hidden->warp_flag)
   6.104  #define resize_icon (this->hidden->resize_icon)
   6.105  #define current_grab_mode (this->hidden->current_grab_mode)
   6.106 -#define in_foreground (this->hidden->in_foreground)
   6.107  #define client_mode_list (this->hidden->client_mode_list)
   6.108  #define keymap (this->hidden->keymap)
   6.109  #define current_mods (this->hidden->current_mods)
   6.110 @@ -185,8 +136,8 @@
   6.111  #define expect_mouse_up (this->hidden->expect_mouse_up)
   6.112  #define grab_state (this->hidden->grab_state)
   6.113  #define cursor_loc (this->hidden->cursor_loc)
   6.114 +#define cursor_should_be_visible (this->hidden->cursor_should_be_visible)
   6.115  #define cursor_visible (this->hidden->cursor_visible)
   6.116 -#define cursor_hidden (this->hidden->cursor_hidden)
   6.117  #define sw_buffers (this->hidden->sw_buffers)
   6.118  #define thread (this->hidden->thread)
   6.119  #define sem1 (this->hidden->sem1)
   6.120 @@ -194,17 +145,6 @@
   6.121  #define current_buffer (this->hidden->current_buffer)
   6.122  #define quit_thread (this->hidden->quit_thread)
   6.123  
   6.124 -#define yuv_idh (this->hidden->yuv_idh)
   6.125 -#define yuv_matrix (this->hidden->yuv_matrix)
   6.126 -#define yuv_codec (this->hidden->yuv_codec)
   6.127 -#define yuv_seq (this->hidden->yuv_seq)
   6.128 -#define yuv_pixmap (this->hidden->yuv_pixmap)
   6.129 -#define yuv_data (this->hidden->yuv_data)
   6.130 -#define yuv_width (this->hidden->yuv_width)
   6.131 -#define yuv_height (this->hidden->yuv_height)
   6.132 -#define yuv_port (this->hidden->yuv_port)
   6.133 -
   6.134 -
   6.135  /* grab states - the input is in one of these states */
   6.136  enum {
   6.137      QZ_UNGRABBED = 0,
   6.138 @@ -220,145 +160,52 @@
   6.139      QZ_SHOWCURSOR
   6.140  };
   6.141  
   6.142 -/* 
   6.143 -    Obscuring code: maximum number of windows above ours (inclusive) 
   6.144 -    
   6.145 -    Note: this doesn't work too well in practice and should be
   6.146 -    phased out when we add OpenGL 2D acceleration. It was never
   6.147 -    enabled in the first place, so this shouldn't be a problem ;-)
   6.148 -*/
   6.149 -#define kMaxWindows 256
   6.150 -
   6.151 -/* Some of the Core Graphics Server API for obscuring code */
   6.152 -#define kCGSWindowLevelTop          2147483632
   6.153 -#define kCGSWindowLevelDockIconDrag 500
   6.154 -#define kCGSWindowLevelDockMenu     101
   6.155 -#define kCGSWindowLevelMenuIgnore    21
   6.156 -#define kCGSWindowLevelMenu          20
   6.157 -#define kCGSWindowLevelDockLabel     12
   6.158 -#define kCGSWindowLevelDockIcon      11
   6.159 -#define kCGSWindowLevelDock          10
   6.160 -#define kCGSWindowLevelUtility        3
   6.161 -#define kCGSWindowLevelNormal         0
   6.162 -
   6.163 -/* 
   6.164 -    For completeness; We never use these window levels, they are always below us
   6.165 -    #define kCGSWindowLevelMBarShadow -20
   6.166 -    #define kCGSWindowLevelDesktopPicture -2147483647
   6.167 -    #define kCGSWindowLevelDesktop        -2147483648
   6.168 -*/
   6.169 -
   6.170 -typedef CGError       CGSError;
   6.171 -typedef long          CGSWindowCount;
   6.172 -typedef void *        CGSConnectionID;
   6.173 -typedef int           CGSWindowID;
   6.174 -typedef CGSWindowID*  CGSWindowIDList;
   6.175 -typedef CGWindowLevel CGSWindowLevel;
   6.176 -typedef NSRect        CGSRect;
   6.177 -
   6.178 -extern CGSConnectionID _CGSDefaultConnection ();
   6.179 -
   6.180 -extern CGSError CGSGetOnScreenWindowList (CGSConnectionID cid,
   6.181 -                                          CGSConnectionID owner,
   6.182 -                                          CGSWindowCount listCapacity,
   6.183 -                                          CGSWindowIDList list,
   6.184 -                                          CGSWindowCount *listCount);
   6.185 -
   6.186 -extern CGSError CGSGetScreenRectForWindow (CGSConnectionID cid,
   6.187 -                                           CGSWindowID wid,
   6.188 -                                           CGSRect *rect);
   6.189 -
   6.190 -extern CGWindowLevel CGSGetWindowLevel (CGSConnectionID cid,
   6.191 -                                        CGSWindowID wid,
   6.192 -                                        CGSWindowLevel *level);
   6.193 -
   6.194 -extern CGSError CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y,
   6.195 -                                  unsigned int w, unsigned int h, unsigned int color);
   6.196 -
   6.197 -extern CGSError CGSDisplayCanHWFill (CGDirectDisplayID id);
   6.198 -
   6.199 -extern CGSError CGSGetMouseEnabledFlags (CGSConnectionID cid, CGSWindowID wid, int *flags);
   6.200 -
   6.201 -int CGSDisplayHWSync (CGDirectDisplayID id);
   6.202 -
   6.203 -/* Bootstrap functions */
   6.204 -static int              QZ_Available ();
   6.205 -static SDL_VideoDevice* QZ_CreateDevice (int device_index);
   6.206 -static void             QZ_DeleteDevice (SDL_VideoDevice *device);
   6.207 -
   6.208 -/* Initialization, Query, Setup, and Redrawing functions */
   6.209 -static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
   6.210 -
   6.211 -static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format,
   6.212 -                                         Uint32 flags);
   6.213 -static void         QZ_UnsetVideoMode   (_THIS);
   6.214 -
   6.215 -static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current,
   6.216 -                                         int width, int height, int bpp,
   6.217 -                                         Uint32 flags);
   6.218 -static int          QZ_ToggleFullScreen (_THIS, int on);
   6.219 -static int          QZ_SetColors        (_THIS, int first_color,
   6.220 -                                         int num_colors, SDL_Color *colors);
   6.221 -
   6.222 -static int          QZ_LockDoubleBuffer   (_THIS, SDL_Surface *surface);
   6.223 -static void         QZ_UnlockDoubleBuffer (_THIS, SDL_Surface *surface);
   6.224 -static int          QZ_ThreadFlip         (_THIS);
   6.225 -static int          QZ_FlipDoubleBuffer   (_THIS, SDL_Surface *surface);
   6.226 -static void         QZ_DoubleBufferUpdate (_THIS, int num_rects, SDL_Rect *rects);
   6.227 -
   6.228 -static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
   6.229 -static int          QZ_LockWindow       (_THIS, SDL_Surface *surface);
   6.230 -static void         QZ_UnlockWindow     (_THIS, SDL_Surface *surface);
   6.231 -static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
   6.232 -static void         QZ_VideoQuit        (_THIS);
   6.233 -
   6.234 -/* Hardware surface functions (for fullscreen mode only) */
   6.235 -#if 0 /* Not used (apparently, it's really slow) */
   6.236 -static int  QZ_FillHWRect (_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
   6.237 -#endif
   6.238 -static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface);
   6.239 -static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
   6.240 -static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
   6.241 -/* static int  QZ_FlipHWSurface (_THIS, SDL_Surface *surface); */
   6.242 -
   6.243  /* Gamma Functions */
   6.244 -static int QZ_SetGamma     (_THIS, float red, float green, float blue);
   6.245 -static int QZ_GetGamma     (_THIS, float *red, float *green, float *blue);
   6.246 -static int QZ_SetGammaRamp (_THIS, Uint16 *ramp);
   6.247 -static int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
   6.248 +int    QZ_SetGamma          (_THIS, float red, float green, float blue);
   6.249 +int    QZ_GetGamma          (_THIS, float *red, float *green, float *blue);
   6.250 +int    QZ_SetGammaRamp      (_THIS, Uint16 *ramp);
   6.251 +int    QZ_GetGammaRamp      (_THIS, Uint16 *ramp);
   6.252  
   6.253  /* OpenGL functions */
   6.254 -static int    QZ_SetupOpenGL       (_THIS, int bpp, Uint32 flags);
   6.255 -static void   QZ_TearDownOpenGL    (_THIS);
   6.256 -static void*  QZ_GL_GetProcAddress (_THIS, const char *proc);
   6.257 -static int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value);
   6.258 -static int    QZ_GL_MakeCurrent    (_THIS);
   6.259 -static void   QZ_GL_SwapBuffers    (_THIS);
   6.260 -static int    QZ_GL_LoadLibrary    (_THIS, const char *location);
   6.261 -
   6.262 -/* Private function to warp the cursor (used internally) */
   6.263 -static void  QZ_PrivateWarpCursor (_THIS, int x, int y);
   6.264 +int    QZ_SetupOpenGL       (_THIS, int bpp, Uint32 flags);
   6.265 +void   QZ_TearDownOpenGL    (_THIS);
   6.266 +void*  QZ_GL_GetProcAddress (_THIS, const char *proc);
   6.267 +int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value);
   6.268 +int    QZ_GL_MakeCurrent    (_THIS);
   6.269 +void   QZ_GL_SwapBuffers    (_THIS);
   6.270 +int    QZ_GL_LoadLibrary    (_THIS, const char *location);
   6.271  
   6.272  /* Cursor and Mouse functions */
   6.273 -static void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
   6.274 -static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask,
   6.275 -                                         int w, int h, int hot_x, int hot_y);
   6.276 -static int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
   6.277 -static void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
   6.278 -static void         QZ_MoveWMCursor     (_THIS, int x, int y);
   6.279 -static void         QZ_CheckMouseMode   (_THIS);
   6.280 +void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
   6.281 +WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask,
   6.282 +                                  int w, int h, int hot_x, int hot_y);
   6.283 +int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
   6.284 +void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
   6.285 +void         QZ_MoveWMCursor     (_THIS, int x, int y);
   6.286 +void         QZ_CheckMouseMode   (_THIS);
   6.287  
   6.288  /* Event functions */
   6.289 -static void         QZ_InitOSKeymap     (_THIS);
   6.290 -static void         QZ_PumpEvents       (_THIS);
   6.291 +void         QZ_InitOSKeymap     (_THIS);
   6.292 +void         QZ_PumpEvents       (_THIS);
   6.293  
   6.294  /* Window Manager functions */
   6.295 -static void QZ_SetCaption        (_THIS, const char *title, const char *icon);
   6.296 -static void QZ_SetIcon           (_THIS, SDL_Surface *icon, Uint8 *mask);
   6.297 -static int  QZ_IconifyWindow     (_THIS);
   6.298 -static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
   6.299 -/*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/
   6.300 +void         QZ_SetCaption       (_THIS, const char *title, const char *icon);
   6.301 +void         QZ_SetIcon          (_THIS, SDL_Surface *icon, Uint8 *mask);
   6.302 +int          QZ_IconifyWindow    (_THIS);
   6.303 +SDL_GrabMode QZ_GrabInput        (_THIS, SDL_GrabMode grab_mode);
   6.304 +/*int          QZ_GetWMInfo        (_THIS, SDL_SysWMinfo *info);*/
   6.305  
   6.306  /* YUV functions */
   6.307 -static SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
   6.308 +SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
   6.309                                           Uint32 format, SDL_Surface *display);
   6.310 +
   6.311 +
   6.312 +/* Private functions (used internally) */
   6.313 +void         QZ_PrivateWarpCursor (_THIS, int x, int y);
   6.314 +void         QZ_ChangeGrabState (_THIS, int action);
   6.315 +void         QZ_RegisterForSleepNotifications (_THIS);
   6.316 +void         QZ_ShowMouse (_THIS);
   6.317 +void         QZ_HideMouse (_THIS);
   6.318 +void         QZ_PrivateGlobalToLocal (_THIS, NSPoint *p);
   6.319 +void         QZ_PrivateCocoaToSDL (_THIS, NSPoint *p);
   6.320 +
     7.1 --- a/src/video/quartz/SDL_QuartzVideo.m	Wed Dec 31 04:48:38 2003 +0000
     7.2 +++ b/src/video/quartz/SDL_QuartzVideo.m	Sun Jan 04 14:55:35 2004 +0000
     7.3 @@ -1,6 +1,6 @@
     7.4  /*
     7.5      SDL - Simple DirectMedia Layer
     7.6 -    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     7.7 +    Copyright (C) 1997-2003  Sam Lantinga
     7.8  
     7.9      This library is free software; you can redistribute it and/or
    7.10      modify it under the terms of the GNU Library General Public
    7.11 @@ -21,11 +21,82 @@
    7.12  */
    7.13  
    7.14  #include "SDL_QuartzVideo.h"
    7.15 +#include "SDL_QuartzWindow.h"
    7.16  
    7.17 -/* Include files into one compile unit...break apart eventually */
    7.18 -#include "SDL_QuartzWM.m"
    7.19 -#include "SDL_QuartzEvents.m"
    7.20 -#include "SDL_QuartzWindow.m"
    7.21 +
    7.22 +/* 
    7.23 +    Add methods to get at private members of NSScreen. 
    7.24 +    Since there is a bug in Apple's screen switching code
    7.25 +    that does not update this variable when switching
    7.26 +    to fullscreen, we'll set it manually (but only for the
    7.27 +    main screen).
    7.28 +*/
    7.29 +@interface NSScreen (NSScreenAccess)
    7.30 +- (void) setFrame:(NSRect)frame;
    7.31 +@end
    7.32 +
    7.33 +@implementation NSScreen (NSScreenAccess)
    7.34 +- (void) setFrame:(NSRect)frame;
    7.35 +{
    7.36 +    _frame = frame;
    7.37 +}
    7.38 +@end
    7.39 +
    7.40 +
    7.41 +/* 
    7.42 +    Structure for rez switch gamma fades
    7.43 +    We can hide the monitor flicker by setting the gamma tables to 0
    7.44 +*/
    7.45 +#define QZ_GAMMA_TABLE_SIZE 256
    7.46 +
    7.47 +typedef struct {
    7.48 +
    7.49 +    CGGammaValue red[QZ_GAMMA_TABLE_SIZE];
    7.50 +    CGGammaValue green[QZ_GAMMA_TABLE_SIZE];
    7.51 +    CGGammaValue blue[QZ_GAMMA_TABLE_SIZE];
    7.52 +
    7.53 +} SDL_QuartzGammaTable;
    7.54 +
    7.55 +
    7.56 +/* Bootstrap functions */
    7.57 +static int              QZ_Available ();
    7.58 +static SDL_VideoDevice* QZ_CreateDevice (int device_index);
    7.59 +static void             QZ_DeleteDevice (SDL_VideoDevice *device);
    7.60 +
    7.61 +/* Initialization, Query, Setup, and Redrawing functions */
    7.62 +static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
    7.63 +
    7.64 +static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format,
    7.65 +                                         Uint32 flags);
    7.66 +static void         QZ_UnsetVideoMode   (_THIS);
    7.67 +
    7.68 +static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current,
    7.69 +                                         int width, int height, int bpp,
    7.70 +                                         Uint32 flags);
    7.71 +static int          QZ_ToggleFullScreen (_THIS, int on);
    7.72 +static int          QZ_SetColors        (_THIS, int first_color,
    7.73 +                                         int num_colors, SDL_Color *colors);
    7.74 +
    7.75 +static int          QZ_LockDoubleBuffer   (_THIS, SDL_Surface *surface);
    7.76 +static void         QZ_UnlockDoubleBuffer (_THIS, SDL_Surface *surface);
    7.77 +static int          QZ_ThreadFlip         (_THIS);
    7.78 +static int          QZ_FlipDoubleBuffer   (_THIS, SDL_Surface *surface);
    7.79 +static void         QZ_DoubleBufferUpdate (_THIS, int num_rects, SDL_Rect *rects);
    7.80 +
    7.81 +static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
    7.82 +static int          QZ_LockWindow       (_THIS, SDL_Surface *surface);
    7.83 +static void         QZ_UnlockWindow     (_THIS, SDL_Surface *surface);
    7.84 +static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
    7.85 +static void         QZ_VideoQuit        (_THIS);
    7.86 +
    7.87 +/* Hardware surface functions (for fullscreen mode only) */
    7.88 +#if 0 /* Not used (apparently, it's really slow) */
    7.89 +static int  QZ_FillHWRect (_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
    7.90 +#endif
    7.91 +static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface);
    7.92 +static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
    7.93 +static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
    7.94 +/* static int  QZ_FlipHWSurface (_THIS, SDL_Surface *surface); */
    7.95  
    7.96  /* Bootstrap binding, enables entry point into the driver */
    7.97  VideoBootStrap QZ_bootstrap = {
    7.98 @@ -130,8 +201,7 @@
    7.99  
   7.100      /* Set misc globals */
   7.101      current_grab_mode = SDL_GRAB_OFF;
   7.102 -    in_foreground     = YES;
   7.103 -    cursor_visible    = YES;
   7.104 +    cursor_should_be_visible    = YES;
   7.105      
   7.106      /* register for sleep notifications so wake from sleep generates SDL_VIDEOEXPOSE */
   7.107      QZ_RegisterForSleepNotifications (this);
   7.108 @@ -712,7 +782,7 @@
   7.109          /* Only recreate the view if it doesn't already exist */
   7.110          if (window_view == nil) {
   7.111          
   7.112 -            window_view = [ [ SDL_QuartzWindowView alloc ] initWithFrame:contentRect ];
   7.113 +            window_view = [ [ NSQuickDrawView alloc ] initWithFrame:contentRect ];
   7.114              [ window_view setAutoresizingMask: NSViewMinYMargin ];
   7.115              [ [ qz_window contentView ] addSubview:window_view ];
   7.116              [ window_view release ];
   7.117 @@ -851,7 +921,7 @@
   7.118      
   7.119      union
   7.120      {
   7.121 -        UInt64	i;
   7.122 +        UInt64 i;
   7.123          Nanoseconds ns;
   7.124      } temp;
   7.125          
   7.126 @@ -990,9 +1060,15 @@
   7.127      The obscured code is based on work by Matt Slot fprefect@ambrosiasw.com,
   7.128      who supplied sample code for Carbon.
   7.129  */
   7.130 +
   7.131 +//#define TEST_OBSCURED 1
   7.132 +
   7.133 +#if TEST_OBSCURED
   7.134 +#include "CGS.h"
   7.135 +#endif
   7.136 +
   7.137  static int QZ_IsWindowObscured (NSWindow *window) {
   7.138  
   7.139 -    //#define TEST_OBSCURED 1
   7.140  
   7.141  #if TEST_OBSCURED
   7.142  
   7.143 @@ -1230,6 +1306,84 @@
   7.144      UnlockPortBits ( [ window_view qdPort ] );
   7.145  }
   7.146  
   7.147 +/* Resize icon, BMP format */
   7.148 +static const unsigned char QZ_ResizeIcon[] = {
   7.149 +    0x42,0x4d,0x31,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
   7.150 +    0x00,0x00,0x0d,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
   7.151 +    0x00,0x00,0xfb,0x01,0x00,0x00,0x13,0x0b,0x00,0x00,0x13,0x0b,0x00,0x00,0x00,0x00,
   7.152 +    0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   7.153 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   7.154 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
   7.155 +    0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,
   7.156 +    0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
   7.157 +    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xda,0xda,0xda,0x87,
   7.158 +    0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,
   7.159 +    0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
   7.160 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd5,0xd5,0xd5,0x87,0x87,0x87,0xe8,0xe8,0xe8,
   7.161 +    0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,
   7.162 +    0xda,0xda,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   7.163 +    0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,
   7.164 +    0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
   7.165 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,
   7.166 +    0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
   7.167 +    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   7.168 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,
   7.169 +    0xe8,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
   7.170 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   7.171 +    0xff,0xff,0xff,0xd9,0xd9,0xd9,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xdc,
   7.172 +    0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   7.173 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,
   7.174 +    0xdb,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
   7.175 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   7.176 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,0xdb,0x87,0x87,0x87,0xe8,
   7.177 +    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   7.178 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   7.179 +    0xff,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
   7.180 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   7.181 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdc,
   7.182 +    0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   7.183 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   7.184 +    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b
   7.185 +};
   7.186 +
   7.187 +static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) {
   7.188 +
   7.189 +    /* Check if we should draw the resize icon */
   7.190 +    if (SDL_VideoSurface->flags & SDL_RESIZABLE) {
   7.191 +    
   7.192 +        Rect    icon;
   7.193 +        SetRect (&icon, SDL_VideoSurface->w - 13, SDL_VideoSurface->h - 13, 
   7.194 +                    SDL_VideoSurface->w, SDL_VideoSurface->h);
   7.195 +                    
   7.196 +        if (RectInRgn (&icon, dirtyRegion)) {
   7.197 +        
   7.198 +            SDL_Rect icon_rect;
   7.199 +            
   7.200 +            /* Create the icon image */
   7.201 +            if (resize_icon == NULL) {
   7.202 +            
   7.203 +                SDL_RWops *rw;
   7.204 +                SDL_Surface *tmp;
   7.205 +                
   7.206 +                rw = SDL_RWFromMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon));
   7.207 +                tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);
   7.208 +                                                                
   7.209 +                resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY);
   7.210 +                SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF);
   7.211 +                
   7.212 +                SDL_FreeSurface (tmp);
   7.213 +            }
   7.214 +            
   7.215 +            icon_rect.x = SDL_VideoSurface->w - 13;
   7.216 +            icon_rect.y = SDL_VideoSurface->h - 13;
   7.217 +            icon_rect.w = 13;
   7.218 +            icon_rect.h = 13;
   7.219 +            
   7.220 +            SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect);
   7.221 +        }
   7.222 +    }
   7.223 +}
   7.224 +
   7.225  static void QZ_UpdateRects (_THIS, int numRects, SDL_Rect *rects) {
   7.226  
   7.227      if (SDL_VideoSurface->flags & SDL_OPENGLBLIT) {
   7.228 @@ -1353,7 +1507,7 @@
   7.229   */
   7.230  
   7.231  /* Gamma functions */
   7.232 -static int QZ_SetGamma (_THIS, float red, float green, float blue) {
   7.233 +int QZ_SetGamma (_THIS, float red, float green, float blue) {
   7.234  
   7.235      const CGGammaValue min = 0.0, max = 1.0;
   7.236  
   7.237 @@ -1383,7 +1537,7 @@
   7.238      }
   7.239  }
   7.240  
   7.241 -static int QZ_GetGamma (_THIS, float *red, float *green, float *blue) {
   7.242 +int QZ_GetGamma (_THIS, float *red, float *green, float *blue) {
   7.243  
   7.244      CGGammaValue dummy;
   7.245      if ( CGDisplayNoErr == CGGetDisplayTransferByFormula
   7.246 @@ -1395,7 +1549,7 @@
   7.247          return -1;
   7.248  }
   7.249  
   7.250 -static int QZ_SetGammaRamp (_THIS, Uint16 *ramp) {
   7.251 +int QZ_SetGammaRamp (_THIS, Uint16 *ramp) {
   7.252  
   7.253      const CGTableCount tableSize = 255;
   7.254      CGGammaValue redTable[tableSize];
   7.255 @@ -1421,7 +1575,7 @@
   7.256          return -1;
   7.257  }
   7.258  
   7.259 -static int QZ_GetGammaRamp (_THIS, Uint16 *ramp) {
   7.260 +int QZ_GetGammaRamp (_THIS, Uint16 *ramp) {
   7.261  
   7.262      const CGTableCount tableSize = 255;
   7.263      CGGammaValue redTable[tableSize];
   7.264 @@ -1449,484 +1603,3 @@
   7.265      return 0;
   7.266  }
   7.267  
   7.268 -/* OpenGL helper functions (used internally) */
   7.269 -
   7.270 -static int QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags) {
   7.271 -
   7.272 -    NSOpenGLPixelFormatAttribute attr[32];
   7.273 -    NSOpenGLPixelFormat *fmt;
   7.274 -    int i = 0;
   7.275 -    int colorBits = bpp;
   7.276 -
   7.277 -    if ( flags & SDL_FULLSCREEN ) {
   7.278 -
   7.279 -        attr[i++] = NSOpenGLPFAFullScreen;
   7.280 -    }
   7.281 -    /* In windowed mode, the OpenGL pixel depth must match device pixel depth */
   7.282 -    else if ( colorBits != device_bpp ) {
   7.283 -
   7.284 -        colorBits = device_bpp;
   7.285 -    }
   7.286 -
   7.287 -    attr[i++] = NSOpenGLPFAColorSize;
   7.288 -    attr[i++] = colorBits;
   7.289 -
   7.290 -    attr[i++] = NSOpenGLPFADepthSize;
   7.291 -    attr[i++] = this->gl_config.depth_size;
   7.292 -
   7.293 -    if ( this->gl_config.double_buffer ) {
   7.294 -        attr[i++] = NSOpenGLPFADoubleBuffer;
   7.295 -    }
   7.296 -
   7.297 -    if ( this->gl_config.stereo ) {
   7.298 -        attr[i++] = NSOpenGLPFAStereo;
   7.299 -    }
   7.300 -
   7.301 -    if ( this->gl_config.stencil_size != 0 ) {
   7.302 -        attr[i++] = NSOpenGLPFAStencilSize;
   7.303 -        attr[i++] = this->gl_config.stencil_size;
   7.304 -    }
   7.305 -
   7.306 -#if NSOPENGL_CURRENT_VERSION > 1  /* What version should this be? */
   7.307 -    if ( this->gl_config.multisamplebuffers != 0 ) {
   7.308 -        attr[i++] = NSOpenGLPFASampleBuffers;
   7.309 -        attr[i++] = this->gl_config.multisamplebuffers;
   7.310 -    }
   7.311 -
   7.312 -    if ( this->gl_config.multisamplesamples != 0 ) {
   7.313 -        attr[i++] = NSOpenGLPFASamples;
   7.314 -        attr[i++] = this->gl_config.multisamplesamples;
   7.315 -    }
   7.316 -#endif
   7.317 -
   7.318 -    attr[i++] = NSOpenGLPFAScreenMask;
   7.319 -    attr[i++] = CGDisplayIDToOpenGLDisplayMask (display_id);
   7.320 -    attr[i] = 0;
   7.321 -
   7.322 -    fmt = [ [ NSOpenGLPixelFormat alloc ] initWithAttributes:attr ];
   7.323 -    if (fmt == nil) {
   7.324 -        SDL_SetError ("Failed creating OpenGL pixel format");
   7.325 -        return 0;
   7.326 -    }
   7.327 -
   7.328 -    gl_context = [ [ NSOpenGLContext alloc ] initWithFormat:fmt
   7.329 -                                               shareContext:nil];
   7.330 -
   7.331 -    if (gl_context == nil) {
   7.332 -        SDL_SetError ("Failed creating OpenGL context");
   7.333 -        return 0;
   7.334 -    }
   7.335 -
   7.336 -    /*
   7.337 -     * Wisdom from Apple engineer in reference to UT2003's OpenGL performance:
   7.338 -     *  "You are blowing a couple of the internal OpenGL function caches. This
   7.339 -     *  appears to be happening in the VAO case.  You can tell OpenGL to up
   7.340 -     *  the cache size by issuing the following calls right after you create
   7.341 -     *  the OpenGL context.  The default cache size is 16."    --ryan.
   7.342 -     */
   7.343 -
   7.344 -    #ifndef GLI_ARRAY_FUNC_CACHE_MAX
   7.345 -    #define GLI_ARRAY_FUNC_CACHE_MAX 284
   7.346 -    #endif
   7.347 -
   7.348 -    #ifndef GLI_SUBMIT_FUNC_CACHE_MAX
   7.349 -    #define GLI_SUBMIT_FUNC_CACHE_MAX 280
   7.350 -    #endif
   7.351 -
   7.352 -    {
   7.353 -        long cache_max = 64;
   7.354 -        CGLContextObj ctx = [ gl_context cglContext ];
   7.355 -        CGLSetParameter (ctx, GLI_SUBMIT_FUNC_CACHE_MAX, &cache_max);
   7.356 -        CGLSetParameter (ctx, GLI_ARRAY_FUNC_CACHE_MAX, &cache_max);
   7.357 -    }
   7.358 -
   7.359 -    /* End Wisdom from Apple Engineer section. --ryan. */
   7.360 -
   7.361 -    /* Convince SDL that the GL "driver" is loaded */
   7.362 -    this->gl_config.driver_loaded = 1;
   7.363 -
   7.364 -    [ fmt release ];
   7.365 -
   7.366 -    return 1;
   7.367 -}
   7.368 -
   7.369 -static void QZ_TearDownOpenGL (_THIS) {
   7.370 -
   7.371 -    [ NSOpenGLContext clearCurrentContext ];
   7.372 -    [ gl_context clearDrawable ];
   7.373 -    [ gl_context release ];
   7.374 -}
   7.375 -
   7.376 -
   7.377 -/* SDL OpenGL functions */
   7.378 -
   7.379 -static int    QZ_GL_LoadLibrary    (_THIS, const char *location) {
   7.380 -    this->gl_config.driver_loaded = 1;
   7.381 -    return 1;
   7.382 -}
   7.383 -
   7.384 -static void*  QZ_GL_GetProcAddress (_THIS, const char *proc) {
   7.385 -
   7.386 -    /* We may want to cache the bundleRef at some point */
   7.387 -    CFBundleRef bundle;
   7.388 -    CFURLRef bundleURL = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,
   7.389 -                                                        CFSTR("/System/Library/Frameworks/OpenGL.framework"), kCFURLPOSIXPathStyle, true);
   7.390 -
   7.391 -    CFStringRef functionName = CFStringCreateWithCString
   7.392 -        (kCFAllocatorDefault, proc, kCFStringEncodingASCII);
   7.393 -
   7.394 -    void *function;
   7.395 -
   7.396 -    bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL);
   7.397 -    assert (bundle != NULL);
   7.398 -
   7.399 -    function = CFBundleGetFunctionPointerForName (bundle, functionName);
   7.400 -
   7.401 -    CFRelease ( bundleURL );
   7.402 -    CFRelease ( functionName );
   7.403 -    CFRelease ( bundle );
   7.404 -
   7.405 -    return function;
   7.406 -}
   7.407 -
   7.408 -static int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value) {
   7.409 -
   7.410 -    GLenum attr = 0;
   7.411 -
   7.412 -    QZ_GL_MakeCurrent (this);
   7.413 -
   7.414 -    switch (attrib) {
   7.415 -        case SDL_GL_RED_SIZE: attr = GL_RED_BITS;   break;
   7.416 -        case SDL_GL_BLUE_SIZE: attr = GL_BLUE_BITS;  break;
   7.417 -        case SDL_GL_GREEN_SIZE: attr = GL_GREEN_BITS; break;
   7.418 -        case SDL_GL_ALPHA_SIZE: attr = GL_ALPHA_BITS; break;
   7.419 -        case SDL_GL_DOUBLEBUFFER: attr = GL_DOUBLEBUFFER; break;
   7.420 -        case SDL_GL_DEPTH_SIZE: attr = GL_DEPTH_BITS;  break;
   7.421 -        case SDL_GL_STENCIL_SIZE: attr = GL_STENCIL_BITS; break;
   7.422 -        case SDL_GL_ACCUM_RED_SIZE: attr = GL_ACCUM_RED_BITS; break;
   7.423 -        case SDL_GL_ACCUM_GREEN_SIZE: attr = GL_ACCUM_GREEN_BITS; break;
   7.424 -        case SDL_GL_ACCUM_BLUE_SIZE: attr = GL_ACCUM_BLUE_BITS; break;
   7.425 -        case SDL_GL_ACCUM_ALPHA_SIZE: attr = GL_ACCUM_ALPHA_BITS; break;
   7.426 -        case SDL_GL_STEREO: attr = GL_STEREO; break;
   7.427 -        case SDL_GL_MULTISAMPLEBUFFERS: attr = GL_SAMPLE_BUFFERS_ARB; break;
   7.428 -        case SDL_GL_MULTISAMPLESAMPLES: attr = GL_SAMPLES_ARB; break;
   7.429 -        case SDL_GL_BUFFER_SIZE:
   7.430 -        {
   7.431 -            GLint bits = 0;
   7.432 -            GLint component;
   7.433 -
   7.434 -            /* there doesn't seem to be a single flag in OpenGL for this! */
   7.435 -            glGetIntegerv (GL_RED_BITS, &component);   bits += component;
   7.436 -            glGetIntegerv (GL_GREEN_BITS,&component);  bits += component;
   7.437 -            glGetIntegerv (GL_BLUE_BITS, &component);  bits += component;
   7.438 -            glGetIntegerv (GL_ALPHA_BITS, &component); bits += component;
   7.439 -
   7.440 -            *value = bits;
   7.441 -        }
   7.442 -        return 0;
   7.443 -    }
   7.444 -
   7.445 -    glGetIntegerv (attr, (GLint *)value);
   7.446 -    return 0;
   7.447 -}
   7.448 -
   7.449 -static int    QZ_GL_MakeCurrent    (_THIS) {
   7.450 -    [ gl_context makeCurrentContext ];
   7.451 -    return 0;
   7.452 -}
   7.453 -
   7.454 -static void   QZ_GL_SwapBuffers    (_THIS) {
   7.455 -    [ gl_context flushBuffer ];
   7.456 -}
   7.457 -
   7.458 -static int QZ_LockYUV (_THIS, SDL_Overlay *overlay) {
   7.459 -
   7.460 -    return 0;
   7.461 -}
   7.462 -
   7.463 -static void QZ_UnlockYUV (_THIS, SDL_Overlay *overlay) {
   7.464 -
   7.465 -    ;
   7.466 -}
   7.467 -
   7.468 -static int QZ_DisplayYUV (_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) {
   7.469 -
   7.470 -    OSErr err;
   7.471 -    CodecFlags flags;
   7.472 -
   7.473 -    if (dstrect->x != 0 || dstrect->y != 0) {
   7.474 -
   7.475 -        SDL_SetError ("Need a dstrect at (0,0)");
   7.476 -        return -1;
   7.477 -    }
   7.478 -
   7.479 -    if (dstrect->w != yuv_width || dstrect->h != yuv_height) {
   7.480 -
   7.481 -        Fixed scale_x, scale_y;
   7.482 -
   7.483 -        scale_x = FixDiv ( Long2Fix (dstrect->w), Long2Fix (overlay->w) );
   7.484 -        scale_y = FixDiv ( Long2Fix (dstrect->h), Long2Fix (overlay->h) );
   7.485 -
   7.486 -        SetIdentityMatrix (yuv_matrix);
   7.487 -        ScaleMatrix (yuv_matrix, scale_x, scale_y, Long2Fix (0), Long2Fix (0));
   7.488 -
   7.489 -        SetDSequenceMatrix (yuv_seq, yuv_matrix);
   7.490 -
   7.491 -        yuv_width = dstrect->w;
   7.492 -        yuv_height = dstrect->h;
   7.493 -    }
   7.494 -
   7.495 -    if( ( err = DecompressSequenceFrameS(
   7.496 -                                         yuv_seq,
   7.497 -                                         (void*)yuv_pixmap,
   7.498 -                                         sizeof (PlanarPixmapInfoYUV420),
   7.499 -                                         codecFlagUseImageBuffer, &flags, nil ) != noErr ) )
   7.500 -    {
   7.501 -        SDL_SetError ("DecompressSequenceFrameS failed");
   7.502 -    }
   7.503 -
   7.504 -    return err == noErr;
   7.505 -}
   7.506 -
   7.507 -static void QZ_FreeHWYUV (_THIS, SDL_Overlay *overlay) {
   7.508 -
   7.509 -    CDSequenceEnd (yuv_seq);
   7.510 -    ExitMovies();
   7.511 -
   7.512 -    free (overlay->hwfuncs);
   7.513 -    free (overlay->pitches);
   7.514 -    free (overlay->pixels);
   7.515 -
   7.516 -    if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
   7.517 -        [ qz_window close ];
   7.518 -        qz_window = nil;
   7.519 -    }
   7.520 -
   7.521 -    free (yuv_matrix);
   7.522 -    DisposeHandle ((Handle)yuv_idh);
   7.523 -}
   7.524 -
   7.525 -#include "SDL_yuvfuncs.h"
   7.526 -
   7.527 -/* check for 16 byte alignment, bail otherwise */
   7.528 -#define CHECK_ALIGN(x) do { if ((Uint32)x & 15) { SDL_SetError("Alignment error"); return NULL; } } while(0)
   7.529 -
   7.530 -/* align a byte offset, return how much to add to make it a multiple of 16 */
   7.531 -#define ALIGN(x) ((16 - (x & 15)) & 15)
   7.532 -
   7.533 -static SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
   7.534 -                                         Uint32 format, SDL_Surface *display) {
   7.535 -
   7.536 -    Uint32 codec;
   7.537 -    OSStatus err;
   7.538 -    CGrafPtr port;
   7.539 -    SDL_Overlay *overlay;
   7.540 -
   7.541 -    if (format == SDL_YV12_OVERLAY ||
   7.542 -        format == SDL_IYUV_OVERLAY) {
   7.543 -
   7.544 -        codec = kYUV420CodecType;
   7.545 -    }
   7.546 -    else {
   7.547 -        SDL_SetError ("Hardware: unsupported video format");
   7.548 -        return NULL;
   7.549 -    }
   7.550 -
   7.551 -    yuv_idh = (ImageDescriptionHandle) NewHandleClear (sizeof(ImageDescription));
   7.552 -    if (yuv_idh == NULL) {
   7.553 -        SDL_OutOfMemory();
   7.554 -        return NULL;
   7.555 -    }
   7.556 -
   7.557 -    yuv_matrix = (MatrixRecordPtr) malloc (sizeof(MatrixRecord));
   7.558 -    if (yuv_matrix == NULL) {
   7.559 -        SDL_OutOfMemory();
   7.560 -        return NULL;
   7.561 -    }
   7.562 -
   7.563 -    if ( EnterMovies() != noErr ) {
   7.564 -        SDL_SetError ("Could not init QuickTime for YUV playback");
   7.565 -        return NULL;
   7.566 -    }
   7.567 -
   7.568 -    err = FindCodec (codec, bestSpeedCodec, nil, &yuv_codec);
   7.569 -    if (err != noErr) {
   7.570 -        SDL_SetError ("Could not find QuickTime codec for format");
   7.571 -        return NULL;
   7.572 -    }
   7.573 -
   7.574 -    if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
   7.575 -
   7.576 -        /*
   7.577 -          Acceleration requires a window to be present.
   7.578 -          A CGrafPtr that points to the screen isn't good enough
   7.579 -        */
   7.580 -        NSRect content = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
   7.581 -
   7.582 -        qz_window = [ [ SDL_QuartzWindow alloc ]
   7.583 -                            initWithContentRect:content
   7.584 -                            styleMask:NSBorderlessWindowMask
   7.585 -                            backing:NSBackingStoreBuffered defer:NO ];
   7.586 -
   7.587 -        if (qz_window == nil) {
   7.588 -            SDL_SetError ("Could not create the Cocoa window");
   7.589 -            return NULL;
   7.590 -        }
   7.591 -
   7.592 -        [ qz_window setContentView:[ [ SDL_QuartzWindowView alloc ] init ] ];
   7.593 -        [ qz_window setReleasedWhenClosed:YES ];
   7.594 -        [ qz_window center ];
   7.595 -        [ qz_window setAcceptsMouseMovedEvents:YES ];
   7.596 -        [ qz_window setLevel:CGShieldingWindowLevel() ];
   7.597 -        [ qz_window makeKeyAndOrderFront:nil ];
   7.598 -
   7.599 -        port = [ [ qz_window contentView ] qdPort ];
   7.600 -        SetPort (port);
   7.601 -        
   7.602 -        /*
   7.603 -            BUG: would like to remove white flash when window kicks in
   7.604 -            {
   7.605 -                Rect r;
   7.606 -                SetRect (&r, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
   7.607 -                PaintRect (&r);
   7.608 -                QDFlushPortBuffer (port, nil);
   7.609 -            }
   7.610 -        */
   7.611 -    }
   7.612 -    else {
   7.613 -        port = [ window_view qdPort ];
   7.614 -        SetPort (port);
   7.615 -    }
   7.616 -    
   7.617 -    SetIdentityMatrix (yuv_matrix);
   7.618 -    
   7.619 -    HLock ((Handle)yuv_idh);
   7.620 -    
   7.621 -    (**yuv_idh).idSize = sizeof(ImageDescription);
   7.622 -    (**yuv_idh).cType  = codec;
   7.623 -    (**yuv_idh).version = 1;
   7.624 -    (**yuv_idh).revisionLevel = 0;
   7.625 -    (**yuv_idh).width = width;
   7.626 -    (**yuv_idh).height = height;
   7.627 -    (**yuv_idh).hRes = Long2Fix(72);
   7.628 -    (**yuv_idh).vRes = Long2Fix(72);
   7.629 -    (**yuv_idh).spatialQuality = codecLosslessQuality;
   7.630 -    (**yuv_idh).frameCount = 1;
   7.631 -    (**yuv_idh).clutID = -1;
   7.632 -    (**yuv_idh).dataSize = 0;
   7.633 -    (**yuv_idh).depth = 24;
   7.634 -    
   7.635 -    HUnlock ((Handle)yuv_idh);
   7.636 -    
   7.637 -    err = DecompressSequenceBeginS (
   7.638 -                                    &yuv_seq,
   7.639 -                                    yuv_idh,
   7.640 -                                    NULL,
   7.641 -                                    0,
   7.642 -                                    port,
   7.643 -                                    NULL,
   7.644 -                                    NULL,
   7.645 -                                    yuv_matrix,
   7.646 -                                    0,
   7.647 -                                    NULL,
   7.648 -                                    codecFlagUseImageBuffer,
   7.649 -                                    codecLosslessQuality,
   7.650 -                                    yuv_codec);
   7.651 -    
   7.652 -    if (err != noErr) {
   7.653 -        SDL_SetError ("Error trying to start YUV codec.");
   7.654 -        return NULL;
   7.655 -    }
   7.656 -    
   7.657 -    overlay = (SDL_Overlay*) malloc (sizeof(*overlay));
   7.658 -    if (overlay == NULL) {
   7.659 -        SDL_OutOfMemory();
   7.660 -        return NULL;
   7.661 -    }
   7.662 -    
   7.663 -    overlay->format      = format;
   7.664 -    overlay->w           = width;
   7.665 -    overlay->h           = height;
   7.666 -    overlay->planes      = 3;
   7.667 -    overlay->hw_overlay  = 1;
   7.668 -    {
   7.669 -        int      offset;
   7.670 -        Uint8  **pixels;
   7.671 -        Uint16  *pitches;
   7.672 -        int      plane2, plane3;
   7.673 -
   7.674 -        if (format == SDL_IYUV_OVERLAY) {
   7.675 -
   7.676 -            plane2 = 1; /* Native codec format */
   7.677 -            plane3 = 2;
   7.678 -        }
   7.679 -        else if (format == SDL_YV12_OVERLAY) {
   7.680 -
   7.681 -            /* switch the U and V planes */
   7.682 -            plane2 = 2; /* U plane maps to plane 3 */
   7.683 -            plane3 = 1; /* V plane maps to plane 2 */
   7.684 -        }
   7.685 -        else {
   7.686 -            SDL_SetError("Unsupported YUV format");
   7.687 -            return NULL;
   7.688 -        }
   7.689 -
   7.690 -        pixels = (Uint8**) malloc (sizeof(*pixels) * 3);
   7.691 -        pitches = (Uint16*) malloc (sizeof(*pitches) * 3);
   7.692 -        if (pixels == NULL || pitches == NULL) {
   7.693 -            SDL_OutOfMemory();
   7.694 -            return NULL;
   7.695 -        }
   7.696 -
   7.697 -        yuv_pixmap = (PlanarPixmapInfoYUV420*)
   7.698 -            malloc (sizeof(PlanarPixmapInfoYUV420) +
   7.699 -                    (width * height * 2));
   7.700 -        if (yuv_pixmap == NULL) {
   7.701 -            SDL_OutOfMemory ();
   7.702 -            return NULL;
   7.703 -        }
   7.704 -
   7.705 -        /* CHECK_ALIGN(yuv_pixmap); */
   7.706 -        offset  = sizeof(PlanarPixmapInfoYUV420);
   7.707 -        /* offset += ALIGN(offset); */
   7.708 -        /* CHECK_ALIGN(offset); */
   7.709 -
   7.710 -        pixels[0] = (Uint8*)yuv_pixmap + offset;
   7.711 -        /* CHECK_ALIGN(pixels[0]); */
   7.712 -
   7.713 -        pitches[0] = width;
   7.714 -        yuv_pixmap->componentInfoY.offset = offset;
   7.715 -        yuv_pixmap->componentInfoY.rowBytes = width;
   7.716 -
   7.717 -        offset += width * height;
   7.718 -        pixels[plane2] = (Uint8*)yuv_pixmap + offset;
   7.719 -        pitches[plane2] = width / 2;
   7.720 -        yuv_pixmap->componentInfoCb.offset = offset;
   7.721 -        yuv_pixmap->componentInfoCb.rowBytes = width / 2;
   7.722 -
   7.723 -        offset += (width * height / 4);
   7.724 -        pixels[plane3] = (Uint8*)yuv_pixmap + offset;
   7.725 -        pitches[plane3] = width / 2;
   7.726 -        yuv_pixmap->componentInfoCr.offset = offset;
   7.727 -        yuv_pixmap->componentInfoCr.rowBytes = width / 2;
   7.728 -
   7.729 -        overlay->pixels = pixels;
   7.730 -        overlay->pitches = pitches;
   7.731 -    }
   7.732 -
   7.733 -    overlay->hwfuncs = malloc (sizeof(*overlay->hwfuncs));
   7.734 -    if (overlay->hwfuncs == NULL) {
   7.735 -        SDL_OutOfMemory();
   7.736 -        return NULL;
   7.737 -    }
   7.738 -    
   7.739 -    overlay->hwfuncs->Lock    = QZ_LockYUV;
   7.740 -    overlay->hwfuncs->Unlock  = QZ_UnlockYUV;
   7.741 -    overlay->hwfuncs->Display = QZ_DisplayYUV;
   7.742 -    overlay->hwfuncs->FreeHW  = QZ_FreeHWYUV;
   7.743 -
   7.744 -    yuv_width = overlay->w;
   7.745 -    yuv_height = overlay->h;
   7.746 -    
   7.747 -    return overlay;
   7.748 -}
     8.1 --- a/src/video/quartz/SDL_QuartzWM.m	Wed Dec 31 04:48:38 2003 +0000
     8.2 +++ b/src/video/quartz/SDL_QuartzWM.m	Sun Jan 04 14:55:35 2004 +0000
     8.3 @@ -1,6 +1,6 @@
     8.4  /*
     8.5      SDL - Simple DirectMedia Layer
     8.6 -    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
     8.7 +    Copyright (C) 1997-2003  Sam Lantinga
     8.8  
     8.9      This library is free software; you can redistribute it and/or
    8.10      modify it under the terms of the GNU Library General Public
    8.11 @@ -20,20 +20,21 @@
    8.12      slouken@libsdl.org
    8.13  */
    8.14  
    8.15 -static void QZ_ChangeGrabState (_THIS, int action);
    8.16 +#include "SDL_QuartzVideo.h"
    8.17 +
    8.18  
    8.19  struct WMcursor {
    8.20      Cursor curs;
    8.21  };
    8.22  
    8.23 -static void QZ_FreeWMCursor     (_THIS, WMcursor *cursor) { 
    8.24 +void QZ_FreeWMCursor     (_THIS, WMcursor *cursor) { 
    8.25  
    8.26      if ( cursor != NULL )
    8.27          free (cursor);
    8.28  }
    8.29  
    8.30  /* Use the Carbon cursor routines for now */
    8.31 -static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
    8.32 +WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
    8.33                                           int w, int h, int hot_x, int hot_y) { 
    8.34      WMcursor *cursor;
    8.35      int row, bytes;
    8.36 @@ -68,26 +69,34 @@
    8.37      return(cursor);
    8.38  }
    8.39  
    8.40 -static int QZ_ShowWMCursor (_THIS, WMcursor *cursor) { 
    8.41 +void QZ_ShowMouse (_THIS) {
    8.42 +    if (!cursor_visible) {
    8.43 +        [ NSCursor unhide ];
    8.44 +        cursor_visible = YES;
    8.45 +    }
    8.46 +}
    8.47 +
    8.48 +void QZ_HideMouse (_THIS) {
    8.49 +    if (cursor_visible) {
    8.50 +        [ NSCursor hide ];
    8.51 +        cursor_visible = NO;
    8.52 +    }
    8.53 +}
    8.54 +
    8.55 +int QZ_ShowWMCursor (_THIS, WMcursor *cursor) { 
    8.56  
    8.57      if ( cursor == NULL) {
    8.58 -        if ( cursor_visible ) {
    8.59 -            if (!cursor_hidden) {
    8.60 -                HideCursor ();
    8.61 -                cursor_hidden = YES;
    8.62 -            }
    8.63 -            cursor_visible = NO;
    8.64 +        if ( cursor_should_be_visible ) {
    8.65 +            QZ_HideMouse (this);
    8.66 +            cursor_should_be_visible = NO;
    8.67              QZ_ChangeGrabState (this, QZ_HIDECURSOR);
    8.68          }
    8.69      }
    8.70      else {
    8.71          SetCursor(&cursor->curs);
    8.72 -        if ( ! cursor_visible ) {
    8.73 -            if (cursor_hidden) {
    8.74 -                ShowCursor ();
    8.75 -                cursor_hidden = NO;
    8.76 -            }
    8.77 -            cursor_visible = YES;
    8.78 +        if ( ! cursor_should_be_visible ) {
    8.79 +            QZ_ShowMouse (this);
    8.80 +            cursor_should_be_visible = YES;
    8.81              QZ_ChangeGrabState (this, QZ_SHOWCURSOR);
    8.82          }
    8.83      }
    8.84 @@ -104,20 +113,20 @@
    8.85  */
    8.86  
    8.87  /* Convert Cocoa screen coordinate to Cocoa window coordinate */
    8.88 -static void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) {
    8.89 +void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) {
    8.90  
    8.91      *p = [ qz_window convertScreenToBase:*p ];
    8.92  }
    8.93  
    8.94  
    8.95  /* Convert Cocoa window coordinate to Cocoa screen coordinate */
    8.96 -static void QZ_PrivateLocalToGlobal (_THIS, NSPoint *p) {
    8.97 +void QZ_PrivateLocalToGlobal (_THIS, NSPoint *p) {
    8.98  
    8.99      *p = [ qz_window convertBaseToScreen:*p ];
   8.100  }
   8.101  
   8.102  /* Convert SDL coordinate to Cocoa coordinate */
   8.103 -static void QZ_PrivateSDLToCocoa (_THIS, NSPoint *p) {
   8.104 +void QZ_PrivateSDLToCocoa (_THIS, NSPoint *p) {
   8.105  
   8.106      if ( CGDisplayIsCaptured (display_id) ) { /* capture signals fullscreen */
   8.107      
   8.108 @@ -134,7 +143,7 @@
   8.109  }
   8.110  
   8.111  /* Convert Cocoa coordinate to SDL coordinate */
   8.112 -static void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p) {
   8.113 +void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p) {
   8.114  
   8.115      if ( CGDisplayIsCaptured (display_id) ) { /* capture signals fullscreen */
   8.116      
   8.117 @@ -151,7 +160,7 @@
   8.118  }
   8.119  
   8.120  /* Convert SDL coordinate to window server (CoreGraphics) coordinate */
   8.121 -static CGPoint QZ_PrivateSDLToCG (_THIS, NSPoint *p) {
   8.122 +CGPoint QZ_PrivateSDLToCG (_THIS, NSPoint *p) {
   8.123      
   8.124      CGPoint cgp;
   8.125      
   8.126 @@ -174,7 +183,7 @@
   8.127  
   8.128  #if 0 /* Dead code */
   8.129  /* Convert window server (CoreGraphics) coordinate to SDL coordinate */
   8.130 -static void QZ_PrivateCGToSDL (_THIS, NSPoint *p) {
   8.131 +void QZ_PrivateCGToSDL (_THIS, NSPoint *p) {
   8.132              
   8.133      if ( ! CGDisplayIsCaptured (display_id) ) { /* not captured => not fullscreen => local coord */
   8.134      
   8.135 @@ -190,7 +199,7 @@
   8.136  }
   8.137  #endif /* Dead code */
   8.138  
   8.139 -static void  QZ_PrivateWarpCursor (_THIS, int x, int y) {
   8.140 +void  QZ_PrivateWarpCursor (_THIS, int x, int y) {
   8.141      
   8.142      NSPoint p;
   8.143      CGPoint cgp;
   8.144 @@ -203,10 +212,10 @@
   8.145      CGWarpMouseCursorPosition (cgp);
   8.146  }
   8.147  
   8.148 -static void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
   8.149 +void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
   8.150  
   8.151      /* Only allow warping when in foreground */
   8.152 -    if ( ! in_foreground )
   8.153 +    if ( ! [ NSApp isActive ] )
   8.154          return;
   8.155              
   8.156      /* Do the actual warp */
   8.157 @@ -216,10 +225,10 @@
   8.158      SDL_PrivateMouseMotion (0, 0, x, y);
   8.159  }
   8.160  
   8.161 -static void QZ_MoveWMCursor     (_THIS, int x, int y) { }
   8.162 -static void QZ_CheckMouseMode   (_THIS) { }
   8.163 +void QZ_MoveWMCursor     (_THIS, int x, int y) { }
   8.164 +void QZ_CheckMouseMode   (_THIS) { }
   8.165  
   8.166 -static void QZ_SetCaption    (_THIS, const char *title, const char *icon) {
   8.167 +void QZ_SetCaption    (_THIS, const char *title, const char *icon) {
   8.168  
   8.169      if ( qz_window != nil ) {
   8.170          NSString *string;
   8.171 @@ -236,7 +245,7 @@
   8.172      }
   8.173  }
   8.174  
   8.175 -static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask)
   8.176 +void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask)
   8.177  {
   8.178      NSBitmapImageRep *imgrep;
   8.179      NSImage *img;
   8.180 @@ -305,7 +314,7 @@
   8.181      [pool release];
   8.182  }
   8.183  
   8.184 -static int  QZ_IconifyWindow (_THIS) { 
   8.185 +int  QZ_IconifyWindow (_THIS) { 
   8.186  
   8.187      if ( ! [ qz_window isMiniaturized ] ) {
   8.188          [ qz_window miniaturize:nil ];
   8.189 @@ -318,12 +327,12 @@
   8.190  }
   8.191  
   8.192  /*
   8.193 -static int  QZ_GetWMInfo  (_THIS, SDL_SysWMinfo *info) { 
   8.194 +int  QZ_GetWMInfo  (_THIS, SDL_SysWMinfo *info) { 
   8.195      info->nsWindowPtr = qz_window;
   8.196      return 0; 
   8.197  }*/
   8.198  
   8.199 -static void QZ_ChangeGrabState (_THIS, int action) {
   8.200 +void QZ_ChangeGrabState (_THIS, int action) {
   8.201  
   8.202      /* 
   8.203          Figure out what the next state should be based on the action.
   8.204 @@ -331,7 +340,7 @@
   8.205      */
   8.206      if ( grab_state == QZ_UNGRABBED ) {
   8.207          if ( action == QZ_ENABLE_GRAB ) {
   8.208 -            if ( cursor_visible )
   8.209 +            if ( cursor_should_be_visible )
   8.210                  grab_state = QZ_VISIBLE_GRAB;
   8.211              else
   8.212                  grab_state = QZ_INVISIBLE_GRAB;
   8.213 @@ -369,7 +378,7 @@
   8.214      }
   8.215  }
   8.216  
   8.217 -static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode) {
   8.218 +SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode) {
   8.219  
   8.220      int doGrab = grab_mode & SDL_GRAB_ON;
   8.221      /*int fullscreen = grab_mode & SDL_GRAB_FULLSCREEN;*/
   8.222 @@ -396,81 +405,3 @@
   8.223  
   8.224      return current_grab_mode;
   8.225  }
   8.226 -
   8.227 -/* Resize icon, BMP format */
   8.228 -static unsigned char QZ_ResizeIcon[] = {
   8.229 -    0x42,0x4d,0x31,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
   8.230 -    0x00,0x00,0x0d,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
   8.231 -    0x00,0x00,0xfb,0x01,0x00,0x00,0x13,0x0b,0x00,0x00,0x13,0x0b,0x00,0x00,0x00,0x00,
   8.232 -    0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   8.233 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   8.234 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
   8.235 -    0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,
   8.236 -    0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
   8.237 -    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xda,0xda,0xda,0x87,
   8.238 -    0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,
   8.239 -    0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
   8.240 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd5,0xd5,0xd5,0x87,0x87,0x87,0xe8,0xe8,0xe8,
   8.241 -    0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,
   8.242 -    0xda,0xda,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   8.243 -    0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,
   8.244 -    0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
   8.245 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,
   8.246 -    0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
   8.247 -    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   8.248 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,
   8.249 -    0xe8,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
   8.250 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   8.251 -    0xff,0xff,0xff,0xd9,0xd9,0xd9,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xdc,
   8.252 -    0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   8.253 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,
   8.254 -    0xdb,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
   8.255 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   8.256 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,0xdb,0x87,0x87,0x87,0xe8,
   8.257 -    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   8.258 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   8.259 -    0xff,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
   8.260 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   8.261 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdc,
   8.262 -    0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   8.263 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
   8.264 -    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b
   8.265 -};
   8.266 -
   8.267 -static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) {
   8.268 -
   8.269 -    /* Check if we should draw the resize icon */
   8.270 -    if (SDL_VideoSurface->flags & SDL_RESIZABLE) {
   8.271 -    
   8.272 -        Rect	icon;
   8.273 -        SetRect (&icon, SDL_VideoSurface->w - 13, SDL_VideoSurface->h - 13, 
   8.274 -                    SDL_VideoSurface->w, SDL_VideoSurface->h);
   8.275 -                    
   8.276 -        if (RectInRgn (&icon, dirtyRegion)) {
   8.277 -        
   8.278 -            SDL_Rect icon_rect;
   8.279 -            
   8.280 -            /* Create the icon image */
   8.281 -            if (resize_icon == NULL) {
   8.282 -            
   8.283 -                SDL_RWops *rw;
   8.284 -                SDL_Surface *tmp;
   8.285 -                
   8.286 -                rw = SDL_RWFromMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon));
   8.287 -                tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);
   8.288 -                                                                
   8.289 -                resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY);								
   8.290 -                SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF);
   8.291 -                
   8.292 -                SDL_FreeSurface (tmp);
   8.293 -            }
   8.294 -            
   8.295 -            icon_rect.x = SDL_VideoSurface->w - 13;
   8.296 -            icon_rect.y = SDL_VideoSurface->h - 13;
   8.297 -            icon_rect.w = 13;
   8.298 -            icon_rect.h = 13;
   8.299 -            
   8.300 -            SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect);
   8.301 -        }
   8.302 -    }
   8.303 -}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/video/quartz/SDL_QuartzWindow.h	Sun Jan 04 14:55:35 2004 +0000
     9.3 @@ -0,0 +1,38 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997-2003  Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Library General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Library General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Library General Public
    9.19 +    License along with this library; if not, write to the Free
    9.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@libsdl.org
    9.24 +*/
    9.25 +
    9.26 +/* Subclass of NSWindow to fix genie effect and support resize events  */
    9.27 +@interface SDL_QuartzWindow : NSWindow
    9.28 +- (void)miniaturize:(id)sender;
    9.29 +- (void)display;
    9.30 +- (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
    9.31 +- (void)appDidHide:(NSNotification*)note;
    9.32 +- (void)appWillUnhide:(NSNotification*)note;
    9.33 +- (void)appDidUnhide:(NSNotification*)note;
    9.34 +- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
    9.35 +@end
    9.36 +
    9.37 +/* Delegate for our NSWindow to send SDLQuit() on close */
    9.38 +@interface SDL_QuartzWindowDelegate : NSObject
    9.39 +- (BOOL)windowShouldClose:(id)sender;
    9.40 +@end
    9.41 +
    10.1 --- a/src/video/quartz/SDL_QuartzWindow.m	Wed Dec 31 04:48:38 2003 +0000
    10.2 +++ b/src/video/quartz/SDL_QuartzWindow.m	Sun Jan 04 14:55:35 2004 +0000
    10.3 @@ -1,3 +1,27 @@
    10.4 +/*
    10.5 +    SDL - Simple DirectMedia Layer
    10.6 +    Copyright (C) 1997-2003  Sam Lantinga
    10.7 +
    10.8 +    This library is free software; you can redistribute it and/or
    10.9 +    modify it under the terms of the GNU Library General Public
   10.10 +    License as published by the Free Software Foundation; either
   10.11 +    version 2 of the License, or (at your option) any later version.
   10.12 +
   10.13 +    This library is distributed in the hope that it will be useful,
   10.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10.16 +    Library General Public License for more details.
   10.17 +
   10.18 +    You should have received a copy of the GNU Library General Public
   10.19 +    License along with this library; if not, write to the Free
   10.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   10.21 +
   10.22 +    Sam Lantinga
   10.23 +    slouken@libsdl.org
   10.24 +*/
   10.25 +
   10.26 +#include "SDL_QuartzVideo.h"
   10.27 +#include "SDL_QuartzWindow.h"
   10.28  
   10.29  /*
   10.30      This function makes the *SDL region* of the window 100% opaque. 
   10.31 @@ -25,18 +49,6 @@
   10.32      }
   10.33  }
   10.34  
   10.35 -/* Subclass of NSWindow to fix genie effect and support resize events  */
   10.36 -@interface SDL_QuartzWindow : NSWindow
   10.37 -{}
   10.38 -- (void)miniaturize:(id)sender;
   10.39 -- (void)display;
   10.40 -- (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
   10.41 -- (void)appDidHide:(NSNotification*)note;
   10.42 -- (void)appWillUnhide:(NSNotification*)note;
   10.43 -- (void)appDidUnhide:(NSNotification*)note;
   10.44 -- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
   10.45 -@end
   10.46 -
   10.47  @implementation SDL_QuartzWindow
   10.48  
   10.49  /* we override these methods to fix the miniaturize animation/dock icon bug */
   10.50 @@ -186,12 +198,6 @@
   10.51  
   10.52  @end
   10.53  
   10.54 -/* Delegate for our NSWindow to send SDLQuit() on close */
   10.55 -@interface SDL_QuartzWindowDelegate : NSObject
   10.56 -{}
   10.57 -- (BOOL)windowShouldClose:(id)sender;
   10.58 -@end
   10.59 -
   10.60  @implementation SDL_QuartzWindowDelegate
   10.61  - (BOOL)windowShouldClose:(id)sender
   10.62  {
   10.63 @@ -199,11 +205,3 @@
   10.64      return NO;
   10.65  }
   10.66  @end
   10.67 -
   10.68 -/* Subclass of NSQuickDrawView for the window's subview */
   10.69 -@interface SDL_QuartzWindowView : NSQuickDrawView
   10.70 -{}
   10.71 -@end
   10.72 -
   10.73 -@implementation SDL_QuartzWindowView
   10.74 -@end
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/video/quartz/SDL_QuartzYUV.m	Sun Jan 04 14:55:35 2004 +0000
    11.3 @@ -0,0 +1,327 @@
    11.4 +/*
    11.5 +    SDL - Simple DirectMedia Layer
    11.6 +    Copyright (C) 1997-2003  Sam Lantinga
    11.7 +
    11.8 +    This library is free software; you can redistribute it and/or
    11.9 +    modify it under the terms of the GNU Library General Public
   11.10 +    License as published by the Free Software Foundation; either
   11.11 +    version 2 of the License, or (at your option) any later version.
   11.12 +
   11.13 +    This library is distributed in the hope that it will be useful,
   11.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.16 +    Library General Public License for more details.
   11.17 +
   11.18 +    You should have received a copy of the GNU Library General Public
   11.19 +    License along with this library; if not, write to the Free
   11.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   11.21 +
   11.22 +    Sam Lantinga
   11.23 +    slouken@libsdl.org
   11.24 +*/
   11.25 +
   11.26 +#include "SDL_QuartzVideo.h"
   11.27 +#include "SDL_QuartzWindow.h"
   11.28 +#include "SDL_yuvfuncs.h"
   11.29 +
   11.30 +
   11.31 +#define yuv_idh (this->hidden->yuv_idh)
   11.32 +#define yuv_matrix (this->hidden->yuv_matrix)
   11.33 +#define yuv_codec (this->hidden->yuv_codec)
   11.34 +#define yuv_seq (this->hidden->yuv_seq)
   11.35 +#define yuv_pixmap (this->hidden->yuv_pixmap)
   11.36 +#define yuv_data (this->hidden->yuv_data)
   11.37 +#define yuv_width (this->hidden->yuv_width)
   11.38 +#define yuv_height (this->hidden->yuv_height)
   11.39 +#define yuv_port (this->hidden->yuv_port)
   11.40 +
   11.41 +
   11.42 +static int QZ_LockYUV (_THIS, SDL_Overlay *overlay) {
   11.43 +
   11.44 +    return 0;
   11.45 +}
   11.46 +
   11.47 +static void QZ_UnlockYUV (_THIS, SDL_Overlay *overlay) {
   11.48 +
   11.49 +    ;
   11.50 +}
   11.51 +
   11.52 +static int QZ_DisplayYUV (_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) {
   11.53 +
   11.54 +    OSErr err;
   11.55 +    CodecFlags flags;
   11.56 +
   11.57 +    if (dstrect->x != 0 || dstrect->y != 0) {
   11.58 +
   11.59 +        SDL_SetError ("Need a dstrect at (0,0)");
   11.60 +        return -1;
   11.61 +    }
   11.62 +
   11.63 +    if (dstrect->w != yuv_width || dstrect->h != yuv_height) {
   11.64 +
   11.65 +        Fixed scale_x, scale_y;
   11.66 +
   11.67 +        scale_x = FixDiv ( Long2Fix (dstrect->w), Long2Fix (overlay->w) );
   11.68 +        scale_y = FixDiv ( Long2Fix (dstrect->h), Long2Fix (overlay->h) );
   11.69 +
   11.70 +        SetIdentityMatrix (yuv_matrix);
   11.71 +        ScaleMatrix (yuv_matrix, scale_x, scale_y, Long2Fix (0), Long2Fix (0));
   11.72 +
   11.73 +        SetDSequenceMatrix (yuv_seq, yuv_matrix);
   11.74 +
   11.75 +        yuv_width = dstrect->w;
   11.76 +        yuv_height = dstrect->h;
   11.77 +    }
   11.78 +
   11.79 +    if( ( err = DecompressSequenceFrameS(
   11.80 +                                         yuv_seq,
   11.81 +                                         (void*)yuv_pixmap,
   11.82 +                                         sizeof (PlanarPixmapInfoYUV420),
   11.83 +                                         codecFlagUseImageBuffer, &flags, nil ) != noErr ) )
   11.84 +    {
   11.85 +        SDL_SetError ("DecompressSequenceFrameS failed");
   11.86 +    }
   11.87 +
   11.88 +    return err == noErr;
   11.89 +}
   11.90 +
   11.91 +static void QZ_FreeHWYUV (_THIS, SDL_Overlay *overlay) {
   11.92 +
   11.93 +    CDSequenceEnd (yuv_seq);
   11.94 +    ExitMovies();
   11.95 +
   11.96 +    free (overlay->hwfuncs);
   11.97 +    free (overlay->pitches);
   11.98 +    free (overlay->pixels);
   11.99 +
  11.100 +    if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
  11.101 +        [ qz_window close ];
  11.102 +        qz_window = nil;
  11.103 +    }
  11.104 +
  11.105 +    free (yuv_matrix);
  11.106 +    DisposeHandle ((Handle)yuv_idh);
  11.107 +}
  11.108 +
  11.109 +/* check for 16 byte alignment, bail otherwise */
  11.110 +#define CHECK_ALIGN(x) do { if ((Uint32)x & 15) { SDL_SetError("Alignment error"); return NULL; } } while(0)
  11.111 +
  11.112 +/* align a byte offset, return how much to add to make it a multiple of 16 */
  11.113 +#define ALIGN(x) ((16 - (x & 15)) & 15)
  11.114 +
  11.115 +SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
  11.116 +                                         Uint32 format, SDL_Surface *display) {
  11.117 +
  11.118 +    Uint32 codec;
  11.119 +    OSStatus err;
  11.120 +    CGrafPtr port;
  11.121 +    SDL_Overlay *overlay;
  11.122 +
  11.123 +    if (format == SDL_YV12_OVERLAY ||
  11.124 +        format == SDL_IYUV_OVERLAY) {
  11.125 +
  11.126 +        codec = kYUV420CodecType;
  11.127 +    }
  11.128 +    else {
  11.129 +        SDL_SetError ("Hardware: unsupported video format");
  11.130 +        return NULL;
  11.131 +    }
  11.132 +
  11.133 +    yuv_idh = (ImageDescriptionHandle) NewHandleClear (sizeof(ImageDescription));
  11.134 +    if (yuv_idh == NULL) {
  11.135 +        SDL_OutOfMemory();
  11.136 +        return NULL;
  11.137 +    }
  11.138 +
  11.139 +    yuv_matrix = (MatrixRecordPtr) malloc (sizeof(MatrixRecord));
  11.140 +    if (yuv_matrix == NULL) {
  11.141 +        SDL_OutOfMemory();
  11.142 +        return NULL;
  11.143 +    }
  11.144 +
  11.145 +    if ( EnterMovies() != noErr ) {
  11.146 +        SDL_SetError ("Could not init QuickTime for YUV playback");
  11.147 +        return NULL;
  11.148 +    }
  11.149 +
  11.150 +    err = FindCodec (codec, bestSpeedCodec, nil, &yuv_codec);
  11.151 +    if (err != noErr) {
  11.152 +        SDL_SetError ("Could not find QuickTime codec for format");
  11.153 +        return NULL;
  11.154 +    }
  11.155 +
  11.156 +    if (SDL_VideoSurface->flags & SDL_FULLSCREEN) {
  11.157 +
  11.158 +        /*
  11.159 +          Acceleration requires a window to be present.
  11.160 +          A CGrafPtr that points to the screen isn't good enough
  11.161 +        */
  11.162 +        NSRect content = NSMakeRect (0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
  11.163 +
  11.164 +        qz_window = [ [ SDL_QuartzWindow alloc ]
  11.165 +                            initWithContentRect:content
  11.166 +                            styleMask:NSBorderlessWindowMask
  11.167 +                            backing:NSBackingStoreBuffered defer:NO ];
  11.168 +
  11.169 +        if (qz_window == nil) {
  11.170 +            SDL_SetError ("Could not create the Cocoa window");
  11.171 +            return NULL;
  11.172 +        }
  11.173 +
  11.174 +        [ qz_window setContentView:[ [ NSQuickDrawView alloc ] init ] ];
  11.175 +        [ qz_window setReleasedWhenClosed:YES ];
  11.176 +        [ qz_window center ];
  11.177 +        [ qz_window setAcceptsMouseMovedEvents:YES ];
  11.178 +        [ qz_window setLevel:CGShieldingWindowLevel() ];
  11.179 +        [ qz_window makeKeyAndOrderFront:nil ];
  11.180 +
  11.181 +        port = [ [ qz_window contentView ] qdPort ];
  11.182 +        SetPort (port);
  11.183 +        
  11.184 +        /*
  11.185 +            BUG: would like to remove white flash when window kicks in
  11.186 +            {
  11.187 +                Rect r;
  11.188 +                SetRect (&r, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h);
  11.189 +                PaintRect (&r);
  11.190 +                QDFlushPortBuffer (port, nil);
  11.191 +            }
  11.192 +        */
  11.193 +    }
  11.194 +    else {
  11.195 +        port = [ window_view qdPort ];
  11.196 +        SetPort (port);
  11.197 +    }
  11.198 +    
  11.199 +    SetIdentityMatrix (yuv_matrix);
  11.200 +    
  11.201 +    HLock ((Handle)yuv_idh);
  11.202 +    
  11.203 +    (**yuv_idh).idSize = sizeof(ImageDescription);
  11.204 +    (**yuv_idh).cType  = codec;
  11.205 +    (**yuv_idh).version = 1;
  11.206 +    (**yuv_idh).revisionLevel = 0;
  11.207 +    (**yuv_idh).width = width;
  11.208 +    (**yuv_idh).height = height;
  11.209 +    (**yuv_idh).hRes = Long2Fix(72);
  11.210 +    (**yuv_idh).vRes = Long2Fix(72);
  11.211 +    (**yuv_idh).spatialQuality = codecLosslessQuality;
  11.212 +    (**yuv_idh).frameCount = 1;
  11.213 +    (**yuv_idh).clutID = -1;
  11.214 +    (**yuv_idh).dataSize = 0;
  11.215 +    (**yuv_idh).depth = 24;
  11.216 +    
  11.217 +    HUnlock ((Handle)yuv_idh);
  11.218 +    
  11.219 +    err = DecompressSequenceBeginS (
  11.220 +                                    &yuv_seq,
  11.221 +                                    yuv_idh,
  11.222 +                                    NULL,
  11.223 +                                    0,
  11.224 +                                    port,
  11.225 +                                    NULL,
  11.226 +                                    NULL,
  11.227 +                                    yuv_matrix,
  11.228 +                                    0,
  11.229 +                                    NULL,
  11.230 +                                    codecFlagUseImageBuffer,
  11.231 +                                    codecLosslessQuality,
  11.232 +                                    yuv_codec);
  11.233 +    
  11.234 +    if (err != noErr) {
  11.235 +        SDL_SetError ("Error trying to start YUV codec.");
  11.236 +        return NULL;
  11.237 +    }
  11.238 +    
  11.239 +    overlay = (SDL_Overlay*) malloc (sizeof(*overlay));
  11.240 +    if (overlay == NULL) {
  11.241 +        SDL_OutOfMemory();
  11.242 +        return NULL;
  11.243 +    }
  11.244 +    
  11.245 +    overlay->format      = format;
  11.246 +    overlay->w           = width;
  11.247 +    overlay->h           = height;
  11.248 +    overlay->planes      = 3;
  11.249 +    overlay->hw_overlay  = 1;
  11.250 +    {
  11.251 +        int      offset;
  11.252 +        Uint8  **pixels;
  11.253 +        Uint16  *pitches;
  11.254 +        int      plane2, plane3;
  11.255 +
  11.256 +        if (format == SDL_IYUV_OVERLAY) {
  11.257 +
  11.258 +            plane2 = 1; /* Native codec format */
  11.259 +            plane3 = 2;
  11.260 +        }
  11.261 +        else if (format == SDL_YV12_OVERLAY) {
  11.262 +
  11.263 +            /* switch the U and V planes */
  11.264 +            plane2 = 2; /* U plane maps to plane 3 */
  11.265 +            plane3 = 1; /* V plane maps to plane 2 */
  11.266 +        }
  11.267 +        else {
  11.268 +            SDL_SetError("Unsupported YUV format");
  11.269 +            return NULL;
  11.270 +        }
  11.271 +
  11.272 +        pixels = (Uint8**) malloc (sizeof(*pixels) * 3);
  11.273 +        pitches = (Uint16*) malloc (sizeof(*pitches) * 3);
  11.274 +        if (pixels == NULL || pitches == NULL) {
  11.275 +            SDL_OutOfMemory();
  11.276 +            return NULL;
  11.277 +        }
  11.278 +
  11.279 +        yuv_pixmap = (PlanarPixmapInfoYUV420*)
  11.280 +            malloc (sizeof(PlanarPixmapInfoYUV420) +
  11.281 +                    (width * height * 2));
  11.282 +        if (yuv_pixmap == NULL) {
  11.283 +            SDL_OutOfMemory ();
  11.284 +            return NULL;
  11.285 +        }
  11.286 +
  11.287 +        /* CHECK_ALIGN(yuv_pixmap); */
  11.288 +        offset  = sizeof(PlanarPixmapInfoYUV420);
  11.289 +        /* offset += ALIGN(offset); */
  11.290 +        /* CHECK_ALIGN(offset); */
  11.291 +
  11.292 +        pixels[0] = (Uint8*)yuv_pixmap + offset;
  11.293 +        /* CHECK_ALIGN(pixels[0]); */
  11.294 +
  11.295 +        pitches[0] = width;
  11.296 +        yuv_pixmap->componentInfoY.offset = offset;
  11.297 +        yuv_pixmap->componentInfoY.rowBytes = width;
  11.298 +
  11.299 +        offset += width * height;
  11.300 +        pixels[plane2] = (Uint8*)yuv_pixmap + offset;
  11.301 +        pitches[plane2] = width / 2;
  11.302 +        yuv_pixmap->componentInfoCb.offset = offset;
  11.303 +        yuv_pixmap->componentInfoCb.rowBytes = width / 2;
  11.304 +
  11.305 +        offset += (width * height / 4);
  11.306 +        pixels[plane3] = (Uint8*)yuv_pixmap + offset;
  11.307 +        pitches[plane3] = width / 2;
  11.308 +        yuv_pixmap->componentInfoCr.offset = offset;
  11.309 +        yuv_pixmap->componentInfoCr.rowBytes = width / 2;
  11.310 +
  11.311 +        overlay->pixels = pixels;
  11.312 +        overlay->pitches = pitches;
  11.313 +    }
  11.314 +
  11.315 +    overlay->hwfuncs = malloc (sizeof(*overlay->hwfuncs));
  11.316 +    if (overlay->hwfuncs == NULL) {
  11.317 +        SDL_OutOfMemory();
  11.318 +        return NULL;
  11.319 +    }
  11.320 +    
  11.321 +    overlay->hwfuncs->Lock    = QZ_LockYUV;
  11.322 +    overlay->hwfuncs->Unlock  = QZ_UnlockYUV;
  11.323 +    overlay->hwfuncs->Display = QZ_DisplayYUV;
  11.324 +    overlay->hwfuncs->FreeHW  = QZ_FreeHWYUV;
  11.325 +
  11.326 +    yuv_width = overlay->w;
  11.327 +    yuv_height = overlay->h;
  11.328 +    
  11.329 +    return overlay;
  11.330 +}