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