xref: /reactos/win32ss/gdi/ntgdi/baseobj.hpp (revision c2c66aff)
1 
2 #pragma once
3 
4 #define GDIOBJ_POOL_TAG(type) ('00hG' + (((type) & 0x1f) << 24))
5 
6 #define BASEOBJECT CBASEOBJECT
7 
8 class BASEOBJECT : private _BASEOBJECT
9 {
10 public:
11 
12     enum OWNER
13     {
14         POWNED = GDI_OBJ_HMGR_POWNED,
15         PUBLIC = GDI_OBJ_HMGR_PUBLIC,
16         NONE = GDI_OBJ_HMGR_NONE
17     };
18 
19 protected:
20 
BASEOBJECT(_In_ GDILOOBJTYPE loobjtype)21     BASEOBJECT(
22         _In_ GDILOOBJTYPE loobjtype)
23     {
24         /* Initialize the object */
25         _BASEOBJECT::hHmgr = (HGDIOBJ)(ULONG_PTR)loobjtype;
26         this->cExclusiveLock = 0;
27         this->ulShareCount = 1;
28         this->BaseFlags = 0;//fl & 0xffff;
29         DBG_INITLOG(&this->slhLog);
30         DBG_LOGEVENT(&this->slhLog, EVENT_ALLOCATE, 0);
31     #if DBG_ENABLE_GDIOBJ_BACKTRACES
32         DbgCaptureStackBackTace(this->apvBackTrace, 1, GDI_OBJECT_STACK_LEVELS);
33     #endif /* GDI_DEBUG */
34     }
35 
36     static
37     BASEOBJECT*
38     LockExclusive(
39         HGDIOBJ hobj,
40         GDIOBJTYPE objtype);
41 
42     static
43     BASEOBJECT*
44     LockExclusive(
45         HGDIOBJ hobj,
46         GDILOOBJTYPE loobjtype);
47 
48     static
49     BASEOBJECT*
LockShared(HGDIOBJ hobj,GDILOOBJTYPE loobjtype,OWNER owner)50     LockShared(
51         HGDIOBJ hobj,
52         GDILOOBJTYPE loobjtype,
53         OWNER owner)
54     {
55         /// FIXME: should check owner!
56         return reinterpret_cast<CBASEOBJECT*>(GDIOBJ_ShareLockObj(hobj, loobjtype));
57     }
58 
59     VOID
vSetObjectAttr(_In_opt_ PVOID pvUserAttr)60     vSetObjectAttr(
61         _In_opt_ PVOID pvUserAttr)
62     {
63         GDIOBJ_vSetObjectAttr((POBJ)this, pvUserAttr);
64     }
65 
66 
67 public:
68 
69     static
70     inline
71     PVOID
pvAllocate(_In_ GDIOBJTYPE objtype,_In_ SIZE_T cjSize)72     pvAllocate(
73         _In_ GDIOBJTYPE objtype,
74         _In_ SIZE_T cjSize)
75     {
76         return ExAllocatePoolWithTag(PagedPool, cjSize, GDIOBJ_POOL_TAG(objtype));
77     }
78 
79     VOID
vUnlock(VOID)80     vUnlock(
81         VOID)
82     {
83         if (this->cExclusiveLock > 0)
84         {
85             GDIOBJ_vUnlockObject(this);
86         }
87         else
88         {
89             GDIOBJ_vDereferenceObject(this);
90         }
91     }
92 
93     inline
94     HGDIOBJ
hHmgr(VOID)95     hHmgr(
96         VOID)
97     {
98         return _BASEOBJECT::hHmgr;
99     }
100 
101     HGDIOBJ
hInsertObject(OWNER owner)102     hInsertObject(
103         OWNER owner)
104     {
105         return GDIOBJ_hInsertObject(this, owner);
106     }
107 
108 };
109 
110 
111