src/video/win32/SDL_win32video.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 09 May 2010 20:47:22 -0700
changeset 4465 3e69e077cb95
parent 3697 f7b03b6838cb
child 4500 eff4e88cc1e8
child 4747 5284a3b3217a
permissions -rw-r--r--
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.

Plus, this lets me start implementing cursor support.
slouken@1895
     1
/*
slouken@1895
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 Sam Lantinga
slouken@1895
     4
slouken@1895
     5
    This library is free software; you can redistribute it and/or
slouken@1895
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1895
     7
    License as published by the Free Software Foundation; either
slouken@1895
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1895
     9
slouken@1895
    10
    This library is distributed in the hope that it will be useful,
slouken@1895
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1895
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1895
    13
    Lesser General Public License for more details.
slouken@1895
    14
slouken@1895
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1895
    16
    License along with this library; if not, write to the Free Software
slouken@1895
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1895
    18
slouken@1895
    19
    Sam Lantinga
slouken@1895
    20
    slouken@libsdl.org
slouken@1895
    21
*/
slouken@1895
    22
#include "SDL_config.h"
slouken@1895
    23
slouken@1895
    24
#include "SDL_main.h"
slouken@1895
    25
#include "SDL_video.h"
slouken@1895
    26
#include "SDL_mouse.h"
slouken@1895
    27
#include "../SDL_sysvideo.h"
slouken@1895
    28
#include "../SDL_pixels_c.h"
slouken@1895
    29
slouken@1895
    30
#include "SDL_win32video.h"
slouken@1895
    31
#include "SDL_d3drender.h"
slouken@1895
    32
#include "SDL_gdirender.h"
slouken@1895
    33
slouken@1895
    34
/* Initialization/Query functions */
slouken@1895
    35
static int WIN_VideoInit(_THIS);
slouken@1895
    36
static void WIN_VideoQuit(_THIS);
slouken@1895
    37
slouken@1895
    38
/* WIN32 driver bootstrap functions */
slouken@1895
    39
slouken@1895
    40
static int
slouken@1895
    41
WIN_Available(void)
slouken@1895
    42
{
slouken@1895
    43
    return (1);
slouken@1895
    44
}
slouken@1895
    45
slouken@1895
    46
static void
slouken@1895
    47
WIN_DeleteDevice(SDL_VideoDevice * device)
slouken@1895
    48
{
slouken@1895
    49
    SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
slouken@1895
    50
slouken@1895
    51
    SDL_UnregisterApp();
slouken@1895
    52
#if SDL_VIDEO_RENDER_D3D
slouken@1895
    53
    if (data->d3d) {
slouken@1895
    54
        IDirect3D9_Release(data->d3d);
slouken@1895
    55
        FreeLibrary(data->d3dDLL);
slouken@1895
    56
    }
slouken@1895
    57
#endif
slouken@3168
    58
#if SDL_VIDEO_RENDER_DDRAW
slouken@3168
    59
    if (data->ddraw) {
slouken@3168
    60
        data->ddraw->lpVtbl->Release(data->ddraw);
slouken@3168
    61
        FreeLibrary(data->ddrawDLL);
slouken@3168
    62
    }
slouken@3168
    63
#endif
slouken@1895
    64
    SDL_free(device->driverdata);
slouken@1895
    65
    SDL_free(device);
slouken@1895
    66
}
slouken@1895
    67
slouken@1895
    68
static SDL_VideoDevice *
slouken@1895
    69
