Sync with trunk head
[reactos.git] / 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 // DoDeviceSync
15 //
16 // based on IntEngEnter from eng/engmisc.c
17 //
18 VOID
19 FASTCALL
20 DoDeviceSync( SURFOBJ *Surface, PRECTL Rect, FLONG fl)
21 {
22 PPDEVOBJ Device = (PDEVOBJ*)Surface->hdev;
23 // No punting and "Handle to a surface, provided that the surface is device-managed.
24 // Otherwise, dhsurf is zero".
25 if (!(Device->flFlags & PDEV_DRIVER_PUNTED_CALL) && (Surface->dhsurf))
26 {
27 if (Device->DriverFunctions.SynchronizeSurface)
28 {
29 Device->DriverFunctions.SynchronizeSurface(Surface, Rect, fl);
30 }
31 else
32 {
33 if (Device->DriverFunctions.Synchronize)
34 {
35 Device->DriverFunctions.Synchronize(Surface->dhpdev, Rect);
36 }
37 }
38 }
39 }
40
41 VOID
42 FASTCALL
43 SynchonizeDriver(FLONG Flags)
44 {
45 SURFOBJ *SurfObj;
46 PPDEVOBJ Device;
47
48 if (Flags & GCAPS2_SYNCFLUSH)
49 Flags = DSS_FLUSH_EVENT;
50 if (Flags & GCAPS2_SYNCTIMER)
51 Flags = DSS_TIMER_EVENT;
52
53 Device = IntEnumHDev();
54
55 SurfObj = EngLockSurface( Device->pSurface );
56 if(!SurfObj) return;
57 DoDeviceSync( SurfObj, NULL, Flags);
58 EngUnlockSurface(SurfObj);
59 return;
60 }
61
62 //
63 // Process the batch.
64 //
65 ULONG
66 FASTCALL
67 GdiFlushUserBatch(PDC dc, PGDIBATCHHDR pHdr)
68 {
69 PDC_ATTR pdcattr = NULL;
70
71 if (dc)
72 {
73 pdcattr = dc->pdcattr;
74 }
75 // The thread is approaching the end of sunset.
76 switch(pHdr->Cmd)
77 {
78 case GdiBCPatBlt: // Highest pri first!
79 break;
80 case GdiBCPolyPatBlt:
81 break;
82 case GdiBCTextOut:
83 break;
84 case GdiBCExtTextOut:
85 break;
86 case GdiBCSetBrushOrg:
87 {
88 PGDIBSSETBRHORG pgSBO;
89 if(!dc) break;
90 pgSBO = (PGDIBSSETBRHORG) pHdr;
91 pdcattr->ptlBrushOrigin = pgSBO->ptlBrushOrigin;
92 break;
93 }
94 case GdiBCExtSelClipRgn:
95 break;
96 case GdiBCSelObj:
97 {
98 PGDIBSOBJECT pgO;
99 if(!dc) break;
100 pgO = (PGDIBSOBJECT) pHdr;
101 TextIntRealizeFont((HFONT) pgO->hgdiobj, NULL);
102 pdcattr->ulDirty_ &= ~(DIRTY_CHARSET);
103 }
104 case GdiBCDelRgn:
105 DPRINT("Delete Region Object!\n");
106 case GdiBCDelObj:
107 {
108 PGDIBSOBJECT pgO = (PGDIBSOBJECT) pHdr;
109 GreDeleteObject( pgO->hgdiobj );
110 break;
111 }
112 default:
113 break;
114 }
115
116 return pHdr->Size; // Return the full size of the structure.
117 }
118
119 /*
120 * NtGdiFlush
121 *
122 * Flushes the calling thread's current batch.
123 */
124 VOID
125 APIENTRY
126 NtGdiFlush(VOID)
127 {
128 SynchonizeDriver(GCAPS2_SYNCFLUSH);
129 }
130
131 /*
132 * NtGdiFlushUserBatch
133 *
134 * Callback for thread batch flush routine.
135 *
136 * Think small & fast!
137 */
138 NTSTATUS
139 APIENTRY
140 NtGdiFlushUserBatch(VOID)
141 {
142 PTEB pTeb = NtCurrentTeb();
143 ULONG GdiBatchCount = pTeb->GdiBatchCount;
144
145 if( (GdiBatchCount > 0) && (GdiBatchCount <= (GDIBATCHBUFSIZE/4)))
146 {
147 HDC hDC = (HDC) pTeb->GdiTebBatch.HDC;
148
149 /* If hDC is zero and the buffer fills up with delete objects we need
150 to run anyway.
151 */
152 if (hDC || GdiBatchCount)
153 {
154 PCHAR pHdr = (PCHAR)&pTeb->GdiTebBatch.Buffer[0];
155 PDC pDC = NULL;
156
157 if (hDC && !IsObjectDead(hDC))
158 {
159 pDC = DC_LockDc(hDC);
160 }
161
162 // No need to init anything, just go!
163 for (; GdiBatchCount > 0; GdiBatchCount--)
164 {
165 // Process Gdi Batch!
166 pHdr += GdiFlushUserBatch(pDC, (PGDIBATCHHDR) pHdr);
167 }
168
169 if (pDC)
170 {
171 DC_UnlockDc(pDC);
172 }
173
174 // Exit and clear out for the next round.
175 pTeb->GdiTebBatch.Offset = 0;
176 pTeb->GdiBatchCount = 0;
177 pTeb->GdiTebBatch.HDC = 0;
178 }
179 }
180
181 // FIXME: on xp the function returns &pTeb->RealClientId, maybe VOID?
182 return STATUS_SUCCESS;
183 }
184
185