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