Commit dc312617 authored by Sam Lantinga's avatar Sam Lantinga

The old windows video drivers are superceded by the unified win32 driver.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401989
parent bd9931af
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifndef _SDL_lowvideo_h
#define _SDL_lowvideo_h
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#ifndef SetClassLongPtr
#define SetClassLongPtr SetClassLong
#endif
#ifndef GetWindowLongPtr
#define GetWindowLongPtr GetWindowLong
#endif
#ifndef SetWindowLongPtr
#define SetWindowLongPtr SetWindowLong
#endif
#ifndef GWLP_WNDPROC
#define GWLP_WNDPROC GWL_WNDPROC
#endif
#ifndef GCLP_HICON
#define GCLP_HICON GCL_HICON
#endif
#include "../SDL_sysvideo.h"
/* Hidden "this" pointer for the video functions */
#define _THIS SDL_VideoDevice *this
#define WINDIB_FULLSCREEN() \
( \
SDL_VideoSurface && \
(SDL_VideoSurface->flags & SDL_FULLSCREEN) && \
((SDL_VideoSurface->flags & SDL_INTERNALOPENGL) || \
((SDL_strcmp(this->name, "windib") == 0) || \
(SDL_strcmp(this->name, "gapi") == 0))) \
)
#define DDRAW_FULLSCREEN() \
( \
SDL_VideoSurface && \
(SDL_VideoSurface->flags & SDL_FULLSCREEN) && \
(SDL_VideoSurface->flags & SDL_INTERNALOPENGL) && \
(SDL_strcmp(this->name, "directx") == 0) \
)
#define DINPUT_FULLSCREEN() DDRAW_FULLSCREEN()
/* The main window -- and a function to set it for the audio */
#ifdef _WIN32_WCE
extern LPWSTR SDL_Appname;
#else
extern LPSTR SDL_Appname;
#endif
extern HINSTANCE SDL_Instance;
extern HWND SDL_Window;
extern BOOL SDL_windowid;
/* Variables and functions exported to other parts of the native video
subsystem (SDL_sysevents.c)
*/
extern void WIN_FlushMessageQueue();
/* Called by windows message loop when system palette is available */
extern void (*WIN_RealizePalette) (_THIS);
/* Called by windows message loop when the system palette changes */
extern void (*WIN_PaletteChanged) (_THIS, HWND window);
/* Called by windows message loop when a portion of the screen needs update */
extern void (*WIN_WinPAINT) (_THIS, HDC hdc);
/* Called by windows message loop when the message isn't handled */
extern LONG(*HandleMessage) (_THIS, HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam);
/* The window cursor (from SDL_sysmouse.c) */
extern HCURSOR SDL_hcursor;
/* The bounds of the window in screen coordinates */
extern RECT SDL_bounds;
/* The position of the window in windowed mode */
extern int SDL_windowX;
extern int SDL_windowY;
/* Flag -- SDL is performing a resize, rather than the user */
extern int SDL_resizing;
/* Flag -- the mouse is in relative motion mode */
extern int mouse_relative;
/* The GDI fullscreen mode currently active */
#ifndef NO_CHANGEDISPLAYSETTINGS
extern DEVMODE SDL_desktop_mode;
extern DEVMODE SDL_fullscreen_mode;
#endif
/* The system gamma ramp for GDI modes */
extern WORD *gamma_saved;
/* This is really from SDL_dx5audio.c */
extern void DX5_SoundFocus(HWND window);
/* DJM: This is really from SDL_sysevents.c, we need it in
GDL_CreateWindow as well */
LRESULT CALLBACK WinMessage(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam);
/* JFP: Implementation of ToUnicode() that works on 9x/ME/2K/XP */
typedef int (WINAPI * ToUnicodeFN) (UINT, UINT, PBYTE, LPWSTR, int, UINT);
extern ToUnicodeFN SDL_ToUnicode;
#endif /* SDL_lowvideo_h */
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "SDL_mouse.h"
#include "../../events/SDL_events_c.h"
#include "../SDL_cursor_c.h"
#include "SDL_sysmouse_c.h"
#include "SDL_lowvideo.h"
#ifdef _WIN32_WCE
#define USE_STATIC_CURSOR
#endif
HCURSOR SDL_hcursor = NULL; /* Exported for SDL_eventloop.c */
/* The implementation dependent data for the window manager cursor */
/* For some reason when creating a windows cursor, the ands and xors memory
is not copied, so we need to keep track of it and free it when we are done
with the cursor. If we free the memory prematurely, the app crashes. :-}
*/
struct WMcursor
{
HCURSOR curs;
#ifndef USE_STATIC_CURSOR
Uint8 *ands;
Uint8 *xors;
#endif
};
/* Convert bits to padded bytes */
#define PAD_BITS(bits) ((bits+7)/8)
#ifdef CURSOR_DEBUG
static void
PrintBITMAP(FILE * out, char *bits, int w, int h)
{
int i;
unsigned char ch;
while (h-- > 0) {
for (i = 0; i < w; ++i) {
if ((i % 8) == 0)
ch = *bits++;
if (ch & 0x80)
fprintf(out, "X");
else
fprintf(out, " ");
ch <<= 1;
}
fprintf(out, "\n");
}
}
#endif
#ifndef USE_STATIC_CURSOR
/* Local functions to convert the SDL cursor mask into Windows format */
static void
memnot(Uint8 * dst, Uint8 * src, int len)
{
while (len-- > 0)
*dst++ = ~*src++;
}
static void
memxor(Uint8 * dst, Uint8 * src1, Uint8 * src2, int len)
{
while (len-- > 0)
*dst++ = (*src1++) ^ (*src2++);
}
#endif /* !USE_STATIC_CURSOR */
void
WIN_FreeWMCursor(_THIS, WMcursor * cursor)
{
#ifndef USE_STATIC_CURSOR
if (cursor->curs == GetCursor())
SetCursor(NULL);
if (cursor->curs != NULL)
DestroyCursor(cursor->curs);
if (cursor->ands != NULL)
SDL_free(cursor->ands);
if (cursor->xors != NULL)
SDL_free(cursor->xors);
#endif /* !USE_STATIC_CURSOR */
SDL_free(cursor);
}
WMcursor *
WIN_CreateWMCursor(_THIS,
Uint8 * data, Uint8 * mask, int w, int h, int hot_x,
int hot_y)
{
#ifdef USE_STATIC_CURSOR
WMcursor *cursor;
/* Allocate the cursor */
cursor = (WMcursor *) SDL_malloc(sizeof(*cursor));
if (cursor) {
cursor->curs = LoadCursor(NULL, IDC_ARROW);
}
return (cursor);
#else
WMcursor *cursor;
int allowed_x;
int allowed_y;
int run, pad, i;
Uint8 *aptr, *xptr;
/* Check to make sure the cursor size is okay */
allowed_x = GetSystemMetrics(SM_CXCURSOR);
allowed_y = GetSystemMetrics(SM_CYCURSOR);
if ((w > allowed_x) || (h > allowed_y)) {
SDL_SetError("Only cursors of dimension (%dx%d) are allowed",
allowed_x, allowed_y);
return (NULL);
}
/* Allocate the cursor */
cursor = (WMcursor *) SDL_malloc(sizeof(*cursor));
if (cursor == NULL) {
SDL_SetError("Out of memory");
return (NULL);
}
cursor->curs = NULL;
cursor->ands = NULL;
cursor->xors = NULL;
/* Pad out to the normal cursor size */
run = PAD_BITS(w);
pad = PAD_BITS(allowed_x) - run;
aptr = cursor->ands = (Uint8 *) SDL_malloc((run + pad) * allowed_y);
xptr = cursor->xors = (Uint8 *) SDL_malloc((run + pad) * allowed_y);
if ((aptr == NULL) || (xptr == NULL)) {
WIN_FreeWMCursor(NULL, cursor);
SDL_OutOfMemory();
return (NULL);
}
for (i = 0; i < h; ++i) {
memxor(xptr, data, mask, run);
xptr += run;
data += run;
memnot(aptr, mask, run);
mask += run;
aptr += run;
SDL_memset(xptr, 0, pad);
xptr += pad;
SDL_memset(aptr, ~0, pad);
aptr += pad;
}
pad += run;
for (; i < allowed_y; ++i) {
SDL_memset(xptr, 0, pad);
xptr += pad;
SDL_memset(aptr, ~0, pad);
aptr += pad;
}
/* Create the cursor */
cursor->curs = CreateCursor((HINSTANCE)
GetWindowLongPtr(SDL_Window,
GWLP_HINSTANCE), hot_x,
hot_y, allowed_x, allowed_y, cursor->ands,
cursor->xors);
if (cursor->curs == NULL) {
WIN_FreeWMCursor(NULL, cursor);
SDL_SetError("Windows couldn't create the requested cursor");
return (NULL);
}
return (cursor);
#endif /* USE_STATIC_CURSOR */
}
int
WIN_ShowWMCursor(_THIS, WMcursor * cursor)
{
POINT mouse_pos;
/* The fullscreen cursor must be done in software with DirectInput */
if (!this->screen || DDRAW_FULLSCREEN()) {
return (0);
}
/* Set the window cursor to our cursor, if applicable */
if (cursor != NULL) {
SDL_hcursor = cursor->curs;
} else {
SDL_hcursor = NULL;
}
GetCursorPos(&mouse_pos);
if (PtInRect(&SDL_bounds, mouse_pos)) {
SetCursor(SDL_hcursor);
}
return (1);
}
void
WIN_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
{
if (DDRAW_FULLSCREEN()) {
SDL_PrivateMouseMotion(0, 0, x, y);
} else if (mouse_relative) {
/* RJR: March 28, 2000
leave physical cursor at center of screen if
mouse hidden and grabbed */
SDL_PrivateMouseMotion(0, 0, x, y);
} else {
POINT pt;
pt.x = x;
pt.y = y;
ClientToScreen(SDL_Window, &pt);
SetCursorPos(pt.x, pt.y);
}
}
/* Update the current mouse state and position */
void
WIN_UpdateMouse(_THIS)
{
RECT rect;
POINT pt;
if (!DDRAW_FULLSCREEN()) {
GetClientRect(SDL_Window, &rect);
GetCursorPos(&pt);
MapWindowPoints(NULL, SDL_Window, &pt, 1);
if (PtInRect(&rect, pt) && (WindowFromPoint(pt) == SDL_Window)) {
SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
SDL_PrivateMouseMotion(0, 0, (Sint16) pt.x, (Sint16) pt.y);
} else {
SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
}
}
}
/* Check to see if we need to enter or leave mouse relative mode */
void
WIN_CheckMouseMode(_THIS)
{
#ifndef _WIN32_WCE
/* If the mouse is hidden and input is grabbed, we use relative mode */
if (!(SDL_cursorstate & CURSOR_VISIBLE) &&
(this->input_grab != SDL_GRAB_OFF)) {
mouse_relative = 1;
} else {
mouse_relative = 0;
}
#else
mouse_relative = 0;
#endif
}
/* vi: set ts=4 sw=4 expandtab: */
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#include "SDL_lowvideo.h"
/* Functions to be exported */
extern void WIN_FreeWMCursor(_THIS, WMcursor * cursor);
extern WMcursor *WIN_CreateWMCursor(_THIS,
Uint8 * data, Uint8 * mask, int w, int h,
int hot_x, int hot_y);
extern int WIN_ShowWMCursor(_THIS, WMcursor * cursor);
extern void WIN_WarpWMCursor(_THIS, Uint16 x, Uint16 y);
extern void WIN_UpdateMouse(_THIS);
extern void WIN_CheckMouseMode(_THIS);
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#include "SDL_lowvideo.h"
/* Data that needs to be freed at SDL_SYS_VideoQuit() */
extern HICON screen_icn;
/* Functions to be exported */
extern void WIN_SetWMIcon(_THIS, SDL_Surface * icon, Uint8 * mask);
extern void WIN_SetWMCaption(_THIS, const char *title, const char *icon);
extern int WIN_IconifyWindow(_THIS);
extern SDL_GrabMode WIN_GrabInput(_THIS, SDL_GrabMode mode);
extern int WIN_GetWMInfo(_THIS, SDL_SysWMinfo * info);
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/* WGL implementation of SDL OpenGL support */
#include "../SDL_sysvideo.h"
struct SDL_PrivateGLData
{
int gl_active; /* to stop switching drivers while we have a valid context */
#if SDL_VIDEO_OPENGL
PIXELFORMATDESCRIPTOR GL_pfd;
HDC GL_hdc;
HGLRC GL_hrc;
int pixel_format;
int WGL_ARB_pixel_format;
void *(WINAPI * wglGetProcAddress) (const char *proc);
HGLRC(WINAPI * wglCreateContext) (HDC hdc);
BOOL(WINAPI * wglDeleteContext) (HGLRC hglrc);
BOOL(WINAPI * wglMakeCurrent) (HDC hdc, HGLRC hglrc);
BOOL(WINAPI * wglChoosePixelFormatARB) (HDC hdc,
const int *piAttribIList,
const FLOAT * pfAttribFList,
UINT nMaxFormats,
int *piFormats,
UINT * nNumFormats);
BOOL(WINAPI * wglGetPixelFormatAttribivARB) (HDC hdc, int iPixelFormat,
int iLayerPlane,
UINT nAttributes,
const int *piAttributes,
int *piValues);
void (WINAPI * wglSwapIntervalEXT) (int interval);
int (WINAPI * wglGetSwapIntervalEXT) (void);
#endif /* SDL_VIDEO_OPENGL */
};
/* Old variable names */
#define gl_active (this->gl_data->gl_active)
#define GL_pfd (this->gl_data->GL_pfd)
#define GL_hdc (this->gl_data->GL_hdc)
#define GL_hrc (this->gl_data->GL_hrc)
#define pixel_format (this->gl_data->pixel_format)
/* OpenGL functions */
extern int WIN_GL_SetupWindow(_THIS);
extern void WIN_GL_ShutDown(_THIS);
#if SDL_VIDEO_OPENGL
extern int WIN_GL_MakeCurrent(_THIS);
extern int WIN_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
extern void WIN_GL_SwapBuffers(_THIS);
extern void WIN_GL_UnloadLibrary(_THIS);
extern int WIN_GL_LoadLibrary(_THIS, const char *path);
extern void *WIN_GL_GetProcAddress(_THIS, const char *proc);
#endif
#if SDL_VIDEO_OPENGL
#ifndef WGL_ARB_pixel_format
#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
#define WGL_DRAW_TO_BITMAP_ARB 0x2002
#define WGL_ACCELERATION_ARB 0x2003
#define WGL_NEED_PALETTE_ARB 0x2004
#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
#define WGL_SWAP_METHOD_ARB 0x2007
#define WGL_NUMBER_OVERLAYS_ARB 0x2008
#define WGL_NUMBER_UNDERLAYS_ARB 0x2009
#define WGL_TRANSPARENT_ARB 0x200A
#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
#define WGL_SHARE_DEPTH_ARB 0x200C
#define WGL_SHARE_STENCIL_ARB 0x200D
#define WGL_SHARE_ACCUM_ARB 0x200E
#define WGL_SUPPORT_GDI_ARB 0x200F
#define WGL_SUPPORT_OPENGL_ARB 0x2010
#define WGL_DOUBLE_BUFFER_ARB 0x2011
#define WGL_STEREO_ARB 0x2012
#define WGL_PIXEL_TYPE_ARB 0x2013
#define WGL_COLOR_BITS_ARB 0x2014
#define WGL_RED_BITS_ARB 0x2015
#define WGL_RED_SHIFT_ARB 0x2016
#define WGL_GREEN_BITS_ARB 0x2017
#define WGL_GREEN_SHIFT_ARB 0x2018
#define WGL_BLUE_BITS_ARB 0x2019
#define WGL_BLUE_SHIFT_ARB 0x201A
#define WGL_ALPHA_BITS_ARB 0x201B
#define WGL_ALPHA_SHIFT_ARB 0x201C
#define WGL_ACCUM_BITS_ARB 0x201D
#define WGL_ACCUM_RED_BITS_ARB 0x201E
#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
#define WGL_DEPTH_BITS_ARB 0x2022
#define WGL_STENCIL_BITS_ARB 0x2023
#define WGL_AUX_BUFFERS_ARB 0x2024
#define WGL_NO_ACCELERATION_ARB 0x2025
#define WGL_GENERIC_ACCELERATION_ARB 0x2026
#define WGL_FULL_ACCELERATION_ARB 0x2027
#define WGL_SWAP_EXCHANGE_ARB 0x2028
#define WGL_SWAP_COPY_ARB 0x2029
#define WGL_SWAP_UNDEFINED_ARB 0x202A
#define WGL_TYPE_RGBA_ARB 0x202B
#define WGL_TYPE_COLORINDEX_ARB 0x202C
#endif
#ifndef WGL_ARB_multisample
#define WGL_SAMPLE_BUFFERS_ARB 0x2041
#define WGL_SAMPLES_ARB 0x2042
#endif
#endif
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#include "../wincommon/SDL_lowvideo.h"
/* Variables and functions exported by SDL_dibevents.c to other parts
of the native video subsystem (SDL_dibvideo.c)
*/
extern LONG
DIB_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
extern int DIB_CreateWindow(_THIS);
extern void DIB_DestroyWindow(_THIS);
extern void DIB_PumpEvents(_THIS);
extern void DIB_InitOSKeymap(_THIS);
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifndef _SDL_dibvideo_h
#define _SDL_dibvideo_h
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* for PDA */
typedef enum
{
SDL_ORIENTATION_UP,
SDL_ORIENTATION_DOWN,
SDL_ORIENTATION_LEFT,
SDL_ORIENTATION_RIGHT
} SDL_ScreenOrientation;
/* Private display data */
struct SDL_PrivateVideoData
{
HBITMAP screen_bmp;
HPALETTE screen_pal;
#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */
int SDL_nummodes[NUM_MODELISTS];
SDL_Rect **SDL_modelist[NUM_MODELISTS];
SDL_ScreenOrientation orientation;
#ifdef _WIN32_WCE
int invert; /* do to remove, used by GAPI driver! */
char hiresFix; /* using hires mode without defining hires resource */
int supportRotation; /* for Pocket PC devices */
DWORD origRotation; /* for Pocket PC devices */
#endif
};
/* Old variable names */
#define screen_bmp (this->hidden->screen_bmp)
#define screen_pal (this->hidden->screen_pal)
#define SDL_nummodes (this->hidden->SDL_nummodes)
#define SDL_modelist (this->hidden->SDL_modelist)
#endif /* _SDL_dibvideo_h */
/* vi: set ts=4 sw=4 expandtab: */
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#ifndef VK_0
#define VK_0 '0'
#define VK_1 '1'
#define VK_2 '2'
#define VK_3 '3'
#define VK_4 '4'
#define VK_5 '5'
#define VK_6 '6'
#define VK_7 '7'
#define VK_8 '8'
#define VK_9 '9'
#define VK_A 'A'
#define VK_B 'B'
#define VK_C 'C'
#define VK_D 'D'
#define VK_E 'E'
#define VK_F 'F'
#define VK_G 'G'
#define VK_H 'H'
#define VK_I 'I'
#define VK_J 'J'
#define VK_K 'K'
#define VK_L 'L'
#define VK_M 'M'
#define VK_N 'N'
#define VK_O 'O'
#define VK_P 'P'
#define VK_Q 'Q'
#define VK_R 'R'
#define VK_S 'S'
#define VK_T 'T'
#define VK_U 'U'
#define VK_V 'V'
#define VK_W 'W'
#define VK_X 'X'
#define VK_Y 'Y'
#define VK_Z 'Z'
#endif /* VK_0 */
/* These keys haven't been defined, but were experimentally determined */
#define VK_SEMICOLON 0xBA
#define VK_EQUALS 0xBB
#define VK_COMMA 0xBC
#define VK_MINUS 0xBD
#define VK_PERIOD 0xBE
#define VK_SLASH 0xBF
#define VK_GRAVE 0xC0
#define VK_LBRACKET 0xDB
#define VK_BACKSLASH 0xDC
#define VK_RBRACKET 0xDD
#define VK_APOSTROPHE 0xDE
#define VK_BACKTICK 0xDF
#define VK_OEM_102 0xE2
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#include "../wincommon/SDL_lowvideo.h"
/* Variables and functions exported by SDL_dx5events.c to other parts
of the native video subsystem (SDL_dx5video.c)
*/
extern LONG
DX5_HandleMessage(_THIS, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
extern int DX5_CreateWindow(_THIS);
extern void DX5_DestroyWindow(_THIS);
extern void DX5_PumpEvents(_THIS);
extern void DX5_InitOSKeymap(_THIS);
extern void DX5_DInputReset(_THIS, int fullscreen);
/* vi: set ts=4 sw=4 expandtab: */
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
#ifndef _SDL_dx5video_h
#define _SDL_dx5video_h
#include "directx.h"
/* Private display data */
struct SDL_PrivateVideoData
{
LPDIRECTDRAW2 ddraw2;
LPDIRECTDRAWSURFACE3 SDL_primary;
LPDIRECTDRAWCLIPPER SDL_clipper;
LPDIRECTDRAWPALETTE SDL_palette;
PALETTEENTRY SDL_colors[256];
int colorchange_expected;
#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */
int SDL_nummodes[NUM_MODELISTS];
SDL_Rect **SDL_modelist[NUM_MODELISTS];
int SDL_modeindex[NUM_MODELISTS];
};
/* Old variable names */
#define ddraw2 (this->hidden->ddraw2)
#define SDL_primary (this->hidden->SDL_primary)
#define SDL_clipper (this->hidden->SDL_clipper)
#define SDL_palette (this->hidden->SDL_palette)
#define SDL_colors (this->hidden->SDL_colors)
#define colorchange_expected (this->hidden->colorchange_expected)
#define SDL_nummodes (this->hidden->SDL_nummodes)
#define SDL_modelist (this->hidden->SDL_modelist)
#define SDL_modeindex (this->hidden->SDL_modeindex)
/* DirectX function pointers for video and events */
extern HRESULT(WINAPI * DDrawCreate) (GUID FAR * lpGUID,
LPDIRECTDRAW FAR * lplpDD,
IUnknown FAR * pUnkOuter);
extern HRESULT(WINAPI * DInputCreate) (HINSTANCE hinst, DWORD dwVersion,
LPDIRECTINPUT * ppDI,
LPUNKNOWN punkOuter);
/* DirectDraw error reporting function */
extern void SetDDerror(const char *function, int code);
#endif /* _SDL_dx5video_h */
/* vi: set ts=4 sw=4 expandtab: */
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/* This is the DirectDraw implementation of YUV video overlays */
#include "SDL_video.h"
#include "SDL_dx5yuv_c.h"
#include "../SDL_yuvfuncs.h"
//#define USE_DIRECTX_OVERLAY
/* The functions used to manipulate software video overlays */
static struct private_yuvhwfuncs dx5_yuvfuncs = {
DX5_LockYUVOverlay,
DX5_UnlockYUVOverlay,
DX5_DisplayYUVOverlay,
DX5_FreeYUVOverlay
};
struct private_yuvhwdata
{
LPDIRECTDRAWSURFACE3 surface;
/* These are just so we don't have to allocate them separately */
Uint16 pitches[3];
Uint8 *planes[3];
};
static LPDIRECTDRAWSURFACE3
CreateYUVSurface(_THIS, int width, int height, Uint32 format)
{
HRESULT result;
LPDIRECTDRAWSURFACE dd_surface1;
LPDIRECTDRAWSURFACE3 dd_surface3;
DDSURFACEDESC ddsd;
/* Set up the surface description */
SDL_memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = (DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_PIXELFORMAT);
ddsd.dwWidth = width;
ddsd.dwHeight = height;
#ifdef USE_DIRECTX_OVERLAY
ddsd.ddsCaps.dwCaps = (DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY);
#else
ddsd.ddsCaps.dwCaps = (DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY);
#endif
ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat);
ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC;
ddsd.ddpfPixelFormat.dwFourCC = format;
/* Create the DirectDraw video surface */
result = IDirectDraw2_CreateSurface(ddraw2, &ddsd, &dd_surface1, NULL);
if (result != DD_OK) {
SetDDerror("DirectDraw2::CreateSurface", result);
return (NULL);
}
result = IDirectDrawSurface_QueryInterface(dd_surface1,
&IID_IDirectDrawSurface3,
(LPVOID *) & dd_surface3);
IDirectDrawSurface_Release(dd_surface1);
if (result != DD_OK) {
SetDDerror("DirectDrawSurface::QueryInterface", result);
return (NULL);
}
/* Make sure the surface format was set properly */
SDL_memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
result = IDirectDrawSurface3_Lock(dd_surface3, NULL,
&ddsd, DDLOCK_NOSYSLOCK, NULL);
if (result != DD_OK) {
SetDDerror("DirectDrawSurface3::Lock", result);
IDirectDrawSurface_Release(dd_surface3);
return (NULL);
}
IDirectDrawSurface3_Unlock(dd_surface3, NULL);
if (!(ddsd.ddpfPixelFormat.dwFlags & DDPF_FOURCC) ||
(ddsd.ddpfPixelFormat.dwFourCC != format)) {
SDL_SetError("DDraw didn't use requested FourCC format");
IDirectDrawSurface_Release(dd_surface3);
return (NULL);
}
/* We're ready to go! */
return (dd_surface3);
}
#ifdef DEBUG_YUV
static char *
PrintFOURCC(Uint32 code)
{
static char buf[5];
buf[3] = code >> 24;
buf[2] = (code >> 16) & 0xFF;
buf[1] = (code >> 8) & 0xFF;
buf[0] = (code & 0xFF);
return (buf);
}
#endif
SDL_Overlay *
DX5_CreateYUVOverlay(_THIS, int width, int height, Uint32 format,
SDL_Surface * display)
{
SDL_Overlay *overlay;
struct private_yuvhwdata *hwdata;
#ifdef DEBUG_YUV
DWORD numcodes;
DWORD *codes;
printf("FOURCC format requested: 0x%x\n", PrintFOURCC(format));
IDirectDraw2_GetFourCCCodes(ddraw2, &numcodes, NULL);
if (numcodes) {
DWORD i;
codes = SDL_malloc(numcodes * sizeof(*codes));
if (codes) {
IDirectDraw2_GetFourCCCodes(ddraw2, &numcodes, codes);
for (i = 0; i < numcodes; ++i) {
fprintf(stderr, "Code %d: 0x%x\n", i, PrintFOURCC(codes[i]));
}
SDL_free(codes);
}
} else {
fprintf(stderr, "No FOURCC codes supported\n");
}
#endif
/* Create the overlay structure */
overlay = (SDL_Overlay *) SDL_malloc(sizeof *overlay);
if (overlay == NULL) {
SDL_OutOfMemory();
return (NULL);
}
SDL_memset(overlay, 0, (sizeof *overlay));
/* Fill in the basic members */
overlay->format = format;
overlay->w = width;
overlay->h = height;
/* Set up the YUV surface function structure */
overlay->hwfuncs = &dx5_yuvfuncs;
/* Create the pixel data and lookup tables */
hwdata = (struct private_yuvhwdata *) SDL_malloc(sizeof *hwdata);
overlay->hwdata = hwdata;
if (hwdata == NULL) {
SDL_OutOfMemory();
SDL_FreeYUVOverlay(overlay);
return (NULL);
}
hwdata->surface = CreateYUVSurface(this, width, height, format);
if (hwdata->surface == NULL) {
SDL_FreeYUVOverlay(overlay);
return (NULL);
}
overlay->hw_overlay = 1;
/* Set up the plane pointers */
overlay->pitches = hwdata->pitches;
overlay->pixels = hwdata->planes;
switch (format) {
case SDL_YV12_OVERLAY:
case SDL_IYUV_OVERLAY:
overlay->planes = 3;
break;
default:
overlay->planes = 1;
break;
}
/* We're all done.. */
return (overlay);
}
int
DX5_LockYUVOverlay(_THIS, SDL_Overlay * overlay)
{
HRESULT result;
LPDIRECTDRAWSURFACE3 surface;
DDSURFACEDESC ddsd;
surface = overlay->hwdata->surface;
SDL_memset(&ddsd, 0, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
result = IDirectDrawSurface3_Lock(surface, NULL,
&ddsd, DDLOCK_NOSYSLOCK, NULL);
if (result == DDERR_SURFACELOST) {
result = IDirectDrawSurface3_Restore(surface);
result = IDirectDrawSurface3_Lock(surface, NULL, &ddsd,
(DDLOCK_NOSYSLOCK | DDLOCK_WAIT),
NULL);
}
if (result != DD_OK) {
SetDDerror("DirectDrawSurface3::Lock", result);
return (-1);
}
/* Find the pitch and offset values for the overlay */
#if defined(NONAMELESSUNION)
overlay->pitches[0] = (Uint16) ddsd.u1.lPitch;
#else
overlay->pitches[0] = (Uint16) ddsd.lPitch;
#endif
overlay->pixels[0] = (Uint8 *) ddsd.lpSurface;
switch (overlay->format) {
case SDL_YV12_OVERLAY:
case SDL_IYUV_OVERLAY:
/* Add the two extra planes */
overlay->pitches[1] = overlay->pitches[0] / 2;
overlay->pitches[2] = overlay->pitches[0] / 2;
overlay->pixels[1] = overlay->pixels[0] +
overlay->pitches[0] * overlay->h;
overlay->pixels[2] = overlay->pixels[1] +
overlay->pitches[1] * overlay->h / 2;
break;
default:
/* Only one plane, no worries */
break;
}
return (0);
}
void
DX5_UnlockYUVOverlay(_THIS, SDL_Overlay * overlay)
{
LPDIRECTDRAWSURFACE3 surface;
surface = overlay->hwdata->surface;
IDirectDrawSurface3_Unlock(surface, NULL);
}
int
DX5_DisplayYUVOverlay(_THIS, SDL_Overlay * overlay, SDL_Rect * src,
SDL_Rect * dst)
{
HRESULT result;
LPDIRECTDRAWSURFACE3 surface;
RECT srcrect, dstrect;
surface = overlay->hwdata->surface;
srcrect.top = src->y;
srcrect.bottom = srcrect.top + src->h;
srcrect.left = src->x;
srcrect.right = srcrect.left + src->w;
dstrect.top = SDL_bounds.top + dst->y;
dstrect.left = SDL_bounds.left + dst->x;
dstrect.bottom = dstrect.top + dst->h;
dstrect.right = dstrect.left + dst->w;
#ifdef USE_DIRECTX_OVERLAY
result = IDirectDrawSurface3_UpdateOverlay(surface, &srcrect,
SDL_primary, &dstrect,
DDOVER_SHOW, NULL);
if (result != DD_OK) {
SetDDerror("DirectDrawSurface3::UpdateOverlay", result);
return (-1);
}
#else
result =
IDirectDrawSurface3_Blt(SDL_primary, &dstrect, surface, &srcrect,
DDBLT_WAIT, NULL);
if (result != DD_OK) {
SetDDerror("DirectDrawSurface3::Blt", result);
return (-1);
}
#endif
return (0);
}
void
DX5_FreeYUVOverlay(_THIS, SDL_Overlay * overlay)
{
struct private_yuvhwdata *hwdata;
hwdata = overlay->hwdata;
if (hwdata) {
if (hwdata->surface) {
IDirectDrawSurface_Release(hwdata->surface);
}
SDL_free(hwdata);
}
}
/* vi: set ts=4 sw=4 expandtab: */
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
#include "SDL_config.h"
/* This is the DirectDraw implementation of YUV video overlays */
#include "SDL_video.h"
#include "../wincommon/SDL_lowvideo.h"
#include "SDL_dx5video.h"
extern SDL_Overlay *DX5_CreateYUVOverlay(_THIS, int width, int height,
Uint32 format,
SDL_Surface * display);
extern int DX5_LockYUVOverlay(_THIS, SDL_Overlay * overlay);
extern void DX5_UnlockYUVOverlay(_THIS, SDL_Overlay * overlay);
extern int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay * overlay,
SDL_Rect * src, SDL_Rect * dst);
extern void DX5_FreeYUVOverlay(_THIS, SDL_Overlay * overlay);
/* vi: set ts=4 sw=4 expandtab: */
#ifndef _directx_h
#define _directx_h
/* Include all of the DirectX 5.0 headers and adds any necessary tweaks */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <mmsystem.h>
#ifndef WIN32
#define WIN32
#endif
#undef WINNT
/* Far pointers don't exist in 32-bit code */
#ifndef FAR
#define FAR
#endif
/* Error codes not yet included in Win32 API header files */
#ifndef MAKE_HRESULT
#define MAKE_HRESULT(sev,fac,code) \
((HRESULT)(((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))))
#endif
#ifndef S_OK
#define S_OK (HRESULT)0x00000000L
#endif
#ifndef SUCCEEDED
#define SUCCEEDED(x) ((HRESULT)(x) >= 0)
#endif
#ifndef FAILED
#define FAILED(x) ((HRESULT)(x)<0)
#endif
#ifndef E_FAIL
#define E_FAIL (HRESULT)0x80000008L
#endif
#ifndef E_NOINTERFACE
#define E_NOINTERFACE (HRESULT)0x80004002L
#endif
#ifndef E_OUTOFMEMORY
#define E_OUTOFMEMORY (HRESULT)0x8007000EL
#endif
#ifndef E_INVALIDARG
#define E_INVALIDARG (HRESULT)0x80070057L
#endif
#ifndef E_NOTIMPL
#define E_NOTIMPL (HRESULT)0x80004001L
#endif
#ifndef REGDB_E_CLASSNOTREG
#define REGDB_E_CLASSNOTREG (HRESULT)0x80040154L
#endif
/* Severity codes */
#ifndef SEVERITY_ERROR
#define SEVERITY_ERROR 1
#endif
/* Error facility codes */
#ifndef FACILITY_WIN32
#define FACILITY_WIN32 7
#endif
#ifndef FIELD_OFFSET
#define FIELD_OFFSET(type, field) ((LONG)&(((type *)0)->field))
#endif
/* DirectX headers (if it isn't included, I haven't tested it yet)
*/
/* We need these defines to mark what version of DirectX API we use */
#define DIRECTDRAW_VERSION 0x0700
#define DIRECTSOUND_VERSION 0x0500
#define DIRECTINPUT_VERSION 0x0500
#ifdef __GNUC__
#define NONAMELESSUNION
#endif
#include <ddraw.h>
#include <dsound.h>
#include <dinput.h>
#endif /* _directx_h */
/* vi: set ts=4 sw=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment