/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
#ifndef __RW_WIN_H__
#define __RW_WIN_H__

#ifdef USE_DDRAW
#include <ddraw.h>
#endif /* USE_DDRAW */

#ifndef PC_NOCOLLAPSE
#define PC_NOCOLLAPSE	0
#endif

#ifdef _WIN32_WCE
#endif /* _WIN32_WCE */

typedef struct {
	HDC				hDC;				// global DC we're using
	HWND			hWnd;				// HWND of parent window

	HDC				hdcDIBSection;		// DC compatible with DIB section
	HBITMAP			hDIBSection;		// DIB section
	byte			*pDIBBase;			// DIB base pointer, NOT used directly for rendering!

#ifdef _WIN32_WCE
	HINSTANCE		hinstGX;
	qboolean		displayOpened;
	qboolean		displayGrabbed;
	uint16			*surfaceStart, *surfaceEnd;
#else /* _WIN32_WCE */
	HPALETTE		hPal;				// palette we're using
	HPALETTE		hpalOld;			// original system palette
	COLORREF		oldsyscolors[20];	// original system colors
#endif /* !_WIN32_WCE */

#ifdef USE_DDRAW
	HINSTANCE		hinstDDRAW;			// library instance for DDRAW.DLL
	LPDIRECTDRAW 	lpDirectDraw;		// pointer to DirectDraw object

	LPDIRECTDRAWSURFACE lpddsFrontBuffer;	// video card display memory front buffer
	LPDIRECTDRAWSURFACE lpddsBackBuffer;	// system memory backbuffer
	LPDIRECTDRAWSURFACE lpddsOffScreenBuffer;	// system memory backbuffer
	LPDIRECTDRAWPALETTE	lpddpPalette;		// DirectDraw palette
#endif /* USE_DDRAW */

	qboolean		palettized;			// qtrue if desktop is paletted
	qboolean		modex;

	vidFlags_t	flags;

	int				width;
	int				height;

	byte			*buffer;
	int				rowbytes;
} swwstate_t;

extern swwstate_t sww_state;

/*
** DIB code
*/
qboolean DIB_Init( byte **ppbuffer, int *ppitch, const byte *palette );
void     DIB_Shutdown( void );
void     DIB_SetPalette( const byte *palette );

#ifdef USE_DDRAW
qboolean	DDRAW_Init( byte **ppbuffer, int *ppitch, const byte *palette );
void	DDRAW_FatalShutdown( void );
void	DDRAW_Shutdown( void );
void	DDRAW_SetPalette( const byte *palette );
void	DDRAW_EndFrame( byte **buffer, int *rowbytes ) ;
#endif /* USE_DDRAW */

#endif
