From 123637fd96ec2906b2961f0589155c850e8026b0 Mon Sep 17 00:00:00 2001 From: Giannis Adamopoulos Date: Mon, 20 Feb 2012 13:23:32 +0000 Subject: [PATCH] [win32k] - Do not store the PDEVOBJ and a fake name in MONITOR struct. Use MONITOR.HDEV instead (which is an opaque pointer to a PDEVOBJ) svn path=/trunk/; revision=55755 --- .../subsystems/win32/win32k/include/monitor.h | 17 ++--- .../subsystems/win32/win32k/ntuser/desktop.c | 7 +- .../subsystems/win32/win32k/ntuser/display.c | 2 +- .../subsystems/win32/win32k/ntuser/monitor.c | 71 ++++++++----------- .../win32/win32k/ntuser/sysparams.c | 4 +- .../subsystems/win32/win32k/ntuser/window.c | 2 +- .../subsystems/win32/win32k/ntuser/winpos.c | 8 +-- .../subsystems/win32/win32k/objects/device.c | 14 +--- 8 files changed, 49 insertions(+), 76 deletions(-) diff --git a/reactos/subsystems/win32/win32k/include/monitor.h b/reactos/subsystems/win32/win32k/include/monitor.h index 84cb0346638..ce1a6faea6d 100644 --- a/reactos/subsystems/win32/win32k/include/monitor.h +++ b/reactos/subsystems/win32/win32k/include/monitor.h @@ -21,18 +21,13 @@ typedef struct _MONITOR SHORT cFullScreen; SHORT cWndStack; HDEV hDev; - - // ReactOS specific fields: - UNICODE_STRING DeviceName; /* Name of the monitor */ - PDEVOBJ *GdiDevice; /* Pointer to the GDI device to - which this monitor is attached */ } MONITOR, *PMONITOR; -NTSTATUS IntAttachMonitor(PDEVOBJ *pGdiDevice, ULONG DisplayNumber); -NTSTATUS IntDetachMonitor(PDEVOBJ *pGdiDevice); -NTSTATUS IntUpdateMonitorSize(IN PDEVOBJ *pGdiDevice); -PMONITOR FASTCALL UserGetMonitorObject(IN HMONITOR); -PMONITOR FASTCALL IntGetPrimaryMonitor(VOID); -PMONITOR FASTCALL IntMonitorFromRect(PRECTL,DWORD); +NTSTATUS NTAPI UserAttachMonitor(IN HDEV hDev); +NTSTATUS NTAPI UserDetachMonitor(HDEV hDev); +NTSTATUS NTAPI UserUpdateMonitorSize(IN HDEV hDev); +PMONITOR NTAPI UserGetMonitorObject(IN HMONITOR); +PMONITOR NTAPI UserGetPrimaryMonitor(VOID); +PMONITOR NTAPI UserMonitorFromRect(PRECTL,DWORD); /* EOF */ diff --git a/reactos/subsystems/win32/win32k/ntuser/desktop.c b/reactos/subsystems/win32/win32k/ntuser/desktop.c index 1428b9cda0b..8f2a6150178 100644 --- a/reactos/subsystems/win32/win32k/ntuser/desktop.c +++ b/reactos/subsystems/win32/win32k/ntuser/desktop.c @@ -565,9 +565,8 @@ UserGetDesktopDC(ULONG DcType, BOOL EmptyDC, BOOL ValidatehWnd) } else { - HDEV hDev; - hDev = (HDEV)pPrimarySurface; - DesktopHDC = IntGdiCreateDisplayDC(hDev, DcType, EmptyDC); + PMONITOR pMonitor = UserGetPrimaryMonitor(); + DesktopHDC = IntGdiCreateDisplayDC(pMonitor->hDev, DcType, EmptyDC); } return DesktopHDC; @@ -860,7 +859,7 @@ NtUserCreateDesktop( /* * Try to open already existing desktop */ - + TRACE("Trying to open desktop (%wZ)\n", &DesktopName); Status = ObOpenObjectByName( diff --git a/reactos/subsystems/win32/win32k/ntuser/display.c b/reactos/subsystems/win32/win32k/ntuser/display.c index 3b703cc0e44..f9b2479f8f5 100644 --- a/reactos/subsystems/win32/win32k/ntuser/display.c +++ b/reactos/subsystems/win32/win32k/ntuser/display.c @@ -779,7 +779,7 @@ UserChangeDisplaySettings( //IntvGetDeviceCaps(&PrimarySurface, &GdiHandleTable->DevCaps); /* Set new size of the monitor */ - IntUpdateMonitorSize(ppdev); + UserUpdateMonitorSize((HDEV)ppdev); /* Remove all cursor clipping */ UserClipCursor(NULL); diff --git a/reactos/subsystems/win32/win32k/ntuser/monitor.c b/reactos/subsystems/win32/win32k/ntuser/monitor.c index fcf835d7d5f..c6e0d61e2b6 100644 --- a/reactos/subsystems/win32/win32k/ntuser/monitor.c +++ b/reactos/subsystems/win32/win32k/ntuser/monitor.c @@ -49,9 +49,6 @@ static void IntDestroyMonitorObject(IN PMONITOR pMonitor) { - /* Free monitor name */ - RtlFreeUnicodeString(&pMonitor->DeviceName); - /* Remove monitor region */ if (pMonitor->hrgnMonitor) { @@ -73,7 +70,7 @@ IntDestroyMonitorObject(IN PMONITOR pMonitor) * hMonitor * Handle of MONITOR object */ -PMONITOR FASTCALL +PMONITOR NTAPI UserGetMonitorObject(IN HMONITOR hMonitor) { PMONITOR pMonitor; @@ -94,16 +91,15 @@ UserGetMonitorObject(IN HMONITOR hMonitor) return pMonitor; } -/* IntGetPrimaryMonitor +/* UserGetPrimaryMonitor * * Returns a PMONITOR for the primary monitor * * Return value * PMONITOR */ -PMONITOR -FASTCALL -IntGetPrimaryMonitor() +PMONITOR NTAPI +UserGetPrimaryMonitor() { PMONITOR pMonitor; @@ -117,7 +113,7 @@ IntGetPrimaryMonitor() return pMonitor; } -/* IntAttachMonitor +/* UserAttachMonitor * * Creates a new MONITOR and appends it to the list of monitors. * @@ -129,12 +125,10 @@ IntGetPrimaryMonitor() * Return value * Returns a NTSTATUS */ -NTSTATUS -IntAttachMonitor(IN PDEVOBJ *pGdiDevice, - IN ULONG DisplayNumber) +NTSTATUS NTAPI +UserAttachMonitor(IN HDEV hDev) { PMONITOR pMonitor; - WCHAR Buffer[CCHDEVICENAME]; TRACE("Attaching monitor...\n"); @@ -145,17 +139,8 @@ IntAttachMonitor(IN PDEVOBJ *pGdiDevice, TRACE("Couldnt create monitor object\n"); return STATUS_INSUFFICIENT_RESOURCES; } - - _snwprintf(Buffer, CCHDEVICENAME, L"\\\\.\\DISPLAY%d", DisplayNumber + 1); - if (!RtlCreateUnicodeString(&pMonitor->DeviceName, Buffer)) - { - TRACE("Couldn't duplicate monitor name!\n"); - UserDereferenceObject(pMonitor); - UserDeleteObject(UserHMGetHandle(pMonitor), otMonitor); - return STATUS_INSUFFICIENT_RESOURCES; - } - - pMonitor->GdiDevice = pGdiDevice; + + pMonitor->hDev = hDev; pMonitor->cWndStack = 0; if (gMonitorList == NULL) @@ -174,12 +159,12 @@ IntAttachMonitor(IN PDEVOBJ *pGdiDevice, pmonLast->pMonitorNext = pMonitor; } - IntUpdateMonitorSize(pGdiDevice); + UserUpdateMonitorSize(hDev); return STATUS_SUCCESS; } -/* IntDetachMonitor +/* UserDetachMonitor * * Deletes a MONITOR and removes it from the list of monitors. * @@ -190,15 +175,15 @@ IntAttachMonitor(IN PDEVOBJ *pGdiDevice, * Return value * Returns a NTSTATUS */ -NTSTATUS -IntDetachMonitor(IN PDEVOBJ *pGdiDevice) +NTSTATUS NTAPI +UserDetachMonitor(IN HDEV hDev) { PMONITOR pMonitor = gMonitorList, *pLink = &gMonitorList; /* Find monitor attached to given device */ while (pMonitor != NULL) { - if (pMonitor->GdiDevice == pGdiDevice) + if (pMonitor->hDev == hDev) break; pLink = &pMonitor->pMonitorNext; @@ -224,7 +209,7 @@ IntDetachMonitor(IN PDEVOBJ *pGdiDevice) return STATUS_SUCCESS; } -/* IntUpdateMonitorSize +/* UserUpdateMonitorSize * * Reset size of the monitor using atached device * @@ -236,15 +221,16 @@ IntDetachMonitor(IN PDEVOBJ *pGdiDevice) * Return value * Returns a NTSTATUS */ -NTSTATUS -IntUpdateMonitorSize(IN PDEVOBJ *pGdiDevice) +NTSTATUS NTAPI +UserUpdateMonitorSize(IN HDEV hDev) { PMONITOR pMonitor; + SIZEL DeviceSize; /* Find monitor attached to given device */ for (pMonitor = gMonitorList; pMonitor != NULL; pMonitor = pMonitor->pMonitorNext) { - if (pMonitor->GdiDevice == pGdiDevice) + if (pMonitor->hDev == hDev) break; } @@ -254,11 +240,14 @@ IntUpdateMonitorSize(IN PDEVOBJ *pGdiDevice) return STATUS_INVALID_PARAMETER; } + /* Get the size of the hdev */ + PDEVOBJ_sizl((PPDEVOBJ)hDev, &DeviceSize); + /* Update monitor size */ pMonitor->rcMonitor.left = 0; pMonitor->rcMonitor.top = 0; - pMonitor->rcMonitor.right = pMonitor->rcMonitor.left + pMonitor->GdiDevice->gdiinfo.ulHorzRes; - pMonitor->rcMonitor.bottom = pMonitor->rcMonitor.top + pMonitor->GdiDevice->gdiinfo.ulVertRes; + pMonitor->rcMonitor.right = pMonitor->rcMonitor.left + DeviceSize.cx; + pMonitor->rcMonitor.bottom = pMonitor->rcMonitor.top + DeviceSize.cy; pMonitor->rcWork = pMonitor->rcMonitor; /* Destroy monitor region... */ @@ -403,9 +392,8 @@ IntGetMonitorsFromRect(OPTIONAL IN LPCRECTL pRect, return cMonitors; } -PMONITOR -FASTCALL -IntMonitorFromRect( +PMONITOR NTAPI +UserMonitorFromRect( PRECTL pRect, DWORD dwFlags) { @@ -703,6 +691,7 @@ NtUserGetMonitorInfo( MONITORINFOEXW MonitorInfo; NTSTATUS Status; BOOL bRet = FALSE; + PWCHAR pwstrDeviceName; TRACE("Enter NtUserGetMonitorInfo\n"); UserEnterShared(); @@ -722,6 +711,8 @@ NtUserGetMonitorInfo( goto cleanup; } + pwstrDeviceName = ((PPDEVOBJ)(pMonitor->hDev))->pGraphicsDevice->szWinDeviceName; + /* Get size of pMonitorInfoUnsafe */ Status = MmCopyFromCaller(&MonitorInfo.cbSize, &pMonitorInfoUnsafe->cbSize, sizeof(MonitorInfo.cbSize)); if (!NT_SUCCESS(Status)) @@ -750,8 +741,8 @@ NtUserGetMonitorInfo( { RtlStringCbCopyNExW(MonitorInfo.szDevice, sizeof(MonitorInfo.szDevice), - pMonitor->DeviceName.Buffer, - pMonitor->DeviceName.Length, + pwstrDeviceName, + (wcslen(pwstrDeviceName)+1) * sizeof(WCHAR), NULL, NULL, STRSAFE_FILL_BEHIND_NULL); } diff --git a/reactos/subsystems/win32/win32k/ntuser/sysparams.c b/reactos/subsystems/win32/win32k/ntuser/sysparams.c index c051ecac6a8..37ea93882a5 100644 --- a/reactos/subsystems/win32/win32k/ntuser/sysparams.c +++ b/reactos/subsystems/win32/win32k/ntuser/sysparams.c @@ -947,7 +947,7 @@ SpiGetSet(UINT uiAction, UINT uiParam, PVOID pvParam, FLONG fl) case SPI_GETWORKAREA: { - PMONITOR pmonitor = IntGetPrimaryMonitor(); + PMONITOR pmonitor = UserGetPrimaryMonitor(); if(!pmonitor) return 0; @@ -959,7 +959,7 @@ SpiGetSet(UINT uiAction, UINT uiParam, PVOID pvParam, FLONG fl) { /* FIXME: We should set the work area of the monitor that contains the specified rectangle */ - PMONITOR pmonitor = IntGetPrimaryMonitor(); + PMONITOR pmonitor = UserGetPrimaryMonitor(); RECT rcWorkArea; if(!pmonitor) diff --git a/reactos/subsystems/win32/win32k/ntuser/window.c b/reactos/subsystems/win32/win32k/ntuser/window.c index e32653d5efb..0ea95317621 100644 --- a/reactos/subsystems/win32/win32k/ntuser/window.c +++ b/reactos/subsystems/win32/win32k/ntuser/window.c @@ -1463,7 +1463,7 @@ IntFixWindowCoordinates(CREATESTRUCTW* Cs, PWND ParentWindow, DWORD* dwShowMode) PMONITOR pMonitor; PRTL_USER_PROCESS_PARAMETERS ProcessParams; - pMonitor = IntGetPrimaryMonitor(); + pMonitor = UserGetPrimaryMonitor(); /* Check if we don't have a monitor attached yet */ if(pMonitor == NULL) diff --git a/reactos/subsystems/win32/win32k/ntuser/winpos.c b/reactos/subsystems/win32/win32k/ntuser/winpos.c index 20026bc1729..32b811faff3 100644 --- a/reactos/subsystems/win32/win32k/ntuser/winpos.c +++ b/reactos/subsystems/win32/win32k/ntuser/winpos.c @@ -323,7 +323,7 @@ WinPosInitInternalPos(PWND Wnd, RECTL *RestoreRect) else { RECTL WorkArea; - PMONITOR pmonitor = IntMonitorFromRect(&Rect, MONITOR_DEFAULTTOPRIMARY ); + PMONITOR pmonitor = UserMonitorFromRect(&Rect, MONITOR_DEFAULTTOPRIMARY ); // FIXME: support DPI aware, rcWorkDPI/Real etc.. if (!(Wnd->style & WS_MAXIMIZEBOX) || (Wnd->state & WNDS_HASCAPTION) || pmonitor->cFullScreen) @@ -389,7 +389,7 @@ IntGetWindowPlacement(PWND Wnd, WINDOWPLACEMENT *lpwndpl) if ( Wnd->spwndParent == Wnd->head.rpdesk->pDeskInfo->spwnd && !(Wnd->ExStyle & WS_EX_TOOLWINDOW)) { - PMONITOR pmonitor = IntMonitorFromRect(&lpwndpl->rcNormalPosition, MONITOR_DEFAULTTOPRIMARY ); + PMONITOR pmonitor = UserMonitorFromRect(&lpwndpl->rcNormalPosition, MONITOR_DEFAULTTOPRIMARY ); // FIXME: support DPI aware, rcWorkDPI/Real etc.. if (Wnd->InternalPos.flags & WPF_MININIT) @@ -414,7 +414,7 @@ IntGetWindowPlacement(PWND Wnd, WINDOWPLACEMENT *lpwndpl) /* make sure the specified rect is visible on screen */ static void make_rect_onscreen( RECT *rect ) { - PMONITOR pmonitor = IntMonitorFromRect( rect, MONITOR_DEFAULTTONEAREST ); // Wine uses this. + PMONITOR pmonitor = UserMonitorFromRect( rect, MONITOR_DEFAULTTONEAREST ); // Wine uses this. // FIXME: support DPI aware, rcWorkDPI/Real etc.. if (!pmonitor) return; @@ -744,7 +744,7 @@ co_WinPosGetMinMaxInfo(PWND Window, POINT* MaxSize, POINT* MaxPos, co_IntSendMessage(Window->head.h, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax); /* if the app didn't change the values, adapt them for the current monitor */ - if ((monitor = IntGetPrimaryMonitor())) + if ((monitor = UserGetPrimaryMonitor())) { RECT rc_work; diff --git a/reactos/subsystems/win32/win32k/objects/device.c b/reactos/subsystems/win32/win32k/objects/device.c index 6b8e281712f..42e2b6efa5a 100644 --- a/reactos/subsystems/win32/win32k/objects/device.c +++ b/reactos/subsystems/win32/win32k/objects/device.c @@ -30,16 +30,9 @@ IntCreatePrimarySurface() { SIZEL SurfSize; SURFOBJ *pso; - BOOL calledFromUser; - - calledFromUser = UserIsEntered(); // FIXME: Possibly upgrade a shared lock - if (!calledFromUser) - { - UserEnterExclusive(); - } /* Attach monitor */ - IntAttachMonitor(gppdevPrimary, 0); + UserAttachMonitor((HDEV)gppdevPrimary); DPRINT("IntCreatePrimarySurface, pPrimarySurface=%p, pPrimarySurface->pSurface = %p\n", pPrimarySurface, pPrimarySurface->pSurface); @@ -57,11 +50,6 @@ IntCreatePrimarySurface() // Init Primary Displays Device Capabilities. PDEVOBJ_vGetDeviceCaps(pPrimarySurface, &GdiHandleTable->DevCaps); - if (!calledFromUser) - { - UserLeave(); - } - return TRUE; }