gpecer.cpp
来自「老外的一个开源项目」· C++ 代码 · 共 1,328 行 · 第 1/3 页
CPP
1,328 行
if (y >= m_nScreenHeight)
{
break;
}
ptrLine = &ptrScreen[y * m_pPrimarySurface->Stride()];
cbsLine = &m_CursorBackingStore[(y - m_CursorRect.top) * (m_CursorSize.x * (m_colorDepth >> 3))];
for (x = m_CursorRect.left; x < m_CursorRect.right; x++)
{
// clip to displayable screen area (left/right)
if (x < 0)
{
continue;
}
if (x >= m_nScreenWidth)
{
break;
}
ptrLine[x * (m_colorDepth >> 3)] = cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3)];
if (m_colorDepth > 8)
{
ptrLine[x * (m_colorDepth >> 3) + 1] = cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3) + 1];
if (m_colorDepth > 16)
{
ptrLine[x * (m_colorDepth >> 3) + 2] = cbsLine[(x - m_CursorRect.left) * (m_colorDepth >> 3) + 2];
}
}
}
}
m_CursorVisible = FALSE;
}
}
SCODE GPECERem::SetPointerShape(GPESurf *pMask, GPESurf *pColorSurf, INT xHot, INT yHot, INT cX, INT cY)
{
UCHAR *andPtr; // input pointer
UCHAR *xorPtr; // input pointer
UCHAR *andLine; // output pointer
UCHAR *xorLine; // output pointer
char bAnd;
char bXor;
int row;
int col;
int i;
int bitMask;
DEBUGMSG(GPE_ZONE_CURSOR,(TEXT("GPECERem::SetPointerShape(0x%X, 0x%X, %d, %d, %d, %d)\r\n"),pMask, pColorSurf, xHot, yHot, cX, cY));
// turn current cursor off
CursorOff();
// release memory associated with old cursor
if (m_CursorBackingStore)
{
delete (void*)m_CursorBackingStore;
m_CursorBackingStore = NULL;
}
if (m_CursorXorShape)
{
delete (void*)m_CursorXorShape;
m_CursorXorShape = NULL;
}
if (m_CursorAndShape)
{
delete (void*)m_CursorAndShape;
m_CursorAndShape = NULL;
}
if (!pMask) // do we have a new cursor shape
{
m_CursorDisabled = TRUE; // no, so tag as disabled
}
else
{
m_CursorDisabled = FALSE; // yes, so tag as not disabled
// allocate memory based on new cursor size
m_CursorBackingStore = new UCHAR[(cX * (m_colorDepth >> 3)) * cY];
m_CursorXorShape = new UCHAR[cX * cY];
m_CursorAndShape = new UCHAR[cX * cY];
// store size and hotspot for new cursor
m_CursorSize.x = cX;
m_CursorSize.y = cY;
m_CursorHotspot.x = xHot;
m_CursorHotspot.y = yHot;
andPtr = (UCHAR*)pMask->Buffer();
xorPtr = (UCHAR*)pMask->Buffer() + (cY * pMask->Stride());
// store OR and AND mask for new cursor
for (row = 0; row < cY; row++)
{
andLine = &m_CursorAndShape[cX * row];
xorLine = &m_CursorXorShape[cX * row];
for (col = 0; col < cX / 8; col++)
{
bAnd = andPtr[row * pMask->Stride() + col];
bXor = xorPtr[row * pMask->Stride() + col];
for (bitMask = 0x0080, i = 0; i < 8; bitMask >>= 1, i++)
{
andLine[(col * 8) + i] = bAnd & bitMask ? 0xFF : 0x00;
xorLine[(col * 8) + i] = bXor & bitMask ? 0xFF : 0x00;
}
}
}
}
return S_OK;
}
SCODE GPECERem::MovePointer(INT xPosition, INT yPosition)
{
DEBUGMSG(GPE_ZONE_CURSOR, (TEXT("GPECERem::MovePointer(%d, %d)\r\n"), xPosition, yPosition));
CursorOff();
if (xPosition != -1 || yPosition != -1)
{
// compute new cursor rect
m_CursorRect.left = xPosition - m_CursorHotspot.x;
m_CursorRect.right = m_CursorRect.left + m_CursorSize.x;
m_CursorRect.top = yPosition - m_CursorHotspot.y;
m_CursorRect.bottom = m_CursorRect.top + m_CursorSize.y;
CursorOn();
}
return S_OK;
}
void GPECERem::WaitForNotBusy(void)
{
DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPECERem::WaitForNotBusy\r\n")));
return;
}
int GPECERem::IsBusy(void)
{
DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPECERem::IsBusy\r\n")));
return 0;
}
void GPECERem::GetPhysicalVideoMemory(unsigned long *physicalMemoryBase, unsigned long *videoMemorySize)
{
DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPECERem::GetPhysicalVideoMemory\r\n")));
*physicalMemoryBase = m_pvFlatFrameBuffer;
*videoMemorySize = m_cbScanLineLength * m_cyPhysicalScreen;
}
#ifdef DD_ENABLE
void GPECERem::GetVirtualVideoMemory(unsigned long *virtualMemoryBase, unsigned long *videoMemorySize)
{
DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPECERem::GetVirtualVideoMemory\r\n")));
*virtualMemoryBase = m_VirtualFrameBuffer;
*videoMemorySize = m_cbScanLineLength * m_cyPhysicalScreen;
}
#endif // DD_ENABLE
SCODE GPECERem::AllocSurface(GPESurf **surface, INT width, INT height, EGPEFormat format, INT surfaceFlags)
{
DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPECERem::AllocSurface\r\n")));
if (surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY)
{
return E_OUTOFMEMORY;
}
// Allocate from system memory
#ifdef DD_ENABLE
*surface = (GPESurf *)new DDGPESurf(width, height, format);
#else // DD_ENABLE
*surface = new GPESurf(width, height, format);
#endif // DD_ENABLE
if (*surface != NULL)
{
// Check that the bits were allocated succesfully
if (((*surface)->Buffer()) == NULL)
{
delete *surface; // Clean up
}
else
{
return S_OK;
}
}
return E_OUTOFMEMORY;
}
SCODE GPECERem::WrappedEmulatedLine (GPELineParms *lineParameters)
{
SCODE retval;
RECT bounds;
int N_plus_1; // Minor length of bounding rect + 1
// calculate the bounding-rect to determine overlap with cursor
if (lineParameters->dN) // The line has a diagonal component (we'll refresh the bounding rect)
{
N_plus_1 = 2 + ((lineParameters->cPels * lineParameters->dN) / lineParameters->dM);
}
else
{
N_plus_1 = 1;
}
switch(lineParameters->iDir)
{
case 0:
bounds.left = lineParameters->xStart;
bounds.top = lineParameters->yStart;
bounds.right = lineParameters->xStart + lineParameters->cPels + 1;
bounds.bottom = bounds.top + N_plus_1;
break;
case 1:
bounds.left = lineParameters->xStart;
bounds.top = lineParameters->yStart;
bounds.bottom = lineParameters->yStart + lineParameters->cPels + 1;
bounds.right = bounds.left + N_plus_1;
break;
case 2:
bounds.right = lineParameters->xStart + 1;
bounds.top = lineParameters->yStart;
bounds.bottom = lineParameters->yStart + lineParameters->cPels + 1;
bounds.left = bounds.right - N_plus_1;
break;
case 3:
bounds.right = lineParameters->xStart + 1;
bounds.top = lineParameters->yStart;
bounds.left = lineParameters->xStart - lineParameters->cPels;
bounds.bottom = bounds.top + N_plus_1;
break;
case 4:
bounds.right = lineParameters->xStart + 1;
bounds.bottom = lineParameters->yStart + 1;
bounds.left = lineParameters->xStart - lineParameters->cPels;
bounds.top = bounds.bottom - N_plus_1;
break;
case 5:
bounds.right = lineParameters->xStart + 1;
bounds.bottom = lineParameters->yStart + 1;
bounds.top = lineParameters->yStart - lineParameters->cPels;
bounds.left = bounds.right - N_plus_1;
break;
case 6:
bounds.left = lineParameters->xStart;
bounds.bottom = lineParameters->yStart + 1;
bounds.top = lineParameters->yStart - lineParameters->cPels;
bounds.right = bounds.left + N_plus_1;
break;
case 7:
bounds.left = lineParameters->xStart;
bounds.bottom = lineParameters->yStart + 1;
bounds.right = lineParameters->xStart + lineParameters->cPels + 1;
bounds.top = bounds.bottom - N_plus_1;
break;
default:
DEBUGMSG(GPE_ZONE_ERROR,(TEXT("Invalid direction: %d\r\n"), lineParameters->iDir));
return E_INVALIDARG;
}
// check for line overlap with cursor and turn off cursor if overlaps
RECTL cursorRect = m_CursorRect;
RotateRectl (&cursorRect);
if (m_CursorVisible && !m_CursorDisabled &&
cursorRect.top < bounds.bottom && cursorRect.bottom > bounds.top &&
cursorRect.left < bounds.right && cursorRect.right > bounds.left)
{
CursorOff();
m_CursorForcedOff = TRUE;
}
// do emulated line
retval = EmulatedLine (lineParameters);
// see if cursor was forced off because of overlap with line bouneds and turn back on
if (m_CursorForcedOff)
{
m_CursorForcedOff = FALSE;
CursorOn();
}
return retval;
}
SCODE GPECERem::Line(GPELineParms *lineParameters, EGPEPhase phase)
{
DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPECERem::Line\r\n")));
if (phase == gpeSingle || phase == gpePrepare)
{
if ((lineParameters->pDst != m_pPrimarySurface))
{
lineParameters->pLine = &GPE::EmulatedLine;
}
else
{
lineParameters->pLine = (SCODE (GPE::*)(struct GPELineParms *)) &GPECERem::WrappedEmulatedLine;
}
}
return S_OK;
}
SCODE GPECERem::BltPrepare(GPEBltParms *blitParameters)
{
RECTL rectl;
DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPECERem::BltPrepare\r\n")));
// default to base EmulatedBlt routine
blitParameters->pBlt = &GPE::EmulatedBlt;
// see if we need to deal with cursor
if (m_CursorVisible && !m_CursorDisabled)
{
// check for destination overlap with cursor and turn off cursor if overlaps
if (blitParameters->pDst == m_pPrimarySurface) // only care if dest is main display surface
{
if (blitParameters->prclDst != NULL) // make sure there is a valid prclDst
{
rectl = *blitParameters->prclDst; // if so, use it
}
else
{
rectl = m_CursorRect; // if not, use the Cursor rect - this forces the cursor to be turned off in this case
}
if (m_CursorRect.top < rectl.bottom && m_CursorRect.bottom > rectl.top &&
m_CursorRect.left < rectl.right && m_CursorRect.right > rectl.left)
{
CursorOff();
m_CursorForcedOff = TRUE;
}
}
// check for source overlap with cursor and turn off cursor if overlaps
if (blitParameters->pSrc == m_pPrimarySurface) // only care if source is main display surface
{
if (blitParameters->prclSrc != NULL) // make sure there is a valid prclSrc
{
rectl = *blitParameters->prclSrc; // if so, use it
}
else
{
rectl = m_CursorRect; // if not, use the CUrsor rect - this forces the cursor to be turned off in this case
}
if (m_CursorRect.top < rectl.bottom && m_CursorRect.bottom > rectl.top &&
m_CursorRect.left < rectl.right && m_CursorRect.right > rectl.left)
{
CursorOff();
m_CursorForcedOff = TRUE;
}
}
}
// see if there are any optimized software blits available
EmulatedBltSelect02(blitParameters);
EmulatedBltSelect08(blitParameters);
EmulatedBltSelect16(blitParameters);
return S_OK;
}
SCODE GPECERem::BltComplete(GPEBltParms *blitParameters)
{
DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPECERem::BltComplete\r\n")));
// see if cursor was forced off because of overlap with source or destination and turn back on
if (m_CursorForcedOff)
{
m_CursorForcedOff = FALSE;
CursorOn();
}
return S_OK;
}
INT GPECERem::InVBlank(void)
{
DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPECERem::InVBlank\r\n")));
return 0;
}
SCODE GPECERem::SetPalette(const PALETTEENTRY *source, USHORT firstEntry, USHORT numEntries)
{
DEBUGMSG (GPE_ZONE_INIT, (TEXT("GPECERem::SetPalette(0x%X, %d, %d)\r\n"),
source, firstEntry, numEntries));
if (firstEntry < 0 || firstEntry + numEntries > 256 || source == NULL)
{
return E_INVALIDARG;
}
for(; numEntries; numEntries--)
{
_rgbIdentity[firstEntry].peRed = source->peRed;
_rgbIdentity[firstEntry].peGreen = source->peGreen;
_rgbIdentity[firstEntry].peBlue = source->peBlue;
_rgbIdentity[firstEntry].peFlags = source->peFlags;
firstEntry++;
source++;
}
v_fPalChanged = TRUE;
return S_OK;
}
ULONG GPECERem::GetGraphicsCaps()
{
if (m_pMode)
{
if (m_pMode->Bpp == 16) // if in 16bpp mode, return GCAPS_GRAY16 to denote that we support anti-aliased fonts
{
return GCAPS_GRAY16;
}
}
return 0;
}
#ifndef DD_ENABLE // if not a DDraw driver, then include dummy versions of these function
void RegisterDDHALAPI(void)
{
return; // no DDHAL support
}
#endif //DD_SUPPORT
ULONG gBitMasks[] = { 0x0001,0x0002,0x0000 };
ULONG *APIENTRY DrvGetMasks(DHPDEV dhpdev)
{
return gBitMasks;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?