src/video/cocoa/SDL_cocoavideo.m
author Sam Lantinga <slouken@libsdl.org>
Sat, 19 Sep 2009 13:29:40 +0000
changeset 3280 00cace2d9080
parent 3057 089a77aebb7d
child 3528 59ff7a2beb57
permissions -rw-r--r--
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
slouken@1931
     1
/*
slouken@1931
     2
    SDL - Simple DirectMedia Layer
slouken@2859
     3
    Copyright (C) 1997-2009 Sam Lantinga
slouken@1931
     4
slouken@1931
     5
    This library is free software; you can redistribute it and/or
slouken@1931
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1931
     7
    License as published by the Free Software Foundation; either
slouken@1931
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1931
     9
slouken@1931
    10
    This library is distributed in the hope that it will be useful,
slouken@1931
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1931
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1931
    13
    Lesser General Public License for more details.
slouken@1931
    14
slouken@1931
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1931
    16
    License along with this library; if not, write to the Free Software
slouken@1931
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1931
    18
slouken@1931
    19
    Sam Lantinga
slouken@1931
    20
    slouken@libsdl.org
slouken@1931
    21
*/
slouken@1931
    22
#include "SDL_config.h"
slouken@1931
    23
slouken@1931
    24
#include "SDL_cocoavideo.h"
slouken@1931
    25
slouken@1931
    26
/* Initialization/Query functions */
slouken@1931
    27
static int Cocoa_VideoInit(_THIS);
slouken@1931
    28
static void Cocoa_VideoQuit(_THIS);
slouken@1931
    29
slouken@1931
    30
/* Cocoa driver bootstrap functions */
slouken@1931
    31
slouken@1931
    32
static int
slouken@1931
    33
Cocoa_Available(void)
slouken@1931
    34
{
slouken@1931
    35
    return (1);
slouken@1931
    36
}
slouken@1931
    37
slouken@1931
    38
static void
slouken@1931
    39
Cocoa_DeleteDevice(SDL_VideoDevice * device)
slouken@1931
    40
{
slouken@1931
    41
    SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
slouken@1931
    42
slouken@1931
    43
    SDL_free(device->driverdata);
slouken@1931
    44
    SDL_free(device);
slouken@1931
    45
}
slouken@1931
    46
slouken@1931
    47
static SDL_VideoDevice *
slouken@1931
    48
