From cdacb4b6b56acf3e4393eb655cef4ab53c578a18 Mon Sep 17 00:00:00 2001 From: James Tabor Date: Tue, 2 Jun 2009 06:50:36 +0000 Subject: [PATCH] - Hax-implement NtGdiSetPixelFormat and add a support function UserGethWnd with some code cleanup. svn path=/trunk/; revision=41250 --- reactos/subsystems/win32/win32k/include/dce.h | 1 + .../subsystems/win32/win32k/ntuser/painting.c | 22 +++--- .../subsystems/win32/win32k/ntuser/windc.c | 30 ++++++++ .../subsystems/win32/win32k/objects/wingl.c | 75 ++++++++++++++++++- 4 files changed, 113 insertions(+), 15 deletions(-) diff --git a/reactos/subsystems/win32/win32k/include/dce.h b/reactos/subsystems/win32/win32k/include/dce.h index 568196e7598..55b94ace4ab 100644 --- a/reactos/subsystems/win32/win32k/include/dce.h +++ b/reactos/subsystems/win32/win32k/include/dce.h @@ -56,5 +56,6 @@ void FASTCALL DceFreeWindowDCE(PWINDOW_OBJECT Window); void FASTCALL DceEmptyCache(void); VOID FASTCALL DceResetActiveDCEs(PWINDOW_OBJECT Window); void FASTCALL DceFreeClassDCE(HDC); +HWND FASTCALL UserGethWnd(HDC,PWNDOBJ*); #endif /* _WIN32K_DCE_H */ diff --git a/reactos/subsystems/win32/win32k/ntuser/painting.c b/reactos/subsystems/win32/win32k/ntuser/painting.c index 2d29c7c4dde..fff7ab7be27 100644 --- a/reactos/subsystems/win32/win32k/ntuser/painting.c +++ b/reactos/subsystems/win32/win32k/ntuser/painting.c @@ -1922,18 +1922,18 @@ NtUserDrawCaptionTemp( ProbeForRead(lpRc, sizeof(RECTL), sizeof(ULONG)); RtlCopyMemory(&SafeRect, lpRc, sizeof(RECTL)); if (str != NULL) - { - SafeStr = ProbeForReadUnicodeString(str); - if (SafeStr.Length != 0) - { - ProbeForRead(SafeStr.Buffer, - SafeStr.Length, - sizeof(WCHAR)); - } - Ret = UserDrawCaption(pWnd, hDC, &SafeRect, hFont, hIcon, &SafeStr, uFlags); + { + SafeStr = ProbeForReadUnicodeString(str); + if (SafeStr.Length != 0) + { + ProbeForRead( SafeStr.Buffer, + SafeStr.Length, + sizeof(WCHAR)); + } + Ret = UserDrawCaption(pWnd, hDC, &SafeRect, hFont, hIcon, &SafeStr, uFlags); } - else - Ret = UserDrawCaption(pWnd, hDC, &SafeRect, hFont, hIcon, NULL, uFlags); + else + Ret = UserDrawCaption(pWnd, hDC, &SafeRect, hFont, hIcon, NULL, uFlags); } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { diff --git a/reactos/subsystems/win32/win32k/ntuser/windc.c b/reactos/subsystems/win32/win32k/ntuser/windc.c index bb5a74be139..0a798a9db72 100644 --- a/reactos/subsystems/win32/win32k/ntuser/windc.c +++ b/reactos/subsystems/win32/win32k/ntuser/windc.c @@ -866,6 +866,36 @@ UserGetWindowDC(PWINDOW_OBJECT Wnd) return UserGetDCEx(Wnd, 0, DCX_USESTYLE | DCX_WINDOW); } +HWND FASTCALL +UserGethWnd( HDC hdc, PWNDOBJ *pwndo) +{ + PWNDGDI pWndgdi; + PWINDOW_OBJECT Wnd = NULL; + HWND hWnd; + BOOL Hit = FALSE; + PLIST_ENTRY Entry; + hWnd = IntWindowFromDC(hdc); + + if (hWnd && !(Wnd = UserGetWindowObject(hWnd))) + { + KeEnterCriticalRegion(); + Entry = Wnd->WndObjListHead.Flink; + while (Entry != &Wnd->WndObjListHead) + { + pWndgdi = (PWNDGDI)Entry; + if (pWndgdi->Hwnd == hWnd) + { + Hit = TRUE; + break; + } + Entry = Entry->Flink; + } + if (pwndo && Hit) *pwndo = (PWNDOBJ)pWndgdi; + KeLeaveCriticalRegion(); + } + return hWnd; +} + HDC APIENTRY NtUserGetDCEx(HWND hWnd OPTIONAL, HANDLE ClipRegion, ULONG Flags) { diff --git a/reactos/subsystems/win32/win32k/objects/wingl.c b/reactos/subsystems/win32/win32k/objects/wingl.c index 6d32b319741..a46dbcec164 100644 --- a/reactos/subsystems/win32/win32k/objects/wingl.c +++ b/reactos/subsystems/win32/win32k/objects/wingl.c @@ -38,7 +38,6 @@ IntGetipfdDevMax(PDC pdc) if (ppdev->DriverFunctions.DescribePixelFormat) { - Ret = ppdev->DriverFunctions.DescribePixelFormat( ppdev->hPDev, 1, @@ -94,7 +93,6 @@ NtGdiDescribePixelFormat(HDC hDC, if (ppdev->DriverFunctions.DescribePixelFormat) { - Ret = ppdev->DriverFunctions.DescribePixelFormat( ppdev->hPDev, PixelFormat, @@ -129,8 +127,77 @@ NtGdiSetPixelFormat( IN HDC hdc, IN INT ipfd) { - UNIMPLEMENTED; - return FALSE; + PDC pdc; + PPDEVOBJ ppdev; + HWND hWnd; + PWNDOBJ pWndObj; + SURFOBJ *pso = NULL; + BOOL Ret = FALSE; + + pdc = DC_LockDc(hdc); + if (!pdc) + { + SetLastWin32Error(ERROR_INVALID_HANDLE); + return FALSE; + } + + if (!pdc->ipfdDevMax) IntGetipfdDevMax(pdc); + + if ( ipfd < 1 || + ipfd > pdc->ipfdDevMax ) + { + SetLastWin32Error(ERROR_INVALID_PARAMETER); + goto Exit; + } + + UserEnterExclusive(); + hWnd = UserGethWnd(hdc, &pWndObj); + UserLeave(); + + if (!hWnd) + { + SetLastWin32Error(ERROR_INVALID_WINDOW_STYLE); + goto Exit; + } + + ppdev = pdc->ppdev; + + if (pWndObj) pso = pWndObj->psoOwner; + else + { + SetLastWin32Error(ERROR_INVALID_PIXEL_FORMAT); + goto Exit; + } + + if (!pso) + { + /* + Based on some rules! InfoDC to DC or, based on wiki information! + All pointers, it's a "must be!", (CONTAINING_RECORD +10h = SURFOBJ), the + pointer will start at SURFOBJ of the SURFACE structure. + */ + pso = (SURFOBJ *)pdc->dclevel.pSurface; + if (!pso) pso = pdc->pSurfInfo; + if (!pso) pso = ppdev->pSurface; + } + + if (ppdev->flFlags & PDEV_META_DEVICE) + { + UNIMPLEMENTED; + goto Exit; + } + + if (ppdev->DriverFunctions.SetPixelFormat) + { + Ret = ppdev->DriverFunctions.SetPixelFormat( + pso, + ipfd, + hWnd); + } + +Exit: + DC_UnlockDc(pdc); + return Ret; } BOOL