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 if (!(rects = region16_rects(&surface->invalidRegion, &nbRects)) || !nbRects)
208 return CHANNEL_RC_OK;
210 if (!update_begin_paint(update))
213 for (UINT32 i = 0; i < nbRects; i++)
215 const UINT32 nXSrc = rects[i].left;
216 const UINT32 nYSrc = rects[i].top;
217 const UINT32 nXDst = (UINT32)MIN(surfaceX + nXSrc * sx, gdi->width - 1);
218 const UINT32 nYDst = (UINT32)MIN(surfaceY + nYSrc * sy, gdi->height - 1);
219 const UINT32 swidth = rects[i].right - rects[i].left;
220 const UINT32 sheight = rects[i].bottom - rects[i].top;
221 const UINT32 dwidth = MIN((UINT32)(swidth * sx), (UINT32)gdi->width - nXDst);
222 const UINT32 dheight = MIN((UINT32)(sheight * sy), (UINT32)gdi->height - nYDst);
224 if (!freerdp_image_scale(gdi->primary_buffer, gdi->dstFormat, gdi->stride, nXDst, nYDst,
225 dwidth, dheight, surface->data, surface->format, surface->scanline,
226 nXSrc, nYSrc, swidth, sheight))
228 rc = CHANNEL_RC_NULL_DATA;
232 if (!gdi_InvalidateRegion(gdi->primary->hdc, (INT32)nXDst, (INT32)nYDst, (INT32)dwidth,
240 if (!update_end_paint(update))
241 rc = ERROR_INTERNAL_ERROR;
243 region16_clear(&(surface->invalidRegion));
247static UINT gdi_WindowUpdate(RdpgfxClientContext* context, gdiGfxSurface* surface)
249 WINPR_ASSERT(context);
250 WINPR_ASSERT(surface);
251 return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateWindowFromSurface, context, surface);
254static UINT gdi_UpdateSurfaces(RdpgfxClientContext* context)
257 UINT16* pSurfaceIds =
nullptr;
259 WINPR_ASSERT(context);
261 rdpGdi* gdi = (rdpGdi*)context->custom;
264 EnterCriticalSection(&context->mux);
266 WINPR_ASSERT(context->GetSurfaceIds);
267 UINT status = context->GetSurfaceIds(context, &pSurfaceIds, &count);
268 if (status != CHANNEL_RC_OK)
271 for (UINT32 index = 0; index < count; index++)
273 WINPR_ASSERT(context->GetSurfaceData);
274 gdiGfxSurface* surface =
275 (gdiGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
281 if (context->UpdateSurfaceArea)
283 if (surface->handleInUpdateSurfaceArea)
287 if (surface->outputMapped)
288 status = gdi_OutputUpdate(gdi, surface);
289 else if (surface->windowMapped)
290 status = gdi_WindowUpdate(context, surface);
292 if (status != CHANNEL_RC_OK)
298 LeaveCriticalSection(&context->mux);
309 rdpGdi* gdi =
nullptr;
311 WINPR_ASSERT(context);
312 WINPR_ASSERT(startFrame);
314 gdi = (rdpGdi*)context->custom;
316 gdi->inGfxFrame = TRUE;
317 gdi->frameId = startFrame->frameId;
318 return CHANNEL_RC_OK;
321static UINT gdi_call_update_surfaces(RdpgfxClientContext* context)
323 WINPR_ASSERT(context);
324 return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaces, context);
332static UINT gdi_EndFrame(RdpgfxClientContext* context,
335 WINPR_ASSERT(context);
336 WINPR_ASSERT(endFrame);
338 rdpGdi* gdi = (rdpGdi*)context->custom;
340 const UINT status = gdi_call_update_surfaces(context);
341 gdi->inGfxFrame = FALSE;
345static UINT gdi_interFrameUpdate(rdpGdi* gdi, RdpgfxClientContext* context)
348 UINT status = CHANNEL_RC_OK;
349 if (!gdi->inGfxFrame)
350 status = gdi_call_update_surfaces(context);
359static UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, RdpgfxClientContext* context,
362 UINT status = CHANNEL_RC_OK;
363 gdiGfxSurface* surface =
nullptr;
368 WINPR_ASSERT(context);
371 WINPR_ASSERT(context->GetSurfaceData);
373 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
377 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
378 return ERROR_NOT_FOUND;
381 if (!is_within_surface(surface, cmd))
382 return ERROR_INVALID_DATA;
384 bpp = FreeRDPGetBytesPerPixel(cmd->format);
385 size = 1ull * bpp * cmd->width * cmd->height;
386 if (cmd->length < size)
388 WLog_ERR(TAG,
"Not enough data, got %" PRIu32
", expected %" PRIuz, cmd->length, size);
389 return ERROR_INVALID_DATA;
392 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline, cmd->left,
393 cmd->top, cmd->width, cmd->height, cmd->data, cmd->format, 0,
394 0, 0,
nullptr, FREERDP_FLIP_NONE))
395 return ERROR_INTERNAL_ERROR;
397 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
398 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
399 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
400 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
401 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
403 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
406 if (status != CHANNEL_RC_OK)
409 status = gdi_interFrameUpdate(gdi, context);
420static UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, RdpgfxClientContext* context,
423 UINT status = ERROR_INTERNAL_ERROR;
424 gdiGfxSurface* surface =
nullptr;
429 WINPR_ASSERT(context);
432 WINPR_ASSERT(context->GetSurfaceData);
434 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
438 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
439 return ERROR_NOT_FOUND;
442 if (!is_within_surface(surface, cmd))
443 return ERROR_INVALID_DATA;
445 WINPR_ASSERT(surface->codecs);
446 rfx_context_set_pixel_format(surface->codecs->rfx, cmd->format);
447 region16_init(&invalidRegion);
449 if (!rfx_process_message(surface->codecs->rfx, cmd->data, cmd->length, cmd->left, cmd->top,
450 surface->data, surface->format, surface->scanline, surface->height,
453 WLog_ERR(TAG,
"Failed to process RemoteFX message");
457 rects = region16_rects(&invalidRegion, &nrRects);
458 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
461 if (status != CHANNEL_RC_OK)
464 for (UINT32 x = 0; x < nrRects; x++)
466 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]))
470 status = gdi_interFrameUpdate(gdi, context);
473 region16_uninit(&invalidRegion);
482static UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context,
486 UINT status = CHANNEL_RC_OK;
487 gdiGfxSurface* surface =
nullptr;
490 WINPR_ASSERT(context);
493 WINPR_ASSERT(context->GetSurfaceData);
495 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
499 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
500 return ERROR_NOT_FOUND;
503 if (!is_within_surface(surface, cmd))
504 return ERROR_INVALID_DATA;
506 WINPR_ASSERT(surface->codecs);
507 rc = clear_decompress(surface->codecs->clear, cmd->data, cmd->length, cmd->width, cmd->height,
508 surface->data, surface->format, surface->scanline, cmd->left, cmd->top,
509 surface->width, surface->height, &gdi->palette);
513 WLog_ERR(TAG,
"clear_decompress failure: %" PRId32
"", rc);
514 return ERROR_INTERNAL_ERROR;
517 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
518 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
519 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
520 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
521 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
523 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
526 if (status != CHANNEL_RC_OK)
529 status = gdi_interFrameUpdate(gdi, context);
540static UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context,
543 UINT status = CHANNEL_RC_OK;
544 BYTE* DstData =
nullptr;
545 gdiGfxSurface* surface =
nullptr;
548 WINPR_ASSERT(context);
551 WINPR_ASSERT(context->GetSurfaceData);
553 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
557 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
558 return ERROR_NOT_FOUND;
561 DstData = surface->data;
563 if (!is_within_surface(surface, cmd))
564 return ERROR_INVALID_DATA;
566 if (!freerdp_bitmap_decompress_planar(surface->codecs->planar, cmd->data, cmd->length,
567 cmd->width, cmd->height, DstData, surface->format,
568 surface->scanline, cmd->left, cmd->top, cmd->width,
570 return ERROR_INTERNAL_ERROR;
572 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
573 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
574 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
575 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
576 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
578 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
581 if (status != CHANNEL_RC_OK)
584 status = gdi_interFrameUpdate(gdi, context);
595static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, RdpgfxClientContext* context,
600 UINT status = CHANNEL_RC_OK;
601 gdiGfxSurface* surface =
nullptr;
605 WINPR_ASSERT(context);
608 WINPR_ASSERT(context->GetSurfaceData);
610 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
614 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
615 return ERROR_NOT_FOUND;
620 surface->h264 = h264_context_new(FALSE);
624 WLog_ERR(TAG,
"unable to create h264 context");
625 return ERROR_NOT_ENOUGH_MEMORY;
628 if (!h264_context_reset(surface->h264, surface->width, surface->height))
629 return ERROR_INTERNAL_ERROR;
633 return ERROR_NOT_SUPPORTED;
635 if (!is_within_surface(surface, cmd))
636 return ERROR_INVALID_DATA;
641 return ERROR_INTERNAL_ERROR;
644 rc = avc420_decompress(surface->h264, bs->data, bs->length, surface->data, surface->format,
645 surface->scanline, surface->width, surface->height, meta->regionRects,
646 meta->numRegionRects);
650 WLog_WARN(TAG,
"avc420_decompress failure: %" PRId32
", ignoring update.", rc);
651 return CHANNEL_RC_OK;
654 for (UINT32 i = 0; i < meta->numRegionRects; i++)
656 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
657 &(meta->regionRects[i])))
661 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
662 meta->numRegionRects, meta->regionRects);
664 if (status != CHANNEL_RC_OK)
667 status = gdi_interFrameUpdate(gdi, context);
672 return ERROR_NOT_SUPPORTED;
681static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context,
686 UINT status = CHANNEL_RC_OK;
687 gdiGfxSurface* surface =
nullptr;
694 WINPR_ASSERT(context);
697 WINPR_ASSERT(context->GetSurfaceData);
699 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
703 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
704 return ERROR_NOT_FOUND;
709 surface->h264 = h264_context_new(FALSE);
713 WLog_ERR(TAG,
"unable to create h264 context");
714 return ERROR_NOT_ENOUGH_MEMORY;
717 if (!h264_context_reset(surface->h264, surface->width, surface->height))
718 return ERROR_INTERNAL_ERROR;
722 return ERROR_NOT_SUPPORTED;
724 if (!is_within_surface(surface, cmd))
725 return ERROR_INVALID_DATA;
730 return ERROR_INTERNAL_ERROR;
732 avc1 = &bs->bitstream[0];
733 avc2 = &bs->bitstream[1];
736 rc = avc444_decompress(surface->h264, bs->LC, meta1->regionRects, meta1->numRegionRects,
737 avc1->data, avc1->length, meta2->regionRects, meta2->numRegionRects,
738 avc2->data, avc2->length, surface->data, surface->format,
739 surface->scanline, surface->width, surface->height, cmd->codecId);
743 WLog_WARN(TAG,
"avc444_decompress failure: %" PRIu32
", ignoring update.", status);
744 return CHANNEL_RC_OK;
747 for (UINT32 i = 0; i < meta1->numRegionRects; i++)
749 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
750 &(meta1->regionRects[i])))
754 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
755 meta1->numRegionRects, meta1->regionRects);
757 if (status != CHANNEL_RC_OK)
760 for (UINT32 i = 0; i < meta2->numRegionRects; i++)
762 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
763 &(meta2->regionRects[i])))
767 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
768 meta2->numRegionRects, meta2->regionRects);
770 if (status != CHANNEL_RC_OK)
773 status = gdi_interFrameUpdate(gdi, context);
778 return ERROR_NOT_SUPPORTED;
782static BOOL gdi_apply_alpha(BYTE* data, UINT32 format, UINT32 stride,
RECTANGLE_16* rect,
783 UINT32 startOffsetX, UINT32 count, BYTE a)
787 const UINT32 bpp = FreeRDPGetBytesPerPixel(format);
790 for (
size_t y = rect->top; y < rect->bottom; y++)
792 BYTE* line = &data[y * stride];
794 for (
size_t x = first ? rect->left + startOffsetX : rect->left; x < rect->right; x++)
800 if (written == count)
803 BYTE* src = &line[x * bpp];
804 UINT32 color = FreeRDPReadColor(src, format);
805 FreeRDPSplitColor(color, format, &r, &g, &b,
nullptr,
nullptr);
806 color = FreeRDPGetColor(format, r, g, b, a);
807 FreeRDPWriteColor(src, format, color);
821static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context,
824 UINT status = CHANNEL_RC_OK;
826 UINT16 compressed = 0;
827 gdiGfxSurface* surface =
nullptr;
832 WINPR_ASSERT(context);
835 s = Stream_StaticConstInit(&buffer, cmd->data, cmd->length);
837 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
838 return ERROR_INVALID_DATA;
840 WINPR_ASSERT(context->GetSurfaceData);
842 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
846 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
847 return ERROR_NOT_FOUND;
850 if (!is_within_surface(surface, cmd))
851 return ERROR_INVALID_DATA;
853 Stream_Read_UINT16(s, alphaSig);
854 Stream_Read_UINT16(s, compressed);
856 if (alphaSig != 0x414C)
857 return ERROR_INVALID_DATA;
861 if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, cmd->height, cmd->width))
862 return ERROR_INVALID_DATA;
864 for (
size_t y = cmd->top; y < cmd->top + cmd->height; y++)
866 BYTE* line = &surface->data[y * surface->scanline];
868 for (
size_t x = cmd->left; x < cmd->left + cmd->width; x++)
875 BYTE* src = &line[x * FreeRDPGetBytesPerPixel(surface->format)];
876 Stream_Read_UINT8(s, a);
877 color = FreeRDPReadColor(src, surface->format);
878 FreeRDPSplitColor(color, surface->format, &r, &g, &b,
nullptr,
nullptr);
879 color = FreeRDPGetColor(surface->format, r, g, b, a);
880 FreeRDPWriteColor(src, surface->format, color);
886 UINT32 startOffsetX = 0;
888 rect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
889 rect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
890 rect.right = (UINT16)MIN(UINT16_MAX, cmd->left + cmd->width);
891 rect.bottom = (UINT16)MIN(UINT16_MAX, cmd->top + cmd->height);
893 while (rect.top < rect.bottom)
898 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
899 return ERROR_INVALID_DATA;
901 Stream_Read_UINT8(s, a);
902 Stream_Read_UINT8(s, count);
906 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
907 return ERROR_INVALID_DATA;
909 Stream_Read_UINT16(s, count);
913 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
914 return ERROR_INVALID_DATA;
916 Stream_Read_UINT32(s, count);
920 if (!gdi_apply_alpha(surface->data, surface->format, surface->scanline, &rect,
921 startOffsetX, count, a))
922 return ERROR_INTERNAL_ERROR;
924 startOffsetX += count;
926 while (startOffsetX >= cmd->width)
928 startOffsetX -= cmd->width;
934 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
935 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
936 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
937 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
938 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
940 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
943 if (status != CHANNEL_RC_OK)
946 status = gdi_interFrameUpdate(gdi, context);
952#if defined(WITH_GFX_FRAME_DUMP)
955 static UINT64 xxx = 0;
956 const char* path =
"/tmp/dump/";
958 char fname[1024] = WINPR_C_ARRAY_INIT;
960 snprintf(fname,
sizeof(fname),
"%s/%08" PRIx64
".raw", path, xxx++);
961 FILE* fp = fopen(fname,
"w");
964 (void)fprintf(fp,
"frameid: %" PRIu32
"\n", frameId);
965 (void)fprintf(fp,
"surfaceId: %" PRIu32
"\n", cmd->surfaceId);
966 (void)fprintf(fp,
"codecId: %" PRIu32
"\n", cmd->codecId);
967 (void)fprintf(fp,
"contextId: %" PRIu32
"\n", cmd->contextId);
968 (void)fprintf(fp,
"format: %" PRIu32
"\n", cmd->format);
969 (void)fprintf(fp,
"left: %" PRIu32
"\n", cmd->left);
970 (void)fprintf(fp,
"top: %" PRIu32
"\n", cmd->top);
971 (void)fprintf(fp,
"right: %" PRIu32
"\n", cmd->right);
972 (void)fprintf(fp,
"bottom: %" PRIu32
"\n", cmd->bottom);
973 (void)fprintf(fp,
"width: %" PRIu32
"\n", cmd->width);
974 (void)fprintf(fp,
"height: %" PRIu32
"\n", cmd->height);
975 (void)fprintf(fp,
"length: %" PRIu32
"\n", cmd->length);
977 char* bdata = crypto_base64_encode_ex(cmd->data, cmd->length, FALSE);
978 (void)fprintf(fp,
"data: %s\n", bdata);
989static UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context,
993 UINT status = ERROR_INTERNAL_ERROR;
994 gdiGfxSurface* surface =
nullptr;
1004 WINPR_ASSERT(context);
1006 const UINT16 surfaceId = (UINT16)MIN(UINT16_MAX, cmd->surfaceId);
1008 WINPR_ASSERT(context->GetSurfaceData);
1009 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceId);
1013 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
1014 return ERROR_NOT_FOUND;
1017 if (!is_within_surface(surface, cmd))
1018 return ERROR_INVALID_DATA;
1020 WINPR_ASSERT(surface->codecs);
1021 rc = progressive_create_surface_context(surface->codecs->progressive, surfaceId, surface->width,
1026 WLog_ERR(TAG,
"progressive_create_surface_context failure: %" PRId32
"", rc);
1027 return ERROR_INTERNAL_ERROR;
1030 region16_init(&invalidRegion);
1032 rc = progressive_decompress(surface->codecs->progressive, cmd->data, cmd->length, surface->data,
1033 surface->format, surface->scanline, cmd->left, cmd->top,
1034 &invalidRegion, surfaceId, gdi->frameId);
1038 WLog_ERR(TAG,
"progressive_decompress failure: %" PRId32
"", rc);
1042 rects = region16_rects(&invalidRegion, &nrRects);
1043 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1046 if (status != CHANNEL_RC_OK)
1049 status = ERROR_INTERNAL_ERROR;
1050 for (UINT32 x = 0; x < nrRects; x++)
1052 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]))
1056 status = gdi_interFrameUpdate(gdi, context);
1060 region16_uninit(&invalidRegion);
1071 UINT status = CHANNEL_RC_OK;
1072 rdpGdi* gdi =
nullptr;
1074 if (!context || !cmd)
1075 return ERROR_INVALID_PARAMETER;
1077 gdi = (rdpGdi*)context->custom;
1079 EnterCriticalSection(&context->mux);
1080 const UINT16 codecId = WINPR_ASSERTING_INT_CAST(UINT16, cmd->codecId);
1081 WLog_Print(gdi->log, WLOG_TRACE,
1082 "surfaceId=%" PRIu32
", codec=%s [%" PRIu32
"], contextId=%" PRIu32
", format=%s, "
1083 "left=%" PRIu32
", top=%" PRIu32
", right=%" PRIu32
", bottom=%" PRIu32
1084 ", width=%" PRIu32
", height=%" PRIu32
" "
1085 "length=%" PRIu32
", data=%p, extra=%p",
1086 cmd->surfaceId, rdpgfx_get_codec_id_string(codecId), cmd->codecId, cmd->contextId,
1087 FreeRDPGetColorFormatName(cmd->format), cmd->left, cmd->top, cmd->right, cmd->bottom,
1088 cmd->width, cmd->height, cmd->length, (
void*)cmd->data, (
void*)cmd->extra);
1089#if defined(WITH_GFX_FRAME_DUMP)
1090 dump_cmd(cmd, gdi->frameId);
1095 case RDPGFX_CODECID_UNCOMPRESSED:
1096 status = gdi_SurfaceCommand_Uncompressed(gdi, context, cmd);
1099 case RDPGFX_CODECID_CAVIDEO:
1100 status = gdi_SurfaceCommand_RemoteFX(gdi, context, cmd);
1103 case RDPGFX_CODECID_CLEARCODEC:
1104 status = gdi_SurfaceCommand_ClearCodec(gdi, context, cmd);
1107 case RDPGFX_CODECID_PLANAR:
1108 status = gdi_SurfaceCommand_Planar(gdi, context, cmd);
1111 case RDPGFX_CODECID_AVC420:
1112 status = gdi_SurfaceCommand_AVC420(gdi, context, cmd);
1115 case RDPGFX_CODECID_AVC444v2:
1116 case RDPGFX_CODECID_AVC444:
1117 status = gdi_SurfaceCommand_AVC444(gdi, context, cmd);
1120 case RDPGFX_CODECID_ALPHA:
1121 status = gdi_SurfaceCommand_Alpha(gdi, context, cmd);
1124 case RDPGFX_CODECID_CAPROGRESSIVE:
1125 status = gdi_SurfaceCommand_Progressive(gdi, context, cmd);
1128 case RDPGFX_CODECID_CAPROGRESSIVE_V2:
1129 WLog_WARN(TAG,
"SurfaceCommand %s [0x%08" PRIX16
"] not implemented",
1130 rdpgfx_get_codec_id_string(codecId), codecId);
1134 WLog_WARN(TAG,
"Invalid SurfaceCommand %s [0x%08" PRIX16
"]",
1135 rdpgfx_get_codec_id_string(codecId), codecId);
1139 LeaveCriticalSection(&context->mux);
1149gdi_DeleteEncodingContext(RdpgfxClientContext* context,
1152 WINPR_ASSERT(context);
1153 WINPR_ASSERT(deleteEncodingContext);
1154 WINPR_UNUSED(context);
1155 WINPR_UNUSED(deleteEncodingContext);
1156 return CHANNEL_RC_OK;
1164static UINT gdi_CreateSurface(RdpgfxClientContext* context,
1167 UINT rc = ERROR_INTERNAL_ERROR;
1168 gdiGfxSurface* surface =
nullptr;
1169 rdpGdi* gdi =
nullptr;
1170 WINPR_ASSERT(context);
1171 WINPR_ASSERT(createSurface);
1172 gdi = (rdpGdi*)context->custom;
1174 WINPR_ASSERT(gdi->context);
1175 EnterCriticalSection(&context->mux);
1176 surface = (gdiGfxSurface*)calloc(1,
sizeof(gdiGfxSurface));
1183 WINPR_ASSERT(context->codecs);
1184 surface->codecs = context->codecs;
1186 if (!surface->codecs)
1193 surface->surfaceId = createSurface->surfaceId;
1194 surface->width = gfx_align_scanline(createSurface->width, 16);
1195 surface->height = gfx_align_scanline(createSurface->height, 16);
1196 surface->mappedWidth = createSurface->width;
1197 surface->mappedHeight = createSurface->height;
1198 surface->outputTargetWidth = createSurface->width;
1199 surface->outputTargetHeight = createSurface->height;
1201 switch (createSurface->pixelFormat)
1203 case GFX_PIXEL_FORMAT_ARGB_8888:
1204 surface->format = PIXEL_FORMAT_BGRA32;
1207 case GFX_PIXEL_FORMAT_XRGB_8888:
1208 surface->format = PIXEL_FORMAT_BGRX32;
1216 surface->scanline = gfx_align_scanline(surface->width * 4UL, 16);
1217 surface->data = (BYTE*)winpr_aligned_malloc(1ull * surface->scanline * surface->height, 16);
1225 memset(surface->data, 0xFF, (
size_t)surface->scanline * surface->height);
1226 region16_init(&surface->invalidRegion);
1228 WINPR_ASSERT(context->SetSurfaceData);
1229 rc = context->SetSurfaceData(context, surface->surfaceId, (
void*)surface);
1231 LeaveCriticalSection(&context->mux);
1240static UINT gdi_DeleteSurface(RdpgfxClientContext* context,
1243 UINT rc = CHANNEL_RC_OK;
1244 UINT res = ERROR_INTERNAL_ERROR;
1245 rdpCodecs* codecs =
nullptr;
1246 gdiGfxSurface* surface =
nullptr;
1247 EnterCriticalSection(&context->mux);
1249 WINPR_ASSERT(context->GetSurfaceData);
1250 surface = (gdiGfxSurface*)context->GetSurfaceData(context, deleteSurface->surfaceId);
1254 if (surface->windowMapped)
1255 rc = IFCALLRESULT(CHANNEL_RC_OK, context->UnmapWindowForSurface, context,
1259 h264_context_free(surface->h264);
1261 region16_uninit(&surface->invalidRegion);
1262 codecs = surface->codecs;
1263 winpr_aligned_free(surface->data);
1267 WINPR_ASSERT(context->SetSurfaceData);
1268 res = context->SetSurfaceData(context, deleteSurface->surfaceId,
nullptr);
1272 if (codecs && codecs->progressive)
1273 progressive_delete_surface_context(codecs->progressive, deleteSurface->surfaceId);
1275 LeaveCriticalSection(&context->mux);
1279static BOOL intersect_rect(
const RECTANGLE_16* rect,
const gdiGfxSurface* surface,
1283 WINPR_ASSERT(surface);
1284 WINPR_ASSERT(prect);
1286 if (rect->left > rect->right)
1288 if (rect->left > surface->width)
1290 if (rect->top > rect->bottom)
1292 if (rect->top > surface->height)
1294 prect->left = rect->left;
1295 prect->top = rect->top;
1297 prect->right = MIN(rect->right, WINPR_ASSERTING_INT_CAST(UINT16, surface->width));
1298 prect->bottom = MIN(rect->bottom, WINPR_ASSERTING_INT_CAST(UINT16, surface->height));
1309 UINT status = ERROR_INTERNAL_ERROR;
1312 rdpGdi* gdi = (rdpGdi*)context->custom;
1314 EnterCriticalSection(&context->mux);
1316 WINPR_ASSERT(context->GetSurfaceData);
1317 gdiGfxSurface* surface = (gdiGfxSurface*)context->GetSurfaceData(context, solidFill->surfaceId);
1323 const BYTE b = solidFill->fillPixel.B;
1324 const BYTE g = solidFill->fillPixel.G;
1325 const BYTE r = solidFill->fillPixel.R;
1332 const UINT32 color = FreeRDPGetColor(surface->format, r, g, b, a);
1333 for (UINT16 index = 0; index < solidFill->fillRectCount; index++)
1335 const RECTANGLE_16* rect = &(solidFill->fillRects[index]);
1337 if (!intersect_rect(rect, surface, &invalidRect))
1340 const UINT32 nWidth = invalidRect.right - invalidRect.left;
1341 const UINT32 nHeight = invalidRect.bottom - invalidRect.top;
1343 if (!freerdp_image_fill(surface->data, surface->format, surface->scanline,
1344 invalidRect.left, invalidRect.top, nWidth, nHeight, color))
1347 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
1353 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1354 solidFill->fillRectCount, solidFill->fillRects);
1356 if (status != CHANNEL_RC_OK)
1359 LeaveCriticalSection(&context->mux);
1361 return gdi_interFrameUpdate(gdi, context);
1363 LeaveCriticalSection(&context->mux);
1372static UINT gdi_SurfaceToSurface(RdpgfxClientContext* context,
1375 UINT status = ERROR_INTERNAL_ERROR;
1376 BOOL sameSurface = 0;
1379 gdiGfxSurface* surfaceSrc =
nullptr;
1380 gdiGfxSurface* surfaceDst =
nullptr;
1381 rdpGdi* gdi = (rdpGdi*)context->custom;
1382 EnterCriticalSection(&context->mux);
1383 rectSrc = &(surfaceToSurface->rectSrc);
1385 WINPR_ASSERT(context->GetSurfaceData);
1386 surfaceSrc = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdSrc);
1387 sameSurface = (surfaceToSurface->surfaceIdSrc == surfaceToSurface->surfaceIdDest);
1391 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdDest);
1393 surfaceDst = surfaceSrc;
1395 if (!surfaceSrc || !surfaceDst)
1398 if (!is_rect_valid(rectSrc, surfaceSrc->width, surfaceSrc->height))
1402 const UINT32 nWidth = rectSrc->right - rectSrc->left;
1403 const UINT32 nHeight = rectSrc->bottom - rectSrc->top;
1405 for (UINT16 index = 0; index < surfaceToSurface->destPtsCount; index++)
1407 const RDPGFX_POINT16* destPt = &surfaceToSurface->destPts[index];
1409 (UINT16)MIN(UINT16_MAX, destPt->x + nWidth),
1410 (UINT16)MIN(UINT16_MAX, destPt->y + nHeight) };
1411 if (!is_rect_valid(&rect, surfaceDst->width, surfaceDst->height))
1414 const UINT32 rwidth = rect.right - rect.left;
1415 const UINT32 rheight = rect.bottom - rect.top;
1416 if (!freerdp_image_copy(surfaceDst->data, surfaceDst->format, surfaceDst->scanline,
1417 destPt->x, destPt->y, rwidth, rheight, surfaceSrc->data,
1418 surfaceSrc->format, surfaceSrc->scanline, rectSrc->left,
1419 rectSrc->top,
nullptr, FREERDP_FLIP_NONE))
1423 if (!region16_union_rect(&surfaceDst->invalidRegion, &surfaceDst->invalidRegion,
1426 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1427 surfaceDst->surfaceId, 1, &invalidRect);
1429 if (status != CHANNEL_RC_OK)
1434 LeaveCriticalSection(&context->mux);
1436 return gdi_interFrameUpdate(gdi, context);
1438 LeaveCriticalSection(&context->mux);
1442static void gdi_GfxCacheEntryFree(gdiGfxCacheEntry* entry)
1450static gdiGfxCacheEntry* gdi_GfxCacheEntryNew(UINT64 cacheKey, UINT32 width, UINT32 height,
1453 gdiGfxCacheEntry* cacheEntry = (gdiGfxCacheEntry*)calloc(1,
sizeof(gdiGfxCacheEntry));
1457 cacheEntry->cacheKey = cacheKey;
1458 cacheEntry->width = width;
1459 cacheEntry->height = height;
1460 cacheEntry->format = format;
1461 cacheEntry->scanline = gfx_align_scanline(cacheEntry->width * 4, 16);
1463 if ((cacheEntry->width > 0) && (cacheEntry->height > 0))
1465 cacheEntry->data = (BYTE*)calloc(cacheEntry->height, cacheEntry->scanline);
1467 if (!cacheEntry->data)
1472 gdi_GfxCacheEntryFree(cacheEntry);
1481static UINT gdi_SurfaceToCache(RdpgfxClientContext* context,
1484 gdiGfxCacheEntry* cacheEntry =
nullptr;
1485 UINT rc = ERROR_INTERNAL_ERROR;
1486 EnterCriticalSection(&context->mux);
1489 WINPR_ASSERT(context->GetSurfaceData);
1490 gdiGfxSurface* surface =
1491 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToCache->surfaceId);
1496 if (!is_rect_valid(rect, surface->width, surface->height))
1499 cacheEntry = gdi_GfxCacheEntryNew(surfaceToCache->cacheKey, (UINT32)(rect->right - rect->left),
1500 (UINT32)(rect->bottom - rect->top), surface->format);
1505 if (!cacheEntry->data)
1508 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1509 0, 0, cacheEntry->width, cacheEntry->height, surface->data,
1510 surface->format, surface->scanline, rect->left, rect->top,
1511 nullptr, FREERDP_FLIP_NONE))
1516 WINPR_ASSERT(context->EvictCacheEntry);
1517 rc = context->EvictCacheEntry(context, &evict);
1518 if (rc != CHANNEL_RC_OK)
1522 WINPR_ASSERT(context->SetCacheSlotData);
1523 rc = context->SetCacheSlotData(context, surfaceToCache->cacheSlot, (
void*)cacheEntry);
1525 if (rc != CHANNEL_RC_OK)
1526 gdi_GfxCacheEntryFree(cacheEntry);
1527 LeaveCriticalSection(&context->mux);
1536static UINT gdi_CacheToSurface(RdpgfxClientContext* context,
1539 UINT status = ERROR_INTERNAL_ERROR;
1540 gdiGfxSurface* surface =
nullptr;
1541 gdiGfxCacheEntry* cacheEntry =
nullptr;
1543 rdpGdi* gdi = (rdpGdi*)context->custom;
1545 EnterCriticalSection(&context->mux);
1547 WINPR_ASSERT(context->GetSurfaceData);
1548 surface = (gdiGfxSurface*)context->GetSurfaceData(context, cacheToSurface->surfaceId);
1550 WINPR_ASSERT(context->GetCacheSlotData);
1551 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheToSurface->cacheSlot);
1553 if (!surface || !cacheEntry)
1556 for (UINT16 index = 0; index < cacheToSurface->destPtsCount; index++)
1560 (UINT16)MIN(UINT16_MAX, destPt->x + cacheEntry->width),
1561 (UINT16)MIN(UINT16_MAX, destPt->y + cacheEntry->height) };
1563 if (rectangle_is_empty(&rect))
1566 if (!is_rect_valid(&rect, surface->width, surface->height))
1569 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline,
1570 destPt->x, destPt->y, cacheEntry->width,
1571 cacheEntry->height, cacheEntry->data, cacheEntry->format,
1572 cacheEntry->scanline, 0, 0,
nullptr, FREERDP_FLIP_NONE))
1576 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect))
1578 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1579 surface->surfaceId, 1, &invalidRect);
1581 if (status != CHANNEL_RC_OK)
1585 LeaveCriticalSection(&context->mux);
1587 return gdi_interFrameUpdate(gdi, context);
1590 LeaveCriticalSection(&context->mux);
1599static UINT gdi_CacheImportReply(RdpgfxClientContext* context,
1603 const UINT16* slots =
nullptr;
1604 UINT error = CHANNEL_RC_OK;
1606 slots = cacheImportReply->cacheSlots;
1607 count = cacheImportReply->importedEntriesCount;
1609 for (UINT16 index = 0; index < count; index++)
1611 UINT16 cacheSlot = slots[index];
1616 WINPR_ASSERT(context->GetCacheSlotData);
1617 gdiGfxCacheEntry* cacheEntry =
1618 (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1623 cacheEntry = gdi_GfxCacheEntryNew(cacheSlot, 0, 0, PIXEL_FORMAT_BGRX32);
1626 return ERROR_INTERNAL_ERROR;
1628 WINPR_ASSERT(context->SetCacheSlotData);
1629 error = context->SetCacheSlotData(context, cacheSlot, (
void*)cacheEntry);
1633 WLog_ERR(TAG,
"CacheImportReply: SetCacheSlotData failed with error %" PRIu32
"",
1635 gdi_GfxCacheEntryFree(cacheEntry);
1643static UINT gdi_ImportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1646 UINT error = ERROR_INTERNAL_ERROR;
1647 gdiGfxCacheEntry* cacheEntry =
nullptr;
1650 return CHANNEL_RC_OK;
1652 cacheEntry = gdi_GfxCacheEntryNew(importCacheEntry->key64, importCacheEntry->width,
1653 importCacheEntry->height, PIXEL_FORMAT_BGRX32);
1658 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1659 0, 0, cacheEntry->width, cacheEntry->height,
1660 importCacheEntry->data, PIXEL_FORMAT_BGRX32, 0, 0, 0,
1661 nullptr, FREERDP_FLIP_NONE))
1666 WINPR_ASSERT(context->EvictCacheEntry);
1667 error = context->EvictCacheEntry(context, &evict);
1669 if (error != CHANNEL_RC_OK)
1672 WINPR_ASSERT(context->SetCacheSlotData);
1673 error = context->SetCacheSlotData(context, cacheSlot, (
void*)cacheEntry);
1678 gdi_GfxCacheEntryFree(cacheEntry);
1679 WLog_ERR(TAG,
"ImportCacheEntry: SetCacheSlotData failed with error %" PRIu32
"", error);
1685static UINT gdi_ExportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1688 gdiGfxCacheEntry* cacheEntry =
nullptr;
1690 WINPR_ASSERT(context->GetCacheSlotData);
1691 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1695 exportCacheEntry->key64 = cacheEntry->cacheKey;
1696 exportCacheEntry->width = (UINT16)MIN(UINT16_MAX, cacheEntry->width);
1697 exportCacheEntry->height = (UINT16)MIN(UINT16_MAX, cacheEntry->height);
1698 exportCacheEntry->size = cacheEntry->width * cacheEntry->height * 4;
1699 exportCacheEntry->flags = 0;
1700 exportCacheEntry->data = cacheEntry->data;
1701 return CHANNEL_RC_OK;
1704 return ERROR_NOT_FOUND;
1712static UINT gdi_EvictCacheEntry(RdpgfxClientContext* context,
1715 gdiGfxCacheEntry* cacheEntry =
nullptr;
1716 UINT rc = ERROR_NOT_FOUND;
1718 WINPR_ASSERT(context);
1719 WINPR_ASSERT(evictCacheEntry);
1721 EnterCriticalSection(&context->mux);
1723 WINPR_ASSERT(context->GetCacheSlotData);
1724 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, evictCacheEntry->cacheSlot);
1726 gdi_GfxCacheEntryFree(cacheEntry);
1728 WINPR_ASSERT(context->SetCacheSlotData);
1729 rc = context->SetCacheSlotData(context, evictCacheEntry->cacheSlot,
nullptr);
1730 LeaveCriticalSection(&context->mux);
1739static UINT gdi_MapSurfaceToOutput(RdpgfxClientContext* context,
1742 UINT rc = ERROR_INTERNAL_ERROR;
1743 gdiGfxSurface* surface =
nullptr;
1744 EnterCriticalSection(&context->mux);
1746 WINPR_ASSERT(context->GetSurfaceData);
1747 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1752 if (surface->windowMapped)
1754 WLog_WARN(TAG,
"surface already windowMapped when trying to set outputMapped");
1758 surface->outputMapped = TRUE;
1759 surface->outputOriginX = surfaceToOutput->outputOriginX;
1760 surface->outputOriginY = surfaceToOutput->outputOriginY;
1761 surface->outputTargetWidth = surface->mappedWidth;
1762 surface->outputTargetHeight = surface->mappedHeight;
1763 region16_clear(&surface->invalidRegion);
1766 LeaveCriticalSection(&context->mux);
1771gdi_MapSurfaceToScaledOutput(RdpgfxClientContext* context,
1774 UINT rc = ERROR_INTERNAL_ERROR;
1775 gdiGfxSurface* surface =
nullptr;
1776 EnterCriticalSection(&context->mux);
1778 WINPR_ASSERT(context->GetSurfaceData);
1779 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1784 if (surface->windowMapped)
1786 WLog_WARN(TAG,
"surface already windowMapped when trying to set outputMapped");
1790 surface->outputMapped = TRUE;
1791 surface->outputOriginX = surfaceToOutput->outputOriginX;
1792 surface->outputOriginY = surfaceToOutput->outputOriginY;
1793 surface->outputTargetWidth = surfaceToOutput->targetWidth;
1794 surface->outputTargetHeight = surfaceToOutput->targetHeight;
1795 region16_clear(&surface->invalidRegion);
1798 LeaveCriticalSection(&context->mux);
1807static UINT gdi_MapSurfaceToWindow(RdpgfxClientContext* context,
1810 UINT rc = ERROR_INTERNAL_ERROR;
1811 gdiGfxSurface* surface =
nullptr;
1812 EnterCriticalSection(&context->mux);
1814 WINPR_ASSERT(context->GetSurfaceData);
1815 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1820 if (surface->outputMapped)
1822 WLog_WARN(TAG,
"surface already outputMapped when trying to set windowMapped");
1826 if (surface->windowMapped)
1828 if (surface->windowId != surfaceToWindow->windowId)
1830 WLog_WARN(TAG,
"surface windowId mismatch, has %" PRIu64
", expected %" PRIu64,
1831 surface->windowId, surfaceToWindow->windowId);
1835 surface->windowMapped = TRUE;
1837 surface->windowId = surfaceToWindow->windowId;
1838 surface->mappedWidth = surfaceToWindow->mappedWidth;
1839 surface->mappedHeight = surfaceToWindow->mappedHeight;
1840 surface->outputTargetWidth = surfaceToWindow->mappedWidth;
1841 surface->outputTargetHeight = surfaceToWindow->mappedHeight;
1842 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1843 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1845 LeaveCriticalSection(&context->mux);
1850gdi_MapSurfaceToScaledWindow(RdpgfxClientContext* context,
1853 UINT rc = ERROR_INTERNAL_ERROR;
1854 gdiGfxSurface* surface =
nullptr;
1855 EnterCriticalSection(&context->mux);
1857 WINPR_ASSERT(context->GetSurfaceData);
1858 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1863 if (surface->outputMapped)
1865 WLog_WARN(TAG,
"surface already outputMapped when trying to set windowMapped");
1869 if (surface->windowMapped)
1871 if (surface->windowId != surfaceToWindow->windowId)
1873 WLog_WARN(TAG,
"surface windowId mismatch, has %" PRIu64
", expected %" PRIu64,
1874 surface->windowId, surfaceToWindow->windowId);
1878 surface->windowMapped = TRUE;
1880 surface->windowId = surfaceToWindow->windowId;
1881 surface->mappedWidth = surfaceToWindow->mappedWidth;
1882 surface->mappedHeight = surfaceToWindow->mappedHeight;
1883 surface->outputTargetWidth = surfaceToWindow->targetWidth;
1884 surface->outputTargetHeight = surfaceToWindow->targetHeight;
1885 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1886 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1888 LeaveCriticalSection(&context->mux);
1892BOOL gdi_graphics_pipeline_init(rdpGdi* gdi, RdpgfxClientContext* gfx)
1894 return gdi_graphics_pipeline_init_ex(gdi, gfx,
nullptr,
nullptr,
nullptr);
1897BOOL gdi_graphics_pipeline_init_ex(rdpGdi* gdi, RdpgfxClientContext* gfx,
1898 pcRdpgfxMapWindowForSurface map,
1899 pcRdpgfxUnmapWindowForSurface unmap,
1900 pcRdpgfxUpdateSurfaceArea update)
1902 if (!gdi || !gfx || !gdi->context || !gdi->context->settings)
1905 rdpContext* context = gdi->context;
1906 rdpSettings* settings = context->settings;
1909 gfx->custom = (
void*)gdi;
1910 gfx->ResetGraphics = gdi_ResetGraphics;
1911 gfx->StartFrame = gdi_StartFrame;
1912 gfx->EndFrame = gdi_EndFrame;
1913 gfx->SurfaceCommand = gdi_SurfaceCommand;
1914 gfx->DeleteEncodingContext = gdi_DeleteEncodingContext;
1915 gfx->CreateSurface = gdi_CreateSurface;
1916 gfx->DeleteSurface = gdi_DeleteSurface;
1917 gfx->SolidFill = gdi_SolidFill;
1918 gfx->SurfaceToSurface = gdi_SurfaceToSurface;
1919 gfx->SurfaceToCache = gdi_SurfaceToCache;
1920 gfx->CacheToSurface = gdi_CacheToSurface;
1921 gfx->CacheImportReply = gdi_CacheImportReply;
1922 gfx->ImportCacheEntry = gdi_ImportCacheEntry;
1923 gfx->ExportCacheEntry = gdi_ExportCacheEntry;
1924 gfx->EvictCacheEntry = gdi_EvictCacheEntry;
1925 gfx->MapSurfaceToOutput = gdi_MapSurfaceToOutput;
1926 gfx->MapSurfaceToWindow = gdi_MapSurfaceToWindow;
1927 gfx->MapSurfaceToScaledOutput = gdi_MapSurfaceToScaledOutput;
1928 gfx->MapSurfaceToScaledWindow = gdi_MapSurfaceToScaledWindow;
1929 gfx->UpdateSurfaces = gdi_UpdateSurfaces;
1930 gfx->MapWindowForSurface = map;
1931 gfx->UnmapWindowForSurface = unmap;
1932 gfx->UpdateSurfaceArea = update;
1940 gfx->codecs = freerdp_client_codecs_new(flags);
1943 if (!freerdp_client_codecs_prepare(gfx->codecs, FREERDP_CODEC_ALL, w, h))
1946 InitializeCriticalSection(&gfx->mux);
1947 PROFILER_CREATE(gfx->SurfaceProfiler,
"GFX-PROFILER")
1955 gdi->graphicsReset = TRUE;
1958 gfx->UpdateSurfaceArea =
nullptr;
1959 gfx->UpdateSurfaces =
nullptr;
1960 gfx->SurfaceCommand =
nullptr;
1966void gdi_graphics_pipeline_uninit(rdpGdi* gdi, RdpgfxClientContext* gfx)
1974 gfx->custom =
nullptr;
1975 freerdp_client_codecs_free(gfx->codecs);
1976 gfx->codecs =
nullptr;
1977 DeleteCriticalSection(&gfx->mux);
1978 PROFILER_PRINT_HEADER
1979 PROFILER_PRINT(gfx->SurfaceProfiler)
1980 PROFILER_PRINT_FOOTER
1981 PROFILER_FREE(gfx->SurfaceProfiler)
1984const
char* rdpgfx_caps_version_str(UINT32 capsVersion)
1986 switch (capsVersion)
1988 case RDPGFX_CAPVERSION_8:
1989 return "RDPGFX_CAPVERSION_8";
1990 case RDPGFX_CAPVERSION_81:
1991 return "RDPGFX_CAPVERSION_81";
1992 case RDPGFX_CAPVERSION_10:
1993 return "RDPGFX_CAPVERSION_10";
1994 case RDPGFX_CAPVERSION_101:
1995 return "RDPGFX_CAPVERSION_101";
1996 case RDPGFX_CAPVERSION_102:
1997 return "RDPGFX_CAPVERSION_102";
1998 case RDPGFX_CAPVERSION_103:
1999 return "RDPGFX_CAPVERSION_103";
2000 case RDPGFX_CAPVERSION_104:
2001 return "RDPGFX_CAPVERSION_104";
2002 case RDPGFX_CAPVERSION_105:
2003 return "RDPGFX_CAPVERSION_105";
2004 case RDPGFX_CAPVERSION_106:
2005 return "RDPGFX_CAPVERSION_106";
2006 case RDPGFX_CAPVERSION_106_ERR:
2007 return "RDPGFX_CAPVERSION_106_ERR";
2008 case RDPGFX_CAPVERSION_107:
2009 return "RDPGFX_CAPVERSION_107";
2011 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.