2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * PURPOSE: Manage GDI Handles
24 * FILE: subsys/win32k/eng/handle.c
25 * PROGRAMER: Jason Filby
30 #include <ddk/winddi.h>
34 #include <win32k/debug1.h>
36 static int LastHandle = MAX_GDI_HANDLES;
38 ULONG FASTCALL CreateGDIHandle(ULONG InternalSize, ULONG UserSize)
44 //size = sizeof( ENGOBJ ) + InternalSize + UserSize;
45 size = InternalSize; //internal size includes header and user portions
46 pObj = EngAllocMem( FL_ZERO_MEMORY, size, 0 );
51 pObj->InternalSize = InternalSize;
52 pObj->UserSize = UserSize;
54 for( i = (MAX_GDI_HANDLES - 1 <= LastHandle ? 1 : LastHandle + 1); i != LastHandle;
55 i = (MAX_GDI_HANDLES - 1 <= i ? 1 : i + 1) ){
56 if( GDIHandles[ i ].pEngObj == NULL ){
58 GDIHandles[ i ].pEngObj = pObj;
59 DPRINT("CreateGDIHandle: obj: %x, handle: %d, usersize: %d\n", pObj, i, UserSize );
64 DPRINT1("CreateGDIHandle: Out of available handles!!!\n");
69 VOID FASTCALL FreeGDIHandle(ULONG Handle)
71 if( Handle == 0 || Handle >= MAX_GDI_HANDLES ){
72 DPRINT1("FreeGDIHandle: invalid handle!!!!\n");
75 DPRINT("FreeGDIHandle: handle: %d\n", Handle);
76 EngFreeMem( GDIHandles[Handle].pEngObj );
77 GDIHandles[Handle].pEngObj = NULL;
80 PVOID FASTCALL AccessInternalObject(ULONG Handle)
84 if( Handle == 0 || Handle >= MAX_GDI_HANDLES ){
85 DPRINT1("AccessInternalObject: invalid handle: %d!!!!\n", Handle);
89 pEngObj = GDIHandles[Handle].pEngObj;
90 return (PVOID)pEngObj;
93 PVOID FASTCALL AccessUserObject(ULONG Handle)
97 if( Handle == 0 || Handle >= MAX_GDI_HANDLES ){
98 DPRINT1("AccessUserObject: invalid handle: %d!!!!\n", Handle);
102 pEngObj = GDIHandles[Handle].pEngObj;
103 return (PVOID)( (PCHAR)pEngObj + sizeof( ENGOBJ ) );
106 ULONG FASTCALL AccessHandleFromUserObject(PVOID UserObject)
112 return INVALID_HANDLE;
114 pEngObj = (PENGOBJ)((PCHAR) UserObject - sizeof( ENGOBJ ));
115 Handle = pEngObj->hObj;
117 if( Handle == 0 || Handle >= MAX_GDI_HANDLES ){
118 DPRINT1("AccessHandleFromUserObject: inv handle: %d, obj: %x!!!!\n", Handle, pEngObj);
119 return INVALID_HANDLE;
124 PVOID FASTCALL AccessInternalObjectFromUserObject(PVOID UserObject)
127 return AccessInternalObject( AccessHandleFromUserObject( UserObject ) );
130 VOID FASTCALL InitEngHandleTable( void )
133 for( i=1; i < MAX_GDI_HANDLES; i++ ){
134 GDIHandles[ i ].pEngObj = NULL;