unixsurf.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 1,131 行 · 第 1/3 页

CPP
1,131
字号
    if( !hxxDC )
        return;

    // XXXNH: constrain ourselves to the current image size.  When the site
    // is shrunk (eg: via user action) we can enter a situation where a
    // damaged rect is queued up for drawing that is larger than the current
    // image.  We will crash if we don't constrain it to the current size.
    XImage* pImage = (XImage*)hxxDC;
    if (right > pImage->width)
	right = pImage->width;
    if (bottom > pImage->height)
	bottom = pImage->height;

    for( int x=left; x<=right-1; x++ )
    {
        for( int y=top; y<=bottom-1; y++ )
        {
#if defined _LINUX &&  defined _OVERLAY
            XPutPixel( pImage, x, y, m_ulColorKey );
#endif
        }
    }
}

void CUnixSurf::_RestoreDCObjects(HXxDC hxxDC, void* hOldBrush, void* hOldPen)
{
}

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...
	     XLockDisplay(m_display);
            XvSetPortAttribute( m_display, m_nPortID, m_atomColorKey, nColorSpaceHighValue );
	     XUnlockDisplay(m_display);
        }
        else
        {
            XLockDisplay(m_display);
            XvSetPortAttribute( m_display, m_nPortID, m_atomColorKey, m_ulColorKey );
	     XUnlockDisplay(m_display);
        }
        bDoneItAlready = TRUE;
    }
#endif   
}

static BOOL CheckIt(Display* dis, XEvent* event, XPointer arg)
{
    BOOL ret = (event->type==(int)arg);
    return ret;
}

#if defined(HELIX_FEATURE_HARDWARE_COLOR_CONTROLS)
inline int _scaleIt( float v, stPortAttribute at )
{
    int nRetVal = (int)(((v+1)*(at.nMaxValue-at.nMinValue))/2+at.nMinValue);
    if( nRetVal < at.nMinValue )
        nRetVal = at.nMinValue;
    if( nRetVal > at.nMaxValue )
        nRetVal = at.nMaxValue;
}

BOOL CUnixSurf::HasHWColorConrols()
{
    BOOL retVal=FALSE;

    if( None != m_atomBrightness &&
        None != m_atomHue        &&
        None != m_atomSaturation &&
        None != m_atomContrast )
    {
        retVal = TRUE;
    }
    return retVal;
}

void CUnixSurf::SetHWColorControls()
{
    float fBright     = m_pSite->GetBrightness();
    float fContrast   = m_pSite->GetContrast();
    float fHue        = m_pSite->GetHue();
    float fSaturation = m_pSite->GetSaturation();
    if( None != m_atomBrightness )
    {
        int nVal = _scaleIt( fBright, paBrightness);
        if( nVal != m_nCurrBrightness )
        {
	     XLockDisplay(m_display);
            XvSetPortAttribute(m_display, m_nPortID, m_atomBrightness, nVal);
	     XUnlockDisplay(m_display);
            m_nCurrBrightness = nVal;
        }
    }            
    if( None != m_atomContrast)
    {
        int nVal = _scaleIt( fContrast, paContrast);
        if( nVal != m_nCurrContrast )
        {
	     XLockDisplay(m_display);
            XvSetPortAttribute(m_display, m_nPortID, m_atomContrast, nVal);
	     XUnlockDisplay(m_display);
            m_nCurrContrast = nVal;
        }
    }            
    if( None != m_atomHue)
    {
        int nVal = _scaleIt( fHue, paHue);
        if( nVal != m_nCurrHue )
        {
	    XLockDisplay(m_display);
            XvSetPortAttribute(m_display, m_nPortID, m_atomHue, nVal);
	    XUnlockDisplay(m_display);
            m_nCurrHue = nVal;
        }
    }            
    if( None != m_atomSaturation)
    {
        int nVal = _scaleIt( fSaturation, paSaturation);
        if( nVal != m_nCurrSaturation )
        {
	     XLockDisplay(m_display);
            XvSetPortAttribute(m_display, m_nPortID, m_atomSaturation, nVal);
	     XUnlockDisplay(m_display);
            m_nCurrSaturation = nVal;
        }
    }
}
#endif        

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 )
    {
	 XLockDisplay(m_display);
        Screen* pScreen = XDefaultScreenOfDisplay(m_display);
	 XUnlockDisplay(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 )
    {

	 XLockDisplay(m_display);
        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
                              );
	XUnlockDisplay(m_display);

    }
    else
    {
        XLockDisplay(m_display);
        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
                           );
	XUnlockDisplay(m_display);
    }

    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;
	 XLockDisplay(m_display);
        XIfEvent( m_display, &event, CheckIt, (XPointer)m_nCompletionEventID );
	 XUnlockDisplay(m_display);
    }
   
#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 )
    {
        XLockDisplay(m_display);
        XvUngrabPort( m_display, m_nPortID, CurrentTime );
	 XUnlockDisplay(m_display);
        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)
{
}

void CUnixSurf::_GetWindowDeviceCords(HXxRect* rect )
{
    memset( rect, 0, sizeof( HXxRect) );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?