src/video/win32/SDL_win32video.c
author Bob Pendleton <bob@pendleton.com>
Fri, 09 Jan 2009 20:43:30 +0000
changeset 3011 8f4ed5ec2b06
parent 2970 94b634c56455
child 3013 8cc00819c8d6
permissions -rw-r--r--
I ran a global "make indent" it modified the following files.
slouken@1895
     1
/*
slouken@1895
     2
    SDL - Simple DirectMedia Layer
slouken@2859
     3
    Copyright (C) 1997-2009 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@2710
    38
int total_mice = 0;             /* total mouse count */
slouken@2710
    39
HANDLE *mice = NULL;            /* the handles to the detected mice */
slouken@2710
    40
HCTX *g_hCtx = NULL;            /* handles to tablet contexts */
slouken@2710
    41
int tablet = -1;                /* we're assuming that there is no tablet */
slouken@2710
    42
slouken@1895
    43
/* WIN32 driver bootstrap functions */
slouken@1895
    44
slouken@1895
    45
static int
slouken@1895
    46
WIN_Available(void)
slouken@1895
    47
{
slouken@1895
    48
    return (1);
slouken@1895
    49
}
slouken@1895
    50
slouken@1895
    51
static void
slouken@1895
    52
WIN_DeleteDevice(SDL_VideoDevice * device)
slouken@1895
    53
{
slouken@1895
    54
    SDL_VideoData *data = (SDL_VideoData *) device->driverdata;
slouken@1895
    55
slouken@1895
    56
    SDL_UnregisterApp();
slouken@1895
    57
#if SDL_VIDEO_RENDER_D3D
slouken@1895
    58
    if (data->d3d) {
slouken@1895
    59
        IDirect3D9_Release(data->d3d);
slouken@1895
    60
        FreeLibrary(data->d3dDLL);
slouken@1895
    61
    }
slouken@1895
    62
#endif
slouken@2726
    63
    if (data->wintabDLL) {
slouken@2726
    64
        FreeLibrary(data->wintabDLL);
slouken@2726
    65
    }
slouken@1895
    66
    SDL_free(device->driverdata);
slouken@1895
    67
    SDL_free(device);
slouken@1895
    68
}
slouken@1895
    69
slouken@1895
    70
static SDL_VideoDevice *
slouken@1895
    71
WIN_CreateDevice(int devindex)
slouken@1895
    72
{
slouken@1895
    73
    SDL_VideoDevice *device;
slouken@1895
    74
    SDL_VideoData *data;
slouken@1895
    75
slouken@1895
    76
    SDL_RegisterApp(NULL, 0, NULL);
slouken@1895
    77
slouken@1895
    78
    /* Initialize all variables that we clean on shutdown */
slouken@1895
    79
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slouken@1895
    80
    if (device) {
slouken@1895
    81
        data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
slouken@1895
    82
    }
slouken@1895
    83
    if (!device || !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@1895
   109
slouken@2726
   110
    data->wintabDLL = LoadLibrary(TEXT("WINTAB32.DLL"));
slouken@2726
   111
    if (data->wintabDLL) {
slouken@2726
   112
#define PROCNAME(X) #X
slouken@2728
   113
        data->WTInfoA =
slouken@2726
   114
            (UINT(*)(UINT, UINT, LPVOID)) GetProcAddress(data->wintabDLL,
slouken@2728
   115
                                                         PROCNAME(WTInfoA));
slouken@2728
   116
        data->WTOpenA =
bob@3011
   117
            (HCTX(*)(HWND, LPLOGCONTEXTA, BOOL))
bob@3011
   118
            GetProcAddress(data->wintabDLL, PROCNAME(WTOpenA));
slouken@2726
   119
        data->WTPacket =
slouken@2726
   120
            (int (*)(HCTX, UINT, LPVOID)) GetProcAddress(data->wintabDLL,
slouken@2726
   121
                                                         PROCNAME(WTPacket));
slouken@2726
   122
        data->WTClose =
slouken@2726
   123
            (BOOL(*)(HCTX)) GetProcAddress(data->wintabDLL,
slouken@2726
   124
                                           PROCNAME(WTClose));
slouken@2726
   125
#undef PROCNAME
slouken@2726
   126
slouken@2728
   127
        if (!data->WTInfoA || !data->WTOpenA || !data->WTPacket
slouken@2726
   128
            || !data->WTClose) {
slouken@2726
   129
            FreeLibrary(data->wintabDLL);
slouken@2726
   130
            data->wintabDLL = NULL;
slouken@2726
   131
        }
slouken@2726
   132
    }
slouken@2726
   133
slouken@1895
   134
    /* Set the function pointers */
slouken@1895
   135
    device->VideoInit = WIN_VideoInit;
slouken@1913
   136
    device->VideoQuit = WIN_VideoQuit;
slouken@1895
   137
    device->GetDisplayModes = WIN_GetDisplayModes;
slouken@1895
   138
    device->SetDisplayMode = WIN_SetDisplayMode;
slouken@1895
   139
    device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp;
slouken@1895
   140
    device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp;
slouken@1895
   141
    device->PumpEvents = WIN_PumpEvents;
slouken@1895
   142
slouken@1895
   143
#undef CreateWindow
slouken@1895
   144
    device->CreateWindow = WIN_CreateWindow;
slouken@1895
   145
    device->CreateWindowFrom = WIN_CreateWindowFrom;
slouken@1895
   146
    device->SetWindowTitle = WIN_SetWindowTitle;
slouken@2970
   147
    device->SetWindowIcon = WIN_SetWindowIcon;
slouken@1895
   148
    device->SetWindowPosition = WIN_SetWindowPosition;
slouken@1895
   149
    device->SetWindowSize = WIN_SetWindowSize;
slouken@1895
   150
    device->ShowWindow = WIN_ShowWindow;
slouken@1895
   151
    device->HideWindow = WIN_HideWindow;
slouken@1895
   152
    device->RaiseWindow = WIN_RaiseWindow;
slouken@1895
   153
    device->MaximizeWindow = WIN_MaximizeWindow;
slouken@1895
   154
    device->MinimizeWindow = WIN_MinimizeWindow;
slouken@1895
   155
    device->RestoreWindow = WIN_RestoreWindow;
slouken@1895
   156
    device->SetWindowGrab = WIN_SetWindowGrab;
slouken@1895
   157
    device->DestroyWindow = WIN_DestroyWindow;
slouken@1895
   158
    device->GetWindowWMInfo = WIN_GetWindowWMInfo;
slouken@1952
   159
#ifdef SDL_VIDEO_OPENGL_WGL
slouken@1913
   160
    device->GL_LoadLibrary = WIN_GL_LoadLibrary;
slouken@1913
   161
    device->GL_GetProcAddress = WIN_GL_GetProcAddress;
slouken@1913
   162
    device->GL_CreateContext = WIN_GL_CreateContext;
slouken@1913
   163
    device->GL_MakeCurrent = WIN_GL_MakeCurrent;
slouken@1913
   164
    device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
slouken@1913
   165
    device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
slouken@1913
   166
    device->GL_SwapWindow = WIN_GL_SwapWindow;
slouken@1913
   167
    device->GL_DeleteContext = WIN_GL_DeleteContext;
slouken@1913
   168
#endif
slouken@1895
   169
slouken@1895
   170
    device->free = WIN_DeleteDevice;
slouken@1895
   171
slouken@1895
   172
    return device;
slouken@1895
   173
}
slouken@1895
   174
slouken@1895
   175
VideoBootStrap WIN32_bootstrap = {
slouken@2710
   176
    "win32", "SDL Win32/64 video driver", WIN_Available, WIN_CreateDevice
slouken@1895
   177
};
slouken@1895
   178
slouken@1895
   179
slouken@1895
   180
int
slouken@1895
   181
WIN_VideoInit(_THIS)
slouken@1895
   182
{
slouken@1895
   183
    WIN_InitModes(_this);
slouken@1895
   184
slouken@1905
   185
#if SDL_VIDEO_RENDER_D3D
slouken@1905
   186
    D3D_AddRenderDriver(_this);
slouken@1905
   187
#endif
slouken@1895
   188
#if SDL_VIDEO_RENDER_GDI
slouken@1895
   189
    GDI_AddRenderDriver(_this);
slouken@1895
   190
#endif
slouken@1895
   191
slouken@2710
   192
    g_hCtx = SDL_malloc(sizeof(HCTX));
slouken@1895
   193
    WIN_InitKeyboard(_this);
slouken@1895
   194
    WIN_InitMouse(_this);
slouken@1895
   195
slouken@1895
   196
    return 0;
slouken@1895
   197
}
slouken@1895
   198
slouken@1895
   199
void
slouken@1895
   200
WIN_VideoQuit(_THIS)
slouken@1895
   201
{
slouken@1895
   202
    WIN_QuitModes(_this);
slouken@1895
   203
    WIN_QuitKeyboard(_this);
slouken@1895
   204
    WIN_QuitMouse(_this);
slouken@2710
   205
    SDL_free(g_hCtx);
slouken@1895
   206
}
slouken@1895
   207
slouken@1895
   208
/* vim: set ts=4 sw=4 expandtab: */