src/video/win32/SDL_win32video.c
author Sam Lantinga <slouken@libsdl.org>
Thu Jun 17 22:23:20 2010 -0700
changeset 4471 11cedc036ca1
parent 3697 f7b03b6838cb
child 4500 eff4e88cc1e8
child 4747 5284a3b3217a
permissions -rw-r--r--
Hello Sam.

I did fix/update the SDL 1.3 pandora port today ( 11 june 2010 ) and you can find the "hg diff" attached :)

David Carr? ( Cpasjuste )
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2010 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 #if SDL_VIDEO_RENDER_DDRAW
    59     if (data->ddraw) {
    60         data->ddraw->lpVtbl->Release(data->ddraw);
    61         FreeLibrary(data->ddrawDLL);
    62     }
    63 #endif
    64     SDL_free(device->driverdata);
    65     SDL_free(device);
    66 }
    67 
    68 static SDL_VideoDevice *
    69 WIN_CreateDevice(int devindex)
    70 {
    71     SDL_VideoDevice *device;
    72     SDL_VideoData *data;
    73 
    74     SDL_RegisterApp(NULL, 0, NULL);
    75 
    76     /* Initialize all variables that we clean on shutdown */
    77     device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    78     if (device) {
    79         data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
    80     } else {
    81         data = NULL;
    82     }
    83     if (!data) {
    84         SDL_OutOfMemory();
    85         if (device) {
    86             SDL_free(device);
    87         }
    88         return NULL;
    89     }
    90     device->driverdata = data;
    91 
    92 #if SDL_VIDEO_RENDER_D3D
    93     data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL"));
    94     if (data->d3dDLL) {
    95         IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
    96 
    97         D3DCreate =
    98             (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL,
    99                                                             "Direct3DCreate9");
   100         if (D3DCreate) {
   101             data->d3d = D3DCreate(D3D_SDK_VERSION);
   102         }
   103         if (!data->d3d) {
   104             FreeLibrary(data->d3dDLL);
   105             data->d3dDLL = NULL;
   106         }
   107     }
   108 #endif /* SDL_VIDEO_RENDER_D3D */
   109 #if SDL_VIDEO_RENDER_DDRAW
   110     data->ddrawDLL = LoadLibrary(TEXT("ddraw.dll"));
   111     if (data->ddrawDLL) {
   112         IDirectDraw *(WINAPI * DDCreate) (GUID FAR * lpGUID,
   113                                           LPDIRECTDRAW FAR * lplpDD,
   114                                           IUnknown FAR * pUnkOuter);
   115 
   116         DDCreate =
   117             (IDirectDraw *
   118              (WINAPI *) (GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *))
   119             GetProcAddress(data->ddrawDLL, TEXT("DirectDrawCreate"));
   120         if (!DDCreate || DDCreate(NULL, &data->ddraw, NULL) != DD_OK) {
   121             FreeLibrary(data->ddrawDLL);
   122             data->ddrawDLL = NULL;
   123             data->ddraw = NULL;
   124         }
   125     }
   126 #endif /* SDL_VIDEO_RENDER_DDRAW */
   127 
   128     /* Set the function pointers */
   129     device->VideoInit = WIN_VideoInit;
   130     device->VideoQuit = WIN_VideoQuit;
   131     device->GetDisplayBounds = WIN_GetDisplayBounds;
   132     device->GetDisplayModes = WIN_GetDisplayModes;
   133     device->SetDisplayMode = WIN_SetDisplayMode;
   134     device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp;
   135     device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp;
   136     device->PumpEvents = WIN_PumpEvents;
   137 
   138 #undef CreateWindow
   139     device->CreateWindow = WIN_CreateWindow;
   140     device->CreateWindowFrom = WIN_CreateWindowFrom;
   141     device->SetWindowTitle = WIN_SetWindowTitle;
   142     device->SetWindowIcon = WIN_SetWindowIcon;
   143     device->SetWindowPosition = WIN_SetWindowPosition;
   144     device->SetWindowSize = WIN_SetWindowSize;
   145     device->ShowWindow = WIN_ShowWindow;
   146     device->HideWindow = WIN_HideWindow;
   147     device->RaiseWindow = WIN_RaiseWindow;
   148     device->MaximizeWindow = WIN_MaximizeWindow;
   149     device->MinimizeWindow = WIN_MinimizeWindow;
   150     device->RestoreWindow = WIN_RestoreWindow;
   151     device->SetWindowGrab = WIN_SetWindowGrab;
   152     device->DestroyWindow = WIN_DestroyWindow;
   153     device->GetWindowWMInfo = WIN_GetWindowWMInfo;
   154 #ifdef SDL_VIDEO_OPENGL_WGL
   155     device->GL_LoadLibrary = WIN_GL_LoadLibrary;
   156     device->GL_GetProcAddress = WIN_GL_GetProcAddress;
   157     device->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
   158     device->GL_CreateContext = WIN_GL_CreateContext;
   159     device->GL_MakeCurrent = WIN_GL_MakeCurrent;
   160     device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
   161     device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
   162     device->GL_SwapWindow = WIN_GL_SwapWindow;
   163     device->GL_DeleteContext = WIN_GL_DeleteContext;
   164 #endif
   165 
   166     device->free = WIN_DeleteDevice;
   167 
   168     return device;
   169 }
   170 
   171 VideoBootStrap WIN32_bootstrap = {
   172     "win32", "SDL Win32/64 video driver", WIN_Available, WIN_CreateDevice
   173 };
   174 
   175 
   176 int
   177 WIN_VideoInit(_THIS)
   178 {
   179     if (WIN_InitModes(_this) < 0) {
   180         return -1;
   181     }
   182 
   183 #if SDL_VIDEO_RENDER_D3D
   184     D3D_AddRenderDriver(_this);
   185 #endif
   186 #if SDL_VIDEO_RENDER_DDRAW
   187     DDRAW_AddRenderDriver(_this);
   188 #endif
   189 #if SDL_VIDEO_RENDER_GDI
   190     GDI_AddRenderDriver(_this);
   191 #endif
   192 #if SDL_VIDEO_RENDER_GAPI
   193     GAPI_AddRenderDriver(_this);
   194 #endif
   195 
   196     WIN_InitKeyboard(_this);
   197     WIN_InitMouse(_this);
   198 
   199     return 0;
   200 }
   201 
   202 void
   203 WIN_VideoQuit(_THIS)
   204 {
   205     WIN_QuitModes(_this);
   206     WIN_QuitKeyboard(_this);
   207     WIN_QuitMouse(_this);
   208 }
   209 
   210 /* vim: set ts=4 sw=4 expandtab: */