src/video/quartz/SDL_QuartzVideo.h
author Sam Lantinga
Sun, 19 Aug 2001 23:57:39 +0000
changeset 155 2d162219f433
parent 58 bd6b0a910a65
child 158 4382c38dfbee
permissions -rw-r--r--
Date: Thu, 16 Aug 2001 21:50:51 -0500 (EST)
From: Darrell Walisser <dwaliss1@purdue.edu>
Subject: Patch for video bugs + Max's additions

I've attached a patch for today's CVS that includes Max's virtual
mouse button fix as well as some other changes:

-building mode list correctly now (had duplicate entries, was unsorted)
-switching modes correctly now (wasn't destroying previous mode)
-releasing memory correctly in event loop
slouken@47
     1
/*
slouken@47
     2
    SDL - Simple DirectMedia Layer
slouken@47
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
slouken@47
     4
slouken@47
     5
    This library is free software; you can redistribute it and/or
slouken@47
     6
    modify it under the terms of the GNU Library General Public
slouken@47
     7
    License as published by the Free Software Foundation; either
slouken@47
     8
    version 2 of the License, or (at your option) any later version.
slouken@47
     9
slouken@47
    10
    This library is distributed in the hope that it will be useful,
slouken@47
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@47
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@47
    13
    Library General Public License for more details.
slouken@47
    14
slouken@47
    15
    You should have received a copy of the GNU Library General Public
slouken@47
    16
    License along with this library; if not, write to the Free
slouken@47
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@47
    18
slouken@47
    19
    Sam Lantinga
slouken@47
    20
    slouken@devolution.com
slouken@47
    21
*/
slouken@47
    22
slouken@47
    23
/*	
slouken@47
    24
    @file   SDL_QuartzVideo.h
slouken@47
    25
    @author Darrell Walisser
slouken@47
    26
    
slouken@47
    27
    @abstract SDL video driver for MacOS X.
slouken@47
    28
    
slouken@47
    29
    @discussion
slouken@47
    30
    
slouken@47
    31
    TODO
slouken@47
    32
        - Hardware Cursor support with NSCursor instead of Carbon
slouken@47
    33
        - Keyboard repeat/mouse speed adjust (if needed)
slouken@47
    34
        - Multiple monitor support (currently only main display)
slouken@47
    35
        - Accelerated blitting support
slouken@47
    36
        - Set the window icon (dock icon when API is available)
slouken@47
    37
        - Avoid erasing window on minimize, or disable minimize
slouken@47
    38
    Problems:
slouken@47
    39
        - OGL not working in full screen with software renderer
slouken@47
    40
        - SetColors sets palette correctly but clears framebuffer
slouken@47
    41
        - Crash in CG after several mode switches
slouken@47
    42
        - Retained windows don't draw their title bar quite right (OS Bug)
slouken@58
    43
        - Should I do depth switching for windowed modes? - No, not usually.
slouken@47
    44
        - Launch times are slow, maybe prebinding will help
slouken@47
    45
        - Direct framebuffer access has some artifacts, maybe a driver issue
slouken@47
    46
        - Cursor in 8 bit modes is screwy
slouken@47
    47
        - Modifier + mouse-down maps alternate mouse button, but if modifier is released
slouken@47
    48
           before mouse button, corresponding mouse-up event is not generated.
slouken@47
    49
        - Clicking in content activates app, but doesn't generate the activate event,
slouken@47
    50
          and subsequent switches generate no activate/deactivate events! (OS Bug I hope)
slouken@47
    51
*/
slouken@47
    52
slouken@47
    53
#include <ApplicationServices/ApplicationServices.h>
slouken@47
    54
#include <OpenGL/OpenGL.h>
slouken@47
    55
#include <Cocoa/Cocoa.h>
slouken@47
    56
#include <Carbon/Carbon.h>
slouken@47
    57
slouken@47
    58
#include "SDL_video.h"
slouken@47
    59
#include "SDL_error.h"
slouken@47
    60
#include "SDL_syswm.h"
slouken@47
    61
#include "SDL_sysvideo.h"
slouken@47
    62
#include "SDL_pixels_c.h"
slouken@47
    63
#include "SDL_events_c.h"
slouken@47
    64
slouken@47
    65
/* This is a workaround to directly access NSOpenGLContext's CGL context */
slouken@47
    66
/* We need to do this in order to check for errors */
slouken@47
    67
@interface NSOpenGLContext (CGLContextAccess)
slouken@47
    68
- (CGLContextObj) cglContext;
slouken@47
    69
@end
slouken@47
    70
slouken@47
    71
@implementation NSOpenGLContext (CGLContextAccess)
slouken@47
    72
- (CGLContextObj) cglContext;
slouken@47
    73
{
slouken@47
    74
    return _contextAuxiliary;
slouken@47
    75
}
slouken@47
    76
@end
slouken@47
    77
slouken@47
    78
typedef struct SDL_PrivateVideoData {
slouken@47
    79
slouken@47
    80
    CGDirectDisplayID  display; /* 0 == main display */
slouken@47
    81
    CFDictionaryRef    mode;
slouken@47
    82
    CFDictionaryRef    save_mode;
slouken@47
    83
    CFArrayRef         mode_list;
slouken@47
    84
    CGDirectPaletteRef palette;
slouken@47
    85
    NSOpenGLContext    *gl_context;
slouken@155
    86
    Uint32             width, height, bpp;
slouken@47
    87
    Uint32             flags;
slouken@155
    88
    SDL_bool           video_is_set; /* tell if the video mode was set */
slouken@47
    89
    
slouken@47
    90
    /* Window-only fields */
slouken@47
    91
    NSWindow        *window;
slouken@47
    92
    NSQuickDrawView *view;
slouken@47
    93
    
slouken@47
    94
} SDL_PrivateVideoData ;
slouken@47
    95
slouken@47
    96
#define _THIS	SDL_VideoDevice *this
slouken@47
    97
#define display_id (this->hidden->display)
slouken@47
    98
#define mode (this->hidden->mode)
slouken@47
    99
#define save_mode (this->hidden->save_mode)
slouken@47
   100
#define mode_list (this->hidden->mode_list)
slouken@47
   101
#define palette (this->hidden->palette)
slouken@47
   102
#define glcontext (this->hidden->glcontext)
slouken@47
   103
#define objc_video (this->hidden->objc_video)
slouken@47
   104
#define gl_context (this->hidden->gl_context)
slouken@47
   105
#define device_width (this->hidden->width)
slouken@47
   106
#define device_height (this->hidden->height)
slouken@47
   107
#define device_bpp (this->hidden->bpp)
slouken@47
   108
#define mode_flags (this->hidden->flags)
slouken@155
   109
#define video_set (this->hidden->video_is_set)
slouken@47
   110
#define window (this->hidden->window)
slouken@47
   111
#define windowView (this->hidden->view)
slouken@47
   112
slouken@47
   113
/* Interface for hardware fill not (yet) in the public API */
slouken@47
   114
int CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y, 
slouken@47
   115
                      unsigned int w, unsigned int h, unsigned int color);
