Coverage Report

Created: 2025-10-10 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/FreeRDP/libfreerdp/gdi/gdi.c
Line
Count
Source
1
/**
2
 * FreeRDP: A Remote Desktop Protocol Implementation
3
 * GDI Library
4
 *
5
 * Copyright 2010-2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6
 * Copyright 2016 Armin Novak <armin.novak@thincast.com>
7
 * Copyright 2016 Thincast Technologies GmbH
8
 *
9
 * Licensed under the Apache License, Version 2.0 (the "License");
10
 * you may not use this file except in compliance with the License.
11
 * You may obtain a copy of the License at
12
 *
13
 *   http://www.apache.org/licenses/LICENSE-2.0
14
 *
15
 * Unless required by applicable law or agreed to in writing, software
16
 * distributed under the License is distributed on an "AS IS" BASIS,
17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
 * See the License for the specific language governing permissions and
19
 * limitations under the License.
20
 */
21
22
#include <freerdp/config.h>
23
24
#include <stdio.h>
25
#include <stdlib.h>
26
27
#include <winpr/crt.h>
28
#include <winpr/assert.h>
29
#include <winpr/cast.h>
30
31
#include <freerdp/api.h>
32
#include <freerdp/log.h>
33
#include <freerdp/freerdp.h>
34
#include <freerdp/codecs.h>
35
36
#include <freerdp/gdi/gdi.h>
37
#include <freerdp/gdi/dc.h>
38
#include <freerdp/gdi/pen.h>
39
#include <freerdp/gdi/shape.h>
40
#include <freerdp/gdi/region.h>
41
#include <freerdp/gdi/bitmap.h>
42
43
#include "drawing.h"
44
#include "clipping.h"
45
#include "brush.h"
46
#include "line.h"
47
#include "gdi.h"
48
#include "../core/graphics.h"
49
#include "../core/update.h"
50
#include "../cache/cache.h"
51
52
0
#define TAG FREERDP_TAG("gdi")
53
54
/* Ternary Raster Operation Table */
55
typedef struct
56
{
57
  DWORD code;
58
  const char* name;
59
} rop_table_entry;
60
61
static const rop_table_entry rop3_code_table[] = { { GDI_BLACKNESS, "0" },
62
                                                 { GDI_DPSoon, "DPSoon" },
63
                                                 { GDI_DPSona, "DPSona" },
64
                                                 { GDI_PSon, "PSon" },
65
                                                 { GDI_SDPona, "SDPona" },
66
                                                 { GDI_DPon, "DPon" },
67
                                                 { GDI_PDSxnon, "PDSxnon" },
68
                                                 { GDI_PDSaon, "PDSaon" },
69
                                                 { GDI_SDPnaa, "SDPnaa" },
70
                                                 { GDI_PDSxon, "PDSxon" },
71
                                                 { GDI_DPna, "DPna" },
72
                                                 { GDI_PSDnaon, "PSDnaon" },
73
                                                 { GDI_SPna, "SPna" },
74
                                                 { GDI_PDSnaon, "PDSnaon" },
75
                                                 { GDI_PDSonon, "PDSonon" },
76
                                                 { GDI_Pn, "Pn" },
77
                                                 { GDI_PDSona, "PDSona" },
78
                                                 { GDI_NOTSRCERASE, "DSon" },
79
                                                 { GDI_SDPxnon, "SDPxnon" },
80
                                                 { GDI_SDPaon, "SDPaon" },
81
                                                 { GDI_DPSxnon, "DPSxnon" },
82
                                                 { GDI_DPSaon, "DPSaon" },
83
                                                 { GDI_PSDPSanaxx, "PSDPSanaxx" },
84
                                                 { GDI_SSPxDSxaxn, "SSPxDSxaxn" },
85
                                                 { GDI_SPxPDxa, "SPxPDxa" },
86
                                                 { GDI_SDPSanaxn, "SDPSanaxn" },
87
                                                 { GDI_PDSPaox, "PDSPaox" },
88
                                                 { GDI_SDPSxaxn, "SDPSxaxn" },
89
                                                 { GDI_PSDPaox, "PSDPaox" },
90
                                                 { GDI_DSPDxaxn, "DSPDxaxn" },
91
                                                 { GDI_PDSox, "PDSox" },
92
                                                 { GDI_PDSoan, "PDSoan" },
93
                                                 { GDI_DPSnaa, "DPSnaa" },
94
                                                 { GDI_SDPxon, "SDPxon" },
95
                                                 { GDI_DSna, "DSna" },
96
                                                 { GDI_SPDnaon, "SPDnaon" },
97
                                                 { GDI_SPxDSxa, "SPxDSxa" },
98
                                                 { GDI_PDSPanaxn, "PDSPanaxn" },
99
                                                 { GDI_SDPSaox, "SDPSaox" },
100
                                                 { GDI_SDPSxnox, "SDPSxnox" },
101
                                                 { GDI_DPSxa, "DPSxa" },
102
                                                 { GDI_PSDPSaoxxn, "PSDPSaoxxn" },
103
                                                 { GDI_DPSana, "DPSana" },
104
                                                 { GDI_SSPxPDxaxn, "SSPxPDxaxn" },
105
                                                 { GDI_SPDSoax, "SPDSoax" },
106
                                                 { GDI_PSDnox, "PSDnox" },
107
                                                 { GDI_PSDPxox, "PSDPxox" },
108
                                                 { GDI_PSDnoan, "PSDnoan" },
109
                                                 { GDI_PSna, "PSna" },
110
                                                 { GDI_SDPnaon, "SDPnaon" },
111
                                                 { GDI_SDPSoox, "SDPSoox" },
112
                                                 { GDI_NOTSRCCOPY, "Sn" },
113
                                                 { GDI_SPDSaox, "SPDSaox" },
114
                                                 { GDI_SPDSxnox, "SPDSxnox" },
115
                                                 { GDI_SDPox, "SDPox" },
116
                                                 { GDI_SDPoan, "SDPoan" },
117
                                                 { GDI_PSDPoax, "PSDPoax" },
118
                                                 { GDI_SPDnox, "SPDnox" },
119
                                                 { GDI_SPDSxox, "SPDSxox" },
120
                                                 { GDI_SPDnoan, "SPDnoan" },
121
                                                 { GDI_PSx, "PSx" },
122
                                                 { GDI_SPDSonox, "SPDSonox" },
123
                                                 { GDI_SPDSnaox, "SPDSnaox" },
124
                                                 { GDI_PSan, "PSan" },
125
                                                 { GDI_PSDnaa, "PSDnaa" },
126
                                                 { GDI_DPSxon, "DPSxon" },
127
                                                 { GDI_SDxPDxa, "SDxPDxa" },
128
                                                 { GDI_SPDSanaxn, "SPDSanaxn" },
129
                                                 { GDI_SRCERASE, "SDna" },
130
                                                 { GDI_DPSnaon, "DPSnaon" },
131
                                                 { GDI_DSPDaox, "DSPDaox" },
132
                                                 { GDI_PSDPxaxn, "PSDPxaxn" },
133
                                                 { GDI_SDPxa, "SDPxa" },
134
                                                 { GDI_PDSPDaoxxn, "PDSPDaoxxn" },
135
                                                 { GDI_DPSDoax, "DPSDoax" },
136
                                                 { GDI_PDSnox, "PDSnox" },
137
                                                 { GDI_SDPana, "SDPana" },
138
                                                 { GDI_SSPxDSxoxn, "SSPxDSxoxn" },
139
                                                 { GDI_PDSPxox, "PDSPxox" },
140
                                                 { GDI_PDSnoan, "PDSnoan" },
141
                                                 { GDI_PDna, "PDna" },
142
                                                 { GDI_DSPnaon, "DSPnaon" },
143
                                                 { GDI_DPSDaox, "DPSDaox" },
144
                                                 { GDI_SPDSxaxn, "SPDSxaxn" },
145
                                                 { GDI_DPSonon, "DPSonon" },
146
                                                 { GDI_DSTINVERT, "Dn" },
147
                                                 { GDI_DPSox, "DPSox" },
148
                                                 { GDI_DPSoan, "DPSoan" },
149
                                                 { GDI_PDSPoax, "PDSPoax" },
150
                                                 { GDI_DPSnox, "DPSnox" },
151
                                                 { GDI_PATINVERT, "DPx" },
152
                                                 { GDI_DPSDonox, "DPSDonox" },
153
                                                 { GDI_DPSDxox, "DPSDxox" },
154
                                                 { GDI_DPSnoan, "DPSnoan" },
155
                                                 { GDI_DPSDnaox, "DPSDnaox" },
156
                                                 { GDI_DPan, "DPan" },
157
                                                 { GDI_PDSxa, "PDSxa" },
158
                                                 { GDI_DSPDSaoxxn, "DSPDSaoxxn" },
159
                                                 { GDI_DSPDoax, "DSPDoax" },
160
                                                 { GDI_SDPnox, "SDPnox" },
161
                                                 { GDI_SDPSoax, "SDPSoax" },
162
                                                 { GDI_DSPnox, "DSPnox" },
163
                                                 { GDI_SRCINVERT, "DSx" },
164
                                                 { GDI_SDPSonox, "SDPSonox" },
165
                                                 { GDI_DSPDSonoxxn, "DSPDSonoxxn" },
166
                                                 { GDI_PDSxxn, "PDSxxn" },
167
                                                 { GDI_DPSax, "DPSax" },
168
                                                 { GDI_PSDPSoaxxn, "PSDPSoaxxn" },
169
                                                 { GDI_SDPax, "SDPax" },
170
                                                 { GDI_PDSPDoaxxn, "PDSPDoaxxn" },
171
                                                 { GDI_SDPSnoax, "SDPSnoax" },
172
                                                 { GDI_PDSxnan, "PDSxnan" },
173
                                                 { GDI_PDSana, "PDSana" },
174
                                                 { GDI_SSDxPDxaxn, "SSDxPDxaxn" },
175
                                                 { GDI_SDPSxox, "SDPSxox" },
176
                                                 { GDI_SDPnoan, "SDPnoan" },
177
                                                 { GDI_DSPDxox, "DSPDxox" },
178
                                                 { GDI_DSPnoan, "DSPnoan" },
179
                                                 { GDI_SDPSnaox, "SDPSnaox" },
180
                                                 { GDI_DSan, "DSan" },
181
                                                 { GDI_PDSax, "PDSax" },
182
                                                 { GDI_DSPDSoaxxn, "DSPDSoaxxn" },
183
                                                 { GDI_DPSDnoax, "DPSDnoax" },
184
                                                 { GDI_SDPxnan, "SDPxnan" },
185
                                                 { GDI_SPDSnoax, "SPDSnoax" },
186
                                                 { GDI_DPSxnan, "DPSxnan" },
187
                                                 { GDI_SPxDSxo, "SPxDSxo" },
188
                                                 { GDI_DPSaan, "DPSaan" },
189
                                                 { GDI_DPSaa, "DPSaa" },
190
                                                 { GDI_SPxDSxon, "SPxDSxon" },
191
                                                 { GDI_DPSxna, "DPSxna" },
192
                                                 { GDI_SPDSnoaxn, "SPDSnoaxn" },
193
                                                 { GDI_SDPxna, "SDPxna" },
194
                                                 { GDI_PDSPnoaxn, "PDSPnoaxn" },
195
                                                 { GDI_DSPDSoaxx, "DSPDSoaxx" },
196
                                                 { GDI_PDSaxn, "PDSaxn" },
197
                                                 { GDI_SRCAND, "DSa" },
198
                                                 { GDI_SDPSnaoxn, "SDPSnaoxn" },
199
                                                 { GDI_DSPnoa, "DSPnoa" },
200
                                                 { GDI_DSPDxoxn, "DSPDxoxn" },
201
                                                 { GDI_SDPnoa, "SDPnoa" },
202
                                                 { GDI_SDPSxoxn, "SDPSxoxn" },
203
                                                 { GDI_SSDxPDxax, "SSDxPDxax" },
204
                                                 { GDI_PDSanan, "PDSanan" },
205
                                                 { GDI_PDSxna, "PDSxna" },
206
                                                 { GDI_SDPSnoaxn, "SDPSnoaxn" },
207
                                                 { GDI_DPSDPoaxx, "DPSDPoaxx" },
208
                                                 { GDI_SPDaxn, "SPDaxn" },
209
                                                 { GDI_PSDPSoaxx, "PSDPSoaxx" },
210
                                                 { GDI_DPSaxn, "DPSaxn" },
211
                                                 { GDI_DPSxx, "DPSxx" },
212
                                                 { GDI_PSDPSonoxx, "PSDPSonoxx" },
213
                                                 { GDI_SDPSonoxn, "SDPSonoxn" },
214
                                                 { GDI_DSxn, "DSxn" },
215
                                                 { GDI_DPSnax, "DPSnax" },
216
                                                 { GDI_SDPSoaxn, "SDPSoaxn" },
217
                                                 { GDI_SPDnax, "SPDnax" },
218
                                                 { GDI_DSPDoaxn, "DSPDoaxn" },
219
                                                 { GDI_DSPDSaoxx, "DSPDSaoxx" },
220
                                                 { GDI_PDSxan, "PDSxan" },
221
                                                 { GDI_DPa, "DPa" },
222
                                                 { GDI_PDSPnaoxn, "PDSPnaoxn" },
223
                                                 { GDI_DPSnoa, "DPSnoa" },
224
                                                 { GDI_DPSDxoxn, "DPSDxoxn" },
225
                                                 { GDI_PDSPonoxn, "PDSPonoxn" },
226
                                                 { GDI_PDxn, "PDxn" },
227
                                                 { GDI_DSPnax, "DSPnax" },
228
                                                 { GDI_PDSPoaxn, "PDSPoaxn" },
229
                                                 { GDI_DPSoa, "DPSoa" },
230
                                                 { GDI_DPSoxn, "DPSoxn" },
231
                                                 { GDI_DSTCOPY, "D" },
232
                                                 { GDI_DPSono, "DPSono" },
233
                                                 { GDI_SPDSxax, "SPDSxax" },
234
                                                 { GDI_DPSDaoxn, "DPSDaoxn" },
235
                                                 { GDI_DSPnao, "DSPnao" },
236
                                                 { GDI_DPno, "DPno" },
237
                                                 { GDI_PDSnoa, "PDSnoa" },
238
                                                 { GDI_PDSPxoxn, "PDSPxoxn" },
239
                                                 { GDI_SSPxDSxox, "SSPxDSxox" },
240
                                                 { GDI_SDPanan, "SDPanan" },
241
                                                 { GDI_PSDnax, "PSDnax" },
242
                                                 { GDI_DPSDoaxn, "DPSDoaxn" },
243
                                                 { GDI_DPSDPaoxx, "DPSDPaoxx" },
244
                                                 { GDI_SDPxan, "SDPxan" },
245
                                                 { GDI_PSDPxax, "PSDPxax" },
246
                                                 { GDI_DSPDaoxn, "DSPDaoxn" },
247
                                                 { GDI_DPSnao, "DPSnao" },
248
                                                 { GDI_MERGEPAINT, "DSno" },
249
                                                 { GDI_SPDSanax, "SPDSanax" },
250
                                                 { GDI_SDxPDxan, "SDxPDxan" },
251
                                                 { GDI_DPSxo, "DPSxo" },
252
                                                 { GDI_DPSano, "DPSano" },
253
                                                 { GDI_MERGECOPY, "PSa" },
254
                                                 { GDI_SPDSnaoxn, "SPDSnaoxn" },
255
                                                 { GDI_SPDSonoxn, "SPDSonoxn" },
256
                                                 { GDI_PSxn, "PSxn" },
257
                                                 { GDI_SPDnoa, "SPDnoa" },
258
                                                 { GDI_SPDSxoxn, "SPDSxoxn" },
259
                                                 { GDI_SDPnax, "SDPnax" },
260
                                                 { GDI_PSDPoaxn, "PSDPoaxn" },
261
                                                 { GDI_SDPoa, "SDPoa" },
262
                                                 { GDI_SPDoxn, "SPDoxn" },
263
                                                 { GDI_DPSDxax, "DPSDxax" },
264
                                                 { GDI_SPDSaoxn, "SPDSaoxn" },
265
                                                 { GDI_SRCCOPY, "S" },
266
                                                 { GDI_SDPono, "SDPono" },
267
                                                 { GDI_SDPnao, "SDPnao" },
268
                                                 { GDI_SPno, "SPno" },
269
                                                 { GDI_PSDnoa, "PSDnoa" },
270
                                                 { GDI_PSDPxoxn, "PSDPxoxn" },
271
                                                 { GDI_PDSnax, "PDSnax" },
272
                                                 { GDI_SPDSoaxn, "SPDSoaxn" },
273
                                                 { GDI_SSPxPDxax, "SSPxPDxax" },
274
                                                 { GDI_DPSanan, "DPSanan" },
275
                                                 { GDI_PSDPSaoxx, "PSDPSaoxx" },
276
                                                 { GDI_DPSxan, "DPSxan" },
277
                                                 { GDI_PDSPxax, "PDSPxax" },
278
                                                 { GDI_SDPSaoxn, "SDPSaoxn" },
279
                                                 { GDI_DPSDanax, "DPSDanax" },
280
                                                 { GDI_SPxDSxan, "SPxDSxan" },
281
                                                 { GDI_SPDnao, "SPDnao" },
282
                                                 { GDI_SDno, "SDno" },
283
                                                 { GDI_SDPxo, "SDPxo" },
284
                                                 { GDI_SDPano, "SDPano" },
285
                                                 { GDI_PDSoa, "PDSoa" },
286
                                                 { GDI_PDSoxn, "PDSoxn" },
287
                                                 { GDI_DSPDxax, "DSPDxax" },
288
                                                 { GDI_PSDPaoxn, "PSDPaoxn" },
289
                                                 { GDI_SDPSxax, "SDPSxax" },
290
                                                 { GDI_PDSPaoxn, "PDSPaoxn" },
291
                                                 { GDI_SDPSanax, "SDPSanax" },
292
                                                 { GDI_SPxPDxan, "SPxPDxan" },
293
                                                 { GDI_SSPxDSxax, "SSPxDSxax" },
294
                                                 { GDI_DSPDSanaxxn, "DSPDSanaxxn" },
295
                                                 { GDI_DPSao, "DPSao" },
296
                                                 { GDI_DPSxno, "DPSxno" },
297
                                                 { GDI_SDPao, "SDPao" },
298
                                                 { GDI_SDPxno, "SDPxno" },
299
                                                 { GDI_SRCPAINT, "DSo" },
300
                                                 { GDI_SDPnoo, "SDPnoo" },
301
                                                 { GDI_PATCOPY, "P" },
302
                                                 { GDI_PDSono, "PDSono" },
303
                                                 { GDI_PDSnao, "PDSnao" },
304
                                                 { GDI_PSno, "PSno" },
305
                                                 { GDI_PSDnao, "PSDnao" },
306
                                                 { GDI_PDno, "PDno" },
307
                                                 { GDI_PDSxo, "PDSxo" },
308
                                                 { GDI_PDSano, "PDSano" },
309
                                                 { GDI_PDSao, "PDSao" },
310
                                                 { GDI_PDSxno, "PDSxno" },
311
                                                 { GDI_DPo, "DPo" },
312
                                                 { GDI_PATPAINT, "DPSnoo" },
313
                                                 { GDI_PSo, "PSo" },
314
                                                 { GDI_PSDnoo, "PSDnoo" },
315
                                                 { GDI_DPSoo, "DPSoo" },
316
                                                 { GDI_WHITENESS, "1" } };
