src/video/win32/SDL_win32video.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 26 Aug 2008 05:26:28 +0000
changeset 2724 0e2b65f32298
parent 2710 44e49d3fa6cf
child 2726 f23ebf1ddac4
permissions -rw-r--r--
Added Wacom API headers.
FIXME: Dynamically load the Wacom API functions from wintab32.dll
slouken@1895
     1
/*
slouken@1895
     2
    SDL - Simple DirectMedia Layer
slouken@1895
     3
    Copyright (C) 1997-2006 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@1895
    63
    SDL_free(device->driverdata);
slouken@1895
    64
    SDL_free(device);
slouken@1895
    65
}
slouken@1895
    66
slouken@1895
    67
static SDL_VideoDevice *
slouken@1895
    68
WIN_CreateDevice(int devindex)
slouken@1895
    69
{
slouken@1895
    70
    SDL_VideoDevice *device;
slouken@1895
    71
    SDL_VideoData *data;
slouken@1895
    72
slouken@1895
    73
    SDL_RegisterApp(NULL, 0, NULL);
slouken@1895
    74
slouken@1895
    75
    /* Initialize all variables that we clean on shutdown */
slouken@1895
    76
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slouken@1895
    77
    if (device) {
slouken@1895
    78
        data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
slouken@1895
    79
    }
slouken@1895
    80
    if (!device || !data) {
slouken@1895
    81
        SDL_OutOfMemory();
slouken@1895
    82
        if (device) {
slouken@1895
    83
            SDL_free(device);
slouken@1895
    84
        }
slouken@1895
    85
        return NULL;
slouken@1895
    86
    }
slouken@1895
    87
    device->driverdata = data;
slouken@1895
    88
slouken@1895
    89
#if SDL_VIDEO_RENDER_D3D
slouken@1895
    90
    data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL"));
slouken@1895
    91
    if (data->d3dDLL) {
slouken@1895
    92
        IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
slouken@1895
    93
slouken@1895
    94
        D3DCreate =
slouken@1895
    95
            (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL,
slouken@1895
    96
                                                            "Direct3DCreate9");
slouken@1895
    97
        if (D3DCreate) {
slouken@1895
    98
            data->d3d = D3DCreate(D3D_SDK_VERSION);
slouken@1895
    99
        }
slouken@1895
   100
        if (!data->d3d) {
slouken@1895
   101
            FreeLibrary(data->d3dDLL);
slouken@1895
   102
            data->d3dDLL = NULL;
slouken@1895
   103
        }
slouken@1895
   104
    }
slouken@1895
   105
#endif /* SDL_VIDEO_RENDER_D3D */
slouken@1895
   106
slouken@1895
   107
    /* Set the function pointers */
slouken@1895
   108
    device->VideoInit = WIN_VideoInit;
slouken@1913
   109
    device->VideoQuit = WIN_VideoQuit;
slouken@1895
   110
    device->GetDisplayModes = WIN_GetDisplayModes;
slouken@1895
   111
    device->SetDisplayMode = WIN_SetDisplayMode;
slouken@1895
   112
    device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp;
slouken@1895
   113
    device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp;
slouken@1895
   114
    device->PumpEvents = WIN_PumpEvents;
slouken@1895
   115
slouken@1895
   116
#undef CreateWindow
slouken@1895
   117
    device->CreateWindow = WIN_CreateWindow;
slouken@1895
   118
    device->CreateWindowFrom = WIN_CreateWindowFrom;
slouken@1895
   119
    device->SetWindowTitle = WIN_SetWindowTitle;
slouken@1895
   120
    device->SetWindowPosition = WIN_SetWindowPosition;
slouken@1895
   121
    device->SetWindowSize = WIN_SetWindowSize;
slouken@1895
   122
    device->ShowWindow = WIN_ShowWindow;
slouken@1895
   123
    device->HideWindow = WIN_HideWindow;
slouken@1895
   124
    device->RaiseWindow = WIN_RaiseWindow;
slouken@1895
   125
    device->MaximizeWindow = WIN_MaximizeWindow;
slouken@1895
   126
    device->MinimizeWindow = WIN_MinimizeWindow;
slouken@1895
   127
    device->RestoreWindow = WIN_RestoreWindow;
slouken@1895
   128
    device->SetWindowGrab = WIN_SetWindowGrab;
slouken@1895
   129
    device->DestroyWindow = WIN_DestroyWindow;
slouken@1895
   130
    device->GetWindowWMInfo = WIN_GetWindowWMInfo;
slouken@1952
   131
#ifdef SDL_VIDEO_OPENGL_WGL
slouken@1913
   132
    device->GL_LoadLibrary = WIN_GL_LoadLibrary;
slouken@1913
   133
    device->GL_GetProcAddress = WIN_GL_GetProcAddress;
slouken@1913
   134
    device->GL_CreateContext = WIN_GL_CreateContext;
slouken@1913
   135
    device->GL_MakeCurrent = WIN_GL_MakeCurrent;
slouken@1913
   136
    device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
slouken@1913
   137
    device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
slouken@1913
   138
    device->GL_SwapWindow = WIN_GL_SwapWindow;
slouken@1913
   139
    device->GL_DeleteContext = WIN_GL_DeleteContext;
slouken@1913
   140
#endif
slouken@1895
   141
slouken@1895
   142
    device->free = WIN_DeleteDevice;
slouken@1895
   143
slouken@1895
   144
    return device;
slouken@1895
   145
}
slouken@1895
   146
slouken@1895
   147
VideoBootStrap WIN32_bootstrap = {
slouken@2710
   148
    "win32", "SDL Win32/64 video driver", WIN_Available, WIN_CreateDevice
slouken@1895
   149
};
slouken@1895
   150
slouken@1895
   151
slouken@1895
   152
int
slouken@1895
   153
WIN_VideoInit(_THIS)
slouken@1895
   154
{
slouken@1895
   155
    WIN_InitModes(_this);
slouken@1895
   156
slouken@1905
   157
#if SDL_VIDEO_RENDER_D3D
slouken@1905
   158
    D3D_AddRenderDriver(_this);
slouken@1905
   159
#endif
slouken@1895
   160
#if SDL_VIDEO_RENDER_GDI
slouken@1895
   161
    GDI_AddRenderDriver(_this);
slouken@1895
   162
#endif
slouken@1895
   163
slouken@2710
   164
    g_hCtx = SDL_malloc(sizeof(HCTX));
slouken@1895
   165
    WIN_InitKeyboard(_this);
slouken@1895
   166
    WIN_InitMouse(_this);
slouken@1895
   167
slouken@1895
   168
    return 0;
slouken@1895
   169
}
slouken@1895
   170
slouken@1895
   171
void
slouken@1895
   172
WIN_VideoQuit(_THIS)
slouken@1895
   173
{
slouken@1895
   174
    WIN_QuitModes(_this);
slouken@1895
   175
    WIN_QuitKeyboard(_this);
slouken@1895
   176
    WIN_QuitMouse(_this);
slouken@2710
   177
    SDL_free(g_hCtx);
slouken@1895
   178
}
slouken@1895
   179
slouken@1895
   180
/* vim: set ts=4 sw=4 expandtab: */