Unbreak gdi batch... Sometimes dc is null.
[reactos.git] / reactos / subsystems / win32 / win32k / objects / gdibatch.c
1
2 #include <w32k.h>
3
4 #define NDEBUG
5 #include <debug.h>
6
7
8 //
9 //
10 // Gdi Batch Flush support functions.
11 //
12
13
14 //
15 // Process the batch.
16 //
17 ULONG
18 FASTCALL
19 GdiFlushUserBatch(HDC hDC, PGDIBATCHHDR pHdr)
20 {
21 PDC dc = NULL;
22 PDC_ATTR Dc_Attr = NULL;
23 if (hDC)
24 {
25 dc = DC_LockDc(hDC);
26 if (dc)
27 {
28 Dc_Attr = dc->pDc_Attr;
29 if (!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
30 }
31 }
32 // The thread is approaching the end of sunset.
33 switch(pHdr->Cmd)
34 {
35 case GdiBCPatBlt: // Highest pri first!
36 break;
37 case GdiBCPolyPatBlt:
38 break;
39 case GdiBCTextOut:
40 break;
41 case GdiBCExtTextOut:
42 break;
43 case GdiBCSetBrushOrg:
44 {
45 PGDIBSSETBRHORG pgSBO;
46 pgSBO = (PGDIBSSETBRHORG) pHdr;
47 Dc_Attr->ptlBrushOrigin = pgSBO->ptlBrushOrigin;
48 break;
49 }
50 case GdiBCExtSelClipRgn:
51 break;
52 case GdiBCSelObj:
53 {
54 PGDIBSOBJECT pgO;
55 if(!dc) break;
56 pgO = (PGDIBSOBJECT) pHdr;
57 if(NT_SUCCESS(TextIntRealizeFont((HFONT) pgO->hgdiobj)))
58 Dc_Attr->hlfntNew = (HFONT) pgO->hgdiobj;
59 }
60 case GdiBCDelObj:
61 case GdiBCDelRgn:
62 {
63 PGDIBSOBJECT pgO = (PGDIBSOBJECT) pHdr;
64 NtGdiDeleteObject( pgO->hgdiobj );
65 break;
66 }
67 default:
68 break;
69 }
70 if (dc) DC_UnlockDc(dc);
71 return pHdr->Size; // Return the full size of the structure.
72 }
73
74 /*
75 * NtGdiFlush
76 *
77 * Flushes the calling thread's current batch.
78 */
79 VOID
80 APIENTRY
81 NtGdiFlush(VOID)
82 {
83 UNIMPLEMENTED;
84 }
85
86 /*
87 * NtGdiFlushUserBatch
88 *
89 * Callback for thread batch flush routine.
90 *
91 * Think small & fast!
92 */
93 NTSTATUS
94 APIENTRY
95 NtGdiFlushUserBatch(VOID)
96 {
97 PTEB pTeb = NtCurrentTeb();
98 ULONG GdiBatchCount = pTeb->GdiBatchCount;
99
100 if( (GdiBatchCount > 0) && (GdiBatchCount <= (GDIBATCHBUFSIZE/4)))
101 {
102 HDC hDC = (HDC) pTeb->GdiTebBatch.HDC;
103 //
104 // If hDC is zero and the buffer fills up with delete objects we need to run
105 // anyway. So, hard code to the system batch limit.
106 //
107 if ((hDC) || ((!hDC) && (GdiBatchCount >= GDI_BATCH_LIMIT)))
108 {
109 PULONG pHdr = &pTeb->GdiTebBatch.Buffer[0];
110 // No need to init anything, just go!
111 for (; GdiBatchCount > 0; GdiBatchCount--)
112 {
113 // Process Gdi Batch!
114 pHdr += GdiFlushUserBatch( hDC, (PGDIBATCHHDR) pHdr );
115 }
116 // Exit and clear out for the next round.
117 pTeb->GdiTebBatch.Offset = 0;
118 pTeb->GdiBatchCount = 0;
119 pTeb->GdiTebBatch.HDC = 0;
120 }
121 }
122 return STATUS_SUCCESS;
123 }
124
125