317
318
/* Hatch Patterns as monochrome data */
319
static const BYTE GDI_BS_HATCHED_PATTERNS[] = {
320
  0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, /* HS_HORIZONTAL */
321
  0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, 0xF7, /* HS_VERTICAL */
322
  0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F, /* HS_FDIAGONAL */
323
  0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0xFE, /* HS_BDIAGONAL */
324
  0xF7, 0xF7, 0xF7, 0x00, 0xF7, 0xF7, 0xF7, 0xF7, /* HS_CROSS */
325
  0x7E, 0xBD, 0xDB, 0xE7, 0xE7, 0xDB, 0xBD, 0x7E  /* HS_DIACROSS */
326
};
327
328
0
#define gdi_rop3_code_checked(code) gdi_rop3_code_checked_int((code), __FILE__, __func__, __LINE__)
329
static inline DWORD gdi_rop3_code_checked_int(UINT32 code, WINPR_ATTR_UNUSED const char* file,
330
                                              WINPR_ATTR_UNUSED const char* fkt,
331
                                              WINPR_ATTR_UNUSED size_t line)
332
0
{
333
0
  WINPR_ASSERT_AT(code <= UINT8_MAX, file, fkt, line);
334
0
  return gdi_rop3_code((UINT8)code);
335
0
}
336
337
BOOL gdi_decode_color(rdpGdi* gdi, UINT32 srcColor, UINT32* color, UINT32* format)
338
0
{
339
0
  UINT32 SrcFormat = 0;
340
341
0
  if (!gdi || !color || !gdi->context || !gdi->context->settings)
342
0
    return FALSE;
343
344
0
  const UINT32 ColorDepth =
345
0
      freerdp_settings_get_uint32(gdi->context->settings, FreeRDP_ColorDepth);
346
347
0
  switch (ColorDepth)
348
0
  {
349
0
    case 32:
350
0
    case 24:
351
0
      SrcFormat = PIXEL_FORMAT_BGR24;
352
0
      break;
353
354
0
    case 16:
355
0
      SrcFormat = PIXEL_FORMAT_RGB16;
356
0
      break;
357
358
0
    case 15:
359
0
      SrcFormat = PIXEL_FORMAT_RGB15;
360
0
      break;
361
362
0
    case 8:
363
0
      SrcFormat = PIXEL_FORMAT_RGB8;
364
0
      break;
365
366
0
    default:
367
0
      return FALSE;
368
0
  }
369
370
0
  if (format)
371
0
    *format = gdi->dstFormat;
372
373
0
  *color = FreeRDPConvertColor(srcColor, SrcFormat, gdi->dstFormat, &gdi->palette);
374
0
  return TRUE;
375
0
}
376
377
/* GDI Helper Functions */
378
DWORD gdi_rop3_code(BYTE code)
379
0
{
380
0
  return rop3_code_table[code].code;
381
0
}
382
383
const char* gdi_rop3_code_string(BYTE code)
384
0
{
385
0
  return rop3_code_table[code].name;
386
0
}
387
388
const char* gdi_rop3_string(DWORD rop)
389
0
{
390
0
  const size_t count = sizeof(rop3_code_table) / sizeof(rop3_code_table[0]);
391
392
0
  for (size_t x = 0; x < count; x++)
393
0
  {
394
0
    if (rop3_code_table[x].code == rop)
395
0
      return rop3_code_table[x].name;
396
0
  }
397
398
0
  return "UNKNOWN";
399
0
}
400
401
UINT32 gdi_get_pixel_format(UINT32 bitsPerPixel)
402
0
{
403
0
  UINT32 format = 0;
404
405
0
  switch (bitsPerPixel)
406
0
  {
407
0
    case 32:
408
0
      format = PIXEL_FORMAT_BGRA32;
409
0
      break;
410
411
0
    case 24:
412
0
      format = PIXEL_FORMAT_BGR24;
413
0
      break;
414
415
0
    case 16:
416
0
      format = PIXEL_FORMAT_RGB16;
417
0
      break;
418
419
0
    case 15:
420
0
      format = PIXEL_FORMAT_RGB15;
421
0
      break;
422
423
0
    case 8:
424
0
      format = PIXEL_FORMAT_RGB8;
425
0
      break;
426
427
0
    default:
428
0
      WLog_ERR(TAG, "Unsupported color depth %" PRIu32, bitsPerPixel);
429
0
      format = 0;
430
0
      break;
431
0
  }
432
433
0
  return format;
434
0
}
435
436
gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp, BYTE* data)
437
0
{
438
0
  gdiBitmap* bitmap = NULL;
439
0
  bitmap = (gdiBitmap*)calloc(1, sizeof(gdiBitmap));
440
441
0
  if (!bitmap)
442
0
    goto fail_bitmap;
443
444
0
  if (!(bitmap->hdc = gdi_CreateCompatibleDC(gdi->hdc)))
445
0
    goto fail_hdc;
446
447
0
  WLog_Print(gdi->log, WLOG_DEBUG, "gdi_bitmap_new: width:%d height:%d bpp:%d", width, height,
448
0
             bpp);
449
450
0
  if (!data)
451
0
    bitmap->bitmap =
452
0
        gdi_CreateCompatibleBitmap(gdi->hdc, WINPR_ASSERTING_INT_CAST(uint32_t, width),
453
0
                                   WINPR_ASSERTING_INT_CAST(uint32_t, height));
454
0
  else
455
0
    bitmap->bitmap = gdi_create_bitmap(gdi, WINPR_ASSERTING_INT_CAST(uint32_t, width),
456
0
                                       WINPR_ASSERTING_INT_CAST(uint32_t, height),
457
0
                                       WINPR_ASSERTING_INT_CAST(uint32_t, bpp), data);
458
459
0
  if (!bitmap->bitmap)
460
0
    goto fail_bitmap_bitmap;
461
462
0
  gdi_SelectObject(bitmap->hdc, (HGDIOBJECT)bitmap->bitmap);
463
0
  bitmap->org_bitmap = NULL;
464
0
  return bitmap;
465
0
fail_bitmap_bitmap:
466
0
  gdi_DeleteDC(bitmap->hdc);
467
0
fail_hdc:
468
0
  free(bitmap);
469
0
fail_bitmap:
470
0
  return NULL;
471
0
}
472
473
void gdi_bitmap_free_ex(gdiBitmap* bitmap)
474
0
{
475
0
  if (bitmap)
476
0
  {
477
0
    gdi_SelectObject(bitmap->hdc, (HGDIOBJECT)bitmap->org_bitmap);
478
0
    gdi_DeleteObject((HGDIOBJECT)bitmap->bitmap);
479
0
    gdi_DeleteDC(bitmap->hdc);
480
0
    free(bitmap);
481
0
  }
482
0
}
483
484
BOOL gdi_bitmap_update(rdpContext* context, const BITMAP_UPDATE* bitmapUpdate)
485
0
{
486
0
  if (!context || !bitmapUpdate || !context->gdi || !context->codecs)
487
0
  {
488
0
    WLog_ERR(TAG,
489
0
             "Invalid arguments: context=%p, bitmapUpdate=%p, context->gdi=%p, "
490
0
             "context->codecs=%p",
491
0
             context, bitmapUpdate, context ? context->gdi : NULL,
492
0
             context ? context->codecs : NULL);
493
0
    return FALSE;
494
0
  }
495
496
0
  for (UINT32 index = 0; index < bitmapUpdate->number; index++)
497
0
  {
498
0
    BOOL rc = FALSE;
499
0
    const BITMAP_DATA* bitmap = &(bitmapUpdate->rectangles[index]);
500
0
    rdpBitmap* bmp = Bitmap_Alloc(context);
501
502
0
    if (!bmp)
503
0
      goto fail;
504
505
0
    if (!Bitmap_SetDimensions(bmp, WINPR_ASSERTING_INT_CAST(UINT16, bitmap->width),
506
0
                              WINPR_ASSERTING_INT_CAST(UINT16, bitmap->height)))
507
0
      goto fail;
508
509
0
    if (!Bitmap_SetRectangle(bmp, WINPR_ASSERTING_INT_CAST(UINT16, bitmap->destLeft),
510
0
                             WINPR_ASSERTING_INT_CAST(UINT16, bitmap->destTop),
511
0
                             WINPR_ASSERTING_INT_CAST(UINT16, bitmap->destRight),
512
0
                             WINPR_ASSERTING_INT_CAST(UINT16, bitmap->destBottom)))
513
0
      goto fail;
514
515
0
    if (!bmp->Decompress(context, bmp, bitmap->bitmapDataStream, bitmap->width, bitmap->height,
516
0
                         bitmap->bitsPerPixel, bitmap->bitmapLength, bitmap->compressed,
517
0
                         RDP_CODEC_ID_NONE))
518
0
      goto fail;
519
520
0
    if (!bmp->New(context, bmp))
521
0
      goto fail;
522
523
0
    if (!bmp->Paint(context, bmp))
524
0
      goto fail;
525
526
0
    rc = TRUE;
527
0
  fail:
528
0
    Bitmap_Free(context, bmp);
529
0
    if (!rc)
530
0
      return FALSE;
531
0
  }
532
533
0
  return TRUE;
534
0
}
535
536
static BOOL gdi_palette_update(rdpContext* context, const PALETTE_UPDATE* palette)
537
0
{
538
0
  rdpGdi* gdi = NULL;
539
540
0
  if (!context || !palette)
541
0
    return FALSE;
542
543
0
  gdi = context->gdi;
544
0
  gdi->palette.format = gdi->dstFormat;
545
546
0
  for (UINT32 index = 0; index < palette->number; index++)
547
0
  {
548
0
    const PALETTE_ENTRY* pe = &(palette->entries[index]);
549
0
    gdi->palette.palette[index] =
550
0
        FreeRDPGetColor(gdi->dstFormat, pe->red, pe->green, pe->blue, 0xFF);
551
0
  }
552
553
0
  return TRUE;
554
0
}
555
556
static BOOL gdi_set_bounds(rdpContext* context, const rdpBounds* bounds)
557
0
{
558
0
  rdpGdi* gdi = NULL;
559
560
0
  if (!context)
561
0
    return FALSE;
562
563
0
  gdi = context->gdi;
564
565
0
  if (bounds)
566
0
  {
567
0
    gdi_SetClipRgn(gdi->drawing->hdc, bounds->left, bounds->top,
568
0
                   bounds->right - bounds->left + 1, bounds->bottom - bounds->top + 1);
569
0
  }
570
0
  else
571
0
    gdi_SetNullClipRgn(gdi->drawing->hdc);
572
573
0
  return TRUE;
574
0
}
575
576
static BOOL gdi_dstblt(rdpContext* context, const DSTBLT_ORDER* dstblt)
577
0
{
578
0
  rdpGdi* gdi = NULL;
579
580
0
  if (!context || !dstblt)
581
0
    return FALSE;
582
583
0
  gdi = context->gdi;
584
0
  return gdi_BitBlt(gdi->drawing->hdc, dstblt->nLeftRect, dstblt->nTopRect, dstblt->nWidth,
585
0
                    dstblt->nHeight, NULL, 0, 0, gdi_rop3_code_checked(dstblt->bRop),
586
0
                    &gdi->palette);
587
0
}
588
589
static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
590
0
{
591
0
  const rdpBrush* brush = &patblt->brush;
592
0
  UINT32 foreColor = 0;
593
0
  UINT32 backColor = 0;
594
0
  UINT32 originalColor = 0;
595
0
  HGDI_BRUSH originalBrush = NULL;
596
0
  HGDI_BRUSH hbrush = NULL;
597
0
  rdpGdi* gdi = context->gdi;
598
0
  BOOL ret = FALSE;
599
0
  const DWORD rop = gdi_rop3_code_checked(patblt->bRop);
600
0
  INT32 nXSrc = 0;
601
0
  INT32 nYSrc = 0;
602
0
  BYTE data[8 * 8 * 4];
603
0
  HGDI_BITMAP hBmp = NULL;
604
605
0
  if (!gdi_decode_color(gdi, patblt->foreColor, &foreColor, NULL))
606
0
    return FALSE;
607
608
0
  if (!gdi_decode_color(gdi, patblt->backColor, &backColor, NULL))
609
0
    return FALSE;
610
611
0
  originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
612
0
  originalBrush = gdi->drawing->hdc->brush;
613
614
0
  switch (brush->style)
615
0
  {
616
0
    case GDI_BS_SOLID:
617
0
      hbrush = gdi_CreateSolidBrush(foreColor);
618
0
      break;
619
620
0
    case GDI_BS_HATCHED:
621
0
    {
622
0
      const BYTE* hatched = NULL;
623
0
      hatched = GDI_BS_HATCHED_PATTERNS + (8ULL * brush->hatch);
624
625
0
      if (!freerdp_image_copy_from_monochrome(data, gdi->drawing->hdc->format, 0, 0, 0, 8, 8,
626
0
                                              hatched, backColor, foreColor, &gdi->palette))
627
0
        goto out_error;
628
629
0
      hBmp = gdi_CreateBitmapEx(8, 8, gdi->drawing->hdc->format, 0, data, NULL);
630
631
0
      if (!hBmp)
632
0
        goto out_error;
633
634
0
      hbrush = gdi_CreateHatchBrush(hBmp);
635
0
    }
636
0
    break;
637
638
0
    case GDI_BS_PATTERN:
639
0
    {
640
0
      UINT32 brushFormat = 0;
641
642
0
      if (brush->bpp > 1)
643
0
      {
644
0
        UINT32 bpp = brush->bpp;
645
646
0
        if ((bpp == 16) &&
647
0
            (freerdp_settings_get_uint32(context->settings, FreeRDP_ColorDepth) == 15))
648
0
          bpp = 15;
649
650
0
        brushFormat = gdi_get_pixel_format(bpp);
651
652
0
        if (!freerdp_image_copy_no_overlap(data, gdi->drawing->hdc->format, 0, 0, 0, 8, 8,
653
0
                                           brush->data, brushFormat, 0, 0, 0, &gdi->palette,
654
0
                                           FREERDP_FLIP_NONE))
655
0
          goto out_error;
656
0
      }
657
0
      else
658
0
      {
659
0
        if (!freerdp_image_copy_from_monochrome(data, gdi->drawing->hdc->format, 0, 0, 0, 8,
660
0
                                                8, brush->data, backColor, foreColor,
661
0
                                                &gdi->palette))
662
0
          goto out_error;
663
0
      }
664
665
0
      hBmp = gdi_CreateBitmapEx(8, 8, gdi->drawing->hdc->format, 0, data, NULL);
666
667
0
      if (!hBmp)
668
0
        goto out_error;
669
670
0
      hbrush = gdi_CreatePatternBrush(hBmp);
671
0
    }
672
0
    break;
673
674
0
    default:
675
0
      WLog_ERR(TAG, "unimplemented brush style:%" PRIu32 "", brush->style);
676
0
      break;
677
0
  }
678
679
0
  if (hbrush)
680
0
  {
681
0
    hbrush->nXOrg = WINPR_ASSERTING_INT_CAST(int32_t, brush->x);
682
0
    hbrush->nYOrg = WINPR_ASSERTING_INT_CAST(int32_t, brush->y);
683
0
    gdi->drawing->hdc->brush = hbrush;
684
0
    ret = gdi_BitBlt(gdi->drawing->hdc, patblt->nLeftRect, patblt->nTopRect, patblt->nWidth,
685
0
                     patblt->nHeight, gdi->primary->hdc, nXSrc, nYSrc, rop, &gdi->palette);
686
0
  }
687
688
0
out_error:
689
0
  gdi_DeleteObject((HGDIOBJECT)hBmp);
690
0
  gdi_DeleteObject((HGDIOBJECT)hbrush);
691
0
  gdi->drawing->hdc->brush = originalBrush;
692
0
  gdi_SetTextColor(gdi->drawing->hdc, originalColor);
693
0
  return ret;
694
0
}
695
696
static BOOL gdi_scrblt(rdpContext* context, const SCRBLT_ORDER* scrblt)
697
0
{
698
0
  rdpGdi* gdi = NULL;
699
700
0
  if (!context || !context->gdi)
701
0
    return FALSE;
702
703
0
  gdi = context->gdi;
704
0
  return gdi_BitBlt(gdi->drawing->hdc, scrblt->nLeftRect, scrblt->nTopRect, scrblt->nWidth,
705
0
                    scrblt->nHeight, gdi->primary->hdc, scrblt->nXSrc, scrblt->nYSrc,
706
0
                    gdi_rop3_code_checked(scrblt->bRop), &gdi->palette);
707
0
}
708
709
static BOOL gdi_opaque_rect(rdpContext* context, const OPAQUE_RECT_ORDER* opaque_rect)
710
0
{
711
0
  GDI_RECT rect;
712
0
  HGDI_BRUSH hBrush = NULL;
713
0
  UINT32 brush_color = 0;
714
0
  rdpGdi* gdi = context->gdi;
715
0
  BOOL ret = 0;
716
0
  INT32 x = opaque_rect->nLeftRect;
717
0
  INT32 y = opaque_rect->nTopRect;
718
0
  INT32 w = opaque_rect->nWidth;
719
0
  INT32 h = opaque_rect->nHeight;
720
0
  gdi_ClipCoords(gdi->drawing->hdc, &x, &y, &w, &h, NULL, NULL);
721
0
  gdi_CRgnToRect(x, y, w, h, &rect);
722
723
0
  if (!gdi_decode_color(gdi, opaque_rect->color, &brush_color, NULL))
724
0
    return FALSE;
725
726
0
  if (!(hBrush = gdi_CreateSolidBrush(brush_color)))
727
0
    return FALSE;
728
729
0
  ret = gdi_FillRect(gdi->drawing->hdc, &rect, hBrush);
730
0
  gdi_DeleteObject((HGDIOBJECT)hBrush);
731
0
  return ret;
732
0
}
733
734
static BOOL gdi_multi_opaque_rect(rdpContext* context,
735
                                  const MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect)
736
0
{
737
0
  GDI_RECT rect;
738
0
  HGDI_BRUSH hBrush = NULL;
739
0
  UINT32 brush_color = 0;
740
0
  rdpGdi* gdi = context->gdi;
741
0
  BOOL ret = TRUE;
742
743
0
  if (!gdi_decode_color(gdi, multi_opaque_rect->color, &brush_color, NULL))
744
0
    return FALSE;
745
746
0
  hBrush = gdi_CreateSolidBrush(brush_color);
747
748
0
  if (!hBrush)
749
0
    return FALSE;
750
751
0
  for (UINT32 i = 0; i < multi_opaque_rect->numRectangles; i++)
752
0
  {
753
0
    const DELTA_RECT* rectangle = &multi_opaque_rect->rectangles[i];
754
0
    INT32 x = rectangle->left;
755
0
    INT32 y = rectangle->top;
756
0
    INT32 w = rectangle->width;
757
0
    INT32 h = rectangle->height;
758
0
    gdi_ClipCoords(gdi->drawing->hdc, &x, &y, &w, &h, NULL, NULL);
759
0
    gdi_CRgnToRect(x, y, w, h, &rect);
760
0
    ret = gdi_FillRect(gdi->drawing->hdc, &rect, hBrush);
761
762
0
    if (!ret)
763
0
      break;
764
0
  }
765
766
0
  gdi_DeleteObject((HGDIOBJECT)hBrush);
767
0
  return ret;
768
0
}
769
770
static BOOL gdi_line_to(rdpContext* context, const LINE_TO_ORDER* lineTo)
771
0
{
772
0
  UINT32 color = 0;
773
0
  HGDI_PEN hPen = NULL;
774
0
  rdpGdi* gdi = context->gdi;
775
0
  INT32 xStart = lineTo->nXStart;
776
0
  INT32 yStart = lineTo->nYStart;
777
0
  INT32 xEnd = lineTo->nXEnd;
778
0
  INT32 yEnd = lineTo->nYEnd;
779
0
  INT32 w = 0;
780
0
  INT32 h = 0;
781
0
  gdi_ClipCoords(gdi->drawing->hdc, &xStart, &yStart, &w, &h, NULL, NULL);
782
0
  gdi_ClipCoords(gdi->drawing->hdc, &xEnd, &yEnd, &w, &h, NULL, NULL);
783
784
0
  if (!gdi_decode_color(gdi, lineTo->penColor, &color, NULL))
785
0
    return FALSE;
786
787
0
  if (!(hPen = gdi_CreatePen(lineTo->penStyle, lineTo->penWidth, color, gdi->drawing->hdc->format,
788
0
                             &gdi->palette)))
789
0
    return FALSE;
790
791
0
  gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT)hPen);
