📄 unixsurf.cpp
字号:
}
}
} //if(bOverlay)...
#endif
return retVal;
}
HX_RESULT CUnixSurf::_LockInternalSurface( UCHAR** ppSurfPtr,
LONG32* pnSurfPitch,
HXxSize& notused )
{
HX_RESULT retVal = HXR_OK;
//Flip internal buffers....
m_nCurrentBuffer++;
if( m_nCurrentBuffer >= m_nMultiBufferCount )
{
m_nCurrentBuffer=0;
}
HX_ASSERT( m_pcVideoBuf[m_nCurrentBuffer] );
HX_ASSERT( m_nVideoPitch != 0 );
*ppSurfPtr = (UCHAR*)m_pcVideoBuf[m_nCurrentBuffer];
*pnSurfPitch = m_nVideoPitch;
return retVal;
}
HX_RESULT CUnixSurf::_UnlockInternalSurface(UCHAR* pSurfPtr)
{
return HXR_OK;
}
void CUnixSurf::_SetupDCObjects(HXxDC hxxDC, void** phOldBrush, void** phOldPen)
{
#ifdef _DEBUG
fprintf( stderr, "CUnixSurf::_SetupDCObjects needs to be written.\n" );
#endif
}
void CUnixSurf::_FillRectangle(HXxDC hxxDC,
UINT32 left, UINT32 top,
UINT32 right, UINT32 bottom)
{
if( !hxxDC )
return;
for( int x=left; x<=right-1; x++ )
{
for( int y=top; y<=bottom-1; y++ )
{
#if defined _LINUX && defined _OVERLAY
XPutPixel( (XImage*)hxxDC, x, y, m_ulColorKey );
#endif
}
}
}
void CUnixSurf::_RestoreDCObjects(HXxDC hxxDC, void* hOldBrush, void* hOldPen)
{
#ifdef _DEBUG
fprintf( stderr, "CUnixSurf::_RestoreDCObjects needs to be written.\n" );
#endif
}
void CUnixSurf::_GetCompositionSurfaceHXxDC(HXxDC *hdc)
{
//This needs to return a drawable that points to the composition surface...
CUnixRootSurf* pSurface = (CUnixRootSurf*)m_pSite->GetRootSurface();
XImage *pImage = pSurface->_GetCompositionSurfaceDrawable();
*hdc = (HXxDC)pImage;
}
void CUnixSurf::_ReleaseCompositionSurfaceHXxDC(HXxDC hdc)
{
//Nothing to do on unix...
}
INT32 CUnixSurf::_InsureColorMatch(INT32 InColor)
{
return InColor;
}
void CUnixSurf::_SetColorKey(INT32 nColorSpaceLowValue,INT32 nColorSpaceHighValue)
{
#if defined(_LINUX) && defined(_OVERLAY)
static BOOL bDoneItAlready = FALSE;
if( m_atomColorKey != None && !bDoneItAlready)
{
if( m_ulColorKey == 0x01020304 )
{
m_ulColorKey = nColorSpaceHighValue;
//The user did not set a color key preference...
XvSetPortAttribute( m_display, m_nPortID, m_atomColorKey, nColorSpaceHighValue );
}
else
{
XvSetPortAttribute( m_display, m_nPortID, m_atomColorKey, m_ulColorKey );
}
bDoneItAlready = TRUE;
}
#endif
}
static BOOL CheckIt(Display* dis, XEvent* event, XPointer arg)
{
BOOL ret = (event->type==(int)arg);
return ret;
}
void CUnixSurf::_UpdateOverlay(HXxRect* dest, HXxRect* src, INT32 inFlags)
{
HXxWindow* pWin = m_pSite->GetWindow();
CBaseRootSurface* pRootSurface = m_pSite->GetRootSurface();
int nRet = 0;
Window winSurface = 0;
HXxRect rectDest = {0,0,0,0};
memcpy( &rectDest, dest, sizeof( HXxRect ) ); /* Flawfinder: ignore */
HX_ASSERT( m_nMultiBufferCount );
#if defined(_LINUX) && defined(_OVERLAY)
m_ulLastOverlayUpdateTime = HX_GET_TICKCOUNT();
//Draw on the root window if the user wants it. This feature isn't tested
//and has known problems for certain window managers that create their own
//window over the root. Looks really cool when it works though. :) Turn
//this on set the color key to the background color of all your xterms.
//Very nice.
if( !m_bWallPaperMode )
{
winSurface = (Window)pWin->window;
}
else
{
winSurface = DefaultRootWindow(m_display);
}
HX_ASSERT( pWin );
#ifdef _DEBUG
// static ULONG32 ulLast =0;
// static ULONG32 ulCount =0;
// static ULONG32 ulCountTot =0;
// static double fpsTot=0;
// ULONG32 ulCurr = HX_GET_TICKCOUNT();
// if( ulCurr-ulLast>1000 )
// {
// float fps = (float)ulCount/((float)(ulCurr-ulLast)/1000.0);
// fpsTot += fps;
// ulCountTot++;
// fprintf( stderr, "%lu elapsed microseconds. %lu frames. %f FPS (Ave: %f)\n",
// ulCurr-ulLast, ulCount, fps, fpsTot/(double)ulCountTot );
// ulCount = 0;
// ulLast = ulCurr;
// }
// ulCount++;
#endif
//if we are on the root window, calculate new dest rect.
//Copy the one passed in.
if( m_bWallPaperMode )
{
Screen* pScreen = XDefaultScreenOfDisplay(m_display);
UINT16 uHorzRes = WidthOfScreen(pScreen);
UINT16 uVertRes = HeightOfScreen(pScreen);
//if the user wants to stretchtofill then make the dest rect the
//whole screen, otherwise preserve aspec ration.
if( m_bStretchToFill )
{
//Make it the whole screen.
rectDest.left = 0;
rectDest.top = 0;
rectDest.right = uHorzRes;
rectDest.bottom = uVertRes;
}
else
{
//maintain aspect ration.
//Scale it.
float fXScale = (float)uHorzRes/(float)(dest->right-dest->left);
float fYScale = (float)uVertRes/(float)(dest->bottom-dest->top);
float fScale = (fXScale<fYScale) ? fXScale : fYScale;
int nWidth = (int)(fScale*(dest->right-dest->left)+.5);
int nHeight = (int)(fScale*(dest->bottom-dest->top)+.5);
rectDest.left = 0;
rectDest.top = 0;
if( nWidth<uHorzRes )
rectDest.left = (uHorzRes-nWidth)/2;
if( nHeight<uVertRes )
rectDest.top = (uVertRes-nHeight)/2;
rectDest.right = rectDest.left+nWidth;
rectDest.bottom = rectDest.top+nHeight;
}
}
if( m_bUseShm )
{
nRet = XvShmPutImage( m_display,
m_nPortID,
winSurface,
((CUnixRootSurf*)pRootSurface)->GetGC(),
m_pXvImage[m_nCurrentBuffer],
src->left,
src->top,
src->right - src->left,
src->bottom - src->top,
rectDest.left,
rectDest.top,
rectDest.right - rectDest.left,
rectDest.bottom - rectDest.top,
True
);
}
else
{
nRet = XvPutImage( m_display,
m_nPortID,
winSurface,
((CUnixRootSurf*)pRootSurface)->GetGC(),
m_pXvImage[m_nCurrentBuffer],
src->left,
src->top,
src->right - src->left,
src->bottom - src->top,
rectDest.left,
rectDest.top,
rectDest.right - rectDest.left,
rectDest.bottom - rectDest.top
);
}
if( m_bUseShm && m_nMultiBufferCount==1 )
{
//If we aren't at least double buffering and we are using
//shared memory, make sure we wait for the completion of the
//copy of the shared memory segment to the server. Tear not
//want not.
HX_ASSERT( m_nCompletionEventID > 0 );
XEvent event;
XIfEvent( m_display, &event, CheckIt, (XPointer)m_nCompletionEventID );
}
#endif
}
BOOL CUnixSurf::_IsSurfaceVisible()
{
return TRUE;
}
void CUnixSurf::_ReleaseSurface()
{
int i=0;
#if defined(_LINUX) && defined(_OVERLAY)
//Release all of our overlay resources.....
if( m_nPortID!=-1 )
{
XvUngrabPort( m_display, m_nPortID, CurrentTime );
m_nPortID=-1;
if( zm_pXvOwner==this )
{
zm_pXvOwner = NULL;
}
}
if( m_pcVideoBuf != NULL )
{
for( i=0 ; i<m_nMultiBufferCount ; i++ )
{
if( m_nShmId[i] != -1 && m_bUseShm )
{
ShmHelp::DetachSharedRegion( &m_pcVideoBuf[i], &m_shmInfo[i] );
m_nShmId[i] = -1;
}
else
{
HX_VECTOR_DELETE(m_pcVideoBuf[i]);
}
m_pcVideoBuf[i] = NULL;
}
}
if( m_pXvImage )
{
for( i=0; i<m_nMultiBufferCount; i++ )
{
XFree( m_pXvImage[i] );
m_pXvImage[i] = NULL;
}
}
memset( &m_surfaceSize, 0, sizeof(m_surfaceSize) );
m_nSurfaceCID = 1234; //what else?
#endif
}
HXxDC CUnixSurf::_GetDC(HXxWindow*)
{
return (HXxDC)m_GC;
}
void CUnixSurf::_ReleaseDC(HXxWindow*, HXxDC)
{
#ifdef _DEBUG
fprintf( stderr, "CUnixSurf::_ReleaseDC needs to be written.\n" );
#endif
}
void CUnixSurf::_GetWindowDeviceCords(HXxRect* rect )
{
memset( rect, 0, sizeof( HXxRect) );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -