src/video/win32/SDL_win32video.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 17 Jul 2006 06:47:33 +0000
changeset 1913 83420da906a5
parent 1905 36d52b1f0504
child 1936 83946ee0ff1f
permissions -rw-r--r--
Implemented Windows OpenGL support
Fixed slowdown enumerating display modes, which was hosing OpenGL as well...
Removed SDL_ from the render driver prefixes
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@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@1895
    58
    SDL_free(device->driverdata);
slouken@1895
    59
    SDL_free(device);
slouken@1895
    60
}
slouken@1895
    61
slouken@1895
    62
static SDL_VideoDevice *
slouken@1895
    63
WIN_CreateDevice(int devindex)
slouken@1895
    64
{
slouken@1895
    65
    SDL_VideoDevice *device;
slouken@1895
    66
    SDL_VideoData *data;
slouken@1895
    67
slouken@1895
    68
    SDL_RegisterApp(NULL, 0, NULL);
slouken@1895
    69
slouken@1895
    70
    /* Initialize all variables that we clean on shutdown */
slouken@1895
    71
    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
slouken@1895
    72
    if (device) {
slouken@1895
    73
        data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
slouken@1895
    74
    }
slouken@1895
    75
    if (!device || !data) {
slouken@1895
    76
        SDL_OutOfMemory();
slouken@1895
    77
        if (device) {
slouken@1895
    78
            SDL_free(device);
slouken@1895
    79
        }
slouken@1895
    80
        return NULL;
slouken@1895
    81
    }
slouken@1895
    82
    device->driverdata = data;
slouken@1895
    83
slouken@1895
    84
#if SDL_VIDEO_RENDER_D3D
slouken@1895
    85
    data->d3dDLL = LoadLibrary(TEXT("D3D9.DLL"));
slouken@1895
    86
    if (data->d3dDLL) {
slouken@1895
    87
        IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
slouken@1895
    88
slouken@1895
    89
        D3DCreate =
slouken@1895
    90
            (IDirect3D9 * (WINAPI *) (UINT)) GetProcAddress(data->d3dDLL,
slouken@1895
    91
                                                            "Direct3DCreate9");
slouken@1895
    92
        if (D3DCreate) {
slouken@1895
    93
            data->d3d = D3DCreate(D3D_SDK_VERSION);
slouken@1895
    94
        }
slouken@1895
    95
        if (!data->d3d) {
slouken@1895
    96
            FreeLibrary(data->d3dDLL);
slouken@1895
    97
            data->d3dDLL = NULL;
slouken@1895
    98
        }
slouken@1895
    99
    }
slouken@1895
   100
#endif /* SDL_VIDEO_RENDER_D3D */
slouken@1895
   101
slouken@1895
   102
    /* Set the function pointers */
slouken@1895
   103
    device->VideoInit = WIN_VideoInit;
slouken@1913
   104
    device->VideoQuit = WIN_VideoQuit;
slouken@1895
   105
    device->GetDisplayModes = WIN_GetDisplayModes;
slouken@1895
   106
    device->SetDisplayMode = WIN_SetDisplayMode;
slouken@1895
   107
    device->SetDisplayGammaRamp = WIN_SetDisplayGammaRamp;
slouken@1895
   108
    device->GetDisplayGammaRamp = WIN_GetDisplayGammaRamp;
slouken@1895
   109
    device->PumpEvents = WIN_PumpEvents;
slouken@1895
   110
slouken@1895
   111
#undef CreateWindow
slouken@1895
   112
    device->CreateWindow = WIN_CreateWindow;
slouken@1895
   113
    device->CreateWindowFrom = WIN_CreateWindowFrom;
slouken@1895
   114
    device->SetWindowTitle = WIN_SetWindowTitle;
slouken@1895
   115
    device->SetWindowPosition = WIN_SetWindowPosition;
slouken@1895
   116
    device->SetWindowSize = WIN_SetWindowSize;
slouken@1895
   117
    device->ShowWindow = WIN_ShowWindow;
slouken@1895
   118
    device->HideWindow = WIN_HideWindow;
slouken@1895
   119
    device->RaiseWindow = WIN_RaiseWindow;
slouken@1895
   120
    device->MaximizeWindow = WIN_MaximizeWindow;
slouken@1895
   121
    device->MinimizeWindow = WIN_MinimizeWindow;
slouken@1895
   122
    device->RestoreWindow = WIN_RestoreWindow;
slouken@1895
   123
    device->SetWindowGrab = WIN_SetWindowGrab;
slouken@1895
   124
    device->DestroyWindow = WIN_DestroyWindow;
slouken@1895
   125
    device->GetWindowWMInfo = WIN_GetWindowWMInfo;
slouken@1913
   126
#ifdef SDL_VIDEO_OPENGL
slouken@1913
   127
    device->GL_LoadLibrary = WIN_GL_LoadLibrary;
slouken@1913
   128
    device->GL_GetProcAddress = WIN_GL_GetProcAddress;
slouken@1913
   129
    device->GL_GetWindowAttribute = WIN_GL_GetWindowAttribute;
slouken@1913
   130
    device->GL_CreateContext = WIN_GL_CreateContext;
slouken@1913
   131
    device->GL_MakeCurrent = WIN_GL_MakeCurrent;
slouken@1913
   132
    device->GL_SetSwapInterval = WIN_GL_SetSwapInterval;
slouken@1913
   133
    device->GL_GetSwapInterval = WIN_GL_GetSwapInterval;
slouken@1913
   134
    device->GL_SwapWindow = WIN_GL_SwapWindow;
slouken@1913
   135
    device->GL_DeleteContext = WIN_GL_DeleteContext;
slouken@1913
   136
#endif
slouken@1895
   137
slouken@1895
   138
    device->free = WIN_DeleteDevice;
slouken@1895
   139
slouken@1895
   140
    return device;
slouken@1895
   141
}
slouken@1895
   142
slouken@1895
   143
VideoBootStrap WIN32_bootstrap = {
slouken@1895
   144
    "win32", "SDL Win32/64 video driver",
slouken@1895
   145
    WIN_Available, WIN_CreateDevice
slouken@1895
   146
};
slouken@1895
   147
slouken@1895
   148
slouken@1895
   149
int
slouken@1895
   150
WIN_VideoInit(_THIS)
slouken@1895
   151
{
slouken@1895
   152
    WIN_InitModes(_this);
slouken@1895
   153
slouken@1905
   154
#if SDL_VIDEO_RENDER_D3D
slouken@1905
   155
    D3D_AddRenderDriver(_this);
slouken@1905
   156
#endif
slouken@1895
   157
#if SDL_VIDEO_RENDER_GDI
slouken@1895
   158
    GDI_AddRenderDriver(_this);
slouken@1895
   159
#endif
slouken@1895
   160
slouken@1895
   161
    WIN_InitKeyboard(_this);
slouken@1895
   162
    WIN_InitMouse(_this);
slouken@1895
   163
slouken@1895
   164
    return 0;
slouken@1895
   165
}
slouken@1895
   166
slouken@1895
   167
void
slouken@1895
   168
WIN_VideoQuit(_THIS)
slouken@1895
   169
{
slouken@1895
   170
    WIN_QuitModes(_this);
slouken@1895
   171
    WIN_QuitKeyboard(_this);
slouken@1895
   172
    WIN_QuitMouse(_this);
slouken@1895
   173
}
slouken@1895
   174
slouken@1895
   175
/* vim: set ts=4 sw=4 expandtab: */