Ejemplo n.º 1
0
boolean BltCopy( LPDIRECTDRAWSURFACE7 src_surface, RECT * src_rect,
				 LPDIRECTDRAWSURFACE7 dst_surface, RECT * dst_rect )
{
	DDSURFACEDESC	ddsd_target;
	HRESULT			result;

	memset( &ddsd_target, 0, sizeof( ddsd_target ) );
	ddsd_target.dwSize = sizeof( ddsd_target );

	// attempt to blt the surface sontents

	result = IDirectDrawSurface7_Blt( dst_surface, dst_rect, src_surface, src_rect, DDBLT_WAIT, 0 );
	if( result != DD_OK )
	{
		if( result != DDERR_SURFACELOST )
		{
			IDirectDrawSurface7_Restore( src_surface );
			IDirectDrawSurface7_Restore( dst_surface );

			IDirectDrawSurface7_Blt( dst_surface, dst_rect, src_surface, src_rect, DDBLT_WAIT, 0 );
		}
		else
		{
			Error( 0, "IDirectDrawSurface7_Blt : error %i", result );
			return FALSE;
		}
	}

	return TRUE;
}
Ejemplo n.º 2
0
boolean Overlay( LPDIRECTDRAWSURFACE7 src_surface, RECT * src_rect,
			 LPDIRECTDRAWSURFACE7 dst_surface, RECT * dst_rect,
			 COLORREF color_key )
{
    DWORD					dw_color_key;
    DDPIXELFORMAT			ddpf;
	DDOVERLAYFX				ddofx;	
	int						flags;
	HRESULT					result;

	// compute the colorkey pixel value from the RGB value we've got/
	// NOTE : based on videolan colorkey code

    memset( &ddpf, 0, sizeof( DDPIXELFORMAT ));
    ddpf.dwSize = sizeof( DDPIXELFORMAT );
    result = IDirectDrawSurface7_GetPixelFormat( dst_surface, &ddpf );
	if( result != DD_OK )
	{
		Error( 0, "IDirectDrawSurface7_GetPixelFormat : could not get surface pixel format" );
		return FALSE;
	}

    dw_color_key = ( DWORD ) color_key;
    dw_color_key = ( DWORD ) ( ( ( dw_color_key * ddpf.dwRBitMask ) / 255 ) & ddpf.dwRBitMask );

    memset( &ddofx, 0, sizeof( DDOVERLAYFX ) );
    ddofx.dwSize = sizeof( DDOVERLAYFX );
    ddofx.dckDestColorkey.dwColorSpaceLowValue = dw_color_key;
    ddofx.dckDestColorkey.dwColorSpaceHighValue = dw_color_key;

	// set our overlay flags

    flags = DDOVER_SHOW | DDOVER_KEYDESTOVERRIDE;

	// attempt to overlay the surface

	result = IDirectDrawSurface7_UpdateOverlay( src_surface, src_rect, dst_surface, dst_rect, flags, &ddofx );
	if( result != DD_OK )
	{
		if( result == DDERR_SURFACELOST )
	    {
			IDirectDrawSurface7_Restore( src_surface );
			IDirectDrawSurface7_Restore( dst_surface );

			IDirectDrawSurface7_UpdateOverlay( src_surface, src_rect, dst_surface, dst_rect, flags, &ddofx );
		}
		else
		{
			Error( 0, "IDirectDrawSurface7_UpdateOverlay : error %i", result );
			return FALSE;
		}
	}

	return TRUE;
}
Ejemplo n.º 3
0
int RestoreDD(int w)
{
	if (w == 1)	// lpDDSBack
	{
		if(!lpDDSBack) return 0;
		if(IDirectDrawSurface7_Restore(lpDDSBack)!=DD_OK) return 0;
	} else	// 0 means lpDDSPrimary
	{
		if(!lpDDSPrimary) return 0;
		if(IDirectDrawSurface7_Restore(lpDDSPrimary)!=DD_OK) return 0;
	}
	veflags|=1;
	return 1;
}
Ejemplo n.º 4
0
void * Lock( void * surface )
{
	LPDIRECTDRAWSURFACE7	lock_surface = ( LPDIRECTDRAWSURFACE7 ) surface;
	DDSURFACEDESC2			ddsd;
	HRESULT					result;

	if( !surface )
		return 0;

	memset( &ddsd, 0, sizeof( ddsd ) );
	ddsd.dwSize = sizeof( ddsd );

	result = IDirectDrawSurface7_Lock( lock_surface, 0, &ddsd, DDLOCK_WAIT | DDLOCK_NOSYSLOCK, 0 );
	if( result == DDERR_SURFACELOST )
    {
		IDirectDrawSurface7_Restore( lock_surface );
		result = IDirectDrawSurface7_Lock( lock_surface, 0, &ddsd, DDLOCK_WAIT | DDLOCK_NOSYSLOCK, 0 );

		if( result != DD_OK )
			return 0;

	}
	else if( result != DD_OK )
	{
		if( result == DDERR_GENERIC )
		{
			Error( 0, "surface->Lock : error, DDERR_GENERIC" );
			exit( 1 );
		}
	}

	return ddsd.lpSurface;

	return 0;
}
Ejemplo n.º 5
0
// 删除表面
void DDrawSurfaceRelease(CSURFACE *surface)
{
	assert(surface);

	if (surface->clip) {
		IDirectDrawClipper_Release(surface->clip);
		surface->clip = NULL;
	}

	if (surface->lpDDS) {
		if (surface->lock) {
			IDirectDrawSurface7_Unlock(surface->lpDDS, NULL);
			surface->lock = 0;
		}
		if (IDirectDrawSurface7_IsLost(surface->lpDDS) != DD_OK) {
			IDirectDrawSurface7_Restore(surface->lpDDS);
		}
		IDirectDrawSurface7_Release(surface->lpDDS);
		surface->lpDDS = NULL;
		hSurfaceCounter--;
	}

	if (surface->primary) {
		if (lpDirectDraw7 && hFullScreenMode) {
			IDirectDraw7_RestoreDisplayMode(lpDirectDraw7);
		}
		hFullScreenMode = 0;
	}

	memset(surface, 0, sizeof(CSURFACE));
	free(surface);

	assert(hSurfaceCounter >= 0);
}
Ejemplo n.º 6
0
// 锁定表面:锁定后才能写数据,flags值如上面三个的组合
// 返回    0 成功,
// 返回    1 表示还在绘制,无法锁定(没有NOWAIT时)
// 返回   -1 表示已经锁定过了,无法再次锁定
// 返回   -2 锁定时候碰到的其他错误 
int DDrawSurfaceLock(CSURFACE *dst, void **bits, long *pitch, int flags)
{
	DDSURFACEDESC2 ddsd;
	DWORD dwFlags;
	HRESULT hr;

	dwFlags = 0;

	if (dst->lock) {
		return -1;
	}

	if ((flags & DDLOCK_NOWAIT) == 0) dwFlags |= DDLOCK_WAIT;
	if ((flags & DDLOCK_OREAD) != 0) dwFlags |= DDLOCK_READONLY;
	if ((flags & DDLOCK_OWRITE) != 0) dwFlags |= DDLOCK_WRITEONLY;

	memset(&ddsd, 0, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);

	hr = IDirectDrawSurface7_Lock(dst->lpDDS, NULL, &ddsd, dwFlags, NULL);

	if (hr == DDERR_SURFACELOST) {
		IDirectDrawSurface7_Restore(dst->lpDDS);
		hr = IDirectDrawSurface7_Lock(dst->lpDDS, NULL, &ddsd, dwFlags, 0);
	}

	if (hr == DDERR_WASSTILLDRAWING) 
		return 1;
	
	if (hr != DD_OK)
		return -2;

	dst->lock = 1;
	dst->bits = (unsigned char*)ddsd.lpSurface;
	dst->pitch = (long)ddsd.dwLinearSize;

	if (bits) *bits = (void*)ddsd.lpSurface;
	if (pitch) *pitch = (long)ddsd.dwLinearSize;

	return 0;
}
Ejemplo n.º 7
0
// 解锁表面:解锁后才能调用BLIT
// 返回    0 成功,
// 返回   -1 表示已经锁定过了,无法再次锁定
// 返回   -2 锁定时候碰到的其他错误 
int DDrawSurfaceUnlock(CSURFACE *dst)
{
	HRESULT hr;

	if (dst->lock == 0) {
		return -1;
	}

	hr = IDirectDrawSurface7_Unlock(dst->lpDDS, NULL);

	if (hr == DDERR_SURFACELOST) {
		IDirectDrawSurface7_Restore(dst->lpDDS);
		hr = IDirectDrawSurface7_Unlock(dst->lpDDS, NULL);
	}

	if (hr != DD_OK) 
		return -2;

	dst->lock = 0;

	return 0;
}
Ejemplo n.º 8
0
// BLIT: 
// (dx, dy, dw, dh)  -  目标表面的区域
// (sx, sy, sw, sh)  -  源表面的区域
// flags的设置在上面那些 DDBLIT_* 开头的宏
// 返回 0表示成功,其他值表示 DirectDrawSurface7::Blt的返回
int DDrawSurfaceBlit(CSURFACE *dst, int dx, int dy, int dw, int dh, 
	CSURFACE *src, int sx, int sy, int sw, int sh, int flags)
{
	LPDIRECTDRAWSURFACE7 lpDDS1;
	LPDIRECTDRAWSURFACE7 lpDDS2;
	RECT RectDst;
	RECT RectSrc;
	DWORD dwFlags;
	HRESULT hr;
	int DBW;
	int DBH;

	// get destination screen size
	if (dst->primary && hFullScreenMode == 0) {
		DDrawSurfaceInfo(dst, &DBW, &DBH, 0, 0);
	}	else {
		DBW = dst->w;
		DBH = dst->h;
	}

	if ((flags & DDBLIT_NOCLIP) == 0) {
		if (DDrawScaleClip(DBW, DBH, &dx, &dy, &dw, &dh,
			src->w, src->h, &sx, &sy, &sw, &sh) != 0) {
			return -1;
		}
	}

	// calculate destination rectangle (window & fullscreen)
	if (dst->primary && hFullScreenMode == 0) {
		RECT Window;
		POINT pt;
		GetClientRect(dst->hWnd, &Window);
		pt.x = pt.y = 0;
		ClientToScreen(dst->hWnd, &pt);
		OffsetRect(&Window, pt.x, pt.y);
		RectDst.left = Window.left + dx;
		RectDst.top = Window.top + dy;
		RectDst.right = RectDst.left + dw;
		RectDst.bottom = RectDst.top + dh;
	}	else {
		RectDst.left = dx;
		RectDst.top = dy;
		RectDst.right = RectDst.left + dw;
		RectDst.bottom = RectDst.top + dh;
	}

	// calculate source rectangle (window & fullscreen)
	if (src->primary && hFullScreenMode == 0) {
		RECT Window;
		POINT pt;
		GetClientRect(src->hWnd, &Window);
		pt.x = pt.y = 0;
		ClientToScreen(src->hWnd, &pt);
		OffsetRect(&Window, pt.x, pt.y);
		RectSrc.left = Window.left + sx;
		RectSrc.top = Window.top + sy;
		RectSrc.right = RectSrc.left + sw;
		RectSrc.bottom = RectSrc.top + sh;
	}	else {
		RectSrc.left = sx;
		RectSrc.top = sy;
		RectSrc.right = RectSrc.left + sw;
		RectSrc.bottom = RectSrc.top + sh;
	}

	lpDDS1 = dst->lpDDS;
	lpDDS2 = src->lpDDS;

	dwFlags = 0;

	if (flags & DDBLIT_MASK) dwFlags |= DDBLT_KEYSRC;
	if (flags & DDBLIT_NOWAIT) dwFlags |= DDBLT_DONOTWAIT;
	else dwFlags |= DDBLT_WAIT;

	hr = IDirectDrawSurface7_Blt(lpDDS1, &RectDst, lpDDS2, &RectSrc, 
		dwFlags, NULL);

	if (hr == DDERR_SURFACELOST) {
		if (IDirectDrawSurface7_IsLost(lpDDS1) == DDERR_SURFACELOST) {
			IDirectDrawSurface7_Restore(lpDDS1);
		}
		if (IDirectDrawSurface7_IsLost(lpDDS2) == DDERR_SURFACELOST) {
			IDirectDrawSurface7_Restore(lpDDS2);
		}
		hr = IDirectDrawSurface7_Blt(lpDDS1, &RectDst, lpDDS2, &RectSrc, 
			dwFlags, NULL);
	}

	if (hr != DD_OK) return (int)hr;

	return 0;
}