src/video/quartz/SDL_QuartzVideo.h
changeset 390 19e73568a75c
parent 297 f6ffac90895c
child 435 140798e1e7a6
equal deleted inserted replaced
389:ca655a7a9d80 390:19e73568a75c
    18 
    18 
    19     Sam Lantinga
    19     Sam Lantinga
    20     slouken@libsdl.org
    20     slouken@libsdl.org
    21 */
    21 */
    22 
    22 
    23 /*	
    23 /*    
    24     @file   SDL_QuartzVideo.h
    24     @file   SDL_QuartzVideo.h
    25     @author Darrell Walisser
    25     @author Darrell Walisser
    26     
    26     
    27     @abstract SDL video driver for MacOS X.
    27     @abstract SDL video driver for MacOS X.
    28     
    28     
    31     TODO
    31     TODO
    32         - Hardware Cursor support with NSCursor instead of Carbon
    32         - Hardware Cursor support with NSCursor instead of Carbon
    33         - Keyboard repeat/mouse speed adjust (if needed)
    33         - Keyboard repeat/mouse speed adjust (if needed)
    34         - Multiple monitor support (currently only main display)
    34         - Multiple monitor support (currently only main display)
    35         - Accelerated blitting support
    35         - Accelerated blitting support
    36         - Set the window icon (dock icon when API is available)
    36         - Fix white OpenGL window on minimize (fixed)
    37         - Fix white OpenGL window on minimize
       
    38         - Find out what events should be sent/ignored if window is mimimized
    37         - Find out what events should be sent/ignored if window is mimimized
    39         - Find a better way to deal with resolution/depth switch while app is running
    38         - Find a way to deal with external resolution/depth switch while app is running
    40         - Resizeable windows
    39         - Resizeable windows
    41         - Check accuracy of QZ_SetGamma()
    40         - Check accuracy of QZ_SetGamma()
    42     Problems:
    41     Problems:
    43         - OGL not working in full screen with software renderer
    42         - OGL not working in full screen with software renderer
    44         - SetColors sets palette correctly but clears framebuffer
    43         - SetColors sets palette correctly but clears framebuffer
    45         - Crash in CG after several mode switches
    44         - Crash in CG after several mode switches (I think this has been fixed)
    46         - Retained windows don't draw their title bar quite right (OS Bug) (not using retained windows)
    45         - Retained windows don't draw their title bar quite right (OS Bug) (not using retained windows)
    47         - Cursor in 8 bit modes is screwy (might just be Radeon PCI bug)
    46         - Cursor in 8 bit modes is screwy (might just be Radeon PCI bug)
    48         - Warping cursor delays mouse events for a fraction of a second,
    47         - Warping cursor delays mouse events for a fraction of a second,
    49           there is a hack around this that helps a bit
    48           there is a hack around this that helps a bit
    50 */
    49 */
    51 
    50 
    52 #include <Cocoa/Cocoa.h>
    51 #include <Cocoa/Cocoa.h>
    53 #include <OpenGL/OpenGL.h>
    52 #include <OpenGL/OpenGL.h>
    54 #include <Carbon/Carbon.h>
    53 #include <Carbon/Carbon.h>
       
    54 #include <QuickTime/QuickTime.h>
    55 
    55 
    56 #include "SDL_video.h"
    56 #include "SDL_video.h"
    57 #include "SDL_error.h"
    57 #include "SDL_error.h"
    58 #include "SDL_timer.h"
    58 #include "SDL_timer.h"
    59 #include "SDL_syswm.h"
    59 #include "SDL_syswm.h"
   100     Uint32             video_set;          /* boolean; indicates if video was set correctly */
   100     Uint32             video_set;          /* boolean; indicates if video was set correctly */
   101     Uint32             warp_flag;          /* boolean; notify to event loop that a warp just occured */
   101     Uint32             warp_flag;          /* boolean; notify to event loop that a warp just occured */
   102     Uint32             warp_ticks;         /* timestamp when the warp occured */
   102     Uint32             warp_ticks;         /* timestamp when the warp occured */
   103     NSWindow           *window;            /* Cocoa window to implement the SDL window */
   103     NSWindow           *window;            /* Cocoa window to implement the SDL window */
   104     NSQuickDrawView    *view;              /* the window's view; draw 2D into this view */
   104     NSQuickDrawView    *view;              /* the window's view; draw 2D into this view */
   105     
   105     ImageDescriptionHandle yuv_idh;
       
   106     MatrixRecordPtr        yuv_matrix;
       
   107     DecompressorComponent  yuv_codec;
       
   108     ImageSequence          yuv_seq;
       
   109     PlanarPixmapInfoYUV420 *yuv_pixmap;
       
   110     Sint16                  yuv_width, yuv_height;
       
   111     CGrafPtr                yuv_port;
       
   112 
   106 } SDL_PrivateVideoData ;
   113 } SDL_PrivateVideoData ;
   107 
   114 
   108 #define _THIS	SDL_VideoDevice *this
   115 #define _THIS    SDL_VideoDevice *this
   109 #define display_id (this->hidden->display)
   116 #define display_id (this->hidden->display)
   110 #define mode (this->hidden->mode)
   117 #define mode (this->hidden->mode)
   111 #define save_mode (this->hidden->save_mode)
   118 #define save_mode (this->hidden->save_mode)
   112 #define mode_list (this->hidden->mode_list)
   119 #define mode_list (this->hidden->mode_list)
   113 #define palette (this->hidden->palette)
   120 #define palette (this->hidden->palette)
   119 #define qz_window (this->hidden->window)
   126 #define qz_window (this->hidden->window)
   120 #define window_view (this->hidden->view)
   127 #define window_view (this->hidden->view)
   121 #define video_set (this->hidden->video_set)
   128 #define video_set (this->hidden->video_set)
   122 #define warp_ticks (this->hidden->warp_ticks)
   129 #define warp_ticks (this->hidden->warp_ticks)
   123 #define warp_flag (this->hidden->warp_flag)
   130 #define warp_flag (this->hidden->warp_flag)
       
   131 #define yuv_idh (this->hidden->yuv_idh)
       
   132 #define yuv_matrix (this->hidden->yuv_matrix)
       
   133 #define yuv_codec (this->hidden->yuv_codec)
       
   134 #define yuv_seq (this->hidden->yuv_seq)
       
   135 #define yuv_pixmap (this->hidden->yuv_pixmap)
       
   136 #define yuv_data (this->hidden->yuv_data)
       
   137 #define yuv_width (this->hidden->yuv_width)
       
   138 #define yuv_height (this->hidden->yuv_height)
       
   139 #define yuv_port (this->hidden->yuv_port)
   124 
   140 
   125 /* Obscuring code: maximum number of windows above ours (inclusive) */
   141 /* Obscuring code: maximum number of windows above ours (inclusive) */
   126 #define kMaxWindows 256
   142 #define kMaxWindows 256
   127 
   143 
   128 /* Some of the Core Graphics Server API for obscuring code */
   144 /* Some of the Core Graphics Server API for obscuring code */
   142 #define kCGSWindowLevelDesktopPicture -2147483647
   158 #define kCGSWindowLevelDesktopPicture -2147483647
   143 #define kCGSWindowLevelDesktop        -2147483648
   159 #define kCGSWindowLevelDesktop        -2147483648
   144 */
   160 */
   145 
   161 
   146 typedef CGError       CGSError;
   162 typedef CGError       CGSError;
   147 typedef long	      CGSWindowCount;
   163 typedef long          CGSWindowCount;
   148 typedef void *	      CGSConnectionID;
   164 typedef void *        CGSConnectionID;
   149 typedef int	      CGSWindowID;
   165 typedef int           CGSWindowID;
   150 typedef CGSWindowID*  CGSWindowIDList;
   166 typedef CGSWindowID*  CGSWindowIDList;
   151 typedef CGWindowLevel CGSWindowLevel;
   167 typedef CGWindowLevel CGSWindowLevel;
   152 typedef NSRect        CGSRect;
   168 typedef NSRect        CGSRect;
   153 
   169 
   154 extern CGSConnectionID _CGSDefaultConnection ();
   170 extern CGSConnectionID _CGSDefaultConnection ();
   155 
   171 
   156 extern CGSError CGSGetOnScreenWindowList (CGSConnectionID cid, 
   172 extern CGSError CGSGetOnScreenWindowList (CGSConnectionID cid,
   157                                           CGSConnectionID owner,
   173                                           CGSConnectionID owner,
   158                                           CGSWindowCount listCapacity,
   174                                           CGSWindowCount listCapacity,
   159                                           CGSWindowIDList list,
   175                                           CGSWindowIDList list,
   160                                           CGSWindowCount *listCount);
   176                                           CGSWindowCount *listCount);
   161 
   177 
   164                                            CGSRect *rect);
   180                                            CGSRect *rect);
   165 
   181 
   166 extern CGWindowLevel CGSGetWindowLevel (CGSConnectionID cid,
   182 extern CGWindowLevel CGSGetWindowLevel (CGSConnectionID cid,
   167                                         CGSWindowID wid,
   183                                         CGSWindowID wid,
   168                                         CGSWindowLevel *level);
   184                                         CGSWindowLevel *level);
   169                                         
   185 
   170 extern CGSError CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y, 
   186 extern CGSError CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y,
   171                       unsigned int w, unsigned int h, unsigned int color);
   187                                   unsigned int w, unsigned int h, unsigned int color);
   172 
   188 
   173 extern CGSError CGSDisplayCanHWFill (CGDirectDisplayID id);
   189 extern CGSError CGSDisplayCanHWFill (CGDirectDisplayID id);
   174 
   190 
   175 extern CGSError CGSGetMouseEnabledFlags (CGSConnectionID cid, CGSWindowID wid, int *flags);
   191 extern CGSError CGSGetMouseEnabledFlags (CGSConnectionID cid, CGSWindowID wid, int *flags);
   176 
   192 
   180 static void             QZ_DeleteDevice (SDL_VideoDevice *device);
   196 static void             QZ_DeleteDevice (SDL_VideoDevice *device);
   181 
   197 
   182 /* Initialization, Query, Setup, and Redrawing functions */
   198 /* Initialization, Query, Setup, and Redrawing functions */
   183 static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
   199 static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
   184 
   200 
   185 static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format, 
   201 static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format,
   186 					 Uint32 flags);
   202                                          Uint32 flags);
   187 static void         QZ_UnsetVideoMode   (_THIS);
   203 static void         QZ_UnsetVideoMode   (_THIS);
   188 
   204 
   189 static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current, 
   205 static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current,
   190 					 int width, int height, int bpp, 
   206                                          int width, int height, int bpp,
   191 					 Uint32 flags);
   207                                          Uint32 flags);
   192 static int          QZ_ToggleFullScreen (_THIS, int on);
   208 static int          QZ_ToggleFullScreen (_THIS, int on);
   193 static int          QZ_SetColors        (_THIS, int first_color, 
   209 static int          QZ_SetColors        (_THIS, int first_color,
   194 					 int num_colors, SDL_Color *colors);
   210                                          int num_colors, SDL_Color *colors);
   195 static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
   211 static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
   196 static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
   212 static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
   197 static void         QZ_VideoQuit        (_THIS);
   213 static void         QZ_VideoQuit        (_THIS);
   198 
   214 
   199 /* Hardware surface functions (for fullscreen mode only) */
   215 /* Hardware surface functions (for fullscreen mode only) */
   221 /* Private function to warp the cursor (used internally) */
   237 /* Private function to warp the cursor (used internally) */
   222 static void  QZ_PrivateWarpCursor (_THIS, int x, int y);
   238 static void  QZ_PrivateWarpCursor (_THIS, int x, int y);
   223 
   239 
   224 /* Cursor and Mouse functions */
   240 /* Cursor and Mouse functions */
   225 static void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
   241 static void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
   226 static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
   242 static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask,
   227                                           int w, int h, int hot_x, int hot_y);
   243                                          int w, int h, int hot_x, int hot_y);
   228 static int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
   244 static int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
   229 static void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
   245 static void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
   230 static void         QZ_MoveWMCursor     (_THIS, int x, int y);
   246 static void         QZ_MoveWMCursor     (_THIS, int x, int y);
   231 static void         QZ_CheckMouseMode   (_THIS);
   247 static void         QZ_CheckMouseMode   (_THIS);
   232 
   248 
   239 static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask);
   255 static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask);
   240 static int  QZ_IconifyWindow (_THIS);
   256 static int  QZ_IconifyWindow (_THIS);
   241 static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
   257 static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
   242 /*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/
   258 /*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/
   243 
   259 
       
   260 /* YUV functions */
       
   261 static SDL_Overlay* QZ_CreateYUVOverlay (_THIS, int width, int height,
       
   262                                          Uint32 format, SDL_Surface *display);
       
   263