From f976cd0c9ead6a5e63146c11823770176c149a12 Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Mon, 27 Sep 2010 20:25:17 +0200 Subject: [PATCH] d3d1x: rework DXGI for occlusion testing and default width/height --- .../d3d1x/dxgi/src/dxgi_native.cpp | 89 +++++++++++++++++-- .../d3d1x/gd3dapi/galliumdxgi.idl | 26 ++++-- .../d3d1x/winedlls/dxgi/dxgi_dll.c | 88 ++++++++++++++---- 3 files changed, 174 insertions(+), 29 deletions(-) diff --git a/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp b/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp index a75a953abfb..e1c34611d14 100644 --- a/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp +++ b/src/gallium/state_trackers/d3d1x/dxgi/src/dxgi_native.cpp @@ -65,10 +65,12 @@ struct GalliumDXGIObject : public GalliumPrivateDataComObject COM_INTERFACE(IGalliumDXGIBackend, IUnknown) +// TODO: somehow check whether the window is fully obscured or not struct GalliumDXGIIdentityBackend : public GalliumComObject { - virtual void * STDMETHODCALLTYPE BeginPresent( + virtual HRESULT STDMETHODCALLTYPE BeginPresent( HWND hwnd, + void** present_cookie, void** window, RECT *rect, RGNDATA **rgndata, @@ -84,7 +86,8 @@ struct GalliumDXGIIdentityBackend : public GalliumComObject // yes, because we like things looking good *preserve_aspect_ratio = TRUE; - return 0; + *present_cookie = 0; + return S_OK; } virtual void STDMETHODCALLTYPE EndPresent( @@ -92,6 +95,45 @@ struct GalliumDXGIIdentityBackend : public GalliumComObject void* present_cookie ) {} + + virtual HRESULT STDMETHODCALLTYPE TestPresent(HWND hwnd) + { + return S_OK; + } + + virtual HRESULT STDMETHODCALLTYPE GetPresentSize( + HWND hwnd, + unsigned* width, + unsigned* height + ) + { + *width = 0; + *height = 0; + return S_OK; + } +}; + +// TODO: maybe install an X11 error hook, so we can return errors properly +struct GalliumDXGIX11IdentityBackend : public GalliumDXGIIdentityBackend +{ + Display* dpy; + + GalliumDXGIX11IdentityBackend(Display* dpy) + : dpy(dpy) + {} + + virtual HRESULT STDMETHODCALLTYPE GetPresentSize( + HWND hwnd, + unsigned* width, + unsigned* height + ) + { + XWindowAttributes xwa; + XGetWindowAttributes(dpy, (Window)hwnd, &xwa); + *width = xwa.width; + *height = xwa.height; + return S_OK; + } }; struct GalliumDXGIFactory : public GalliumDXGIObject @@ -107,6 +149,8 @@ struct GalliumDXGIFactory : public GalliumDXGIObject { if(p_backend) backend = p_backend; + else if(!strcmp(platform->name, "X11")) + backend.reset(new GalliumDXGIX11IdentityBackend((Display*)display)); else backend.reset(new GalliumDXGIIdentityBackend()); } @@ -887,6 +931,10 @@ struct GalliumDXGISwapChain : public GalliumDXGIObjectbackend->GetPresentSize(desc.OutputWindow, &width, &height); + if(!SUCCEEDED(hr)) + return hr; + + // On Windows, 8 is used, and a debug message saying so gets printed + if(!width) + width = 8; + if(!height) + height = 8; + + if(!desc.BufferDesc.Width) + desc.BufferDesc.Width = width; + if(!desc.BufferDesc.Height) + desc.BufferDesc.Height = height; + return S_OK; + } + virtual HRESULT STDMETHODCALLTYPE Present( UINT sync_interval, UINT flags) { + HRESULT hr; if(flags & DXGI_PRESENT_TEST) - return S_OK; + return parent->backend->TestPresent(desc.OutputWindow); if(!buffer0) { @@ -1030,7 +1102,11 @@ struct GalliumDXGISwapChain : public GalliumDXGIObjectbackend->BeginPresent(desc.OutputWindow, &cur_window, &rect, &rgndata, &preserve_aspect_ratio); + void* present_cookie; + hr = parent->backend->BeginPresent(desc.OutputWindow, &present_cookie, &cur_window, &rect, &rgndata, &preserve_aspect_ratio); + if(hr != S_OK) + return hr; + if(!cur_window || rect.left >= rect.right || rect.top >= rect.bottom) goto end_present; @@ -1051,6 +1127,9 @@ struct GalliumDXGISwapChain : public GalliumDXGIObjectright = prect->left + client_rect.right; prect->bottom = prect->top + client_rect.bottom; - rgndata_size = GetRegionData(hrgn, 0, NULL); - rgndata = HeapAlloc(GetProcessHeap(), 0, rgndata_size); - GetRegionData(hrgn, rgndata_size, rgndata); - *prgndata = rgndata; - // Windows doesn't preserve the aspect ratio // TODO: maybe let the user turn this on somehow *ppreserve_aspect_ratio = FALSE; - DeleteObject(hrgn); + *ppresent_cookie = rgndata; - return rgndata; + // TODO: check for errors and return them + return S_OK; } static void STDMETHODCALLTYPE WineDXGIBackend_EndPresent( - IGalliumDXGIBackend* This, - HWND hwnd, - void *present_cookie) + IGalliumDXGIBackend* This, + HWND hwnd, + void *present_cookie) { HeapFree(GetProcessHeap(), 0, present_cookie); } +static HRESULT STDMETHODCALLTYPE WineDXGIBackend_TestPresent( + IGalliumDXGIBackend* This, + HWND hwnd) +{ + HDC hdc; + HRGN hrgn; + RECT rgn_box; + int rgn_box_type; + + // TODO: is there a simpler way to check this? + hdc = GetDC(hwnd); + hrgn = CreateRectRgn(0, 0, 0, 0); + GetRandomRgn(hdc, hrgn, SYSRGN); + rgn_box_type = GetRgnBox(hrgn, &rgn_box); + DeleteObject(hrgn); + ReleaseDC(hwnd, hdc); + + return rgn_box_type == NULLREGION ? DXGI_STATUS_OCCLUDED : S_OK; +} + +static HRESULT STDMETHODCALLTYPE WineDXGIBackend_GetPresentSize( + IGalliumDXGIBackend* This, + HWND hwnd, + unsigned* width, + unsigned* height) +{ + RECT client_rect; + GetClientRect(hwnd, &client_rect); + *width = client_rect.right - client_rect.left; + *height = client_rect.bottom - client_rect.top; + + // TODO: check for errors and return them + return S_OK; +} + /* Wine should switch to C++ at least to be able to implement COM interfaces in a sensible way, * instead of this ridiculous amount of clumsy duplicated code everywhere * C++ exists exactly to avoid having to write the following code */ @@ -165,7 +213,9 @@ static IGalliumDXGIBackendVtbl WineDXGIBackend_vtbl = WineDXGIBackend_AddRef, WineDXGIBackend_Release, WineDXGIBackend_BeginPresent, - WineDXGIBackend_EndPresent + WineDXGIBackend_EndPresent, + WineDXGIBackend_TestPresent, + WineDXGIBackend_GetPresentSize }; IGalliumDXGIBackend* new_WineDXGIBackend() -- 2.30.2