From 152368464dbd050287ea4d157fc3560fcc230548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Tue, 25 Nov 2003 22:06:31 +0000 Subject: [PATCH] Switch screen to graphics mode when the first window or DC is created and switch back to text mode when the last app which created a window or DC terminates svn path=/trunk/; revision=6794 --- reactos/include/napi/win32.h | 1 + reactos/subsys/win32k/include/guicheck.h | 5 ++- reactos/subsys/win32k/include/winsta.h | 2 +- reactos/subsys/win32k/main/dllmain.c | 7 +++- reactos/subsys/win32k/ntuser/guicheck.c | 47 ++++++++++++++++-------- reactos/subsys/win32k/ntuser/window.c | 22 +++++------ reactos/subsys/win32k/ntuser/winsta.c | 39 +++++++++++++------- reactos/subsys/win32k/objects/gdiobj.c | 3 +- 8 files changed, 79 insertions(+), 47 deletions(-) diff --git a/reactos/include/napi/win32.h b/reactos/include/napi/win32.h index 77c6124e0e8..772cc6f65f0 100644 --- a/reactos/include/napi/win32.h +++ b/reactos/include/napi/win32.h @@ -21,6 +21,7 @@ typedef struct _W32PROCESS struct _WINSTATION_OBJECT* WindowStation; WORD GDIObjects; WORD UserObjects; + BOOL CreatedWindowOrDC; } W32PROCESS, *PW32PROCESS; PW32THREAD STDCALL diff --git a/reactos/subsys/win32k/include/guicheck.h b/reactos/subsys/win32k/include/guicheck.h index fd51ba429cf..47003d0142a 100644 --- a/reactos/subsys/win32k/include/guicheck.h +++ b/reactos/subsys/win32k/include/guicheck.h @@ -4,8 +4,9 @@ #include #include -VOID FASTCALL -IntGraphicsCheck(BOOL Create); +BOOL FASTCALL IntGraphicsCheck(BOOL Create); +BOOL FASTCALL IntCreatePrimarySurface(); +VOID FASTCALL IntDestroyPrimarySurface(); #endif /* _WIN32K_GUICHECK_H */ diff --git a/reactos/subsys/win32k/include/winsta.h b/reactos/subsys/win32k/include/winsta.h index 8ac905f0782..0d2eb9262dc 100644 --- a/reactos/subsys/win32k/include/winsta.h +++ b/reactos/subsys/win32k/include/winsta.h @@ -46,7 +46,7 @@ IntDesktopWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); HDC FASTCALL IntGetScreenDC(VOID); -VOID FASTCALL +BOOL FASTCALL IntInitializeDesktopGraphics(VOID); VOID FASTCALL diff --git a/reactos/subsys/win32k/main/dllmain.c b/reactos/subsys/win32k/main/dllmain.c index cb3b625fc9a..c38459cfe0b 100644 --- a/reactos/subsys/win32k/main/dllmain.c +++ b/reactos/subsys/win32k/main/dllmain.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: dllmain.c,v 1.54 2003/11/24 00:22:53 arty Exp $ +/* $Id: dllmain.c,v 1.55 2003/11/25 22:06:31 gvg Exp $ * * Entry Point for win32k.sys */ @@ -40,6 +40,7 @@ #include #include #include +#include #define NDEBUG #include @@ -87,6 +88,8 @@ Win32kProcessCallback (struct _EPROCESS *Process, "process.\n"); } } + + Win32Process->CreatedWindowOrDC = FALSE; } else { @@ -98,6 +101,8 @@ Win32kProcessCallback (struct _EPROCESS *Process, IntCleanupMenus(Process, Win32Process); CleanupForProcess(Process, Process->UniqueProcessId); + + IntGraphicsCheck(FALSE); } return STATUS_SUCCESS; diff --git a/reactos/subsys/win32k/ntuser/guicheck.c b/reactos/subsys/win32k/ntuser/guicheck.c index 2bd7b1c7a66..cc22f5137a7 100644 --- a/reactos/subsys/win32k/ntuser/guicheck.c +++ b/reactos/subsys/win32k/ntuser/guicheck.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: guicheck.c,v 1.14 2003/08/19 11:48:49 weiden Exp $ +/* $Id: guicheck.c,v 1.15 2003/11/25 22:06:31 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -51,29 +51,44 @@ static ULONG NrGuiApplicationsRunning = 0; /* FUNCTIONS *****************************************************************/ -VOID FASTCALL +BOOL FASTCALL IntGraphicsCheck(BOOL Create) { + PW32PROCESS W32Data; + + W32Data = PsGetWin32Process(); if (Create) { - if (0 == NrGuiApplicationsRunning) - { - IntInitializeDesktopGraphics(); - } - NrGuiApplicationsRunning++; + if (! W32Data->CreatedWindowOrDC) + { + W32Data->CreatedWindowOrDC = TRUE; + if (0 == NrGuiApplicationsRunning++) + { + if (! IntInitializeDesktopGraphics()) + { + W32Data->CreatedWindowOrDC = FALSE; + NrGuiApplicationsRunning--; + return FALSE; + } + } + } } else { - if (0 < NrGuiApplicationsRunning) - { - NrGuiApplicationsRunning--; - } - if (0 == NrGuiApplicationsRunning) - { - IntEndDesktopGraphics(); - } + if (W32Data->CreatedWindowOrDC) + { + if (0 < NrGuiApplicationsRunning) + { + NrGuiApplicationsRunning--; + } + if (0 == NrGuiApplicationsRunning) + { + IntEndDesktopGraphics(); + } + } } - + + return TRUE; } /* EOF */ diff --git a/reactos/subsys/win32k/ntuser/window.c b/reactos/subsys/win32k/ntuser/window.c index 4b0488d2053..c99d9fb31ad 100644 --- a/reactos/subsys/win32k/ntuser/window.c +++ b/reactos/subsys/win32k/ntuser/window.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: window.c,v 1.147 2003/11/24 09:27:54 weiden Exp $ +/* $Id: window.c,v 1.148 2003/11/25 22:06:31 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -370,8 +370,6 @@ static LRESULT IntDestroyWindow(PWINDOW_OBJECT Window, Window->Class = NULL; ObmCloseHandle(ProcessData->WindowStation->HandleTable, Window->Self); - IntGraphicsCheck(FALSE); - return 0; } @@ -628,7 +626,7 @@ IntInitDesktopWindow(ULONG Width, ULONG Height) { PWINDOW_OBJECT DesktopWindow; HRGN DesktopRgn; - + DesktopWindow = IntGetWindowObject(PsGetWin32Thread()->Desktop->DesktopWindow); if (NULL == DesktopWindow) { @@ -1305,6 +1303,13 @@ NtUserCreateWindowEx(DWORD dwExStyle, DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x, y, nWidth, nHeight); + /* Initialize gui state if necessary. */ + if (! IntGraphicsCheck(TRUE)) + { + DPRINT1("Unable to initialize graphics, returning NULL window\n"); + return NULL; + } + if (!RtlCreateUnicodeString(&WindowName, NULL == lpWindowName->Buffer ? L"" : lpWindowName->Buffer)) @@ -1313,9 +1318,6 @@ NtUserCreateWindowEx(DWORD dwExStyle, return((HWND)0); } - /* Initialize gui state if necessary. */ - IntGraphicsCheck(TRUE); - ParentWindowHandle = PsGetWin32Thread()->Desktop->DesktopWindow; OwnerWindowHandle = NULL; @@ -1336,7 +1338,6 @@ NtUserCreateWindowEx(DWORD dwExStyle, } else if ((dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD) { - IntGraphicsCheck(FALSE); return (HWND)0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */ } @@ -1350,7 +1351,6 @@ NtUserCreateWindowEx(DWORD dwExStyle, { RtlFreeUnicodeString(&WindowName); IntReleaseWindowObject(ParentWindow); - IntGraphicsCheck(FALSE); return((HWND)0); } @@ -1368,7 +1368,6 @@ NtUserCreateWindowEx(DWORD dwExStyle, IntReleaseWindowObject(ParentWindow); DPRINT("Validation of window station handle (0x%X) failed\n", PROCESS_WINDOW_STATION()); - IntGraphicsCheck(FALSE); return (HWND)0; } @@ -1385,7 +1384,6 @@ NtUserCreateWindowEx(DWORD dwExStyle, ObmDereferenceObject(ClassObject); RtlFreeUnicodeString(&WindowName); IntReleaseWindowObject(ParentWindow); - IntGraphicsCheck(FALSE); SetLastNtError(STATUS_INSUFFICIENT_RESOURCES); return (HWND)0; } @@ -1555,7 +1553,6 @@ NtUserCreateWindowEx(DWORD dwExStyle, { /* FIXME: Cleanup. */ IntReleaseWindowObject(ParentWindow); - IntGraphicsCheck(FALSE); DPRINT("NtUserCreateWindowEx(): NCCREATE message failed.\n"); return((HWND)0); } @@ -1594,7 +1591,6 @@ NtUserCreateWindowEx(DWORD dwExStyle, { /* FIXME: Cleanup. */ IntReleaseWindowObject(ParentWindow); - IntGraphicsCheck(FALSE); DPRINT("NtUserCreateWindowEx(): send CREATE message failed.\n"); return((HWND)0); } diff --git a/reactos/subsys/win32k/ntuser/winsta.c b/reactos/subsys/win32k/ntuser/winsta.c index 8a13bfd5a14..9af92a34675 100644 --- a/reactos/subsys/win32k/ntuser/winsta.c +++ b/reactos/subsys/win32k/ntuser/winsta.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * $Id: winsta.c,v 1.46 2003/11/24 16:15:00 gvg Exp $ + * $Id: winsta.c,v 1.47 2003/11/25 22:06:31 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -49,6 +49,7 @@ #include #include #include +#include #define NDEBUG #include @@ -279,28 +280,40 @@ IntValidateDesktopHandle( return Status; } -VOID FASTCALL +BOOL FASTCALL IntInitializeDesktopGraphics(VOID) { - ScreenDeviceContext = NtGdiCreateDC(L"DISPLAY", NULL, NULL, NULL); - GDIOBJ_MarkObjectGlobal(ScreenDeviceContext); - EnableMouse(ScreenDeviceContext); - /* not the best place to load the cursors but it's good for now */ - IntLoadDefaultCursors(FALSE); - NtUserAcquireOrReleaseInputOwnership(FALSE); + if (! IntCreatePrimarySurface()) + { + return FALSE; + } + ScreenDeviceContext = NtGdiCreateDC(L"DISPLAY", NULL, NULL, NULL); + if (NULL == ScreenDeviceContext) + { + IntDestroyPrimarySurface(); + return FALSE; + } + GDIOBJ_MarkObjectGlobal(ScreenDeviceContext); + EnableMouse(ScreenDeviceContext); + /* not the best place to load the cursors but it's good for now */ + IntLoadDefaultCursors(FALSE); + NtUserAcquireOrReleaseInputOwnership(FALSE); + + return TRUE; } VOID FASTCALL IntEndDesktopGraphics(VOID) { - NtUserAcquireOrReleaseInputOwnership(TRUE); - EnableMouse(FALSE); - if (NULL != ScreenDeviceContext) - { + NtUserAcquireOrReleaseInputOwnership(TRUE); + EnableMouse(FALSE); + if (NULL != ScreenDeviceContext) + { GDIOBJ_UnmarkObjectGlobal(ScreenDeviceContext); NtGdiDeleteDC(ScreenDeviceContext); ScreenDeviceContext = NULL; - } + } + IntDestroyPrimarySurface(); } HDC FASTCALL diff --git a/reactos/subsys/win32k/objects/gdiobj.c b/reactos/subsys/win32k/objects/gdiobj.c index 385cbb37412..4a4a0f2d577 100644 --- a/reactos/subsys/win32k/objects/gdiobj.c +++ b/reactos/subsys/win32k/objects/gdiobj.c @@ -19,7 +19,7 @@ /* * GDIOBJ.C - GDI object manipulation routines * - * $Id: gdiobj.c,v 1.50 2003/11/19 12:25:03 weiden Exp $ + * $Id: gdiobj.c,v 1.51 2003/11/25 22:06:31 gvg Exp $ * */ @@ -454,6 +454,7 @@ GDIOBJ_MarkObjectGlobal(HGDIOBJ ObjectHandle) { W32Process->GDIObjects--; } + ObDereferenceObject(Process); } ObjHdr->hProcessId = GDI_GLOBAL_PROCESS;