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