792
0
  gdi_SetROP2(gdi->drawing->hdc, WINPR_ASSERTING_INT_CAST(int32_t, lineTo->bRop2));
793
0
  gdi_MoveToEx(gdi->drawing->hdc, lineTo->nXStart, lineTo->nYStart, NULL);
794
0
  gdi_LineTo(gdi->drawing->hdc, lineTo->nXEnd, lineTo->nYEnd);
795
0
  gdi_DeleteObject((HGDIOBJECT)hPen);
796
0
  return TRUE;
797
0
}
798
799
static BOOL gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
800
0
{
801
0
  INT32 x = 0;
802
0
  INT32 y = 0;
803
0
  UINT32 color = 0;
804
0
  HGDI_PEN hPen = NULL;
805
0
  DELTA_POINT* points = NULL;
806
0
  rdpGdi* gdi = context->gdi;
807
0
  INT32 w = 0;
808
0
  INT32 h = 0;
809
810
0
  if (!gdi_decode_color(gdi, polyline->penColor, &color, NULL))
811
0
    return FALSE;
812
813
0
  if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 1, color, gdi->drawing->hdc->format, &gdi->palette)))
814
0
    return FALSE;
815
816
0
  gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT)hPen);
817
0
  gdi_SetROP2(gdi->drawing->hdc, WINPR_ASSERTING_INT_CAST(int32_t, polyline->bRop2));
