FreeRDP
Loading...
Searching...
No Matches
gdi/gfx.c
1
22#include <freerdp/config.h>
23
24#include "../core/update.h"
25
26#include <winpr/assert.h>
27#include <winpr/cast.h>
28
29#include <freerdp/api.h>
30#include <freerdp/log.h>
31#include <freerdp/gdi/gfx.h>
32#include <freerdp/gdi/region.h>
33#include <freerdp/utils/gfx.h>
34#include <math.h>
35
36#define TAG FREERDP_TAG("gdi")
37
38static BOOL is_rect_valid(const RECTANGLE_16* rect, size_t width, size_t height)
39{
40 if (!rect)
41 return FALSE;
42 if ((rect->left > rect->right) || (rect->right > width))
43 return FALSE;
44 if ((rect->top > rect->bottom) || (rect->bottom > height))
45 return FALSE;
46 return TRUE;
47}
48
49static BOOL is_within_surface(const gdiGfxSurface* surface, const RDPGFX_SURFACE_COMMAND* cmd)
50{
51 RECTANGLE_16 rect;
52 if (!surface || !cmd)
53 return FALSE;
54 rect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
55 rect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
56 rect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
57 rect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
58 if (!is_rect_valid(&rect, surface->width, surface->height))
59 {
60 WLog_ERR(TAG,
61 "Command rect %" PRIu32 "x%" PRIu32 "-%" PRIu32 "x%" PRIu32
62 " not within bounds of %" PRIu32 "x%" PRIu32,
63 rect.left, rect.top, cmd->width, cmd->height, surface->width, surface->height);
64 return FALSE;
65 }
66 if (rect.left > surface->width)
67 return FALSE;
68 if (rect.right > surface->width)
69 return FALSE;
70 if (rect.top > surface->height)
71 return FALSE;
72 if (rect.bottom > surface->height)
73 return FALSE;
74
75 return TRUE;
76}
77
78static DWORD gfx_align_scanline(DWORD widthInBytes, DWORD alignment)
79{
80 const UINT32 align = alignment;
81 const UINT32 pad = align - (widthInBytes % alignment);
82 UINT32 scanline = widthInBytes;
83
84 if (align != pad)
85 scanline += pad;
86
87 return scanline;
88}
89
95static UINT gdi_ResetGraphics(RdpgfxClientContext* context,
96 const RDPGFX_RESET_GRAPHICS_PDU* resetGraphics)
97{
98 UINT rc = ERROR_INTERNAL_ERROR;
99 UINT16 count = 0;
100 UINT16* pSurfaceIds = nullptr;
101
102 WINPR_ASSERT(context);
103 WINPR_ASSERT(resetGraphics);
104
105 rdpGdi* gdi = (rdpGdi*)context->custom;
106 WINPR_ASSERT(gdi);
107
108 rdpUpdate* update = gdi->context->update;
109 WINPR_ASSERT(update);
110
111 rdpSettings* settings = gdi->context->settings;
112 WINPR_ASSERT(settings);
113 EnterCriticalSection(&context->mux);
114 const UINT32 DesktopWidth = resetGraphics->width;
115 const UINT32 DesktopHeight = resetGraphics->height;
116
117 WLog_DBG(TAG, "new size: %" PRIu32 "x%" PRIu32, DesktopWidth, DesktopHeight);
118
119 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, DesktopWidth))
120 goto fail;
121 if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, DesktopHeight))
122 goto fail;
123
124 if (update)
125 {
126 WINPR_ASSERT(update->DesktopResize);
127 if (!update->DesktopResize(gdi->context))
128 goto fail;
129 }
130
131 WINPR_ASSERT(context->GetSurfaceIds);
132 rc = context->GetSurfaceIds(context, &pSurfaceIds, &count);
133 if (rc != CHANNEL_RC_OK)
134 goto fail;
135
136 for (UINT32 index = 0; index < count; index++)
137 {
138 WINPR_ASSERT(context->GetSurfaceData);
139 gdiGfxSurface* surface =
140 (gdiGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
141
142 if (!surface)
143 continue;
144
145 memset(surface->data, 0xFF, (size_t)surface->scanline * surface->height);
146 region16_clear(&surface->invalidRegion);
147 }
148
149 free(pSurfaceIds);
150
151 if (!freerdp_settings_get_bool(gdi->context->settings, FreeRDP_DeactivateClientDecoding))
152 {
153 const UINT32 width = (UINT32)MAX(0, gdi->width);
154 const UINT32 height = (UINT32)MAX(0, gdi->height);
155
156 if (!freerdp_client_codecs_reset(
157 context->codecs, freerdp_settings_get_codecs_flags(settings), width, height))
158 {
159 goto fail;
160 }
161 if (!freerdp_client_codecs_reset(
162 gdi->context->codecs, freerdp_settings_get_codecs_flags(settings), width, height))
163 {
164 goto fail;
165 }
166 }
167
168 rc = CHANNEL_RC_OK;
169fail:
170 LeaveCriticalSection(&context->mux);
171 return rc;
172}
173
174static UINT gdi_OutputUpdate(rdpGdi* gdi, gdiGfxSurface* surface)
175{
176 UINT rc = ERROR_INTERNAL_ERROR;
177 UINT32 surfaceX = 0;
178 UINT32 surfaceY = 0;
179 RECTANGLE_16 surfaceRect;
180 const RECTANGLE_16* rects = nullptr;
181 UINT32 nbRects = 0;
182 rdpUpdate* update = nullptr;
183
184 WINPR_ASSERT(gdi);
185 WINPR_ASSERT(gdi->context);
186 WINPR_ASSERT(surface);
187
188 update = gdi->context->update;
189 WINPR_ASSERT(update);
190
191 if (gdi->suppressOutput)
192 return CHANNEL_RC_OK;
193
194 surfaceX = surface->outputOriginX;
195 surfaceY = surface->outputOriginY;
196 surfaceRect.left = 0;
197 surfaceRect.top = 0;
198 surfaceRect.right = (UINT16)MIN(UINT16_MAX, surface->mappedWidth);
199 surfaceRect.bottom = (UINT16)MIN(UINT16_MAX, surface->mappedHeight);
200 if (!region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion),
201 &surfaceRect))
202 goto fail;
203
204 const double sx = surface->outputTargetWidth / (double)surface->mappedWidth;
205 const double sy = surface->outputTargetHeight / (double)surface->mappedHeight;
206
207 rects = region16_rects(&surface->invalidRegion, &nbRects);
208 if (!rects || (nbRects == 0))
209 {
210 rc = CHANNEL_RC_OK;
211 goto fail;
212 }
213
214 if (!update_begin_paint(update))
215 goto fail;
216
217 for (UINT32 i = 0; i < nbRects; i++)
218 {
219 const UINT32 nXSrc = rects[i].left;
220 const UINT32 nYSrc = rects[i].top;
221 const UINT32 nXDst = (UINT32)MIN(surfaceX + nXSrc * sx, gdi->width - 1);
222 const UINT32 nYDst = (UINT32)MIN(surfaceY + nYSrc * sy, gdi->height - 1);
223 const UINT32 swidth = rects[i].right - rects[i].left;
224 const UINT32 sheight = rects[i].bottom - rects[i].top;
225 const UINT32 dwidth = MIN((UINT32)(swidth * sx), (UINT32)gdi->width - nXDst);
226 const UINT32 dheight = MIN((UINT32)(sheight * sy), (UINT32)gdi->height - nYDst);
227
228 if (!freerdp_image_scale(gdi->primary_buffer, gdi->dstFormat, gdi->stride, nXDst, nYDst,
229 dwidth, dheight, surface->data, surface->format, surface->scanline,
230 nXSrc, nYSrc, swidth, sheight))
231 {
232 rc = CHANNEL_RC_NULL_DATA;
233 goto clear;
234 }
235
236 if (!gdi_InvalidateRegion(gdi->primary->hdc, (INT32)nXDst, (INT32)nYDst, (INT32)dwidth,
237 (INT32)dheight))
238 goto clear;
239 }
240
241 rc = CHANNEL_RC_OK;
242clear:
243
244 if (!update_end_paint(update))
245 rc = ERROR_INTERNAL_ERROR;
246
247fail:
248 region16_clear(&(surface->invalidRegion));
249 return rc;
250}
251
252static UINT gdi_WindowUpdate(RdpgfxClientContext* context, gdiGfxSurface* surface)
253{
254 WINPR_ASSERT(context);
255 WINPR_ASSERT(surface);
256 return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateWindowFromSurface, context, surface);
257}
258
259static UINT gdi_UpdateSurfaces(RdpgfxClientContext* context)
260{
261 UINT16 count = 0;
262 UINT16* pSurfaceIds = nullptr;
263
264 WINPR_ASSERT(context);
265
266 rdpGdi* gdi = (rdpGdi*)context->custom;
267 WINPR_ASSERT(gdi);
268
269 EnterCriticalSection(&context->mux);
270
271 WINPR_ASSERT(context->GetSurfaceIds);
272 UINT status = context->GetSurfaceIds(context, &pSurfaceIds, &count);
273 if (status != CHANNEL_RC_OK)
274 goto fail;
275
276 for (UINT32 index = 0; index < count; index++)
277 {
278 WINPR_ASSERT(context->GetSurfaceData);
279 gdiGfxSurface* surface =
280 (gdiGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
281
282 if (!surface)
283 continue;
284
285 /* Already handled in UpdateSurfaceArea callbacks */
286 if (context->UpdateSurfaceArea)
287 {
288 if (surface->handleInUpdateSurfaceArea)
289 continue;
290 }
291
292 if (surface->outputMapped)
293 status = gdi_OutputUpdate(gdi, surface);
294 else if (surface->windowMapped)
295 status = gdi_WindowUpdate(context, surface);
296
297 if (status != CHANNEL_RC_OK)
298 break;
299 }
300
301fail:
302 free(pSurfaceIds);
303 LeaveCriticalSection(&context->mux);
304 return status;
305}
306
312static UINT gdi_StartFrame(RdpgfxClientContext* context, const RDPGFX_START_FRAME_PDU* startFrame)
313{
314 rdpGdi* gdi = nullptr;
315
316 WINPR_ASSERT(context);
317 WINPR_ASSERT(startFrame);
318
319 gdi = (rdpGdi*)context->custom;
320 WINPR_ASSERT(gdi);
321 gdi->inGfxFrame = TRUE;
322 gdi->frameId = startFrame->frameId;
323 return CHANNEL_RC_OK;
324}
325
326static UINT gdi_call_update_surfaces(RdpgfxClientContext* context)
327{
328 WINPR_ASSERT(context);
329 return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaces, context);
330}
331
337static UINT gdi_EndFrame(RdpgfxClientContext* context,
338 WINPR_ATTR_UNUSED const RDPGFX_END_FRAME_PDU* endFrame)
339{
340 WINPR_ASSERT(context);
341 WINPR_ASSERT(endFrame);
342
343 rdpGdi* gdi = (rdpGdi*)context->custom;
344 WINPR_ASSERT(gdi);
345 const UINT status = gdi_call_update_surfaces(context);
346 gdi->inGfxFrame = FALSE;
347 return status;
348}
349
350static UINT gdi_interFrameUpdate(rdpGdi* gdi, RdpgfxClientContext* context)
351{
352 WINPR_ASSERT(gdi);
353 UINT status = CHANNEL_RC_OK;
354 if (!gdi->inGfxFrame)
355 status = gdi_call_update_surfaces(context);
356 return status;
357}
358
364static UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, RdpgfxClientContext* context,
365 const RDPGFX_SURFACE_COMMAND* cmd)
366{
367 UINT status = CHANNEL_RC_OK;
368 gdiGfxSurface* surface = nullptr;
369 RECTANGLE_16 invalidRect;
370 DWORD bpp = 0;
371 size_t size = 0;
372 WINPR_ASSERT(gdi);
373 WINPR_ASSERT(context);
374 WINPR_ASSERT(cmd);
375
376 WINPR_ASSERT(context->GetSurfaceData);
377 surface =
378 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
379
380 if (!surface)
381 {
382 WLog_ERR(TAG, "unable to retrieve surfaceData for surfaceId=%" PRIu32 "", cmd->surfaceId);
383 return ERROR_NOT_FOUND;
384 }
385
386 if (!is_within_surface(surface, cmd))
387 return ERROR_INVALID_DATA;
388
389 bpp = FreeRDPGetBytesPerPixel(cmd->format);
390 size = 1ull * bpp * cmd->width * cmd->height;
391 if (cmd->length < size)
392 {
393 WLog_ERR(TAG, "Not enough data, got %" PRIu32 ", expected %" PRIuz, cmd->length, size);
394 return ERROR_INVALID_DATA;
395 }
396
397 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline, cmd->left,
398 cmd->top, cmd->width, cmd->height, cmd->data, cmd->format, 0,
399 0, 0, nullptr, FREERDP_FLIP_NONE))
400 return ERROR_INTERNAL_ERROR;
401
402 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
403 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
404 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
405 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
406 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
407 goto fail;
408 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
409 &invalidRect);
410
411 if (status != CHANNEL_RC_OK)
412 goto fail;
413
414 status = gdi_interFrameUpdate(gdi, context);
415
416fail:
417 return status;
418}
419
425static UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, RdpgfxClientContext* context,
426 const RDPGFX_SURFACE_COMMAND* cmd)
427{
428 UINT status = ERROR_INTERNAL_ERROR;
429 gdiGfxSurface* surface = nullptr;
430 REGION16 invalidRegion;
431 const RECTANGLE_16* rects = nullptr;
432 UINT32 nrRects = 0;
433 WINPR_ASSERT(gdi);
434 WINPR_ASSERT(context);
435 WINPR_ASSERT(cmd);
436
437 WINPR_ASSERT(context->GetSurfaceData);
438 surface =
439 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
440
441 if (!surface)
442 {
443 WLog_ERR(TAG, "unable to retrieve surfaceData for surfaceId=%" PRIu32 "", cmd->surfaceId);
444 return ERROR_NOT_FOUND;
445 }
446
447 if (!is_within_surface(surface, cmd))
448 return ERROR_INVALID_DATA;
449
450 WINPR_ASSERT(surface->codecs);
451 rfx_context_set_pixel_format(surface->codecs->rfx, cmd->format);
452 region16_init(&invalidRegion);
453
454 if (!rfx_process_message(surface->codecs->rfx, cmd->data, cmd->length, cmd->left, cmd->top,
455 surface->data, surface->format, surface->scanline, surface->height,
456 &invalidRegion))
457 {
458 WLog_ERR(TAG, "Failed to process RemoteFX message");
459 goto fail;
460 }
461
462 rects = region16_rects(&invalidRegion, &nrRects);
463 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
464 nrRects, rects);
465
466 if (status != CHANNEL_RC_OK)
467 goto fail;
468
469 for (UINT32 x = 0; x < nrRects; x++)
470 {
471 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]))
472 goto fail;
473 }
474
475 status = gdi_interFrameUpdate(gdi, context);
476
477fail:
478 region16_uninit(&invalidRegion);
479 return status;
480}
481
487static UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context,
488 const RDPGFX_SURFACE_COMMAND* cmd)
489{
490 INT32 rc = 0;
491 UINT status = CHANNEL_RC_OK;
492 gdiGfxSurface* surface = nullptr;
493 RECTANGLE_16 invalidRect;
494 WINPR_ASSERT(gdi);
495 WINPR_ASSERT(context);
496 WINPR_ASSERT(cmd);
497
498 WINPR_ASSERT(context->GetSurfaceData);
499 surface =
500 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
501
502 if (!surface)
503 {
504 WLog_ERR(TAG, "unable to retrieve surfaceData for surfaceId=%" PRIu32 "", cmd->surfaceId);
505 return ERROR_NOT_FOUND;
506 }
507
508 if (!is_within_surface(surface, cmd))
509 return ERROR_INVALID_DATA;
510
511 WINPR_ASSERT(surface->codecs);
512 rc = clear_decompress(surface->codecs->clear, cmd->data, cmd->length, cmd->width, cmd->height,
513 surface->data, surface->format, surface->scanline, cmd->left, cmd->top,
514 surface->width, surface->height, &gdi->palette);
515
516 if (rc < 0)
517 {
518 WLog_ERR(TAG, "clear_decompress failure: %" PRId32 "", rc);
519 return ERROR_INTERNAL_ERROR;
520 }
521
522 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
523 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
524 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
525 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
526 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
527 goto fail;
528 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
529 &invalidRect);
530
531 if (status != CHANNEL_RC_OK)
532 goto fail;
533
534 status = gdi_interFrameUpdate(gdi, context);
535
536fail:
537 return status;
538}
539
545static UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context,
546 const RDPGFX_SURFACE_COMMAND* cmd)
547{
548 UINT status = CHANNEL_RC_OK;
549 BYTE* DstData = nullptr;
550 gdiGfxSurface* surface = nullptr;
551 RECTANGLE_16 invalidRect;
552 WINPR_ASSERT(gdi);
553 WINPR_ASSERT(context);
554 WINPR_ASSERT(cmd);
555
556 WINPR_ASSERT(context->GetSurfaceData);
557 surface =
558 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
559
560 if (!surface)
561 {
562 WLog_ERR(TAG, "unable to retrieve surfaceData for surfaceId=%" PRIu32 "", cmd->surfaceId);
563 return ERROR_NOT_FOUND;
564 }
565
566 DstData = surface->data;
567
568 if (!is_within_surface(surface, cmd))
569 return ERROR_INVALID_DATA;
570
571 if (!freerdp_bitmap_decompress_planar(surface->codecs->planar, cmd->data, cmd->length,
572 cmd->width, cmd->height, DstData, surface->format,
573 surface->scanline, cmd->left, cmd->top, cmd->width,
574 cmd->height, FALSE))
575 return ERROR_INTERNAL_ERROR;
576
577 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
578 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
579 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
580 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
581 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
582 goto fail;
583 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
584 &invalidRect);
585
586 if (status != CHANNEL_RC_OK)
587 goto fail;
588
589 status = gdi_interFrameUpdate(gdi, context);
590
591fail:
592 return status;
593}
594
600static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, RdpgfxClientContext* context,
601 const RDPGFX_SURFACE_COMMAND* cmd)
602{
603#ifdef WITH_GFX_H264
604 INT32 rc = 0;
605 UINT status = CHANNEL_RC_OK;
606 gdiGfxSurface* surface = nullptr;
607 RDPGFX_H264_METABLOCK* meta = nullptr;
608 RDPGFX_AVC420_BITMAP_STREAM* bs = nullptr;
609 WINPR_ASSERT(gdi);
610 WINPR_ASSERT(context);
611 WINPR_ASSERT(cmd);
612
613 WINPR_ASSERT(context->GetSurfaceData);
614 surface =
615 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
616
617 if (!surface)
618 {
619 WLog_ERR(TAG, "unable to retrieve surfaceData for surfaceId=%" PRIu32 "", cmd->surfaceId);
620 return ERROR_NOT_FOUND;
621 }
622
623 if (!surface->h264)
624 {
625 surface->h264 = h264_context_new(FALSE);
626
627 if (!surface->h264)
628 {
629 WLog_ERR(TAG, "unable to create h264 context");
630 return ERROR_NOT_ENOUGH_MEMORY;
631 }
632
633 if (!h264_context_reset(surface->h264, surface->width, surface->height))
634 return ERROR_INTERNAL_ERROR;
635 }
636
637 if (!surface->h264)
638 return ERROR_NOT_SUPPORTED;
639
640 if (!is_within_surface(surface, cmd))
641 return ERROR_INVALID_DATA;
642
643 bs = (RDPGFX_AVC420_BITMAP_STREAM*)cmd->extra;
644
645 if (!bs)
646 return ERROR_INTERNAL_ERROR;
647
648 meta = &(bs->meta);
649 rc = avc420_decompress(surface->h264, bs->data, bs->length, surface->data, surface->format,
650 surface->scanline, surface->width, surface->height, meta->regionRects,
651 meta->numRegionRects);
652
653 if (rc < 0)
654 {
655 WLog_WARN(TAG, "avc420_decompress failure: %" PRId32 ", ignoring update.", rc);
656 return CHANNEL_RC_OK;
657 }
658
659 for (UINT32 i = 0; i < meta->numRegionRects; i++)
660 {
661 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
662 &(meta->regionRects[i])))
663 goto fail;
664 }
665
666 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
667 meta->numRegionRects, meta->regionRects);
668
669 if (status != CHANNEL_RC_OK)
670 goto fail;
671
672 status = gdi_interFrameUpdate(gdi, context);
673
674fail:
675 return status;
676#else
677 return ERROR_NOT_SUPPORTED;
678#endif
679}
680
686static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context,
687 const RDPGFX_SURFACE_COMMAND* cmd)
688{
689#ifdef WITH_GFX_H264
690 INT32 rc = 0;
691 UINT status = CHANNEL_RC_OK;
692 gdiGfxSurface* surface = nullptr;
693 RDPGFX_AVC444_BITMAP_STREAM* bs = nullptr;
694 RDPGFX_AVC420_BITMAP_STREAM* avc1 = nullptr;
695 RDPGFX_H264_METABLOCK* meta1 = nullptr;
696 RDPGFX_AVC420_BITMAP_STREAM* avc2 = nullptr;
697 RDPGFX_H264_METABLOCK* meta2 = nullptr;
698 WINPR_ASSERT(gdi);
699 WINPR_ASSERT(context);
700 WINPR_ASSERT(cmd);
701
702 WINPR_ASSERT(context->GetSurfaceData);
703 surface =
704 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
705
706 if (!surface)
707 {
708 WLog_ERR(TAG, "unable to retrieve surfaceData for surfaceId=%" PRIu32 "", cmd->surfaceId);
709 return ERROR_NOT_FOUND;
710 }
711
712 if (!surface->h264)
713 {
714 surface->h264 = h264_context_new(FALSE);
715
716 if (!surface->h264)
717 {
718 WLog_ERR(TAG, "unable to create h264 context");
719 return ERROR_NOT_ENOUGH_MEMORY;
720 }
721
722 if (!h264_context_reset(surface->h264, surface->width, surface->height))
723 return ERROR_INTERNAL_ERROR;
724 }
725
726 if (!surface->h264)
727 return ERROR_NOT_SUPPORTED;
728
729 if (!is_within_surface(surface, cmd))
730 return ERROR_INVALID_DATA;
731
732 bs = (RDPGFX_AVC444_BITMAP_STREAM*)cmd->extra;
733
734 if (!bs)
735 return ERROR_INTERNAL_ERROR;
736
737 avc1 = &bs->bitstream[0];
738 avc2 = &bs->bitstream[1];
739 meta1 = &avc1->meta;
740 meta2 = &avc2->meta;
741 rc = avc444_decompress(surface->h264, bs->LC, meta1->regionRects, meta1->numRegionRects,
742 avc1->data, avc1->length, meta2->regionRects, meta2->numRegionRects,
743 avc2->data, avc2->length, surface->data, surface->format,
744 surface->scanline, surface->width, surface->height, cmd->codecId);
745
746 if (rc < 0)
747 {
748 WLog_WARN(TAG, "avc444_decompress failure: %" PRIu32 ", ignoring update.", status);
749 return CHANNEL_RC_OK;
750 }
751
752 for (UINT32 i = 0; i < meta1->numRegionRects; i++)
753 {
754 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
755 &(meta1->regionRects[i])))
756 goto fail;
757 }
758
759 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
760 meta1->numRegionRects, meta1->regionRects);
761
762 if (status != CHANNEL_RC_OK)
763 goto fail;
764
765 for (UINT32 i = 0; i < meta2->numRegionRects; i++)
766 {
767 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
768 &(meta2->regionRects[i])))
769 goto fail;
770 }
771
772 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
773 meta2->numRegionRects, meta2->regionRects);
774
775 if (status != CHANNEL_RC_OK)
776 goto fail;
777
778 status = gdi_interFrameUpdate(gdi, context);
779
780fail:
781 return status;
782#else
783 return ERROR_NOT_SUPPORTED;
784#endif
785}
786
787static BOOL gdi_apply_alpha(BYTE* data, UINT32 format, UINT32 stride, RECTANGLE_16* rect,
788 UINT32 startOffsetX, UINT32 count, BYTE a)
789{
790 UINT32 written = 0;
791 BOOL first = TRUE;
792 const UINT32 bpp = FreeRDPGetBytesPerPixel(format);
793 WINPR_ASSERT(rect);
794
795 for (size_t y = rect->top; y < rect->bottom; y++)
796 {
797 BYTE* line = &data[y * stride];
798
799 for (size_t x = first ? rect->left + startOffsetX : rect->left; x < rect->right; x++)
800 {
801 BYTE r = 0;
802 BYTE g = 0;
803 BYTE b = 0;
804
805 if (written == count)
806 return TRUE;
807
808 BYTE* src = &line[x * bpp];
809 UINT32 color = FreeRDPReadColor(src, format);
810 FreeRDPSplitColor(color, format, &r, &g, &b, nullptr, nullptr);
811 color = FreeRDPGetColor(format, r, g, b, a);
812 FreeRDPWriteColor(src, format, color);
813 written++;
814 }
815
816 first = FALSE;
817 }
818
819 return TRUE;
820}
826static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context,
827 const RDPGFX_SURFACE_COMMAND* cmd)
828{
829 UINT status = CHANNEL_RC_OK;
830 UINT16 alphaSig = 0;
831 UINT16 compressed = 0;
832 gdiGfxSurface* surface = nullptr;
833 RECTANGLE_16 invalidRect;
834 wStream buffer;
835 wStream* s = nullptr;
836 WINPR_ASSERT(gdi);
837 WINPR_ASSERT(context);
838 WINPR_ASSERT(cmd);
839
840 s = Stream_StaticConstInit(&buffer, cmd->data, cmd->length);
841
842 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
843 return ERROR_INVALID_DATA;
844
845 WINPR_ASSERT(context->GetSurfaceData);
846 surface =
847 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
848
849 if (!surface)
850 {
851 WLog_ERR(TAG, "unable to retrieve surfaceData for surfaceId=%" PRIu32 "", cmd->surfaceId);
852 return ERROR_NOT_FOUND;
853 }
854
855 if (!is_within_surface(surface, cmd))
856 return ERROR_INVALID_DATA;
857
858 Stream_Read_UINT16(s, alphaSig);
859 Stream_Read_UINT16(s, compressed);
860
861 if (alphaSig != 0x414C)
862 return ERROR_INVALID_DATA;
863
864 if (compressed == 0)
865 {
866 if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, cmd->height, cmd->width))
867 return ERROR_INVALID_DATA;
868
869 for (size_t y = cmd->top; y < cmd->top + cmd->height; y++)
870 {
871 BYTE* line = &surface->data[y * surface->scanline];
872
873 for (size_t x = cmd->left; x < cmd->left + cmd->width; x++)
874 {
875 UINT32 color = 0;
876 BYTE r = 0;
877 BYTE g = 0;
878 BYTE b = 0;
879 BYTE a = 0;
880 BYTE* src = &line[x * FreeRDPGetBytesPerPixel(surface->format)];
881 Stream_Read_UINT8(s, a);
882 color = FreeRDPReadColor(src, surface->format);
883 FreeRDPSplitColor(color, surface->format, &r, &g, &b, nullptr, nullptr);
884 color = FreeRDPGetColor(surface->format, r, g, b, a);
885 FreeRDPWriteColor(src, surface->format, color);
886 }
887 }
888 }
889 else
890 {
891 UINT32 startOffsetX = 0;
892 RECTANGLE_16 rect = WINPR_C_ARRAY_INIT;
893 rect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
894 rect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
895 rect.right = (UINT16)MIN(UINT16_MAX, cmd->left + cmd->width);
896 rect.bottom = (UINT16)MIN(UINT16_MAX, cmd->top + cmd->height);
897
898 while (rect.top < rect.bottom)
899 {
900 UINT32 count = 0;
901 BYTE a = 0;
902
903 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
904 return ERROR_INVALID_DATA;
905
906 Stream_Read_UINT8(s, a);
907 Stream_Read_UINT8(s, count);
908
909 if (count >= 0xFF)
910 {
911 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
912 return ERROR_INVALID_DATA;
913
914 Stream_Read_UINT16(s, count);
915
916 if (count >= 0xFFFF)
917 {
918 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
919 return ERROR_INVALID_DATA;
920
921 Stream_Read_UINT32(s, count);
922 }
923 }
924
925 if (!gdi_apply_alpha(surface->data, surface->format, surface->scanline, &rect,
926 startOffsetX, count, a))
927 return ERROR_INTERNAL_ERROR;
928
929 startOffsetX += count;
930
931 while (startOffsetX >= cmd->width)
932 {
933 startOffsetX -= cmd->width;
934 rect.top++;
935 }
936 }
937 }
938
939 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
940 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
941 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
942 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
943 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
944 goto fail;
945 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
946 &invalidRect);
947
948 if (status != CHANNEL_RC_OK)
949 goto fail;
950
951 status = gdi_interFrameUpdate(gdi, context);
952
953fail:
954 return status;
955}
956
957#if defined(WITH_GFX_FRAME_DUMP)
958static void dump_cmd(const RDPGFX_SURFACE_COMMAND* cmd, UINT32 frameId)
959{
960 static UINT64 xxx = 0;
961 const char* path = "/tmp/dump/";
962 WINPR_ASSERT(cmd);
963 char fname[1024] = WINPR_C_ARRAY_INIT;
964
965 snprintf(fname, sizeof(fname), "%s/%08" PRIx64 ".raw", path, xxx++);
966 FILE* fp = fopen(fname, "w");
967 if (!fp)
968 return;
969 (void)fprintf(fp, "frameid: %" PRIu32 "\n", frameId);
970 (void)fprintf(fp, "surfaceId: %" PRIu32 "\n", cmd->surfaceId);
971 (void)fprintf(fp, "codecId: %" PRIu32 "\n", cmd->codecId);
972 (void)fprintf(fp, "contextId: %" PRIu32 "\n", cmd->contextId);
973 (void)fprintf(fp, "format: %" PRIu32 "\n", cmd->format);
974 (void)fprintf(fp, "left: %" PRIu32 "\n", cmd->left);
975 (void)fprintf(fp, "top: %" PRIu32 "\n", cmd->top);
976 (void)fprintf(fp, "right: %" PRIu32 "\n", cmd->right);
977 (void)fprintf(fp, "bottom: %" PRIu32 "\n", cmd->bottom);
978 (void)fprintf(fp, "width: %" PRIu32 "\n", cmd->width);
979 (void)fprintf(fp, "height: %" PRIu32 "\n", cmd->height);
980 (void)fprintf(fp, "length: %" PRIu32 "\n", cmd->length);
981
982 char* bdata = crypto_base64_encode_ex(cmd->data, cmd->length, FALSE);
983 (void)fprintf(fp, "data: %s\n", bdata);
984 free(bdata);
985 fclose(fp);
986}
987#endif
988
994static UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context,
995 const RDPGFX_SURFACE_COMMAND* cmd)
996{
997 INT32 rc = 0;
998 UINT status = ERROR_INTERNAL_ERROR;
999 gdiGfxSurface* surface = nullptr;
1000 REGION16 invalidRegion;
1001 const RECTANGLE_16* rects = nullptr;
1002 UINT32 nrRects = 0;
1008 WINPR_ASSERT(gdi);
1009 WINPR_ASSERT(context);
1010 WINPR_ASSERT(cmd);
1011 const UINT16 surfaceId = (UINT16)MIN(UINT16_MAX, cmd->surfaceId);
1012
1013 WINPR_ASSERT(context->GetSurfaceData);
1014 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceId);
1015
1016 if (!surface)
1017 {
1018 WLog_ERR(TAG, "unable to retrieve surfaceData for surfaceId=%" PRIu32 "", cmd->surfaceId);
1019 return ERROR_NOT_FOUND;
1020 }
1021
1022 if (!is_within_surface(surface, cmd))
1023 return ERROR_INVALID_DATA;
1024
1025 WINPR_ASSERT(surface->codecs);
1026 rc = progressive_create_surface_context(surface->codecs->progressive, surfaceId, surface->width,
1027 surface->height);
1028
1029 if (rc < 0)
1030 {
1031 WLog_ERR(TAG, "progressive_create_surface_context failure: %" PRId32 "", rc);
1032 return ERROR_INTERNAL_ERROR;
1033 }
1034
1035 region16_init(&invalidRegion);
1036
1037 rc = progressive_decompress(surface->codecs->progressive, cmd->data, cmd->length, surface->data,
1038 surface->format, surface->scanline, cmd->left, cmd->top,
1039 &invalidRegion, surfaceId, gdi->frameId);
1040
1041 if (rc < 0)
1042 {
1043 WLog_ERR(TAG, "progressive_decompress failure: %" PRId32 "", rc);
1044 goto fail;
1045 }
1046
1047 rects = region16_rects(&invalidRegion, &nrRects);
1048 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1049 nrRects, rects);
1050
1051 if (status != CHANNEL_RC_OK)
1052 goto fail;
1053
1054 status = ERROR_INTERNAL_ERROR;
1055 for (UINT32 x = 0; x < nrRects; x++)
1056 {
1057 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]))
1058 goto fail;
1059 }
1060
1061 status = gdi_interFrameUpdate(gdi, context);
1062
1063fail:
1064
1065 region16_uninit(&invalidRegion);
1066 return status;
1067}
1068
1074static UINT gdi_SurfaceCommand(RdpgfxClientContext* context, const RDPGFX_SURFACE_COMMAND* cmd)
1075{
1076 UINT status = CHANNEL_RC_OK;
1077 rdpGdi* gdi = nullptr;
1078
1079 if (!context || !cmd)
1080 return ERROR_INVALID_PARAMETER;
1081
1082 gdi = (rdpGdi*)context->custom;
1083
1084 EnterCriticalSection(&context->mux);
1085 const UINT16 codecId = WINPR_ASSERTING_INT_CAST(UINT16, cmd->codecId);
1086 WLog_Print(gdi->log, WLOG_TRACE,
1087 "surfaceId=%" PRIu32 ", codec=%s [%" PRIu32 "], contextId=%" PRIu32 ", format=%s, "
1088 "left=%" PRIu32 ", top=%" PRIu32 ", right=%" PRIu32 ", bottom=%" PRIu32
1089 ", width=%" PRIu32 ", height=%" PRIu32 " "
1090 "length=%" PRIu32 ", data=%p, extra=%p",
1091 cmd->surfaceId, rdpgfx_get_codec_id_string(codecId), cmd->codecId, cmd->contextId,
1092 FreeRDPGetColorFormatName(cmd->format), cmd->left, cmd->top, cmd->right, cmd->bottom,
1093 cmd->width, cmd->height, cmd->length, (void*)cmd->data, (void*)cmd->extra);
1094#if defined(WITH_GFX_FRAME_DUMP)
1095 dump_cmd(cmd, gdi->frameId);
1096#endif
1097
1098 switch (codecId)
1099 {
1100 case RDPGFX_CODECID_UNCOMPRESSED:
1101 status = gdi_SurfaceCommand_Uncompressed(gdi, context, cmd);
1102 break;
1103
1104 case RDPGFX_CODECID_CAVIDEO:
1105 status = gdi_SurfaceCommand_RemoteFX(gdi, context, cmd);
1106 break;
1107
1108 case RDPGFX_CODECID_CLEARCODEC:
1109 status = gdi_SurfaceCommand_ClearCodec(gdi, context, cmd);
1110 break;
1111
1112 case RDPGFX_CODECID_PLANAR:
1113 status = gdi_SurfaceCommand_Planar(gdi, context, cmd);
1114 break;
1115
1116 case RDPGFX_CODECID_AVC420:
1117 status = gdi_SurfaceCommand_AVC420(gdi, context, cmd);
1118 break;
1119
1120 case RDPGFX_CODECID_AVC444v2:
1121 case RDPGFX_CODECID_AVC444:
1122 status = gdi_SurfaceCommand_AVC444(gdi, context, cmd);
1123 break;
1124
1125 case RDPGFX_CODECID_ALPHA:
1126 status = gdi_SurfaceCommand_Alpha(gdi, context, cmd);
1127 break;
1128
1129 case RDPGFX_CODECID_CAPROGRESSIVE:
1130 status = gdi_SurfaceCommand_Progressive(gdi, context, cmd);
1131 break;
1132
1133 case RDPGFX_CODECID_CAPROGRESSIVE_V2:
1134 WLog_WARN(TAG, "SurfaceCommand %s [0x%08" PRIX16 "] not implemented",
1135 rdpgfx_get_codec_id_string(codecId), codecId);
1136 break;
1137
1138 default:
1139 WLog_WARN(TAG, "Invalid SurfaceCommand %s [0x%08" PRIX16 "]",
1140 rdpgfx_get_codec_id_string(codecId), codecId);
1141 break;
1142 }
1143
1144 LeaveCriticalSection(&context->mux);
1145 return status;
1146}
1147
1153static UINT
1154gdi_DeleteEncodingContext(RdpgfxClientContext* context,
1155 const RDPGFX_DELETE_ENCODING_CONTEXT_PDU* deleteEncodingContext)
1156{
1157 WINPR_ASSERT(context);
1158 WINPR_ASSERT(deleteEncodingContext);
1159 WINPR_UNUSED(context);
1160 WINPR_UNUSED(deleteEncodingContext);
1161 return CHANNEL_RC_OK;
1162}
1163
1169static UINT gdi_CreateSurface(RdpgfxClientContext* context,
1170 const RDPGFX_CREATE_SURFACE_PDU* createSurface)
1171{
1172 UINT rc = ERROR_INTERNAL_ERROR;
1173 gdiGfxSurface* surface = nullptr;
1174 rdpGdi* gdi = nullptr;
1175 WINPR_ASSERT(context);
1176 WINPR_ASSERT(createSurface);
1177 gdi = (rdpGdi*)context->custom;
1178 WINPR_ASSERT(gdi);
1179 WINPR_ASSERT(gdi->context);
1180 EnterCriticalSection(&context->mux);
1181 surface = (gdiGfxSurface*)calloc(1, sizeof(gdiGfxSurface));
1182
1183 if (!surface)
1184 goto fail;
1185
1186 if (!freerdp_settings_get_bool(gdi->context->settings, FreeRDP_DeactivateClientDecoding))
1187 {
1188 WINPR_ASSERT(context->codecs);
1189 surface->codecs = context->codecs;
1190
1191 if (!surface->codecs)
1192 {
1193 free(surface);
1194 goto fail;
1195 }
1196 }
1197
1198 surface->surfaceId = createSurface->surfaceId;
1199 surface->width = gfx_align_scanline(createSurface->width, 16);
1200 surface->height = gfx_align_scanline(createSurface->height, 16);
1201 surface->mappedWidth = createSurface->width;
1202 surface->mappedHeight = createSurface->height;
1203 surface->outputTargetWidth = createSurface->width;
1204 surface->outputTargetHeight = createSurface->height;
1205
1206 switch (createSurface->pixelFormat)
1207 {
1208 case GFX_PIXEL_FORMAT_ARGB_8888:
1209 surface->format = PIXEL_FORMAT_BGRA32;
1210 break;
1211
1212 case GFX_PIXEL_FORMAT_XRGB_8888:
1213 surface->format = PIXEL_FORMAT_BGRX32;
1214 break;
1215
1216 default:
1217 free(surface);
1218 goto fail;
1219 }
1220
1221 surface->scanline = gfx_align_scanline(surface->width * 4UL, 16);
1222 surface->data = (BYTE*)winpr_aligned_malloc(1ull * surface->scanline * surface->height, 16);
1223
1224 if (!surface->data)
1225 {
1226 free(surface);
1227 goto fail;
1228 }
1229
1230 memset(surface->data, 0xFF, (size_t)surface->scanline * surface->height);
1231 region16_init(&surface->invalidRegion);
1232
1233 WINPR_ASSERT(context->SetSurfaceData);
1234 rc = context->SetSurfaceData(context, surface->surfaceId, (void*)surface);
1235fail:
1236 LeaveCriticalSection(&context->mux);
1237 return rc;
1238}
1239
1245static UINT gdi_DeleteSurface(RdpgfxClientContext* context,
1246 const RDPGFX_DELETE_SURFACE_PDU* deleteSurface)
1247{
1248 UINT rc = CHANNEL_RC_OK;
1249 UINT res = ERROR_INTERNAL_ERROR;
1250 rdpCodecs* codecs = nullptr;
1251 gdiGfxSurface* surface = nullptr;
1252 EnterCriticalSection(&context->mux);
1253
1254 WINPR_ASSERT(context->GetSurfaceData);
1255 surface = (gdiGfxSurface*)context->GetSurfaceData(context, deleteSurface->surfaceId);
1256
1257 if (surface)
1258 {
1259 if (surface->windowMapped)
1260 rc = IFCALLRESULT(CHANNEL_RC_OK, context->UnmapWindowForSurface, context,
1261 surface->windowId);
1262
1263#ifdef WITH_GFX_H264
1264 h264_context_free(surface->h264);
1265#endif
1266 region16_uninit(&surface->invalidRegion);
1267 codecs = surface->codecs;
1268 winpr_aligned_free(surface->data);
1269 free(surface);
1270 }
1271
1272 WINPR_ASSERT(context->SetSurfaceData);
1273 res = context->SetSurfaceData(context, deleteSurface->surfaceId, nullptr);
1274 if (res)
1275 rc = res;
1276
1277 if (codecs && codecs->progressive)
1278 progressive_delete_surface_context(codecs->progressive, deleteSurface->surfaceId);
1279
1280 LeaveCriticalSection(&context->mux);
1281 return rc;
1282}
1283
1284static BOOL intersect_rect(const RECTANGLE_16* rect, const gdiGfxSurface* surface,
1285 RECTANGLE_16* prect)
1286{
1287 WINPR_ASSERT(rect);
1288 WINPR_ASSERT(surface);
1289 WINPR_ASSERT(prect);
1290
1291 if (rect->left > rect->right)
1292 return FALSE;
1293 if (rect->left > surface->width)
1294 return FALSE;
1295 if (rect->top > rect->bottom)
1296 return FALSE;
1297 if (rect->top > surface->height)
1298 return FALSE;
1299 prect->left = rect->left;
1300 prect->top = rect->top;
1301
1302 prect->right = MIN(rect->right, WINPR_ASSERTING_INT_CAST(UINT16, surface->width));
1303 prect->bottom = MIN(rect->bottom, WINPR_ASSERTING_INT_CAST(UINT16, surface->height));
1304 return TRUE;
1305}
1306
1312static UINT gdi_SolidFill(RdpgfxClientContext* context, const RDPGFX_SOLID_FILL_PDU* solidFill)
1313{
1314 UINT status = ERROR_INTERNAL_ERROR;
1315 BYTE a = 0xff;
1316 RECTANGLE_16 invalidRect = WINPR_C_ARRAY_INIT;
1317 rdpGdi* gdi = (rdpGdi*)context->custom;
1318
1319 EnterCriticalSection(&context->mux);
1320
1321 WINPR_ASSERT(context->GetSurfaceData);
1322 gdiGfxSurface* surface = (gdiGfxSurface*)context->GetSurfaceData(context, solidFill->surfaceId);
1323
1324 if (!surface)
1325 goto fail;
1326
1327 {
1328 const BYTE b = solidFill->fillPixel.B;
1329 const BYTE g = solidFill->fillPixel.G;
1330 const BYTE r = solidFill->fillPixel.R;
1331
1332 /* [MS-RDPEGFX] 3.3.5.4 Processing an RDPGFX_SOLIDFILL_PDU message
1333 * https://learn.microsoft.com/en-us/windows/win32/gdi/binary-raster-operations
1334 *
1335 * this sounds like the alpha value is always ignored.
1336 */
1337 const UINT32 color = FreeRDPGetColor(surface->format, r, g, b, a);
1338 for (UINT16 index = 0; index < solidFill->fillRectCount; index++)
1339 {
1340 const RECTANGLE_16* rect = &(solidFill->fillRects[index]);
1341
1342 if (!intersect_rect(rect, surface, &invalidRect))
1343 goto fail;
1344
1345 const UINT32 nWidth = invalidRect.right - invalidRect.left;
1346 const UINT32 nHeight = invalidRect.bottom - invalidRect.top;
1347
1348 if (!freerdp_image_fill(surface->data, surface->format, surface->scanline,
1349 invalidRect.left, invalidRect.top, nWidth, nHeight, color))
1350 goto fail;
1351
1352 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
1353 &invalidRect))
1354 goto fail;
1355 }
1356 }
1357
1358 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1359 solidFill->fillRectCount, solidFill->fillRects);
1360
1361 if (status != CHANNEL_RC_OK)
1362 goto fail;
1363
1364 LeaveCriticalSection(&context->mux);
1365
1366 return gdi_interFrameUpdate(gdi, context);
1367fail:
1368 LeaveCriticalSection(&context->mux);
1369 return status;
1370}
1371
1377static UINT gdi_SurfaceToSurface(RdpgfxClientContext* context,
1378 const RDPGFX_SURFACE_TO_SURFACE_PDU* surfaceToSurface)
1379{
1380 UINT status = ERROR_INTERNAL_ERROR;
1381 BOOL sameSurface = 0;
1382 const RECTANGLE_16* rectSrc = nullptr;
1383 RECTANGLE_16 invalidRect;
1384 gdiGfxSurface* surfaceSrc = nullptr;
1385 gdiGfxSurface* surfaceDst = nullptr;
1386 rdpGdi* gdi = (rdpGdi*)context->custom;
1387 EnterCriticalSection(&context->mux);
1388 rectSrc = &(surfaceToSurface->rectSrc);
1389
1390 WINPR_ASSERT(context->GetSurfaceData);
1391 surfaceSrc = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdSrc);
1392 sameSurface = (surfaceToSurface->surfaceIdSrc == surfaceToSurface->surfaceIdDest);
1393
1394 if (!sameSurface)
1395 surfaceDst =
1396 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdDest);
1397 else
1398 surfaceDst = surfaceSrc;
1399
1400 if (!surfaceSrc || !surfaceDst)
1401 goto fail;
1402
1403 if (!is_rect_valid(rectSrc, surfaceSrc->width, surfaceSrc->height))
1404 goto fail;
1405
1406 {
1407 const UINT32 nWidth = rectSrc->right - rectSrc->left;
1408 const UINT32 nHeight = rectSrc->bottom - rectSrc->top;
1409
1410 for (UINT16 index = 0; index < surfaceToSurface->destPtsCount; index++)
1411 {
1412 const RDPGFX_POINT16* destPt = &surfaceToSurface->destPts[index];
1413 const RECTANGLE_16 rect = { destPt->x, destPt->y,
1414 (UINT16)MIN(UINT16_MAX, destPt->x + nWidth),
1415 (UINT16)MIN(UINT16_MAX, destPt->y + nHeight) };
1416 if (!is_rect_valid(&rect, surfaceDst->width, surfaceDst->height))
1417 goto fail;
1418
1419 const UINT32 rwidth = rect.right - rect.left;
1420 const UINT32 rheight = rect.bottom - rect.top;
1421 if (!freerdp_image_copy(surfaceDst->data, surfaceDst->format, surfaceDst->scanline,
1422 destPt->x, destPt->y, rwidth, rheight, surfaceSrc->data,
1423 surfaceSrc->format, surfaceSrc->scanline, rectSrc->left,
1424 rectSrc->top, nullptr, FREERDP_FLIP_NONE))
1425 goto fail;
1426
1427 invalidRect = rect;
1428 if (!region16_union_rect(&surfaceDst->invalidRegion, &surfaceDst->invalidRegion,
1429 &invalidRect))
1430 goto fail;
1431 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1432 surfaceDst->surfaceId, 1, &invalidRect);
1433
1434 if (status != CHANNEL_RC_OK)
1435 goto fail;
1436 }
1437 }
1438
1439 LeaveCriticalSection(&context->mux);
1440
1441 return gdi_interFrameUpdate(gdi, context);
1442fail:
1443 LeaveCriticalSection(&context->mux);
1444 return status;
1445}
1446
1447static void gdi_GfxCacheEntryFree(gdiGfxCacheEntry* entry)
1448{
1449 if (!entry)
1450 return;
1451 free(entry->data);
1452 free(entry);
1453}
1454
1455static gdiGfxCacheEntry* gdi_GfxCacheEntryNew(UINT64 cacheKey, UINT32 width, UINT32 height,
1456 UINT32 format)
1457{
1458 gdiGfxCacheEntry* cacheEntry = (gdiGfxCacheEntry*)calloc(1, sizeof(gdiGfxCacheEntry));
1459 if (!cacheEntry)
1460 goto fail;
1461
1462 cacheEntry->cacheKey = cacheKey;
1463 cacheEntry->width = width;
1464 cacheEntry->height = height;
1465 cacheEntry->format = format;
1466 cacheEntry->scanline = gfx_align_scanline(cacheEntry->width * 4, 16);
1467
1468 if ((cacheEntry->width > 0) && (cacheEntry->height > 0))
1469 {
1470 cacheEntry->data = (BYTE*)calloc(cacheEntry->height, cacheEntry->scanline);
1471
1472 if (!cacheEntry->data)
1473 goto fail;
1474 }
1475 return cacheEntry;
1476fail:
1477 gdi_GfxCacheEntryFree(cacheEntry);
1478 return nullptr;
1479}
1480
1486static UINT gdi_SurfaceToCache(RdpgfxClientContext* context,
1487 const RDPGFX_SURFACE_TO_CACHE_PDU* surfaceToCache)
1488{
1489 gdiGfxCacheEntry* cacheEntry = nullptr;
1490 UINT rc = ERROR_INTERNAL_ERROR;
1491 EnterCriticalSection(&context->mux);
1492 const RECTANGLE_16* rect = &(surfaceToCache->rectSrc);
1493
1494 WINPR_ASSERT(context->GetSurfaceData);
1495 gdiGfxSurface* surface =
1496 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToCache->surfaceId);
1497
1498 if (!surface)
1499 goto fail;
1500
1501 if (!is_rect_valid(rect, surface->width, surface->height))
1502 goto fail;
1503
1504 cacheEntry = gdi_GfxCacheEntryNew(surfaceToCache->cacheKey, (UINT32)(rect->right - rect->left),
1505 (UINT32)(rect->bottom - rect->top), surface->format);
1506
1507 if (!cacheEntry)
1508 goto fail;
1509
1510 if (!cacheEntry->data)
1511 goto fail;
1512
1513 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1514 0, 0, cacheEntry->width, cacheEntry->height, surface->data,
1515 surface->format, surface->scanline, rect->left, rect->top,
1516 nullptr, FREERDP_FLIP_NONE))
1517 goto fail;
1518
1519 {
1520 RDPGFX_EVICT_CACHE_ENTRY_PDU evict = { surfaceToCache->cacheSlot };
1521 WINPR_ASSERT(context->EvictCacheEntry);
1522 rc = context->EvictCacheEntry(context, &evict);
1523 if (rc != CHANNEL_RC_OK)
1524 goto fail;
1525 }
1526
1527 WINPR_ASSERT(context->SetCacheSlotData);
1528 rc = context->SetCacheSlotData(context, surfaceToCache->cacheSlot, (void*)cacheEntry);
1529fail:
1530 if (rc != CHANNEL_RC_OK)
1531 gdi_GfxCacheEntryFree(cacheEntry);
1532 LeaveCriticalSection(&context->mux);
1533 return rc;
1534}
1535
1541static UINT gdi_CacheToSurface(RdpgfxClientContext* context,
1542 const RDPGFX_CACHE_TO_SURFACE_PDU* cacheToSurface)
1543{
1544 UINT status = ERROR_INTERNAL_ERROR;
1545 gdiGfxSurface* surface = nullptr;
1546 gdiGfxCacheEntry* cacheEntry = nullptr;
1547 RECTANGLE_16 invalidRect;
1548 rdpGdi* gdi = (rdpGdi*)context->custom;
1549
1550 EnterCriticalSection(&context->mux);
1551
1552 WINPR_ASSERT(context->GetSurfaceData);
1553 surface = (gdiGfxSurface*)context->GetSurfaceData(context, cacheToSurface->surfaceId);
1554
1555 WINPR_ASSERT(context->GetCacheSlotData);
1556 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheToSurface->cacheSlot);
1557
1558 if (!surface || !cacheEntry)
1559 goto fail;
1560
1561 for (UINT16 index = 0; index < cacheToSurface->destPtsCount; index++)
1562 {
1563 const RDPGFX_POINT16* destPt = &cacheToSurface->destPts[index];
1564 const RECTANGLE_16 rect = { destPt->x, destPt->y,
1565 (UINT16)MIN(UINT16_MAX, destPt->x + cacheEntry->width),
1566 (UINT16)MIN(UINT16_MAX, destPt->y + cacheEntry->height) };
1567
1568 if (rectangle_is_empty(&rect))
1569 continue;
1570
1571 if (!is_rect_valid(&rect, surface->width, surface->height))
1572 goto fail;
1573
1574 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline,
1575 destPt->x, destPt->y, cacheEntry->width,
1576 cacheEntry->height, cacheEntry->data, cacheEntry->format,
1577 cacheEntry->scanline, 0, 0, nullptr, FREERDP_FLIP_NONE))
1578 goto fail;
1579
1580 invalidRect = rect;
1581 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect))
1582 goto fail;
1583 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1584 surface->surfaceId, 1, &invalidRect);
1585
1586 if (status != CHANNEL_RC_OK)
1587 goto fail;
1588 }
1589
1590 LeaveCriticalSection(&context->mux);
1591
1592 return gdi_interFrameUpdate(gdi, context);
1593
1594fail:
1595 LeaveCriticalSection(&context->mux);
1596 return status;
1597}
1598
1604static UINT gdi_CacheImportReply(RdpgfxClientContext* context,
1605 const RDPGFX_CACHE_IMPORT_REPLY_PDU* cacheImportReply)
1606{
1607 UINT16 count = 0;
1608 const UINT16* slots = nullptr;
1609 UINT error = CHANNEL_RC_OK;
1610
1611 slots = cacheImportReply->cacheSlots;
1612 count = cacheImportReply->importedEntriesCount;
1613
1614 for (UINT16 index = 0; index < count; index++)
1615 {
1616 UINT16 cacheSlot = slots[index];
1617
1618 if (cacheSlot == 0)
1619 continue;
1620
1621 WINPR_ASSERT(context->GetCacheSlotData);
1622 gdiGfxCacheEntry* cacheEntry =
1623 (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1624
1625 if (cacheEntry)
1626 continue;
1627
1628 cacheEntry = gdi_GfxCacheEntryNew(cacheSlot, 0, 0, PIXEL_FORMAT_BGRX32);
1629
1630 if (!cacheEntry)
1631 return ERROR_INTERNAL_ERROR;
1632
1633 WINPR_ASSERT(context->SetCacheSlotData);
1634 error = context->SetCacheSlotData(context, cacheSlot, (void*)cacheEntry);
1635
1636 if (error)
1637 {
1638 WLog_ERR(TAG, "CacheImportReply: SetCacheSlotData failed with error %" PRIu32 "",
1639 error);
1640 gdi_GfxCacheEntryFree(cacheEntry);
1641 break;
1642 }
1643 }
1644
1645 return error;
1646}
1647
1648static UINT gdi_ImportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1649 const PERSISTENT_CACHE_ENTRY* importCacheEntry)
1650{
1651 UINT error = ERROR_INTERNAL_ERROR;
1652 gdiGfxCacheEntry* cacheEntry = nullptr;
1653
1654 if (cacheSlot == 0)
1655 return CHANNEL_RC_OK;
1656
1657 cacheEntry = gdi_GfxCacheEntryNew(importCacheEntry->key64, importCacheEntry->width,
1658 importCacheEntry->height, PIXEL_FORMAT_BGRX32);
1659
1660 if (!cacheEntry)
1661 goto fail;
1662
1663 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1664 0, 0, cacheEntry->width, cacheEntry->height,
1665 importCacheEntry->data, PIXEL_FORMAT_BGRX32, 0, 0, 0,
1666 nullptr, FREERDP_FLIP_NONE))
1667 goto fail;
1668
1669 {
1670 RDPGFX_EVICT_CACHE_ENTRY_PDU evict = { cacheSlot };
1671 WINPR_ASSERT(context->EvictCacheEntry);
1672 error = context->EvictCacheEntry(context, &evict);
1673 }
1674 if (error != CHANNEL_RC_OK)
1675 goto fail;
1676
1677 WINPR_ASSERT(context->SetCacheSlotData);
1678 error = context->SetCacheSlotData(context, cacheSlot, (void*)cacheEntry);
1679
1680fail:
1681 if (error)
1682 {
1683 gdi_GfxCacheEntryFree(cacheEntry);
1684 WLog_ERR(TAG, "ImportCacheEntry: SetCacheSlotData failed with error %" PRIu32 "", error);
1685 }
1686
1687 return error;
1688}
1689
1690static UINT gdi_ExportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1691 PERSISTENT_CACHE_ENTRY* exportCacheEntry)
1692{
1693 gdiGfxCacheEntry* cacheEntry = nullptr;
1694
1695 WINPR_ASSERT(context->GetCacheSlotData);
1696 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1697
1698 if (cacheEntry)
1699 {
1700 exportCacheEntry->key64 = cacheEntry->cacheKey;
1701 exportCacheEntry->width = (UINT16)MIN(UINT16_MAX, cacheEntry->width);
1702 exportCacheEntry->height = (UINT16)MIN(UINT16_MAX, cacheEntry->height);
1703 exportCacheEntry->size = cacheEntry->width * cacheEntry->height * 4;
1704 exportCacheEntry->flags = 0;
1705 exportCacheEntry->data = cacheEntry->data;
1706 return CHANNEL_RC_OK;
1707 }
1708
1709 return ERROR_NOT_FOUND;
1710}
1711
1717static UINT gdi_EvictCacheEntry(RdpgfxClientContext* context,
1718 const RDPGFX_EVICT_CACHE_ENTRY_PDU* evictCacheEntry)
1719{
1720 gdiGfxCacheEntry* cacheEntry = nullptr;
1721 UINT rc = ERROR_NOT_FOUND;
1722
1723 WINPR_ASSERT(context);
1724 WINPR_ASSERT(evictCacheEntry);
1725
1726 EnterCriticalSection(&context->mux);
1727
1728 WINPR_ASSERT(context->GetCacheSlotData);
1729 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, evictCacheEntry->cacheSlot);
1730
1731 gdi_GfxCacheEntryFree(cacheEntry);
1732
1733 WINPR_ASSERT(context->SetCacheSlotData);
1734 rc = context->SetCacheSlotData(context, evictCacheEntry->cacheSlot, nullptr);
1735 LeaveCriticalSection(&context->mux);
1736 return rc;
1737}
1738
1744static UINT gdi_MapSurfaceToOutput(RdpgfxClientContext* context,
1745 const RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU* surfaceToOutput)
1746{
1747 UINT rc = ERROR_INTERNAL_ERROR;
1748 gdiGfxSurface* surface = nullptr;
1749 EnterCriticalSection(&context->mux);
1750
1751 WINPR_ASSERT(context->GetSurfaceData);
1752 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1753
1754 if (!surface)
1755 goto fail;
1756
1757 if (surface->windowMapped)
1758 {
1759 WLog_WARN(TAG, "surface already windowMapped when trying to set outputMapped");
1760 goto fail;
1761 }
1762
1763 surface->outputMapped = TRUE;
1764 surface->outputOriginX = surfaceToOutput->outputOriginX;
1765 surface->outputOriginY = surfaceToOutput->outputOriginY;
1766 surface->outputTargetWidth = surface->mappedWidth;
1767 surface->outputTargetHeight = surface->mappedHeight;
1768 region16_clear(&surface->invalidRegion);
1769 rc = CHANNEL_RC_OK;
1770fail:
1771 LeaveCriticalSection(&context->mux);
1772 return rc;
1773}
1774
1775static UINT
1776gdi_MapSurfaceToScaledOutput(RdpgfxClientContext* context,
1777 const RDPGFX_MAP_SURFACE_TO_SCALED_OUTPUT_PDU* surfaceToOutput)
1778{
1779 UINT rc = ERROR_INTERNAL_ERROR;
1780 gdiGfxSurface* surface = nullptr;
1781 EnterCriticalSection(&context->mux);
1782
1783 WINPR_ASSERT(context->GetSurfaceData);
1784 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1785
1786 if (!surface)
1787 goto fail;
1788
1789 if (surface->windowMapped)
1790 {
1791 WLog_WARN(TAG, "surface already windowMapped when trying to set outputMapped");
1792 goto fail;
1793 }
1794
1795 surface->outputMapped = TRUE;
1796 surface->outputOriginX = surfaceToOutput->outputOriginX;
1797 surface->outputOriginY = surfaceToOutput->outputOriginY;
1798 surface->outputTargetWidth = surfaceToOutput->targetWidth;
1799 surface->outputTargetHeight = surfaceToOutput->targetHeight;
1800 region16_clear(&surface->invalidRegion);
1801 rc = CHANNEL_RC_OK;
1802fail:
1803 LeaveCriticalSection(&context->mux);
1804 return rc;
1805}
1806
1812static UINT gdi_MapSurfaceToWindow(RdpgfxClientContext* context,
1813 const RDPGFX_MAP_SURFACE_TO_WINDOW_PDU* surfaceToWindow)
1814{
1815 UINT rc = ERROR_INTERNAL_ERROR;
1816 gdiGfxSurface* surface = nullptr;
1817 EnterCriticalSection(&context->mux);
1818
1819 WINPR_ASSERT(context->GetSurfaceData);
1820 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1821
1822 if (!surface)
1823 goto fail;
1824
1825 if (surface->outputMapped)
1826 {
1827 WLog_WARN(TAG, "surface already outputMapped when trying to set windowMapped");
1828 goto fail;
1829 }
1830
1831 if (surface->windowMapped)
1832 {
1833 if (surface->windowId != surfaceToWindow->windowId)
1834 {
1835 WLog_WARN(TAG, "surface windowId mismatch, has %" PRIu64 ", expected %" PRIu64,
1836 surface->windowId, surfaceToWindow->windowId);
1837 goto fail;
1838 }
1839 }
1840 surface->windowMapped = TRUE;
1841
1842 surface->windowId = surfaceToWindow->windowId;
1843 surface->mappedWidth = surfaceToWindow->mappedWidth;
1844 surface->mappedHeight = surfaceToWindow->mappedHeight;
1845 surface->outputTargetWidth = surfaceToWindow->mappedWidth;
1846 surface->outputTargetHeight = surfaceToWindow->mappedHeight;
1847 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1848 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1849fail:
1850 LeaveCriticalSection(&context->mux);
1851 return rc;
1852}
1853
1854static UINT
1855gdi_MapSurfaceToScaledWindow(RdpgfxClientContext* context,
1856 const RDPGFX_MAP_SURFACE_TO_SCALED_WINDOW_PDU* surfaceToWindow)
1857{
1858 UINT rc = ERROR_INTERNAL_ERROR;
1859 gdiGfxSurface* surface = nullptr;
1860 EnterCriticalSection(&context->mux);
1861
1862 WINPR_ASSERT(context->GetSurfaceData);
1863 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1864
1865 if (!surface)
1866 goto fail;
1867
1868 if (surface->outputMapped)
1869 {
1870 WLog_WARN(TAG, "surface already outputMapped when trying to set windowMapped");
1871 goto fail;
1872 }
1873
1874 if (surface->windowMapped)
1875 {
1876 if (surface->windowId != surfaceToWindow->windowId)
1877 {
1878 WLog_WARN(TAG, "surface windowId mismatch, has %" PRIu64 ", expected %" PRIu64,
1879 surface->windowId, surfaceToWindow->windowId);
1880 goto fail;
1881 }
1882 }
1883 surface->windowMapped = TRUE;
1884
1885 surface->windowId = surfaceToWindow->windowId;
1886 surface->mappedWidth = surfaceToWindow->mappedWidth;
1887 surface->mappedHeight = surfaceToWindow->mappedHeight;
1888 surface->outputTargetWidth = surfaceToWindow->targetWidth;
1889 surface->outputTargetHeight = surfaceToWindow->targetHeight;
1890 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1891 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1892fail:
1893 LeaveCriticalSection(&context->mux);
1894 return rc;
1895}
1896
1897BOOL gdi_graphics_pipeline_init(rdpGdi* gdi, RdpgfxClientContext* gfx)
1898{
1899 return gdi_graphics_pipeline_init_ex(gdi, gfx, nullptr, nullptr, nullptr);
1900}
1901
1902BOOL gdi_graphics_pipeline_init_ex(rdpGdi* gdi, RdpgfxClientContext* gfx,
1903 pcRdpgfxMapWindowForSurface map,
1904 pcRdpgfxUnmapWindowForSurface unmap,
1905 pcRdpgfxUpdateSurfaceArea update)
1906{
1907 if (!gdi || !gfx || !gdi->context || !gdi->context->settings)
1908 return FALSE;
1909
1910 rdpContext* context = gdi->context;
1911 rdpSettings* settings = context->settings;
1912
1913 gdi->gfx = gfx;
1914 gfx->custom = (void*)gdi;
1915 gfx->ResetGraphics = gdi_ResetGraphics;
1916 gfx->StartFrame = gdi_StartFrame;
1917 gfx->EndFrame = gdi_EndFrame;
1918 gfx->SurfaceCommand = gdi_SurfaceCommand;
1919 gfx->DeleteEncodingContext = gdi_DeleteEncodingContext;
1920 gfx->CreateSurface = gdi_CreateSurface;
1921 gfx->DeleteSurface = gdi_DeleteSurface;
1922 gfx->SolidFill = gdi_SolidFill;
1923 gfx->SurfaceToSurface = gdi_SurfaceToSurface;
1924 gfx->SurfaceToCache = gdi_SurfaceToCache;
1925 gfx->CacheToSurface = gdi_CacheToSurface;
1926 gfx->CacheImportReply = gdi_CacheImportReply;
1927 gfx->ImportCacheEntry = gdi_ImportCacheEntry;
1928 gfx->ExportCacheEntry = gdi_ExportCacheEntry;
1929 gfx->EvictCacheEntry = gdi_EvictCacheEntry;
1930 gfx->MapSurfaceToOutput = gdi_MapSurfaceToOutput;
1931 gfx->MapSurfaceToWindow = gdi_MapSurfaceToWindow;
1932 gfx->MapSurfaceToScaledOutput = gdi_MapSurfaceToScaledOutput;
1933 gfx->MapSurfaceToScaledWindow = gdi_MapSurfaceToScaledWindow;
1934 gfx->UpdateSurfaces = gdi_UpdateSurfaces;
1935 gfx->MapWindowForSurface = map;
1936 gfx->UnmapWindowForSurface = unmap;
1937 gfx->UpdateSurfaceArea = update;
1938
1939 if (!freerdp_settings_get_bool(settings, FreeRDP_DeactivateClientDecoding))
1940 {
1941 const UINT32 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
1942 const UINT32 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
1943 const UINT32 flags = freerdp_settings_get_uint32(settings, FreeRDP_ThreadingFlags);
1944
1945 gfx->codecs = freerdp_client_codecs_new(flags);
1946 if (!gfx->codecs)
1947 return FALSE;
1948 if (!freerdp_client_codecs_prepare(gfx->codecs, FREERDP_CODEC_ALL, w, h))
1949 return FALSE;
1950 }
1951 InitializeCriticalSection(&gfx->mux);
1952 PROFILER_CREATE(gfx->SurfaceProfiler, "GFX-PROFILER")
1953
1954
1960 gdi->graphicsReset = TRUE;
1961 if (freerdp_settings_get_bool(settings, FreeRDP_DeactivateClientDecoding))
1962 {
1963 gfx->UpdateSurfaceArea = nullptr;
1964 gfx->UpdateSurfaces = nullptr;
1965 gfx->SurfaceCommand = nullptr;
1966 }
1967
1968 return TRUE;
1969}
1970
1971void gdi_graphics_pipeline_uninit(rdpGdi* gdi, RdpgfxClientContext* gfx)
1972{
1973 if (gdi)
1974 gdi->gfx = nullptr;
1975
1976 if (!gfx)
1977 return;
1978
1979 gfx->custom = nullptr;
1980 freerdp_client_codecs_free(gfx->codecs);
1981 gfx->codecs = nullptr;
1982 DeleteCriticalSection(&gfx->mux);
1983 PROFILER_PRINT_HEADER
1984 PROFILER_PRINT(gfx->SurfaceProfiler)
1985 PROFILER_PRINT_FOOTER
1986 PROFILER_FREE(gfx->SurfaceProfiler)
1987}
1988
1989const char* rdpgfx_caps_version_str(UINT32 capsVersion)
1990{
1991 switch (capsVersion)
1992 {
1993 case RDPGFX_CAPVERSION_8:
1994 return "RDPGFX_CAPVERSION_8";
1995 case RDPGFX_CAPVERSION_81:
1996 return "RDPGFX_CAPVERSION_81";
1997 case RDPGFX_CAPVERSION_10:
1998 return "RDPGFX_CAPVERSION_10";
1999 case RDPGFX_CAPVERSION_101:
2000 return "RDPGFX_CAPVERSION_101";
2001 case RDPGFX_CAPVERSION_102:
2002 return "RDPGFX_CAPVERSION_102";
2003 case RDPGFX_CAPVERSION_103:
2004 return "RDPGFX_CAPVERSION_103";
2005 case RDPGFX_CAPVERSION_104:
2006 return "RDPGFX_CAPVERSION_104";
2007 case RDPGFX_CAPVERSION_105:
2008 return "RDPGFX_CAPVERSION_105";
2009 case RDPGFX_CAPVERSION_106:
2010 return "RDPGFX_CAPVERSION_106";
2011 case RDPGFX_CAPVERSION_106_ERR:
2012 return "RDPGFX_CAPVERSION_106_ERR";
2013 case RDPGFX_CAPVERSION_107:
2014 return "RDPGFX_CAPVERSION_107";
2015 default:
2016 return "RDPGFX_CAPVERSION_UNKNOWN";
2017 }
2018}
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_codecs_flags(const rdpSettings *settings)
helper function to get a mask of supported codec flags.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 val)
Sets a UINT32 settings value.
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
Definition persistent.h:70