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