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);
70static DWORD gfx_align_scanline(DWORD widthInBytes, DWORD alignment)
72 const UINT32 align = alignment;
73 const UINT32 pad = align - (widthInBytes % alignment);
74 UINT32 scanline = widthInBytes;
87static UINT gdi_ResetGraphics(RdpgfxClientContext* context,
90 UINT rc = ERROR_INTERNAL_ERROR;
92 UINT32 DesktopWidth = 0;
93 UINT32 DesktopHeight = 0;
94 UINT16* pSurfaceIds =
nullptr;
95 rdpGdi* gdi =
nullptr;
96 rdpUpdate* update =
nullptr;
97 rdpSettings* settings =
nullptr;
99 WINPR_ASSERT(context);
100 WINPR_ASSERT(resetGraphics);
102 gdi = (rdpGdi*)context->custom;
105 update = gdi->context->update;
106 WINPR_ASSERT(update);
108 settings = gdi->context->settings;
109 WINPR_ASSERT(settings);
110 EnterCriticalSection(&context->mux);
111 DesktopWidth = resetGraphics->width;
112 DesktopHeight = resetGraphics->height;
121 WINPR_ASSERT(update->DesktopResize);
122 if (!update->DesktopResize(gdi->context))
126 WINPR_ASSERT(context->GetSurfaceIds);
127 rc = context->GetSurfaceIds(context, &pSurfaceIds, &count);
128 if (rc != CHANNEL_RC_OK)
131 for (UINT32 index = 0; index < count; index++)
133 WINPR_ASSERT(context->GetSurfaceData);
134 gdiGfxSurface* surface =
135 (gdiGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
140 memset(surface->data, 0xFF, (
size_t)surface->scanline * surface->height);
141 region16_clear(&surface->invalidRegion);
148 const UINT32 width = (UINT32)MAX(0, gdi->width);
149 const UINT32 height = (UINT32)MAX(0, gdi->height);
151 if (!freerdp_client_codecs_reset(
156 if (!freerdp_client_codecs_reset(
165 LeaveCriticalSection(&context->mux);
169static UINT gdi_OutputUpdate(rdpGdi* gdi, gdiGfxSurface* surface)
171 UINT rc = ERROR_INTERNAL_ERROR;
177 rdpUpdate* update =
nullptr;
180 WINPR_ASSERT(gdi->context);
181 WINPR_ASSERT(surface);
183 update = gdi->context->update;
184 WINPR_ASSERT(update);
186 if (gdi->suppressOutput)
187 return CHANNEL_RC_OK;
189 surfaceX = surface->outputOriginX;
190 surfaceY = surface->outputOriginY;
191 surfaceRect.left = 0;
193 surfaceRect.right = (UINT16)MIN(UINT16_MAX, surface->mappedWidth);
194 surfaceRect.bottom = (UINT16)MIN(UINT16_MAX, surface->mappedHeight);
195 if (!region16_intersect_rect(&(surface->invalidRegion), &(surface->invalidRegion),
199 const double sx = surface->outputTargetWidth / (double)surface->mappedWidth;
200 const double sy = surface->outputTargetHeight / (double)surface->mappedHeight;
202 if (!(rects = region16_rects(&surface->invalidRegion, &nbRects)) || !nbRects)
203 return CHANNEL_RC_OK;
205 if (!update_begin_paint(update))
208 for (UINT32 i = 0; i < nbRects; i++)
210 const UINT32 nXSrc = rects[i].left;
211 const UINT32 nYSrc = rects[i].top;
212 const UINT32 nXDst = (UINT32)MIN(surfaceX + nXSrc * sx, gdi->width - 1);
213 const UINT32 nYDst = (UINT32)MIN(surfaceY + nYSrc * sy, gdi->height - 1);
214 const UINT32 swidth = rects[i].right - rects[i].left;
215 const UINT32 sheight = rects[i].bottom - rects[i].top;
216 const UINT32 dwidth = MIN((UINT32)(swidth * sx), (UINT32)gdi->width - nXDst);
217 const UINT32 dheight = MIN((UINT32)(sheight * sy), (UINT32)gdi->height - nYDst);
219 if (!freerdp_image_scale(gdi->primary_buffer, gdi->dstFormat, gdi->stride, nXDst, nYDst,
220 dwidth, dheight, surface->data, surface->format, surface->scanline,
221 nXSrc, nYSrc, swidth, sheight))
223 rc = CHANNEL_RC_NULL_DATA;
227 if (!gdi_InvalidateRegion(gdi->primary->hdc, (INT32)nXDst, (INT32)nYDst, (INT32)dwidth,
235 if (!update_end_paint(update))
236 rc = ERROR_INTERNAL_ERROR;
238 region16_clear(&(surface->invalidRegion));
242static UINT gdi_WindowUpdate(RdpgfxClientContext* context, gdiGfxSurface* surface)
244 WINPR_ASSERT(context);
245 WINPR_ASSERT(surface);
246 return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateWindowFromSurface, context, surface);
249static UINT gdi_UpdateSurfaces(RdpgfxClientContext* context)
252 UINT16* pSurfaceIds =
nullptr;
254 WINPR_ASSERT(context);
256 rdpGdi* gdi = (rdpGdi*)context->custom;
259 EnterCriticalSection(&context->mux);
261 WINPR_ASSERT(context->GetSurfaceIds);
262 UINT status = context->GetSurfaceIds(context, &pSurfaceIds, &count);
263 if (status != CHANNEL_RC_OK)
266 for (UINT32 index = 0; index < count; index++)
268 WINPR_ASSERT(context->GetSurfaceData);
269 gdiGfxSurface* surface =
270 (gdiGfxSurface*)context->GetSurfaceData(context, pSurfaceIds[index]);
276 if (context->UpdateSurfaceArea)
278 if (surface->handleInUpdateSurfaceArea)
282 if (surface->outputMapped)
283 status = gdi_OutputUpdate(gdi, surface);
284 else if (surface->windowMapped)
285 status = gdi_WindowUpdate(context, surface);
287 if (status != CHANNEL_RC_OK)
293 LeaveCriticalSection(&context->mux);
304 rdpGdi* gdi =
nullptr;
306 WINPR_ASSERT(context);
307 WINPR_ASSERT(startFrame);
309 gdi = (rdpGdi*)context->custom;
311 gdi->inGfxFrame = TRUE;
312 gdi->frameId = startFrame->frameId;
313 return CHANNEL_RC_OK;
316static UINT gdi_call_update_surfaces(RdpgfxClientContext* context)
318 WINPR_ASSERT(context);
319 return IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaces, context);
327static UINT gdi_EndFrame(RdpgfxClientContext* context,
330 WINPR_ASSERT(context);
331 WINPR_ASSERT(endFrame);
333 rdpGdi* gdi = (rdpGdi*)context->custom;
335 const UINT status = gdi_call_update_surfaces(context);
336 gdi->inGfxFrame = FALSE;
340static UINT gdi_interFrameUpdate(rdpGdi* gdi, RdpgfxClientContext* context)
343 UINT status = CHANNEL_RC_OK;
344 if (!gdi->inGfxFrame)
345 status = gdi_call_update_surfaces(context);
354static UINT gdi_SurfaceCommand_Uncompressed(rdpGdi* gdi, RdpgfxClientContext* context,
357 UINT status = CHANNEL_RC_OK;
358 gdiGfxSurface* surface =
nullptr;
363 WINPR_ASSERT(context);
366 WINPR_ASSERT(context->GetSurfaceData);
368 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
372 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
373 return ERROR_NOT_FOUND;
376 if (!is_within_surface(surface, cmd))
377 return ERROR_INVALID_DATA;
379 bpp = FreeRDPGetBytesPerPixel(cmd->format);
380 size = 1ull * bpp * cmd->width * cmd->height;
381 if (cmd->length < size)
383 WLog_ERR(TAG,
"Not enough data, got %" PRIu32
", expected %" PRIuz, cmd->length, size);
384 return ERROR_INVALID_DATA;
387 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline, cmd->left,
388 cmd->top, cmd->width, cmd->height, cmd->data, cmd->format, 0,
389 0, 0,
nullptr, FREERDP_FLIP_NONE))
390 return ERROR_INTERNAL_ERROR;
392 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
393 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
394 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
395 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
396 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
398 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
401 if (status != CHANNEL_RC_OK)
404 status = gdi_interFrameUpdate(gdi, context);
415static UINT gdi_SurfaceCommand_RemoteFX(rdpGdi* gdi, RdpgfxClientContext* context,
418 UINT status = ERROR_INTERNAL_ERROR;
419 gdiGfxSurface* surface =
nullptr;
424 WINPR_ASSERT(context);
427 WINPR_ASSERT(context->GetSurfaceData);
429 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
433 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
434 return ERROR_NOT_FOUND;
437 WINPR_ASSERT(surface->codecs);
438 rfx_context_set_pixel_format(surface->codecs->rfx, cmd->format);
439 region16_init(&invalidRegion);
441 if (!rfx_process_message(surface->codecs->rfx, cmd->data, cmd->length, cmd->left, cmd->top,
442 surface->data, surface->format, surface->scanline, surface->height,
445 WLog_ERR(TAG,
"Failed to process RemoteFX message");
449 rects = region16_rects(&invalidRegion, &nrRects);
450 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
453 if (status != CHANNEL_RC_OK)
456 for (UINT32 x = 0; x < nrRects; x++)
458 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]))
462 status = gdi_interFrameUpdate(gdi, context);
465 region16_uninit(&invalidRegion);
474static UINT gdi_SurfaceCommand_ClearCodec(rdpGdi* gdi, RdpgfxClientContext* context,
478 UINT status = CHANNEL_RC_OK;
479 gdiGfxSurface* surface =
nullptr;
482 WINPR_ASSERT(context);
485 WINPR_ASSERT(context->GetSurfaceData);
487 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
491 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
492 return ERROR_NOT_FOUND;
495 WINPR_ASSERT(surface->codecs);
496 rc = clear_decompress(surface->codecs->clear, cmd->data, cmd->length, cmd->width, cmd->height,
497 surface->data, surface->format, surface->scanline, cmd->left, cmd->top,
498 surface->width, surface->height, &gdi->palette);
502 WLog_ERR(TAG,
"clear_decompress failure: %" PRId32
"", rc);
503 return ERROR_INTERNAL_ERROR;
506 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
507 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
508 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
509 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
510 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
512 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
515 if (status != CHANNEL_RC_OK)
518 status = gdi_interFrameUpdate(gdi, context);
529static UINT gdi_SurfaceCommand_Planar(rdpGdi* gdi, RdpgfxClientContext* context,
532 UINT status = CHANNEL_RC_OK;
533 BYTE* DstData =
nullptr;
534 gdiGfxSurface* surface =
nullptr;
537 WINPR_ASSERT(context);
540 WINPR_ASSERT(context->GetSurfaceData);
542 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
546 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
547 return ERROR_NOT_FOUND;
550 DstData = surface->data;
552 if (!is_within_surface(surface, cmd))
553 return ERROR_INVALID_DATA;
555 if (!freerdp_bitmap_decompress_planar(surface->codecs->planar, cmd->data, cmd->length,
556 cmd->width, cmd->height, DstData, surface->format,
557 surface->scanline, cmd->left, cmd->top, cmd->width,
559 return ERROR_INTERNAL_ERROR;
561 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
562 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
563 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
564 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
565 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
567 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
570 if (status != CHANNEL_RC_OK)
573 status = gdi_interFrameUpdate(gdi, context);
584static UINT gdi_SurfaceCommand_AVC420(rdpGdi* gdi, RdpgfxClientContext* context,
589 UINT status = CHANNEL_RC_OK;
590 gdiGfxSurface* surface =
nullptr;
594 WINPR_ASSERT(context);
597 WINPR_ASSERT(context->GetSurfaceData);
599 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
603 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
604 return ERROR_NOT_FOUND;
609 surface->h264 = h264_context_new(FALSE);
613 WLog_ERR(TAG,
"unable to create h264 context");
614 return ERROR_NOT_ENOUGH_MEMORY;
617 if (!h264_context_reset(surface->h264, surface->width, surface->height))
618 return ERROR_INTERNAL_ERROR;
622 return ERROR_NOT_SUPPORTED;
627 return ERROR_INTERNAL_ERROR;
630 rc = avc420_decompress(surface->h264, bs->data, bs->length, surface->data, surface->format,
631 surface->scanline, surface->width, surface->height, meta->regionRects,
632 meta->numRegionRects);
636 WLog_WARN(TAG,
"avc420_decompress failure: %" PRId32
", ignoring update.", rc);
637 return CHANNEL_RC_OK;
640 for (UINT32 i = 0; i < meta->numRegionRects; i++)
642 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
643 &(meta->regionRects[i])))
647 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
648 meta->numRegionRects, meta->regionRects);
650 if (status != CHANNEL_RC_OK)
653 status = gdi_interFrameUpdate(gdi, context);
658 return ERROR_NOT_SUPPORTED;
667static UINT gdi_SurfaceCommand_AVC444(rdpGdi* gdi, RdpgfxClientContext* context,
672 UINT status = CHANNEL_RC_OK;
673 gdiGfxSurface* surface =
nullptr;
680 WINPR_ASSERT(context);
683 WINPR_ASSERT(context->GetSurfaceData);
685 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
689 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
690 return ERROR_NOT_FOUND;
695 surface->h264 = h264_context_new(FALSE);
699 WLog_ERR(TAG,
"unable to create h264 context");
700 return ERROR_NOT_ENOUGH_MEMORY;
703 if (!h264_context_reset(surface->h264, surface->width, surface->height))
704 return ERROR_INTERNAL_ERROR;
708 return ERROR_NOT_SUPPORTED;
713 return ERROR_INTERNAL_ERROR;
715 avc1 = &bs->bitstream[0];
716 avc2 = &bs->bitstream[1];
719 rc = avc444_decompress(surface->h264, bs->LC, meta1->regionRects, meta1->numRegionRects,
720 avc1->data, avc1->length, meta2->regionRects, meta2->numRegionRects,
721 avc2->data, avc2->length, surface->data, surface->format,
722 surface->scanline, surface->width, surface->height, cmd->codecId);
726 WLog_WARN(TAG,
"avc444_decompress failure: %" PRIu32
", ignoring update.", status);
727 return CHANNEL_RC_OK;
730 for (UINT32 i = 0; i < meta1->numRegionRects; i++)
732 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
733 &(meta1->regionRects[i])))
737 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
738 meta1->numRegionRects, meta1->regionRects);
740 if (status != CHANNEL_RC_OK)
743 for (UINT32 i = 0; i < meta2->numRegionRects; i++)
745 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
746 &(meta2->regionRects[i])))
750 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
751 meta2->numRegionRects, meta2->regionRects);
753 if (status != CHANNEL_RC_OK)
756 status = gdi_interFrameUpdate(gdi, context);
761 return ERROR_NOT_SUPPORTED;
765static BOOL gdi_apply_alpha(BYTE* data, UINT32 format, UINT32 stride,
RECTANGLE_16* rect,
766 UINT32 startOffsetX, UINT32 count, BYTE a)
770 const UINT32 bpp = FreeRDPGetBytesPerPixel(format);
773 for (
size_t y = rect->top; y < rect->bottom; y++)
775 BYTE* line = &data[y * stride];
777 for (
size_t x = first ? rect->left + startOffsetX : rect->left; x < rect->right; x++)
783 if (written == count)
786 BYTE* src = &line[x * bpp];
787 UINT32 color = FreeRDPReadColor(src, format);
788 FreeRDPSplitColor(color, format, &r, &g, &b,
nullptr,
nullptr);
789 color = FreeRDPGetColor(format, r, g, b, a);
790 FreeRDPWriteColor(src, format, color);
804static UINT gdi_SurfaceCommand_Alpha(rdpGdi* gdi, RdpgfxClientContext* context,
807 UINT status = CHANNEL_RC_OK;
809 UINT16 compressed = 0;
810 gdiGfxSurface* surface =
nullptr;
815 WINPR_ASSERT(context);
818 s = Stream_StaticConstInit(&buffer, cmd->data, cmd->length);
820 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
821 return ERROR_INVALID_DATA;
823 WINPR_ASSERT(context->GetSurfaceData);
825 (gdiGfxSurface*)context->GetSurfaceData(context, (UINT16)MIN(UINT16_MAX, cmd->surfaceId));
829 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
830 return ERROR_NOT_FOUND;
833 if (!is_within_surface(surface, cmd))
834 return ERROR_INVALID_DATA;
836 Stream_Read_UINT16(s, alphaSig);
837 Stream_Read_UINT16(s, compressed);
839 if (alphaSig != 0x414C)
840 return ERROR_INVALID_DATA;
844 if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, cmd->height, cmd->width))
845 return ERROR_INVALID_DATA;
847 for (
size_t y = cmd->top; y < cmd->top + cmd->height; y++)
849 BYTE* line = &surface->data[y * surface->scanline];
851 for (
size_t x = cmd->left; x < cmd->left + cmd->width; x++)
858 BYTE* src = &line[x * FreeRDPGetBytesPerPixel(surface->format)];
859 Stream_Read_UINT8(s, a);
860 color = FreeRDPReadColor(src, surface->format);
861 FreeRDPSplitColor(color, surface->format, &r, &g, &b,
nullptr,
nullptr);
862 color = FreeRDPGetColor(surface->format, r, g, b, a);
863 FreeRDPWriteColor(src, surface->format, color);
869 UINT32 startOffsetX = 0;
871 rect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
872 rect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
873 rect.right = (UINT16)MIN(UINT16_MAX, cmd->left + cmd->width);
874 rect.bottom = (UINT16)MIN(UINT16_MAX, cmd->top + cmd->height);
876 while (rect.top < rect.bottom)
881 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
882 return ERROR_INVALID_DATA;
884 Stream_Read_UINT8(s, a);
885 Stream_Read_UINT8(s, count);
889 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
890 return ERROR_INVALID_DATA;
892 Stream_Read_UINT16(s, count);
896 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
897 return ERROR_INVALID_DATA;
899 Stream_Read_UINT32(s, count);
903 if (!gdi_apply_alpha(surface->data, surface->format, surface->scanline, &rect,
904 startOffsetX, count, a))
905 return ERROR_INTERNAL_ERROR;
907 startOffsetX += count;
909 while (startOffsetX >= cmd->width)
911 startOffsetX -= cmd->width;
917 invalidRect.left = (UINT16)MIN(UINT16_MAX, cmd->left);
918 invalidRect.top = (UINT16)MIN(UINT16_MAX, cmd->top);
919 invalidRect.right = (UINT16)MIN(UINT16_MAX, cmd->right);
920 invalidRect.bottom = (UINT16)MIN(UINT16_MAX, cmd->bottom);
921 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion), &invalidRect))
923 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId, 1,
926 if (status != CHANNEL_RC_OK)
929 status = gdi_interFrameUpdate(gdi, context);
935#if defined(WITH_GFX_FRAME_DUMP)
938 static UINT64 xxx = 0;
939 const char* path =
"/tmp/dump/";
941 char fname[1024] = WINPR_C_ARRAY_INIT;
943 snprintf(fname,
sizeof(fname),
"%s/%08" PRIx64
".raw", path, xxx++);
944 FILE* fp = fopen(fname,
"w");
947 (void)fprintf(fp,
"frameid: %" PRIu32
"\n", frameId);
948 (void)fprintf(fp,
"surfaceId: %" PRIu32
"\n", cmd->surfaceId);
949 (void)fprintf(fp,
"codecId: %" PRIu32
"\n", cmd->codecId);
950 (void)fprintf(fp,
"contextId: %" PRIu32
"\n", cmd->contextId);
951 (void)fprintf(fp,
"format: %" PRIu32
"\n", cmd->format);
952 (void)fprintf(fp,
"left: %" PRIu32
"\n", cmd->left);
953 (void)fprintf(fp,
"top: %" PRIu32
"\n", cmd->top);
954 (void)fprintf(fp,
"right: %" PRIu32
"\n", cmd->right);
955 (void)fprintf(fp,
"bottom: %" PRIu32
"\n", cmd->bottom);
956 (void)fprintf(fp,
"width: %" PRIu32
"\n", cmd->width);
957 (void)fprintf(fp,
"height: %" PRIu32
"\n", cmd->height);
958 (void)fprintf(fp,
"length: %" PRIu32
"\n", cmd->length);
960 char* bdata = crypto_base64_encode_ex(cmd->data, cmd->length, FALSE);
961 (void)fprintf(fp,
"data: %s\n", bdata);
972static UINT gdi_SurfaceCommand_Progressive(rdpGdi* gdi, RdpgfxClientContext* context,
976 UINT status = ERROR_INTERNAL_ERROR;
977 gdiGfxSurface* surface =
nullptr;
987 WINPR_ASSERT(context);
989 const UINT16 surfaceId = (UINT16)MIN(UINT16_MAX, cmd->surfaceId);
991 WINPR_ASSERT(context->GetSurfaceData);
992 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceId);
996 WLog_ERR(TAG,
"unable to retrieve surfaceData for surfaceId=%" PRIu32
"", cmd->surfaceId);
997 return ERROR_NOT_FOUND;
1000 if (!is_within_surface(surface, cmd))
1001 return ERROR_INVALID_DATA;
1003 WINPR_ASSERT(surface->codecs);
1004 rc = progressive_create_surface_context(surface->codecs->progressive, surfaceId, surface->width,
1009 WLog_ERR(TAG,
"progressive_create_surface_context failure: %" PRId32
"", rc);
1010 return ERROR_INTERNAL_ERROR;
1013 region16_init(&invalidRegion);
1015 rc = progressive_decompress(surface->codecs->progressive, cmd->data, cmd->length, surface->data,
1016 surface->format, surface->scanline, cmd->left, cmd->top,
1017 &invalidRegion, surfaceId, gdi->frameId);
1021 WLog_ERR(TAG,
"progressive_decompress failure: %" PRId32
"", rc);
1025 rects = region16_rects(&invalidRegion, &nrRects);
1026 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1029 if (status != CHANNEL_RC_OK)
1032 status = ERROR_INTERNAL_ERROR;
1033 for (UINT32 x = 0; x < nrRects; x++)
1035 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &rects[x]))
1039 status = gdi_interFrameUpdate(gdi, context);
1043 region16_uninit(&invalidRegion);
1054 UINT status = CHANNEL_RC_OK;
1055 rdpGdi* gdi =
nullptr;
1057 if (!context || !cmd)
1058 return ERROR_INVALID_PARAMETER;
1060 gdi = (rdpGdi*)context->custom;
1062 EnterCriticalSection(&context->mux);
1063 const UINT16 codecId = WINPR_ASSERTING_INT_CAST(UINT16, cmd->codecId);
1064 WLog_Print(gdi->log, WLOG_TRACE,
1065 "surfaceId=%" PRIu32
", codec=%s [%" PRIu32
"], contextId=%" PRIu32
", format=%s, "
1066 "left=%" PRIu32
", top=%" PRIu32
", right=%" PRIu32
", bottom=%" PRIu32
1067 ", width=%" PRIu32
", height=%" PRIu32
" "
1068 "length=%" PRIu32
", data=%p, extra=%p",
1069 cmd->surfaceId, rdpgfx_get_codec_id_string(codecId), cmd->codecId, cmd->contextId,
1070 FreeRDPGetColorFormatName(cmd->format), cmd->left, cmd->top, cmd->right, cmd->bottom,
1071 cmd->width, cmd->height, cmd->length, (
void*)cmd->data, (
void*)cmd->extra);
1072#if defined(WITH_GFX_FRAME_DUMP)
1073 dump_cmd(cmd, gdi->frameId);
1078 case RDPGFX_CODECID_UNCOMPRESSED:
1079 status = gdi_SurfaceCommand_Uncompressed(gdi, context, cmd);
1082 case RDPGFX_CODECID_CAVIDEO:
1083 status = gdi_SurfaceCommand_RemoteFX(gdi, context, cmd);
1086 case RDPGFX_CODECID_CLEARCODEC:
1087 status = gdi_SurfaceCommand_ClearCodec(gdi, context, cmd);
1090 case RDPGFX_CODECID_PLANAR:
1091 status = gdi_SurfaceCommand_Planar(gdi, context, cmd);
1094 case RDPGFX_CODECID_AVC420:
1095 status = gdi_SurfaceCommand_AVC420(gdi, context, cmd);
1098 case RDPGFX_CODECID_AVC444v2:
1099 case RDPGFX_CODECID_AVC444:
1100 status = gdi_SurfaceCommand_AVC444(gdi, context, cmd);
1103 case RDPGFX_CODECID_ALPHA:
1104 status = gdi_SurfaceCommand_Alpha(gdi, context, cmd);
1107 case RDPGFX_CODECID_CAPROGRESSIVE:
1108 status = gdi_SurfaceCommand_Progressive(gdi, context, cmd);
1111 case RDPGFX_CODECID_CAPROGRESSIVE_V2:
1112 WLog_WARN(TAG,
"SurfaceCommand %s [0x%08" PRIX16
"] not implemented",
1113 rdpgfx_get_codec_id_string(codecId), codecId);
1117 WLog_WARN(TAG,
"Invalid SurfaceCommand %s [0x%08" PRIX16
"]",
1118 rdpgfx_get_codec_id_string(codecId), codecId);
1122 LeaveCriticalSection(&context->mux);
1132gdi_DeleteEncodingContext(RdpgfxClientContext* context,
1135 WINPR_ASSERT(context);
1136 WINPR_ASSERT(deleteEncodingContext);
1137 WINPR_UNUSED(context);
1138 WINPR_UNUSED(deleteEncodingContext);
1139 return CHANNEL_RC_OK;
1147static UINT gdi_CreateSurface(RdpgfxClientContext* context,
1150 UINT rc = ERROR_INTERNAL_ERROR;
1151 gdiGfxSurface* surface =
nullptr;
1152 rdpGdi* gdi =
nullptr;
1153 WINPR_ASSERT(context);
1154 WINPR_ASSERT(createSurface);
1155 gdi = (rdpGdi*)context->custom;
1157 WINPR_ASSERT(gdi->context);
1158 EnterCriticalSection(&context->mux);
1159 surface = (gdiGfxSurface*)calloc(1,
sizeof(gdiGfxSurface));
1166 WINPR_ASSERT(context->codecs);
1167 surface->codecs = context->codecs;
1169 if (!surface->codecs)
1176 surface->surfaceId = createSurface->surfaceId;
1177 surface->width = gfx_align_scanline(createSurface->width, 16);
1178 surface->height = gfx_align_scanline(createSurface->height, 16);
1179 surface->mappedWidth = createSurface->width;
1180 surface->mappedHeight = createSurface->height;
1181 surface->outputTargetWidth = createSurface->width;
1182 surface->outputTargetHeight = createSurface->height;
1184 switch (createSurface->pixelFormat)
1186 case GFX_PIXEL_FORMAT_ARGB_8888:
1187 surface->format = PIXEL_FORMAT_BGRA32;
1190 case GFX_PIXEL_FORMAT_XRGB_8888:
1191 surface->format = PIXEL_FORMAT_BGRX32;
1199 surface->scanline = gfx_align_scanline(surface->width * 4UL, 16);
1200 surface->data = (BYTE*)winpr_aligned_malloc(1ull * surface->scanline * surface->height, 16);
1208 memset(surface->data, 0xFF, (
size_t)surface->scanline * surface->height);
1209 region16_init(&surface->invalidRegion);
1211 WINPR_ASSERT(context->SetSurfaceData);
1212 rc = context->SetSurfaceData(context, surface->surfaceId, (
void*)surface);
1214 LeaveCriticalSection(&context->mux);
1223static UINT gdi_DeleteSurface(RdpgfxClientContext* context,
1226 UINT rc = CHANNEL_RC_OK;
1227 UINT res = ERROR_INTERNAL_ERROR;
1228 rdpCodecs* codecs =
nullptr;
1229 gdiGfxSurface* surface =
nullptr;
1230 EnterCriticalSection(&context->mux);
1232 WINPR_ASSERT(context->GetSurfaceData);
1233 surface = (gdiGfxSurface*)context->GetSurfaceData(context, deleteSurface->surfaceId);
1237 if (surface->windowMapped)
1238 rc = IFCALLRESULT(CHANNEL_RC_OK, context->UnmapWindowForSurface, context,
1242 h264_context_free(surface->h264);
1244 region16_uninit(&surface->invalidRegion);
1245 codecs = surface->codecs;
1246 winpr_aligned_free(surface->data);
1250 WINPR_ASSERT(context->SetSurfaceData);
1251 res = context->SetSurfaceData(context, deleteSurface->surfaceId,
nullptr);
1255 if (codecs && codecs->progressive)
1256 progressive_delete_surface_context(codecs->progressive, deleteSurface->surfaceId);
1258 LeaveCriticalSection(&context->mux);
1262static BOOL intersect_rect(
const RECTANGLE_16* rect,
const gdiGfxSurface* surface,
1266 WINPR_ASSERT(surface);
1267 WINPR_ASSERT(prect);
1269 if (rect->left > rect->right)
1271 if (rect->left > surface->width)
1273 if (rect->top > rect->bottom)
1275 if (rect->top > surface->height)
1277 prect->left = rect->left;
1278 prect->top = rect->top;
1280 prect->right = MIN(rect->right, WINPR_ASSERTING_INT_CAST(UINT16, surface->width));
1281 prect->bottom = MIN(rect->bottom, WINPR_ASSERTING_INT_CAST(UINT16, surface->height));
1292 UINT status = ERROR_INTERNAL_ERROR;
1295 rdpGdi* gdi = (rdpGdi*)context->custom;
1297 EnterCriticalSection(&context->mux);
1299 WINPR_ASSERT(context->GetSurfaceData);
1300 gdiGfxSurface* surface = (gdiGfxSurface*)context->GetSurfaceData(context, solidFill->surfaceId);
1306 const BYTE b = solidFill->fillPixel.B;
1307 const BYTE g = solidFill->fillPixel.G;
1308 const BYTE r = solidFill->fillPixel.R;
1315 const UINT32 color = FreeRDPGetColor(surface->format, r, g, b, a);
1316 for (UINT16 index = 0; index < solidFill->fillRectCount; index++)
1318 const RECTANGLE_16* rect = &(solidFill->fillRects[index]);
1320 if (!intersect_rect(rect, surface, &invalidRect))
1323 const UINT32 nWidth = invalidRect.right - invalidRect.left;
1324 const UINT32 nHeight = invalidRect.bottom - invalidRect.top;
1326 if (!freerdp_image_fill(surface->data, surface->format, surface->scanline,
1327 invalidRect.left, invalidRect.top, nWidth, nHeight, color))
1330 if (!region16_union_rect(&(surface->invalidRegion), &(surface->invalidRegion),
1336 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context, surface->surfaceId,
1337 solidFill->fillRectCount, solidFill->fillRects);
1339 if (status != CHANNEL_RC_OK)
1342 LeaveCriticalSection(&context->mux);
1344 return gdi_interFrameUpdate(gdi, context);
1346 LeaveCriticalSection(&context->mux);
1355static UINT gdi_SurfaceToSurface(RdpgfxClientContext* context,
1358 UINT status = ERROR_INTERNAL_ERROR;
1359 BOOL sameSurface = 0;
1362 gdiGfxSurface* surfaceSrc =
nullptr;
1363 gdiGfxSurface* surfaceDst =
nullptr;
1364 rdpGdi* gdi = (rdpGdi*)context->custom;
1365 EnterCriticalSection(&context->mux);
1366 rectSrc = &(surfaceToSurface->rectSrc);
1368 WINPR_ASSERT(context->GetSurfaceData);
1369 surfaceSrc = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdSrc);
1370 sameSurface = (surfaceToSurface->surfaceIdSrc == surfaceToSurface->surfaceIdDest);
1374 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToSurface->surfaceIdDest);
1376 surfaceDst = surfaceSrc;
1378 if (!surfaceSrc || !surfaceDst)
1381 if (!is_rect_valid(rectSrc, surfaceSrc->width, surfaceSrc->height))
1385 const UINT32 nWidth = rectSrc->right - rectSrc->left;
1386 const UINT32 nHeight = rectSrc->bottom - rectSrc->top;
1388 for (UINT16 index = 0; index < surfaceToSurface->destPtsCount; index++)
1390 const RDPGFX_POINT16* destPt = &surfaceToSurface->destPts[index];
1392 (UINT16)MIN(UINT16_MAX, destPt->x + nWidth),
1393 (UINT16)MIN(UINT16_MAX, destPt->y + nHeight) };
1394 if (!is_rect_valid(&rect, surfaceDst->width, surfaceDst->height))
1397 const UINT32 rwidth = rect.right - rect.left;
1398 const UINT32 rheight = rect.bottom - rect.top;
1399 if (!freerdp_image_copy(surfaceDst->data, surfaceDst->format, surfaceDst->scanline,
1400 destPt->x, destPt->y, rwidth, rheight, surfaceSrc->data,
1401 surfaceSrc->format, surfaceSrc->scanline, rectSrc->left,
1402 rectSrc->top,
nullptr, FREERDP_FLIP_NONE))
1406 if (!region16_union_rect(&surfaceDst->invalidRegion, &surfaceDst->invalidRegion,
1409 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1410 surfaceDst->surfaceId, 1, &invalidRect);
1412 if (status != CHANNEL_RC_OK)
1417 LeaveCriticalSection(&context->mux);
1419 return gdi_interFrameUpdate(gdi, context);
1421 LeaveCriticalSection(&context->mux);
1425static void gdi_GfxCacheEntryFree(gdiGfxCacheEntry* entry)
1433static gdiGfxCacheEntry* gdi_GfxCacheEntryNew(UINT64 cacheKey, UINT32 width, UINT32 height,
1436 gdiGfxCacheEntry* cacheEntry = (gdiGfxCacheEntry*)calloc(1,
sizeof(gdiGfxCacheEntry));
1440 cacheEntry->cacheKey = cacheKey;
1441 cacheEntry->width = width;
1442 cacheEntry->height = height;
1443 cacheEntry->format = format;
1444 cacheEntry->scanline = gfx_align_scanline(cacheEntry->width * 4, 16);
1446 if ((cacheEntry->width > 0) && (cacheEntry->height > 0))
1448 cacheEntry->data = (BYTE*)calloc(cacheEntry->height, cacheEntry->scanline);
1450 if (!cacheEntry->data)
1455 gdi_GfxCacheEntryFree(cacheEntry);
1464static UINT gdi_SurfaceToCache(RdpgfxClientContext* context,
1467 gdiGfxCacheEntry* cacheEntry =
nullptr;
1468 UINT rc = ERROR_INTERNAL_ERROR;
1469 EnterCriticalSection(&context->mux);
1472 WINPR_ASSERT(context->GetSurfaceData);
1473 gdiGfxSurface* surface =
1474 (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToCache->surfaceId);
1479 if (!is_rect_valid(rect, surface->width, surface->height))
1482 cacheEntry = gdi_GfxCacheEntryNew(surfaceToCache->cacheKey, (UINT32)(rect->right - rect->left),
1483 (UINT32)(rect->bottom - rect->top), surface->format);
1488 if (!cacheEntry->data)
1491 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1492 0, 0, cacheEntry->width, cacheEntry->height, surface->data,
1493 surface->format, surface->scanline, rect->left, rect->top,
1494 nullptr, FREERDP_FLIP_NONE))
1499 WINPR_ASSERT(context->EvictCacheEntry);
1500 rc = context->EvictCacheEntry(context, &evict);
1501 if (rc != CHANNEL_RC_OK)
1505 WINPR_ASSERT(context->SetCacheSlotData);
1506 rc = context->SetCacheSlotData(context, surfaceToCache->cacheSlot, (
void*)cacheEntry);
1508 if (rc != CHANNEL_RC_OK)
1509 gdi_GfxCacheEntryFree(cacheEntry);
1510 LeaveCriticalSection(&context->mux);
1519static UINT gdi_CacheToSurface(RdpgfxClientContext* context,
1522 UINT status = ERROR_INTERNAL_ERROR;
1523 gdiGfxSurface* surface =
nullptr;
1524 gdiGfxCacheEntry* cacheEntry =
nullptr;
1526 rdpGdi* gdi = (rdpGdi*)context->custom;
1528 EnterCriticalSection(&context->mux);
1530 WINPR_ASSERT(context->GetSurfaceData);
1531 surface = (gdiGfxSurface*)context->GetSurfaceData(context, cacheToSurface->surfaceId);
1533 WINPR_ASSERT(context->GetCacheSlotData);
1534 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheToSurface->cacheSlot);
1536 if (!surface || !cacheEntry)
1539 for (UINT16 index = 0; index < cacheToSurface->destPtsCount; index++)
1543 (UINT16)MIN(UINT16_MAX, destPt->x + cacheEntry->width),
1544 (UINT16)MIN(UINT16_MAX, destPt->y + cacheEntry->height) };
1546 if (rectangle_is_empty(&rect))
1549 if (!is_rect_valid(&rect, surface->width, surface->height))
1552 if (!freerdp_image_copy_no_overlap(surface->data, surface->format, surface->scanline,
1553 destPt->x, destPt->y, cacheEntry->width,
1554 cacheEntry->height, cacheEntry->data, cacheEntry->format,
1555 cacheEntry->scanline, 0, 0,
nullptr, FREERDP_FLIP_NONE))
1559 if (!region16_union_rect(&surface->invalidRegion, &surface->invalidRegion, &invalidRect))
1561 status = IFCALLRESULT(CHANNEL_RC_OK, context->UpdateSurfaceArea, context,
1562 surface->surfaceId, 1, &invalidRect);
1564 if (status != CHANNEL_RC_OK)
1568 LeaveCriticalSection(&context->mux);
1570 return gdi_interFrameUpdate(gdi, context);
1573 LeaveCriticalSection(&context->mux);
1582static UINT gdi_CacheImportReply(RdpgfxClientContext* context,
1586 const UINT16* slots =
nullptr;
1587 UINT error = CHANNEL_RC_OK;
1589 slots = cacheImportReply->cacheSlots;
1590 count = cacheImportReply->importedEntriesCount;
1592 for (UINT16 index = 0; index < count; index++)
1594 UINT16 cacheSlot = slots[index];
1599 WINPR_ASSERT(context->GetCacheSlotData);
1600 gdiGfxCacheEntry* cacheEntry =
1601 (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1606 cacheEntry = gdi_GfxCacheEntryNew(cacheSlot, 0, 0, PIXEL_FORMAT_BGRX32);
1609 return ERROR_INTERNAL_ERROR;
1611 WINPR_ASSERT(context->SetCacheSlotData);
1612 error = context->SetCacheSlotData(context, cacheSlot, (
void*)cacheEntry);
1616 WLog_ERR(TAG,
"CacheImportReply: SetCacheSlotData failed with error %" PRIu32
"",
1618 gdi_GfxCacheEntryFree(cacheEntry);
1626static UINT gdi_ImportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1629 UINT error = ERROR_INTERNAL_ERROR;
1630 gdiGfxCacheEntry* cacheEntry =
nullptr;
1633 return CHANNEL_RC_OK;
1635 cacheEntry = gdi_GfxCacheEntryNew(importCacheEntry->key64, importCacheEntry->width,
1636 importCacheEntry->height, PIXEL_FORMAT_BGRX32);
1641 if (!freerdp_image_copy_no_overlap(cacheEntry->data, cacheEntry->format, cacheEntry->scanline,
1642 0, 0, cacheEntry->width, cacheEntry->height,
1643 importCacheEntry->data, PIXEL_FORMAT_BGRX32, 0, 0, 0,
1644 nullptr, FREERDP_FLIP_NONE))
1649 WINPR_ASSERT(context->EvictCacheEntry);
1650 error = context->EvictCacheEntry(context, &evict);
1652 if (error != CHANNEL_RC_OK)
1655 WINPR_ASSERT(context->SetCacheSlotData);
1656 error = context->SetCacheSlotData(context, cacheSlot, (
void*)cacheEntry);
1661 gdi_GfxCacheEntryFree(cacheEntry);
1662 WLog_ERR(TAG,
"ImportCacheEntry: SetCacheSlotData failed with error %" PRIu32
"", error);
1668static UINT gdi_ExportCacheEntry(RdpgfxClientContext* context, UINT16 cacheSlot,
1671 gdiGfxCacheEntry* cacheEntry =
nullptr;
1673 WINPR_ASSERT(context->GetCacheSlotData);
1674 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, cacheSlot);
1678 exportCacheEntry->key64 = cacheEntry->cacheKey;
1679 exportCacheEntry->width = (UINT16)MIN(UINT16_MAX, cacheEntry->width);
1680 exportCacheEntry->height = (UINT16)MIN(UINT16_MAX, cacheEntry->height);
1681 exportCacheEntry->size = cacheEntry->width * cacheEntry->height * 4;
1682 exportCacheEntry->flags = 0;
1683 exportCacheEntry->data = cacheEntry->data;
1684 return CHANNEL_RC_OK;
1687 return ERROR_NOT_FOUND;
1695static UINT gdi_EvictCacheEntry(RdpgfxClientContext* context,
1698 gdiGfxCacheEntry* cacheEntry =
nullptr;
1699 UINT rc = ERROR_NOT_FOUND;
1701 WINPR_ASSERT(context);
1702 WINPR_ASSERT(evictCacheEntry);
1704 EnterCriticalSection(&context->mux);
1706 WINPR_ASSERT(context->GetCacheSlotData);
1707 cacheEntry = (gdiGfxCacheEntry*)context->GetCacheSlotData(context, evictCacheEntry->cacheSlot);
1709 gdi_GfxCacheEntryFree(cacheEntry);
1711 WINPR_ASSERT(context->SetCacheSlotData);
1712 rc = context->SetCacheSlotData(context, evictCacheEntry->cacheSlot,
nullptr);
1713 LeaveCriticalSection(&context->mux);
1722static UINT gdi_MapSurfaceToOutput(RdpgfxClientContext* context,
1725 UINT rc = ERROR_INTERNAL_ERROR;
1726 gdiGfxSurface* surface =
nullptr;
1727 EnterCriticalSection(&context->mux);
1729 WINPR_ASSERT(context->GetSurfaceData);
1730 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1735 if (surface->windowMapped)
1737 WLog_WARN(TAG,
"surface already windowMapped when trying to set outputMapped");
1741 surface->outputMapped = TRUE;
1742 surface->outputOriginX = surfaceToOutput->outputOriginX;
1743 surface->outputOriginY = surfaceToOutput->outputOriginY;
1744 surface->outputTargetWidth = surface->mappedWidth;
1745 surface->outputTargetHeight = surface->mappedHeight;
1746 region16_clear(&surface->invalidRegion);
1749 LeaveCriticalSection(&context->mux);
1754gdi_MapSurfaceToScaledOutput(RdpgfxClientContext* context,
1757 UINT rc = ERROR_INTERNAL_ERROR;
1758 gdiGfxSurface* surface =
nullptr;
1759 EnterCriticalSection(&context->mux);
1761 WINPR_ASSERT(context->GetSurfaceData);
1762 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToOutput->surfaceId);
1767 if (surface->windowMapped)
1769 WLog_WARN(TAG,
"surface already windowMapped when trying to set outputMapped");
1773 surface->outputMapped = TRUE;
1774 surface->outputOriginX = surfaceToOutput->outputOriginX;
1775 surface->outputOriginY = surfaceToOutput->outputOriginY;
1776 surface->outputTargetWidth = surfaceToOutput->targetWidth;
1777 surface->outputTargetHeight = surfaceToOutput->targetHeight;
1778 region16_clear(&surface->invalidRegion);
1781 LeaveCriticalSection(&context->mux);
1790static UINT gdi_MapSurfaceToWindow(RdpgfxClientContext* context,
1793 UINT rc = ERROR_INTERNAL_ERROR;
1794 gdiGfxSurface* surface =
nullptr;
1795 EnterCriticalSection(&context->mux);
1797 WINPR_ASSERT(context->GetSurfaceData);
1798 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1803 if (surface->outputMapped)
1805 WLog_WARN(TAG,
"surface already outputMapped when trying to set windowMapped");
1809 if (surface->windowMapped)
1811 if (surface->windowId != surfaceToWindow->windowId)
1813 WLog_WARN(TAG,
"surface windowId mismatch, has %" PRIu64
", expected %" PRIu64,
1814 surface->windowId, surfaceToWindow->windowId);
1818 surface->windowMapped = TRUE;
1820 surface->windowId = surfaceToWindow->windowId;
1821 surface->mappedWidth = surfaceToWindow->mappedWidth;
1822 surface->mappedHeight = surfaceToWindow->mappedHeight;
1823 surface->outputTargetWidth = surfaceToWindow->mappedWidth;
1824 surface->outputTargetHeight = surfaceToWindow->mappedHeight;
1825 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1826 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1828 LeaveCriticalSection(&context->mux);
1833gdi_MapSurfaceToScaledWindow(RdpgfxClientContext* context,
1836 UINT rc = ERROR_INTERNAL_ERROR;
1837 gdiGfxSurface* surface =
nullptr;
1838 EnterCriticalSection(&context->mux);
1840 WINPR_ASSERT(context->GetSurfaceData);
1841 surface = (gdiGfxSurface*)context->GetSurfaceData(context, surfaceToWindow->surfaceId);
1846 if (surface->outputMapped)
1848 WLog_WARN(TAG,
"surface already outputMapped when trying to set windowMapped");
1852 if (surface->windowMapped)
1854 if (surface->windowId != surfaceToWindow->windowId)
1856 WLog_WARN(TAG,
"surface windowId mismatch, has %" PRIu64
", expected %" PRIu64,
1857 surface->windowId, surfaceToWindow->windowId);
1861 surface->windowMapped = TRUE;
1863 surface->windowId = surfaceToWindow->windowId;
1864 surface->mappedWidth = surfaceToWindow->mappedWidth;
1865 surface->mappedHeight = surfaceToWindow->mappedHeight;
1866 surface->outputTargetWidth = surfaceToWindow->targetWidth;
1867 surface->outputTargetHeight = surfaceToWindow->targetHeight;
1868 rc = IFCALLRESULT(CHANNEL_RC_OK, context->MapWindowForSurface, context,
1869 surfaceToWindow->surfaceId, surfaceToWindow->windowId);
1871 LeaveCriticalSection(&context->mux);
1875BOOL gdi_graphics_pipeline_init(rdpGdi* gdi, RdpgfxClientContext* gfx)
1877 return gdi_graphics_pipeline_init_ex(gdi, gfx,
nullptr,
nullptr,
nullptr);
1880BOOL gdi_graphics_pipeline_init_ex(rdpGdi* gdi, RdpgfxClientContext* gfx,
1881 pcRdpgfxMapWindowForSurface map,
1882 pcRdpgfxUnmapWindowForSurface unmap,
1883 pcRdpgfxUpdateSurfaceArea update)
1885 if (!gdi || !gfx || !gdi->context || !gdi->context->settings)
1888 rdpContext* context = gdi->context;
1889 rdpSettings* settings = context->settings;
1892 gfx->custom = (
void*)gdi;
1893 gfx->ResetGraphics = gdi_ResetGraphics;
1894 gfx->StartFrame = gdi_StartFrame;
1895 gfx->EndFrame = gdi_EndFrame;
1896 gfx->SurfaceCommand = gdi_SurfaceCommand;
1897 gfx->DeleteEncodingContext = gdi_DeleteEncodingContext;
1898 gfx->CreateSurface = gdi_CreateSurface;
1899 gfx->DeleteSurface = gdi_DeleteSurface;
1900 gfx->SolidFill = gdi_SolidFill;
1901 gfx->SurfaceToSurface = gdi_SurfaceToSurface;
1902 gfx->SurfaceToCache = gdi_SurfaceToCache;
1903 gfx->CacheToSurface = gdi_CacheToSurface;
1904 gfx->CacheImportReply = gdi_CacheImportReply;
1905 gfx->ImportCacheEntry = gdi_ImportCacheEntry;
1906 gfx->ExportCacheEntry = gdi_ExportCacheEntry;
1907 gfx->EvictCacheEntry = gdi_EvictCacheEntry;
1908 gfx->MapSurfaceToOutput = gdi_MapSurfaceToOutput;
1909 gfx->MapSurfaceToWindow = gdi_MapSurfaceToWindow;
1910 gfx->MapSurfaceToScaledOutput = gdi_MapSurfaceToScaledOutput;
1911 gfx->MapSurfaceToScaledWindow = gdi_MapSurfaceToScaledWindow;
1912 gfx->UpdateSurfaces = gdi_UpdateSurfaces;
1913 gfx->MapWindowForSurface = map;
1914 gfx->UnmapWindowForSurface = unmap;
1915 gfx->UpdateSurfaceArea = update;
1923 gfx->codecs = freerdp_client_codecs_new(flags);
1926 if (!freerdp_client_codecs_prepare(gfx->codecs, FREERDP_CODEC_ALL, w, h))
1929 InitializeCriticalSection(&gfx->mux);
1930 PROFILER_CREATE(gfx->SurfaceProfiler,
"GFX-PROFILER")
1938 gdi->graphicsReset = TRUE;
1941 gfx->UpdateSurfaceArea =
nullptr;
1942 gfx->UpdateSurfaces =
nullptr;
1943 gfx->SurfaceCommand =
nullptr;
1949void gdi_graphics_pipeline_uninit(rdpGdi* gdi, RdpgfxClientContext* gfx)
1957 gfx->custom =
nullptr;
1958 freerdp_client_codecs_free(gfx->codecs);
1959 gfx->codecs =
nullptr;
1960 DeleteCriticalSection(&gfx->mux);
1961 PROFILER_PRINT_HEADER
1962 PROFILER_PRINT(gfx->SurfaceProfiler)
1963 PROFILER_PRINT_FOOTER
1964 PROFILER_FREE(gfx->SurfaceProfiler)
1967const
char* rdpgfx_caps_version_str(UINT32 capsVersion)
1969 switch (capsVersion)
1971 case RDPGFX_CAPVERSION_8:
1972 return "RDPGFX_CAPVERSION_8";
1973 case RDPGFX_CAPVERSION_81:
1974 return "RDPGFX_CAPVERSION_81";
1975 case RDPGFX_CAPVERSION_10:
1976 return "RDPGFX_CAPVERSION_10";
1977 case RDPGFX_CAPVERSION_101:
1978 return "RDPGFX_CAPVERSION_101";
1979 case RDPGFX_CAPVERSION_102:
1980 return "RDPGFX_CAPVERSION_102";
1981 case RDPGFX_CAPVERSION_103:
1982 return "RDPGFX_CAPVERSION_103";
1983 case RDPGFX_CAPVERSION_104:
1984 return "RDPGFX_CAPVERSION_104";
1985 case RDPGFX_CAPVERSION_105:
1986 return "RDPGFX_CAPVERSION_105";
1987 case RDPGFX_CAPVERSION_106:
1988 return "RDPGFX_CAPVERSION_106";
1989 case RDPGFX_CAPVERSION_106_ERR:
1990 return "RDPGFX_CAPVERSION_106_ERR";
1991 case RDPGFX_CAPVERSION_107:
1992 return "RDPGFX_CAPVERSION_107";
1994 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.