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;
WORD GDIObjects;
WORD UserObjects;
BOOL CreatedWindowOrDC;
} W32PROCESS, *PW32PROCESS;
PW32THREAD STDCALL

View file

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

View file

@ -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

View file

@ -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/text.h>
#include <include/caret.h>
#include <include/hotkey.h>
#include <include/guicheck.h>
#define NDEBUG
#include <win32k/debug1.h>
@ -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;

View file

@ -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 */

View file

@ -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);
}

View file

@ -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/color.h>
#include <include/mouse.h>
#include <include/callback.h>
#include <include/guicheck.h>
#define NDEBUG
#include <debug.h>
@ -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

View file

@ -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;