22#include <freerdp/config.h>
24#include "../core/update.h"
26#include <winpr/assert.h>
27#include <winpr/cast.h>
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>
36#define TAG FREERDP_TAG("gdi")
38static BOOL is_rect_valid(
const RECTANGLE_16* rect,
size_t width,
size_t height)
42 if ((rect->left > rect->right) || (rect->right > width))
44 if ((rect->top > rect->bottom) || (rect->bottom > height))
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))
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);
66 if (rect.left > surface->width)
68 if (rect.right > surface->width)
70 if (rect.top > surface->height)
72 if (rect.bottom > surface->height)
78static DWORD gfx_align_scanline(DWORD widthInBytes, DWORD alignment)
80 const UINT32 align = alignment;
81 const UINT32 pad = align - (widthInBytes % alignment);
82 UINT32 scanline = widthInBytes;
95static UINT gdi_ResetGraphics(RdpgfxClientContext* context,
98 UINT rc = ERROR_INTERNAL_ERROR;
100 UINT16* pSurfaceIds =
nullptr;
102 WINPR_ASSERT(context);
103 WINPR_ASSERT(resetGraphics);
105 rdpGdi* gdi = (rdpGdi*)context->custom;
108 rdpUpdate* update = gdi->context->update;
109 WINPR_ASSERT(update);
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;
117 WLog_DBG(TAG,
"new size: %" PRIu32
"x%" PRIu32, DesktopWidth, DesktopHeight);
126 WINPR_ASSERT(update->DesktopResize);
127 if (!update->DesktopResize(gdi->context))
131 WINPR_ASSERT(context->GetSurfaceIds);
132 rc = context->GetSurfaceIds(context, &pSurfaceIds, &count);
133 if (rc != CHANNEL_RC_OK)
136 for (UINT32 index = 0; index < count; index++)
138 WINPR_ASSERT(context->GetSurfaceData);
139 gdiGfxSurface* surface =
140 (gdiGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
145 memset(surface->data, 0xFF, (
size_t)surface->scanline * surface->height);
146 region16_clear(&surface->invalidRegion);
153 const UINT32 width = (UINT32)MAX(0, gdi->width);
154 const UINT32 height = (UINT32)MAX(0, gdi->height);
156 if (!freerdp_client_codecs_reset(
161 if (!freerdp_client_codecs_reset(
170 LeaveCriticalSection(&context->mux);
174static UINT gdi_OutputUpdate(rdpGdi* gdi, gdiGfxSurface* surface)
176 UINT rc = ERROR_INTERNAL_ERROR;
182 rdpUpdate* update =
nullptr;
185 WINPR_ASSERT(gdi->context);
186 WINPR_ASSERT(surface);
188 update = gdi->context->update;
189 WINPR_ASSERT(update);
191 if (gdi->suppressOutput)
192 return CHANNEL_RC_OK;
194 surfaceX = surface->outputOriginX;
195 surfaceY = surface->outputOriginY;
196 surfaceRect.left = 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),
204 const double sx = surface->outputTargetWidth / (double)surface->mappedWidth;
205 const double sy = surface->outputTargetHeight / (double)surface->mappedHeight;
207 rects = region16_rects(&surface->invalidRegion, &nbRects);
208 if (!rects || (nbRects == 0))
214 if (!update_begin_paint(update))
217 for (UINT32 i = 0; i < nbRects; i++)
219 const UINT32 nXSrc = rects[i].left;
220 const UINT32 nYSrc = rects[i].top;
221 const UINT32 nXDst = (UINT32)MIN(surfaceX + nXSrc * sx, gdi->width - 1);
222 const UINT32 nYDst = (UINT32)MIN(surfaceY + nYSrc * sy, gdi->height - 1);
223 const UINT32 swidth = rects[i].right - rects[i].left;
224 const UINT32 sheight = rects[i].bottom - rects[i].top;
225 const UINT32 dwidth = MIN((UINT32)(swidth * sx), (UINT32)gdi->width - nXDst);
226 const UINT32 dheight = MIN((UINT32)(sheight * sy), (UINT32)gdi->height - nYDst);
228 if (!freerdp_image_scale(gdi->primary_buffer, gdi->dstFormat, gdi->stride, nXDst, nYDst,
229 dwidth, dheight, surface->data, surface->format, surface->scanline,
230 nXSrc, nYSrc, swidth, sheight))
232 rc = CHANNEL_RC_NULL_DATA;
236 if (!gdi_InvalidateRegion(gdi->primary->hdc, (INT32)nXDst, (INT32)nYDst, (INT32)dwidth,
244 if (!update_end_paint(update))
245 rc = ERROR_INTERNAL_ERROR;
248 region16_clear(&(surface->invalidRegion));
252static UINT gdi_WindowUpdate(RdpgfxClientContext* context, gdiGfxSurface* surface)
254 WINPR_ASSERT(context);
255 WINPR_ASSERT(surface);
256 return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateWindowFromSurface, context, surface);
259static UINT gdi_UpdateSurfaces(RdpgfxClientContext* context)
262 UINT16* pSurfaceIds =
nullptr;
264 WINPR_ASSERT(context);
266 rdpGdi* gdi = (rdpGdi*)context->custom;
269 EnterCriticalSection(&context->mux);
271 WINPR_ASSERT(context->GetSurfaceIds);
272 UINT status = context->GetSurfaceIds(context, &pSurfaceIds, &count);
273 if (status != CHANNEL_RC_OK)
276 for (UINT32 index = 0; index < count; index++)
278 WINPR_ASSERT(context->GetSurfaceData);
279 gdiGfxSurface* surface =
280 (gdiGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
286 if (context->UpdateSurfaceArea)
288 if (surface->handleInUpdateSurfaceArea)
292 if (surface->outputMapped)
293 status = gdi_OutputUpdate(gdi, surface);
294 else if (surface->windowMapped)
295 status = gdi_WindowUpdate(context, surface);
297 if (status != CHANNEL_RC_OK)
303 LeaveCriticalSection(&context->mux);
314 rdpGdi* gdi =
nullptr;
316 WINPR_ASSERT(context);
317 WINPR_ASSERT(startFrame);
319 gdi = (rdpGdi*)context->custom;
321 gdi->inGfxFrame = TRUE;
322 gdi->frameId = startFrame->frameId;
323 return CHANNEL_RC_OK;
326static UINT gdi_call_update_surfaces(RdpgfxClientContext* context)
328 WINPR_ASSERT(context);
329 return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaces, context);
337static UINT gdi_EndFrame(RdpgfxClientContext* context,
340 WINPR_ASSERT(context);
341 WINPR_ASSERT(endFrame);
343 rdpGdi* gdi = (rdpGdi*)context->custom;
345 const UINT status = gdi_call_update_surfaces(context);
346 gdi->inGfxFrame = FALSE;
350static UINT gdi_interFrameUpdate(rdpGdi* gdi, RdpgfxClientContext* context)
353 UINT status = CHANNEL_RC_OK;
354 if (!gdi->inGfxFrame)
355 status = gdi_call_update_surfaces(context);
364static UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, RdpgfxClientContext* context,
367 UINT status = CHANNEL_RC_OK;
368 gdiGfxSurface* surface =
nullptr;
373 WINPR_ASSERT(context);
376 WINPR_ASSERT(context->GetSurfaceData);
378 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
382 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
383 return ERROR_NOT_FOUND;
386 if (!is_within_surface(surface, cmd))
387 return ERROR_INVALID_DATA;
389 bpp = FreeRDPGetBytesPerPixel(cmd->format);
390 size = 1ull * bpp * cmd->width * cmd->height;
391 if (cmd->length < size)
393 WLog_ERR(TAG,
"Not enough data, got %" PRIu32
", expected %" PRIuz, cmd->length, size);
394 return ERROR_INVALID_DATA;
397 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline, cmd->left,
398 cmd->top, cmd->width, cmd->height, cmd->data, cmd->format, 0,
399 0, 0,
nullptr, FREERDP_FLIP_NONE))
400 return ERROR_INTERNAL_ERROR;
402 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
403 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
404 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
405 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
406 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
408 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
411 if (status != CHANNEL_RC_OK)
414 status = gdi_interFrameUpdate(gdi, context);
420#if defined(WITH_GFX_AV1)
421static UINT gdi_SurfaceCommand_AV1(rdpGdi* gdi, RdpgfxClientContext* context,
425 UINT status = CHANNEL_RC_OK;
426 gdiGfxSurface* surface =
nullptr;
430 WINPR_ASSERT(context);
433 WINPR_ASSERT(context->GetSurfaceData);
435 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
439 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
440 return ERROR_NOT_FOUND;
445 surface->av1 = freerdp_av1_context_new(FALSE);
449 WLog_ERR(TAG,
"unable to create av1 context");
450 return ERROR_NOT_ENOUGH_MEMORY;
453 if (!freerdp_av1_context_reset(surface->av1, surface->width, surface->height))
454 return ERROR_INTERNAL_ERROR;
458 return ERROR_NOT_SUPPORTED;
460 if (!is_within_surface(surface, cmd))
461 return ERROR_INVALID_DATA;
466 return ERROR_INTERNAL_ERROR;
469 rc = freerdp_av1_decompress(surface->av1, bs->data, bs->length, surface->data, surface->format,
470 surface->scanline, surface->width, surface->height,
471 meta->regionRects, meta->numRegionRects);
475 WLog_WARN(TAG,
"freerdp_av1_decompress failure: %" PRId32
", ignoring update.", rc);
476 return CHANNEL_RC_OK;
479 for (UINT32 i = 0; i < meta->numRegionRects; i++)
481 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
482 &(meta->regionRects[i])))
486 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
487 meta->numRegionRects, meta->regionRects);
489 if (status != CHANNEL_RC_OK)
492 status = gdi_interFrameUpdate(gdi, context);
504static UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, RdpgfxClientContext* context,
507 UINT status = ERROR_INTERNAL_ERROR;
508 gdiGfxSurface* surface =
nullptr;
513 WINPR_ASSERT(context);
516 WINPR_ASSERT(context->GetSurfaceData);
518 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
522 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
523 return ERROR_NOT_FOUND;
526 if (!is_within_surface(surface, cmd))
527 return ERROR_INVALID_DATA;
529 WINPR_ASSERT(surface->codecs);
530 rfx_context_set_pixel_format(surface->codecs->rfx, cmd->format);
531 region16_init(&invalidRegion);
533 if (!rfx_process_message(surface->codecs->rfx, cmd->data, cmd->length, cmd->left, cmd->top,
534 surface->data, surface->format, surface->scanline, surface->height,
537 WLog_ERR(TAG,
"Failed to process RemoteFX message");
541 rects = region16_rects(&invalidRegion, &nrRects);
542 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
545 if (status != CHANNEL_RC_OK)
548 for (UINT32 x = 0; x < nrRects; x++)
550 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]))
554 status = gdi_interFrameUpdate(gdi, context);
557 region16_uninit(&invalidRegion);
566static UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context,
570 UINT status = CHANNEL_RC_OK;
571 gdiGfxSurface* surface =
nullptr;
574 WINPR_ASSERT(context);
577 WINPR_ASSERT(context->GetSurfaceData);
579 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
583 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
584 return ERROR_NOT_FOUND;
587 if (!is_within_surface(surface, cmd))
588 return ERROR_INVALID_DATA;
590 WINPR_ASSERT(surface->codecs);
591 rc = clear_decompress(surface->codecs->clear, cmd->data, cmd->length, cmd->width, cmd->height,
592 surface->data, surface->format, surface->scanline, cmd->left, cmd->top,
593 surface->width, surface->height, &gdi->palette);
597 WLog_ERR(TAG,
"clear_decompress failure: %" PRId32
"", rc);
598 return ERROR_INTERNAL_ERROR;
601 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
602 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
603 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
604 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
605 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
607 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
610 if (status != CHANNEL_RC_OK)
613 status = gdi_interFrameUpdate(gdi, context);
624static UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context,
627 UINT status = CHANNEL_RC_OK;
628 BYTE* DstData =
nullptr;
629 gdiGfxSurface* surface =
nullptr;
632 WINPR_ASSERT(context);
635 WINPR_ASSERT(context->GetSurfaceData);
637 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
641 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
642 return ERROR_NOT_FOUND;
645 DstData = surface->data;
647 if (!is_within_surface(surface, cmd))
648 return ERROR_INVALID_DATA;
650 if (!freerdp_bitmap_decompress_planar(surface->codecs->planar, cmd->data, cmd->length,
651 cmd->width, cmd->height, DstData, surface->format,
652 surface->scanline, cmd->left, cmd->top, cmd->width,
654 return ERROR_INTERNAL_ERROR;
656 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
657 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
658 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
659 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
660 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
662 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
665 if (status != CHANNEL_RC_OK)
668 status = gdi_interFrameUpdate(gdi, context);
679static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, RdpgfxClientContext* context,
684 UINT status = CHANNEL_RC_OK;
685 gdiGfxSurface* surface =
nullptr;
689 WINPR_ASSERT(context);
692 WINPR_ASSERT(context->GetSurfaceData);
694 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
698 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
699 return ERROR_NOT_FOUND;
704 surface->h264 = h264_context_new(FALSE);
708 WLog_ERR(TAG,
"unable to create h264 context");
709 return ERROR_NOT_ENOUGH_MEMORY;
712 if (!h264_context_reset(surface->h264, surface->width, surface->height))
713 return ERROR_INTERNAL_ERROR;
717 return ERROR_NOT_SUPPORTED;
719 if (!is_within_surface(surface, cmd))
720 return ERROR_INVALID_DATA;
725 return ERROR_INTERNAL_ERROR;
728 rc = avc420_decompress(surface->h264, bs->data, bs->length, surface->data, surface->format,
729 surface->scanline, surface->width, surface->height, meta->regionRects,
730 meta->numRegionRects);
734 WLog_WARN(TAG,
"avc420_decompress failure: %" PRId32
", ignoring update.", rc);
735 return CHANNEL_RC_OK;
738 for (UINT32 i = 0; i < meta->numRegionRects; i++)
740 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
741 &(meta->regionRects[i])))
745 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
746 meta->numRegionRects, meta->regionRects);
748 if (status != CHANNEL_RC_OK)
751 status = gdi_interFrameUpdate(gdi, context);
756 return ERROR_NOT_SUPPORTED;
765static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context,
770 UINT status = CHANNEL_RC_OK;
771 gdiGfxSurface* surface =
nullptr;
778 WINPR_ASSERT(context);
781 WINPR_ASSERT(context->GetSurfaceData);
783 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
787 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
788 return ERROR_NOT_FOUND;
793 surface->h264 = h264_context_new(FALSE);
797 WLog_ERR(TAG,
"unable to create h264 context");
798 return ERROR_NOT_ENOUGH_MEMORY;
801 if (!h264_context_reset(surface->h264, surface->width, surface->height))
802 return ERROR_INTERNAL_ERROR;
806 return ERROR_NOT_SUPPORTED;
808 if (!is_within_surface(surface, cmd))
809 return ERROR_INVALID_DATA;
814 return ERROR_INTERNAL_ERROR;
816 avc1 = &bs->bitstream[0];
817 avc2 = &bs->bitstream[1];
820 rc = avc444_decompress(surface->h264, bs->LC, meta1->regionRects, meta1->numRegionRects,
821 avc1->data, avc1->length, meta2->regionRects, meta2->numRegionRects,
822 avc2->data, avc2->length, surface->data, surface->format,
823 surface->scanline, surface->width, surface->height, cmd->codecId);
827 WLog_WARN(TAG,
"avc444_decompress failure: %" PRId32
", ignoring update.", rc);
828 return CHANNEL_RC_OK;
831 for (UINT32 i = 0; i < meta1->numRegionRects; i++)
833 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
834 &(meta1->regionRects[i])))
838 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
839 meta1->numRegionRects, meta1->regionRects);
841 if (status != CHANNEL_RC_OK)
844 for (UINT32 i = 0; i < meta2->numRegionRects; i++)
846 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
847 &(meta2->regionRects[i])))
851 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
852 meta2->numRegionRects, meta2->regionRects);
854 if (status != CHANNEL_RC_OK)
857 status = gdi_interFrameUpdate(gdi, context);
862 return ERROR_NOT_SUPPORTED;
866static BOOL gdi_apply_alpha(BYTE* data, UINT32 format, UINT32 stride,
RECTANGLE_16* rect,
867 UINT32 startOffsetX, UINT32 count, BYTE a)
871 const UINT32 bpp = FreeRDPGetBytesPerPixel(format);
874 for (
size_t y = rect->top; y < rect->bottom; y++)
876 BYTE* line = &data[y * stride];
878 for (
size_t x = first ? rect->left + startOffsetX : rect->left; x < rect->right; x++)
884 if (written == count)
887 BYTE* src = &line[x * bpp];
888 UINT32 color = FreeRDPReadColor(src, format);
889 FreeRDPSplitColor(color, format, &r, &g, &b,
nullptr,
nullptr);
890 color = FreeRDPGetColor(format, r, g, b, a);
891 FreeRDPWriteColor(src, format, color);
905static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context,
908 UINT status = CHANNEL_RC_OK;
910 UINT16 compressed = 0;
911 gdiGfxSurface* surface =
nullptr;
916 WINPR_ASSERT(context);
919 s = Stream_StaticConstInit(&buffer, cmd->data, cmd->length);
921 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
922 return ERROR_INVALID_DATA;
924 WINPR_ASSERT(context->GetSurfaceData);
926 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
930 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
931 return ERROR_NOT_FOUND;
934 if (!is_within_surface(surface, cmd))
935 return ERROR_INVALID_DATA;
937 Stream_Read_UINT16(s, alphaSig);
938 Stream_Read_UINT16(s, compressed);
940 if (alphaSig != 0x414C)
941 return ERROR_INVALID_DATA;
945 if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, cmd->height, cmd->width))
946 return ERROR_INVALID_DATA;
948 for (
size_t y = cmd->top; y < cmd->top + cmd->height; y++)
950 BYTE* line = &surface->data[y * surface->scanline];
952 for (
size_t x = cmd->left; x < cmd->left + cmd->width; x++)
959 BYTE* src = &line[x * FreeRDPGetBytesPerPixel(surface->format)];
960 Stream_Read_UINT8(s, a);
961 color = FreeRDPReadColor(src, surface->format);
962 FreeRDPSplitColor(color, surface->format, &r, &g, &b,
nullptr,
nullptr);
963 color = FreeRDPGetColor(surface->format, r, g, b, a);
964 FreeRDPWriteColor(src, surface->format, color);
970 UINT32 startOffsetX = 0;
972 rect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
973 rect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
974 rect.right = (UINT16)MIN(UINT16_MAX, cmd->left + cmd->width);
975 rect.bottom = (UINT16)MIN(UINT16_MAX, cmd->top + cmd->height);
977 while (rect.top < rect.bottom)
982 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
983 return ERROR_INVALID_DATA;
985 Stream_Read_UINT8(s, a);
986 Stream_Read_UINT8(s, count);
990 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
991 return ERROR_INVALID_DATA;
993 Stream_Read_UINT16(s, count);
997 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
998 return ERROR_INVALID_DATA;
1000 Stream_Read_UINT32(s, count);
1004 if (!gdi_apply_alpha(surface->data, surface->format, surface->scanline, &rect,
1005 startOffsetX, count, a))
1006 return ERROR_INTERNAL_ERROR;
1008 startOffsetX += count;
1010 while (startOffsetX >= cmd->width)
1012 startOffsetX -= cmd->width;
1018 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
1019 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
1020 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
1021 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
1022 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
1024 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
1027 if (status != CHANNEL_RC_OK)
1030 status = gdi_interFrameUpdate(gdi, context);
1036#if defined(WITH_GFX_FRAME_DUMP)
1039 static UINT64 xxx = 0;
1040 const char* path =
"/tmp/dump/";
1042 char fname[1024] = WINPR_C_ARRAY_INIT;
1044 snprintf(fname,
sizeof(fname),
"%s/%08" PRIx64
".raw", path, xxx++);
1045 FILE* fp = fopen(fname,
"w");
1048 (void)fprintf(fp,
"frameid: %" PRIu32
"\n", frameId);
1049 (void)fprintf(fp,
"surfaceId: %" PRIu32
"\n", cmd->surfaceId);
1050 (void)fprintf(fp,
"codecId: %" PRIu32
"\n", cmd->codecId);
1051 (void)fprintf(fp,
"contextId: %" PRIu32
"\n", cmd->contextId);
1052 (void)fprintf(fp,
"format: %" PRIu32
"\n", cmd->format);
1053 (void)fprintf(fp,
"left: %" PRIu32
"\n", cmd->left);
1054 (void)fprintf(fp,
"top: %" PRIu32
"\n", cmd->top);
1055 (void)fprintf(fp,
"right: %" PRIu32
"\n", cmd->right);
1056 (void)fprintf(fp,
"bottom: %" PRIu32
"\n", cmd->bottom);
1057 (void)fprintf(fp,
"width: %" PRIu32
"\n", cmd->width);
1058 (void)fprintf(fp,
"height: %" PRIu32
"\n", cmd->height);
1059 (void)fprintf(fp,
"length: %" PRIu32
"\n", cmd->length);
1061 char* bdata = crypto_base64_encode_ex(cmd->data, cmd->length, FALSE);
1062 (void)fprintf(fp,
"data: %s\n", bdata);
1073static UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context,
1077 UINT status = ERROR_INTERNAL_ERROR;
1078 gdiGfxSurface* surface =
nullptr;
1088 WINPR_ASSERT(context);
1090 const UINT16 surfaceId = (UINT16)MIN(UINT16_MAX, cmd->surfaceId);
1092 WINPR_ASSERT(context->GetSurfaceData);
1093 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceId);
1097 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
1098 return ERROR_NOT_FOUND;
1101 if (!is_within_surface(surface, cmd))
1102 return ERROR_INVALID_DATA;
1104 WINPR_ASSERT(surface->codecs);
1105 rc = progressive_create_surface_context(surface->codecs->progressive, surfaceId, surface->width,
1110 WLog_ERR(TAG,
"progressive_create_surface_context failure: %" PRId32
"", rc);
1111 return ERROR_INTERNAL_ERROR;
1114 region16_init(&invalidRegion);
1116 rc = progressive_decompress(surface->codecs->progressive, cmd->data, cmd->length, surface->data,
1117 surface->format, surface->scanline, cmd->left, cmd->top,
1118 &invalidRegion, surfaceId, gdi->frameId);
1122 WLog_ERR(TAG,
"progressive_decompress failure: %" PRId32
"", rc);
1126 rects = region16_rects(&invalidRegion, &nrRects);
1127 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1130 if (status != CHANNEL_RC_OK)
1133 status = ERROR_INTERNAL_ERROR;
1134 for (UINT32 x = 0; x < nrRects; x++)
1136 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]))
1140 status = gdi_interFrameUpdate(gdi, context);
1144 region16_uninit(&invalidRegion);
1155 UINT status = CHANNEL_RC_OK;
1156 rdpGdi* gdi =
nullptr;
1158 if (!context || !cmd)
1159 return ERROR_INVALID_PARAMETER;
1161 gdi = (rdpGdi*)context->custom;
1163 EnterCriticalSection(&context->mux);
1164 const UINT16 codecId = WINPR_ASSERTING_INT_CAST(UINT16, cmd->codecId);
1165 WLog_Print(gdi->log, WLOG_TRACE,
1166 "surfaceId=%" PRIu32
", codec=%s [%" PRIu32
"], contextId=%" PRIu32
", format=%s, "
1167 "left=%" PRIu32
", top=%" PRIu32
", right=%" PRIu32
", bottom=%" PRIu32
1168 ", width=%" PRIu32
", height=%" PRIu32
" "
1169 "length=%" PRIu32
", data=%p, extra=%p",
1170 cmd->surfaceId, rdpgfx_get_codec_id_string(codecId), cmd->codecId, cmd->contextId,
1171 FreeRDPGetColorFormatName(cmd->format), cmd->left, cmd->top, cmd->right, cmd->bottom,
1172 cmd->width, cmd->height, cmd->length, (
void*)cmd->data, (
void*)cmd->extra);
1173#if defined(WITH_GFX_FRAME_DUMP)
1174 dump_cmd(cmd, gdi->frameId);
1179 case RDPGFX_CODECID_UNCOMPRESSED:
1180 status = gdi_SurfaceCommand_Uncompressed(gdi, context, cmd);
1183#if defined(WITH_GFX_AV1)
1184 case RDPGFX_CODECID_AV1:
1185 status = gdi_SurfaceCommand_AV1(gdi, context, cmd);
1189 case RDPGFX_CODECID_CAVIDEO:
1190 status = gdi_SurfaceCommand_RemoteFX(gdi, context, cmd);
1193 case RDPGFX_CODECID_CLEARCODEC:
1194 status = gdi_SurfaceCommand_ClearCodec(gdi, context, cmd);
1197 case RDPGFX_CODECID_PLANAR:
1198 status = gdi_SurfaceCommand_Planar(gdi, context, cmd);
1201 case RDPGFX_CODECID_AVC420:
1202 status = gdi_SurfaceCommand_AVC420(gdi, context, cmd);
1205 case RDPGFX_CODECID_AVC444v2:
1206 case RDPGFX_CODECID_AVC444:
1207 status = gdi_SurfaceCommand_AVC444(gdi, context, cmd);
1210 case RDPGFX_CODECID_ALPHA:
1211 status = gdi_SurfaceCommand_Alpha(gdi, context, cmd);
1214 case RDPGFX_CODECID_CAPROGRESSIVE:
1215 status = gdi_SurfaceCommand_Progressive(gdi, context, cmd);
1218 case RDPGFX_CODECID_CAPROGRESSIVE_V2:
1219 WLog_WARN(TAG,
"SurfaceCommand %s [0x%08" PRIX16
"] not implemented",
1220 rdpgfx_get_codec_id_string(codecId), codecId);
1224 WLog_WARN(TAG,
"Invalid SurfaceCommand %s [0x%08" PRIX16
"]",
1225 rdpgfx_get_codec_id_string(codecId), codecId);
1229 LeaveCriticalSection(&context->mux);
1239gdi_DeleteEncodingContext(RdpgfxClientContext* context,
1242 WINPR_ASSERT(context);
1243 WINPR_ASSERT(deleteEncodingContext);
1244 WINPR_UNUSED(context);
1245 WINPR_UNUSED(deleteEncodingContext);
1246 return CHANNEL_RC_OK;
1254static UINT gdi_CreateSurface(RdpgfxClientContext* context,
1257 UINT rc = ERROR_INTERNAL_ERROR;
1258 gdiGfxSurface* surface =
nullptr;
1259 rdpGdi* gdi =
nullptr;
1260 WINPR_ASSERT(context);
1261 WINPR_ASSERT(createSurface);
1262 gdi = (rdpGdi*)context->custom;
1264 WINPR_ASSERT(gdi->context);
1265 EnterCriticalSection(&context->mux);
1266 surface = (gdiGfxSurface*)calloc(1,
sizeof(gdiGfxSurface));
1273 WINPR_ASSERT(context->codecs);
1274 surface->codecs = context->codecs;
1276 if (!surface->codecs)
1283 surface->surfaceId = createSurface->surfaceId;
1284 surface->width = gfx_align_scanline(createSurface->width, 16);
1285 surface->height = gfx_align_scanline(createSurface->height, 16);
1286 surface->mappedWidth = createSurface->width;
1287 surface->mappedHeight = createSurface->height;
1288 surface->outputTargetWidth = createSurface->width;
1289 surface->outputTargetHeight = createSurface->height;
1291 switch (createSurface->pixelFormat)
1293 case GFX_PIXEL_FORMAT_ARGB_8888:
1294 surface->format = PIXEL_FORMAT_BGRA32;
1297 case GFX_PIXEL_FORMAT_XRGB_8888:
1298 surface->format = PIXEL_FORMAT_BGRX32;
1306 surface->scanline = gfx_align_scanline(surface->width * 4UL, 16);
1307 surface->data = (BYTE*)winpr_aligned_malloc(1ull * surface->scanline * surface->height, 16);
1315 memset(surface->data, 0xFF, (
size_t)surface->scanline * surface->height);
1316 region16_init(&surface->invalidRegion);
1318 WINPR_ASSERT(context->SetSurfaceData);
1319 rc = context->SetSurfaceData(context, surface->surfaceId, (
void*)surface);
1321 LeaveCriticalSection(&context->mux);
1330static UINT gdi_DeleteSurface(RdpgfxClientContext* context,
1333 UINT rc = CHANNEL_RC_OK;
1334 UINT res = ERROR_INTERNAL_ERROR;
1335 rdpCodecs* codecs =
nullptr;
1336 gdiGfxSurface* surface =
nullptr;
1337 EnterCriticalSection(&context->mux);
1339 WINPR_ASSERT(context->GetSurfaceData);
1340 surface = (gdiGfxSurface*)context->GetSurfaceData(context, deleteSurface->surfaceId);
1344 if (surface->windowMapped)
1345 rc = IFCALLRESULT(CHANNEL_RC_OK, context->UnmapWindowForSurface, context,
1349 h264_context_free(surface->h264);
1351#if defined(WITH_GFX_AV1)
1352 freerdp_av1_context_free(surface->av1);
1354 region16_uninit(&surface->invalidRegion);
1355 codecs = surface->codecs;
1356 winpr_aligned_free(surface->data);
1360 WINPR_ASSERT(context->SetSurfaceData);
1361 res = context->SetSurfaceData(context, deleteSurface->surfaceId,
nullptr);
1365 if (codecs && codecs->progressive)
1366 progressive_delete_surface_context(codecs->progressive, deleteSurface->surfaceId);
1368 LeaveCriticalSection(&context->mux);
1372static BOOL intersect_rect(
const RECTANGLE_16* rect,
const gdiGfxSurface* surface,
1376 WINPR_ASSERT(surface);
1377 WINPR_ASSERT(prect);
1379 if (rect->left > rect->right)
1381 if (rect->left > surface->width)
1383 if (rect->top > rect->bottom)
1385 if (rect->top > surface->height)
1387 prect->left = rect->left;
1388 prect->top = rect->top;
1390 prect->right = MIN(rect->right, WINPR_ASSERTING_INT_CAST(UINT16, surface->width));
1391 prect->bottom = MIN(rect->bottom, WINPR_ASSERTING_INT_CAST(UINT16, surface->height));
1402 UINT status = ERROR_INTERNAL_ERROR;
1405 rdpGdi* gdi = (rdpGdi*)context->custom;
1407 EnterCriticalSection(&context->mux);
1409 WINPR_ASSERT(context->GetSurfaceData);
1410 gdiGfxSurface* surface = (gdiGfxSurface*)context->GetSurfaceData(context, solidFill->surfaceId);
1416 const BYTE b = solidFill->fillPixel.B;
1417 const BYTE g = solidFill->fillPixel.G;
1418 const BYTE r = solidFill->fillPixel.R;
1425 const UINT32 color = FreeRDPGetColor(surface->format, r, g, b, a);
1426 for (UINT16 index = 0; index < solidFill->fillRectCount; index++)
1428 const RECTANGLE_16* rect = &(solidFill->fillRects[index]);
1430 if (!intersect_rect(rect, surface, &invalidRect))
1433 const UINT32 nWidth = invalidRect.right - invalidRect.left;
1434 const UINT32 nHeight = invalidRect.bottom - invalidRect.top;
1436 if (!freerdp_image_fill(surface->data, surface->format, surface->scanline,
1437 invalidRect.left, invalidRect.top, nWidth, nHeight, color))
1440 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
1446 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1447 solidFill->fillRectCount, solidFill->fillRects);
1449 if (status != CHANNEL_RC_OK)
1452 LeaveCriticalSection(&context->mux);
1454 return gdi_interFrameUpdate(gdi, context);
1456 LeaveCriticalSection(&context->mux);
1465static UINT gdi_SurfaceToSurface(RdpgfxClientContext* context,
1468 UINT status = ERROR_INTERNAL_ERROR;
1469 BOOL sameSurface = 0;
1472 gdiGfxSurface* surfaceSrc =
nullptr;
1473 gdiGfxSurface* surfaceDst =
nullptr;
1474 rdpGdi* gdi = (rdpGdi*)context->custom;
1475 EnterCriticalSection(&context->mux);
1476 rectSrc = &(surfaceToSurface->rectSrc);
1478 WINPR_ASSERT(context->GetSurfaceData);
1479 surfaceSrc = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdSrc);
1480 sameSurface = (surfaceToSurface->surfaceIdSrc == surfaceToSurface->surfaceIdDest);
1484 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdDest);
1486 surfaceDst = surfaceSrc;
1488 if (!surfaceSrc || !surfaceDst)
1491 if (!is_rect_valid(rectSrc, surfaceSrc->width, surfaceSrc->height))
1495 const UINT32 nWidth = rectSrc->right - rectSrc->left;
1496 const UINT32 nHeight = rectSrc->bottom - rectSrc->top;
1498 for (UINT16 index = 0; index < surfaceToSurface->destPtsCount; index++)
1500 const RDPGFX_POINT16* destPt = &surfaceToSurface->destPts[index];
1502 (UINT16)MIN(UINT16_MAX, destPt->x + nWidth),
1503 (UINT16)MIN(UINT16_MAX, destPt->y + nHeight) };
1504 if (!is_rect_valid(&rect, surfaceDst->width, surfaceDst->height))
1507 const UINT32 rwidth = rect.right - rect.left;
1508 const UINT32 rheight = rect.bottom - rect.top;
1509 if (!freerdp_image_copy(surfaceDst->data, surfaceDst->format, surfaceDst->scanline,
1510 destPt->x, destPt->y, rwidth, rheight, surfaceSrc->data,
1511 surfaceSrc->format, surfaceSrc->scanline, rectSrc->left,
1512 rectSrc->top,
nullptr, FREERDP_FLIP_NONE))
1516 if (!region16_union_rect(&surfaceDst->invalidRegion, &surfaceDst->invalidRegion,
1519 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1520 surfaceDst->surfaceId, 1, &invalidRect);
1522 if (status != CHANNEL_RC_OK)
1527 LeaveCriticalSection(&context->mux);
1529 return gdi_interFrameUpdate(gdi, context);
1531 LeaveCriticalSection(&context->mux);
1535static void gdi_GfxCacheEntryFree(gdiGfxCacheEntry* entry)
1543static gdiGfxCacheEntry* gdi_GfxCacheEntryNew(UINT64 cacheKey, UINT32 width, UINT32 height,
1546 gdiGfxCacheEntry* cacheEntry = (gdiGfxCacheEntry*)calloc(1,
sizeof(gdiGfxCacheEntry));
1550 cacheEntry->cacheKey = cacheKey;
1551 cacheEntry->width = width;
1552 cacheEntry->height = height;
1553 cacheEntry->format = format;
1555 const UINT32 bpp = MAX(4, FreeRDPGetBytesPerPixel(format));
1556 cacheEntry->scanline = gfx_align_scanline(cacheEntry->width * bpp, 16);
1558 if ((cacheEntry->width > 0) && (cacheEntry->height > 0))
1560 cacheEntry->data = (BYTE*)calloc(cacheEntry->height, cacheEntry->scanline);
1562 if (!cacheEntry->data)
1567 gdi_GfxCacheEntryFree(cacheEntry);
1576static UINT gdi_SurfaceToCache(RdpgfxClientContext* context,
1579 gdiGfxCacheEntry* cacheEntry =
nullptr;
1580 UINT rc = ERROR_INTERNAL_ERROR;
1581 EnterCriticalSection(&context->mux);
1584 WINPR_ASSERT(context->GetSurfaceData);
1585 gdiGfxSurface* surface =
1586 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToCache->surfaceId);
1591 if (!is_rect_valid(rect, surface->width, surface->height))
1594 cacheEntry = gdi_GfxCacheEntryNew(surfaceToCache->cacheKey, (UINT32)(rect->right - rect->left),
1595 (UINT32)(rect->bottom - rect->top), surface->format);
1600 if (!cacheEntry->data)
1603 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1604 0, 0, cacheEntry->width, cacheEntry->height, surface->data,
1605 surface->format, surface->scanline, rect->left, rect->top,
1606 nullptr, FREERDP_FLIP_NONE))
1611 WINPR_ASSERT(context->EvictCacheEntry);
1612 rc = context->EvictCacheEntry(context, &evict);
1613 if (rc != CHANNEL_RC_OK)
1617 WINPR_ASSERT(context->SetCacheSlotData);
1618 rc = context->SetCacheSlotData(context, surfaceToCache->cacheSlot, (
void*)cacheEntry);
1620 if (rc != CHANNEL_RC_OK)
1621 gdi_GfxCacheEntryFree(cacheEntry);
1622 LeaveCriticalSection(&context->mux);
1631static UINT gdi_CacheToSurface(RdpgfxClientContext* context,
1634 UINT status = ERROR_INTERNAL_ERROR;
1635 gdiGfxSurface* surface =
nullptr;
1636 gdiGfxCacheEntry* cacheEntry =
nullptr;
1638 rdpGdi* gdi = (rdpGdi*)context->custom;
1640 EnterCriticalSection(&context->mux);
1642 WINPR_ASSERT(context->GetSurfaceData);
1643 surface = (gdiGfxSurface*)context->GetSurfaceData(context, cacheToSurface->surfaceId);
1645 WINPR_ASSERT(context->GetCacheSlotData);
1646 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheToSurface->cacheSlot);
1648 if (!surface || !cacheEntry)
1651 for (UINT16 index = 0; index < cacheToSurface->destPtsCount; index++)
1655 (UINT16)MIN(UINT16_MAX, destPt->x + cacheEntry->width),
1656 (UINT16)MIN(UINT16_MAX, destPt->y + cacheEntry->height) };
1658 if (rectangle_is_empty(&rect))
1661 if (!is_rect_valid(&rect, surface->width, surface->height))
1664 const UINT32 w = rect.right - rect.left;
1665 const UINT32 h = rect.bottom - rect.top;
1666 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline,
1667 destPt->x, destPt->y, w, h, cacheEntry->data,
1668 cacheEntry->format, cacheEntry->scanline, 0, 0,
nullptr,
1673 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect))
1675 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1676 surface->surfaceId, 1, &invalidRect);
1678 if (status != CHANNEL_RC_OK)
1682 LeaveCriticalSection(&context->mux);
1684 return gdi_interFrameUpdate(gdi, context);
1687 LeaveCriticalSection(&context->mux);
1696static UINT gdi_CacheImportReply(RdpgfxClientContext* context,
1700 const UINT16* slots =
nullptr;
1701 UINT error = CHANNEL_RC_OK;
1703 slots = cacheImportReply->cacheSlots;
1704 count = cacheImportReply->importedEntriesCount;
1706 for (UINT16 index = 0; index < count; index++)
1708 UINT16 cacheSlot = slots[index];
1713 WINPR_ASSERT(context->GetCacheSlotData);
1714 gdiGfxCacheEntry* cacheEntry =
1715 (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1720 cacheEntry = gdi_GfxCacheEntryNew(cacheSlot, 0, 0, PIXEL_FORMAT_BGRX32);
1723 return ERROR_INTERNAL_ERROR;
1725 WINPR_ASSERT(context->SetCacheSlotData);
1726 error = context->SetCacheSlotData(context, cacheSlot, (
void*)cacheEntry);
1730 WLog_ERR(TAG,
"CacheImportReply: SetCacheSlotData failed with error %" PRIu32
"",
1732 gdi_GfxCacheEntryFree(cacheEntry);
1740static UINT gdi_ImportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1743 UINT error = ERROR_INTERNAL_ERROR;
1744 gdiGfxCacheEntry* cacheEntry =
nullptr;
1747 return CHANNEL_RC_OK;
1749 cacheEntry = gdi_GfxCacheEntryNew(importCacheEntry->key64, importCacheEntry->width,
1750 importCacheEntry->height, PIXEL_FORMAT_BGRX32);
1755 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1756 0, 0, cacheEntry->width, cacheEntry->height,
1757 importCacheEntry->data, PIXEL_FORMAT_BGRX32, 0, 0, 0,
1758 nullptr, FREERDP_FLIP_NONE))
1763 WINPR_ASSERT(context->EvictCacheEntry);
1764 error = context->EvictCacheEntry(context, &evict);
1766 if (error != CHANNEL_RC_OK)
1769 WINPR_ASSERT(context->SetCacheSlotData);
1770 error = context->SetCacheSlotData(context, cacheSlot, (
void*)cacheEntry);
1775 gdi_GfxCacheEntryFree(cacheEntry);
1776 WLog_ERR(TAG,
"ImportCacheEntry: SetCacheSlotData failed with error %" PRIu32
"", error);
1782static UINT gdi_ExportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1785 gdiGfxCacheEntry* cacheEntry =
nullptr;
1787 WINPR_ASSERT(context->GetCacheSlotData);
1788 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1792 exportCacheEntry->key64 = cacheEntry->cacheKey;
1793 exportCacheEntry->width = (UINT16)MIN(UINT16_MAX, cacheEntry->width);
1794 exportCacheEntry->height = (UINT16)MIN(UINT16_MAX, cacheEntry->height);
1795 exportCacheEntry->size = cacheEntry->width * cacheEntry->height * 4;
1796 exportCacheEntry->flags = 0;
1797 exportCacheEntry->data = cacheEntry->data;
1798 return CHANNEL_RC_OK;
1801 return ERROR_NOT_FOUND;
1809static UINT gdi_EvictCacheEntry(RdpgfxClientContext* context,
1812 gdiGfxCacheEntry* cacheEntry =
nullptr;
1813 UINT rc = ERROR_NOT_FOUND;
1815 WINPR_ASSERT(context);
1816 WINPR_ASSERT(evictCacheEntry);
1818 EnterCriticalSection(&context->mux);
1820 WINPR_ASSERT(context->GetCacheSlotData);
1821 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, evictCacheEntry->cacheSlot);
1823 gdi_GfxCacheEntryFree(cacheEntry);
1825 WINPR_ASSERT(context->SetCacheSlotData);
1826 rc = context->SetCacheSlotData(context, evictCacheEntry->cacheSlot,
nullptr);
1827 LeaveCriticalSection(&context->mux);
1836static UINT gdi_MapSurfaceToOutput(RdpgfxClientContext* context,
1839 UINT rc = ERROR_INTERNAL_ERROR;
1840 gdiGfxSurface* surface =
nullptr;
1841 EnterCriticalSection(&context->mux);
1843 WINPR_ASSERT(context->GetSurfaceData);
1844 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1849 if (surface->windowMapped)
1851 WLog_WARN(TAG,
"surface already windowMapped when trying to set outputMapped");
1855 surface->outputMapped = TRUE;
1856 surface->outputOriginX = surfaceToOutput->outputOriginX;
1857 surface->outputOriginY = surfaceToOutput->outputOriginY;
1858 surface->outputTargetWidth = surface->mappedWidth;
1859 surface->outputTargetHeight = surface->mappedHeight;
1860 region16_clear(&surface->invalidRegion);
1863 LeaveCriticalSection(&context->mux);
1868gdi_MapSurfaceToScaledOutput(RdpgfxClientContext* context,
1871 UINT rc = ERROR_INTERNAL_ERROR;
1872 gdiGfxSurface* surface =
nullptr;
1873 EnterCriticalSection(&context->mux);
1875 WINPR_ASSERT(context->GetSurfaceData);
1876 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1881 if (surface->windowMapped)
1883 WLog_WARN(TAG,
"surface already windowMapped when trying to set outputMapped");
1887 surface->outputMapped = TRUE;
1888 surface->outputOriginX = surfaceToOutput->outputOriginX;
1889 surface->outputOriginY = surfaceToOutput->outputOriginY;
1890 surface->outputTargetWidth = surfaceToOutput->targetWidth;
1891 surface->outputTargetHeight = surfaceToOutput->targetHeight;
1892 region16_clear(&surface->invalidRegion);
1895 LeaveCriticalSection(&context->mux);
1904static UINT gdi_MapSurfaceToWindow(RdpgfxClientContext* context,
1907 UINT rc = ERROR_INTERNAL_ERROR;
1908 gdiGfxSurface* surface =
nullptr;
1909 EnterCriticalSection(&context->mux);
1911 WINPR_ASSERT(context->GetSurfaceData);
1912 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1917 if (surface->outputMapped)
1919 WLog_WARN(TAG,
"surface already outputMapped when trying to set windowMapped");
1923 if (surface->windowMapped)
1925 if (surface->windowId != surfaceToWindow->windowId)
1927 WLog_WARN(TAG,
"surface windowId mismatch, has %" PRIu64
", expected %" PRIu64,
1928 surface->windowId, surfaceToWindow->windowId);
1932 surface->windowMapped = TRUE;
1934 surface->windowId = surfaceToWindow->windowId;
1935 surface->mappedWidth = surfaceToWindow->mappedWidth;
1936 surface->mappedHeight = surfaceToWindow->mappedHeight;
1937 surface->outputTargetWidth = surfaceToWindow->mappedWidth;
1938 surface->outputTargetHeight = surfaceToWindow->mappedHeight;
1939 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1940 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1942 LeaveCriticalSection(&context->mux);
1947gdi_MapSurfaceToScaledWindow(RdpgfxClientContext* context,
1950 UINT rc = ERROR_INTERNAL_ERROR;
1951 gdiGfxSurface* surface =
nullptr;
1952 EnterCriticalSection(&context->mux);
1954 WINPR_ASSERT(context->GetSurfaceData);
1955 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1960 if (surface->outputMapped)
1962 WLog_WARN(TAG,
"surface already outputMapped when trying to set windowMapped");
1966 if (surface->windowMapped)
1968 if (surface->windowId != surfaceToWindow->windowId)
1970 WLog_WARN(TAG,
"surface windowId mismatch, has %" PRIu64
", expected %" PRIu64,
1971 surface->windowId, surfaceToWindow->windowId);
1975 surface->windowMapped = TRUE;
1977 surface->windowId = surfaceToWindow->windowId;
1978 surface->mappedWidth = surfaceToWindow->mappedWidth;
1979 surface->mappedHeight = surfaceToWindow->mappedHeight;
1980 surface->outputTargetWidth = surfaceToWindow->targetWidth;
1981 surface->outputTargetHeight = surfaceToWindow->targetHeight;
1982 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1983 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1985 LeaveCriticalSection(&context->mux);
1989BOOL gdi_graphics_pipeline_init(rdpGdi* gdi, RdpgfxClientContext* gfx)
1991 return gdi_graphics_pipeline_init_ex(gdi, gfx,
nullptr,
nullptr,
nullptr);
1994BOOL gdi_graphics_pipeline_init_ex(rdpGdi* gdi, RdpgfxClientContext* gfx,
1995 pcRdpgfxMapWindowForSurface map,
1996 pcRdpgfxUnmapWindowForSurface unmap,
1997 pcRdpgfxUpdateSurfaceArea update)
1999 if (!gdi || !gfx || !gdi->context || !gdi->context->settings)
2002 rdpContext* context = gdi->context;
2003 rdpSettings* settings = context->settings;
2006 gfx->custom = (
void*)gdi;
2007 gfx->ResetGraphics = gdi_ResetGraphics;
2008 gfx->StartFrame = gdi_StartFrame;
2009 gfx->EndFrame = gdi_EndFrame;
2010 gfx->SurfaceCommand = gdi_SurfaceCommand;
2011 gfx->DeleteEncodingContext = gdi_DeleteEncodingContext;
2012 gfx->CreateSurface = gdi_CreateSurface;
2013 gfx->DeleteSurface = gdi_DeleteSurface;
2014 gfx->SolidFill = gdi_SolidFill;
2015 gfx->SurfaceToSurface = gdi_SurfaceToSurface;
2016 gfx->SurfaceToCache = gdi_SurfaceToCache;
2017 gfx->CacheToSurface = gdi_CacheToSurface;
2018 gfx->CacheImportReply = gdi_CacheImportReply;
2019 gfx->ImportCacheEntry = gdi_ImportCacheEntry;
2020 gfx->ExportCacheEntry = gdi_ExportCacheEntry;
2021 gfx->EvictCacheEntry = gdi_EvictCacheEntry;
2022 gfx->MapSurfaceToOutput = gdi_MapSurfaceToOutput;
2023 gfx->MapSurfaceToWindow = gdi_MapSurfaceToWindow;
2024 gfx->MapSurfaceToScaledOutput = gdi_MapSurfaceToScaledOutput;
2025 gfx->MapSurfaceToScaledWindow = gdi_MapSurfaceToScaledWindow;
2026 gfx->UpdateSurfaces = gdi_UpdateSurfaces;
2027 gfx->MapWindowForSurface = map;
2028 gfx->UnmapWindowForSurface = unmap;
2029 gfx->UpdateSurfaceArea = update;
2037 gfx->codecs = freerdp_client_codecs_new(flags);
2040 if (!freerdp_client_codecs_prepare(gfx->codecs, FREERDP_CODEC_ALL, w, h))
2043 InitializeCriticalSection(&gfx->mux);
2044 PROFILER_CREATE(gfx->SurfaceProfiler,
"GFX-PROFILER")
2052 gdi->graphicsReset = TRUE;
2055 gfx->UpdateSurfaceArea =
nullptr;
2056 gfx->UpdateSurfaces =
nullptr;
2057 gfx->SurfaceCommand =
nullptr;
2063void gdi_graphics_pipeline_uninit(rdpGdi* gdi, RdpgfxClientContext* gfx)
2071 gfx->custom =
nullptr;
2072 freerdp_client_codecs_free(gfx->codecs);
2073 gfx->codecs =
nullptr;
2074 DeleteCriticalSection(&gfx->mux);
2075 PROFILER_PRINT_HEADER
2076 PROFILER_PRINT(gfx->SurfaceProfiler)
2077 PROFILER_PRINT_FOOTER
2078 PROFILER_FREE(gfx->SurfaceProfiler)
2081const
char* rdpgfx_caps_version_str(UINT32 capsVersion)
2083 switch (capsVersion)
2085#if defined(WITH_GFX_AV1)
2086 case RDPGFX_CAPVERSION_FRDP_1:
2087 return "RDPGFX_CAPVERSION_FRDP_1";
2089 case RDPGFX_CAPVERSION_8:
2090 return "RDPGFX_CAPVERSION_8";
2091 case RDPGFX_CAPVERSION_81:
2092 return "RDPGFX_CAPVERSION_81";
2093 case RDPGFX_CAPVERSION_10:
2094 return "RDPGFX_CAPVERSION_10";
2095 case RDPGFX_CAPVERSION_101:
2096 return "RDPGFX_CAPVERSION_101";
2097 case RDPGFX_CAPVERSION_102:
2098 return "RDPGFX_CAPVERSION_102";
2099 case RDPGFX_CAPVERSION_103:
2100 return "RDPGFX_CAPVERSION_103";
2101 case RDPGFX_CAPVERSION_104:
2102 return "RDPGFX_CAPVERSION_104";
2103 case RDPGFX_CAPVERSION_105:
2104 return "RDPGFX_CAPVERSION_105";
2105 case RDPGFX_CAPVERSION_106:
2106 return "RDPGFX_CAPVERSION_106";
2107 case RDPGFX_CAPVERSION_106_ERR:
2108 return "RDPGFX_CAPVERSION_106_ERR";
2109 case RDPGFX_CAPVERSION_107:
2110 return "RDPGFX_CAPVERSION_107";
2112 return "RDPGFX_CAPVERSION_UNKNOWN";
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.