xref: /reactos/win32ss/gdi/ntgdi/dcattr.c (revision c2c66aff)
1 /*
2  * COPYRIGHT:         See COPYING in the top level directory
3  * PROJECT:           ReactOS kernel
4  * PURPOSE:           Functions for creation and destruction of DCs
5  * FILE:              win32ss/gdi/ntgdi/dcattr.c
6  * PROGRAMER:         Timo Kreuzer (timo.kreuzer@rectos.org)
7  */
8 
9 #include <win32k.h>
10 
11 #define NDEBUG
12 #include <debug.h>
13 
14 #define GDIDCATTRFREE 8
15 
16 typedef struct _GDI_DC_ATTR_FREELIST
17 {
18   LIST_ENTRY Entry;
19   DWORD nEntries;
20   PVOID AttrList[GDIDCATTRFREE];
21 } GDI_DC_ATTR_FREELIST, *PGDI_DC_ATTR_FREELIST;
22 
23 typedef struct _GDI_DC_ATTR_ENTRY
24 {
25   DC_ATTR Attr[GDIDCATTRFREE];
26 } GDI_DC_ATTR_ENTRY, *PGDI_DC_ATTR_ENTRY;
27 
28 
29 BOOL
30 NTAPI
DC_bAllocDcAttr(PDC pdc)31 DC_bAllocDcAttr(PDC pdc)
32 {
33     PPROCESSINFO ppi;
34     PDC_ATTR pdcattr;
35 
36     ppi = PsGetCurrentProcessWin32Process();
37     ASSERT(ppi);
38 
39     pdcattr = GdiPoolAllocate(ppi->pPoolDcAttr);
40     if (!pdcattr)
41     {
42         DPRINT1("Could not allocate DC attr\n");
43         return FALSE;
44     }
45 
46     /* Copy the content from the kernel mode dc attr */
47     pdc->pdcattr = pdcattr;
48     *pdc->pdcattr = pdc->dcattr;
49 
50     /* Set the object attribute in the handle table */
51     GDIOBJ_vSetObjectAttr(&pdc->BaseObject, pdcattr);
52 
53     DPRINT("DC_AllocDcAttr: pdc=%p, pdc->pdcattr=%p\n", pdc, pdc->pdcattr);
54     return TRUE;
55 }
56 
57 VOID
58 NTAPI
DC_vFreeDcAttr(PDC pdc)59 DC_vFreeDcAttr(PDC pdc)
60 {
61     PPROCESSINFO ppi;
62 
63     if (pdc->pdcattr == &pdc->dcattr)
64     {
65         // Internal DC object!
66         return;
67     }
68 
69     /* Reset the object attribute in the handle table */
70     GDIOBJ_vSetObjectAttr(&pdc->BaseObject, NULL);
71 
72     ppi = PsGetCurrentProcessWin32Process();
73     ASSERT(ppi);
74     GdiPoolFree(ppi->pPoolDcAttr, pdc->pdcattr);
75 
76     /* Reset to kmode dcattr */
77     pdc->pdcattr = &pdc->dcattr;
78 }
79