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 UINT32 DesktopWidth = 0;
101 UINT32 DesktopHeight = 0;
102 UINT16* pSurfaceIds =
nullptr;
103 rdpGdi* gdi =
nullptr;
104 rdpUpdate* update =
nullptr;
105 rdpSettings* settings =
nullptr;
107 WINPR_ASSERT(context);
108 WINPR_ASSERT(resetGraphics);
110 gdi = (rdpGdi*)context->custom;
113 update = gdi->context->update;
114 WINPR_ASSERT(update);
116 settings = gdi->context->settings;
117 WINPR_ASSERT(settings);
118 EnterCriticalSection(&context->mux);
119 DesktopWidth = resetGraphics->width;
120 DesktopHeight = resetGraphics->height;
129 WINPR_ASSERT(update->DesktopResize);
130 if (!update->DesktopResize(gdi->context))
134 WINPR_ASSERT(context->GetSurfaceIds);
135 rc = context->GetSurfaceIds(context, &pSurfaceIds, &count);
136 if (rc != CHANNEL_RC_OK)
139 for (UINT32 index = 0; index < count; index++)
141 WINPR_ASSERT(context->GetSurfaceData);
142 gdiGfxSurface* surface =
143 (gdiGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
148 memset(surface->data, 0xFF, (
size_t)surface->scanline * surface->height);
149 region16_clear(&surface->invalidRegion);
156 const UINT32 width = (UINT32)MAX(0, gdi->width);
157 const UINT32 height = (UINT32)MAX(0, gdi->height);
159 if (!freerdp_client_codecs_reset(
164 if (!freerdp_client_codecs_reset(
173 LeaveCriticalSection(&context->mux);
177static UINT gdi_OutputUpdate(rdpGdi* gdi, gdiGfxSurface* surface)
179 UINT rc = ERROR_INTERNAL_ERROR;
185 rdpUpdate* update =
nullptr;
188 WINPR_ASSERT(gdi->context);
189 WINPR_ASSERT(surface);
191 update = gdi->context->update;
192 WINPR_ASSERT(update);
194 if (gdi->suppressOutput)
195 return CHANNEL_RC_OK;
197 surfaceX = surface->outputOriginX;
198 surfaceY = surface->outputOriginY;
199 surfaceRect.left = 0;
201 surfaceRect.right = (UINT16)MIN(UINT16_MAX, surface->mappedWidth);
202 surfaceRect.bottom = (UINT16)MIN(UINT16_MAX, surface->mappedHeight);
203 if (!region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion),
207 const double sx = surface->outputTargetWidth / (double)surface->mappedWidth;
208 const double sy = surface->outputTargetHeight / (double)surface->mappedHeight;
210 if (!(rects = region16_rects(&surface->invalidRegion, &nbRects)) || !nbRects)
211 return CHANNEL_RC_OK;
213 if (!update_begin_paint(update))
216 for (UINT32 i = 0; i < nbRects; i++)
218 const UINT32 nXSrc = rects[i].left;
219 const UINT32 nYSrc = rects[i].top;
220 const UINT32 nXDst = (UINT32)MIN(surfaceX + nXSrc * sx, gdi->width - 1);
221 const UINT32 nYDst = (UINT32)MIN(surfaceY + nYSrc * sy, gdi->height - 1);
222 const UINT32 swidth = rects[i].right - rects[i].left;
223 const UINT32 sheight = rects[i].bottom - rects[i].top;
224 const UINT32 dwidth = MIN((UINT32)(swidth * sx), (UINT32)gdi->width - nXDst);
225 const UINT32 dheight = MIN((UINT32)(sheight * sy), (UINT32)gdi->height - nYDst);
227 if (!freerdp_image_scale(gdi->primary_buffer, gdi->dstFormat, gdi->stride, nXDst, nYDst,
228 dwidth, dheight, surface->data, surface->format, surface->scanline,
229 nXSrc, nYSrc, swidth, sheight))
231 rc = CHANNEL_RC_NULL_DATA;
235 if (!gdi_InvalidateRegion(gdi->primary->hdc, (INT32)nXDst, (INT32)nYDst, (INT32)dwidth,
243 if (!update_end_paint(update))
244 rc = ERROR_INTERNAL_ERROR;
246 region16_clear(&(surface->invalidRegion));
250static UINT gdi_WindowUpdate(RdpgfxClientContext* context, gdiGfxSurface* surface)
252 WINPR_ASSERT(context);
253 WINPR_ASSERT(surface);
254 return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateWindowFromSurface, context, surface);
257static UINT gdi_UpdateSurfaces(RdpgfxClientContext* context)
260 UINT16* pSurfaceIds =
nullptr;
262 WINPR_ASSERT(context);
264 rdpGdi* gdi = (rdpGdi*)context->custom;
267 EnterCriticalSection(&context->mux);
269 WINPR_ASSERT(context->GetSurfaceIds);
270 UINT status = context->GetSurfaceIds(context, &pSurfaceIds, &count);
271 if (status != CHANNEL_RC_OK)
274 for (UINT32 index = 0; index < count; index++)
276 WINPR_ASSERT(context->GetSurfaceData);
277 gdiGfxSurface* surface =
278 (gdiGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
284 if (context->UpdateSurfaceArea)
286 if (surface->handleInUpdateSurfaceArea)
290 if (surface->outputMapped)
291 status = gdi_OutputUpdate(gdi, surface);
292 else if (surface->windowMapped)
293 status = gdi_WindowUpdate(context, surface);
295 if (status != CHANNEL_RC_OK)
301 LeaveCriticalSection(&context->mux);
312 rdpGdi* gdi =
nullptr;
314 WINPR_ASSERT(context);
315 WINPR_ASSERT(startFrame);
317 gdi = (rdpGdi*)context->custom;
319 gdi->inGfxFrame = TRUE;
320 gdi->frameId = startFrame->frameId;
321 return CHANNEL_RC_OK;
324static UINT gdi_call_update_surfaces(RdpgfxClientContext* context)
326 WINPR_ASSERT(context);
327 return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaces, context);
335static UINT gdi_EndFrame(RdpgfxClientContext* context,
338 WINPR_ASSERT(context);
339 WINPR_ASSERT(endFrame);
341 rdpGdi* gdi = (rdpGdi*)context->custom;
343 const UINT status = gdi_call_update_surfaces(context);
344 gdi->inGfxFrame = FALSE;
348static UINT gdi_interFrameUpdate(rdpGdi* gdi, RdpgfxClientContext* context)
351 UINT status = CHANNEL_RC_OK;
352 if (!gdi->inGfxFrame)
353 status = gdi_call_update_surfaces(context);
362static UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, RdpgfxClientContext* context,
365 UINT status = CHANNEL_RC_OK;
366 gdiGfxSurface* surface =
nullptr;
371 WINPR_ASSERT(context);
374 WINPR_ASSERT(context->GetSurfaceData);
376 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
380 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
381 return ERROR_NOT_FOUND;
384 if (!is_within_surface(surface, cmd))
385 return ERROR_INVALID_DATA;
387 bpp = FreeRDPGetBytesPerPixel(cmd->format);
388 size = 1ull * bpp * cmd->width * cmd->height;
389 if (cmd->length < size)
391 WLog_ERR(TAG,
"Not enough data, got %" PRIu32
", expected %" PRIuz, cmd->length, size);
392 return ERROR_INVALID_DATA;
395 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline, cmd->left,
396 cmd->top, cmd->width, cmd->height, cmd->data, cmd->format, 0,
397 0, 0,
nullptr, FREERDP_FLIP_NONE))
398 return ERROR_INTERNAL_ERROR;
400 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
401 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
402 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
403 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
404 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
406 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
409 if (status != CHANNEL_RC_OK)
412 status = gdi_interFrameUpdate(gdi, context);
423static UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, RdpgfxClientContext* context,
426 UINT status = ERROR_INTERNAL_ERROR;
427 gdiGfxSurface* surface =
nullptr;
432 WINPR_ASSERT(context);
435 WINPR_ASSERT(context->GetSurfaceData);
437 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
441 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
442 return ERROR_NOT_FOUND;
445 if (!is_within_surface(surface, cmd))
446 return ERROR_INVALID_DATA;
448 WINPR_ASSERT(surface->codecs);
449 rfx_context_set_pixel_format(surface->codecs->rfx, cmd->format);
450 region16_init(&invalidRegion);
452 if (!rfx_process_message(surface->codecs->rfx, cmd->data, cmd->length, cmd->left, cmd->top,
453 surface->data, surface->format, surface->scanline, surface->height,
456 WLog_ERR(TAG,
"Failed to process RemoteFX message");
460 rects = region16_rects(&invalidRegion, &nrRects);
461 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
464 if (status != CHANNEL_RC_OK)
467 for (UINT32 x = 0; x < nrRects; x++)
469 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]))
473 status = gdi_interFrameUpdate(gdi, context);
476 region16_uninit(&invalidRegion);
485static UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context,
489 UINT status = CHANNEL_RC_OK;
490 gdiGfxSurface* surface =
nullptr;
493 WINPR_ASSERT(context);
496 WINPR_ASSERT(context->GetSurfaceData);
498 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
502 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
503 return ERROR_NOT_FOUND;
506 if (!is_within_surface(surface, cmd))
507 return ERROR_INVALID_DATA;
509 WINPR_ASSERT(surface->codecs);
510 rc = clear_decompress(surface->codecs->clear, cmd->data, cmd->length, cmd->width, cmd->height,
511 surface->data, surface->format, surface->scanline, cmd->left, cmd->top,
512 surface->width, surface->height, &gdi->palette);
516 WLog_ERR(TAG,
"clear_decompress failure: %" PRId32
"", rc);
517 return ERROR_INTERNAL_ERROR;
520 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
521 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
522 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
523 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
524 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
526 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
529 if (status != CHANNEL_RC_OK)
532 status = gdi_interFrameUpdate(gdi, context);
543static UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context,
546 UINT status = CHANNEL_RC_OK;
547 BYTE* DstData =
nullptr;
548 gdiGfxSurface* surface =
nullptr;
551 WINPR_ASSERT(context);
554 WINPR_ASSERT(context->GetSurfaceData);
556 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
560 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
561 return ERROR_NOT_FOUND;
564 DstData = surface->data;
566 if (!is_within_surface(surface, cmd))
567 return ERROR_INVALID_DATA;
569 if (!freerdp_bitmap_decompress_planar(surface->codecs->planar, cmd->data, cmd->length,
570 cmd->width, cmd->height, DstData, surface->format,
571 surface->scanline, cmd->left, cmd->top, cmd->width,
573 return ERROR_INTERNAL_ERROR;
575 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
576 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
577 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
578 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
579 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
581 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
584 if (status != CHANNEL_RC_OK)
587 status = gdi_interFrameUpdate(gdi, context);
598static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, RdpgfxClientContext* context,
603 UINT status = CHANNEL_RC_OK;
604 gdiGfxSurface* surface =
nullptr;
608 WINPR_ASSERT(context);
611 WINPR_ASSERT(context->GetSurfaceData);
613 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
617 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
618 return ERROR_NOT_FOUND;
623 surface->h264 = h264_context_new(FALSE);
627 WLog_ERR(TAG,
"unable to create h264 context");
628 return ERROR_NOT_ENOUGH_MEMORY;
631 if (!h264_context_reset(surface->h264, surface->width, surface->height))
632 return ERROR_INTERNAL_ERROR;
636 return ERROR_NOT_SUPPORTED;
638 if (!is_within_surface(surface, cmd))
639 return ERROR_INVALID_DATA;
644 return ERROR_INTERNAL_ERROR;
647 rc = avc420_decompress(surface->h264, bs->data, bs->length, surface->data, surface->format,
648 surface->scanline, surface->width, surface->height, meta->regionRects,
649 meta->numRegionRects);
653 WLog_WARN(TAG,
"avc420_decompress failure: %" PRId32
", ignoring update.", rc);
654 return CHANNEL_RC_OK;
657 for (UINT32 i = 0; i < meta->numRegionRects; i++)
659 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
660 &(meta->regionRects[i])))
664 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
665 meta->numRegionRects, meta->regionRects);
667 if (status != CHANNEL_RC_OK)
670 status = gdi_interFrameUpdate(gdi, context);
675 return ERROR_NOT_SUPPORTED;
684static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context,
689 UINT status = CHANNEL_RC_OK;
690 gdiGfxSurface* surface =
nullptr;
697 WINPR_ASSERT(context);
700 WINPR_ASSERT(context->GetSurfaceData);
702 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
706 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
707 return ERROR_NOT_FOUND;
712 surface->h264 = h264_context_new(FALSE);
716 WLog_ERR(TAG,
"unable to create h264 context");
717 return ERROR_NOT_ENOUGH_MEMORY;
720 if (!h264_context_reset(surface->h264, surface->width, surface->height))
721 return ERROR_INTERNAL_ERROR;
725 return ERROR_NOT_SUPPORTED;
727 if (!is_within_surface(surface, cmd))
728 return ERROR_INVALID_DATA;
733 return ERROR_INTERNAL_ERROR;
735 avc1 = &bs->bitstream[0];
736 avc2 = &bs->bitstream[1];
739 rc = avc444_decompress(surface->h264, bs->LC, meta1->regionRects, meta1->numRegionRects,
740 avc1->data, avc1->length, meta2->regionRects, meta2->numRegionRects,
741 avc2->data, avc2->length, surface->data, surface->format,
742 surface->scanline, surface->width, surface->height, cmd->codecId);
746 WLog_WARN(TAG,
"avc444_decompress failure: %" PRIu32
", ignoring update.", status);
747 return CHANNEL_RC_OK;
750 for (UINT32 i = 0; i < meta1->numRegionRects; i++)
752 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
753 &(meta1->regionRects[i])))
757 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
758 meta1->numRegionRects, meta1->regionRects);
760 if (status != CHANNEL_RC_OK)
763 for (UINT32 i = 0; i < meta2->numRegionRects; i++)
765 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
766 &(meta2->regionRects[i])))
770 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
771 meta2->numRegionRects, meta2->regionRects);
773 if (status != CHANNEL_RC_OK)
776 status = gdi_interFrameUpdate(gdi, context);
781 return ERROR_NOT_SUPPORTED;
785static BOOL gdi_apply_alpha(BYTE* data, UINT32 format, UINT32 stride,
RECTANGLE_16* rect,
786 UINT32 startOffsetX, UINT32 count, BYTE a)
790 const UINT32 bpp = FreeRDPGetBytesPerPixel(format);
793 for (
size_t y = rect->top; y < rect->bottom; y++)
795 BYTE* line = &data[y * stride];
797 for (
size_t x = first ? rect->left + startOffsetX : rect->left; x < rect->right; x++)
803 if (written == count)
806 BYTE* src = &line[x * bpp];
807 UINT32 color = FreeRDPReadColor(src, format);
808 FreeRDPSplitColor(color, format, &r, &g, &b,
nullptr,
nullptr);
809 color = FreeRDPGetColor(format, r, g, b, a);
810 FreeRDPWriteColor(src, format, color);
824static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context,
827 UINT status = CHANNEL_RC_OK;
829 UINT16 compressed = 0;
830 gdiGfxSurface* surface =
nullptr;
835 WINPR_ASSERT(context);
838 s = Stream_StaticConstInit(&buffer, cmd->data, cmd->length);
840 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
841 return ERROR_INVALID_DATA;
843 WINPR_ASSERT(context->GetSurfaceData);
845 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
849 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
850 return ERROR_NOT_FOUND;
853 if (!is_within_surface(surface, cmd))
854 return ERROR_INVALID_DATA;
856 Stream_Read_UINT16(s, alphaSig);
857 Stream_Read_UINT16(s, compressed);
859 if (alphaSig != 0x414C)
860 return ERROR_INVALID_DATA;
864 if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, cmd->height, cmd->width))
865 return ERROR_INVALID_DATA;
867 for (
size_t y = cmd->top; y < cmd->top + cmd->height; y++)
869 BYTE* line = &surface->data[y * surface->scanline];
871 for (
size_t x = cmd->left; x < cmd->left + cmd->width; x++)
878 BYTE* src = &line[x * FreeRDPGetBytesPerPixel(surface->format)];
879 Stream_Read_UINT8(s, a);
880 color = FreeRDPReadColor(src, surface->format);
881 FreeRDPSplitColor(color, surface->format, &r, &g, &b,
nullptr,
nullptr);
882 color = FreeRDPGetColor(surface->format, r, g, b, a);
883 FreeRDPWriteColor(src, surface->format, color);
889 UINT32 startOffsetX = 0;
891 rect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
892 rect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
893 rect.right = (UINT16)MIN(UINT16_MAX, cmd->left + cmd->width);
894 rect.bottom = (UINT16)MIN(UINT16_MAX, cmd->top + cmd->height);
896 while (rect.top < rect.bottom)
901 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
902 return ERROR_INVALID_DATA;
904 Stream_Read_UINT8(s, a);
905 Stream_Read_UINT8(s, count);
909 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
910 return ERROR_INVALID_DATA;
912 Stream_Read_UINT16(s, count);
916 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
917 return ERROR_INVALID_DATA;
919 Stream_Read_UINT32(s, count);
923 if (!gdi_apply_alpha(surface->data, surface->format, surface->scanline, &rect,
924 startOffsetX, count, a))
925 return ERROR_INTERNAL_ERROR;
927 startOffsetX += count;
929 while (startOffsetX >= cmd->width)
931 startOffsetX -= cmd->width;
937 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
938 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
939 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
940 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
941 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
943 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
946 if (status != CHANNEL_RC_OK)
949 status = gdi_interFrameUpdate(gdi, context);
955#if defined(WITH_GFX_FRAME_DUMP)
958 static UINT64 xxx = 0;
959 const char* path =
"/tmp/dump/";
961 char fname[1024] = WINPR_C_ARRAY_INIT;
963 snprintf(fname,
sizeof(fname),
"%s/%08" PRIx64
".raw", path, xxx++);
964 FILE* fp = fopen(fname,
"w");
967 (void)fprintf(fp,
"frameid: %" PRIu32
"\n", frameId);
968 (void)fprintf(fp,
"surfaceId: %" PRIu32
"\n", cmd->surfaceId);
969 (void)fprintf(fp,
"codecId: %" PRIu32
"\n", cmd->codecId);
970 (void)fprintf(fp,
"contextId: %" PRIu32
"\n", cmd->contextId);
971 (void)fprintf(fp,
"format: %" PRIu32
"\n", cmd->format);
972 (void)fprintf(fp,
"left: %" PRIu32
"\n", cmd->left);
973 (void)fprintf(fp,
"top: %" PRIu32
"\n", cmd->top);
974 (void)fprintf(fp,
"right: %" PRIu32
"\n", cmd->right);
975 (void)fprintf(fp,
"bottom: %" PRIu32
"\n", cmd->bottom);
976 (void)fprintf(fp,
"width: %" PRIu32
"\n", cmd->width);
977 (void)fprintf(fp,
"height: %" PRIu32
"\n", cmd->height);
978 (void)fprintf(fp,
"length: %" PRIu32
"\n", cmd->length);
980 char* bdata = crypto_base64_encode_ex(cmd->data, cmd->length, FALSE);
981 (void)fprintf(fp,
"data: %s\n", bdata);
992static UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context,
996 UINT status = ERROR_INTERNAL_ERROR;
997 gdiGfxSurface* surface =
nullptr;
1007 WINPR_ASSERT(context);
1009 const UINT16 surfaceId = (UINT16)MIN(UINT16_MAX, cmd->surfaceId);
1011 WINPR_ASSERT(context->GetSurfaceData);
1012 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceId);
1016 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
1017 return ERROR_NOT_FOUND;
1020 if (!is_within_surface(surface, cmd))
1021 return ERROR_INVALID_DATA;
1023 WINPR_ASSERT(surface->codecs);
1024 rc = progressive_create_surface_context(surface->codecs->progressive, surfaceId, surface->width,
1029 WLog_ERR(TAG,
"progressive_create_surface_context failure: %" PRId32
"", rc);
1030 return ERROR_INTERNAL_ERROR;
1033 region16_init(&invalidRegion);
1035 rc = progressive_decompress(surface->codecs->progressive, cmd->data, cmd->length, surface->data,
1036 surface->format, surface->scanline, cmd->left, cmd->top,
1037 &invalidRegion, surfaceId, gdi->frameId);
1041 WLog_ERR(TAG,
"progressive_decompress failure: %" PRId32
"", rc);
1045 rects = region16_rects(&invalidRegion, &nrRects);
1046 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1049 if (status != CHANNEL_RC_OK)
1052 status = ERROR_INTERNAL_ERROR;
1053 for (UINT32 x = 0; x < nrRects; x++)
1055 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]))
1059 status = gdi_interFrameUpdate(gdi, context);
1063 region16_uninit(&invalidRegion);
1074 UINT status = CHANNEL_RC_OK;
1075 rdpGdi* gdi =
nullptr;
1077 if (!context || !cmd)
1078 return ERROR_INVALID_PARAMETER;
1080 gdi = (rdpGdi*)context->custom;
1082 EnterCriticalSection(&context->mux);
1083 const UINT16 codecId = WINPR_ASSERTING_INT_CAST(UINT16, cmd->codecId);
1084 WLog_Print(gdi->log, WLOG_TRACE,
1085 "surfaceId=%" PRIu32
", codec=%s [%" PRIu32
"], contextId=%" PRIu32
", format=%s, "
1086 "left=%" PRIu32
", top=%" PRIu32
", right=%" PRIu32
", bottom=%" PRIu32
1087 ", width=%" PRIu32
", height=%" PRIu32
" "
1088 "length=%" PRIu32
", data=%p, extra=%p",
1089 cmd->surfaceId, rdpgfx_get_codec_id_string(codecId), cmd->codecId, cmd->contextId,
1090 FreeRDPGetColorFormatName(cmd->format), cmd->left, cmd->top, cmd->right, cmd->bottom,
1091 cmd->width, cmd->height, cmd->length, (
void*)cmd->data, (
void*)cmd->extra);
1092#if defined(WITH_GFX_FRAME_DUMP)
1093 dump_cmd(cmd, gdi->frameId);
1098 case RDPGFX_CODECID_UNCOMPRESSED:
1099 status = gdi_SurfaceCommand_Uncompressed(gdi, context, cmd);
1102 case RDPGFX_CODECID_CAVIDEO:
1103 status = gdi_SurfaceCommand_RemoteFX(gdi, context, cmd);
1106 case RDPGFX_CODECID_CLEARCODEC:
1107 status = gdi_SurfaceCommand_ClearCodec(gdi, context, cmd);
1110 case RDPGFX_CODECID_PLANAR:
1111 status = gdi_SurfaceCommand_Planar(gdi, context, cmd);
1114 case RDPGFX_CODECID_AVC420:
1115 status = gdi_SurfaceCommand_AVC420(gdi, context, cmd);
1118 case RDPGFX_CODECID_AVC444v2:
1119 case RDPGFX_CODECID_AVC444:
1120 status = gdi_SurfaceCommand_AVC444(gdi, context, cmd);
1123 case RDPGFX_CODECID_ALPHA:
1124 status = gdi_SurfaceCommand_Alpha(gdi, context, cmd);
1127 case RDPGFX_CODECID_CAPROGRESSIVE:
1128 status = gdi_SurfaceCommand_Progressive(gdi, context, cmd);
1131 case RDPGFX_CODECID_CAPROGRESSIVE_V2:
1132 WLog_WARN(TAG,
"SurfaceCommand %s [0x%08" PRIX16
"] not implemented",
1133 rdpgfx_get_codec_id_string(codecId), codecId);
1137 WLog_WARN(TAG,
"Invalid SurfaceCommand %s [0x%08" PRIX16
"]",
1138 rdpgfx_get_codec_id_string(codecId), codecId);
1142 LeaveCriticalSection(&context->mux);
1152gdi_DeleteEncodingContext(RdpgfxClientContext* context,
1155 WINPR_ASSERT(context);
1156 WINPR_ASSERT(deleteEncodingContext);
1157 WINPR_UNUSED(context);
1158 WINPR_UNUSED(deleteEncodingContext);
1159 return CHANNEL_RC_OK;
1167static UINT gdi_CreateSurface(RdpgfxClientContext* context,
1170 UINT rc = ERROR_INTERNAL_ERROR;
1171 gdiGfxSurface* surface =
nullptr;
1172 rdpGdi* gdi =
nullptr;
1173 WINPR_ASSERT(context);
1174 WINPR_ASSERT(createSurface);
1175 gdi = (rdpGdi*)context->custom;
1177 WINPR_ASSERT(gdi->context);
1178 EnterCriticalSection(&context->mux);
1179 surface = (gdiGfxSurface*)calloc(1,
sizeof(gdiGfxSurface));
1186 WINPR_ASSERT(context->codecs);
1187 surface->codecs = context->codecs;
1189 if (!surface->codecs)
1196 surface->surfaceId = createSurface->surfaceId;
1197 surface->width = gfx_align_scanline(createSurface->width, 16);
1198 surface->height = gfx_align_scanline(createSurface->height, 16);
1199 surface->mappedWidth = createSurface->width;
1200 surface->mappedHeight = createSurface->height;
1201 surface->outputTargetWidth = createSurface->width;
1202 surface->outputTargetHeight = createSurface->height;
1204 switch (createSurface->pixelFormat)
1206 case GFX_PIXEL_FORMAT_ARGB_8888:
1207 surface->format = PIXEL_FORMAT_BGRA32;
1210 case GFX_PIXEL_FORMAT_XRGB_8888:
1211 surface->format = PIXEL_FORMAT_BGRX32;
1219 surface->scanline = gfx_align_scanline(surface->width * 4UL, 16);
1220 surface->data = (BYTE*)winpr_aligned_malloc(1ull * surface->scanline * surface->height, 16);
1228 memset(surface->data, 0xFF, (
size_t)surface->scanline * surface->height);
1229 region16_init(&surface->invalidRegion);
1231 WINPR_ASSERT(context->SetSurfaceData);
1232 rc = context->SetSurfaceData(context, surface->surfaceId, (
void*)surface);
1234 LeaveCriticalSection(&context->mux);
1243static UINT gdi_DeleteSurface(RdpgfxClientContext* context,
1246 UINT rc = CHANNEL_RC_OK;
1247 UINT res = ERROR_INTERNAL_ERROR;
1248 rdpCodecs* codecs =
nullptr;
1249 gdiGfxSurface* surface =
nullptr;
1250 EnterCriticalSection(&context->mux);
1252 WINPR_ASSERT(context->GetSurfaceData);
1253 surface = (gdiGfxSurface*)context->GetSurfaceData(context, deleteSurface->surfaceId);
1257 if (surface->windowMapped)
1258 rc = IFCALLRESULT(CHANNEL_RC_OK, context->UnmapWindowForSurface, context,
1262 h264_context_free(surface->h264);
1264 region16_uninit(&surface->invalidRegion);
1265 codecs = surface->codecs;
1266 winpr_aligned_free(surface->data);
1270 WINPR_ASSERT(context->SetSurfaceData);
1271 res = context->SetSurfaceData(context, deleteSurface->surfaceId,
nullptr);
1275 if (codecs && codecs->progressive)
1276 progressive_delete_surface_context(codecs->progressive, deleteSurface->surfaceId);
1278 LeaveCriticalSection(&context->mux);
1282static BOOL intersect_rect(
const RECTANGLE_16* rect,
const gdiGfxSurface* surface,
1286 WINPR_ASSERT(surface);
1287 WINPR_ASSERT(prect);
1289 if (rect->left > rect->right)
1291 if (rect->left > surface->width)
1293 if (rect->top > rect->bottom)
1295 if (rect->top > surface->height)
1297 prect->left = rect->left;
1298 prect->top = rect->top;
1300 prect->right = MIN(rect->right, WINPR_ASSERTING_INT_CAST(UINT16, surface->width));
1301 prect->bottom = MIN(rect->bottom, WINPR_ASSERTING_INT_CAST(UINT16, surface->height));
1312 UINT status = ERROR_INTERNAL_ERROR;
1315 rdpGdi* gdi = (rdpGdi*)context->custom;
1317 EnterCriticalSection(&context->mux);
1319 WINPR_ASSERT(context->GetSurfaceData);
1320 gdiGfxSurface* surface = (gdiGfxSurface*)context->GetSurfaceData(context, solidFill->surfaceId);
1326 const BYTE b = solidFill->fillPixel.B;
1327 const BYTE g = solidFill->fillPixel.G;
1328 const BYTE r = solidFill->fillPixel.R;
1335 const UINT32 color = FreeRDPGetColor(surface->format, r, g, b, a);
1336 for (UINT16 index = 0; index < solidFill->fillRectCount; index++)
1338 const RECTANGLE_16* rect = &(solidFill->fillRects[index]);
1340 if (!intersect_rect(rect, surface, &invalidRect))
1343 const UINT32 nWidth = invalidRect.right - invalidRect.left;
1344 const UINT32 nHeight = invalidRect.bottom - invalidRect.top;
1346 if (!freerdp_image_fill(surface->data, surface->format, surface->scanline,
1347 invalidRect.left, invalidRect.top, nWidth, nHeight, color))
1350 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
1356 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1357 solidFill->fillRectCount, solidFill->fillRects);
1359 if (status != CHANNEL_RC_OK)
1362 LeaveCriticalSection(&context->mux);
1364 return gdi_interFrameUpdate(gdi, context);
1366 LeaveCriticalSection(&context->mux);
1375static UINT gdi_SurfaceToSurface(RdpgfxClientContext* context,
1378 UINT status = ERROR_INTERNAL_ERROR;
1379 BOOL sameSurface = 0;
1382 gdiGfxSurface* surfaceSrc =
nullptr;
1383 gdiGfxSurface* surfaceDst =
nullptr;
1384 rdpGdi* gdi = (rdpGdi*)context->custom;
1385 EnterCriticalSection(&context->mux);
1386 rectSrc = &(surfaceToSurface->rectSrc);
1388 WINPR_ASSERT(context->GetSurfaceData);
1389 surfaceSrc = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdSrc);
1390 sameSurface = (surfaceToSurface->surfaceIdSrc == surfaceToSurface->surfaceIdDest);
1394 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdDest);
1396 surfaceDst = surfaceSrc;
1398 if (!surfaceSrc || !surfaceDst)
1401 if (!is_rect_valid(rectSrc, surfaceSrc->width, surfaceSrc->height))
1405 const UINT32 nWidth = rectSrc->right - rectSrc->left;
1406 const UINT32 nHeight = rectSrc->bottom - rectSrc->top;
1408 for (UINT16 index = 0; index < surfaceToSurface->destPtsCount; index++)
1410 const RDPGFX_POINT16* destPt = &surfaceToSurface->destPts[index];
1412 (UINT16)MIN(UINT16_MAX, destPt->x + nWidth),
1413 (UINT16)MIN(UINT16_MAX, destPt->y + nHeight) };
1414 if (!is_rect_valid(&rect, surfaceDst->width, surfaceDst->height))
1417 const UINT32 rwidth = rect.right - rect.left;
1418 const UINT32 rheight = rect.bottom - rect.top;
1419 if (!freerdp_image_copy(surfaceDst->data, surfaceDst->format, surfaceDst->scanline,
1420 destPt->x, destPt->y, rwidth, rheight, surfaceSrc->data,
1421 surfaceSrc->format, surfaceSrc->scanline, rectSrc->left,
1422 rectSrc->top,
nullptr, FREERDP_FLIP_NONE))
1426 if (!region16_union_rect(&surfaceDst->invalidRegion, &surfaceDst->invalidRegion,
1429 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1430 surfaceDst->surfaceId, 1, &invalidRect);
1432 if (status != CHANNEL_RC_OK)
1437 LeaveCriticalSection(&context->mux);
1439 return gdi_interFrameUpdate(gdi, context);
1441 LeaveCriticalSection(&context->mux);
1445static void gdi_GfxCacheEntryFree(gdiGfxCacheEntry* entry)
1453static gdiGfxCacheEntry* gdi_GfxCacheEntryNew(UINT64 cacheKey, UINT32 width, UINT32 height,
1456 gdiGfxCacheEntry* cacheEntry = (gdiGfxCacheEntry*)calloc(1,
sizeof(gdiGfxCacheEntry));
1460 cacheEntry->cacheKey = cacheKey;
1461 cacheEntry->width = width;
1462 cacheEntry->height = height;
1463 cacheEntry->format = format;
1464 cacheEntry->scanline = gfx_align_scanline(cacheEntry->width * 4, 16);
1466 if ((cacheEntry->width > 0) && (cacheEntry->height > 0))
1468 cacheEntry->data = (BYTE*)calloc(cacheEntry->height, cacheEntry->scanline);
1470 if (!cacheEntry->data)
1475 gdi_GfxCacheEntryFree(cacheEntry);
1484static UINT gdi_SurfaceToCache(RdpgfxClientContext* context,
1487 gdiGfxCacheEntry* cacheEntry =
nullptr;
1488 UINT rc = ERROR_INTERNAL_ERROR;
1489 EnterCriticalSection(&context->mux);
1492 WINPR_ASSERT(context->GetSurfaceData);
1493 gdiGfxSurface* surface =
1494 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToCache->surfaceId);
1499 if (!is_rect_valid(rect, surface->width, surface->height))
1502 cacheEntry = gdi_GfxCacheEntryNew(surfaceToCache->cacheKey, (UINT32)(rect->right - rect->left),
1503 (UINT32)(rect->bottom - rect->top), surface->format);
1508 if (!cacheEntry->data)
1511 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1512 0, 0, cacheEntry->width, cacheEntry->height, surface->data,
1513 surface->format, surface->scanline, rect->left, rect->top,
1514 nullptr, FREERDP_FLIP_NONE))
1519 WINPR_ASSERT(context->EvictCacheEntry);
1520 rc = context->EvictCacheEntry(context, &evict);
1521 if (rc != CHANNEL_RC_OK)
1525 WINPR_ASSERT(context->SetCacheSlotData);
1526 rc = context->SetCacheSlotData(context, surfaceToCache->cacheSlot, (
void*)cacheEntry);
1528 if (rc != CHANNEL_RC_OK)
1529 gdi_GfxCacheEntryFree(cacheEntry);
1530 LeaveCriticalSection(&context->mux);
1539static UINT gdi_CacheToSurface(RdpgfxClientContext* context,
1542 UINT status = ERROR_INTERNAL_ERROR;
1543 gdiGfxSurface* surface =
nullptr;
1544 gdiGfxCacheEntry* cacheEntry =
nullptr;
1546 rdpGdi* gdi = (rdpGdi*)context->custom;
1548 EnterCriticalSection(&context->mux);
1550 WINPR_ASSERT(context->GetSurfaceData);
1551 surface = (gdiGfxSurface*)context->GetSurfaceData(context, cacheToSurface->surfaceId);
1553 WINPR_ASSERT(context->GetCacheSlotData);
1554 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheToSurface->cacheSlot);
1556 if (!surface || !cacheEntry)
1559 for (UINT16 index = 0; index < cacheToSurface->destPtsCount; index++)
1563 (UINT16)MIN(UINT16_MAX, destPt->x + cacheEntry->width),
1564 (UINT16)MIN(UINT16_MAX, destPt->y + cacheEntry->height) };
1566 if (rectangle_is_empty(&rect))
1569 if (!is_rect_valid(&rect, surface->width, surface->height))
1572 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline,
1573 destPt->x, destPt->y, cacheEntry->width,
1574 cacheEntry->height, cacheEntry->data, cacheEntry->format,
1575 cacheEntry->scanline, 0, 0,
nullptr, FREERDP_FLIP_NONE))
1579 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect))
1581 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1582 surface->surfaceId, 1, &invalidRect);
1584 if (status != CHANNEL_RC_OK)
1588 LeaveCriticalSection(&context->mux);
1590 return gdi_interFrameUpdate(gdi, context);
1593 LeaveCriticalSection(&context->mux);
1602static UINT gdi_CacheImportReply(RdpgfxClientContext* context,
1606 const UINT16* slots =
nullptr;
1607 UINT error = CHANNEL_RC_OK;
1609 slots = cacheImportReply->cacheSlots;
1610 count = cacheImportReply->importedEntriesCount;
1612 for (UINT16 index = 0; index < count; index++)
1614 UINT16 cacheSlot = slots[index];
1619 WINPR_ASSERT(context->GetCacheSlotData);
1620 gdiGfxCacheEntry* cacheEntry =
1621 (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1626 cacheEntry = gdi_GfxCacheEntryNew(cacheSlot, 0, 0, PIXEL_FORMAT_BGRX32);
1629 return ERROR_INTERNAL_ERROR;
1631 WINPR_ASSERT(context->SetCacheSlotData);
1632 error = context->SetCacheSlotData(context, cacheSlot, (
void*)cacheEntry);
1636 WLog_ERR(TAG,
"CacheImportReply: SetCacheSlotData failed with error %" PRIu32
"",
1638 gdi_GfxCacheEntryFree(cacheEntry);
1646static UINT gdi_ImportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1649 UINT error = ERROR_INTERNAL_ERROR;
1650 gdiGfxCacheEntry* cacheEntry =
nullptr;
1653 return CHANNEL_RC_OK;
1655 cacheEntry = gdi_GfxCacheEntryNew(importCacheEntry->key64, importCacheEntry->width,
1656 importCacheEntry->height, PIXEL_FORMAT_BGRX32);
1661 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1662 0, 0, cacheEntry->width, cacheEntry->height,
1663 importCacheEntry->data, PIXEL_FORMAT_BGRX32, 0, 0, 0,
1664 nullptr, FREERDP_FLIP_NONE))
1669 WINPR_ASSERT(context->EvictCacheEntry);
1670 error = context->EvictCacheEntry(context, &evict);
1672 if (error != CHANNEL_RC_OK)
1675 WINPR_ASSERT(context->SetCacheSlotData);
1676 error = context->SetCacheSlotData(context, cacheSlot, (
void*)cacheEntry);
1681 gdi_GfxCacheEntryFree(cacheEntry);
1682 WLog_ERR(TAG,
"ImportCacheEntry: SetCacheSlotData failed with error %" PRIu32
"", error);
1688static UINT gdi_ExportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1691 gdiGfxCacheEntry* cacheEntry =
nullptr;
1693 WINPR_ASSERT(context->GetCacheSlotData);
1694 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1698 exportCacheEntry->key64 = cacheEntry->cacheKey;
1699 exportCacheEntry->width = (UINT16)MIN(UINT16_MAX, cacheEntry->width);
1700 exportCacheEntry->height = (UINT16)MIN(UINT16_MAX, cacheEntry->height);
1701 exportCacheEntry->size = cacheEntry->width * cacheEntry->height * 4;
1702 exportCacheEntry->flags = 0;
1703 exportCacheEntry->data = cacheEntry->data;
1704 return CHANNEL_RC_OK;
1707 return ERROR_NOT_FOUND;
1715static UINT gdi_EvictCacheEntry(RdpgfxClientContext* context,
1718 gdiGfxCacheEntry* cacheEntry =
nullptr;
1719 UINT rc = ERROR_NOT_FOUND;
1721 WINPR_ASSERT(context);
1722 WINPR_ASSERT(evictCacheEntry);
1724 EnterCriticalSection(&context->mux);
1726 WINPR_ASSERT(context->GetCacheSlotData);
1727 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, evictCacheEntry->cacheSlot);
1729 gdi_GfxCacheEntryFree(cacheEntry);
1731 WINPR_ASSERT(context->SetCacheSlotData);
1732 rc = context->SetCacheSlotData(context, evictCacheEntry->cacheSlot,
nullptr);
1733 LeaveCriticalSection(&context->mux);
1742static UINT gdi_MapSurfaceToOutput(RdpgfxClientContext* context,
1745 UINT rc = ERROR_INTERNAL_ERROR;
1746 gdiGfxSurface* surface =
nullptr;
1747 EnterCriticalSection(&context->mux);
1749 WINPR_ASSERT(context->GetSurfaceData);
1750 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1755 if (surface->windowMapped)
1757 WLog_WARN(TAG,
"surface already windowMapped when trying to set outputMapped");
1761 surface->outputMapped = TRUE;
1762 surface->outputOriginX = surfaceToOutput->outputOriginX;
1763 surface->outputOriginY = surfaceToOutput->outputOriginY;
1764 surface->outputTargetWidth = surface->mappedWidth;
1765 surface->outputTargetHeight = surface->mappedHeight;
1766 region16_clear(&surface->invalidRegion);
1769 LeaveCriticalSection(&context->mux);
1774gdi_MapSurfaceToScaledOutput(RdpgfxClientContext* context,
1777 UINT rc = ERROR_INTERNAL_ERROR;
1778 gdiGfxSurface* surface =
nullptr;
1779 EnterCriticalSection(&context->mux);
1781 WINPR_ASSERT(context->GetSurfaceData);
1782 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1787 if (surface->windowMapped)
1789 WLog_WARN(TAG,
"surface already windowMapped when trying to set outputMapped");
1793 surface->outputMapped = TRUE;
1794 surface->outputOriginX = surfaceToOutput->outputOriginX;
1795 surface->outputOriginY = surfaceToOutput->outputOriginY;
1796 surface->outputTargetWidth = surfaceToOutput->targetWidth;
1797 surface->outputTargetHeight = surfaceToOutput->targetHeight;
1798 region16_clear(&surface->invalidRegion);
1801 LeaveCriticalSection(&context->mux);
1810static UINT gdi_MapSurfaceToWindow(RdpgfxClientContext* context,
1813 UINT rc = ERROR_INTERNAL_ERROR;
1814 gdiGfxSurface* surface =
nullptr;
1815 EnterCriticalSection(&context->mux);
1817 WINPR_ASSERT(context->GetSurfaceData);
1818 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1823 if (surface->outputMapped)
1825 WLog_WARN(TAG,
"surface already outputMapped when trying to set windowMapped");
1829 if (surface->windowMapped)
1831 if (surface->windowId != surfaceToWindow->windowId)
1833 WLog_WARN(TAG,
"surface windowId mismatch, has %" PRIu64
", expected %" PRIu64,
1834 surface->windowId, surfaceToWindow->windowId);
1838 surface->windowMapped = TRUE;
1840 surface->windowId = surfaceToWindow->windowId;
1841 surface->mappedWidth = surfaceToWindow->mappedWidth;
1842 surface->mappedHeight = surfaceToWindow->mappedHeight;
1843 surface->outputTargetWidth = surfaceToWindow->mappedWidth;
1844 surface->outputTargetHeight = surfaceToWindow->mappedHeight;
1845 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1846 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1848 LeaveCriticalSection(&context->mux);
1853gdi_MapSurfaceToScaledWindow(RdpgfxClientContext* context,
1856 UINT rc = ERROR_INTERNAL_ERROR;
1857 gdiGfxSurface* surface =
nullptr;
1858 EnterCriticalSection(&context->mux);
1860 WINPR_ASSERT(context->GetSurfaceData);
1861 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1866 if (surface->outputMapped)
1868 WLog_WARN(TAG,
"surface already outputMapped when trying to set windowMapped");
1872 if (surface->windowMapped)
1874 if (surface->windowId != surfaceToWindow->windowId)
1876 WLog_WARN(TAG,
"surface windowId mismatch, has %" PRIu64
", expected %" PRIu64,
1877 surface->windowId, surfaceToWindow->windowId);
1881 surface->windowMapped = TRUE;
1883 surface->windowId = surfaceToWindow->windowId;
1884 surface->mappedWidth = surfaceToWindow->mappedWidth;
1885 surface->mappedHeight = surfaceToWindow->mappedHeight;
1886 surface->outputTargetWidth = surfaceToWindow->targetWidth;
1887 surface->outputTargetHeight = surfaceToWindow->targetHeight;
1888 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1889 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1891 LeaveCriticalSection(&context->mux);
1895BOOL gdi_graphics_pipeline_init(rdpGdi* gdi, RdpgfxClientContext* gfx)
1897 return gdi_graphics_pipeline_init_ex(gdi, gfx,
nullptr,
nullptr,
nullptr);
1900BOOL gdi_graphics_pipeline_init_ex(rdpGdi* gdi, RdpgfxClientContext* gfx,
1901 pcRdpgfxMapWindowForSurface map,
1902 pcRdpgfxUnmapWindowForSurface unmap,
1903 pcRdpgfxUpdateSurfaceArea update)
1905 if (!gdi || !gfx || !gdi->context || !gdi->context->settings)
1908 rdpContext* context = gdi->context;
1909 rdpSettings* settings = context->settings;
1912 gfx->custom = (
void*)gdi;
1913 gfx->ResetGraphics = gdi_ResetGraphics;
1914 gfx->StartFrame = gdi_StartFrame;
1915 gfx->EndFrame = gdi_EndFrame;
1916 gfx->SurfaceCommand = gdi_SurfaceCommand;
1917 gfx->DeleteEncodingContext = gdi_DeleteEncodingContext;
1918 gfx->CreateSurface = gdi_CreateSurface;
1919 gfx->DeleteSurface = gdi_DeleteSurface;
1920 gfx->SolidFill = gdi_SolidFill;
1921 gfx->SurfaceToSurface = gdi_SurfaceToSurface;
1922 gfx->SurfaceToCache = gdi_SurfaceToCache;
1923 gfx->CacheToSurface = gdi_CacheToSurface;
1924 gfx->CacheImportReply = gdi_CacheImportReply;
1925 gfx->ImportCacheEntry = gdi_ImportCacheEntry;
1926 gfx->ExportCacheEntry = gdi_ExportCacheEntry;
1927 gfx->EvictCacheEntry = gdi_EvictCacheEntry;
1928 gfx->MapSurfaceToOutput = gdi_MapSurfaceToOutput;
1929 gfx->MapSurfaceToWindow = gdi_MapSurfaceToWindow;
1930 gfx->MapSurfaceToScaledOutput = gdi_MapSurfaceToScaledOutput;
1931 gfx->MapSurfaceToScaledWindow = gdi_MapSurfaceToScaledWindow;
1932 gfx->UpdateSurfaces = gdi_UpdateSurfaces;
1933 gfx->MapWindowForSurface = map;
1934 gfx->UnmapWindowForSurface = unmap;
1935 gfx->UpdateSurfaceArea = update;
1943 gfx->codecs = freerdp_client_codecs_new(flags);
1946 if (!freerdp_client_codecs_prepare(gfx->codecs, FREERDP_CODEC_ALL, w, h))
1949 InitializeCriticalSection(&gfx->mux);
1950 PROFILER_CREATE(gfx->SurfaceProfiler,
"GFX-PROFILER")
1958 gdi->graphicsReset = TRUE;
1961 gfx->UpdateSurfaceArea =
nullptr;
1962 gfx->UpdateSurfaces =
nullptr;
1963 gfx->SurfaceCommand =
nullptr;
1969void gdi_graphics_pipeline_uninit(rdpGdi* gdi, RdpgfxClientContext* gfx)
1977 gfx->custom =
nullptr;
1978 freerdp_client_codecs_free(gfx->codecs);
1979 gfx->codecs =
nullptr;
1980 DeleteCriticalSection(&gfx->mux);
1981 PROFILER_PRINT_HEADER
1982 PROFILER_PRINT(gfx->SurfaceProfiler)
1983 PROFILER_PRINT_FOOTER
1984 PROFILER_FREE(gfx->SurfaceProfiler)
1987const
char* rdpgfx_caps_version_str(UINT32 capsVersion)
1989 switch (capsVersion)
1991 case RDPGFX_CAPVERSION_8:
1992 return "RDPGFX_CAPVERSION_8";
1993 case RDPGFX_CAPVERSION_81:
1994 return "RDPGFX_CAPVERSION_81";
1995 case RDPGFX_CAPVERSION_10:
1996 return "RDPGFX_CAPVERSION_10";
1997 case RDPGFX_CAPVERSION_101:
1998 return "RDPGFX_CAPVERSION_101";
1999 case RDPGFX_CAPVERSION_102:
2000 return "RDPGFX_CAPVERSION_102";
2001 case RDPGFX_CAPVERSION_103:
2002 return "RDPGFX_CAPVERSION_103";
2003 case RDPGFX_CAPVERSION_104:
2004 return "RDPGFX_CAPVERSION_104";
2005 case RDPGFX_CAPVERSION_105:
2006 return "RDPGFX_CAPVERSION_105";
2007 case RDPGFX_CAPVERSION_106:
2008 return "RDPGFX_CAPVERSION_106";
2009 case RDPGFX_CAPVERSION_106_ERR:
2010 return "RDPGFX_CAPVERSION_106_ERR";
2011 case RDPGFX_CAPVERSION_107:
2012 return "RDPGFX_CAPVERSION_107";
2014 return "RDPGFX_CAPVERSION_UNKNOWN";
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 val)
Sets a UINT32 settings value.
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_codecs_flags(const rdpSettings *settings)
helper function to get a mask of supported codec flags.
WINPR_ATTR_NODISCARD FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
WINPR_ATTR_NODISCARD FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.