2001-01-04 23:44:55 +01:00
|
|
|
/* User-based primary surface driver
|
|
|
|
*
|
2001-04-17 19:34:11 +02:00
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-01-04 23:44:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
2001-01-26 21:43:40 +01:00
|
|
|
#include <string.h>
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2001-01-26 21:43:40 +01:00
|
|
|
#include "winerror.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2001-01-04 23:44:55 +01:00
|
|
|
#include "ddraw_private.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
/* if you use OWN_WINDOW, don't use SYNC_UPDATE, or you may get trouble */
|
|
|
|
/* #define SYNC_UPDATE */
|
2002-06-29 01:26:57 +02:00
|
|
|
/*
|
2002-07-20 22:01:57 +02:00
|
|
|
* FIXME: This does not work any more because the created window has its own
|
2002-06-29 01:26:57 +02:00
|
|
|
* thread queue that cannot be manipulated by application threads.
|
2002-07-20 22:01:57 +02:00
|
|
|
* #define OWN_WINDOW
|
2002-06-29 01:26:57 +02:00
|
|
|
*/
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
static void User_create_own_window(IDirectDrawSurfaceImpl* This);
|
|
|
|
static void User_destroy_own_window(IDirectDrawSurfaceImpl* This);
|
|
|
|
#endif
|
|
|
|
#ifndef SYNC_UPDATE
|
|
|
|
static DWORD CALLBACK User_update_thread(LPVOID);
|
|
|
|
#endif
|
|
|
|
static void User_copy_to_screen(IDirectDrawSurfaceImpl* This, LPCRECT rc);
|
|
|
|
|
2001-04-17 19:34:11 +02:00
|
|
|
static HWND get_display_window(IDirectDrawSurfaceImpl* This, LPPOINT pt);
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirectDrawSurface7Vtbl User_IDirectDrawSurface7_VTable;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
HRESULT
|
|
|
|
User_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;
|
|
|
|
|
2001-04-17 19:34:11 +02:00
|
|
|
This->get_gamma_ramp = User_DirectDrawSurface_get_gamma_ramp;
|
|
|
|
This->set_gamma_ramp = User_DirectDrawSurface_set_gamma_ramp;
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
This->get_display_window = User_DirectDrawSurface_get_display_window;
|
|
|
|
|
|
|
|
if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
|
|
|
{
|
2001-04-17 19:34:11 +02:00
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
DirectDrawSurface_RegisterClass();
|
|
|
|
#endif
|
2001-01-04 23:44:55 +01:00
|
|
|
#ifndef SYNC_UPDATE
|
2002-07-20 22:01:57 +02:00
|
|
|
InitializeCriticalSection(&priv->user.crit);
|
2005-01-07 16:40:09 +01:00
|
|
|
priv->user.refresh_event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
priv->user.update_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2001-01-04 23:44:55 +01:00
|
|
|
priv->user.update_thread = CreateThread(NULL, 0, User_update_thread, This, 0, NULL);
|
2001-04-17 19:34:11 +02:00
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
if (This->ddraw_owner->cooperative_level & DDSCL_FULLSCREEN) {
|
|
|
|
/* wait for window creation (or update thread destruction) */
|
2002-07-20 22:01:57 +02:00
|
|
|
while (WaitForMultipleObjects(1, &priv->user.update_thread, FALSE, 100) == WAIT_TIMEOUT)
|
2001-04-17 19:34:11 +02:00
|
|
|
if (This->more.lpDDRAWReserved) break;
|
|
|
|
if (!This->more.lpDDRAWReserved) {
|
|
|
|
ERR("window creation failed\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2001-01-04 23:44:55 +01:00
|
|
|
#else
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
User_create_own_window(This);
|
|
|
|
#endif
|
|
|
|
#endif
|
2001-04-17 19:34:11 +02:00
|
|
|
if (!This->more.lpDDRAWReserved)
|
|
|
|
This->more.lpDDRAWReserved = (LPVOID)pDD->window;
|
2001-01-04 23:44:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return DIB_DirectDrawSurface_alloc_dc(This, &priv->user.cached_dc);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
User_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");
|
2002-07-20 22:01:57 +02:00
|
|
|
CloseHandle(event);
|
2001-01-04 23:44:55 +01:00
|
|
|
CloseHandle(priv->user.update_thread);
|
2002-07-20 22:01:57 +02:00
|
|
|
CloseHandle(priv->user.refresh_event);
|
|
|
|
DeleteCriticalSection(&priv->user.crit);
|
2001-01-04 23:44:55 +01:00
|
|
|
#else
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
User_destroy_own_window(This);
|
|
|
|
#endif
|
2001-04-17 19:34:11 +02:00
|
|
|
#endif
|
|
|
|
This->more.lpDDRAWReserved = 0;
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
DirectDrawSurface_UnregisterClass();
|
2001-01-04 23:44:55 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
DIB_DirectDrawSurface_free_dc(This, priv->user.cached_dc);
|
|
|
|
DIB_DirectDrawSurface_final_release(This);
|
|
|
|
}
|
|
|
|
|
2002-07-20 22:01:57 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
void User_DirectDrawSurface_lock_update(IDirectDrawSurfaceImpl* This,
|
2001-09-11 01:12:16 +02:00
|
|
|
LPCRECT pRect, DWORD dwFlags)
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
2002-07-20 22:01:57 +02:00
|
|
|
#if 0
|
2001-09-11 01:12:16 +02:00
|
|
|
if (!(dwFlags & DDLOCK_WRITEONLY))
|
|
|
|
User_copy_from_screen(This, pRect);
|
2002-07-20 22:01:57 +02:00
|
|
|
#endif
|
|
|
|
if (dwFlags & DDLOCK_WAIT) User_DirectDrawSurface_wait_update(This);
|
2001-09-11 01:12:16 +02:00
|
|
|
|
|
|
|
if (pRect) {
|
|
|
|
This->lastlockrect = *pRect;
|
|
|
|
} else {
|
|
|
|
This->lastlockrect.left = This->lastlockrect.right = 0;
|
|
|
|
}
|
2001-01-04 23:44:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void User_DirectDrawSurface_unlock_update(IDirectDrawSurfaceImpl* This,
|
|
|
|
LPCRECT pRect)
|
|
|
|
{
|
2002-07-20 22:01:57 +02:00
|
|
|
if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
|
|
|
{
|
2001-01-04 23:44:55 +01:00
|
|
|
#ifdef SYNC_UPDATE
|
2002-07-20 22:01:57 +02:00
|
|
|
User_copy_to_screen(This, pRect);
|
2001-01-04 23:44:55 +01:00
|
|
|
#else
|
2002-07-20 22:01:57 +02:00
|
|
|
USER_PRIV_VAR(priv, This);
|
|
|
|
SetEvent(priv->user.update_event);
|
2001-01-04 23:44:55 +01:00
|
|
|
#endif
|
2002-07-20 22:01:57 +02:00
|
|
|
}
|
2001-01-04 23:44:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void User_DirectDrawSurface_set_palette(IDirectDrawSurfaceImpl* This,
|
2002-06-01 01:06:46 +02:00
|
|
|
IDirectDrawPaletteImpl* pal)
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2002-07-20 22:01:57 +02:00
|
|
|
#ifndef SYNC_UPDATE
|
2001-01-04 23:44:55 +01:00
|
|
|
USER_PRIV_VAR(priv, This);
|
2002-07-20 22:01:57 +02:00
|
|
|
#endif
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2001-04-16 21:06:13 +02:00
|
|
|
BOOL User_DirectDrawSurface_flip_data(IDirectDrawSurfaceImpl* front,
|
|
|
|
IDirectDrawSurfaceImpl* back,
|
|
|
|
DWORD dwFlags)
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-04-16 21:06:13 +02:00
|
|
|
return DIB_DirectDrawSurface_flip_data(front, back, dwFlags);
|
2001-01-04 23:44:55 +01:00
|
|
|
}
|
|
|
|
|
2001-04-16 21:06:13 +02:00
|
|
|
void User_DirectDrawSurface_flip_update(IDirectDrawSurfaceImpl* This, DWORD dwFlags)
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
|
|
|
#ifdef SYNC_UPDATE
|
2001-10-17 19:45:53 +02:00
|
|
|
This->lastlockrect.left = This->lastlockrect.right = 0;
|
2001-01-04 23:44:55 +01:00
|
|
|
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);
|
2002-07-20 22:01:57 +02:00
|
|
|
if (dwFlags & DDFLIP_WAIT) User_DirectDrawSurface_wait_update(This);
|
|
|
|
This->lastlockrect.left = This->lastlockrect.right = 0;
|
2001-01-04 23:44:55 +01:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-17 19:34:11 +02:00
|
|
|
HRESULT User_DirectDrawSurface_get_gamma_ramp(IDirectDrawSurfaceImpl* This,
|
|
|
|
DWORD dwFlags,
|
|
|
|
LPDDGAMMARAMP lpGammaRamp)
|
|
|
|
{
|
|
|
|
if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
|
|
|
{
|
|
|
|
POINT offset;
|
|
|
|
HWND hDisplayWnd;
|
|
|
|
HDC hDisplayDC;
|
|
|
|
HRESULT hr;
|
|
|
|
hDisplayWnd = get_display_window(This, &offset);
|
2001-07-31 02:14:06 +02:00
|
|
|
hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
|
2001-04-17 19:34:11 +02:00
|
|
|
hr = GetDeviceGammaRamp(hDisplayDC, lpGammaRamp) ? DD_OK : DDERR_UNSUPPORTED;
|
|
|
|
ReleaseDC(hDisplayWnd, hDisplayDC);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
return Main_DirectDrawSurface_get_gamma_ramp(This, dwFlags, lpGammaRamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT User_DirectDrawSurface_set_gamma_ramp(IDirectDrawSurfaceImpl* This,
|
|
|
|
DWORD dwFlags,
|
|
|
|
LPDDGAMMARAMP lpGammaRamp)
|
|
|
|
{
|
|
|
|
if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
|
|
|
{
|
|
|
|
POINT offset;
|
|
|
|
HWND hDisplayWnd;
|
|
|
|
HDC hDisplayDC;
|
|
|
|
HRESULT hr;
|
|
|
|
hDisplayWnd = get_display_window(This, &offset);
|
2001-07-31 02:14:06 +02:00
|
|
|
hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
|
2001-04-17 19:34:11 +02:00
|
|
|
hr = SetDeviceGammaRamp(hDisplayDC, lpGammaRamp) ? DD_OK : DDERR_UNSUPPORTED;
|
|
|
|
ReleaseDC(hDisplayWnd, hDisplayDC);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
return Main_DirectDrawSurface_set_gamma_ramp(This, dwFlags, lpGammaRamp);
|
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
/* Returns the window that hosts the display.
|
|
|
|
* *pt is set to the upper left position of the window relative to the
|
|
|
|
* upper left corner of the surface. */
|
|
|
|
static HWND get_display_window(IDirectDrawSurfaceImpl* This, LPPOINT pt)
|
|
|
|
{
|
|
|
|
memset(pt, 0, sizeof(*pt));
|
|
|
|
|
|
|
|
if (This->ddraw_owner->cooperative_level & DDSCL_FULLSCREEN)
|
|
|
|
{
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
USER_PRIV_VAR(priv, This);
|
2001-04-17 19:34:11 +02:00
|
|
|
#if 1
|
2001-01-04 23:44:55 +01:00
|
|
|
SetWindowPos(priv->user.window, HWND_TOP, 0, 0, 0, 0,
|
|
|
|
SWP_DEFERERASE|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|
|
|
|
|
SWP_NOREDRAW|SWP_NOSENDCHANGING|SWP_NOSIZE);
|
2001-04-17 19:34:11 +02:00
|
|
|
#endif
|
2001-01-04 23:44:55 +01:00
|
|
|
return priv->user.window;
|
|
|
|
#else
|
|
|
|
return This->ddraw_owner->window;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (This->clipper != NULL)
|
|
|
|
{
|
|
|
|
/* looks silly, but since we don't have the clipper locked */
|
|
|
|
HWND hWnd = This->clipper->hWnd;
|
|
|
|
|
|
|
|
if (hWnd != 0)
|
|
|
|
{
|
|
|
|
ClientToScreen(hWnd, pt);
|
|
|
|
return hWnd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static BOOL warn = 0;
|
|
|
|
if (!warn++) FIXME("clipper clip lists not supported\n");
|
|
|
|
|
|
|
|
return GetDesktopWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static BOOL warn = 0;
|
|
|
|
if (!warn++) WARN("hosting on root\n");
|
|
|
|
|
|
|
|
return GetDesktopWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND User_DirectDrawSurface_get_display_window(IDirectDrawSurfaceImpl* This)
|
|
|
|
{
|
|
|
|
POINT offset;
|
|
|
|
return get_display_window(This, &offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
static void User_create_own_window(IDirectDrawSurfaceImpl* This)
|
|
|
|
{
|
|
|
|
USER_PRIV_VAR(priv, This);
|
|
|
|
|
|
|
|
if (This->ddraw_owner->cooperative_level & DDSCL_FULLSCREEN)
|
|
|
|
{
|
2001-04-17 19:34:11 +02:00
|
|
|
priv->user.window = CreateWindowExA(WS_EX_TOPMOST |
|
|
|
|
WS_EX_LAYERED |
|
|
|
|
WS_EX_TRANSPARENT,
|
2001-01-04 23:44:55 +01:00
|
|
|
"WINE_DDRAW", "DirectDraw",
|
|
|
|
WS_POPUP,
|
|
|
|
0, 0,
|
|
|
|
This->surface_desc.dwWidth,
|
|
|
|
This->surface_desc.dwHeight,
|
|
|
|
GetDesktopWindow(),
|
|
|
|
0, 0, This);
|
2001-04-17 19:34:11 +02:00
|
|
|
This->more.lpDDRAWReserved = (LPVOID)priv->user.window;
|
2001-01-04 23:44:55 +01:00
|
|
|
SetWindowPos(priv->user.window, HWND_TOP, 0, 0, 0, 0,
|
|
|
|
SWP_DEFERERASE|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|
|
|
|
|
SWP_NOREDRAW|SWP_NOSENDCHANGING|SWP_NOSIZE|SWP_SHOWWINDOW);
|
|
|
|
UpdateWindow(priv->user.window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void User_destroy_own_window(IDirectDrawSurfaceImpl* This)
|
|
|
|
{
|
|
|
|
USER_PRIV_VAR(priv, This);
|
|
|
|
|
2001-01-13 00:18:22 +01:00
|
|
|
if (priv->user.window)
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
|
|
|
SetWindowPos(priv->user.window, 0, 0, 0, 0, 0,
|
|
|
|
SWP_DEFERERASE|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOMOVE|SWP_NOZORDER|
|
|
|
|
SWP_NOREDRAW|SWP_NOSENDCHANGING|SWP_NOSIZE|SWP_HIDEWINDOW);
|
2001-04-17 19:34:11 +02:00
|
|
|
This->more.lpDDRAWReserved = NULL;
|
2001-01-04 23:44:55 +01:00
|
|
|
DestroyWindow(priv->user.window);
|
2001-01-13 00:18:22 +01:00
|
|
|
priv->user.window = 0;
|
2001-01-04 23:44:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SYNC_UPDATE
|
|
|
|
static DWORD CALLBACK User_update_thread(LPVOID arg)
|
|
|
|
{
|
|
|
|
IDirectDrawSurfaceImpl *This = (IDirectDrawSurfaceImpl *)arg;
|
|
|
|
USER_PRIV_VAR(priv, This);
|
2002-10-19 01:48:57 +02:00
|
|
|
volatile HANDLE *pActive = (volatile HANDLE *)&priv->user.update_event;
|
2001-01-04 23:44:55 +01:00
|
|
|
HANDLE event = *pActive;
|
|
|
|
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
User_create_own_window(This);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* the point of this is that many games lock the primary surface
|
|
|
|
* multiple times per frame; this thread will then simply copy as
|
|
|
|
* often as it can without keeping the main thread waiting for
|
|
|
|
* each unlock, thus keeping the frame rate high */
|
|
|
|
do {
|
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
DWORD ret = MsgWaitForMultipleObjects(1, &event, FALSE, INFINITE, QS_ALLINPUT);
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
switch (msg.message) {
|
|
|
|
case WM_PAINT:
|
|
|
|
DispatchMessageA(&msg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* since we risk getting keyboard messages posted to us,
|
|
|
|
* repost posted messages to cooperative window */
|
|
|
|
PostMessageA(This->ddraw_owner->window, msg.message, msg.wParam, msg.lParam);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
DWORD ret = WaitForSingleObject(event, INFINITE);
|
|
|
|
#endif
|
|
|
|
if (ret == WAIT_OBJECT_0)
|
|
|
|
{
|
2002-07-20 22:01:57 +02:00
|
|
|
if (*pActive) {
|
|
|
|
priv->user.in_refresh = TRUE;
|
2001-01-04 23:44:55 +01:00
|
|
|
User_copy_to_screen(This, NULL);
|
2002-07-20 22:01:57 +02:00
|
|
|
EnterCriticalSection(&priv->user.crit);
|
|
|
|
priv->user.in_refresh = FALSE;
|
|
|
|
if (priv->user.wait_count)
|
|
|
|
SetEvent(priv->user.refresh_event);
|
|
|
|
LeaveCriticalSection(&priv->user.crit);
|
|
|
|
} else
|
2001-01-04 23:44:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (ret != WAIT_OBJECT_0+1) break;
|
|
|
|
} while (TRUE);
|
|
|
|
|
2002-07-20 22:01:57 +02:00
|
|
|
SetEvent(priv->user.refresh_event);
|
2001-01-04 23:44:55 +01:00
|
|
|
#ifdef OWN_WINDOW
|
|
|
|
User_destroy_own_window(This);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void User_copy_to_screen(IDirectDrawSurfaceImpl* This, LPCRECT rc)
|
|
|
|
{
|
|
|
|
if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
|
|
|
{
|
|
|
|
POINT offset;
|
|
|
|
HWND hDisplayWnd;
|
|
|
|
HDC hDisplayDC;
|
|
|
|
HDC hSurfaceDC;
|
2001-09-11 01:12:16 +02:00
|
|
|
RECT drawrect;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
if (FAILED(This->get_dc(This, &hSurfaceDC)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
hDisplayWnd = get_display_window(This, &offset);
|
2001-07-31 02:14:06 +02:00
|
|
|
hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
|
2001-01-04 23:44:55 +01:00
|
|
|
#if 0
|
|
|
|
/* FIXME: this doesn't work... if users really want to run
|
|
|
|
* X in 8bpp, then we need to call directly into display.drv
|
|
|
|
* (or Wine's equivalent), and force a private colormap
|
|
|
|
* without default entries. */
|
|
|
|
if (This->palette) {
|
|
|
|
SelectPalette(hDisplayDC, This->palette->hpal, FALSE);
|
|
|
|
RealizePalette(hDisplayDC); /* sends messages => deadlocks */
|
|
|
|
}
|
|
|
|
#endif
|
2001-09-11 01:12:16 +02:00
|
|
|
drawrect.left = 0;
|
|
|
|
drawrect.right = This->surface_desc.dwWidth;
|
|
|
|
drawrect.top = 0;
|
|
|
|
drawrect.bottom = This->surface_desc.dwHeight;
|
|
|
|
|
|
|
|
if (This->clipper) {
|
|
|
|
RECT xrc;
|
|
|
|
HWND hwnd = This->clipper->hWnd;
|
2002-07-20 22:01:57 +02:00
|
|
|
if (hwnd && GetClientRect(hwnd,&xrc)) {
|
|
|
|
OffsetRect(&xrc,offset.x,offset.y);
|
2001-09-11 01:12:16 +02:00
|
|
|
IntersectRect(&drawrect,&drawrect,&xrc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rc)
|
|
|
|
IntersectRect(&drawrect,&drawrect,rc);
|
|
|
|
else {
|
|
|
|
/* Only use this if the caller did not pass a rectangle, since
|
|
|
|
* due to double locking this could be the wrong one ... */
|
|
|
|
if (This->lastlockrect.left != This->lastlockrect.right)
|
|
|
|
IntersectRect(&drawrect,&drawrect,&This->lastlockrect);
|
|
|
|
}
|
|
|
|
BitBlt(hDisplayDC,
|
2002-07-20 22:01:57 +02:00
|
|
|
drawrect.left-offset.x, drawrect.top-offset.y,
|
2001-09-11 01:12:16 +02:00
|
|
|
drawrect.right-drawrect.left, drawrect.bottom-drawrect.top,
|
|
|
|
hSurfaceDC,
|
|
|
|
drawrect.left, drawrect.top,
|
|
|
|
SRCCOPY
|
|
|
|
);
|
2001-01-04 23:44:55 +01:00
|
|
|
ReleaseDC(hDisplayWnd, hDisplayDC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-02 03:34:17 +02:00
|
|
|
#if 0
|
2001-01-04 23:44:55 +01:00
|
|
|
static void User_copy_from_screen(IDirectDrawSurfaceImpl* This, LPCRECT rc)
|
|
|
|
{
|
|
|
|
if (This->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
|
|
|
|
{
|
|
|
|
POINT offset;
|
|
|
|
HWND hDisplayWnd = get_display_window(This, &offset);
|
|
|
|
HDC hDisplayDC = GetDC(hDisplayWnd);
|
2001-09-11 01:12:16 +02:00
|
|
|
RECT drawrect;
|
|
|
|
|
|
|
|
drawrect.left = 0;
|
|
|
|
drawrect.right = This->surface_desc.dwWidth;
|
|
|
|
drawrect.top = 0;
|
|
|
|
drawrect.bottom = This->surface_desc.dwHeight;
|
|
|
|
if (rc)
|
|
|
|
IntersectRect(&drawrect,&drawrect,rc);
|
|
|
|
|
|
|
|
BitBlt(This->hDC,
|
|
|
|
drawrect.left, drawrect.top,
|
|
|
|
drawrect.right-drawrect.left, drawrect.bottom-drawrect.top,
|
|
|
|
hDisplayDC,
|
|
|
|
drawrect.left+offset.x, drawrect.top+offset.y,
|
|
|
|
SRCCOPY
|
|
|
|
);
|
2001-01-04 23:44:55 +01:00
|
|
|
ReleaseDC(hDisplayWnd, hDisplayDC);
|
|
|
|
}
|
|
|
|
}
|
2002-10-02 03:34:17 +02:00
|
|
|
#endif
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IDirectDrawSurface7Vtbl User_IDirectDrawSurface7_VTable =
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
|
|
|
Main_DirectDrawSurface_QueryInterface,
|
|
|
|
Main_DirectDrawSurface_AddRef,
|
|
|
|
Main_DirectDrawSurface_Release,
|
|
|
|
Main_DirectDrawSurface_AddAttachedSurface,
|
|
|
|
Main_DirectDrawSurface_AddOverlayDirtyRect,
|
|
|
|
DIB_DirectDrawSurface_Blt,
|
|
|
|
Main_DirectDrawSurface_BltBatch,
|
|
|
|
DIB_DirectDrawSurface_BltFast,
|
|
|
|
Main_DirectDrawSurface_DeleteAttachedSurface,
|
|
|
|
Main_DirectDrawSurface_EnumAttachedSurfaces,
|
|
|
|
Main_DirectDrawSurface_EnumOverlayZOrders,
|
|
|
|
Main_DirectDrawSurface_Flip,
|
|
|
|
Main_DirectDrawSurface_GetAttachedSurface,
|
|
|
|
Main_DirectDrawSurface_GetBltStatus,
|
|
|
|
Main_DirectDrawSurface_GetCaps,
|
|
|
|
Main_DirectDrawSurface_GetClipper,
|
|
|
|
Main_DirectDrawSurface_GetColorKey,
|
|
|
|
Main_DirectDrawSurface_GetDC,
|
|
|
|
Main_DirectDrawSurface_GetFlipStatus,
|
|
|
|
Main_DirectDrawSurface_GetOverlayPosition,
|
|
|
|
Main_DirectDrawSurface_GetPalette,
|
|
|
|
Main_DirectDrawSurface_GetPixelFormat,
|
|
|
|
Main_DirectDrawSurface_GetSurfaceDesc,
|
|
|
|
Main_DirectDrawSurface_Initialize,
|
|
|
|
Main_DirectDrawSurface_IsLost,
|
|
|
|
Main_DirectDrawSurface_Lock,
|
|
|
|
Main_DirectDrawSurface_ReleaseDC,
|
|
|
|
DIB_DirectDrawSurface_Restore,
|
|
|
|
Main_DirectDrawSurface_SetClipper,
|
|
|
|
Main_DirectDrawSurface_SetColorKey,
|
|
|
|
Main_DirectDrawSurface_SetOverlayPosition,
|
|
|
|
Main_DirectDrawSurface_SetPalette,
|
|
|
|
Main_DirectDrawSurface_Unlock,
|
|
|
|
Main_DirectDrawSurface_UpdateOverlay,
|
|
|
|
Main_DirectDrawSurface_UpdateOverlayDisplay,
|
|
|
|
Main_DirectDrawSurface_UpdateOverlayZOrder,
|
|
|
|
Main_DirectDrawSurface_GetDDInterface,
|
|
|
|
Main_DirectDrawSurface_PageLock,
|
|
|
|
Main_DirectDrawSurface_PageUnlock,
|
|
|
|
DIB_DirectDrawSurface_SetSurfaceDesc,
|
|
|
|
Main_DirectDrawSurface_SetPrivateData,
|
|
|
|
Main_DirectDrawSurface_GetPrivateData,
|
|
|
|
Main_DirectDrawSurface_FreePrivateData,
|
|
|
|
Main_DirectDrawSurface_GetUniquenessValue,
|
|
|
|
Main_DirectDrawSurface_ChangeUniquenessValue,
|
|
|
|
Main_DirectDrawSurface_SetPriority,
|
|
|
|
Main_DirectDrawSurface_GetPriority,
|
|
|
|
Main_DirectDrawSurface_SetLOD,
|
|
|
|
Main_DirectDrawSurface_GetLOD
|
|
|
|
};
|