818
0
  x = polyline->xStart;
819
0
  y = polyline->yStart;
820
0
  gdi_ClipCoords(gdi->drawing->hdc, &x, &y, &w, &h, NULL, NULL);
821
0
  gdi_MoveToEx(gdi->drawing->hdc, x, y, NULL);
822
0
  points = polyline->points;
823
824
0
  for (UINT32 i = 0; i < polyline->numDeltaEntries; i++)
825
0
  {
826
0
    x += points[i].x;
827
0
    y += points[i].y;
828
0
    gdi_ClipCoords(gdi->drawing->hdc, &x, &y, &w, &h, NULL, NULL);
829
0
    gdi_LineTo(gdi->drawing->hdc, x, y);
830
0
    gdi_MoveToEx(gdi->drawing->hdc, x, y, NULL);
831
0
  }
832
833
0
  gdi_DeleteObject((HGDIOBJECT)hPen);
834
0
  return TRUE;
835
0
}
836
837
static BOOL gdi_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
838
0
{
839
0
  gdiBitmap* bitmap = NULL;
840
0
  rdpGdi* gdi = NULL;
841
842
0
  if (!context || !memblt || !context->gdi || !memblt->bitmap)
843
0
    return FALSE;
844
845
0
  bitmap = (gdiBitmap*)memblt->bitmap;
846
0
  gdi = context->gdi;
847
0
  return gdi_BitBlt(gdi->drawing->hdc, memblt->nLeftRect, memblt->nTopRect, memblt->nWidth,
848
0
                    memblt->nHeight, bitmap->hdc, memblt->nXSrc, memblt->nYSrc,
849
0
                    gdi_rop3_code_checked(memblt->bRop), &gdi->palette);
850
0
}
851
852
static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
853
0
{
854
0
  HGDI_BRUSH originalBrush = NULL;
855
0
  rdpGdi* gdi = context->gdi;
856
0
  BOOL ret = TRUE;
857
0
  const rdpBrush* brush = &mem3blt->brush;
858
0
  gdiBitmap* bitmap = (gdiBitmap*)mem3blt->bitmap;
859
0
  UINT32 foreColor = 0;
860
0
  UINT32 backColor = 0;
861
0
  UINT32 originalColor = 0;
862
863
0
  if (!gdi_decode_color(gdi, mem3blt->foreColor, &foreColor, NULL))
864
0
    return FALSE;
865
866
0
  if (!gdi_decode_color(gdi, mem3blt->backColor, &backColor, NULL))
867
0
    return FALSE;
868
869
0
  originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
870
871
0
  switch (brush->style)
872
0
  {
873
0
    case GDI_BS_SOLID:
874
0
      originalBrush = gdi->drawing->hdc->brush;
875
0
      gdi->drawing->hdc->brush = gdi_CreateSolidBrush(foreColor);
876
877
0
      if (!gdi->drawing->hdc->brush)
878
0
      {
879
0
        ret = FALSE;
880
0
        goto out_fail;
881
0
      }
882
883
0
      ret = gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
884
0
                       mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc, mem3blt->nXSrc,
885
0
                       mem3blt->nYSrc, gdi_rop3_code_checked(mem3blt->bRop), &gdi->palette);
886
0
      gdi_DeleteObject((HGDIOBJECT)gdi->drawing->hdc->brush);
887
0
      gdi->drawing->hdc->brush = originalBrush;
888
0
      break;
889
890
0
    case GDI_BS_PATTERN:
891
0
    {
892
0
      HGDI_BITMAP hBmp = NULL;
893
0
      UINT32 brushFormat = 0;
894
0
      BYTE* data = (BYTE*)winpr_aligned_malloc(
895
0
          8ULL * 8ULL * FreeRDPGetBytesPerPixel(gdi->drawing->hdc->format), 16);
896
897
0
      if (!data)
898
0
      {
899
0
        ret = FALSE;
900
0
        goto out_fail;
901
0
      }
902
903
0
      if (brush->bpp > 1)
904
0
      {
905
0
        UINT32 bpp = brush->bpp;
906
907
0
        const UINT32 ColorDepth =
908
0
            freerdp_settings_get_uint32(gdi->context->settings, FreeRDP_ColorDepth);
909
0
        if ((bpp == 16) && (ColorDepth == 15))
910
0
          bpp = 15;
911
912
0
        brushFormat = gdi_get_pixel_format(bpp);
913
914
0
        if (!freerdp_image_copy_no_overlap(data, gdi->drawing->hdc->format, 0, 0, 0, 8, 8,
915
0
                                           brush->data, brushFormat, 0, 0, 0, &gdi->palette,
916
0
                                           FREERDP_FLIP_NONE))
917
0
        {
918
0
          ret = FALSE;
919
0
          winpr_aligned_free(data);
920
0
          goto out_fail;
921
0
        }
922
0
      }
923
0
      else
924
0
      {
925
0
        if (!freerdp_image_copy_from_monochrome(data, gdi->drawing->hdc->format, 0, 0, 0, 8,
926
0
                                                8, brush->data, backColor, foreColor,
927
0
                                                &gdi->palette))
928
0
        {
929
0
          ret = FALSE;
930
0
          winpr_aligned_free(data);
931
0
          goto out_fail;
932
0
        }
933
0
      }
934
935
0
      hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data);
936
937
0
      if (!hBmp)
938
0
      {
939
0
        ret = FALSE;
940
0
        winpr_aligned_free(data);
941
0
        goto out_fail;
942
0
      }
943
944
0
      originalBrush = gdi->drawing->hdc->brush;
945
0
      gdi->drawing->hdc->brush = gdi_CreatePatternBrush(hBmp);
946
947
0
      if (!gdi->drawing->hdc->brush)
948
0
      {
949
0
        gdi_DeleteObject((HGDIOBJECT)hBmp);
950
0
        goto out_fail;
951
0
      }
952
953
0
      gdi->drawing->hdc->brush->nXOrg = WINPR_ASSERTING_INT_CAST(int32_t, brush->x);
954
0
      gdi->drawing->hdc->brush->nYOrg = WINPR_ASSERTING_INT_CAST(int32_t, brush->y);
955
0
      ret = gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
956
0
                       mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc, mem3blt->nXSrc,
957
0
                       mem3blt->nYSrc, gdi_rop3_code_checked(mem3blt->bRop), &gdi->palette);
