📄 unixsurf.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: unixsurf.cpp,v 1.2.40.5 2004/07/20 23:43:41 nhart Exp $ * * Portions Copyright (c) 1995-2004 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 (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (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. * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. * * 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;#endifCUnixSurf::CUnixSurf( IUnknown* pContext, CHXBaseSite* pSite ) : CBaseSurface( pContext, pSite )#if defined(_LINUX) && defined(_OVERLAY) , m_bWallPaperMode(FALSE) , m_nPortID(-1) , m_bPaintClipList(TRUE) , m_ulColorKey(0x01020304) , m_bStretchToFill(FALSE) , m_pXvImage(NULL) , m_atomColorKey(None) , m_atomClipKey(None)#if defined(HELIX_FEATURE_HARDWARE_COLOR_CONTROLS) , m_atomBrightness(None) , m_atomContrast(None) , m_atomHue(None) , m_atomSaturation(None) , m_nCurrBrightness(0) , m_nCurrContrast(0) , m_nCurrHue(0) , m_nCurrSaturation(0)#endif , 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; } } //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) { XLockDisplay(m_display); XFreeGC(m_display, m_GC); XUnlockDisplay(m_display); 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 ) { 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]); } } 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 ) { XFree( m_pXvImage[i] ); m_pXvImage[i] = NULL; } } } m_nVideoPitch = 0; HX_ASSERT( m_display ); //Clear BitmapInfo struct.... HXBitmapInfo bmi; memset( &bmi, 0, sizeof(HXBitmapInfo) ); int nResult = MakeBitmap( &bmi, sizeof(bmi), m_nSurfaceCID, m_surfaceSize.cx, m_surfaceSize.cy, NULL, 0); if( nResult ) { ShmHelp::Init(m_display); m_bUseShm = ShmHelp::ShmAvailable(); for( i=0 ; i<m_nMultiBufferCount ; i++ ) { if( m_bUseShm ) { HX_RESULT retVal = ShmHelp::CreateSharedRegion( bmi.bmiHeader.biSizeImage, &m_pcVideoBuf[i], &m_nShmId[i], &m_shmInfo[i] ); if( retVal != HXR_OK ) { HX_ASSERT("Can't alloc shared memory segment." == NULL ); m_nShmId[i] = -1; m_pcVideoBuf[i] = NULL; } } //did the shm alloc work? if( m_pcVideoBuf[i] == NULL ) { m_bUseShm = FALSE; m_nShmId[i] = -1; m_pcVideoBuf[i] = new UCHAR[bmi.bmiHeader.biSizeImage]; } HX_ASSERT( m_pcVideoBuf ); } m_nVideoPitch = GetBitmapPitch(&bmi); } HX_ASSERT( m_nVideoPitch != 0 ); //Now create the XvImage to blt to..... HX_ASSERT( m_nPortID != -1 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -