src/video/quartz/SDL_QuartzVideo.h
author Sam Lantinga
Tue, 21 Aug 2001 07:19:59 +0000
changeset 158 4382c38dfbee
parent 155 2d162219f433
child 252 e8157fcb3114
permissions -rw-r--r--
Date: Tue, 21 Aug 2001 03:50:01 +0200
From: Max Horn <max@quendi.de>
Subject: New patch for OS X

Attached a .patch file for SDL/OSX with some nice bug fixes / enhancments.

* fixes the activation issues, which also caused the window to be
always drawn like an inactive. The close/minimize widgets now are
animated properly, too.

* the menu items are automatically adjusted to use the app name
instead of just "SDL App". I did this so that we really can use one
central SDLMain.nib file, w/o requiring developers to make a copy of
it and adjust it.

* libSDLMain now contains the proper cocoa code, not as before the
carbon code. This means apps no longer have to carry a copy of
SDLMain.m/SDLMain.h

* revamped configure.in to properly build a Cocoa/Quartz SDL lib, not
a Carbon based SDL lib
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
*/
slouken@47
    48
slouken@47
    49
#include <ApplicationServices/ApplicationServices.h>
slouken@47
    50
#include <OpenGL/OpenGL.h>
slouken@47
    51
#include <Cocoa/Cocoa.h>
slouken@47
    52
#include <Carbon/Carbon.h>
slouken@47
    53
slouken@47
    54
#include "SDL_video.h"
slouken@47
    55
#include "SDL_error.h"
slouken@47
    56
#include "SDL_syswm.h"
slouken@47
    57
#include "SDL_sysvideo.h"
slouken@47
    58
#include "SDL_pixels_c.h"
slouken@47
    59
#include "SDL_events_c.h"
slouken@47
    60
slouken@47
    61
/* This is a workaround to directly access NSOpenGLContext's CGL context */
slouken@47
    62
/* We need to do this in order to check for errors */
slouken@47
    63
@interface NSOpenGLContext (CGLContextAccess)
slouken@47
    64
- (CGLContextObj) cglContext;
slouken@47
    65
@end
slouken@47
    66
slouken@47
    67
@implementation NSOpenGLContext (CGLContextAccess)
slouken@47
    68
- (CGLContextObj) cglContext;
slouken@47
    69
{
slouken@47
    70
    return _contextAuxiliary;
slouken@47
    71
}
slouken@47
    72
@end
slouken@47
    73
slouken@47
    74
typedef struct SDL_PrivateVideoData {
slouken@47
    75
slouken@47
    76
    CGDirectDisplayID  display; /* 0 == main display */
slouken@47
    77
    CFDictionaryRef    mode;
slouken@47
    78
    CFDictionaryRef    save_mode;
slouken@47
    79
    CFArrayRef         mode_list;
slouken@47
    80
    CGDirectPaletteRef palette;
slouken@47
    81
    NSOpenGLContext    *gl_context;
slouken@155
    82
    Uint32             width, height, bpp;
slouken@47
    83
    Uint32             flags;
slouken@155
    84
    SDL_bool           video_is_set; /* tell if the video mode was set */
slouken@47
    85
    
slouken@47
    86
    /* Window-only fields */
slouken@47
    87
    NSWindow        *window;
slouken@47
    88
    NSQuickDrawView *view;
slouken@47
    89
    
slouken@47
    90
} SDL_PrivateVideoData ;
slouken@47
    91
slouken@47
    92
#define _THIS	SDL_VideoDevice *this
slouken@47
    93
#define display_id (this->hidden->display)
slouken@47
    94
#define mode (this->hidden->mode)
slouken@47
    95
#define save_mode (this->hidden->save_mode)
slouken@47
    96
#define mode_list (this->hidden->mode_list)
slouken@47
    97
#define palette (this->hidden->palette)
slouken@47
    98
#define glcontext (this->hidden->glcontext)
slouken@47
    99
#define objc_video (this->hidden->objc_video)
slouken@47
   100
#define gl_context (this->hidden->gl_context)
slouken@47
   101
#define device_width (this->hidden->width)
slouken@47
   102
#define device_height (this->hidden->height)
slouken@47
   103
#define device_bpp (this->hidden->bpp)
slouken@47
   104
#define mode_flags (this->hidden->flags)
slouken@155
   105
#define video_set (this->hidden->video_is_set)
slouken@158
   106
#define qz_window (this->hidden->window)
slouken@47
   107
#define windowView (this->hidden->view)
slouken@47
   108
slouken@47
   109
/* Interface for hardware fill not (yet) in the public API */
slouken@47
   110
int CGSDisplayHWFill (CGDirectDisplayID id, unsigned int x, unsigned int y, 
slouken@47
   111
                      unsigned int w, unsigned int h, unsigned int color);
slouken@47
   112
int CGSDisplayCanHWFill (CGDirectDisplayID id);
slouken@47
   113
slouken@47
   114
/* Bootstrap functions */
slouken@47
   115