958
0
      gdi_DeleteObject((HGDIOBJECT)gdi->drawing->hdc->brush);
959
0
      gdi_DeleteObject((HGDIOBJECT)hBmp);
960
0
      gdi->drawing->hdc->brush = originalBrush;
961
0
    }
962
0
    break;
963
964
0
    default:
965
0
      WLog_ERR(TAG, "Mem3Blt unimplemented brush style:%" PRIu32 "", brush->style);
966
0
      break;
967
0
  }
968
969
0
out_fail:
970
0
  gdi_SetTextColor(gdi->drawing->hdc, originalColor);
971
0
  return ret;
972
0
}
973
974
static BOOL gdi_polygon_sc(WINPR_ATTR_UNUSED rdpContext* context,
975
                           WINPR_ATTR_UNUSED const POLYGON_SC_ORDER* polygon_sc)
976
0
{
977
0
  WLog_WARN(TAG, "not implemented");
978
0
  return FALSE;
979
0
}
980
981
static BOOL gdi_polygon_cb(WINPR_ATTR_UNUSED rdpContext* context,
982
                           WINPR_ATTR_UNUSED POLYGON_CB_ORDER* polygon_cb)
983
0
{
984
0
  WLog_WARN(TAG, "not implemented");
985
0
  return FALSE;
986
0
}
987
988
static BOOL gdi_ellipse_sc(WINPR_ATTR_UNUSED rdpContext* context,
989
                           WINPR_ATTR_UNUSED const ELLIPSE_SC_ORDER* ellipse_sc)
990
0
{
991
0
  WLog_WARN(TAG, "not implemented");
992
0
  return FALSE;
993
0
}
994
995
static BOOL gdi_ellipse_cb(WINPR_ATTR_UNUSED rdpContext* context,
996
                           WINPR_ATTR_UNUSED const ELLIPSE_CB_ORDER* ellipse_cb)
997
0
{
998
0
  WLog_WARN(TAG, "not implemented");
999
0
  return FALSE;
1000
0
}
1001
1002
static BOOL gdi_frame_marker(WINPR_ATTR_UNUSED rdpContext* context,
1003
                             WINPR_ATTR_UNUSED const FRAME_MARKER_ORDER* frameMarker)
1004
0
{
1005
0
  return TRUE;
1006
0
}
1007
1008
static BOOL gdi_surface_frame_marker(rdpContext* context,
1009
                                     const SURFACE_FRAME_MARKER* surfaceFrameMarker)
1010
0
{
1011
0
  WLog_Print(context->gdi->log, WLOG_DEBUG, "frameId %" PRIu32 " frameAction %" PRIu32 "",
1012
0
             surfaceFrameMarker->frameId, surfaceFrameMarker->frameAction);
1013
1014
0
  switch (surfaceFrameMarker->frameAction)
1015
0
  {
1016
0
    case SURFACECMD_FRAMEACTION_BEGIN:
1017
0
      break;
1018
1019
0
    case SURFACECMD_FRAMEACTION_END:
1020
0
      if (freerdp_settings_get_uint32(context->settings, FreeRDP_FrameAcknowledge) > 0)
1021
0
      {
1022
0
        IFCALL(context->update->SurfaceFrameAcknowledge, context,
1023
0
               surfaceFrameMarker->frameId);
1024
0
      }
1025
1026
0
      break;
1027
0
    default:
1028
0
      break;
1029
0
  }
1030
1031
0
  return TRUE;
1032
0
}
1033
1034
static BOOL intersect_rect(const rdpGdi* gdi, const SURFACE_BITS_COMMAND* cmd, RECTANGLE_16* prect)
1035
0
{
1036
0
  const UINT32 w = (const UINT32)gdi->width;
1037
0
  const UINT32 h = (const UINT32)gdi->height;
1038
1039
0
  if (cmd->destLeft > w)
1040
0
    return FALSE;
1041
0
  if (cmd->destRight > w)
1042
0
    return FALSE;
1043
0
  if (cmd->destLeft > cmd->destRight)
1044
0
    return FALSE;
1045
0
  if (cmd->destRight > UINT16_MAX)
1046
0
    return FALSE;
1047
1048
0
  if (cmd->destTop > h)
1049
0
    return FALSE;
1050
0
  if (cmd->destBottom > h)
1051
0
    return FALSE;
1052
0
  if (cmd->destTop > cmd->destBottom)
1053
0
    return FALSE;
1054
0
  if (cmd->destBottom > UINT16_MAX)
1055
0
    return FALSE;
1056
1057
0
  prect->left = (const UINT16)cmd->destLeft;
1058
0
  prect->top = (const UINT16)cmd->destTop;
1059
0
  prect->right = MIN((UINT16)cmd->destRight, prect->left + cmd->bmp.width);
1060
0
  prect->bottom = MIN((UINT16)cmd->destBottom, prect->top + cmd->bmp.height);
1061
0
  return TRUE;
1062
0
}
1063
1064
static BOOL gdi_surface_bits(rdpContext* context, const SURFACE_BITS_COMMAND* cmd)
1065
0
{
1066
0
  BOOL result = FALSE;
1067
0
  DWORD format = 0;
1068
0
  rdpGdi* gdi = NULL;
1069
0
  size_t size = 0;
1070
0
  REGION16 region;
1071
0
  RECTANGLE_16 cmdRect = { 0 };
1072
1073
0
  if (!context || !cmd)
1074
0
    return FALSE;
1075
1076
0
  gdi = context->gdi;
1077
0
  WLog_Print(gdi->log, WLOG_DEBUG,
1078
0
             "destLeft %" PRIu32 " destTop %" PRIu32 " destRight %" PRIu32 " destBottom %" PRIu32
1079
0
             " "
1080
0
             "bpp %" PRIu8 " flags %" PRIx8 " codecID %s [0x%04" PRIu16 "] width %" PRIu16
1081
0
             " height %" PRIu16 " length %" PRIu32 "",
1082
0
             cmd->destLeft, cmd->destTop, cmd->destRight, cmd->destBottom, cmd->bmp.bpp,
1083
0
             cmd->bmp.flags, freerdp_codec_id_to_str(cmd->bmp.codecID), cmd->bmp.codecID,
1084
0
             cmd->bmp.width, cmd->bmp.height, cmd->bmp.bitmapDataLength);
1085
0
  region16_init(&region);
1086
1087
0
  if (!intersect_rect(gdi, cmd, &cmdRect))
1088
0
    goto out;
1089
1090
0
  switch (cmd->bmp.codecID)
1091
0
  {
1092
0
    case RDP_CODEC_ID_REMOTEFX:
1093
0
    case RDP_CODEC_ID_IMAGE_REMOTEFX:
1094
0
      if (!rfx_process_message(context->codecs->rfx, cmd->bmp.bitmapData,
1095
0
                               cmd->bmp.bitmapDataLength, cmdRect.left, cmdRect.top,
1096
0
                               gdi->primary_buffer, gdi->dstFormat, gdi->stride,
1097
0
                               WINPR_ASSERTING_INT_CAST(uint32_t, gdi->height), &region))
1098
0
      {
1099
0
        WLog_ERR(TAG, "Failed to process RemoteFX message");
1100
0
        goto out;
1101
0
      }
1102
1103
0
      break;
1104
1105
0
    case RDP_CODEC_ID_NSCODEC:
1106
0
      format = gdi->dstFormat;
1107
1108
0
      if (!nsc_process_message(
1109
0
              context->codecs->nsc, cmd->bmp.bpp, cmd->bmp.width, cmd->bmp.height,
1110
0
              cmd->bmp.bitmapData, cmd->bmp.bitmapDataLength, gdi->primary_buffer, format,
1111
0
              gdi->stride, cmdRect.left, cmdRect.top, cmdRect.right - cmdRect.left,
1112
0
              cmdRect.bottom - cmdRect.top, FREERDP_FLIP_VERTICAL))
1113
0
      {
1114
0
        WLog_ERR(TAG, "Failed to process NSCodec message");
1115
0
        goto out;
1116
0
      }
1117
1118
0
      region16_union_rect(&region, &region, &cmdRect);
1119
0
      break;
1120
1121
0
    case RDP_CODEC_ID_NONE:
1122
0
      format = gdi_get_pixel_format(cmd->bmp.bpp);
1123
0
      size = 1ull * cmd->bmp.width * cmd->bmp.height * FreeRDPGetBytesPerPixel(format);
1124
0
      if (size > cmd->bmp.bitmapDataLength)
1125
0
      {
1126
0
        WLog_ERR(TAG, "Short nocodec message: got %" PRIu32 " bytes, require %" PRIuz,
1127
0
                 cmd->bmp.bitmapDataLength, size);
1128
0
        goto out;
1129
0
      }
1130
1131
0
      if (!freerdp_image_copy_no_overlap(
1132
0
              gdi->primary_buffer, gdi->dstFormat, gdi->stride, cmdRect.left, cmdRect.top,
1133
0
              cmdRect.right - cmdRect.left, cmdRect.bottom - cmdRect.top, cmd->bmp.bitmapData,
1134
0
              format, 0, 0, 0, &gdi->palette, FREERDP_FLIP_VERTICAL))
1135
0
      {
1136
0
        WLog_ERR(TAG, "Failed to process nocodec message");
1137
0
        goto out;
1138
0
      }
1139
1140
0
      region16_union_rect(&region, &region, &cmdRect);
1141
0
      break;
1142
1143
0
    default:
1144
0
      WLog_ERR(TAG, "Unsupported codecID %" PRIu32 "", cmd->bmp.codecID);
1145
0
      break;
1146
0
  }
1147
1148
0
  UINT32 nbRects = 0;
1149
0
  const RECTANGLE_16* rects = region16_rects(&region, &nbRects);
1150
0
  if (!rects && (nbRects > 0))
1151
0
    goto out;
1152
1153
0
  if (nbRects == 0)
1154
0
  {
1155
0
    const int32_t w = cmdRect.right - cmdRect.left;
1156
0
    const int32_t h = cmdRect.bottom - cmdRect.top;
1157
0
    if (!gdi_InvalidateRegion(gdi->primary->hdc, cmdRect.left, cmdRect.top, w, h))
1158
0
      goto out;
1159
0
  }
1160
0
  for (UINT32 i = 0; i < nbRects; i++)
1161
0
  {
1162
0
    const RECTANGLE_16* rect = &rects[i];
1163
1164
0
    UINT32 left = rect->left;
1165
0
    UINT32 top = rect->top;
1166
0
    UINT32 width = rect->right - rect->left;
1167
0
    UINT32 height = rect->bottom - rect->top;
1168
1169
0
    if (!gdi_InvalidateRegion(gdi->primary->hdc, WINPR_ASSERTING_INT_CAST(int32_t, left),
1170
0
                              WINPR_ASSERTING_INT_CAST(int32_t, top),
1171
0
                              WINPR_ASSERTING_INT_CAST(int32_t, width),
1172
0
                              WINPR_ASSERTING_INT_CAST(int32_t, height)))
1173
0
    {
1174
0
      WLog_ERR(TAG, "Failed to update invalid region");
1175
0
      goto out;
1176
0
    }
1177
0
  }
1178
1179
0
  result = TRUE;
1180
0
out:
1181
0
  region16_uninit(&region);
1182
0
  return result;
1183
0
}
1184
1185
/**
1186
 * Register GDI callbacks with libfreerdp-core.
1187
 * @param update current instance
1188
 */
1189
1190
static void gdi_register_update_callbacks(rdpUpdate* update)
1191
0
{
1192
0
  rdpPrimaryUpdate* primary = NULL;
1193
0
  const rdpSettings* settings = NULL;
1194
1195
0
  WINPR_ASSERT(update);
1196
0
  WINPR_ASSERT(update->context);
1197
1198
0
  settings = update->context->settings;
1199
0
  WINPR_ASSERT(settings);
1200
1201
0
  primary = update->primary;
1202
0
  WINPR_ASSERT(primary);
1203
1204
0
  if (freerdp_settings_get_bool(settings, FreeRDP_DeactivateClientDecoding))
1205
0
    return;
1206
0
  update->Palette = gdi_palette_update;
1207
0
  update->SetBounds = gdi_set_bounds;
1208
0
  primary->DstBlt = gdi_dstblt;
1209
0
  primary->PatBlt = gdi_patblt;
1210
0
  primary->ScrBlt = gdi_scrblt;
1211
0
  primary->OpaqueRect = gdi_opaque_rect;
1212
0
  primary->DrawNineGrid = NULL;
1213
0
  primary->MultiDstBlt = NULL;
1214
0
  primary->MultiPatBlt = NULL;
1215
0
  primary->MultiScrBlt = NULL;
1216
0
  primary->MultiOpaqueRect = gdi_multi_opaque_rect;
1217
0
  primary->MultiDrawNineGrid = NULL;
1218
0
  primary->LineTo = gdi_line_to;
1219
0
  primary->Polyline = gdi_polyline;
1220
0
  primary->MemBlt = gdi_memblt;
1221
0
  primary->Mem3Blt = gdi_mem3blt;
1222
0
  primary->SaveBitmap = NULL;
1223
0
  primary->GlyphIndex = NULL;
1224
0
  primary->FastIndex = NULL;
1225
0
  primary->FastGlyph = NULL;
1226
0
  primary->PolygonSC = gdi_polygon_sc;
1227
0
  primary->PolygonCB = gdi_polygon_cb;
1228
0
  primary->EllipseSC = gdi_ellipse_sc;
1229
0
  primary->EllipseCB = gdi_ellipse_cb;
1230
0
  update->SurfaceBits = gdi_surface_bits;
1231
0
  update->SurfaceFrameMarker = gdi_surface_frame_marker;
1232
0
  update->altsec->FrameMarker = gdi_frame_marker;
1233
0
}
1234
1235
static BOOL gdi_init_primary(rdpGdi* gdi, UINT32 stride, UINT32 format, BYTE* buffer,
1236
                             void (*pfree)(void*), BOOL isLocked)
1237
0
{
1238
0
  WINPR_ASSERT(gdi);
1239
0
  WINPR_ASSERT(gdi->context);
1240
0
  WINPR_ASSERT(gdi->context->update);
1241
0
  if (!isLocked)
1242
0
    rdp_update_lock(gdi->context->update);
1243
1244
0
  gdi->primary = (gdiBitmap*)calloc(1, sizeof(gdiBitmap));
1245
1246
0
  if (format > 0)
1247
0
    gdi->dstFormat = format;
1248
1249
0
  if (stride > 0)
1250
0
    gdi->stride = stride;
1251
0
  else
1252
0
    gdi->stride = WINPR_ASSERTING_INT_CAST(uint32_t, gdi->width) *
1253
0
                  FreeRDPGetBytesPerPixel(gdi->dstFormat);
1254
1255
0
  if (!gdi->primary)
1256
0
    goto fail_primary;
1257
1258
0
  if (!(gdi->primary->hdc = gdi_CreateCompatibleDC(gdi->hdc)))
1259
0
    goto fail_hdc;
1260
1261
0
  if (!buffer)
1262
0
  {
1263
0
    gdi->primary->bitmap =
1264
0
        gdi_CreateCompatibleBitmap(gdi->hdc, WINPR_ASSERTING_INT_CAST(uint32_t, gdi->width),
1265
0
                                   WINPR_ASSERTING_INT_CAST(uint32_t, gdi->height));
1266
0
  }
1267
0
  else
1268
0
  {
1269
0
    gdi->primary->bitmap = gdi_CreateBitmapEx(WINPR_ASSERTING_INT_CAST(uint32_t, gdi->width),
1270
0
                                              WINPR_ASSERTING_INT_CAST(uint32_t, gdi->height),
1271
0
                                              gdi->dstFormat, gdi->stride, buffer, pfree);
1272
0
  }
1273
1274
0
  if (!gdi->primary->bitmap)
1275
0
    goto fail_bitmap;
1276
1277
0
  gdi->stride = gdi->primary->bitmap->scanline;
1278
0
  gdi_SelectObject(gdi->primary->hdc, (HGDIOBJECT)gdi->primary->bitmap);
1279
0
  gdi->primary->org_bitmap = NULL;
1280
0
  gdi->primary_buffer = gdi->primary->bitmap->data;
1281
1282
0
  if (!(gdi->primary->hdc->hwnd = (HGDI_WND)calloc(1, sizeof(GDI_WND))))
1283
0
    goto fail_hwnd;
1284
1285
0
  if (!(gdi->primary->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0)))
