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
This commit is contained in:
Gé van Geldorp 2003-11-25 22:06:31 +00:00
parent 500ec5fe43
commit 152368464d
8 changed files with 79 additions and 47 deletions

View file

@ -21,6 +21,7 @@ typedef struct _W32PROCESS
struct _WINSTATION_OBJECT* WindowStation; struct _WINSTATION_OBJECT* WindowStation;
WORD GDIObjects; WORD GDIObjects;
WORD UserObjects; WORD UserObjects;
BOOL CreatedWindowOrDC;
} W32PROCESS, *PW32PROCESS; } W32PROCESS, *PW32PROCESS;
PW32THREAD STDCALL PW32THREAD STDCALL

View file

@ -4,8 +4,9 @@
#include <windows.h> #include <windows.h>
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
VOID FASTCALL BOOL FASTCALL IntGraphicsCheck(BOOL Create);
IntGraphicsCheck(BOOL Create); BOOL FASTCALL IntCreatePrimarySurface();
VOID FASTCALL IntDestroyPrimarySurface();
#endif /* _WIN32K_GUICHECK_H */ #endif /* _WIN32K_GUICHECK_H */

View file

@ -46,7 +46,7 @@ IntDesktopWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
HDC FASTCALL HDC FASTCALL
IntGetScreenDC(VOID); IntGetScreenDC(VOID);
VOID FASTCALL BOOL FASTCALL
IntInitializeDesktopGraphics(VOID); IntInitializeDesktopGraphics(VOID);
VOID FASTCALL VOID FASTCALL

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * Entry Point for win32k.sys
*/ */
@ -40,6 +40,7 @@
#include <include/text.h> #include <include/text.h>
#include <include/caret.h> #include <include/caret.h>
#include <include/hotkey.h> #include <include/hotkey.h>
#include <include/guicheck.h>
#define NDEBUG #define NDEBUG
#include <win32k/debug1.h> #include <win32k/debug1.h>
@ -87,6 +88,8 @@ Win32kProcessCallback (struct _EPROCESS *Process,
"process.\n"); "process.\n");
} }
} }
Win32Process->CreatedWindowOrDC = FALSE;
} }
else else
{ {
@ -98,6 +101,8 @@ Win32kProcessCallback (struct _EPROCESS *Process,
IntCleanupMenus(Process, Win32Process); IntCleanupMenus(Process, Win32Process);
CleanupForProcess(Process, Process->UniqueProcessId); CleanupForProcess(Process, Process->UniqueProcessId);
IntGraphicsCheck(FALSE);
} }
return STATUS_SUCCESS; return STATUS_SUCCESS;

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -51,29 +51,44 @@ static ULONG NrGuiApplicationsRunning = 0;
/* FUNCTIONS *****************************************************************/ /* FUNCTIONS *****************************************************************/
VOID FASTCALL BOOL FASTCALL
IntGraphicsCheck(BOOL Create) IntGraphicsCheck(BOOL Create)
{ {
PW32PROCESS W32Data;
W32Data = PsGetWin32Process();
if (Create) if (Create)
{ {
if (0 == NrGuiApplicationsRunning) if (! W32Data->CreatedWindowOrDC)
{ {
IntInitializeDesktopGraphics(); W32Data->CreatedWindowOrDC = TRUE;
} if (0 == NrGuiApplicationsRunning++)
NrGuiApplicationsRunning++; {
if (! IntInitializeDesktopGraphics())
{
W32Data->CreatedWindowOrDC = FALSE;
NrGuiApplicationsRunning--;
return FALSE;
}
}
}
} }
else else
{ {
if (0 < NrGuiApplicationsRunning) if (W32Data->CreatedWindowOrDC)
{ {
NrGuiApplicationsRunning--; if (0 < NrGuiApplicationsRunning)
} {
if (0 == NrGuiApplicationsRunning) NrGuiApplicationsRunning--;
{ }
IntEndDesktopGraphics(); if (0 == NrGuiApplicationsRunning)
} {
IntEndDesktopGraphics();
}
}
} }
return TRUE;
} }
/* EOF */ /* EOF */

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -370,8 +370,6 @@ static LRESULT IntDestroyWindow(PWINDOW_OBJECT Window,
Window->Class = NULL; Window->Class = NULL;
ObmCloseHandle(ProcessData->WindowStation->HandleTable, Window->Self); ObmCloseHandle(ProcessData->WindowStation->HandleTable, Window->Self);
IntGraphicsCheck(FALSE);
return 0; return 0;
} }
@ -628,7 +626,7 @@ IntInitDesktopWindow(ULONG Width, ULONG Height)
{ {
PWINDOW_OBJECT DesktopWindow; PWINDOW_OBJECT DesktopWindow;
HRGN DesktopRgn; HRGN DesktopRgn;
DesktopWindow = IntGetWindowObject(PsGetWin32Thread()->Desktop->DesktopWindow); DesktopWindow = IntGetWindowObject(PsGetWin32Thread()->Desktop->DesktopWindow);
if (NULL == DesktopWindow) if (NULL == DesktopWindow)
{ {
@ -1305,6 +1303,13 @@ NtUserCreateWindowEx(DWORD dwExStyle,
DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x, y, nWidth, nHeight); 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, if (!RtlCreateUnicodeString(&WindowName,
NULL == lpWindowName->Buffer ? NULL == lpWindowName->Buffer ?
L"" : lpWindowName->Buffer)) L"" : lpWindowName->Buffer))
@ -1313,9 +1318,6 @@ NtUserCreateWindowEx(DWORD dwExStyle,
return((HWND)0); return((HWND)0);
} }
/* Initialize gui state if necessary. */
IntGraphicsCheck(TRUE);
ParentWindowHandle = PsGetWin32Thread()->Desktop->DesktopWindow; ParentWindowHandle = PsGetWin32Thread()->Desktop->DesktopWindow;
OwnerWindowHandle = NULL; OwnerWindowHandle = NULL;
@ -1336,7 +1338,6 @@ NtUserCreateWindowEx(DWORD dwExStyle,
} }
else if ((dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD) else if ((dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD)
{ {
IntGraphicsCheck(FALSE);
return (HWND)0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */ return (HWND)0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
} }
@ -1350,7 +1351,6 @@ NtUserCreateWindowEx(DWORD dwExStyle,
{ {
RtlFreeUnicodeString(&WindowName); RtlFreeUnicodeString(&WindowName);
IntReleaseWindowObject(ParentWindow); IntReleaseWindowObject(ParentWindow);
IntGraphicsCheck(FALSE);
return((HWND)0); return((HWND)0);
} }
@ -1368,7 +1368,6 @@ NtUserCreateWindowEx(DWORD dwExStyle,
IntReleaseWindowObject(ParentWindow); IntReleaseWindowObject(ParentWindow);
DPRINT("Validation of window station handle (0x%X) failed\n", DPRINT("Validation of window station handle (0x%X) failed\n",
PROCESS_WINDOW_STATION()); PROCESS_WINDOW_STATION());
IntGraphicsCheck(FALSE);
return (HWND)0; return (HWND)0;
} }
@ -1385,7 +1384,6 @@ NtUserCreateWindowEx(DWORD dwExStyle,
ObmDereferenceObject(ClassObject); ObmDereferenceObject(ClassObject);
RtlFreeUnicodeString(&WindowName); RtlFreeUnicodeString(&WindowName);
IntReleaseWindowObject(ParentWindow); IntReleaseWindowObject(ParentWindow);
IntGraphicsCheck(FALSE);
SetLastNtError(STATUS_INSUFFICIENT_RESOURCES); SetLastNtError(STATUS_INSUFFICIENT_RESOURCES);
return (HWND)0; return (HWND)0;
} }
@ -1555,7 +1553,6 @@ NtUserCreateWindowEx(DWORD dwExStyle,
{ {
/* FIXME: Cleanup. */ /* FIXME: Cleanup. */
IntReleaseWindowObject(ParentWindow); IntReleaseWindowObject(ParentWindow);
IntGraphicsCheck(FALSE);
DPRINT("NtUserCreateWindowEx(): NCCREATE message failed.\n"); DPRINT("NtUserCreateWindowEx(): NCCREATE message failed.\n");
return((HWND)0); return((HWND)0);
} }
@ -1594,7 +1591,6 @@ NtUserCreateWindowEx(DWORD dwExStyle,
{ {
/* FIXME: Cleanup. */ /* FIXME: Cleanup. */
IntReleaseWindowObject(ParentWindow); IntReleaseWindowObject(ParentWindow);
IntGraphicsCheck(FALSE);
DPRINT("NtUserCreateWindowEx(): send CREATE message failed.\n"); DPRINT("NtUserCreateWindowEx(): send CREATE message failed.\n");
return((HWND)0); return((HWND)0);
} }

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -49,6 +49,7 @@
#include <include/color.h> #include <include/color.h>
#include <include/mouse.h> #include <include/mouse.h>
#include <include/callback.h> #include <include/callback.h>
#include <include/guicheck.h>
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
@ -279,28 +280,40 @@ IntValidateDesktopHandle(
return Status; return Status;
} }
VOID FASTCALL BOOL FASTCALL
IntInitializeDesktopGraphics(VOID) IntInitializeDesktopGraphics(VOID)
{ {
ScreenDeviceContext = NtGdiCreateDC(L"DISPLAY", NULL, NULL, NULL); if (! IntCreatePrimarySurface())
GDIOBJ_MarkObjectGlobal(ScreenDeviceContext); {
EnableMouse(ScreenDeviceContext); return FALSE;
/* not the best place to load the cursors but it's good for now */ }
IntLoadDefaultCursors(FALSE); ScreenDeviceContext = NtGdiCreateDC(L"DISPLAY", NULL, NULL, NULL);
NtUserAcquireOrReleaseInputOwnership(FALSE); 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 VOID FASTCALL
IntEndDesktopGraphics(VOID) IntEndDesktopGraphics(VOID)
{ {
NtUserAcquireOrReleaseInputOwnership(TRUE); NtUserAcquireOrReleaseInputOwnership(TRUE);
EnableMouse(FALSE); EnableMouse(FALSE);
if (NULL != ScreenDeviceContext) if (NULL != ScreenDeviceContext)
{ {
GDIOBJ_UnmarkObjectGlobal(ScreenDeviceContext); GDIOBJ_UnmarkObjectGlobal(ScreenDeviceContext);
NtGdiDeleteDC(ScreenDeviceContext); NtGdiDeleteDC(ScreenDeviceContext);
ScreenDeviceContext = NULL; ScreenDeviceContext = NULL;
} }
IntDestroyPrimarySurface();
} }
HDC FASTCALL HDC FASTCALL

View file

@ -19,7 +19,7 @@
/* /*
* GDIOBJ.C - GDI object manipulation routines * 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--; W32Process->GDIObjects--;
} }
ObDereferenceObject(Process);
} }
ObjHdr->hProcessId = GDI_GLOBAL_PROCESS; ObjHdr->hProcessId = GDI_GLOBAL_PROCESS;