📄 ddgpesurf.cpp
字号:
#include "precomp.h"
#include "pwinbase.h"
//////////////////////////////////////////////////////////////////////////////////////////////
// DDGPESurf
//////////////////////////////////////////////////////////////////////////////////////////////
DDGPESurf::DDGPESurf(
int width,
int height,
void * pBits, // virtual address of allocated bits
int stride,
EGPEFormat format)
: GPESurf( width, height, pBits, stride, format )
{
m_ePixelFormat = EGPEFormatToEDDGPEPixelFormat[format];
m_dwColorKeyLowValue = 0L;
m_dwColorKeyHighValue = 0L;
m_dwColorKeyMask = 0xFFFFFFFFL;
lpDDSurface = NULL;
}
DDGPESurf::DDGPESurf(
int width,
int height,
void * pBits, // virtual address of allocated bits
int stride,
EGPEFormat format,
EDDGPEPixelFormat pixelFormat)
: GPESurf( width, height, pBits, stride, format )
{
m_ePixelFormat = pixelFormat;
m_dwColorKeyLowValue = 0L;
m_dwColorKeyHighValue = 0L;
m_dwColorKeyMask = 0xFFFFFFFFL;
lpDDSurface = NULL;
m_pDriverData = NULL;
}
DDGPESurf::DDGPESurf(
int width,
int height,
int stride,
EGPEFormat format,
EDDGPEPixelFormat pixelFormat)
{
DWORD bpp = EGPEFormatToBpp[format];
LONG align = 8;
DWORD alignedWidth = (( width + align - 1 ) & ( - align ));
DWORD nSurfaceBytes = ((bpp) * ( alignedWidth * height )) / 8;
DWORD realStride = ((alignedWidth * bpp) / 8);
BYTE* pLocalBytes = (BYTE*)RemoteLocalAlloc( LMEM_FIXED, nSurfaceBytes );
DEBUGMSG(GPE_ZONE_CREATE, (TEXT("DDGPE: I have allocated system memory surface's buffer 0x%08x\r\n"), pLocalBytes ));
Init(width, height, pLocalBytes, realStride, format, pixelFormat);
m_fOwnsBuffer = TRUE;
m_dwColorKeyLowValue = 0L;
m_dwColorKeyHighValue = 0L;
m_dwColorKeyMask = 0xFFFFFFFFL;
lpDDSurface = NULL;
m_pDriverData = NULL;
}
DDGPESurf::DDGPESurf
(int width,
int height,
EGPEFormat format)
{
DWORD bpp = EGPEFormatToBpp[format];
LONG align = 8;
DWORD alignedWidth = (( width + align - 1 ) & ( - align ));
DWORD nSurfaceBytes = ((bpp) * ( alignedWidth * height )) / 8;
DWORD realStride = ((alignedWidth * bpp) / 8);
BYTE* pLocalBytes = (BYTE*)RemoteLocalAlloc( LMEM_FIXED, nSurfaceBytes );
DEBUGMSG(GPE_ZONE_CREATE, (TEXT("DDGPE: I have allocated system memory surface's buffer 0x%08x\r\n"), pLocalBytes ));
Init(width, height, pLocalBytes, realStride, format,
EGPEFormatToEDDGPEPixelFormat[format]);
m_fOwnsBuffer = TRUE;
m_dwColorKeyLowValue = 0L;
m_dwColorKeyHighValue = 0L;
m_dwColorKeyMask = 0xFFFFFFFFL;
lpDDSurface = NULL;
m_pDriverData = NULL;
}
DDGPESurf::DDGPESurf()
: GPESurf()
{
//BUGBUG should get the real format from GPE
m_ePixelFormat = ddgpePixelFormat_565;
m_dwColorKeyLowValue = 0L;
m_dwColorKeyHighValue = 0L;
m_dwColorKeyMask = 0xFFFFFFFFL;
lpDDSurface = NULL;
m_pDriverData = NULL;
}
DDGPESurf::~DDGPESurf()
{
if (m_fOwnsBuffer)
{
if (m_pVirtAddr != NULL)
{
DEBUGMSG(GPE_ZONE_CREATE, (TEXT("DDGPE: Freeing system memory surface's buffer 0x%08x\r\n"), m_pVirtAddr ));
RemoteLocalFree((void*)m_pVirtAddr);
m_pVirtAddr = NULL;
}
}
}
void DDGPESurf::Init
(int width,
int height,
void * pBits,
int stride,
EGPEFormat format,
EDDGPEPixelFormat pixelFormat)
{
GPESurf::Init(width, height, pBits, stride, format);
m_ePixelFormat = pixelFormat;
}
DWORD
DDGPESurf::Bpp(void)
{
return EGPEFormatToBpp[Format()];
}
// get the actual width of the surface's allocated memory
DWORD
DDGPESurf::AlignedWidth(void)
{
return ( (Stride() * 8) / (Bpp()) );
}
void
DDGPESurf::SetColorKey(DWORD dwColorKey)
{
SetColorKeyHigh(dwColorKey);
SetColorKeyLow(dwColorKey);
}
DWORD
DDGPESurf::ColorKey(void)
{
return ColorKeyLow();
}
void
DDGPESurf::SetColorKeyMask(DWORD dwColorKeyMask)
{
m_dwColorKeyMask = dwColorKeyMask;
}
DWORD
DDGPESurf::ColorKeyMask(void)
{
return m_dwColorKeyMask;
}
void
DDGPESurf::SetColorKeyLow(DWORD dwColorKey)
{
m_dwColorKeyLowValue = dwColorKey;
}
DWORD
DDGPESurf::ColorKeyLow(void)
{
return m_dwColorKeyLowValue;
}
void
DDGPESurf::SetColorKeyHigh(DWORD dwColorKey)
{
m_dwColorKeyHighValue = dwColorKey;
}
DWORD
DDGPESurf::ColorKeyHigh(void)
{
return m_dwColorKeyHighValue;
}
EDDGPEPixelFormat
DDGPESurf::PixelFormat(void)
{
return m_ePixelFormat;
}
BOOL
DDGPESurf::HasAlpha(void)
{
return
( m_ePixelFormat == ddgpePixelFormat_5551 ) ||
( m_ePixelFormat == ddgpePixelFormat_4444 ) ||
( m_ePixelFormat == ddgpePixelFormat_8888 ) ||
0;
}
void
DDGPESurf::SetDDGPESurf(LPDDRAWI_DDRAWSURFACE_GBL lpDDSurface)
{
if (lpDDSurface == NULL)
return;
lpDDSurface->dwReserved1 = (ULONG_PTR)this;
}
//
// static functions
//
void
DDGPESurf::DeleteSurface(LPDDRAWI_DDRAWSURFACE_LCL lpDDSurface)
{
if (lpDDSurface != NULL)
{
DDGPESurf* pSurf = DDGPESurf::GetDDGPESurf(lpDDSurface);
if (pSurf != NULL)
{
delete pSurf;
}
}
}
DDGPESurf*
DDGPESurf::GetDDGPESurf(LPDDRAWI_DDRAWSURFACE_LCL lpDDSurface)
{
if (lpDDSurface == NULL)
{
return NULL;
}
return ((DDGPESurf*)lpDDSurface->lpGbl->dwReserved1);
}
/*
Switching to surface GBL - and we no longer need this... ddraw does flipping
for us...
void
DDGPESurf::Swap(LPDDRAWI_DDRAWSURFACE_LCL s1, LPDDRAWI_DDRAWSURFACE_LCL s2)
{
DWORD temp1 = s1->dwReserved1;
//DWORD temp2 = s2->reserved1;
s1->dwReserved1 = s2->dwReserved1;//(ULONG)temp2;
s2->dwReserved1 = (ULONG)temp1;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -