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 BOOL Hit = FALSE;
70 ULONG Cmd = 0, Size = 0;
71 PDC_ATTR pdcattr = NULL;
72
73 if (dc)
74 {
75 pdcattr = dc->pdcattr;
76 }
77
78 _SEH2_TRY
79 {
80 Cmd = pHdr->Cmd;
81 Size = pHdr->Size; // Return the full size of the structure.
82 }
83 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
84 {
85 Hit = TRUE;
86 }
87 _SEH2_END;
88
89 if (Hit)
90 {
91 DPRINT1("WARNING! GdiBatch Fault!\n");
92 return 0;
93 }
94
95 // FYI! The thread is approaching the end of sunset.
96 switch(Cmd)
97 {
98 case GdiBCPatBlt: // Highest pri first!
99 break;
100 case GdiBCPolyPatBlt:
101 break;
102 case GdiBCTextOut:
103 break;
104 case GdiBCExtTextOut:
105 break;
106 case GdiBCSetBrushOrg:
107 {
108 PGDIBSSETBRHORG pgSBO;
109 if(!dc) break;
110 pgSBO = (PGDIBSSETBRHORG) pHdr;
111 pdcattr->ptlBrushOrigin = pgSBO->ptlBrushOrigin;
112 break;
113 }
114 case GdiBCExtSelClipRgn:
115 break;
116 case GdiBCSelObj:
117 {
118 PGDIBSOBJECT pgO;
119 if(!dc) break;
120 pgO = (PGDIBSOBJECT) pHdr;
121 TextIntRealizeFont((HFONT) pgO->hgdiobj, NULL);
122 pdcattr->ulDirty_ &= ~(DIRTY_CHARSET);
123 }
124 case GdiBCDelRgn:
125 DPRINT("Delete Region Object!\n");
126 case GdiBCDelObj:
127 {
128 PGDIBSOBJECT pgO = (PGDIBSOBJECT) pHdr;
129 GreDeleteObject( pgO->hgdiobj );
130 break;
131 }
132 default:
133 break;
134 }
135
136 return Size;
137 }
138
139 /*
140 * NtGdiFlush
141 *
142 * Flushes the calling thread's current batch.
143 */
144 VOID
145 APIENTRY
146 NtGdiFlush(VOID)
147 {
148 SynchonizeDriver(GCAPS2_SYNCFLUSH);
149 }
150
151 /*
152 * NtGdiFlushUserBatch
153 *
154 * Callback for thread batch flush routine.
155 *
156 * Think small & fast!
157 */
158 NTSTATUS
159 APIENTRY
160 NtGdiFlushUserBatch(VOID)
161 {
162 PTEB pTeb = NtCurrentTeb();
163 ULONG GdiBatchCount = pTeb->GdiBatchCount;
164
165 if( (GdiBatchCount > 0) && (GdiBatchCount <= (GDIBATCHBUFSIZE/4)))
166 {
167 HDC hDC = (HDC) pTeb->GdiTebBatch.HDC;
168
169 /* If hDC is zero and the buffer fills up with delete objects we need
170 to run anyway.
171 */
172 if (hDC || GdiBatchCount)
173 {
174 PCHAR pHdr = (PCHAR)&pTeb->GdiTebBatch.Buffer[0];
175 PDC pDC = NULL;
176
177 if (hDC && !IsObjectDead(hDC))
178 {
179 pDC = DC_LockDc(hDC);
180 }
181
182 // No need to init anything, just go!
183 for (; GdiBatchCount > 0; GdiBatchCount--)
184 {
185 ULONG Size;
186 // Process Gdi Batch!
187 Size = GdiFlushUserBatch(pDC, (PGDIBATCHHDR) pHdr);
188 if (!Size) break;
189 pHdr += Size;
190 }
191
192 if (pDC)
193 {
194 DC_UnlockDc(pDC);
195 }
196
197 // Exit and clear out for the next round.
198 pTeb->GdiTebBatch.Offset = 0;
199 pTeb->GdiBatchCount = 0;
200 pTeb->GdiTebBatch.HDC = 0;
201 }
202 }
203
204 // FIXME: on xp the function returns &pTeb->RealClientId, maybe VOID?
205 return STATUS_SUCCESS;
206 }
207
208