src/video/win32/SDL_win32video.c
author Edgar Simo <bobbens@gmail.com>
Sun, 06 Jul 2008 17:06:37 +0000
branchgsoc2008_force_feedback
changeset 2498 ab567bd667bf
parent 1952 420716272158
child 2710 44e49d3fa6cf
child 3767 abc8acb8e3d7
permissions -rw-r--r--
Fixed various mistakes in the doxygen.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 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_main.h"
    25 #include "SDL_video.h"
    26 #include "SDL_mouse.h"
    27 #include "../SDL_sysvideo.h"
    28 #include "../SDL_pixels_c.h"
    29 
    30 #include "SDL_win32video.h"
    31 #include "SDL_d3drender.h"
    32 #include "SDL_gdirender.h"
    33 
    34 /* Initialization/Query functions */
    35 static int WIN_VideoInit(_THIS);
    36 static void WIN_VideoQuit(_THIS);
    37 
    38 /* WIN32 driver bootstrap functions */
    39 
    40 static int
    41 WIN_Available(void)
    42 {
    43     return (1);
    44 }
    45 
    46 static void
    47 WIN_DeleteDevice(SDL_VideoDevice * device)
    48 {
    49     SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
    50 
    51     SDL_UnregisterApp();
    52 #if SDL_VIDEO_RENDER_D3D
    53     if (data->d3d) {
    54         IDirect3D9_Release(data->d3d);
    55         FreeLibrary(data->d3dDLL);
    56     }
    57 #endif
    58     SDL_free(device->driverdata);
    59     SDL_free(device);
    60 }
    61 
    62 static SDL_VideoDevice *
    63 WIN_CreateDevice(int devindex)
    64 {
    65     SDL_VideoDevice *device;
    66     SDL_VideoData *data;
    67 
    68     SDL_RegisterApp(NULL, 0, NULL);
    69 
    70     /* Initialize all variables that we clean on shutdown */
    71     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    72     if (device) {
    73         data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
    74     }
    75     if (!device || !data) {
    76         SDL_OutOfMemory();
    77         if (device) {
    78             SDL_free(device);
    79         }
    80         return NULL;
    81     }
    82     device->driverdata = data;
    83 
    84 #if SDL_VIDEO_RENDER_D3D
    85     data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL"));
    86     if (data->d3dDLL) {
    87         IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
    88 
    89         D3DCreate =
    90             (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL,
    91                                                             "Direct3DCreate9");
    92         if (D3DCreate) {
    93             data->d3d = D3DCreate(D3D_SDK_VERSION);
    94         }
    95         if (!data->d3d) {
    96             FreeLibrary(data->d3dDLL);
    97             data->d3dDLL = NULL;
    98         }
    99     }
   100 #endif /* SDL_VIDEO_RENDER_D3D */
   101 
   102     /* Set the function pointers */
   103     device->VideoInit = WIN_VideoInit;
   104     device->VideoQuit = WIN_VideoQuit;
   105     device->GetDisplayModes = WIN_GetDisplayModes;
   106     device->SetDisplayMode = WIN_SetDisplayMode;
   107     device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp;
   108     device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp;
   109     device->PumpEvents = WIN_PumpEvents;
   110 
   111 #undef CreateWindow
   112     device->CreateWindow = WIN_CreateWindow;
   113     device->CreateWindowFrom = WIN_CreateWindowFrom;
   114     device->SetWindowTitle = WIN_SetWindowTitle;
   115     device->SetWindowPosition = WIN_SetWindowPosition;
   116     device->SetWindowSize = WIN_SetWindowSize;
   117     device->ShowWindow = WIN_ShowWindow;
   118     device->HideWindow = WIN_HideWindow;
   119     device->RaiseWindow = WIN_RaiseWindow;
   120     device->MaximizeWindow = WIN_MaximizeWindow;
   121     device->MinimizeWindow = WIN_MinimizeWindow;
   122     device->RestoreWindow = WIN_RestoreWindow;
   123     device->SetWindowGrab = WIN_SetWindowGrab;
   124     device->DestroyWindow = WIN_DestroyWindow;
   125     device->GetWindowWMInfo = WIN_GetWindowWMInfo;
   126 #ifdef SDL_VIDEO_OPENGL_WGL
   127     device->GL_LoadLibrary = WIN_GL_LoadLibrary;
   128     device->GL_GetProcAddress = WIN_GL_GetProcAddress;
   129     device->GL_CreateContext = WIN_GL_CreateContext;
   130     device->GL_MakeCurrent = WIN_GL_MakeCurrent;
   131     device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
   132     device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
   133     device->GL_SwapWindow = WIN_GL_SwapWindow;
   134     device->GL_DeleteContext = WIN_GL_DeleteContext;
   135 #endif
   136 
   137     device->free = WIN_DeleteDevice;
   138 
   139     return device;
   140 }
   141 
   142 VideoBootStrap WIN32_bootstrap = {
   143     "win32", "SDL Win32/64 video driver",
   144     WIN_Available, WIN_CreateDevice
   145 };
   146 
   147 
   148 int
   149 WIN_VideoInit(_THIS)
   150 {
   151     WIN_InitModes(_this);
   152 
   153 #if SDL_VIDEO_RENDER_D3D
   154     D3D_AddRenderDriver(_this);
   155 #endif
   156 #if SDL_VIDEO_RENDER_GDI
   157     GDI_AddRenderDriver(_this);
   158 #endif
   159 
   160     WIN_InitKeyboard(_this);
   161     WIN_InitMouse(_this);
   162 
   163     return 0;
   164 }
   165 
   166 void
   167 WIN_VideoQuit(_THIS)
   168 {
   169     WIN_QuitModes(_this);
   170     WIN_QuitKeyboard(_this);
   171     WIN_QuitMouse(_this);
   172 }
   173 
   174 /* vim: set ts=4 sw=4 expandtab: */