⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unixsurf.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
 *      
 * The contents of this file, and the files included with this file, are 
 * subject to the current version of the RealNetworks Public Source License 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
 * in which case the RCSL will apply. You may also obtain the license terms 
 * directly from RealNetworks.  You may not use this file except in 
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
 * applicable to this file, the RCSL.  Please see the applicable RPSL or 
 * RCSL for the rights, obligations and limitations governing use of the 
 * contents of the file.  
 *  
 * This file is part of the Helix DNA Technology. RealNetworks is the 
 * developer of the Original Code and owns the copyrights in the portions 
 * it created. 
 *  
 * This file, and the files included with this file, is distributed and made 
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
 * 
 * Technology Compatibility Kit Test Suite(s) Location: 
 *    http://www.helixcommunity.org/content/tck 
 * 
 * Contributor(s): 
 *  
 * ***** END LICENSE BLOCK ***** */ 

#include <errno.h>

#include "hxcom.h"
#include "hxtypes.h"
#include "hxwintyp.h"
#include "hxvsurf.h"
#include "hxslist.h"
#include "hxheap.h"
#include "hxtick.h"
#include "colormap.h"
#include "hxthread.h"
#include "ihxpckts.h"
#include "unixsurf.h"
#include "unixroot.h"
#include "unixsite.h"
#include "basesite.h"
#include "shmhelp.h"

#if defined(_LINUX) && defined(_OVERLAY)
#include "hxprefs.h"
CUnixSurf* CUnixSurf::zm_pXvOwner     = NULL;
#endif


CUnixSurf::CUnixSurf( IUnknown* pContext, CHXBaseSite* pSite )
    : CBaseSurface( pContext, pSite )
#if defined(_LINUX) && defined(_OVERLAY)
    , m_bWallPaperMode(FALSE)
    , m_nPortID(-1)
    , m_nContrast(-9999)
    , m_nBrightness(-9999)
    , m_bPaintClipList(TRUE)
    , m_ulColorKey(0x01020304)
    , m_bStretchToFill(FALSE)
    , m_pXvImage(NULL)
    , m_atomColorKey(None)
    , m_atomClipKey(None)
    , m_atomBrightness(None)
    , m_atomContrast(None)
    , m_ulLastOverlayUpdateTime(0)
