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

📄 user.c

📁 Wine-20031016
💻 C
📖 第 1 页 / 共 2 页
字号:
/*	User-based primary surface driver * * Copyright 2000-2001 TransGaming Technologies Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include "config.h"#include <assert.h>#include <stdlib.h>#include <string.h>#include "winerror.h"#include "wine/debug.h"#include "ddraw_private.h"#include "dsurface/main.h"#include "dsurface/dib.h"#include "dsurface/user.h"#include "dsurface/wndproc.h"WINE_DEFAULT_DEBUG_CHANNEL(ddraw);/* if you use OWN_WINDOW, don't use SYNC_UPDATE, or you may get trouble *//* #define SYNC_UPDATE *//* * FIXME: This does not work any more because the created window has its own *        thread queue that cannot be manipulated by application threads. * #define OWN_WINDOW */#ifdef OWN_WINDOWstatic void User_create_own_window(IDirectDrawSurfaceImpl* This);static void User_destroy_own_window(IDirectDrawSurfaceImpl* This);#endif#ifndef SYNC_UPDATEstatic DWORD CALLBACK User_update_thread(LPVOID);#endifstatic void User_copy_to_screen(IDirectDrawSurfaceImpl* This, LPCRECT rc);static HWND get_display_window(IDirectDrawSurfaceImpl* This, LPPOINT pt);static ICOM_VTABLE(IDirectDrawSurface7) User_IDirectDrawSurface7_VTable;HRESULTUser_DirectDrawSurface_Construct(IDirectDrawSurfaceImpl* This,				 IDirectDrawImpl* pDD,				 const DDSURFACEDESC2* pDDSD){    USER_PRIV_VAR(priv, This);    HRESULT hr;    TRACE("(%p,%p,%p)\n",This,pDD,pDDSD);    hr = DIB_DirectDrawSurface_Construct(This, pDD, pDDSD);    if (FAILED(hr)) return hr;    ICOM_INIT_INTERFACE(This, IDirectDrawSurface7,			User_IDirectDrawSurface7_VTable);    This->final_release = User_DirectDrawSurface_final_release;    This->duplicate_surface = User_DirectDrawSurface_duplicate_surface;    This->lock_update   = User_DirectDrawSurface_lock_update;    This->unlock_update = User_DirectDrawSurface_unlock_update;    This->flip_data   = User_DirectDrawSurface_flip_data;    This->flip_update = User_DirectDrawSurface_flip_update;    This->get_dc     = User_DirectDrawSurface_get_dc;    This->release_dc = User_DirectDrawSurface_release_dc;    This->set_palette    = User_DirectDrawSurface_set_palette;    This->update_palette = User_DirectDrawSurface_update_palette;    This->get_gamma_ramp = User_DirectDrawSurface_get_gamma_ramp;    This->set_gamma_ramp = User_DirectDrawSurface_set_gamma_ramp;    This->get_display_window = User_DirectDrawSurface_get_display_window;    if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)    {#ifdef OWN_WINDOW	DirectDrawSurface_RegisterClass();#endif#ifndef SYNC_UPDATE	InitializeCriticalSection(&priv->user.crit);	priv->user.refresh_event = CreateEventA(NULL, TRUE, FALSE, NULL);	priv->user.update_event = CreateEventA(NULL, FALSE, FALSE, NULL);	priv->user.update_thread = CreateThread(NULL, 0, User_update_thread, This, 0, NULL);#ifdef OWN_WINDOW	if (This->ddraw_owner->cooperative_level & DDSCL_FULLSCREEN) {	    /* wait for window creation (or update thread destruction) */	    while (WaitForMultipleObjects(1, &priv->user.update_thread, FALSE, 100) == WAIT_TIMEOUT)		if (This->more.lpDDRAWReserved) break;	    if (!This->more.lpDDRAWReserved) {		ERR("window creation failed\n");	    }	}#endif#else#ifdef OWN_WINDOW	User_create_own_window(This);#endif#endif	if (!This->more.lpDDRAWReserved)	    This->more.lpDDRAWReserved = (LPVOID)pDD->window;    }    return DIB_DirectDrawSurface_alloc_dc(This, &priv->user.cached_dc);}HRESULTUser_DirectDrawSurface_Create(IDirectDrawImpl *pDD,			      const DDSURFACEDESC2 *pDDSD,			      LPDIRECTDRAWSURFACE7 *ppSurf,			      IUnknown *pUnkOuter){    IDirectDrawSurfaceImpl* This;    HRESULT hr;    assert(pUnkOuter == NULL);    This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,		     sizeof(*This) + sizeof(User_DirectDrawSurfaceImpl));    if (This == NULL) return E_OUTOFMEMORY;    This->private = (User_DirectDrawSurfaceImpl*)(This+1);    hr = User_DirectDrawSurface_Construct(This, pDD, pDDSD);    if (FAILED(hr))	HeapFree(GetProcessHeap(), 0, This);    else	*ppSurf = ICOM_INTERFACE(This, IDirectDrawSurface7);    return hr;}void User_DirectDrawSurface_final_release(IDirectDrawSurfaceImpl* This){    USER_PRIV_VAR(priv, This);    if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)    {#ifndef SYNC_UPDATE	HANDLE event = priv->user.update_event;	priv->user.update_event = 0;	SetEvent(event);	TRACE("waiting for update thread to terminate...\n");#ifdef OWN_WINDOW	/* dispatch any waiting sendmessages */	{	    MSG msg;	    PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);	}	/* to avoid deadlocks, allow SendMessages from update thread	 * through while we wait for it */	while (MsgWaitForMultipleObjects(1, &priv->user.update_thread, FALSE,					 INFINITE, QS_SENDMESSAGE) == WAIT_OBJECT_0+1)	{	    MSG msg;	    PeekMessageA(&msg, 0, 0, 0, PM_NOREMOVE);	}#else	WaitForSingleObject(priv->user.update_thread,INFINITE);#endif	TRACE("update thread terminated\n");	CloseHandle(event);	CloseHandle(priv->user.update_thread);	CloseHandle(priv->user.refresh_event);	DeleteCriticalSection(&priv->user.crit);#else#ifdef OWN_WINDOW	User_destroy_own_window(This);#endif#endif	This->more.lpDDRAWReserved = 0;#ifdef OWN_WINDOW	DirectDrawSurface_UnregisterClass();#endif    }    DIB_DirectDrawSurface_free_dc(This, priv->user.cached_dc);    DIB_DirectDrawSurface_final_release(This);}static int User_DirectDrawSurface_init_wait(IDirectDrawSurfaceImpl* This){    USER_PRIV_VAR(priv, This);    int need_wait;    EnterCriticalSection(&priv->user.crit);    priv->user.wait_count++;    need_wait = priv->user.in_refresh;    LeaveCriticalSection(&priv->user.crit);    return need_wait;}static void User_DirectDrawSurface_end_wait(IDirectDrawSurfaceImpl* This){    USER_PRIV_VAR(priv, This);    EnterCriticalSection(&priv->user.crit);    if (!--priv->user.wait_count)	ResetEvent(priv->user.refresh_event);    LeaveCriticalSection(&priv->user.crit);}static void User_DirectDrawSurface_wait_update(IDirectDrawSurfaceImpl* This){    USER_PRIV_VAR(priv, This);    if (priv->user.in_refresh) {	if (User_DirectDrawSurface_init_wait(This))	    WaitForSingleObject(priv->user.refresh_event, 2);	User_DirectDrawSurface_end_wait(This);    }}void User_DirectDrawSurface_lock_update(IDirectDrawSurfaceImpl* This,					LPCRECT pRect, DWORD dwFlags){#if 0    if (!(dwFlags & DDLOCK_WRITEONLY))	User_copy_from_screen(This, pRect);#endif    if (dwFlags & DDLOCK_WAIT) User_DirectDrawSurface_wait_update(This);    if (pRect) {	This->lastlockrect = *pRect;    } else {	This->lastlockrect.left = This->lastlockrect.right = 0;    }}void User_DirectDrawSurface_unlock_update(IDirectDrawSurfaceImpl* This,					  LPCRECT pRect){    if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)    {#ifdef SYNC_UPDATE	User_copy_to_screen(This, pRect);#else	USER_PRIV_VAR(priv, This);	SetEvent(priv->user.update_event);#endif    }}void User_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl* This,					IDirectDrawPaletteImpl* pal){    USER_PRIV_VAR(priv, This);    if (!pal) {	FIXME("selecting null palette\n");	/* I don't think selecting GDI object 0 will work, we should select	 * the original palette, returned by the first SelectPalette */	SelectPalette(priv->user.cached_dc, 0, FALSE);	return;    }    SelectPalette(priv->user.cached_dc, pal->hpal, FALSE);    DIB_DirectDrawSurface_set_palette(This, pal);}void User_DirectDrawSurface_update_palette(IDirectDrawSurfaceImpl* This,					   IDirectDrawPaletteImpl* pal,					   DWORD dwStart, DWORD dwCount,					   LPPALETTEENTRY palent){#ifndef SYNC_UPDATE    USER_PRIV_VAR(priv, This);#endif    DIB_DirectDrawSurface_update_palette(This, pal, dwStart, dwCount, palent);    /* FIXME: realize palette on display window */#ifndef SYNC_UPDATE    /* with async updates, it's probably cool to force an update */    SetEvent(priv->user.update_event);#endif}HRESULT User_DirectDrawSurface_duplicate_surface(IDirectDrawSurfaceImpl* This,						 LPDIRECTDRAWSURFACE7* ppDup){    return User_DirectDrawSurface_Create(This->ddraw_owner,					 &This->surface_desc, ppDup, NULL);}BOOL User_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl* front,				      IDirectDrawSurfaceImpl* back,				      DWORD dwFlags){    USER_PRIV_VAR(front_priv, front);    USER_PRIV_VAR(back_priv, back);    {	HDC tmp;	tmp = front_priv->user.cached_dc;	front_priv->user.cached_dc = back_priv->user.cached_dc;	back_priv->user.cached_dc = tmp;    }    return DIB_DirectDrawSurface_flip_data(front, back, dwFlags);}void User_DirectDrawSurface_flip_update(IDirectDrawSurfaceImpl* This, DWORD dwFlags){#ifdef SYNC_UPDATE    This->lastlockrect.left = This->lastlockrect.right = 0;    assert(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE);    User_copy_to_screen(This,NULL);#else    USER_PRIV_VAR(priv, This);    assert(This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE);    if (dwFlags & DDFLIP_WAIT) User_DirectDrawSurface_wait_update(This);    This->lastlockrect.left = This->lastlockrect.right = 0;    SetEvent(priv->user.update_event);#endif}HRESULT User_DirectDrawSurface_get_dc(IDirectDrawSurfaceImpl* This, HDC* phDC){    USER_PRIV_VAR(priv, This);    *phDC = priv->user.cached_dc;    return S_OK;}HRESULT User_DirectDrawSurface_release_dc(IDirectDrawSurfaceImpl* This,					  HDC hDC){

⌨️ 快捷键说明

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