调用覆盖表面( Overlay Surfaces)的方法

编者:李国帅

qq:9611153 微信lgs9611153

时间:2012.5.10

背景原因:

覆盖表面是具有特殊硬件支持能力的表面,就像一张透明纸贴在主表面,改变看上去的画面。

以前的一个提取代码,可参考理解。

源码:

 

	// For create overlay surface
	LPDIRECTDRAW7			m_lpDD;
	LPDIRECTDRAWSURFACE7	m_lpPrimary;
	LPDIRECTDRAWSURFACE7	m_lpOverlay;


	VOID InitOverlays();
	VOID ReleaseOverlay();
	BOOL    CreateOverlay();
	BOOL	AreOverlaysSupported();

VOID CGraphPlayer::InitOverlays()
{
	m_lpDD		= NULL;
	m_lpPrimary = NULL;
	m_lpOverlay = NULL;
	CreateOverlay();
}

BOOL CGraphPlayer::AreOverlaysSupported()
{
    DDCAPS  capsDrv;
    HRESULT ddrval;

    // Get driver capabilities to determine Overlay support.
    ZeroMemory(&capsDrv, sizeof(capsDrv));
    capsDrv.dwSize = sizeof(capsDrv);

    ddrval = m_lpDD->GetCaps(&capsDrv, NULL);
    if (FAILED(ddrval))
    {
		return FALSE;
	}

    // Does the driver support overlays in the current mode?
    // (Currently the DirectDraw emulation layer does not support overlays.
    // Overlay related APIs will fail without hardware support).
    if (!(capsDrv.dwCaps & DDCAPS_OVERLAY))
	{
		return FALSE;
	}

    return TRUE;
}

VOID CGraphPlayer::ReleaseOverlay()
{
	if(NULL != m_lpOverlay)
	{
		lpOverlay->UpdateOverlay(NULL, m_lpPrimary, NULL, DDOVER_HIDE, NULL);
		IDirectDrawSurface_Release(m_lpOverlay);
		m_lpOverlay = NULL;
	}

	if(NULL != m_lpPrimary)
	{
		IDirectDrawSurface_Release(m_lpPrimary);
		m_lpPrimary = NULL;
	}

	if(NULL != m_lpDD)
	{
		IDirectDraw_Release(m_lpDD);
		m_lpDD = NULL;
	}
}
BOOL CGraphPlayer::CreateOverlay()
{
	// Initialize DDraw
	if(FAILED(DirectDrawCreateEx(NULL, (void**)&m_lpDD, IID_IDirectDraw7, NULL)))
	{
		return FALSE;
	}

	if(FAILED(m_lpDD->SetCooperativeLevel(NULL, DDSCL_NORMAL)))
	{
		IDirectDraw_Release(m_lpDD);
		m_lpDD = NULL;
		return FALSE;
	}

	// Try to create an overlay surface using one of the pixel formats
	FailedReturn(AreOverlaysSupported(), FALSE);

	// Create primary surface
	DDSURFACEDESC2 ddsd;
	ZeroMemory(&ddsd, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS ;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;

	HRESULT hr = m_lpDD->CreateSurface(&ddsd, &m_lpPrimary, NULL);
	if(FAILED(hr))
	{
		IDirectDraw_Release(m_lpDD);
		m_lpDD = NULL;
		return FALSE;
	}

	// Create overlay surface
	ZeroMemory(&ddsd, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwWidth = 320;
	ddsd.dwHeight = 240;
	ddsd.dwBackBufferCount = 0;
	ddsd.ddpfPixelFormat = g_ddpfOverlayFormats;
	ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT;
	ddsd.ddsCaps.dwCaps = DDSCAPS_OVERLAY | DDSCAPS_VIDEOMEMORY;

	hr = m_lpDD->CreateSurface(&ddsd, &m_lpOverlay, NULL);
	if(FAILED(hr))
	{
		IDirectDraw_Release(m_lpDD);
		IDirectDrawSurface_Release(m_lpPrimary);
		m_lpDD = NULL;
		m_lpPrimary	= NULL;
		return FALSE;
	}

	return TRUE;
}

 

 

猜你喜欢

转载自blog.csdn.net/lgs790709/article/details/84836306
0条评论
添加一条新回复