src/video/win32/SDL_win32video.c
author Eli Gottlieb <eligottlieb@gmail.com>
Fri, 09 Jul 2010 20:24:44 -0400
changeset 4788 0bfda420c936
parent 3697 f7b03b6838cb
child 4809 329708ffe2a7
permissions -rw-r--r--
Put in a couple of fixes that I realized hadn't gotten done when I wrote out the SCRUM stuff in TODO. Added SCRUM listings in TODO.
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"
eligottlieb@4788
    31
#include "SDL_win32shape.h"
slouken@1895
    32
#include "SDL_d3drender.h"
slouken@1895
    33
#include "SDL_gdirender.h"
slouken@1895
    34
slouken@1895
    35
/* Initialization/Query functions */
slouken@1895
    36
static int WIN_VideoInit(_THIS);
slouken@1895
    37
static void WIN_VideoQuit(_THIS);
slouken@1895
    38
slouken@2710
    39
int total_mice = 0;             /* total mouse count */
slouken@2710
    40
HANDLE *mice = NULL;            /* the handles to the detected mice */
slouken@2710
    41
HCTX *g_hCtx = NULL;            /* handles to tablet contexts */
slouken@2710
    42
int tablet = -1;                /* we're assuming that there is no tablet */
slouken@2710
    43
slouken@1895
    44
/* WIN32 driver bootstrap functions */
slouken@1895
    45
slouken@1895
    46
static int
slouken@1895
    47
WIN_Available(void)
slouken@1895
    48
{
slouken@1895
    49
    return (1);
slouken@1895
    50
}
slouken@1895
    51
slouken@1895
    52
static void
slouken@1895
    53
WIN_DeleteDevice(SDL_VideoDevice * device)
slouken@1895
    54
{
slouken@1895
    55
    SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
slouken@1895
    56
slouken@1895
    57
    SDL_UnregisterApp();
slouken@1895
    58
#if SDL_VIDEO_RENDER_D3D
slouken@1895
    59
    if (data->d3d) {
slouken@1895
    60
        IDirect3D9_Release(data->d3d);
slouken@1895
    61
        FreeLibrary(data->d3dDLL);
slouken@1895
    62
    }
slouken@1895
    63
#endif
slouken@3168
    64
#if SDL_VIDEO_RENDER_DDRAW
slouken@3168
    65
    if (data->ddraw) {
slouken@3168
    66
        data->ddraw->lpVtbl->Release(data->ddraw);
slouken@3168
    67
        FreeLibrary(data->ddrawDLL);
slouken@3168
    68
    }
slouken@3168
    69
#endif
slouken@2726
    70
    if (data->wintabDLL) {
slouken@2726
    71
        FreeLibrary(data->wintabDLL);
slouken@2726
    72
    }
slouken@1895
    73
    SDL_free(device->driverdata);
slouken@1895
    74
    SDL_free(device);
slouken@1895
    75
}
slouken@1895
    76
slouken@1895
    77
static SDL_VideoDevice *
slouken@1895
    78
