From: Henri Verbeet Subject: [PATCH 1/5] ddraw: Use the window's client rect for clipping. Message-Id: <1325845207-30905-1-git-send-email-hverbeet@codeweavers.com> Date: Fri, 6 Jan 2012 11:20:03 +0100 --- dlls/ddraw/clipper.c | 76 ++++++++++++++++++++++++++++++++++++------------- 1 files changed, 56 insertions(+), 20 deletions(-) diff --git a/dlls/ddraw/clipper.c b/dlls/ddraw/clipper.c index b3482e7..5b8e9ce 100644 --- a/dlls/ddraw/clipper.c +++ b/dlls/ddraw/clipper.c @@ -93,6 +93,32 @@ static HRESULT WINAPI ddraw_clipper_SetHWnd(IDirectDrawClipper *iface, DWORD fla return DD_OK; } +static HRGN get_window_region(HWND window) +{ + POINT origin = {0, 0}; + RECT client_rect; + + if (!GetClientRect(window, &client_rect)) + { + ERR("Failed to get client rect.\n"); + return NULL; + } + + if (!ClientToScreen(window, &origin)) + { + ERR("Failed to translate origin.\n"); + return NULL; + } + + if (!OffsetRect(&client_rect, origin.x, origin.y)) + { + ERR("Failed to translate client rect.\n"); + return NULL; + } + + return CreateRectRgnIndirect(&client_rect); +} + /***************************************************************************** * IDirectDrawClipper::GetClipList * @@ -116,6 +142,7 @@ static HRESULT WINAPI ddraw_clipper_GetClipList(IDirectDrawClipper *iface, RECT { struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface); static unsigned int once; + HRGN region; TRACE("iface %p, rect %s, clip_list %p, clip_list_size %p.\n", iface, wine_dbgstr_rect(rect), clip_list, clip_list_size); @@ -124,31 +151,40 @@ static HRESULT WINAPI ddraw_clipper_GetClipList(IDirectDrawClipper *iface, RECT if (clipper->window) { - HDC dc = GetDCEx(clipper->window, NULL, DCX_WINDOW); - if (dc) + if (!(region = get_window_region(clipper->window))) + { + wined3d_mutex_unlock(); + ERR("Failed to get window region.\n"); + return E_FAIL; + } + + if (rect) { - HRGN rgn = CreateRectRgn(0, 0, 0, 0); - if (GetRandomRgn(dc, rgn, SYSRGN)) + HRGN clip_region; + int ret; + + if (!(clip_region = CreateRectRgnIndirect(rect))) + { + wined3d_mutex_unlock(); + ERR("Failed to create region.\n"); + DeleteObject(region); + return E_FAIL; + } + + ret = CombineRgn(region, region, clip_region, RGN_AND); + DeleteObject(clip_region); + if (ret == ERROR) { - if (GetVersion() & 0x80000000) - { - POINT origin; - GetDCOrgEx(dc, &origin); - OffsetRgn(rgn, origin.x, origin.y); - } - if (rect) - { - HRGN clip_rgn = CreateRectRgn(rect->left, rect->top, - rect->right, rect->bottom); - CombineRgn(rgn, rgn, clip_rgn, RGN_AND); - DeleteObject(clip_rgn); - } - *clip_list_size = GetRegionData(rgn, *clip_list_size, clip_list); + wined3d_mutex_unlock(); + ERR("Failed to combine regions.\n"); + DeleteObject(region); + return E_FAIL; } - DeleteObject(rgn); - ReleaseDC(clipper->window, dc); } + *clip_list_size = GetRegionData(region, *clip_list_size, clip_list); + DeleteObject(region); + wined3d_mutex_unlock(); return DD_OK; } -- 1.7.3.4