WIN_CreateDevice(int devindex)
slouken@1895
    70
{
slouken@1895
    71
    SDL_VideoDevice *device;
slouken@1895
    72
    SDL_VideoData *data;
slouken@1895
    73
slouken@1895
    74
    SDL_RegisterApp(NULL, 0, NULL);
slouken@1895
    75
slouken@1895
    76
    /* Initialize all variables that we clean on shutdown */
slouken@1895
    77
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slouken@1895
    78
    if (device) {
slouken@1895
    79
        data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
slouken@4465
    80
    } else {
slouken@4465
    81
        data = NULL;
slouken@1895
    82
    }
slouken@4465
    83
    if (!data) {
slouken@1895
    84
        SDL_OutOfMemory();
slouken@1895
    85
        if (device) {
slouken@1895
    86
            SDL_free(device);
slouken@1895
    87
        }
slouken@1895
    88
        return NULL;
slouken@1895
    89
    }
slouken@1895
    90
    device->driverdata = data;
slouken@1895
    91
slouken@1895
    92
#if SDL_VIDEO_RENDER_D3D
slouken@1895
    93
    data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL"));
slouken@1895
    94
    if (data->d3dDLL) {
slouken@1895
    95
        IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
slouken@1895
    96
slouken@1895
    97
        D3DCreate =
slouken@1895
    98
            (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL,
slouken@1895
    99
                                                            "Direct3DCreate9");
slouken@1895
   100
        if (D3DCreate) {
slouken@1895
   101
            data->d3d = D3DCreate(D3D_SDK_VERSION);
slouken@1895
   102
        }
slouken@1895
   103
        if (!data->d3d) {
slouken@1895
   104
            FreeLibrary(data->d3dDLL);
slouken@1895
   105
            data->d3dDLL = NULL;
slouken@1895
   106
        }
slouken@1895
   107
    }
slouken@1895
   108
#endif /* SDL_VIDEO_RENDER_D3D */
slouken@3168
   109
#if SDL_VIDEO_RENDER_DDRAW
slouken@3168
   110
    data->ddrawDLL = LoadLibrary(TEXT("ddraw.dll"));
slouken@3168
   111
    if (data->ddrawDLL) {
slouken@3168
   112
        IDirectDraw *(WINAPI * DDCreate) (GUID FAR * lpGUID,
slouken@3168
   113
                                          LPDIRECTDRAW FAR * lplpDD,
slouken@3168
   114
                                          IUnknown FAR * pUnkOuter);
slouken@3168
   115
slouken@3168
   116
        DDCreate =
slouken@3168
   117
            (IDirectDraw *
slouken@3168
   118
             (WINAPI *) (GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *))
slouken@3168
   119
            GetProcAddress(data->ddrawDLL, TEXT("DirectDrawCreate"));
slouken@3168
   120
        if (!DDCreate || DDCreate(NULL, &data->ddraw, NULL) != DD_OK) {
slouken@3168
   121
            FreeLibrary(data->ddrawDLL);
slouken@3168
   122
            data->ddrawDLL = NULL;
slouken@3168
   123
            data->ddraw = NULL;
slouken@3168
   124
        }
slouken@3168
   125
    }
slouken@3168
   126
#endif /* SDL_VIDEO_RENDER_DDRAW */
slouken@1895
   127
slouken@1895
   128
    /* Set the function pointers */
slouken@1895
   129
    device->VideoInit = WIN_VideoInit;
slouken@1913
   130
    device->VideoQuit = WIN_VideoQuit;
slouken@3528
   131
    device->GetDisplayBounds = WIN_GetDisplayBounds;
slouken@1895
   132
    device->GetDisplayModes = WIN_GetDisplayModes;
slouken@1895
   133
    device->SetDisplayMode = WIN_SetDisplayMode;
slouken@1895
   134
    device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp;
slouken@1895
   135
    device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp;
slouken@1895
   136
    device->PumpEvents = WIN_PumpEvents;
slouken@1895
   137
slouken@1895
   138
#undef CreateWindow
slouken@1895
   139
    device->CreateWindow = WIN_CreateWindow;
slouken@1895
   140
    device->CreateWindowFrom = WIN_CreateWindowFrom;
slouken@1895
   141
    device->SetWindowTitle = WIN_SetWindowTitle;
slouken@2970
   142
    device->SetWindowIcon = WIN_SetWindowIcon;
slouken@1895
   143
    device->SetWindowPosition = WIN_SetWindowPosition;
slouken@1895
   144
    device->SetWindowSize = WIN_SetWindowSize;
slouken@1895
   145
    device->ShowWindow = WIN_ShowWindow;
slouken@1895
   146
    device->HideWindow = WIN_HideWindow;
slouken@1895
   147
    device->RaiseWindow = WIN_RaiseWindow;
slouken@1895
   148
    device->MaximizeWindow = WIN_MaximizeWindow;
slouken@1895
   149
    device->MinimizeWindow = WIN_MinimizeWindow;
slouken@1895
   150
    device->RestoreWindow = WIN_RestoreWindow;
slouken@1895
   151
    device->SetWindowGrab = WIN_SetWindowGrab;
slouken@1895
   152
    device->DestroyWindow = WIN_DestroyWindow;
slouken@1895
   153
    device->GetWindowWMInfo = WIN_GetWindowWMInfo;
slouken@1952
   154
#ifdef SDL_VIDEO_OPENGL_WGL
slouken@1913
   155
    device->GL_LoadLibrary = WIN_GL_LoadLibrary;
slouken@1913
   156
    device->GL_GetProcAddress = WIN_GL_GetProcAddress;
slouken@3057
   157
    device->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
slouken@1913
   158
    device->GL_CreateContext = WIN_GL_CreateContext;
slouken@1913
   159
    device->GL_MakeCurrent = WIN_GL_MakeCurrent;
slouken@1913
   160
    device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
slouken@1913
   161
    device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
slouken@1913
   162
    device->GL_SwapWindow = WIN_GL_SwapWindow;
slouken@1913
   163
    device->GL_DeleteContext = WIN_GL_DeleteContext;
slouken@1913
   164
#endif
slouken@1895
   165
slouken@1895
   166
    device->free = WIN_DeleteDevice;
slouken@1895
   167
slouken@1895
   168
    return device;
slouken@1895
   169
}
slouken@1895
   170
