surf.cpp
来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C++ 代码 · 共 226 行
CPP
226 行
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995, 1996, 1997, 1998 Microsoft Corporation
Module Name:
Abstract:
Sample MGDI driver (for IGS2010)
Functions:
Notes:
ported from CT65550 driver Dec.1997
--*/
#include "precomp.h"
//
// AllocSurface -
// inputs:
// outputs:
//
SCODE IGS2010::AllocSurface(
GPESurf **ppSurf,
int width,
int height,
EGPEFormat format,
int surfaceFlags )
{
if( surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY ) {
if( !( format == m_pMode->format ) ) {
return E_INVALIDARG;
}
// Attempt to allocate from video memory
Node2D *pNode = m_p2DVideoMemory->Alloc( width, height );
if( pNode ) {
unsigned long offset = m_nScreenStride * pNode->Top() + pNode->Left();
*ppSurf = new IGS2010Surf(
width,
height,
offset,
m_pLAW + offset,
m_nScreenStride,
format,
pNode );
return S_OK;
}
if( surfaceFlags & GPE_REQUIRE_VIDEO_MEMORY ) {
*ppSurf = (GPESurf *)NULL;
return E_OUTOFMEMORY;
}
}
// Allocate from system memory
DEBUGMSG(GPE_ZONE_CREATE,(TEXT("Creating a GPESurf in system memory. EGPEFormat = %d\r\n"), (int)format ));
*ppSurf = new GPESurf( width, height, format );
if(*ppSurf) {
// check we allocated bits succesfully
if(!((*ppSurf)->Buffer())) {
delete *ppSurf; // and then return E_OUTOFMEMORY
} else {
return S_OK;
}
}
return E_OUTOFMEMORY;
}
//
// IGS2010Surf - constructor
// inputs:
// outputs:
//
IGS2010Surf::IGS2010Surf(
int width,
int height,
unsigned long offset,
void *pBits, // virtual address of allocated bits
int stride,
EGPEFormat format,
Node2D *pNode )
: GPESurf( width, height, pBits, stride, format )
{
m_pNode2D = pNode;
m_fInVideoMemory = TRUE;
m_nOffsetInVideoMemory = offset;
}
//
// ~IGS2010Surf - destructor
// inputs:
// outputs:
//
IGS2010Surf::~IGS2010Surf()
{
m_pNode2D->Free();
}
//
// CheckVisibleSurface -
// inputs:
// outputs:
//
void IGS2010::CheckVisibleSurface()
{
unsigned long tickCount = GetTickCount();
if( tickCount - m_nTicksAtFlip > m_nTicksPerFrame + 1 ) {
m_pOldVisibleSurface = m_pNewVisibleSurface;
return;
}
unsigned int phase = ( tickCount - m_nTicksAtResync ) % m_nTicksPerFrame;
unsigned int flipPhase = ( m_nTicksAtFlip - m_nTicksAtResync ) % m_nTicksPerFrame;
if( (phase >= m_nTicksPerFrame * 7 / 8) || // near end of frame, may as well wait
( tickCount - m_nTicksAtResync > m_nTicksPerFrame * 20 ) || // overdue for resync
( tickCount < m_nTicksAtFlip ) || // Time went backwards
( m_nTicksAtFlip < m_nTicksAtResync ) ) { // Time went backwards
WaitForVBlank();
return;
}
if( phase < flipPhase ) {
m_pOldVisibleSurface = m_pNewVisibleSurface;
return;
}
DEBUGMSG( GPE_ZONE_FLIP,
( TEXT("Not flipped. Ticks at flip:%d, now %d, "),
m_nTicksAtFlip,
tickCount ) );
DEBUGMSG( GPE_ZONE_FLIP,
( TEXT("per frame %d resync %d\r\n"),
m_nTicksPerFrame,
m_nTicksAtResync ) );
}
//
// SurfaceBusyFlipping -
// inputs:
// outputs:
//
int IGS2010::SurfaceBusyFlipping( IGS2010Surf *pSurf )
{
if( pSurf == m_pOldVisibleSurface || pSurf == m_pNewVisibleSurface ) {
CheckVisibleSurface();
}
return ( pSurf == m_pOldVisibleSurface || pSurf == m_pNewVisibleSurface );
}
//
// FlipInProgress -
// inputs:
// outputs:
//
int IGS2010::FlipInProgress()
{
if( m_pOldVisibleSurface != m_pNewVisibleSurface ) {
CheckVisibleSurface();
} else {
return 0;
}
if( m_pOldVisibleSurface != m_pNewVisibleSurface ) {
DEBUGMSG( GPE_ZONE_FLIP, ( TEXT("Flip from surf 0x%08x to 0x%08x in progress\r\n"),
m_pOldVisibleSurface, m_pNewVisibleSurface ));
}
return ( m_pOldVisibleSurface != m_pNewVisibleSurface );
}
#if DEBUG
int tickCountValid = 0;
unsigned int lastTickCount;
int frameCount = 0;
#endif
//
// SetVisibleSurface -
// inputs:
// outputs:
//
void IGS2010::SetVisibleSurface( GPESurf *pTempSurf )
{
IGS2010Surf *pSurf = (IGS2010Surf *) pTempSurf;
int displayStart = pSurf->Stride() * pSurf->Top();
m_pNewVisibleSurface = pSurf;
displayStart >>= 2;
reg_STA_H = (displayStart>>8) & 0xFF;
reg_STA_L = displayStart & 0xFF;
reg_CR[0x40] = 0x80 | (displayStart>>16)&0x0F;
m_nTicksAtFlip = GetTickCount();
#if DEBUG
if( tickCountValid ) {
frameCount++;
if( m_nTicksAtFlip - lastTickCount > 10000 ) {
int framesPerTenSecs = frameCount * 10000 / ( m_nTicksAtFlip - lastTickCount );
if( framesPerTenSecs < 2000 ) {
DEBUGMSG( GPE_ZONE_PERF, (TEXT("Frames per second: %d.%1d\r\n"),
framesPerTenSecs/10, framesPerTenSecs%10 ));
}
lastTickCount = m_nTicksAtFlip;
frameCount = 0;
}
} else {
tickCountValid = 1;
lastTickCount = m_nTicksAtFlip;
frameCount = 0;
}
#endif
}
//
// VBlankReceived -
// inputs:
// outputs:
//
void IGS2010::VBlankReceived()
{
m_nTicksAtFlip = m_nTicksAtResync = GetTickCount();
m_pOldVisibleSurface = m_pNewVisibleSurface;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?