1286
0
    goto fail_hwnd;
1287
1288
0
  gdi->primary->hdc->hwnd->invalid->null = TRUE;
1289
0
  gdi->primary->hdc->hwnd->count = 32;
1290
1291
0
  if (!(gdi->primary->hdc->hwnd->cinvalid =
1292
0
            (GDI_RGN*)calloc(gdi->primary->hdc->hwnd->count, sizeof(GDI_RGN))))
1293
0
    goto fail_hwnd;
1294
1295
0
  gdi->primary->hdc->hwnd->ninvalid = 0;
1296
1297
0
  if (!gdi->drawing)
1298
0
    gdi->drawing = gdi->primary;
1299
1300
0
  rdp_update_unlock(gdi->context->update);
1301
0
  return TRUE;
1302
0
fail_hwnd:
1303
0
  gdi_DeleteObject((HGDIOBJECT)gdi->primary->bitmap);
1304
0
fail_bitmap:
1305
0
  gdi_DeleteDC(gdi->primary->hdc);
1306
0
fail_hdc:
1307
0
  free(gdi->primary);
1308
0
  gdi->primary = NULL;
1309
0
fail_primary:
1310
0
  rdp_update_unlock(gdi->context->update);
1311
0
  return FALSE;
1312
0
}
1313
1314
BOOL gdi_resize(rdpGdi* gdi, UINT32 width, UINT32 height)
1315
0
{
1316
0
  return gdi_resize_ex(gdi, width, height, 0, 0, NULL, NULL);
1317
0
}
1318
1319
BOOL gdi_resize_ex(rdpGdi* gdi, UINT32 width, UINT32 height, UINT32 stride, UINT32 format,
1320
                   BYTE* buffer, void (*pfree)(void*))
1321
0
{
1322
0
  if (!gdi || !gdi->primary)
1323
0
    return FALSE;
1324
1325
0
  if ((width > INT32_MAX) || (height > INT32_MAX))
1326
0
    return FALSE;
1327
1328
0
  if ((gdi->width == (INT32)width) && (gdi->height == (INT32)height) &&
1329
0
      (!buffer || (gdi->primary_buffer == buffer)))
1330
0
    return TRUE;
1331
1332
0
  WINPR_ASSERT(gdi->context);
1333
0
  WINPR_ASSERT(gdi->context->update);
1334
1335
  /* EndPaint might not have been called, ensure the update lock is released */
1336
0
  if (!update_end_paint(gdi->context->update))
1337
0
    return FALSE;
1338
0
  rdp_update_lock(gdi->context->update);
1339
1340
0
  if (gdi->drawing == gdi->primary)
1341
0
    gdi->drawing = NULL;
1342
1343
0
  gdi->width = (INT32)width;
1344
0
  gdi->height = (INT32)height;
1345
0
  gdi_bitmap_free_ex(gdi->primary);
1346
0
  gdi->primary = NULL;
1347
0
  gdi->primary_buffer = NULL;
1348
0
  return gdi_init_primary(gdi, stride, format, buffer, pfree, TRUE);
1349
0
}
1350
1351
/**
1352
 * Initialize GDI
1353
 *
1354
 * @param instance A pointer to the instance to use
1355
 * @param format The color format for the local framebuffer
1356
 * @return \b TRUE for success, \b FALSE for failure
1357
 */
1358
BOOL gdi_init(freerdp* instance, UINT32 format)
1359
0
{
1360
0
  return gdi_init_ex(instance, format, 0, NULL, winpr_aligned_free);
1361
0
}
1362
1363
/**
1364
 * Initialize GDI
1365
 *
1366
 * @param instance A pointer to the instance to use
1367
 * @param format The color format for the local framebuffer
1368
 * @param stride The size of a framebuffer line in bytes
1369
 * @param buffer A pointer to a buffer to be used as framebuffer
1370
 * @param pfree A custom function pointer to use to free the framebuffer
1371
 *
1372
 * @return \b TRUE for success, \b FALSE for failure
1373
 */
1374
BOOL gdi_init_ex(freerdp* instance, UINT32 format, UINT32 stride, BYTE* buffer,
1375
                 void (*pfree)(void*))
1376
0
{
1377
0
  rdpContext* context = NULL;
1378
0
  UINT32 SrcFormat = 0;
1379
0
  rdpGdi* gdi = NULL;
1380
1381
0
  WINPR_ASSERT(instance);
1382
1383
0
  context = instance->context;
1384
0
  WINPR_ASSERT(context);
1385
0
  WINPR_ASSERT(context->settings);
1386
1387
0
  const UINT32 ColorDepth = freerdp_settings_get_uint32(context->settings, FreeRDP_ColorDepth);
1388
0
  SrcFormat = gdi_get_pixel_format(ColorDepth);
1389
0
  gdi = (rdpGdi*)calloc(1, sizeof(rdpGdi));
1390
1391
0
  if (!gdi)
1392
0
    goto fail;
1393
1394
0
  context->gdi = gdi;
1395
0
  gdi->log = WLog_Get(TAG);
1396
1397
0
  if (!gdi->log)
1398
0
    goto fail;
1399
1400
0
  gdi->context = context;
1401
0
  gdi->width = WINPR_ASSERTING_INT_CAST(
1402
0
      int32_t, freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopWidth));
1403
0
  gdi->height = WINPR_ASSERTING_INT_CAST(
1404
0
      int32_t, freerdp_settings_get_uint32(context->settings, FreeRDP_DesktopHeight));
1405
0
  gdi->dstFormat = format;
1406
  /* default internal buffer format */
1407
0
  WLog_Print(gdi->log, WLOG_INFO, "Local framebuffer format  %s",
1408
0
             FreeRDPGetColorFormatName(gdi->dstFormat));
1409
0
  WLog_Print(gdi->log, WLOG_INFO, "Remote framebuffer format %s",
1410
0
             FreeRDPGetColorFormatName(SrcFormat));
1411
1412
0
  if (!(gdi->hdc = gdi_GetDC()))
1413
0
    goto fail;
1414
1415
0
  gdi->hdc->format = gdi->dstFormat;
1416
1417
0
  if (!gdi_init_primary(gdi, stride, gdi->dstFormat, buffer, pfree, FALSE))
1418
0
    goto fail;
1419
1420
0
  if (!(context->cache = cache_new(context)))
1421
0
    goto fail;
1422
1423
0
  gdi_register_update_callbacks(context->update);
1424
0
  brush_cache_register_callbacks(context->update);
1425
0
  glyph_cache_register_callbacks(context->update);
1426
0
  bitmap_cache_register_callbacks(context->update);
1427
0
  offscreen_cache_register_callbacks(context->update);
1428
0
  palette_cache_register_callbacks(context->update);
1429
1430
0
  if (!gdi_register_graphics(context->graphics))
1431
0
    goto fail;
1432
1433
0
  return TRUE;
1434
0
fail:
1435
0
  gdi_free(instance);
1436
0
  WLog_ERR(TAG, "failed to initialize gdi");
1437
0
  return FALSE;
1438
0
}
1439
1440
void gdi_free(freerdp* instance)
1441
0
{
1442
0
  rdpGdi* gdi = NULL;
1443
0
  rdpContext* context = NULL;
1444
1445
0
  if (!instance || !instance->context)
1446
0
    return;
1447
1448
0
  gdi = instance->context->gdi;
1449
1450
0
  if (gdi)
1451
0
  {
1452
0
    gdi_bitmap_free_ex(gdi->primary);
1453
0
    gdi_DeleteDC(gdi->hdc);
1454
0
    free(gdi);
1455
0
  }
1456
1457
0
  context = instance->context;
1458
0
  cache_free(context->cache);
1459
0
  context->cache = NULL;
1460
0
  instance->context->gdi = (rdpGdi*)NULL;
1461
0
}
1462
1463
BOOL gdi_send_suppress_output(rdpGdi* gdi, BOOL suppress)
1464
0
{
1465
0
  if (!gdi || !gdi->context)
1466
0
    return FALSE;
1467
1468
0
  if (gdi->suppressOutput == suppress)
1469
0
    return TRUE;
1470
1471
0
  gdi->suppressOutput = suppress;
1472
1473
0
  rdpContext* context = gdi->context;
1474
0
  rdpSettings* settings = context->settings;
1475
0
  WINPR_ASSERT(settings);
1476
1477
0
  rdpUpdate* update = context->update;
1478
0
  WINPR_ASSERT(update);
1479
1480
0
  const UINT32 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
1481
0
  const UINT32 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
1482
1483
0
  const RECTANGLE_16 rect = { .left = 0,
1484
0
                            .top = 0,
1485
0
                            .right = WINPR_ASSERTING_INT_CAST(UINT16, w),
1486
0
                            .bottom = WINPR_ASSERTING_INT_CAST(UINT16, h) };
1487
1488
0
  WINPR_ASSERT(update->SuppressOutput);
1489
0
  return update->SuppressOutput(context, !suppress, &rect);
1490
0
}