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);
425static UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, RdpgfxClientContext* context,
428 UINT status = ERROR_INTERNAL_ERROR;
429 gdiGfxSurface* surface =
nullptr;
434 WINPR_ASSERT(context);
437 WINPR_ASSERT(context->GetSurfaceData);
439 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
443 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
444 return ERROR_NOT_FOUND;
447 if (!is_within_surface(surface, cmd))
448 return ERROR_INVALID_DATA;
450 WINPR_ASSERT(surface->codecs);
451 rfx_context_set_pixel_format(surface->codecs->rfx, cmd->format);
452 region16_init(&invalidRegion);
454 if (!rfx_process_message(surface->codecs->rfx, cmd->data, cmd->length, cmd->left, cmd->top,
455 surface->data, surface->format, surface->scanline, surface->height,
458 WLog_ERR(TAG,
"Failed to process RemoteFX message");
462 rects = region16_rects(&invalidRegion, &nrRects);
463 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
466 if (status != CHANNEL_RC_OK)
469 for (UINT32 x = 0; x < nrRects; x++)
471 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]))
475 status = gdi_interFrameUpdate(gdi, context);
478 region16_uninit(&invalidRegion);
487static UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context,
491 UINT status = CHANNEL_RC_OK;
492 gdiGfxSurface* surface =
nullptr;
495 WINPR_ASSERT(context);
498 WINPR_ASSERT(context->GetSurfaceData);
500 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
504 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
505 return ERROR_NOT_FOUND;
508 if (!is_within_surface(surface, cmd))
509 return ERROR_INVALID_DATA;
511 WINPR_ASSERT(surface->codecs);
512 rc = clear_decompress(surface->codecs->clear, cmd->data, cmd->length, cmd->width, cmd->height,
513 surface->data, surface->format, surface->scanline, cmd->left, cmd->top,
514 surface->width, surface->height, &gdi->palette);
518 WLog_ERR(TAG,
"clear_decompress failure: %" PRId32
"", rc);
519 return ERROR_INTERNAL_ERROR;
522 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
523 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
524 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
525 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
526 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
528 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
531 if (status != CHANNEL_RC_OK)
534 status = gdi_interFrameUpdate(gdi, context);
545static UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context,
548 UINT status = CHANNEL_RC_OK;
549 BYTE* DstData =
nullptr;
550 gdiGfxSurface* surface =
nullptr;
553 WINPR_ASSERT(context);
556 WINPR_ASSERT(context->GetSurfaceData);
558 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
562 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
563 return ERROR_NOT_FOUND;
566 DstData = surface->data;
568 if (!is_within_surface(surface, cmd))
569 return ERROR_INVALID_DATA;
571 if (!freerdp_bitmap_decompress_planar(surface->codecs->planar, cmd->data, cmd->length,
572 cmd->width, cmd->height, DstData, surface->format,
573 surface->scanline, cmd->left, cmd->top, cmd->width,
575 return ERROR_INTERNAL_ERROR;
577 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
578 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
579 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
580 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
581 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
583 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
586 if (status != CHANNEL_RC_OK)
589 status = gdi_interFrameUpdate(gdi, context);
600static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, RdpgfxClientContext* context,
605 UINT status = CHANNEL_RC_OK;
606 gdiGfxSurface* surface =
nullptr;
610 WINPR_ASSERT(context);
613 WINPR_ASSERT(context->GetSurfaceData);
615 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
619 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
620 return ERROR_NOT_FOUND;
625 surface->h264 = h264_context_new(FALSE);
629 WLog_ERR(TAG,
"unable to create h264 context");
630 return ERROR_NOT_ENOUGH_MEMORY;
633 if (!h264_context_reset(surface->h264, surface->width, surface->height))
634 return ERROR_INTERNAL_ERROR;
638 return ERROR_NOT_SUPPORTED;
640 if (!is_within_surface(surface, cmd))
641 return ERROR_INVALID_DATA;
646 return ERROR_INTERNAL_ERROR;
649 rc = avc420_decompress(surface->h264, bs->data, bs->length, surface->data, surface->format,
650 surface->scanline, surface->width, surface->height, meta->regionRects,
651 meta->numRegionRects);
655 WLog_WARN(TAG,
"avc420_decompress failure: %" PRId32
", ignoring update.", rc);
656 return CHANNEL_RC_OK;
659 for (UINT32 i = 0; i < meta->numRegionRects; i++)
661 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
662 &(meta->regionRects[i])))
666 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
667 meta->numRegionRects, meta->regionRects);
669 if (status != CHANNEL_RC_OK)
672 status = gdi_interFrameUpdate(gdi, context);
677 return ERROR_NOT_SUPPORTED;
686static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context,
691 UINT status = CHANNEL_RC_OK;
692 gdiGfxSurface* surface =
nullptr;
699 WINPR_ASSERT(context);
702 WINPR_ASSERT(context->GetSurfaceData);
704 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
708 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
709 return ERROR_NOT_FOUND;
714 surface->h264 = h264_context_new(FALSE);
718 WLog_ERR(TAG,
"unable to create h264 context");
719 return ERROR_NOT_ENOUGH_MEMORY;
722 if (!h264_context_reset(surface->h264, surface->width, surface->height))
723 return ERROR_INTERNAL_ERROR;
727 return ERROR_NOT_SUPPORTED;
729 if (!is_within_surface(surface, cmd))
730 return ERROR_INVALID_DATA;
735 return ERROR_INTERNAL_ERROR;
737 avc1 = &bs->bitstream[0];
738 avc2 = &bs->bitstream[1];
741 rc = avc444_decompress(surface->h264, bs->LC, meta1->regionRects, meta1->numRegionRects,
742 avc1->data, avc1->length, meta2->regionRects, meta2->numRegionRects,
743 avc2->data, avc2->length, surface->data, surface->format,
744 surface->scanline, surface->width, surface->height, cmd->codecId);
748 WLog_WARN(TAG,
"avc444_decompress failure: %" PRIu32
", ignoring update.", status);
749 return CHANNEL_RC_OK;
752 for (UINT32 i = 0; i < meta1->numRegionRects; i++)
754 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
755 &(meta1->regionRects[i])))
759 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
760 meta1->numRegionRects, meta1->regionRects);
762 if (status != CHANNEL_RC_OK)
765 for (UINT32 i = 0; i < meta2->numRegionRects; i++)
767 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
768 &(meta2->regionRects[i])))
772 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
773 meta2->numRegionRects, meta2->regionRects);
775 if (status != CHANNEL_RC_OK)
778 status = gdi_interFrameUpdate(gdi, context);
783 return ERROR_NOT_SUPPORTED;
787static BOOL gdi_apply_alpha(BYTE* data, UINT32 format, UINT32 stride,
RECTANGLE_16* rect,
788 UINT32 startOffsetX, UINT32 count, BYTE a)
792 const UINT32 bpp = FreeRDPGetBytesPerPixel(format);
795 for (
size_t y = rect->top; y < rect->bottom; y++)
797 BYTE* line = &data[y * stride];
799 for (
size_t x = first ? rect->left + startOffsetX : rect->left; x < rect->right; x++)
805 if (written == count)
808 BYTE* src = &line[x * bpp];
809 UINT32 color = FreeRDPReadColor(src, format);
810 FreeRDPSplitColor(color, format, &r, &g, &b,
nullptr,
nullptr);
811 color = FreeRDPGetColor(format, r, g, b, a);
812 FreeRDPWriteColor(src, format, color);
826static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context,
829 UINT status = CHANNEL_RC_OK;
831 UINT16 compressed = 0;
832 gdiGfxSurface* surface =
nullptr;
837 WINPR_ASSERT(context);
840 s = Stream_StaticConstInit(&buffer, cmd->data, cmd->length);
842 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
843 return ERROR_INVALID_DATA;
845 WINPR_ASSERT(context->GetSurfaceData);
847 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
851 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
852 return ERROR_NOT_FOUND;
855 if (!is_within_surface(surface, cmd))
856 return ERROR_INVALID_DATA;
858 Stream_Read_UINT16(s, alphaSig);
859 Stream_Read_UINT16(s, compressed);
861 if (alphaSig != 0x414C)
862 return ERROR_INVALID_DATA;
866 if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, cmd->height, cmd->width))
867 return ERROR_INVALID_DATA;
869 for (
size_t y = cmd->top; y < cmd->top + cmd->height; y++)
871 BYTE* line = &surface->data[y * surface->scanline];
873 for (
size_t x = cmd->left; x < cmd->left + cmd->width; x++)
880 BYTE* src = &line[x * FreeRDPGetBytesPerPixel(surface->format)];
881 Stream_Read_UINT8(s, a);
882 color = FreeRDPReadColor(src, surface->format);
883 FreeRDPSplitColor(color, surface->format, &r, &g, &b,
nullptr,
nullptr);
884 color = FreeRDPGetColor(surface->format, r, g, b, a);
885 FreeRDPWriteColor(src, surface->format, color);
891 UINT32 startOffsetX = 0;
893 rect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
894 rect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
895 rect.right = (UINT16)MIN(UINT16_MAX, cmd->left + cmd->width);
896 rect.bottom = (UINT16)MIN(UINT16_MAX, cmd->top + cmd->height);
898 while (rect.top < rect.bottom)
903 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
904 return ERROR_INVALID_DATA;
906 Stream_Read_UINT8(s, a);
907 Stream_Read_UINT8(s, count);
911 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
912 return ERROR_INVALID_DATA;
914 Stream_Read_UINT16(s, count);
918 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
919 return ERROR_INVALID_DATA;
921 Stream_Read_UINT32(s, count);
925 if (!gdi_apply_alpha(surface->data, surface->format, surface->scanline, &rect,
926 startOffsetX, count, a))
927 return ERROR_INTERNAL_ERROR;
929 startOffsetX += count;
931 while (startOffsetX >= cmd->width)
933 startOffsetX -= cmd->width;
939 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
940 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
941 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
942 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
943 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
945 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
948 if (status != CHANNEL_RC_OK)
951 status = gdi_interFrameUpdate(gdi, context);
957#if defined(WITH_GFX_FRAME_DUMP)
960 static UINT64 xxx = 0;
961 const char* path =
"/tmp/dump/";
963 char fname[1024] = WINPR_C_ARRAY_INIT;
965 snprintf(fname,
sizeof(fname),
"%s/%08" PRIx64
".raw", path, xxx++);
966 FILE* fp = fopen(fname,
"w");
969 (void)fprintf(fp,
"frameid: %" PRIu32
"\n", frameId);
970 (void)fprintf(fp,
"surfaceId: %" PRIu32
"\n", cmd->surfaceId);
971 (void)fprintf(fp,
"codecId: %" PRIu32
"\n", cmd->codecId);
972 (void)fprintf(fp,
"contextId: %" PRIu32
"\n", cmd->contextId);
973 (void)fprintf(fp,
"format: %" PRIu32
"\n", cmd->format);
974 (void)fprintf(fp,
"left: %" PRIu32
"\n", cmd->left);
975 (void)fprintf(fp,
"top: %" PRIu32
"\n", cmd->top);
976 (void)fprintf(fp,
"right: %" PRIu32
"\n", cmd->right);
977 (void)fprintf(fp,
"bottom: %" PRIu32
"\n", cmd->bottom);
978 (void)fprintf(fp,
"width: %" PRIu32
"\n", cmd->width);
979 (void)fprintf(fp,
"height: %" PRIu32
"\n", cmd->height);
980 (void)fprintf(fp,
"length: %" PRIu32
"\n", cmd->length);
982 char* bdata = crypto_base64_encode_ex(cmd->data, cmd->length, FALSE);
983 (void)fprintf(fp,
"data: %s\n", bdata);
994static UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context,
998 UINT status = ERROR_INTERNAL_ERROR;
999 gdiGfxSurface* surface =
nullptr;
1009 WINPR_ASSERT(context);
1011 const UINT16 surfaceId = (UINT16)MIN(UINT16_MAX, cmd->surfaceId);
1013 WINPR_ASSERT(context->GetSurfaceData);
1014 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceId);
1018 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
1019 return ERROR_NOT_FOUND;
1022 if (!is_within_surface(surface, cmd))
1023 return ERROR_INVALID_DATA;
1025 WINPR_ASSERT(surface->codecs);
1026 rc = progressive_create_surface_context(surface->codecs->progressive, surfaceId, surface->width,
1031 WLog_ERR(TAG,
"progressive_create_surface_context failure: %" PRId32
"", rc);
1032 return ERROR_INTERNAL_ERROR;
1035 region16_init(&invalidRegion);
1037 rc = progressive_decompress(surface->codecs->progressive, cmd->data, cmd->length, surface->data,
1038 surface->format, surface->scanline, cmd->left, cmd->top,
1039 &invalidRegion, surfaceId, gdi->frameId);
1043 WLog_ERR(TAG,
"progressive_decompress failure: %" PRId32
"", rc);
1047 rects = region16_rects(&invalidRegion, &nrRects);
1048 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1051 if (status != CHANNEL_RC_OK)
1054 status = ERROR_INTERNAL_ERROR;
1055 for (UINT32 x = 0; x < nrRects; x++)
1057 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]))
1061 status = gdi_interFrameUpdate(gdi, context);
1065 region16_uninit(&invalidRegion);
1076 UINT status = CHANNEL_RC_OK;
1077 rdpGdi* gdi =
nullptr;
1079 if (!context || !cmd)
1080 return ERROR_INVALID_PARAMETER;
1082 gdi = (rdpGdi*)context->custom;
1084 EnterCriticalSection(&context->mux);
1085 const UINT16 codecId = WINPR_ASSERTING_INT_CAST(UINT16, cmd->codecId);
1086 WLog_Print(gdi->log, WLOG_TRACE,
1087 "surfaceId=%" PRIu32
", codec=%s [%" PRIu32
"], contextId=%" PRIu32
", format=%s, "
1088 "left=%" PRIu32
", top=%" PRIu32
", right=%" PRIu32
", bottom=%" PRIu32
1089 ", width=%" PRIu32
", height=%" PRIu32
" "
1090 "length=%" PRIu32
", data=%p, extra=%p",
1091 cmd->surfaceId, rdpgfx_get_codec_id_string(codecId), cmd->codecId, cmd->contextId,
1092 FreeRDPGetColorFormatName(cmd->format), cmd->left, cmd->top, cmd->right, cmd->bottom,
1093 cmd->width, cmd->height, cmd->length, (
void*)cmd->data, (
void*)cmd->extra);
1094#if defined(WITH_GFX_FRAME_DUMP)
1095 dump_cmd(cmd, gdi->frameId);
1100 case RDPGFX_CODECID_UNCOMPRESSED:
1101 status = gdi_SurfaceCommand_Uncompressed(gdi, context, cmd);
1104 case RDPGFX_CODECID_CAVIDEO:
1105 status = gdi_SurfaceCommand_RemoteFX(gdi, context, cmd);
1108 case RDPGFX_CODECID_CLEARCODEC:
1109 status = gdi_SurfaceCommand_ClearCodec(gdi, context, cmd);
1112 case RDPGFX_CODECID_PLANAR:
1113 status = gdi_SurfaceCommand_Planar(gdi, context, cmd);
1116 case RDPGFX_CODECID_AVC420:
1117 status = gdi_SurfaceCommand_AVC420(gdi, context, cmd);
1120 case RDPGFX_CODECID_AVC444v2:
1121 case RDPGFX_CODECID_AVC444:
1122 status = gdi_SurfaceCommand_AVC444(gdi, context, cmd);
1125 case RDPGFX_CODECID_ALPHA:
1126 status = gdi_SurfaceCommand_Alpha(gdi, context, cmd);
1129 case RDPGFX_CODECID_CAPROGRESSIVE:
1130 status = gdi_SurfaceCommand_Progressive(gdi, context, cmd);
1133 case RDPGFX_CODECID_CAPROGRESSIVE_V2:
1134 WLog_WARN(TAG,
"SurfaceCommand %s [0x%08" PRIX16
"] not implemented",
1135 rdpgfx_get_codec_id_string(codecId), codecId);
1139 WLog_WARN(TAG,
"Invalid SurfaceCommand %s [0x%08" PRIX16
"]",
1140 rdpgfx_get_codec_id_string(codecId), codecId);
1144 LeaveCriticalSection(&context->mux);
1154gdi_DeleteEncodingContext(RdpgfxClientContext* context,
1157 WINPR_ASSERT(context);
1158 WINPR_ASSERT(deleteEncodingContext);
1159 WINPR_UNUSED(context);
1160 WINPR_UNUSED(deleteEncodingContext);
1161 return CHANNEL_RC_OK;
1169static UINT gdi_CreateSurface(RdpgfxClientContext* context,
1172 UINT rc = ERROR_INTERNAL_ERROR;
1173 gdiGfxSurface* surface =
nullptr;
1174 rdpGdi* gdi =
nullptr;
1175 WINPR_ASSERT(context);
1176 WINPR_ASSERT(createSurface);
1177 gdi = (rdpGdi*)context->custom;
1179 WINPR_ASSERT(gdi->context);
1180 EnterCriticalSection(&context->mux);
1181 surface = (gdiGfxSurface*)calloc(1,
sizeof(gdiGfxSurface));
1188 WINPR_ASSERT(context->codecs);
1189 surface->codecs = context->codecs;
1191 if (!surface->codecs)
1198 surface->surfaceId = createSurface->surfaceId;
1199 surface->width = gfx_align_scanline(createSurface->width, 16);
1200 surface->height = gfx_align_scanline(createSurface->height, 16);
1201 surface->mappedWidth = createSurface->width;
1202 surface->mappedHeight = createSurface->height;
1203 surface->outputTargetWidth = createSurface->width;
1204 surface->outputTargetHeight = createSurface->height;
1206 switch (createSurface->pixelFormat)
1208 case GFX_PIXEL_FORMAT_ARGB_8888:
1209 surface->format = PIXEL_FORMAT_BGRA32;
1212 case GFX_PIXEL_FORMAT_XRGB_8888:
1213 surface->format = PIXEL_FORMAT_BGRX32;
1221 surface->scanline = gfx_align_scanline(surface->width * 4UL, 16);
1222 surface->data = (BYTE*)winpr_aligned_malloc(1ull * surface->scanline * surface->height, 16);
1230 memset(surface->data, 0xFF, (
size_t)surface->scanline * surface->height);
1231 region16_init(&surface->invalidRegion);
1233 WINPR_ASSERT(context->SetSurfaceData);
1234 rc = context->SetSurfaceData(context, surface->surfaceId, (
void*)surface);
1236 LeaveCriticalSection(&context->mux);
1245static UINT gdi_DeleteSurface(RdpgfxClientContext* context,
1248 UINT rc = CHANNEL_RC_OK;
1249 UINT res = ERROR_INTERNAL_ERROR;
1250 rdpCodecs* codecs =
nullptr;
1251 gdiGfxSurface* surface =
nullptr;
1252 EnterCriticalSection(&context->mux);
1254 WINPR_ASSERT(context->GetSurfaceData);
1255 surface = (gdiGfxSurface*)context->GetSurfaceData(context, deleteSurface->surfaceId);
1259 if (surface->windowMapped)
1260 rc = IFCALLRESULT(CHANNEL_RC_OK, context->UnmapWindowForSurface, context,
1264 h264_context_free(surface->h264);
1266 region16_uninit(&surface->invalidRegion);
1267 codecs = surface->codecs;
1268 winpr_aligned_free(surface->data);
1272 WINPR_ASSERT(context->SetSurfaceData);
1273 res = context->SetSurfaceData(context, deleteSurface->surfaceId,
nullptr);
1277 if (codecs && codecs->progressive)
1278 progressive_delete_surface_context(codecs->progressive, deleteSurface->surfaceId);
1280 LeaveCriticalSection(&context->mux);
1284static BOOL intersect_rect(
const RECTANGLE_16* rect,
const gdiGfxSurface* surface,
1288 WINPR_ASSERT(surface);
1289 WINPR_ASSERT(prect);
1291 if (rect->left > rect->right)
1293 if (rect->left > surface->width)
1295 if (rect->top > rect->bottom)
1297 if (rect->top > surface->height)
1299 prect->left = rect->left;
1300 prect->top = rect->top;
1302 prect->right = MIN(rect->right, WINPR_ASSERTING_INT_CAST(UINT16, surface->width));
1303 prect->bottom = MIN(rect->bottom, WINPR_ASSERTING_INT_CAST(UINT16, surface->height));
1314 UINT status = ERROR_INTERNAL_ERROR;
1317 rdpGdi* gdi = (rdpGdi*)context->custom;
1319 EnterCriticalSection(&context->mux);
1321 WINPR_ASSERT(context->GetSurfaceData);
1322 gdiGfxSurface* surface = (gdiGfxSurface*)context->GetSurfaceData(context, solidFill->surfaceId);
1328 const BYTE b = solidFill->fillPixel.B;
1329 const BYTE g = solidFill->fillPixel.G;
1330 const BYTE r = solidFill->fillPixel.R;
1337 const UINT32 color = FreeRDPGetColor(surface->format, r, g, b, a);
1338 for (UINT16 index = 0; index < solidFill->fillRectCount; index++)
1340 const RECTANGLE_16* rect = &(solidFill->fillRects[index]);
1342 if (!intersect_rect(rect, surface, &invalidRect))
1345 const UINT32 nWidth = invalidRect.right - invalidRect.left;
1346 const UINT32 nHeight = invalidRect.bottom - invalidRect.top;
1348 if (!freerdp_image_fill(surface->data, surface->format, surface->scanline,
1349 invalidRect.left, invalidRect.top, nWidth, nHeight, color))
1352 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
1358 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1359 solidFill->fillRectCount, solidFill->fillRects);
1361 if (status != CHANNEL_RC_OK)
1364 LeaveCriticalSection(&context->mux);
1366 return gdi_interFrameUpdate(gdi, context);
1368 LeaveCriticalSection(&context->mux);
1377static UINT gdi_SurfaceToSurface(RdpgfxClientContext* context,
1380 UINT status = ERROR_INTERNAL_ERROR;
1381 BOOL sameSurface = 0;
1384 gdiGfxSurface* surfaceSrc =
nullptr;
1385 gdiGfxSurface* surfaceDst =
nullptr;
1386 rdpGdi* gdi = (rdpGdi*)context->custom;
1387 EnterCriticalSection(&context->mux);
1388 rectSrc = &(surfaceToSurface->rectSrc);
1390 WINPR_ASSERT(context->GetSurfaceData);
1391 surfaceSrc = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdSrc);
1392 sameSurface = (surfaceToSurface->surfaceIdSrc == surfaceToSurface->surfaceIdDest);
1396 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdDest);
1398 surfaceDst = surfaceSrc;
1400 if (!surfaceSrc || !surfaceDst)
1403 if (!is_rect_valid(rectSrc, surfaceSrc->width, surfaceSrc->height))
1407 const UINT32 nWidth = rectSrc->right - rectSrc->left;
1408 const UINT32 nHeight = rectSrc->bottom - rectSrc->top;
1410 for (UINT16 index = 0; index < surfaceToSurface->destPtsCount; index++)
1412 const RDPGFX_POINT16* destPt = &surfaceToSurface->destPts[index];
1414 (UINT16)MIN(UINT16_MAX, destPt->x + nWidth),
1415 (UINT16)MIN(UINT16_MAX, destPt->y + nHeight) };
1416 if (!is_rect_valid(&rect, surfaceDst->width, surfaceDst->height))
1419 const UINT32 rwidth = rect.right - rect.left;
1420 const UINT32 rheight = rect.bottom - rect.top;
1421 if (!freerdp_image_copy(surfaceDst->data, surfaceDst->format, surfaceDst->scanline,
1422 destPt->x, destPt->y, rwidth, rheight, surfaceSrc->data,
1423 surfaceSrc->format, surfaceSrc->scanline, rectSrc->left,
1424 rectSrc->top,
nullptr, FREERDP_FLIP_NONE))
1428 if (!region16_union_rect(&surfaceDst->invalidRegion, &surfaceDst->invalidRegion,
1431 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1432 surfaceDst->surfaceId, 1, &invalidRect);
1434 if (status != CHANNEL_RC_OK)
1439 LeaveCriticalSection(&context->mux);
1441 return gdi_interFrameUpdate(gdi, context);
1443 LeaveCriticalSection(&context->mux);
1447static void gdi_GfxCacheEntryFree(gdiGfxCacheEntry* entry)
1455static gdiGfxCacheEntry* gdi_GfxCacheEntryNew(UINT64 cacheKey, UINT32 width, UINT32 height,
1458 gdiGfxCacheEntry* cacheEntry = (gdiGfxCacheEntry*)calloc(1,
sizeof(gdiGfxCacheEntry));
1462 cacheEntry->cacheKey = cacheKey;
1463 cacheEntry->width = width;
1464 cacheEntry->height = height;
1465 cacheEntry->format = format;
1466 cacheEntry->scanline = gfx_align_scanline(cacheEntry->width * 4, 16);
1468 if ((cacheEntry->width > 0) && (cacheEntry->height > 0))
1470 cacheEntry->data = (BYTE*)calloc(cacheEntry->height, cacheEntry->scanline);
1472 if (!cacheEntry->data)
1477 gdi_GfxCacheEntryFree(cacheEntry);
1486static UINT gdi_SurfaceToCache(RdpgfxClientContext* context,
1489 gdiGfxCacheEntry* cacheEntry =
nullptr;
1490 UINT rc = ERROR_INTERNAL_ERROR;
1491 EnterCriticalSection(&context->mux);
1494 WINPR_ASSERT(context->GetSurfaceData);
1495 gdiGfxSurface* surface =
1496 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToCache->surfaceId);
1501 if (!is_rect_valid(rect, surface->width, surface->height))
1504 cacheEntry = gdi_GfxCacheEntryNew(surfaceToCache->cacheKey, (UINT32)(rect->right - rect->left),
1505 (UINT32)(rect->bottom - rect->top), surface->format);
1510 if (!cacheEntry->data)
1513 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1514 0, 0, cacheEntry->width, cacheEntry->height, surface->data,
1515 surface->format, surface->scanline, rect->left, rect->top,
1516 nullptr, FREERDP_FLIP_NONE))
1521 WINPR_ASSERT(context->EvictCacheEntry);
1522 rc = context->EvictCacheEntry(context, &evict);
1523 if (rc != CHANNEL_RC_OK)
1527 WINPR_ASSERT(context->SetCacheSlotData);
1528 rc = context->SetCacheSlotData(context, surfaceToCache->cacheSlot, (
void*)cacheEntry);
1530 if (rc != CHANNEL_RC_OK)
1531 gdi_GfxCacheEntryFree(cacheEntry);
1532 LeaveCriticalSection(&context->mux);
1541static UINT gdi_CacheToSurface(RdpgfxClientContext* context,
1544 UINT status = ERROR_INTERNAL_ERROR;
1545 gdiGfxSurface* surface =
nullptr;
1546 gdiGfxCacheEntry* cacheEntry =
nullptr;
1548 rdpGdi* gdi = (rdpGdi*)context->custom;
1550 EnterCriticalSection(&context->mux);
1552 WINPR_ASSERT(context->GetSurfaceData);
1553 surface = (gdiGfxSurface*)context->GetSurfaceData(context, cacheToSurface->surfaceId);
1555 WINPR_ASSERT(context->GetCacheSlotData);
1556 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheToSurface->cacheSlot);
1558 if (!surface || !cacheEntry)
1561 for (UINT16 index = 0; index < cacheToSurface->destPtsCount; index++)
1565 (UINT16)MIN(UINT16_MAX, destPt->x + cacheEntry->width),
1566 (UINT16)MIN(UINT16_MAX, destPt->y + cacheEntry->height) };
1568 if (rectangle_is_empty(&rect))
1571 if (!is_rect_valid(&rect, surface->width, surface->height))
1574 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline,
1575 destPt->x, destPt->y, cacheEntry->width,
1576 cacheEntry->height, cacheEntry->data, cacheEntry->format,
1577 cacheEntry->scanline, 0, 0,
nullptr, FREERDP_FLIP_NONE))
1581 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect))
1583 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1584 surface->surfaceId, 1, &invalidRect);
1586 if (status != CHANNEL_RC_OK)
1590 LeaveCriticalSection(&context->mux);
1592 return gdi_interFrameUpdate(gdi, context);
1595 LeaveCriticalSection(&context->mux);
1604static UINT gdi_CacheImportReply(RdpgfxClientContext* context,
1608 const UINT16* slots =
nullptr;
1609 UINT error = CHANNEL_RC_OK;
1611 slots = cacheImportReply->cacheSlots;
1612 count = cacheImportReply->importedEntriesCount;
1614 for (UINT16 index = 0; index < count; index++)
1616 UINT16 cacheSlot = slots[index];
1621 WINPR_ASSERT(context->GetCacheSlotData);
1622 gdiGfxCacheEntry* cacheEntry =
1623 (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1628 cacheEntry = gdi_GfxCacheEntryNew(cacheSlot, 0, 0, PIXEL_FORMAT_BGRX32);
1631 return ERROR_INTERNAL_ERROR;
1633 WINPR_ASSERT(context->SetCacheSlotData);
1634 error = context->SetCacheSlotData(context, cacheSlot, (
void*)cacheEntry);
1638 WLog_ERR(TAG,
"CacheImportReply: SetCacheSlotData failed with error %" PRIu32
"",
1640 gdi_GfxCacheEntryFree(cacheEntry);
1648static UINT gdi_ImportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1651 UINT error = ERROR_INTERNAL_ERROR;
1652 gdiGfxCacheEntry* cacheEntry =
nullptr;
1655 return CHANNEL_RC_OK;
1657 cacheEntry = gdi_GfxCacheEntryNew(importCacheEntry->key64, importCacheEntry->width,
1658 importCacheEntry->height, PIXEL_FORMAT_BGRX32);
1663 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1664 0, 0, cacheEntry->width, cacheEntry->height,
1665 importCacheEntry->data, PIXEL_FORMAT_BGRX32, 0, 0, 0,
1666 nullptr, FREERDP_FLIP_NONE))
1671 WINPR_ASSERT(context->EvictCacheEntry);
1672 error = context->EvictCacheEntry(context, &evict);
1674 if (error != CHANNEL_RC_OK)
1677 WINPR_ASSERT(context->SetCacheSlotData);
1678 error = context->SetCacheSlotData(context, cacheSlot, (
void*)cacheEntry);
1683 gdi_GfxCacheEntryFree(cacheEntry);
1684 WLog_ERR(TAG,
"ImportCacheEntry: SetCacheSlotData failed with error %" PRIu32
"", error);
1690static UINT gdi_ExportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1693 gdiGfxCacheEntry* cacheEntry =
nullptr;
1695 WINPR_ASSERT(context->GetCacheSlotData);
1696 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1700 exportCacheEntry->key64 = cacheEntry->cacheKey;
1701 exportCacheEntry->width = (UINT16)MIN(UINT16_MAX, cacheEntry->width);
1702 exportCacheEntry->height = (UINT16)MIN(UINT16_MAX, cacheEntry->height);
1703 exportCacheEntry->size = cacheEntry->width * cacheEntry->height * 4;
1704 exportCacheEntry->flags = 0;
1705 exportCacheEntry->data = cacheEntry->data;
1706 return CHANNEL_RC_OK;
1709 return ERROR_NOT_FOUND;
1717static UINT gdi_EvictCacheEntry(RdpgfxClientContext* context,
1720 gdiGfxCacheEntry* cacheEntry =
nullptr;
1721 UINT rc = ERROR_NOT_FOUND;
1723 WINPR_ASSERT(context);
1724 WINPR_ASSERT(evictCacheEntry);
1726 EnterCriticalSection(&context->mux);
1728 WINPR_ASSERT(context->GetCacheSlotData);
1729 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, evictCacheEntry->cacheSlot);
1731 gdi_GfxCacheEntryFree(cacheEntry);
1733 WINPR_ASSERT(context->SetCacheSlotData);
1734 rc = context->SetCacheSlotData(context, evictCacheEntry->cacheSlot,
nullptr);
1735 LeaveCriticalSection(&context->mux);
1744static UINT gdi_MapSurfaceToOutput(RdpgfxClientContext* context,
1747 UINT rc = ERROR_INTERNAL_ERROR;
1748 gdiGfxSurface* surface =
nullptr;
1749 EnterCriticalSection(&context->mux);
1751 WINPR_ASSERT(context->GetSurfaceData);
1752 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1757 if (surface->windowMapped)
1759 WLog_WARN(TAG,
"surface already windowMapped when trying to set outputMapped");
1763 surface->outputMapped = TRUE;
1764 surface->outputOriginX = surfaceToOutput->outputOriginX;
1765 surface->outputOriginY = surfaceToOutput->outputOriginY;
1766 surface->outputTargetWidth = surface->mappedWidth;
1767 surface->outputTargetHeight = surface->mappedHeight;
1768 region16_clear(&surface->invalidRegion);
1771 LeaveCriticalSection(&context->mux);
1776gdi_MapSurfaceToScaledOutput(RdpgfxClientContext* context,
1779 UINT rc = ERROR_INTERNAL_ERROR;
1780 gdiGfxSurface* surface =
nullptr;
1781 EnterCriticalSection(&context->mux);
1783 WINPR_ASSERT(context->GetSurfaceData);
1784 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1789 if (surface->windowMapped)
1791 WLog_WARN(TAG,
"surface already windowMapped when trying to set outputMapped");
1795 surface->outputMapped = TRUE;
1796 surface->outputOriginX = surfaceToOutput->outputOriginX;
1797 surface->outputOriginY = surfaceToOutput->outputOriginY;
1798 surface->outputTargetWidth = surfaceToOutput->targetWidth;
1799 surface->outputTargetHeight = surfaceToOutput->targetHeight;
1800 region16_clear(&surface->invalidRegion);
1803 LeaveCriticalSection(&context->mux);
1812static UINT gdi_MapSurfaceToWindow(RdpgfxClientContext* context,
1815 UINT rc = ERROR_INTERNAL_ERROR;
1816 gdiGfxSurface* surface =
nullptr;
1817 EnterCriticalSection(&context->mux);
1819 WINPR_ASSERT(context->GetSurfaceData);
1820 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1825 if (surface->outputMapped)
1827 WLog_WARN(TAG,
"surface already outputMapped when trying to set windowMapped");
1831 if (surface->windowMapped)
1833 if (surface->windowId != surfaceToWindow->windowId)
1835 WLog_WARN(TAG,
"surface windowId mismatch, has %" PRIu64
", expected %" PRIu64,
1836 surface->windowId, surfaceToWindow->windowId);
1840 surface->windowMapped = TRUE;
1842 surface->windowId = surfaceToWindow->windowId;
1843 surface->mappedWidth = surfaceToWindow->mappedWidth;
1844 surface->mappedHeight = surfaceToWindow->mappedHeight;
1845 surface->outputTargetWidth = surfaceToWindow->mappedWidth;
1846 surface->outputTargetHeight = surfaceToWindow->mappedHeight;
1847 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1848 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1850 LeaveCriticalSection(&context->mux);
1855gdi_MapSurfaceToScaledWindow(RdpgfxClientContext* context,
1858 UINT rc = ERROR_INTERNAL_ERROR;
1859 gdiGfxSurface* surface =
nullptr;
1860 EnterCriticalSection(&context->mux);
1862 WINPR_ASSERT(context->GetSurfaceData);
1863 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1868 if (surface->outputMapped)
1870 WLog_WARN(TAG,
"surface already outputMapped when trying to set windowMapped");
1874 if (surface->windowMapped)
1876 if (surface->windowId != surfaceToWindow->windowId)
1878 WLog_WARN(TAG,
"surface windowId mismatch, has %" PRIu64
", expected %" PRIu64,
1879 surface->windowId, surfaceToWindow->windowId);
1883 surface->windowMapped = TRUE;
1885 surface->windowId = surfaceToWindow->windowId;
1886 surface->mappedWidth = surfaceToWindow->mappedWidth;
1887 surface->mappedHeight = surfaceToWindow->mappedHeight;
1888 surface->outputTargetWidth = surfaceToWindow->targetWidth;
1889 surface->outputTargetHeight = surfaceToWindow->targetHeight;
1890 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1891 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1893 LeaveCriticalSection(&context->mux);
1897BOOL gdi_graphics_pipeline_init(rdpGdi* gdi, RdpgfxClientContext* gfx)
1899 return gdi_graphics_pipeline_init_ex(gdi, gfx,
nullptr,
nullptr,
nullptr);
1902BOOL gdi_graphics_pipeline_init_ex(rdpGdi* gdi, RdpgfxClientContext* gfx,
1903 pcRdpgfxMapWindowForSurface map,
1904 pcRdpgfxUnmapWindowForSurface unmap,
1905 pcRdpgfxUpdateSurfaceArea update)
1907 if (!gdi || !gfx || !gdi->context || !gdi->context->settings)
1910 rdpContext* context = gdi->context;
1911 rdpSettings* settings = context->settings;
1914 gfx->custom = (
void*)gdi;
1915 gfx->ResetGraphics = gdi_ResetGraphics;
1916 gfx->StartFrame = gdi_StartFrame;
1917 gfx->EndFrame = gdi_EndFrame;
1918 gfx->SurfaceCommand = gdi_SurfaceCommand;
1919 gfx->DeleteEncodingContext = gdi_DeleteEncodingContext;
1920 gfx->CreateSurface = gdi_CreateSurface;
1921 gfx->DeleteSurface = gdi_DeleteSurface;
1922 gfx->SolidFill = gdi_SolidFill;
1923 gfx->SurfaceToSurface = gdi_SurfaceToSurface;
1924 gfx->SurfaceToCache = gdi_SurfaceToCache;
1925 gfx->CacheToSurface = gdi_CacheToSurface;
1926 gfx->CacheImportReply = gdi_CacheImportReply;
1927 gfx->ImportCacheEntry = gdi_ImportCacheEntry;
1928 gfx->ExportCacheEntry = gdi_ExportCacheEntry;
1929 gfx->EvictCacheEntry = gdi_EvictCacheEntry;
1930 gfx->MapSurfaceToOutput = gdi_MapSurfaceToOutput;
1931 gfx->MapSurfaceToWindow = gdi_MapSurfaceToWindow;
1932 gfx->MapSurfaceToScaledOutput = gdi_MapSurfaceToScaledOutput;
1933 gfx->MapSurfaceToScaledWindow = gdi_MapSurfaceToScaledWindow;
1934 gfx->UpdateSurfaces = gdi_UpdateSurfaces;
1935 gfx->MapWindowForSurface = map;
1936 gfx->UnmapWindowForSurface = unmap;
1937 gfx->UpdateSurfaceArea = update;
1945 gfx->codecs = freerdp_client_codecs_new(flags);
1948 if (!freerdp_client_codecs_prepare(gfx->codecs, FREERDP_CODEC_ALL, w, h))
1951 InitializeCriticalSection(&gfx->mux);
1952 PROFILER_CREATE(gfx->SurfaceProfiler,
"GFX-PROFILER")
1960 gdi->graphicsReset = TRUE;
1963 gfx->UpdateSurfaceArea =
nullptr;
1964 gfx->UpdateSurfaces =
nullptr;
1965 gfx->SurfaceCommand =
nullptr;
1971void gdi_graphics_pipeline_uninit(rdpGdi* gdi, RdpgfxClientContext* gfx)
1979 gfx->custom =
nullptr;
1980 freerdp_client_codecs_free(gfx->codecs);
1981 gfx->codecs =
nullptr;
1982 DeleteCriticalSection(&gfx->mux);
1983 PROFILER_PRINT_HEADER
1984 PROFILER_PRINT(gfx->SurfaceProfiler)
1985 PROFILER_PRINT_FOOTER
1986 PROFILER_FREE(gfx->SurfaceProfiler)
1989const
char* rdpgfx_caps_version_str(UINT32 capsVersion)
1991 switch (capsVersion)
1993 case RDPGFX_CAPVERSION_8:
1994 return "RDPGFX_CAPVERSION_8";
1995 case RDPGFX_CAPVERSION_81:
1996 return "RDPGFX_CAPVERSION_81";
1997 case RDPGFX_CAPVERSION_10:
1998 return "RDPGFX_CAPVERSION_10";
1999 case RDPGFX_CAPVERSION_101:
2000 return "RDPGFX_CAPVERSION_101";
2001 case RDPGFX_CAPVERSION_102:
2002 return "RDPGFX_CAPVERSION_102";
2003 case RDPGFX_CAPVERSION_103:
2004 return "RDPGFX_CAPVERSION_103";
2005 case RDPGFX_CAPVERSION_104:
2006 return "RDPGFX_CAPVERSION_104";
2007 case RDPGFX_CAPVERSION_105:
2008 return "RDPGFX_CAPVERSION_105";
2009 case RDPGFX_CAPVERSION_106:
2010 return "RDPGFX_CAPVERSION_106";
2011 case RDPGFX_CAPVERSION_106_ERR:
2012 return "RDPGFX_CAPVERSION_106_ERR";
2013 case RDPGFX_CAPVERSION_107:
2014 return "RDPGFX_CAPVERSION_107";
2016 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.