slouken@47
   116
int CGSDisplayCanHWFill (CGDirectDisplayID id);
slouken@47
   117
slouken@47
   118
/* Bootstrap functions */
slouken@47
   119
static int              QZ_Available ();
slouken@47
   120
static SDL_VideoDevice* QZ_CreateDevice (int device_index);
slouken@47
   121
static void             QZ_DeleteDevice (SDL_VideoDevice *device);
slouken@47
   122
slouken@47
   123
/* Initialization, Query, Setup, and Redrawing functions */
slouken@47
   124
static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
slouken@47
   125
slouken@47
   126
static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format, 
slouken@47
   127
					 Uint32 flags);
slouken@47
   128
static void         QZ_UnsetVideoMode   (_THIS);
slouken@47
   129
slouken@47
   130
static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current, 
slouken@47
   131
					 int width, int height, int bpp, 
slouken@47
   132
					 Uint32 flags);
slouken@47
   133
static int          QZ_ToggleFullScreen (_THIS, int on);
slouken@47
   134
static int          QZ_SetColors        (_THIS, int first_color, 
slouken@47
   135
					 int num_colors, SDL_Color *colors);
slouken@47
   136
static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
slouken@47
   137
static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
slouken@47
   138
static void         QZ_VideoQuit        (_THIS);
slouken@47
   139
slouken@47
   140
/* Hardware surface functions (for fullscreen mode only) */
slouken@47
   141
static int  QZ_FillHWRect (_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
slouken@47
   142
static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface);
slouken@47
   143
static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
slouken@47
   144
static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
slouken@47
   145
/* static int  QZ_FlipHWSurface (_THIS, SDL_Surface *surface); */
slouken@47
   146
slouken@47
   147
/* Gamma Functions */
slouken@47
   148
static int QZ_SetGamma     (_THIS, float red, float green, float blue);
slouken@47
   149
static int QZ_GetGamma     (_THIS, float *red, float *green, float *blue);
slouken@47
   150
static int QZ_SetGammaRamp (_THIS, Uint16 *ramp);
slouken@47
   151
static int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
slouken@47
   152
slouken@47
   153
/* OpenGL functions */
slouken@47
   154
static int    QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags);
slouken@47
   155
static void   QZ_TearDownOpenGL (_THIS);
slouken@47
   156
static void*  QZ_GL_GetProcAddress (_THIS, const char *proc);
slouken@47
   157
static int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value);
slouken@47
   158
static int    QZ_GL_MakeCurrent    (_THIS);
slouken@47
   159
static void   QZ_GL_SwapBuffers    (_THIS);
slouken@47
   160
static int    QZ_GL_LoadLibrary    (_THIS, const char *location);
slouken@47
   161
slouken@47
   162
/* Private function to warp the cursor (used internally) */
slouken@47
   163
static void  QZ_PrivateWarpCursor (_THIS, int fullscreen, int h, int x, int y);
slouken@47
   164
slouken@47
   165
/* Cursor and Mouse functions */
slouken@47
   166
static void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
slouken@47
   167
static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
slouken@47
   168
                                          int w, int h, int hot_x, int hot_y);
slouken@47
   169
static int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
slouken@47
   170
static void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
slouken@47
   171
static void         QZ_MoveWMCursor     (_THIS, int x, int y);
slouken@47
   172
static void         QZ_CheckMouseMode   (_THIS);
slouken@47
   173
slouken@47
   174
/* Event functions */
slouken@47
   175
static void         QZ_InitOSKeymap     (_THIS);
slouken@47
   176
static void         QZ_PumpEvents       (_THIS);
slouken@47
   177
slouken@47
   178
/* Window Manager functions */
slouken@47
   179
static void QZ_SetCaption    (_THIS, const char *title, const char *icon);
slouken@47
   180
static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask);
slouken@47
   181
static int  QZ_IconifyWindow (_THIS);
slouken@47
   182
static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
slouken@47
   183
/*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/