WIN_CreateDevice(int devindex)
slouken@1895
    79
{
slouken@1895
    80
    SDL_VideoDevice *device;
slouken@1895
    81
    SDL_VideoData *data;
slouken@1895
    82
slouken@1895
    83
    SDL_RegisterApp(NULL, 0, NULL);
slouken@1895
    84
slouken@1895
    85
    /* Initialize all variables that we clean on shutdown */
slouken@1895
    86
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slouken@1895
    87
    if (device) {
slouken@1895
    88
        data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
slouken@1895
    89
    }
slouken@1895
    90
    if (!device || !data) {
slouken@1895
    91
        SDL_OutOfMemory();
slouken@1895
    92
        if (device) {
slouken@1895
    93
            SDL_free(device);
slouken@1895
    94
        }
slouken@1895
    95
        return NULL;
slouken@1895
    96
    }
slouken@1895
    97
    device->driverdata = data;
slouken@1895
    98
slouken@1895
    99
#if SDL_VIDEO_RENDER_D3D
slouken@1895
   100
    data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL"));
slouken@1895
   101
    if (data->d3dDLL) {
slouken@1895
   102
        IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
slouken@1895
   103
slouken@1895
   104
        D3DCreate =
slouken@1895
   105
            (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL,
slouken@1895
   106
                                                            "Direct3DCreate9");
slouken@1895
   107
        if (D3DCreate) {
slouken@1895
   108
            data->d3d = D3DCreate(D3D_SDK_VERSION);
slouken@1895
   109
        }
slouken@1895
   110
        if (!data->d3d) {
slouken@1895
   111
            FreeLibrary(data->d3dDLL);
slouken@1895
   112
            data->d3dDLL = NULL;
slouken@1895
   113
        }
slouken@1895
   114
    }
slouken@1895
   115
#endif /* SDL_VIDEO_RENDER_D3D */
slouken@3168
   116
#if SDL_VIDEO_RENDER_DDRAW
slouken@3168
   117
    data->ddrawDLL = LoadLibrary(TEXT("ddraw.dll"));
slouken@3168
   118
    if (data->ddrawDLL) {
slouken@3168
   119
        IDirectDraw *(WINAPI * DDCreate) (GUID FAR * lpGUID,
slouken@3168
   120
                                          LPDIRECTDRAW FAR * lplpDD,
slouken@3168
   121
                                          IUnknown FAR * pUnkOuter);
slouken@3168
   122
slouken@3168
   123
        DDCreate =
slouken@3168
   124
            (IDirectDraw *
slouken@3168
   125
             (WINAPI *) (GUID FAR *, LPDIRECTDRAW FAR *, IUnknown FAR *))
slouken@3168
   126
            GetProcAddress(data->ddrawDLL, TEXT("DirectDrawCreate"));
slouken@3168
   127
        if (!DDCreate || DDCreate(NULL, &data->ddraw, NULL) != DD_OK) {
slouken@3168
   128
            FreeLibrary(data->ddrawDLL);
slouken@3168
   129
            data->ddrawDLL = NULL;
slouken@3168
   130
            data->ddraw = NULL;
slouken@3168
   131
        }
slouken@3168
   132
    }
slouken@3168
   133
#endif /* SDL_VIDEO_RENDER_DDRAW */
slouken@1895
   134
slouken@2726
   135
    data->wintabDLL = LoadLibrary(TEXT("WINTAB32.DLL"));
slouken@2726
   136
    if (data->wintabDLL) {
slouken@2726
   137
#define PROCNAME(X) #X
slouken@2728
   138
        data->WTInfoA =
slouken@2726
   139
            (UINT(*)(UINT, UINT, LPVOID)) GetProcAddress(data->wintabDLL,
slouken@2728
   140
                                                         PROCNAME(WTInfoA));
slouken@2728
   141
        data->WTOpenA =
slouken@3013
   142
            (HCTX(*)(HWND, LPLOGCONTEXTA, BOOL)) GetProcAddress(data->
slouken@3013
   143
                                                                wintabDLL,
slouken@3013
   144
                                                                PROCNAME
slouken@3013
   145
                                                                (WTOpenA));
slouken@2726
   146
        data->WTPacket =
slouken@2726
   147
            (int (*)(HCTX, UINT, LPVOID)) GetProcAddress(data->wintabDLL,
slouken@2726
   148
                                                         PROCNAME(WTPacket));
slouken@2726
   149
        data->WTClose =
slouken@2726
   150
            (BOOL(*)(HCTX)) GetProcAddress(data->wintabDLL,
slouken@2726
   151
                                           PROCNAME(WTClose));
slouken@2726
   152
#undef PROCNAME
slouken@2726
   153
slouken@2728
   154
        if (!data->WTInfoA || !data->WTOpenA || !data->WTPacket
slouken@2726
   155
            || !data->WTClose) {
slouken@2726
   156
            FreeLibrary(data->wintabDLL);
slouken@2726
   157
            data->wintabDLL = NULL;
slouken@2726
   158
        }
slouken@2726
   159
    }
slouken@2726
   160
slouken@1895
   161
    /* Set the function pointers */
slouken@1895
   162
    device->VideoInit = WIN_VideoInit;
slouken@1913
   163
    device->VideoQuit = WIN_VideoQuit;
slouken@3528
   164
    device->GetDisplayBounds = WIN_GetDisplayBounds;
slouken@1895
   165
    device->GetDisplayModes = WIN_GetDisplayModes;
slouken@1895
   166
    device->SetDisplayMode = WIN_SetDisplayMode;
slouken@1895
   167
    device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp;
slouken@1895
   168
    device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp;
slouken@1895
   169
    device->PumpEvents = WIN_PumpEvents;
slouken@1895
   170
slouken@1895
   171
#undef CreateWindow
slouken@1895
   172
    device->CreateWindow = WIN_CreateWindow;
slouken@1895
   173
    device->CreateWindowFrom = WIN_CreateWindowFrom;
slouken@1895
   174
    device->SetWindowTitle = WIN_SetWindowTitle;
slouken@2970
   175
    device->SetWindowIcon = WIN_SetWindowIcon;
slouken@1895
   176
    device->SetWindowPosition = WIN_SetWindowPosition;
slouken@1895
   177
    device->SetWindowSize = WIN_SetWindowSize;
slouken@1895
   178
    device->ShowWindow = WIN_ShowWindow;
slouken@1895
   179
    device->HideWindow = WIN_HideWindow;
slouken@1895
   180
    device->RaiseWindow = WIN_RaiseWindow;
slouken@1895
   181
    device->MaximizeWindow = WIN_MaximizeWindow;
slouken@1895
   182
    device->MinimizeWindow = WIN_MinimizeWindow;
slouken@1895
   183
    device->RestoreWindow = WIN_RestoreWindow;
slouken@1895
   184
    device->SetWindowGrab = WIN_SetWindowGrab;
slouken@1895
   185
    device->DestroyWindow = WIN_DestroyWindow;
slouken@1895
   186
    device->GetWindowWMInfo = WIN_GetWindowWMInfo;
eligottlieb@4788
   187
    
eligottlieb@4788
   188
    device->shape_driver.CreateShaper = Win32_CreateShaper;
eligottlieb@4788
   189
    device->shape_driver.SetWindowShape = Win32_SetWindowShape;
eligottlieb@4788
   190
    device->shape_driver.ResizeWindowShape = Win32_ResizeWindowShape;
eligottlieb@4788
   191
    
slouken@1952
   192
#ifdef SDL_VIDEO_OPENGL_WGL
slouken@1913
   193
    device->GL_LoadLibrary = WIN_GL_LoadLibrary;
slouken@1913
   194
    device->GL_GetProcAddress = WIN_GL_GetProcAddress;
slouken@3057
   195
    device->GL_UnloadLibrary = WIN_GL_UnloadLibrary;
slouken@1913
   196
    device->GL_CreateContext = WIN_GL_CreateContext;
slouken@1913
   197
    device->GL_MakeCurrent = WIN_GL_MakeCurrent;
slouken@1913
   198
    device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
slouken@1913
   199
    device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
slouken@1913
   200
    device->GL_SwapWindow = WIN_GL_SwapWindow;
slouken@1913
   201
    device->GL_DeleteContext = WIN_GL_DeleteContext;
slouken@1913
   202
#endif
slouken@1895
   203
slouken@1895
   204
    device->free = WIN_DeleteDevice;
slouken@1895
   205
slouken@1895
   206
    return device;
slouken@1895
   207
}
slouken@1895
   208