#endif
    , m_pcVideoBuf(NULL)
    , m_ulFourCCID(0)
    , m_nVideoPitch(0)
    , m_bUseShm(FALSE)
    , m_display(NULL)
    , m_GC(0)
    , m_nScreenNumber(0)
    , m_shmInfo(NULL)
    , m_nShmId(NULL)
    , m_nCurrentBuffer(0)
    , m_nCompletionEventID(-1)
    , m_nMultiBufferCount(2)
{
    int i=0;
    
#if defined(_LINUX) && defined(_OVERLAY)
    HX_ASSERT( m_pContext );
    IHXPreferences* pPreferences = NULL;   
    if( m_pContext && HXR_OK == m_pContext->QueryInterface( IID_IHXPreferences, (void **) &pPreferences))
    { 
        IHXBuffer *pBuffer = NULL;
        //This makes the overlay appear on the root window....
        //Just for inhouse testing right now...
        pPreferences->ReadPref("OverlayMode", pBuffer);
        if(pBuffer)
        {
            m_bUseOverlays = (::atoi((const char*)pBuffer->GetBuffer()) == 1);
            HX_RELEASE(pBuffer);
        }
        else
        {
            if (pPreferences->ReadPref("UseOverlay", pBuffer) == HXR_OK)
            {
                m_bUseOverlays = ::atoi((char*) pBuffer->GetBuffer()) == 1;
            }
            HX_RELEASE(pBuffer);
        }

        //This makes the overlay appear on the root window....
        //Just for inhouse testing right now...
        pPreferences->ReadPref("WallPaperMode", pBuffer);
        if (pBuffer)
        {
            m_bWallPaperMode = (::atoi((const char*)pBuffer->GetBuffer()) == 1);
            HX_RELEASE(pBuffer);
        }
        //This is used only when WallPaperMode=1 and stretches the
        //presentation to fill the whole root window NOT preserving
        //aspect ratio.
        pPreferences->ReadPref("StretchToFill", pBuffer);
        if (pBuffer)
        {
            m_bStretchToFill = (::atoi((const char*)pBuffer->GetBuffer()) == 1);
            HX_RELEASE(pBuffer);
        }

        //This is used on ATI cards for debugging. It tells the driver
        //to paint the window with the color key before each blt, or not.
        pPreferences->ReadPref("PaintClipList", pBuffer);
        if (pBuffer)
        {
            m_bPaintClipList = (::atoi((const char*)pBuffer->GetBuffer()) == 1);
            HX_RELEASE(pBuffer);
        }
        //This is the color key to use. If not set each card's driver will
        //choose one.
        pPreferences->ReadPref("ColorKey", pBuffer);
        if (pBuffer)
        {
            char *pszTmp   = NULL;
            const char *pszColor = (const char*)pBuffer->GetBuffer();
            long lTmp = ::strtol(pszColor, &pszTmp, 0);
            HX_RELEASE(pBuffer);
            if( lTmp>=0 && pszTmp!=pszColor && errno!=ERANGE )
            {
                m_ulColorKey = lTmp;
            }
        }
        //For use in testing on Matrox G400 cards that support this
        //atom.
        pPreferences->ReadPref("Contrast", pBuffer);
        if (pBuffer)
        {
            char *pszTmp   = NULL;
            const char *pszContrast = (const char*)pBuffer->GetBuffer();
            long lTmp = ::strtol(pszContrast, &pszTmp, 0);
            HX_RELEASE(pBuffer);
            if( pszTmp!=pszContrast && errno!=ERANGE )
            {
                m_nContrast = lTmp;
            }
        }
        //For use in testing on Matrox G400 cards that support this
        //atom.
        pPreferences->ReadPref("Brightness", pBuffer);
        if (pBuffer)
        {
            char *pszTmp   = NULL;
            const char *pszBrightness = (const char*)pBuffer->GetBuffer();
            long lTmp = ::strtol(pszBrightness, &pszTmp, 0);
            HX_RELEASE(pBuffer);
            if( pszTmp!=pszBrightness && errno!=ERANGE )
            {
                m_nBrightness = lTmp;
            }
        }
        //Find out how much multi buffering to do
        m_nMultiBufferCount = 2; //default to 2.
        pPreferences->ReadPref("MultiBufferingCount", pBuffer);
        if (pBuffer)
        {
            char *pszTmp   = NULL;
            const char *pszBufferCount = (const char*)pBuffer->GetBuffer();
            long lTmp = ::strtol(pszBufferCount, &pszTmp, 0);
            HX_RELEASE(pBuffer);
            if( pszTmp!=pszBufferCount && errno!=ERANGE )
            {
                m_nMultiBufferCount = lTmp;
            }
        }
        if( m_nMultiBufferCount < 1 )
            m_nMultiBufferCount = 1;
      
        HX_RELEASE( pPreferences );
    }

    if( m_bUseOverlays )
    {
        //Alloc our multi buffer lists.
        m_pXvImage   = new XvImage* [m_nMultiBufferCount];
        m_pcVideoBuf = new UCHAR* [m_nMultiBufferCount];
        m_shmInfo    = new XShmSegmentInfo[m_nMultiBufferCount];
        m_nShmId     = new int[m_nMultiBufferCount];
        for( i=0 ; i<m_nMultiBufferCount ; i++ )
        {
            m_pXvImage[i] = NULL;
            m_pcVideoBuf[i] = NULL;
            m_nShmId[i] = -1;
        }
    }
   
#endif //_LINUX && _OVERLAY
   
}

CUnixSurf::~CUnixSurf()
{
    int i = 0;
    
    if( m_GC)
    {
        XFreeGC(m_display, m_GC);
        m_GC=0;
    }
    
#if defined(_LINUX) && defined(_OVERLAY)
   
    if( m_pXvImage )
    {
        for( i=0; i<m_nMultiBufferCount; i++ )
        {
            XFree( m_pXvImage[i] );
        }
        HX_VECTOR_DELETE(m_pXvImage);
    }
   
    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]);
            }
        }
        HX_VECTOR_DELETE(m_pcVideoBuf);
        HX_VECTOR_DELETE(m_shmInfo);
    }
    memset( &m_surfaceSize, 0, sizeof(m_surfaceSize) );
   
#endif //_LINUX && _OVERLAY
   
}

void CUnixSurf::_ReleaseSurface(CBaseRootSurface* pSurface)
{
    //Release our grab on the port and assorted memory.....
    _ReleaseSurface();
}

void CUnixSurf::_DrawBlack(void* pWindow)
{
    //XXXgfw fill whole window with black? Just our rect?
}

HX_RESULT CUnixSurf::_BltToPrimary(HXxRect& rDestRect, HXxRect& rSrcRect)
{
#ifdef _DEBUG   
    fprintf( stderr, "CUnixSurf::_BltToPrimary is called...\n" );
#endif   
    return HXR_FAIL;
}


void CUnixSurf::_CreateBuffer()
{
    int i = 0;
#if defined(_LINUX) && defined(_OVERLAY)
    //Clean up the old stuff....
    if( m_pcVideoBuf != NULL )
    {
        for( i=0 ; i<m_nMultiBufferCount ; i++ )
        {
            if( m_pcVideoBuf[i] != NULL )
            {
                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++ )
        {
            if( m_pXvImage[i] != NULL )
            {

⌨️ 快捷键说明

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