slouken@1895
   171
VideoBootStrap WIN32_bootstrap = {
slouken@2710
   172
    "win32", "SDL Win32/64 video driver", WIN_Available, WIN_CreateDevice
slouken@1895
   173
};
slouken@1895
   174
slouken@1895
   175
slouken@1895
   176
int
slouken@1895
   177
WIN_VideoInit(_THIS)
slouken@1895
   178
{
slouken@3521
   179
    if (WIN_InitModes(_this) < 0) {
slouken@3521
   180
        return -1;
slouken@3521
   181
    }
slouken@1895
   182
slouken@1905
   183
#if SDL_VIDEO_RENDER_D3D
slouken@1905
   184
    D3D_AddRenderDriver(_this);
slouken@1905
   185
#endif
slouken@3168
   186
#if SDL_VIDEO_RENDER_DDRAW
slouken@3168
   187
    DDRAW_AddRenderDriver(_this);
slouken@3168
   188
#endif
slouken@1895
   189
#if SDL_VIDEO_RENDER_GDI
slouken@1895
   190
    GDI_AddRenderDriver(_this);
slouken@1895
   191
#endif
slouken@3168
   192
#if SDL_VIDEO_RENDER_GAPI
slouken@3168
   193
    GAPI_AddRenderDriver(_this);
slouken@3168
   194
#endif
slouken@1895
   195
slouken@1895
   196
    WIN_InitKeyboard(_this);
slouken@1895
   197
    WIN_InitMouse(_this);
slouken@1895
   198
slouken@1895
   199
    return 0;
slouken@1895
   200
}
slouken@1895
   201
slouken@1895
   202
void
slouken@1895
   203
WIN_VideoQuit(_THIS)
slouken@1895
   204
{
slouken@1895
   205
    WIN_QuitModes(_this);
slouken@1895
   206
    WIN_QuitKeyboard(_this);
slouken@1895
   207
    WIN_QuitMouse(_this);
slouken@1895
   208
}
slouken@1895
   209
slouken@1895
   210
/* vim: set ts=4 sw=4 expandtab: */