slouken@1895
   209
VideoBootStrap WIN32_bootstrap = {
slouken@2710
   210
    "win32", "SDL Win32/64 video driver", WIN_Available, WIN_CreateDevice
slouken@1895
   211
};
slouken@1895
   212
slouken@1895
   213
slouken@1895
   214
int
slouken@1895
   215
WIN_VideoInit(_THIS)
slouken@1895
   216
{
slouken@3521
   217
    if (WIN_InitModes(_this) < 0) {
slouken@3521
   218
        return -1;
slouken@3521
   219
    }
slouken@1895
   220
slouken@1905
   221
#if SDL_VIDEO_RENDER_D3D
slouken@1905
   222
    D3D_AddRenderDriver(_this);
slouken@1905
   223
#endif
slouken@3168
   224
#if SDL_VIDEO_RENDER_DDRAW
slouken@3168
   225
    DDRAW_AddRenderDriver(_this);
slouken@3168
   226
#endif
slouken@1895
   227
#if SDL_VIDEO_RENDER_GDI
slouken@1895
   228
    GDI_AddRenderDriver(_this);
slouken@1895
   229
#endif
slouken@3168
   230
#if SDL_VIDEO_RENDER_GAPI
slouken@3168
   231
    GAPI_AddRenderDriver(_this);
slouken@3168
   232
#endif
slouken@1895
   233
slouken@2710
   234
    g_hCtx = SDL_malloc(sizeof(HCTX));
slouken@1895
   235
    WIN_InitKeyboard(_this);
slouken@1895
   236
    WIN_InitMouse(_this);
slouken@1895
   237
slouken@1895
   238
    return 0;
slouken@1895
   239
}
slouken@1895
   240
slouken@1895
   241
void
slouken@1895
   242
WIN_VideoQuit(_THIS)
slouken@1895
   243
{
slouken@1895
   244
    WIN_QuitModes(_this);
slouken@1895
   245
    WIN_QuitKeyboard(_this);
slouken@1895
   246
    WIN_QuitMouse(_this);
slouken@2710
   247
    SDL_free(g_hCtx);
slouken@1895
   248
}
slouken@1895
   249
slouken@1895
   250
/* vim: set ts=4 sw=4 expandtab: */