Cocoa_CreateDevice(int devindex)
slouken@1931
    49
{
slouken@1931
    50
    SDL_VideoDevice *device;
slouken@1931
    51
    SDL_VideoData *data;
slouken@1931
    52
slouken@1931
    53
    Cocoa_RegisterApp();
slouken@1931
    54
slouken@1931
    55
    /* Initialize all variables that we clean on shutdown */
slouken@1931
    56
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slouken@1931
    57
    if (device) {
slouken@1931
    58
        data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
slouken@1931
    59
    }
slouken@1931
    60
    if (!device || !data) {
slouken@1931
    61
        SDL_OutOfMemory();
slouken@1931
    62
        if (device) {
slouken@1931
    63
            SDL_free(device);
slouken@1931
    64
        }
slouken@1931
    65
        return NULL;
slouken@1931
    66
    }
slouken@1931
    67
    device->driverdata = data;
slouken@1931
    68
slouken@1959
    69
    /* Find out what version of Mac OS X we're running */
slouken@1959
    70
    Gestalt(gestaltSystemVersion, &data->osversion);
slouken@1959
    71
slouken@1931
    72
    /* Set the function pointers */
slouken@1931
    73
    device->VideoInit = Cocoa_VideoInit;
slouken@1931
    74
    device->VideoQuit = Cocoa_VideoQuit;
slouken@1931
    75
    device->GetDisplayModes = Cocoa_GetDisplayModes;
slouken@1931
    76
    device->SetDisplayMode = Cocoa_SetDisplayMode;
slouken@1931
    77
    device->PumpEvents = Cocoa_PumpEvents;
slouken@1931
    78
slouken@1931
    79
    device->CreateWindow = Cocoa_CreateWindow;
slouken@1931
    80
    device->CreateWindowFrom = Cocoa_CreateWindowFrom;
slouken@1931
    81
    device->SetWindowTitle = Cocoa_SetWindowTitle;
slouken@1931
    82
    device->SetWindowPosition = Cocoa_SetWindowPosition;
slouken@1931
    83
    device->SetWindowSize = Cocoa_SetWindowSize;
slouken@1931
    84
    device->ShowWindow = Cocoa_ShowWindow;
slouken@1931
    85
    device->HideWindow = Cocoa_HideWindow;
slouken@1931
    86
    device->RaiseWindow = Cocoa_RaiseWindow;
slouken@1931
    87
    device->MaximizeWindow = Cocoa_MaximizeWindow;
slouken@1931
    88
    device->MinimizeWindow = Cocoa_MinimizeWindow;
slouken@1931
    89
    device->RestoreWindow = Cocoa_RestoreWindow;
slouken@1931
    90
    device->SetWindowGrab = Cocoa_SetWindowGrab;
slouken@1931
    91
    device->DestroyWindow = Cocoa_DestroyWindow;
slouken@1931
    92
    device->GetWindowWMInfo = Cocoa_GetWindowWMInfo;
slouken@1952
    93
#ifdef SDL_VIDEO_OPENGL_CGL
slouken@1931
    94
    device->GL_LoadLibrary = Cocoa_GL_LoadLibrary;
slouken@1931
    95
    device->GL_GetProcAddress = Cocoa_GL_GetProcAddress;
slouken@3057
    96
    device->GL_UnloadLibrary = Cocoa_GL_UnloadLibrary;
slouken@1931
    97
    device->GL_CreateContext = Cocoa_GL_CreateContext;
slouken@1931
    98
    device->GL_MakeCurrent = Cocoa_GL_MakeCurrent;
slouken@1931
    99
    device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval;
slouken@1931
   100
    device->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval;
slouken@1931
   101
    device->GL_SwapWindow = Cocoa_GL_SwapWindow;
slouken@1931
   102
    device->GL_DeleteContext = Cocoa_GL_DeleteContext;
slouken@1931
   103
#endif
slouken@1931
   104
slouken@3280
   105
    device->StartTextInput = Cocoa_StartTextInput;
slouken@3280
   106
    device->StopTextInput = Cocoa_StopTextInput;
slouken@3280
   107
    device->SetTextInputRect = Cocoa_SetTextInputRect;
slouken@3280
   108
slouken@1931
   109
    device->free = Cocoa_DeleteDevice;
slouken@1931
   110
slouken@1931
   111
    return device;
slouken@1931
   112
}
slouken@1931
   113
slouken@1931
   114
VideoBootStrap COCOA_bootstrap = {
slouken@1931
   115
    "cocoa", "SDL Cocoa video driver",
slouken@1931
   116
    Cocoa_Available, Cocoa_CreateDevice
slouken@1931
   117
};
slouken@1931
   118
slouken@1931
   119
slouken@1931
   120
int
slouken@1931
   121
Cocoa_VideoInit(_THIS)
slouken@1931
   122
{
slouken@1931
   123
    Cocoa_InitModes(_this);
slouken@1931
   124
    Cocoa_InitKeyboard(_this);
slouken@1931
   125
    Cocoa_InitMouse(_this);
slouken@1931
   126
    return 0;
slouken@1931
   127
}
slouken@1931
   128
slouken@1931
   129
void
slouken@1931
   130
Cocoa_VideoQuit(_THIS)
slouken@1931
   131
{
slouken@1931
   132
    Cocoa_QuitModes(_this);
slouken@1931
   133
    Cocoa_QuitKeyboard(_this);
slouken@1931
   134
    Cocoa_QuitMouse(_this);
slouken@1931
   135
}
slouken@1931
   136
slouken@1931
   137
/* vim: set ts=4 sw=4 expandtab: */