static int              QZ_Available ();
slouken@47
   116
static SDL_VideoDevice* QZ_CreateDevice (int device_index);
slouken@47
   117
static void             QZ_DeleteDevice (SDL_VideoDevice *device);
slouken@47
   118
slouken@47
   119
/* Initialization, Query, Setup, and Redrawing functions */
slouken@47
   120
static int          QZ_VideoInit        (_THIS, SDL_PixelFormat *video_format);
slouken@47
   121
slouken@47
   122
static SDL_Rect**   QZ_ListModes        (_THIS, SDL_PixelFormat *format, 
slouken@47
   123
					 Uint32 flags);
slouken@47
   124
static void         QZ_UnsetVideoMode   (_THIS);
slouken@47
   125
slouken@47
   126
static SDL_Surface* QZ_SetVideoMode     (_THIS, SDL_Surface *current, 
slouken@47
   127
					 int width, int height, int bpp, 
slouken@47
   128
					 Uint32 flags);
slouken@47
   129
static int          QZ_ToggleFullScreen (_THIS, int on);
slouken@47
   130
static int          QZ_SetColors        (_THIS, int first_color, 
slouken@47
   131
					 int num_colors, SDL_Color *colors);
slouken@47
   132
static void         QZ_DirectUpdate     (_THIS, int num_rects, SDL_Rect *rects);
slouken@47
   133
static void         QZ_UpdateRects      (_THIS, int num_rects, SDL_Rect *rects);
slouken@47
   134
static void         QZ_VideoQuit        (_THIS);
slouken@47
   135
slouken@47
   136
/* Hardware surface functions (for fullscreen mode only) */
slouken@47
   137
static int  QZ_FillHWRect (_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color);
slouken@47
   138
static int  QZ_LockHWSurface(_THIS, SDL_Surface *surface);
slouken@47
   139
static void QZ_UnlockHWSurface(_THIS, SDL_Surface *surface);
slouken@47
   140
static void QZ_FreeHWSurface (_THIS, SDL_Surface *surface);
slouken@47
   141
/* static int  QZ_FlipHWSurface (_THIS, SDL_Surface *surface); */
slouken@47
   142
slouken@47
   143
/* Gamma Functions */
slouken@47
   144
static int QZ_SetGamma     (_THIS, float red, float green, float blue);
slouken@47
   145
static int QZ_GetGamma     (_THIS, float *red, float *green, float *blue);
slouken@47
   146
static int QZ_SetGammaRamp (_THIS, Uint16 *ramp);
slouken@47
   147
static int QZ_GetGammaRamp (_THIS, Uint16 *ramp);
slouken@47
   148
slouken@47
   149
/* OpenGL functions */
slouken@47
   150
static int    QZ_SetupOpenGL (_THIS, int bpp, Uint32 flags);
slouken@47
   151
static void   QZ_TearDownOpenGL (_THIS);
slouken@47
   152
static void*  QZ_GL_GetProcAddress (_THIS, const char *proc);
slouken@47
   153
static int    QZ_GL_GetAttribute   (_THIS, SDL_GLattr attrib, int* value);
slouken@47
   154
static int    QZ_GL_MakeCurrent    (_THIS);
slouken@47
   155
static void   QZ_GL_SwapBuffers    (_THIS);
slouken@47
   156
static int    QZ_GL_LoadLibrary    (_THIS, const char *location);
slouken@47
   157
slouken@47
   158
/* Private function to warp the cursor (used internally) */
slouken@47
   159
static void  QZ_PrivateWarpCursor (_THIS, int fullscreen, int h, int x, int y);
slouken@47
   160
slouken@47
   161
/* Cursor and Mouse functions */
slouken@47
   162
static void         QZ_FreeWMCursor     (_THIS, WMcursor *cursor);
slouken@47
   163
static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
slouken@47
   164
                                          int w, int h, int hot_x, int hot_y);
slouken@47
   165
static int          QZ_ShowWMCursor     (_THIS, WMcursor *cursor);
slouken@47
   166
static void         QZ_WarpWMCursor     (_THIS, Uint16 x, Uint16 y);
slouken@47
   167
static void         QZ_MoveWMCursor     (_THIS, int x, int y);
slouken@47
   168
static void         QZ_CheckMouseMode   (_THIS);
slouken@47
   169
slouken@47
   170
/* Event functions */
slouken@47
   171
static void         QZ_InitOSKeymap     (_THIS);
slouken@47
   172
static void         QZ_PumpEvents       (_THIS);
slouken@47
   173
slouken@47
   174
/* Window Manager functions */
slouken@47
   175
static void QZ_SetCaption    (_THIS, const char *title, const char *icon);
slouken@47
   176
static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask);
slouken@47
   177
static int  QZ_IconifyWindow (_THIS);
slouken@47
   178
static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode);
slouken@47
   179
/*static int  QZ_GetWMInfo     (_THIS, SDL_SysWMinfo *info);*/