24#include <freerdp/config.h>
26#include <winpr/assert.h>
27#include <winpr/cast.h>
30#include <winpr/wlog.h>
31#include <winpr/print.h>
32#include <winpr/synch.h>
33#include <winpr/thread.h>
34#include <winpr/stream.h>
35#include <winpr/sysinfo.h>
36#include <winpr/cmdline.h>
37#include <winpr/collections.h>
39#include <freerdp/addin.h>
40#include <freerdp/channels/log.h>
42#include "rdpgfx_common.h"
43#include "rdpgfx_codec.h"
45#include "rdpgfx_main.h"
47#define GFXTAG CHANNELS_TAG("rdpgfx.client")
49#define RDPGFX_NUMBER_CAPSETS 0x100
53 uint64_t cntGfxCodecID[RDPGFX_CODECID_MAX];
54 uint64_t cntGfxCommandID[RDPGFX_CMDID_MAX + 1];
55} RdpgfxClientContextStats;
59 RdpgfxClientContext common;
60 RdpgfxClientContextStats stats;
61} RdpgfxClientContextInt;
63static const UINT32 MAX_SURFACE_SIZE = 32766;
64static const UINT32 MAX_MONITOR_COUNT = 16;
66size_t rdpgfx_stats_max_index(
void)
68 return sizeof(RdpgfxClientContextStats) /
sizeof(uint64_t);
71const char* rdpgfx_stats_name_for_index(
size_t index)
73 if (index < RDPGFX_CODECID_MAX)
74 return rdpgfx_get_codec_id_string(WINPR_ASSERTING_INT_CAST(UINT16, index));
76 index -= RDPGFX_CODECID_MAX;
77 if (index < RDPGFX_CMDID_MAX)
78 return rdpgfx_get_cmd_id_string(WINPR_ASSERTING_INT_CAST(UINT16, index));
79 return "RDPGFX_STATS_UNUSED";
82uint64_t rdpgfx_stats_value_for_index(RdpgfxClientContext* context,
size_t index)
84 WINPR_ASSERT(context);
86 RdpgfxClientContextInt* intCtx = (RdpgfxClientContextInt*)context;
88 if (index < RDPGFX_CODECID_MAX)
89 return intCtx->stats.cntGfxCodecID[WINPR_ASSERTING_INT_CAST(UINT16, index)];
91 index -= RDPGFX_CODECID_MAX;
92 if (index < RDPGFX_CMDID_MAX)
93 return intCtx->stats.cntGfxCommandID[WINPR_ASSERTING_INT_CAST(UINT16, index)];
97static void rdpgfx_codecid_event(RdpgfxClientContext* context, uint32_t index)
101 RdpgfxClientContextInt* intCtx = (RdpgfxClientContextInt*)context;
102 WINPR_ASSERT(intCtx);
103 if (index < RDPGFX_CODECID_MAX)
104 intCtx->stats.cntGfxCodecID[index]++;
109 WLog_Print(gfx->base.log, WLOG_WARN,
"Invalid event index %" PRIu32, index);
113static void rdpgfx_stats_cmdid_event(RdpgfxClientContext* context, uint32_t index)
117 RdpgfxClientContextInt* intCtx = (RdpgfxClientContextInt*)context;
118 WINPR_ASSERT(intCtx);
120 if (index >= RDPGFX_CMDID_MAX)
124 WLog_Print(gfx->base.log, WLOG_WARN,
"Invalid codecID %" PRIu32, index);
125 index = RDPGFX_CMDID_MAX;
127 intCtx->stats.cntGfxCommandID[index]++;
130static BOOL delete_surface(
const void* key,
void* value,
void* arg)
132 const ULONG_PTR
id = (ULONG_PTR)(key);
133 if ((
id < 1) || (
id - 1 > UINT16_MAX))
135 const UINT16 uid = WINPR_ASSERTING_INT_CAST(UINT16,
id - 1);
137 RdpgfxClientContext* context = arg;
144 UINT error = CHANNEL_RC_OK;
145 IFCALLRET(context->DeleteSurface, error, context, &pdu);
151 WLog_Print(gfx->base.log, WLOG_ERROR,
152 "context->DeleteSurface failed with error %" PRIu32
"", error);
158static void free_surfaces(RdpgfxClientContext* context, wHashTable* SurfaceTable)
160 WINPR_ASSERT(context);
161 if (!HashTable_Foreach(SurfaceTable, delete_surface, context))
165 WLog_Print(gfx->base.log, WLOG_WARN,
"delete_surface failed");
169static UINT evict_cache_slots(RdpgfxClientContext* context, UINT16 MaxCacheSlots,
void** CacheSlots)
171 UINT error = CHANNEL_RC_OK;
173 WINPR_ASSERT(CacheSlots);
174 for (UINT16 index = 0; index < MaxCacheSlots; index++)
176 if (CacheSlots[index])
180 if (context && context->EvictCacheEntry)
182 const UINT rc = context->EvictCacheEntry(context, &pdu);
183 if (rc != CHANNEL_RC_OK)
187 CacheSlots[index] =
nullptr;
198static UINT rdpgfx_send_caps_advertise_pdu(RdpgfxClientContext* context,
201 UINT error = CHANNEL_RC_OK;
204 WINPR_ASSERT(context);
208 if (!gfx || !gfx->base.listener_callback)
209 return ERROR_BAD_ARGUMENTS;
214 .cmdId = RDPGFX_CMDID_CAPSADVERTISE,
215 .pduLength = RDPGFX_HEADER_SIZE + 2 };
217 for (UINT16 index = 0; index < pdu->capsSetCount; index++)
220 header.pduLength += RDPGFX_CAPSET_BASE_SIZE + capsSet->length;
223 WLog_Print(gfx->base.log, WLOG_DEBUG,
"SendCapsAdvertisePdu %" PRIu16
"", pdu->capsSetCount);
224 wStream* s = Stream_New(
nullptr, header.pduLength);
228 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
229 return CHANNEL_RC_NO_MEMORY;
232 if ((error = rdpgfx_write_header(s, &header)))
236 Stream_Write_UINT16(s, pdu->capsSetCount);
238 for (UINT16 index = 0; index < pdu->capsSetCount; index++)
242 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Sending %s [0x%08" PRIx32
"] flags=0x%08" PRIx32,
243 rdpgfx_caps_version_str(capsSet->version), capsSet->version, capsSet->flags);
245 Stream_Write_UINT32(s, capsSet->version);
246 Stream_Write_UINT32(s, capsSet->length);
247 Stream_Write_UINT32(s, capsSet->flags);
248 if (capsSet->length < 4)
250 Stream_Zero(s, capsSet->length - 4);
253 Stream_SealLength(s);
254 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
257 Stream_Free(s, TRUE);
261static BOOL rdpgfx_is_capability_filtered(
RDPGFX_PLUGIN* gfx, UINT32 caps)
264 const UINT32 filter =
266 const UINT32 capList[] = {
267#if defined(WITH_GFX_AV1)
268 RDPGFX_CAPVERSION_FRDP_1,
271 RDPGFX_CAPVERSION_81,
272 RDPGFX_CAPVERSION_10,
273 RDPGFX_CAPVERSION_101,
274 RDPGFX_CAPVERSION_102,
275 RDPGFX_CAPVERSION_103,
276 RDPGFX_CAPVERSION_104,
277 RDPGFX_CAPVERSION_105,
278 RDPGFX_CAPVERSION_106,
279 RDPGFX_CAPVERSION_106_ERR,
280 RDPGFX_CAPVERSION_107
281#if defined(WITH_GFX_AZURE)
283 RDPGFX_CAPVERSION_111,
284 RDPGFX_CAPVERSION_112,
285 RDPGFX_CAPVERSION_113
289 for (
size_t x = 0; x < ARRAYSIZE(capList); x++)
291 if (caps == capList[x])
292 return (filter & (1u << x)) != 0;
302 WINPR_ASSERT(pdu->capsSets);
303 WINPR_ASSERT(count > 0);
304 WINPR_ASSERT(pdu->capsSetCount < count);
305 if (pdu->capsSetCount >= count)
307 return &pdu->capsSets[pdu->capsSetCount++];
317 RDPGFX_CAPSET capsSets[RDPGFX_NUMBER_CAPSETS] = WINPR_C_ARRAY_INIT;
320 return ERROR_BAD_ARGUMENTS;
325 return ERROR_BAD_CONFIGURATION;
327 RdpgfxClientContext* context = gfx->context;
330 return ERROR_BAD_CONFIGURATION;
334 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_8))
336 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
338 return ERROR_BAD_CONFIGURATION;
339 capsSet->version = RDPGFX_CAPVERSION_8;
344 capsSet->flags |= RDPGFX_CAPS_FLAG_THINCLIENT;
351 capsSet->flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE;
354 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_81))
356 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
358 return ERROR_BAD_CONFIGURATION;
359 capsSet->version = RDPGFX_CAPVERSION_81;
364 capsSet->flags |= RDPGFX_CAPS_FLAG_THINCLIENT;
367 capsSet->flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE;
372 capsSet->flags |= RDPGFX_CAPS_FLAG_AVC420_ENABLED;
377 UINT32 caps10Flags = 0;
382 caps10Flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE;
387 caps10Flags |= RDPGFX_CAPS_FLAG_AVC_DISABLED;
390 caps10Flags |= RDPGFX_CAPS_FLAG_AVC_DISABLED;
393 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_10))
395 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
397 return ERROR_BAD_CONFIGURATION;
398 capsSet->version = RDPGFX_CAPVERSION_10;
400 capsSet->flags = caps10Flags;
403 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_101))
405 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
407 return ERROR_BAD_CONFIGURATION;
408 capsSet->version = RDPGFX_CAPVERSION_101;
409 capsSet->length = 0x10;
413 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_102))
415 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
417 return ERROR_BAD_CONFIGURATION;
418 capsSet->version = RDPGFX_CAPVERSION_102;
419 capsSet->length = 0x4;
420 capsSet->flags = caps10Flags;
425 if ((caps10Flags & RDPGFX_CAPS_FLAG_AVC_DISABLED) == 0)
426 caps10Flags |= RDPGFX_CAPS_FLAG_AVC_THINCLIENT;
429 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_103))
431 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
433 return ERROR_BAD_CONFIGURATION;
434 capsSet->version = RDPGFX_CAPVERSION_103;
435 capsSet->length = 0x4;
436 capsSet->flags = caps10Flags & ~RDPGFX_CAPS_FLAG_SMALL_CACHE;
439 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_104))
441 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
443 return ERROR_BAD_CONFIGURATION;
444 capsSet->version = RDPGFX_CAPVERSION_104;
445 capsSet->length = 0x4;
446 capsSet->flags = caps10Flags;
452#if defined(WITH_CAIRO) || defined(WITH_SWSCALE)
453 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_105))
455 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
457 return ERROR_BAD_CONFIGURATION;
458 capsSet->version = RDPGFX_CAPVERSION_105;
459 capsSet->length = 0x4;
460 capsSet->flags = caps10Flags;
463 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_106))
465 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
467 return ERROR_BAD_CONFIGURATION;
468 capsSet->version = RDPGFX_CAPVERSION_106;
469 capsSet->length = 0x4;
470 capsSet->flags = caps10Flags;
473 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_106_ERR))
475 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
477 return ERROR_BAD_CONFIGURATION;
478 capsSet->version = RDPGFX_CAPVERSION_106_ERR;
479 capsSet->length = 0x4;
480 capsSet->flags = caps10Flags;
484 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_107))
486 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
488 return ERROR_BAD_CONFIGURATION;
489 capsSet->version = RDPGFX_CAPVERSION_107;
490 capsSet->length = 0x4;
491 capsSet->flags = caps10Flags;
492#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
493 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
497#if defined(WITH_GFX_AZURE)
498 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_111))
500 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
502 return ERROR_BAD_CONFIGURATION;
503 capsSet->version = RDPGFX_CAPVERSION_111;
504 capsSet->length = 0x4;
505 capsSet->flags = caps10Flags;
506#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
507 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
511 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_112))
513 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
515 return ERROR_BAD_CONFIGURATION;
516 capsSet->version = RDPGFX_CAPVERSION_112;
517 capsSet->length = 0x4;
518 capsSet->flags = caps10Flags;
519#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
520 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
524 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_113))
526 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
528 return ERROR_BAD_CONFIGURATION;
529 capsSet->version = RDPGFX_CAPVERSION_113;
530 capsSet->length = 0x4;
531 capsSet->flags = caps10Flags;
532#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
533 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
539#if defined(WITH_GFX_AV1)
542 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_FRDP_1))
544 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
546 return ERROR_BAD_CONFIGURATION;
547 capsSet->version = RDPGFX_CAPVERSION_FRDP_1;
548 capsSet->length = 0x4;
550 capsSet->flags = caps10Flags | RDPGFX_CAPS_FLAG_AV1_I444_SUPPORTED;
551 const UINT32 profile =
554 capsSet->flags |= RDPGFX_CAPS_FLAG_AV1_I444_DISABLED;
556#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
557 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
563 return IFCALLRESULT(ERROR_BAD_CONFIGURATION, context->CapsAdvertise, context, &pdu);
573 WINPR_ASSERT(callback);
577 RdpgfxClientContext* context = gfx->context;
582 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 12))
583 return ERROR_INVALID_DATA;
585 Stream_Read_UINT32(s, capsSet.version);
586 Stream_Read_UINT32(s, capsSet.length);
587 Stream_Read_UINT32(s, capsSet.flags);
588 gfx->TotalDecodedFrames = 0;
589 gfx->ConnectionCaps = capsSet;
590 WLog_Print(gfx->base.log, WLOG_DEBUG,
591 "RecvCapsConfirmPdu: version: %s [0x%08" PRIX32
"] flags: 0x%08" PRIX32
"",
592 rdpgfx_caps_version_str(capsSet.version), capsSet.version, capsSet.flags);
595 return ERROR_BAD_CONFIGURATION;
597 return IFCALLRESULT(CHANNEL_RC_OK, context->CapsConfirm, context, &pdu);
605static UINT rdpgfx_send_frame_acknowledge_pdu(RdpgfxClientContext* context,
610 if (!context || !pdu)
611 return ERROR_BAD_ARGUMENTS;
615 if (!gfx || !gfx->base.listener_callback)
616 return ERROR_BAD_CONFIGURATION;
621 return ERROR_BAD_CONFIGURATION;
624 .cmdId = RDPGFX_CMDID_FRAMEACKNOWLEDGE,
625 .pduLength = RDPGFX_HEADER_SIZE + 12 };
627 WLog_Print(gfx->base.log, WLOG_TRACE,
"SendFrameAcknowledgePdu: %" PRIu32
"", pdu->frameId);
629 wStream* s = Stream_New(
nullptr, header.pduLength);
633 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
634 return CHANNEL_RC_NO_MEMORY;
637 if ((error = rdpgfx_write_header(s, &header)))
641 Stream_Write_UINT32(s, pdu->queueDepth);
642 Stream_Write_UINT32(s, pdu->frameId);
643 Stream_Write_UINT32(s, pdu->totalFramesDecoded);
644 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
647 if (error == CHANNEL_RC_OK)
648 gfx->UnacknowledgedFrames--;
651 Stream_Free(s, TRUE);
655static UINT rdpgfx_send_qoe_frame_acknowledge_pdu(RdpgfxClientContext* context,
658 UINT error = CHANNEL_RC_OK;
660 .cmdId = RDPGFX_CMDID_QOEFRAMEACKNOWLEDGE,
661 .pduLength = RDPGFX_HEADER_SIZE + 12 };
663 if (!context || !pdu)
664 return ERROR_BAD_ARGUMENTS;
668 if (!gfx || !gfx->base.listener_callback)
669 return ERROR_BAD_CONFIGURATION;
674 return ERROR_BAD_CONFIGURATION;
676 WLog_Print(gfx->base.log, WLOG_TRACE,
"SendQoeFrameAcknowledgePdu: %" PRIu32
"", pdu->frameId);
677 wStream* s = Stream_New(
nullptr, header.pduLength);
681 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
682 return CHANNEL_RC_NO_MEMORY;
685 if ((error = rdpgfx_write_header(s, &header)))
689 Stream_Write_UINT32(s, pdu->frameId);
690 Stream_Write_UINT32(s, pdu->timestamp);
691 Stream_Write_UINT16(s, pdu->timeDiffSE);
692 Stream_Write_UINT16(s, pdu->timeDiffEDR);
693 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
696 Stream_Free(s, TRUE);
708 WINPR_ASSERT(callback);
714 RdpgfxClientContext* context = gfx->context;
715 UINT error = CHANNEL_RC_OK;
716 GraphicsResetEventArgs graphicsReset = WINPR_C_ARRAY_INIT;
718 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 12))
719 return ERROR_INVALID_DATA;
721 Stream_Read_UINT32(s, pdu.width);
722 Stream_Read_UINT32(s, pdu.height);
723 Stream_Read_UINT32(s, pdu.monitorCount);
725 if ((pdu.width == 0) || (pdu.height == 0) || (pdu.monitorCount == 0))
727 WLog_Print(gfx->base.log, WLOG_ERROR,
728 "context->ResetGraphics Width[%" PRIu32
"], Height[%" PRIu32
729 "] or monitorCount[%" PRIu32
" is 0",
730 pdu.width, pdu.height, pdu.monitorCount);
731 return ERROR_INVALID_DATA;
733 if ((pdu.width > MAX_SURFACE_SIZE) || (pdu.height > MAX_SURFACE_SIZE) ||
734 (pdu.monitorCount > MAX_MONITOR_COUNT))
736 WLog_Print(gfx->base.log, WLOG_ERROR,
737 "context->ResetGraphics Width[%" PRIu32
"], Height[%" PRIu32
"] > %" PRIu32
738 " or monitorCount[%" PRIu32
" > %" PRIu32,
739 pdu.width, pdu.height, MAX_SURFACE_SIZE, pdu.monitorCount, MAX_MONITOR_COUNT);
740 return ERROR_INVALID_DATA;
743 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.monitorCount, 20ull))
744 return ERROR_INVALID_DATA;
748 if (!pdu.monitorDefArray)
750 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
751 return CHANNEL_RC_NO_MEMORY;
754 for (UINT32 index = 0; index < pdu.monitorCount; index++)
756 MONITOR_DEF* monitor = &(pdu.monitorDefArray[index]);
757 Stream_Read_INT32(s, monitor->left);
758 Stream_Read_INT32(s, monitor->top);
759 Stream_Read_INT32(s, monitor->right);
760 Stream_Read_INT32(s, monitor->bottom);
761 Stream_Read_UINT32(s, monitor->flags);
764 const size_t size = (RDPGFX_HEADER_SIZE + 12ULL + (pdu.monitorCount * 20ULL));
767 free(pdu.monitorDefArray);
768 return CHANNEL_RC_NULL_DATA;
770 const size_t pad = 340ULL - size;
772 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, (
size_t)pad))
774 free(pdu.monitorDefArray);
775 return CHANNEL_RC_NO_MEMORY;
779 WLog_Print(gfx->base.log, WLOG_DEBUG,
780 "RecvResetGraphicsPdu: width: %" PRIu32
" height: %" PRIu32
" count: %" PRIu32
"",
781 pdu.width, pdu.height, pdu.monitorCount);
783 for (UINT32 index = 0; index < pdu.monitorCount; index++)
785 MONITOR_DEF* monitor = &(pdu.monitorDefArray[index]);
786 WLog_Print(gfx->base.log, WLOG_TRACE,
787 "RecvResetGraphicsPdu: monitor left:%" PRIi32
" top:%" PRIi32
" right:%" PRIi32
788 " bottom:%" PRIi32
" flags:0x%" PRIx32
"",
789 monitor->left, monitor->top, monitor->right, monitor->bottom, monitor->flags);
794 IFCALLRET(context->ResetGraphics, error, context, &pdu);
797 WLog_Print(gfx->base.log, WLOG_ERROR,
798 "context->ResetGraphics failed with error %" PRIu32
"", error);
801 free(pdu.monitorDefArray);
804 if (error == CHANNEL_RC_OK)
806 EventArgsInit(&graphicsReset,
"libfreerdp");
807 graphicsReset.width = pdu.width;
808 graphicsReset.height = pdu.height;
809 if (PubSub_OnGraphicsReset(gfx->rdpcontext->pubSub, gfx->rdpcontext, &graphicsReset) < 0)
810 return ERROR_INTERNAL_ERROR;
823 WINPR_ASSERT(callback);
826 RdpgfxClientContext* context = gfx->context;
827 UINT error = CHANNEL_RC_OK;
829 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 2))
830 return ERROR_INVALID_DATA;
832 Stream_Read_UINT16(s, pdu.cacheSlot);
833 WLog_Print(gfx->base.log, WLOG_DEBUG,
"RecvEvictCacheEntryPdu: cacheSlot: %" PRIu16
"",
838 IFCALLRET(context->EvictCacheEntry, error, context, &pdu);
841 WLog_Print(gfx->base.log, WLOG_ERROR,
842 "context->EvictCacheEntry failed with error %" PRIu32
"", error);
855 UINT error = CHANNEL_RC_OK;
858 WINPR_ASSERT(gfx->rdpcontext);
859 rdpSettings* settings = gfx->rdpcontext->settings;
860 RdpgfxClientContext* context = gfx->context;
862 WINPR_ASSERT(context);
863 WINPR_ASSERT(settings);
866 return CHANNEL_RC_OK;
868 const char* BitmapCachePersistFile =
870 if (!BitmapCachePersistFile)
871 return CHANNEL_RC_OK;
873 if (!context->ExportCacheEntry)
874 return CHANNEL_RC_INITIALIZATION_ERROR;
876 rdpPersistentCache* persistent = persistent_cache_new();
879 return CHANNEL_RC_NO_MEMORY;
881 if (persistent_cache_open(persistent, BitmapCachePersistFile, TRUE, 3) < 1)
883 error = CHANNEL_RC_INITIALIZATION_ERROR;
887 for (UINT16 idx = 0; idx < gfx->MaxCacheSlots; idx++)
889 if (gfx->CacheSlots[idx])
891 const UINT16 cacheSlot = idx;
894 if (context->ExportCacheEntry(context, cacheSlot, &cacheEntry) != CHANNEL_RC_OK)
897 if (persistent_cache_write_entry(persistent, &cacheEntry) < 0)
902 persistent_cache_free(persistent);
906 persistent_cache_free(persistent);
915static UINT rdpgfx_send_cache_import_offer_pdu(RdpgfxClientContext* context,
918 UINT error = CHANNEL_RC_OK;
920 if (!context || !pdu)
921 return ERROR_BAD_ARGUMENTS;
925 if (!gfx || !gfx->base.listener_callback)
926 return ERROR_BAD_CONFIGURATION;
931 return ERROR_BAD_CONFIGURATION;
934 .cmdId = RDPGFX_CMDID_CACHEIMPORTOFFER,
936 RDPGFX_HEADER_SIZE + 2ul + pdu->cacheEntriesCount * 12ul };
938 WLog_Print(gfx->base.log, WLOG_DEBUG,
"SendCacheImportOfferPdu: cacheEntriesCount: %" PRIu16
"",
939 pdu->cacheEntriesCount);
940 wStream* s = Stream_New(
nullptr, header.pduLength);
944 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
945 return CHANNEL_RC_NO_MEMORY;
948 if ((error = rdpgfx_write_header(s, &header)))
951 if (pdu->cacheEntriesCount <= 0)
953 WLog_Print(gfx->base.log, WLOG_ERROR,
"Invalid cacheEntriesCount: %" PRIu16
"",
954 pdu->cacheEntriesCount);
955 error = ERROR_INVALID_DATA;
960 Stream_Write_UINT16(s, pdu->cacheEntriesCount);
962 for (UINT16 index = 0; index < pdu->cacheEntriesCount; index++)
965 Stream_Write_UINT64(s, cacheEntry->cacheKey);
966 Stream_Write_UINT32(s, cacheEntry->bitmapLength);
969 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
973 Stream_Free(s, TRUE);
985 UINT error = CHANNEL_RC_OK;
990 WINPR_ASSERT(gfx->rdpcontext);
992 RdpgfxClientContext* context = gfx->context;
993 rdpSettings* settings = gfx->rdpcontext->settings;
996 return CHANNEL_RC_OK;
998 const char* BitmapCachePersistFile =
1000 if (!BitmapCachePersistFile)
1001 return CHANNEL_RC_OK;
1003 rdpPersistentCache* persistent = persistent_cache_new();
1006 return CHANNEL_RC_NO_MEMORY;
1008 if (persistent_cache_open(persistent, BitmapCachePersistFile, FALSE, 3) < 1)
1010 error = CHANNEL_RC_INITIALIZATION_ERROR;
1014 if (persistent_cache_get_version(persistent) != 3)
1016 error = ERROR_INVALID_DATA;
1020 count = persistent_cache_get_count(persistent);
1023 error = ERROR_INVALID_DATA;
1027 if (count >= RDPGFX_CACHE_ENTRY_MAX_COUNT)
1028 count = RDPGFX_CACHE_ENTRY_MAX_COUNT - 1;
1030 if (count > gfx->MaxCacheSlots)
1031 count = gfx->MaxCacheSlots;
1036 error = CHANNEL_RC_NO_MEMORY;
1040 WINPR_ASSERT(count <= UINT16_MAX);
1041 offer->cacheEntriesCount = (UINT16)count;
1043 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Sending Cache Import Offer: %d", count);
1045 for (
int idx = 0; idx < count; idx++)
1047 if (persistent_cache_read_entry(persistent, &entry) < 1)
1049 error = ERROR_INVALID_DATA;
1053 offer->cacheEntries[idx].cacheKey = entry.key64;
1054 offer->cacheEntries[idx].bitmapLength = entry.size;
1057 if (offer->cacheEntriesCount > 0)
1059 error = rdpgfx_send_cache_import_offer_pdu(context, offer);
1060 if (error != CHANNEL_RC_OK)
1062 WLog_Print(gfx->base.log, WLOG_ERROR,
"Failed to send cache import offer PDU");
1068 persistent_cache_free(persistent);
1078static UINT rdpgfx_load_cache_import_reply(
RDPGFX_PLUGIN* gfx,
1081 UINT error = CHANNEL_RC_OK;
1082 rdpPersistentCache* persistent =
nullptr;
1084 WINPR_ASSERT(gfx->rdpcontext);
1085 rdpSettings* settings = gfx->rdpcontext->settings;
1086 RdpgfxClientContext* context = gfx->context;
1088 WINPR_ASSERT(settings);
1089 WINPR_ASSERT(reply);
1091 return CHANNEL_RC_OK;
1093 const char* BitmapCachePersistFile =
1095 if (!BitmapCachePersistFile)
1096 return CHANNEL_RC_OK;
1098 persistent = persistent_cache_new();
1101 return CHANNEL_RC_NO_MEMORY;
1103 if (persistent_cache_open(persistent, BitmapCachePersistFile, FALSE, 3) < 1)
1105 error = CHANNEL_RC_INITIALIZATION_ERROR;
1109 if (persistent_cache_get_version(persistent) != 3)
1111 error = ERROR_INVALID_DATA;
1115 int count = persistent_cache_get_count(persistent);
1117 count = (count < reply->importedEntriesCount) ? count : reply->importedEntriesCount;
1119 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Receiving Cache Import Reply: %d", count);
1121 for (
int idx = 0; idx < count; idx++)
1124 if (persistent_cache_read_entry(persistent, &entry) < 1)
1126 error = ERROR_INVALID_DATA;
1130 const UINT16 cacheSlot = reply->cacheSlots[idx];
1131 if (context && context->ImportCacheEntry)
1133 error = context->ImportCacheEntry(context, cacheSlot, &entry);
1134 if (error != CHANNEL_RC_OK)
1139 persistent_cache_free(persistent);
1143 persistent_cache_free(persistent);
1155 WINPR_ASSERT(callback);
1158 RdpgfxClientContext* context = gfx->context;
1159 UINT error = CHANNEL_RC_OK;
1161 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 2))
1162 return ERROR_INVALID_DATA;
1164 Stream_Read_UINT16(s, pdu.importedEntriesCount);
1166 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.importedEntriesCount,
1168 return ERROR_INVALID_DATA;
1170 if (pdu.importedEntriesCount > RDPGFX_CACHE_ENTRY_MAX_COUNT)
1171 return ERROR_INVALID_DATA;
1173 for (UINT16 idx = 0; idx < pdu.importedEntriesCount; idx++)
1175 Stream_Read_UINT16(s, pdu.cacheSlots[idx]);
1178 WLog_Print(gfx->base.log, WLOG_TRACE,
1179 "RecvCacheImportReplyPdu: importedEntriesCount: %" PRIu16
"",
1180 pdu.importedEntriesCount);
1182 error = rdpgfx_load_cache_import_reply(gfx, &pdu);
1186 WLog_Print(gfx->base.log, WLOG_ERROR,
1187 "rdpgfx_load_cache_import_reply failed with error %" PRIu32
"", error);
1193 IFCALLRET(context->CacheImportReply, error, context, &pdu);
1196 WLog_Print(gfx->base.log, WLOG_ERROR,
1197 "context->CacheImportReply failed with error %" PRIu32
"", error);
1211 WINPR_ASSERT(callback);
1214 RdpgfxClientContext* context = gfx->context;
1215 UINT error = CHANNEL_RC_OK;
1217 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 7))
1218 return ERROR_INVALID_DATA;
1220 Stream_Read_UINT16(s, pdu.surfaceId);
1221 Stream_Read_UINT16(s, pdu.width);
1222 Stream_Read_UINT16(s, pdu.height);
1223 Stream_Read_UINT8(s, pdu.pixelFormat);
1225 if ((pdu.width == 0) || (pdu.height == 0))
1227 WLog_Print(gfx->base.log, WLOG_ERROR,
1228 "context->RecvCreateSurfacePdu Width[%" PRIu32
"], Height[%" PRIu32
"] is 0",
1229 pdu.width, pdu.height);
1230 return ERROR_INVALID_DATA;
1232 if ((pdu.width > MAX_SURFACE_SIZE) || (pdu.height > MAX_SURFACE_SIZE))
1234 WLog_Print(gfx->base.log, WLOG_ERROR,
1235 "context->RecvCreateSurfacePdu Width[%" PRIu32
"], Height[%" PRIu32
1237 pdu.width, pdu.height, MAX_SURFACE_SIZE);
1238 return ERROR_INVALID_DATA;
1241 WLog_Print(gfx->base.log, WLOG_DEBUG,
1242 "RecvCreateSurfacePdu: surfaceId: %" PRIu16
" width: %" PRIu16
" height: %" PRIu16
1243 " pixelFormat: 0x%02" PRIX8
"",
1244 pdu.surfaceId, pdu.width, pdu.height, pdu.pixelFormat);
1253 const UINT drc = IFCALLRESULT(CHANNEL_RC_OK, context->DeleteSurface, context, &deletePdu);
1254 if (drc != CHANNEL_RC_OK)
1255 WLog_Print(gfx->base.log, WLOG_WARN,
1256 "context->DeleteSurface failed with error %" PRIu32
", ignoring", drc);
1258 IFCALLRET(context->CreateSurface, error, context, &pdu);
1261 WLog_Print(gfx->base.log, WLOG_ERROR,
1262 "context->CreateSurface failed with error %" PRIu32
"", error);
1276 WINPR_ASSERT(callback);
1279 RdpgfxClientContext* context = gfx->context;
1280 UINT error = CHANNEL_RC_OK;
1282 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 2))
1283 return ERROR_INVALID_DATA;
1285 Stream_Read_UINT16(s, pdu.surfaceId);
1286 WLog_Print(gfx->base.log, WLOG_DEBUG,
"RecvDeleteSurfacePdu: surfaceId: %" PRIu16
"",
1291 IFCALLRET(context->DeleteSurface, error, context, &pdu);
1294 WLog_Print(gfx->base.log, WLOG_ERROR,
1295 "context->DeleteSurface failed with error %" PRIu32
"", error);
1309 WINPR_ASSERT(callback);
1312 RdpgfxClientContext* context = gfx->context;
1313 UINT error = CHANNEL_RC_OK;
1315 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_START_FRAME_PDU_SIZE))
1316 return ERROR_INVALID_DATA;
1318 Stream_Read_UINT32(s, pdu.timestamp);
1319 Stream_Read_UINT32(s, pdu.frameId);
1320 WLog_Print(gfx->base.log, WLOG_TRACE,
1321 "RecvStartFramePdu: frameId: %" PRIu32
" timestamp: 0x%08" PRIX32
"", pdu.frameId,
1323 gfx->StartDecodingTime = GetTickCount64();
1327 IFCALLRET(context->StartFrame, error, context, &pdu);
1330 WLog_Print(gfx->base.log, WLOG_ERROR,
1331 "context->StartFrame failed with error %" PRIu32
"", error);
1334 gfx->UnacknowledgedFrames++;
1347 WINPR_ASSERT(callback);
1350 RdpgfxClientContext* context = gfx->context;
1351 UINT error = CHANNEL_RC_OK;
1353 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_END_FRAME_PDU_SIZE))
1354 return ERROR_INVALID_DATA;
1356 Stream_Read_UINT32(s, pdu.frameId);
1357 WLog_Print(gfx->base.log, WLOG_TRACE,
"RecvEndFramePdu: frameId: %" PRIu32
"", pdu.frameId);
1359 const UINT64 start = GetTickCount64();
1362 IFCALLRET(context->EndFrame, error, context, &pdu);
1366 WLog_Print(gfx->base.log, WLOG_ERROR,
"context->EndFrame failed with error %" PRIu32
"",
1371 const UINT64 end = GetTickCount64();
1372 const UINT64 EndFrameTime = end - start;
1373 gfx->TotalDecodedFrames++;
1375 if (!gfx->sendFrameAcks)
1378 ack.frameId = pdu.frameId;
1379 ack.totalFramesDecoded = gfx->TotalDecodedFrames;
1381 if (gfx->suspendFrameAcks)
1383 ack.queueDepth = SUSPEND_FRAME_ACKNOWLEDGEMENT;
1385 if (gfx->TotalDecodedFrames == 1)
1386 if ((error = rdpgfx_send_frame_acknowledge_pdu(context, &ack)))
1387 WLog_Print(gfx->base.log, WLOG_ERROR,
1388 "rdpgfx_send_frame_acknowledge_pdu failed with error %" PRIu32
"",
1393 ack.queueDepth = QUEUE_DEPTH_UNAVAILABLE;
1395 if ((error = rdpgfx_send_frame_acknowledge_pdu(context, &ack)))
1396 WLog_Print(gfx->base.log, WLOG_ERROR,
1397 "rdpgfx_send_frame_acknowledge_pdu failed with error %" PRIu32
"", error);
1400 switch (gfx->ConnectionCaps.version)
1402#if defined(WITH_GFX_AV1)
1403 case RDPGFX_CAPVERSION_FRDP_1:
1405 case RDPGFX_CAPVERSION_10:
1406 case RDPGFX_CAPVERSION_102:
1407 case RDPGFX_CAPVERSION_103:
1408 case RDPGFX_CAPVERSION_104:
1409 case RDPGFX_CAPVERSION_105:
1410 case RDPGFX_CAPVERSION_106:
1411 case RDPGFX_CAPVERSION_106_ERR:
1412 case RDPGFX_CAPVERSION_107:
1413#if defined(WITH_GFX_AZURE)
1414 case RDPGFX_CAPVERSION_111:
1415 case RDPGFX_CAPVERSION_112:
1416 case RDPGFX_CAPVERSION_113:
1421 UINT64 diff = (GetTickCount64() - gfx->StartDecodingTime);
1426 qoe.frameId = pdu.frameId;
1427 qoe.timestamp = gfx->StartDecodingTime % UINT32_MAX;
1428 qoe.timeDiffSE = WINPR_ASSERTING_INT_CAST(UINT16, diff);
1429 qoe.timeDiffEDR = WINPR_ASSERTING_INT_CAST(UINT16, EndFrameTime);
1431 if ((error = rdpgfx_send_qoe_frame_acknowledge_pdu(context, &qoe)))
1432 WLog_Print(gfx->base.log, WLOG_ERROR,
1433 "rdpgfx_send_qoe_frame_acknowledge_pdu failed with error %" PRIu32
1456 WINPR_ASSERT(callback);
1461 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_WIRE_TO_SURFACE_PDU_1_SIZE))
1462 return ERROR_INVALID_DATA;
1464 Stream_Read_UINT16(s, pdu.surfaceId);
1465 Stream_Read_UINT16(s, pdu.codecId);
1466 Stream_Read_UINT8(s, pdu.pixelFormat);
1468 if ((error = rdpgfx_read_rect16(gfx->base.log, s, &(pdu.destRect))))
1470 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_rect16 failed with error %" PRIu32
"",
1475 Stream_Read_UINT32(s, pdu.bitmapDataLength);
1477 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, pdu.bitmapDataLength))
1478 return ERROR_INVALID_DATA;
1480 pdu.bitmapData = Stream_Pointer(s);
1481 Stream_Seek(s, pdu.bitmapDataLength);
1483 WLog_Print(gfx->base.log, WLOG_TRACE,
1484 "RecvWireToSurface1Pdu: surfaceId: %" PRIu16
" codecId: %s (0x%04" PRIX16
1485 ") pixelFormat: 0x%02" PRIX8
" "
1486 "destRect: left: %" PRIu16
" top: %" PRIu16
" right: %" PRIu16
" bottom: %" PRIu16
1487 " bitmapDataLength: %" PRIu32
"",
1488 pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId, pdu.pixelFormat,
1489 pdu.destRect.left, pdu.destRect.top, pdu.destRect.right, pdu.destRect.bottom,
1490 pdu.bitmapDataLength);
1491 cmd.surfaceId = pdu.surfaceId;
1492 cmd.codecId = pdu.codecId;
1495 switch (pdu.pixelFormat)
1497 case GFX_PIXEL_FORMAT_XRGB_8888:
1498 cmd.format = PIXEL_FORMAT_BGRX32;
1501 case GFX_PIXEL_FORMAT_ARGB_8888:
1502 cmd.format = PIXEL_FORMAT_BGRA32;
1506 return ERROR_INVALID_DATA;
1509 cmd.left = pdu.destRect.left;
1510 cmd.top = pdu.destRect.top;
1511 cmd.right = pdu.destRect.right;
1512 cmd.bottom = pdu.destRect.bottom;
1513 cmd.width = cmd.right - cmd.left;
1514 cmd.height = cmd.bottom - cmd.top;
1515 cmd.length = pdu.bitmapDataLength;
1516 cmd.data = pdu.bitmapData;
1517 cmd.extra =
nullptr;
1519 if (cmd.right < cmd.left)
1521 WLog_Print(gfx->base.log, WLOG_ERROR,
1522 "RecvWireToSurface1Pdu right=%" PRIu32
" < left=%" PRIu32, cmd.right, cmd.left);
1523 return ERROR_INVALID_DATA;
1525 if (cmd.bottom < cmd.top)
1527 WLog_Print(gfx->base.log, WLOG_ERROR,
1528 "RecvWireToSurface1Pdu bottom=%" PRIu32
" < top=%" PRIu32, cmd.bottom, cmd.top);
1529 return ERROR_INVALID_DATA;
1532 if ((error = rdpgfx_decode(gfx, &cmd)))
1533 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_decode failed with error %" PRIu32
"!",
1542 switch (cmd->codecId)
1544 case RDPGFX_CODECID_UNCOMPRESSED:
1545 case RDPGFX_CODECID_CAVIDEO:
1546 case RDPGFX_CODECID_CLEARCODEC:
1547 case RDPGFX_CODECID_PLANAR:
1548 case RDPGFX_CODECID_AVC420:
1549 case RDPGFX_CODECID_ALPHA:
1550 case RDPGFX_CODECID_AVC444:
1551 case RDPGFX_CODECID_AVC444v2:
1552 case RDPGFX_CODECID_CAPROGRESSIVE:
1553 case RDPGFX_CODECID_CAPROGRESSIVE_V2:
1555#if defined(WITH_GFX_AV1)
1556 case RDPGFX_CODECID_AV1:
1557 if (gfx->ConnectionCaps.version != RDPGFX_CAPVERSION_FRDP_1)
1559 WLog_Print(gfx->base.log, WLOG_ERROR,
1560 "RDPGFX_SURFACE_COMMAND::codecId %" PRIu32
1561 " only supported with %s but connection uses %s [0x%08" PRIx32
"]",
1562 cmd->codecId, rdpgfx_caps_version_str(RDPGFX_CAPVERSION_FRDP_1),
1563 rdpgfx_caps_version_str(gfx->ConnectionCaps.version),
1564 gfx->ConnectionCaps.version);
1570 WLog_Print(gfx->base.log, WLOG_ERROR,
1571 "Unknown RDPGFX_SURFACE_COMMAND::codecId %" PRIu32, cmd->codecId);
1580 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Got GFX %s",
1581 rdpgfx_get_codec_id_string(WINPR_ASSERTING_INT_CAST(UINT16, cmd->codecId)));
1583 RdpgfxClientContext* context = gfx->context;
1585 return CHANNEL_RC_OK;
1587 if (!checkSurfaceCommand(gfx, cmd))
1588 return CHANNEL_RC_NULL_DATA;
1590 const UINT error = IFCALLRESULT(CHANNEL_RC_OK, context->SurfaceCommand, context, cmd);
1593 WLog_Print(gfx->base.log, WLOG_ERROR,
1594 "context->SurfaceCommand failed with error %" PRIu32
"", error);
1596 rdpgfx_codecid_event(context, cmd->codecId);
1610 WINPR_ASSERT(callback);
1614 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_WIRE_TO_SURFACE_PDU_2_SIZE))
1615 return ERROR_INVALID_DATA;
1617 Stream_Read_UINT16(s, pdu.surfaceId);
1618 Stream_Read_UINT16(s, pdu.codecId);
1619 Stream_Read_UINT32(s, pdu.codecContextId);
1620 Stream_Read_UINT8(s, pdu.pixelFormat);
1621 Stream_Read_UINT32(s, pdu.bitmapDataLength);
1622 pdu.bitmapData = Stream_Pointer(s);
1623 if (!Stream_SafeSeek(s, pdu.bitmapDataLength))
1624 return ERROR_INVALID_DATA;
1626 WLog_Print(gfx->base.log, WLOG_TRACE,
1627 "RecvWireToSurface2Pdu: surfaceId: %" PRIu16
" codecId: %s (0x%04" PRIX16
") "
1628 "codecContextId: %" PRIu32
" pixelFormat: 0x%02" PRIX8
" bitmapDataLength: %" PRIu32
1630 pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId,
1631 pdu.codecContextId, pdu.pixelFormat, pdu.bitmapDataLength);
1633 cmd.surfaceId = pdu.surfaceId;
1634 cmd.codecId = pdu.codecId;
1635 cmd.contextId = pdu.codecContextId;
1637 switch (pdu.pixelFormat)
1639 case GFX_PIXEL_FORMAT_XRGB_8888:
1640 cmd.format = PIXEL_FORMAT_BGRX32;
1643 case GFX_PIXEL_FORMAT_ARGB_8888:
1644 cmd.format = PIXEL_FORMAT_BGRA32;
1648 return ERROR_INVALID_DATA;
1651 cmd.length = pdu.bitmapDataLength;
1652 cmd.data = pdu.bitmapData;
1653 cmd.extra =
nullptr;
1655 if (cmd.codecId != RDPGFX_CODECID_CAPROGRESSIVE)
1656 return ERROR_INVALID_DATA;
1658 return logSurfaceCommand(gfx, &cmd);
1669 WINPR_ASSERT(callback);
1672 RdpgfxClientContext* context = gfx->context;
1673 UINT error = CHANNEL_RC_OK;
1675 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 6))
1676 return ERROR_INVALID_DATA;
1678 Stream_Read_UINT16(s, pdu.surfaceId);
1679 Stream_Read_UINT32(s, pdu.codecContextId);
1681 WLog_Print(gfx->base.log, WLOG_DEBUG,
1682 "RecvDeleteEncodingContextPdu: surfaceId: %" PRIu16
" codecContextId: %" PRIu32
"",
1683 pdu.surfaceId, pdu.codecContextId);
1687 IFCALLRET(context->DeleteEncodingContext, error, context, &pdu);
1690 WLog_Print(gfx->base.log, WLOG_ERROR,
1691 "context->DeleteEncodingContext failed with error %" PRIu32
"", error);
1705 WINPR_ASSERT(callback);
1708 RdpgfxClientContext* context = gfx->context;
1710 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 8))
1711 return ERROR_INVALID_DATA;
1713 Stream_Read_UINT16(s, pdu.surfaceId);
1715 UINT error = rdpgfx_read_color32(gfx->base.log, s, &(pdu.fillPixel));
1716 if (error != CHANNEL_RC_OK)
1718 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_color32 failed with error %" PRIu32
"!",
1723 Stream_Read_UINT16(s, pdu.fillRectCount);
1725 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.fillRectCount, 8ull))
1726 return ERROR_INVALID_DATA;
1732 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
1733 return CHANNEL_RC_NO_MEMORY;
1736 for (UINT16 index = 0; index < pdu.fillRectCount; index++)
1740 if ((error = rdpgfx_read_rect16(gfx->base.log, s, fillRect)))
1742 WLog_Print(gfx->base.log, WLOG_ERROR,
1743 "rdpgfx_read_rect16 failed with error %" PRIu32
"!", error);
1744 free(pdu.fillRects);
1748 WLog_Print(gfx->base.log, WLOG_TRACE,
1749 "RecvSolidFillPdu: surfaceId: %" PRIu16
" fillRectCount: %" PRIu16
"", pdu.surfaceId,
1754 IFCALLRET(context->SolidFill, error, context, &pdu);
1757 WLog_Print(gfx->base.log, WLOG_ERROR,
1758 "context->SolidFill failed with error %" PRIu32
"", error);
1761 free(pdu.fillRects);
1773 WINPR_ASSERT(callback);
1776 RdpgfxClientContext* context = gfx->context;
1779 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 14))
1780 return ERROR_INVALID_DATA;
1782 Stream_Read_UINT16(s, pdu.surfaceIdSrc);
1783 Stream_Read_UINT16(s, pdu.surfaceIdDest);
1785 if ((error = rdpgfx_read_rect16(gfx->base.log, s, &(pdu.rectSrc))))
1787 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_rect16 failed with error %" PRIu32
"!",
1792 Stream_Read_UINT16(s, pdu.destPtsCount);
1794 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.destPtsCount, 4ull))
1795 return ERROR_INVALID_DATA;
1801 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
1802 return CHANNEL_RC_NO_MEMORY;
1805 for (UINT16 index = 0; index < pdu.destPtsCount; index++)
1809 if ((error = rdpgfx_read_point16(gfx->base.log, s, destPt)))
1811 WLog_Print(gfx->base.log, WLOG_ERROR,
1812 "rdpgfx_read_point16 failed with error %" PRIu32
"!", error);
1818 WLog_Print(gfx->base.log, WLOG_TRACE,
1819 "RecvSurfaceToSurfacePdu: surfaceIdSrc: %" PRIu16
" surfaceIdDest: %" PRIu16
" "
1820 "left: %" PRIu16
" top: %" PRIu16
" right: %" PRIu16
" bottom: %" PRIu16
1821 " destPtsCount: %" PRIu16
"",
1822 pdu.surfaceIdSrc, pdu.surfaceIdDest, pdu.rectSrc.left, pdu.rectSrc.top,
1823 pdu.rectSrc.right, pdu.rectSrc.bottom, pdu.destPtsCount);
1827 IFCALLRET(context->SurfaceToSurface, error, context, &pdu);
1830 WLog_Print(gfx->base.log, WLOG_ERROR,
1831 "context->SurfaceToSurface failed with error %" PRIu32
"", error);
1846 WINPR_ASSERT(callback);
1850 RdpgfxClientContext* context = gfx->context;
1852 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 20))
1853 return ERROR_INVALID_DATA;
1855 Stream_Read_UINT16(s, pdu.surfaceId);
1856 Stream_Read_UINT64(s, pdu.cacheKey);
1857 Stream_Read_UINT16(s, pdu.cacheSlot);
1859 UINT error = rdpgfx_read_rect16(gfx->base.log, s, &(pdu.rectSrc));
1860 if (error != CHANNEL_RC_OK)
1862 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_rect16 failed with error %" PRIu32
"!",
1867 WLog_Print(gfx->base.log, WLOG_TRACE,
1868 "RecvSurfaceToCachePdu: surfaceId: %" PRIu16
" cacheKey: 0x%016" PRIX64
1869 " cacheSlot: %" PRIu16
" "
1870 "left: %" PRIu16
" top: %" PRIu16
" right: %" PRIu16
" bottom: %" PRIu16
"",
1871 pdu.surfaceId, pdu.cacheKey, pdu.cacheSlot, pdu.rectSrc.left, pdu.rectSrc.top,
1872 pdu.rectSrc.right, pdu.rectSrc.bottom);
1876 IFCALLRET(context->SurfaceToCache, error, context, &pdu);
1879 WLog_Print(gfx->base.log, WLOG_ERROR,
1880 "context->SurfaceToCache failed with error %" PRIu32
"", error);
1894 WINPR_ASSERT(callback);
1898 RdpgfxClientContext* context = gfx->context;
1899 UINT error = CHANNEL_RC_OK;
1901 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 6))
1902 return ERROR_INVALID_DATA;
1904 Stream_Read_UINT16(s, pdu.cacheSlot);
1905 Stream_Read_UINT16(s, pdu.surfaceId);
1906 Stream_Read_UINT16(s, pdu.destPtsCount);
1908 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.destPtsCount, 4ull))
1909 return ERROR_INVALID_DATA;
1915 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
1916 return CHANNEL_RC_NO_MEMORY;
1919 for (UINT16 index = 0; index < pdu.destPtsCount; index++)
1923 if ((error = rdpgfx_read_point16(gfx->base.log, s, destPt)))
1925 WLog_Print(gfx->base.log, WLOG_ERROR,
1926 "rdpgfx_read_point16 failed with error %" PRIu32
"", error);
1932 WLog_Print(gfx->base.log, WLOG_TRACE,
1933 "RdpGfxRecvCacheToSurfacePdu: cacheSlot: %" PRIu16
" surfaceId: %" PRIu16
1934 " destPtsCount: %" PRIu16
"",
1935 pdu.cacheSlot, pdu.surfaceId, pdu.destPtsCount);
1939 IFCALLRET(context->CacheToSurface, error, context, &pdu);
1942 WLog_Print(gfx->base.log, WLOG_ERROR,
1943 "context->CacheToSurface failed with error %" PRIu32
"", error);
1958 WINPR_ASSERT(callback);
1962 RdpgfxClientContext* context = gfx->context;
1963 UINT error = CHANNEL_RC_OK;
1965 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 12))
1966 return ERROR_INVALID_DATA;
1968 Stream_Read_UINT16(s, pdu.surfaceId);
1969 Stream_Read_UINT16(s, pdu.reserved);
1970 Stream_Read_UINT32(s, pdu.outputOriginX);
1971 Stream_Read_UINT32(s, pdu.outputOriginY);
1972 WLog_Print(gfx->base.log, WLOG_DEBUG,
1973 "RecvMapSurfaceToOutputPdu: surfaceId: %" PRIu16
" outputOriginX: %" PRIu32
1974 " outputOriginY: %" PRIu32
"",
1975 pdu.surfaceId, pdu.outputOriginX, pdu.outputOriginY);
1979 IFCALLRET(context->MapSurfaceToOutput, error, context, &pdu);
1982 WLog_Print(gfx->base.log, WLOG_ERROR,
1983 "context->MapSurfaceToOutput failed with error %" PRIu32
"", error);
1993 WINPR_ASSERT(callback);
1997 RdpgfxClientContext* context = gfx->context;
1998 UINT error = CHANNEL_RC_OK;
2000 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 20))
2001 return ERROR_INVALID_DATA;
2003 Stream_Read_UINT16(s, pdu.surfaceId);
2004 Stream_Read_UINT16(s, pdu.reserved);
2005 Stream_Read_UINT32(s, pdu.outputOriginX);
2006 Stream_Read_UINT32(s, pdu.outputOriginY);
2007 Stream_Read_UINT32(s, pdu.targetWidth);
2008 Stream_Read_UINT32(s, pdu.targetHeight);
2009 WLog_Print(gfx->base.log, WLOG_DEBUG,
2010 "RecvMapSurfaceToScaledOutputPdu: surfaceId: %" PRIu16
" outputOriginX: %" PRIu32
2011 " outputOriginY: %" PRIu32
" targetWidth: %" PRIu32
" targetHeight: %" PRIu32,
2012 pdu.surfaceId, pdu.outputOriginX, pdu.outputOriginY, pdu.targetWidth,
2017 IFCALLRET(context->MapSurfaceToScaledOutput, error, context, &pdu);
2020 WLog_Print(gfx->base.log, WLOG_ERROR,
2021 "context->MapSurfaceToScaledOutput failed with error %" PRIu32
"", error);
2035 WINPR_ASSERT(callback);
2039 RdpgfxClientContext* context = gfx->context;
2040 UINT error = CHANNEL_RC_OK;
2042 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 18))
2043 return ERROR_INVALID_DATA;
2045 Stream_Read_UINT16(s, pdu.surfaceId);
2046 Stream_Read_UINT64(s, pdu.windowId);
2047 Stream_Read_UINT32(s, pdu.mappedWidth);
2048 Stream_Read_UINT32(s, pdu.mappedHeight);
2050 if ((pdu.mappedWidth == 0) || (pdu.mappedHeight == 0))
2052 WLog_Print(gfx->base.log, WLOG_ERROR,
2053 "context->MapSurfaceToWindow mappedWidth[%" PRIu32
"], mappedHeight[%" PRIu32
2055 pdu.mappedWidth, pdu.mappedHeight);
2056 return ERROR_INVALID_DATA;
2058 if ((pdu.mappedWidth > MAX_SURFACE_SIZE) || (pdu.mappedHeight > MAX_SURFACE_SIZE))
2060 WLog_Print(gfx->base.log, WLOG_ERROR,
2061 "context->MapSurfaceToWindow mappedWidth[%" PRIu32
"], mappedHeight[%" PRIu32
2063 pdu.mappedWidth, pdu.mappedHeight, MAX_SURFACE_SIZE);
2064 return ERROR_INVALID_DATA;
2067 WLog_Print(gfx->base.log, WLOG_DEBUG,
2068 "RecvMapSurfaceToWindowPdu: surfaceId: %" PRIu16
" windowId: 0x%016" PRIX64
2069 " mappedWidth: %" PRIu32
" mappedHeight: %" PRIu32
"",
2070 pdu.surfaceId, pdu.windowId, pdu.mappedWidth, pdu.mappedHeight);
2072 if (context && context->MapSurfaceToWindow)
2074 IFCALLRET(context->MapSurfaceToWindow, error, context, &pdu);
2077 WLog_Print(gfx->base.log, WLOG_ERROR,
2078 "context->MapSurfaceToWindow failed with error %" PRIu32
"", error);
2088 WINPR_ASSERT(callback);
2091 RdpgfxClientContext* context = gfx->context;
2092 UINT error = CHANNEL_RC_OK;
2094 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 26))
2095 return ERROR_INVALID_DATA;
2097 Stream_Read_UINT16(s, pdu.surfaceId);
2098 Stream_Read_UINT64(s, pdu.windowId);
2099 Stream_Read_UINT32(s, pdu.mappedWidth);
2100 Stream_Read_UINT32(s, pdu.mappedHeight);
2101 Stream_Read_UINT32(s, pdu.targetWidth);
2102 Stream_Read_UINT32(s, pdu.targetHeight);
2104 if ((pdu.mappedWidth == 0) || (pdu.mappedHeight == 0))
2106 WLog_Print(gfx->base.log, WLOG_ERROR,
2107 "context->RecvMapSurfaceToScaledWindowPdu mappedWidth[%" PRIu32
2108 "], mappedHeight[%" PRIu32
"] is 0",
2109 pdu.mappedWidth, pdu.mappedHeight);
2110 return ERROR_INVALID_DATA;
2112 if ((pdu.targetWidth == 0) || (pdu.targetHeight == 0))
2114 WLog_Print(gfx->base.log, WLOG_ERROR,
2115 "context->RecvMapSurfaceToScaledWindowPdu targetWidth[%" PRIu32
2116 "], targetHeight[%" PRIu32
"] is 0",
2117 pdu.targetWidth, pdu.targetHeight);
2118 return ERROR_INVALID_DATA;
2121 if ((pdu.mappedWidth > MAX_SURFACE_SIZE) || (pdu.mappedHeight > MAX_SURFACE_SIZE))
2123 WLog_Print(gfx->base.log, WLOG_ERROR,
2124 "context->RecvMapSurfaceToScaledWindowPdu mappedWidth[%" PRIu32
2125 "], mappedHeight[%" PRIu32
"] > %" PRIu32,
2126 pdu.mappedWidth, pdu.mappedHeight, MAX_SURFACE_SIZE);
2127 return ERROR_INVALID_DATA;
2130 WLog_Print(gfx->base.log, WLOG_DEBUG,
2131 "RecvMapSurfaceToScaledWindowPdu: surfaceId: %" PRIu16
" windowId: 0x%016" PRIX64
2132 " mappedWidth: %" PRIu32
" mappedHeight: %" PRIu32
" targetWidth: %" PRIu32
2133 " targetHeight: %" PRIu32
"",
2134 pdu.surfaceId, pdu.windowId, pdu.mappedWidth, pdu.mappedHeight, pdu.targetWidth,
2137 if (context && context->MapSurfaceToScaledWindow)
2139 IFCALLRET(context->MapSurfaceToScaledWindow, error, context, &pdu);
2142 WLog_Print(gfx->base.log, WLOG_ERROR,
2143 "context->MapSurfaceToScaledWindow failed with error %" PRIu32
"", error);
2158 WINPR_ASSERT(callback);
2160 const size_t beg = Stream_GetPosition(s);
2164 size_t packetlen = 0;
2165 UINT error = rdpgfx_read_header(gfx->base.log, s, &header, &packetlen);
2166 if (error != CHANNEL_RC_OK)
2168 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_header failed with error %" PRIu32
"!",
2173 WLog_Print(gfx->base.log, WLOG_TRACE,
2174 "cmdId: %s (0x%04" PRIX16
") flags: 0x%04" PRIX16
" pduLength: %" PRIu32
"",
2175 rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId, header.flags,
2178 rdpgfx_stats_cmdid_event(gfx->context, header.cmdId);
2179 switch (header.cmdId)
2181 case RDPGFX_CMDID_WIRETOSURFACE_1:
2182 if ((error = rdpgfx_recv_wire_to_surface_1_pdu(callback, s)))
2183 WLog_Print(gfx->base.log, WLOG_ERROR,
2184 "rdpgfx_recv_wire_to_surface_1_pdu failed with error %" PRIu32
"!",
2189 case RDPGFX_CMDID_WIRETOSURFACE_2:
2190 if ((error = rdpgfx_recv_wire_to_surface_2_pdu(callback, s)))
2191 WLog_Print(gfx->base.log, WLOG_ERROR,
2192 "rdpgfx_recv_wire_to_surface_2_pdu failed with error %" PRIu32
"!",
2197 case RDPGFX_CMDID_DELETEENCODINGCONTEXT:
2198 if ((error = rdpgfx_recv_delete_encoding_context_pdu(callback, s)))
2199 WLog_Print(gfx->base.log, WLOG_ERROR,
2200 "rdpgfx_recv_delete_encoding_context_pdu failed with error %" PRIu32
"!",
2205 case RDPGFX_CMDID_SOLIDFILL:
2206 if ((error = rdpgfx_recv_solid_fill_pdu(callback, s)))
2207 WLog_Print(gfx->base.log, WLOG_ERROR,
2208 "rdpgfx_recv_solid_fill_pdu failed with error %" PRIu32
"!", error);
2212 case RDPGFX_CMDID_SURFACETOSURFACE:
2213 if ((error = rdpgfx_recv_surface_to_surface_pdu(callback, s)))
2214 WLog_Print(gfx->base.log, WLOG_ERROR,
2215 "rdpgfx_recv_surface_to_surface_pdu failed with error %" PRIu32
"!",
2220 case RDPGFX_CMDID_SURFACETOCACHE:
2221 if ((error = rdpgfx_recv_surface_to_cache_pdu(callback, s)))
2222 WLog_Print(gfx->base.log, WLOG_ERROR,
2223 "rdpgfx_recv_surface_to_cache_pdu failed with error %" PRIu32
"!",
2228 case RDPGFX_CMDID_CACHETOSURFACE:
2229 if ((error = rdpgfx_recv_cache_to_surface_pdu(callback, s)))
2230 WLog_Print(gfx->base.log, WLOG_ERROR,
2231 "rdpgfx_recv_cache_to_surface_pdu failed with error %" PRIu32
"!",
2236 case RDPGFX_CMDID_EVICTCACHEENTRY:
2237 if ((error = rdpgfx_recv_evict_cache_entry_pdu(callback, s)))
2238 WLog_Print(gfx->base.log, WLOG_ERROR,
2239 "rdpgfx_recv_evict_cache_entry_pdu failed with error %" PRIu32
"!",
2244 case RDPGFX_CMDID_CREATESURFACE:
2245 if ((error = rdpgfx_recv_create_surface_pdu(callback, s)))
2246 WLog_Print(gfx->base.log, WLOG_ERROR,
2247 "rdpgfx_recv_create_surface_pdu failed with error %" PRIu32
"!", error);
2251 case RDPGFX_CMDID_DELETESURFACE:
2252 if ((error = rdpgfx_recv_delete_surface_pdu(callback, s)))
2253 WLog_Print(gfx->base.log, WLOG_ERROR,
2254 "rdpgfx_recv_delete_surface_pdu failed with error %" PRIu32
"!", error);
2258 case RDPGFX_CMDID_STARTFRAME:
2259 if ((error = rdpgfx_recv_start_frame_pdu(callback, s)))
2260 WLog_Print(gfx->base.log, WLOG_ERROR,
2261 "rdpgfx_recv_start_frame_pdu failed with error %" PRIu32
"!", error);
2265 case RDPGFX_CMDID_ENDFRAME:
2266 if ((error = rdpgfx_recv_end_frame_pdu(callback, s)))
2267 WLog_Print(gfx->base.log, WLOG_ERROR,
2268 "rdpgfx_recv_end_frame_pdu failed with error %" PRIu32
"!", error);
2272 case RDPGFX_CMDID_RESETGRAPHICS:
2273 if ((error = rdpgfx_recv_reset_graphics_pdu(callback, s)))
2274 WLog_Print(gfx->base.log, WLOG_ERROR,
2275 "rdpgfx_recv_reset_graphics_pdu failed with error %" PRIu32
"!", error);
2279 case RDPGFX_CMDID_MAPSURFACETOOUTPUT:
2280 if ((error = rdpgfx_recv_map_surface_to_output_pdu(callback, s)))
2281 WLog_Print(gfx->base.log, WLOG_ERROR,
2282 "rdpgfx_recv_map_surface_to_output_pdu failed with error %" PRIu32
"!",
2287 case RDPGFX_CMDID_CACHEIMPORTREPLY:
2288 if ((error = rdpgfx_recv_cache_import_reply_pdu(callback, s)))
2289 WLog_Print(gfx->base.log, WLOG_ERROR,
2290 "rdpgfx_recv_cache_import_reply_pdu failed with error %" PRIu32
"!",
2295 case RDPGFX_CMDID_CAPSCONFIRM:
2296 if ((error = rdpgfx_recv_caps_confirm_pdu(callback, s)))
2297 WLog_Print(gfx->base.log, WLOG_ERROR,
2298 "rdpgfx_recv_caps_confirm_pdu failed with error %" PRIu32
"!", error);
2300 if ((error = rdpgfx_send_cache_offer(gfx)))
2301 WLog_Print(gfx->base.log, WLOG_ERROR,
2302 "rdpgfx_send_cache_offer failed with error %" PRIu32
"!", error);
2306 case RDPGFX_CMDID_MAPSURFACETOWINDOW:
2307 if ((error = rdpgfx_recv_map_surface_to_window_pdu(callback, s)))
2308 WLog_Print(gfx->base.log, WLOG_ERROR,
2309 "rdpgfx_recv_map_surface_to_window_pdu failed with error %" PRIu32
"!",
2314 case RDPGFX_CMDID_MAPSURFACETOSCALEDWINDOW:
2315 if ((error = rdpgfx_recv_map_surface_to_scaled_window_pdu(callback, s)))
2316 WLog_Print(gfx->base.log, WLOG_ERROR,
2317 "rdpgfx_recv_map_surface_to_scaled_window_pdu failed with error %" PRIu32
2323 case RDPGFX_CMDID_MAPSURFACETOSCALEDOUTPUT:
2324 if ((error = rdpgfx_recv_map_surface_to_scaled_output_pdu(callback, s)))
2325 WLog_Print(gfx->base.log, WLOG_ERROR,
2326 "rdpgfx_recv_map_surface_to_scaled_output_pdu failed with error %" PRIu32
2332 case RDPGFX_CMDID_PROTECT_SURFACE:
2333 case RDPGFX_CMDID_WATERMARK:
2334 WLog_Print(gfx->base.log, WLOG_WARN,
2335 "Command %s not implemented, skipping %" PRIu32
" bytes",
2336 rdpgfx_get_cmd_id_string(header.cmdId), header.pduLength);
2337 if (!Stream_SafeSeek(s, packetlen))
2338 error = ERROR_INVALID_DATA;
2341 error = CHANNEL_RC_BAD_PROC;
2347 WLog_Print(gfx->base.log, WLOG_ERROR,
2348 "Error while processing GFX cmdId: %s (0x%04" PRIX16
")",
2349 rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId);
2350 if (!Stream_SetPosition(s, (beg + header.pduLength)))
2351 return ERROR_INVALID_DATA;
2355 const size_t end = Stream_GetPosition(s);
2357 if (end != (beg + header.pduLength))
2359 WLog_Print(gfx->base.log, WLOG_ERROR,
2360 "Unexpected gfx pdu end: Actual: %" PRIuz
", Expected: %" PRIuz, end,
2361 (beg + header.pduLength));
2362 if (!Stream_SetPosition(s, (beg + header.pduLength)))
2363 return ERROR_INVALID_DATA;
2374static UINT rdpgfx_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
wStream* data)
2377 BYTE* pDstData =
nullptr;
2379 WINPR_ASSERT(callback);
2381 UINT error = CHANNEL_RC_OK;
2384 int status = zgfx_decompress(gfx->zgfx, Stream_ConstPointer(data),
2385 (UINT32)Stream_GetRemainingLength(data), &pDstData, &DstSize, 0);
2387 if ((status < 0) || (DstSize == 0))
2389 WLog_Print(gfx->base.log, WLOG_ERROR,
2390 "zgfx_decompress failure! status: %d, DstSize=%" PRIu32, status, DstSize);
2392 return ERROR_INTERNAL_ERROR;
2395 wStream sbuffer = WINPR_C_ARRAY_INIT;
2396 wStream* s = Stream_StaticConstInit(&sbuffer, pDstData, DstSize);
2400 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
2402 return CHANNEL_RC_NO_MEMORY;
2405 while (Stream_GetPosition(s) < Stream_Length(s))
2407 if ((error = rdpgfx_recv_pdu(callback, s)))
2409 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_recv_pdu failed with error %" PRIu32
"!",
2424static UINT rdpgfx_on_open(IWTSVirtualChannelCallback* pChannelCallback)
2427 WINPR_ASSERT(callback);
2430 RdpgfxClientContext* context = gfx->context;
2431 UINT error = CHANNEL_RC_OK;
2432 BOOL do_caps_advertise = TRUE;
2434 gfx->sendFrameAcks = TRUE;
2438 IFCALLRET(context->OnOpen, error, context, &do_caps_advertise, &gfx->sendFrameAcks);
2441 WLog_Print(gfx->base.log, WLOG_ERROR,
"context->OnOpen failed with error %" PRIu32
"",
2444 RdpgfxClientContextInt* ctx = (RdpgfxClientContextInt*)context;
2445 const RdpgfxClientContextStats empty = WINPR_C_ARRAY_INIT;
2449 if (do_caps_advertise)
2450 error = rdpgfx_send_supported_caps(callback);
2455static void rdpgfx_dump_stats(RdpgfxClientContext* context)
2457 WINPR_ASSERT(context);
2462 wLog* log = gfx->base.log;
2463 const DWORD level = WLOG_TRACE;
2464 if (!WLog_IsLevelActive(log, level))
2467 WLog_Print(log, level,
"RdpgfxClientContextStats");
2468 for (
size_t x = 0; x < rdpgfx_stats_max_index(); x++)
2470 const char* name = rdpgfx_stats_name_for_index(x);
2471 const uint64_t val = rdpgfx_stats_value_for_index(context, x);
2472 WLog_Print(log, level,
"%s: %" PRIu64, name, val);
2481static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback)
2483 UINT error = CHANNEL_RC_OK;
2485 WINPR_ASSERT(callback);
2491 RdpgfxClientContext* context = gfx->context;
2493 WLog_Print(gfx->base.log, WLOG_DEBUG,
"OnClose");
2494 error = rdpgfx_save_persistent_cache(gfx);
2499 WLog_Print(gfx->base.log, WLOG_ERROR,
2500 "rdpgfx_save_persistent_cache failed with error %" PRIu32
"", error);
2503 free_surfaces(context, gfx->SurfaceTable);
2504 error = evict_cache_slots(context, gfx->MaxCacheSlots, gfx->CacheSlots);
2508 WLog_Print(gfx->base.log, WLOG_ERROR,
"evict_cache_slots failed with error %" PRIu32
"",
2513 gfx->UnacknowledgedFrames = 0;
2514 gfx->TotalDecodedFrames = 0;
2518 error = IFCALLRESULT(CHANNEL_RC_OK, context->OnClose, context);
2522 WLog_Print(gfx->base.log, WLOG_ERROR,
"context->OnClose failed with error %" PRIu32
"",
2525 rdpgfx_dump_stats(context);
2529 return CHANNEL_RC_OK;
2536 RdpgfxClientContext* context = gfx->context;
2538 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Terminated");
2539 rdpgfx_client_context_free(context);
2547static UINT rdpgfx_set_surface_data(RdpgfxClientContext* context, UINT16 surfaceId,
void* pData)
2549 WINPR_ASSERT(context);
2552 ULONG_PTR key = ((ULONG_PTR)surfaceId) + 1;
2556 if (!HashTable_Insert(gfx->SurfaceTable, (
void*)key, pData))
2557 return ERROR_BAD_ARGUMENTS;
2560 HashTable_Remove(gfx->SurfaceTable, (
void*)key);
2562 return CHANNEL_RC_OK;
2570static UINT rdpgfx_get_surface_ids(RdpgfxClientContext* context, UINT16** ppSurfaceIds,
2573 ULONG_PTR* pKeys =
nullptr;
2574 WINPR_ASSERT(context);
2577 size_t count = HashTable_GetKeys(gfx->SurfaceTable, &pKeys);
2579 WINPR_ASSERT(ppSurfaceIds);
2580 WINPR_ASSERT(count_out);
2584 return CHANNEL_RC_OK;
2587 UINT16* pSurfaceIds = (UINT16*)calloc(count,
sizeof(UINT16));
2591 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
2593 return CHANNEL_RC_NO_MEMORY;
2596 for (
size_t index = 0; index < count; index++)
2598 pSurfaceIds[index] = (UINT16)(pKeys[index] - 1);
2602 *ppSurfaceIds = pSurfaceIds;
2603 *count_out = (UINT16)count;
2604 return CHANNEL_RC_OK;
2607static void* rdpgfx_get_surface_data(RdpgfxClientContext* context, UINT16 surfaceId)
2609 WINPR_ASSERT(context);
2612 ULONG_PTR key = ((ULONG_PTR)surfaceId) + 1;
2613 return HashTable_GetItemValue(gfx->SurfaceTable, (
void*)key);
2621static UINT rdpgfx_set_cache_slot_data(RdpgfxClientContext* context, UINT16 cacheSlot,
void* pData)
2623 WINPR_ASSERT(context);
2628 if (cacheSlot == 0 || cacheSlot > gfx->MaxCacheSlots)
2630 WLog_Print(gfx->base.log, WLOG_ERROR,
2631 "invalid cache slot %" PRIu16
", must be between 1 and %" PRIu16
"", cacheSlot,
2632 gfx->MaxCacheSlots);
2633 return ERROR_INVALID_INDEX;
2636 gfx->CacheSlots[cacheSlot - 1] = pData;
2637 return CHANNEL_RC_OK;
2640static void* rdpgfx_get_cache_slot_data(RdpgfxClientContext* context, UINT16 cacheSlot)
2642 WINPR_ASSERT(context);
2646 if (cacheSlot == 0 || cacheSlot > gfx->MaxCacheSlots)
2648 WLog_Print(gfx->base.log, WLOG_ERROR,
2649 "invalid cache slot %" PRIu16
", must be between 1 and %" PRIu16
"", cacheSlot,
2650 gfx->MaxCacheSlots);
2654 return gfx->CacheSlots[cacheSlot - 1];
2658 WINPR_ATTR_UNUSED rdpSettings* settings)
2663 gfx->rdpcontext = rcontext;
2665 gfx->SurfaceTable = HashTable_New(TRUE);
2666 if (!gfx->SurfaceTable)
2668 WLog_Print(gfx->base.log, WLOG_ERROR,
"HashTable_New for surfaces failed !");
2669 return CHANNEL_RC_NO_MEMORY;
2672 gfx->suspendFrameAcks =
2674 gfx->MaxCacheSlots =
2677 RdpgfxClientContextInt* context =
2678 (RdpgfxClientContextInt*)calloc(1,
sizeof(RdpgfxClientContextInt));
2681 WLog_Print(gfx->base.log, WLOG_ERROR,
"context calloc failed!");
2682 HashTable_Free(gfx->SurfaceTable);
2683 gfx->SurfaceTable =
nullptr;
2684 return CHANNEL_RC_NO_MEMORY;
2687 gfx->zgfx = zgfx_context_new(FALSE);
2690 WLog_Print(gfx->base.log, WLOG_ERROR,
"zgfx_context_new failed!");
2691 HashTable_Free(gfx->SurfaceTable);
2692 gfx->SurfaceTable =
nullptr;
2694 return CHANNEL_RC_NO_MEMORY;
2697 context->common.handle = (
void*)gfx;
2698 context->common.GetSurfaceIds = rdpgfx_get_surface_ids;
2699 context->common.SetSurfaceData = rdpgfx_set_surface_data;
2700 context->common.GetSurfaceData = rdpgfx_get_surface_data;
2701 context->common.SetCacheSlotData = rdpgfx_set_cache_slot_data;
2702 context->common.GetCacheSlotData = rdpgfx_get_cache_slot_data;
2703 context->common.CapsAdvertise = rdpgfx_send_caps_advertise_pdu;
2704 context->common.FrameAcknowledge = rdpgfx_send_frame_acknowledge_pdu;
2705 context->common.CacheImportOffer = rdpgfx_send_cache_import_offer_pdu;
2706 context->common.QoeFrameAcknowledge = rdpgfx_send_qoe_frame_acknowledge_pdu;
2708 gfx->base.iface.pInterface = (
void*)context;
2709 gfx->context = &context->common;
2710 return CHANNEL_RC_OK;
2713void rdpgfx_client_context_free(RdpgfxClientContext* context)
2720 free_surfaces(context, gfx->SurfaceTable);
2721 evict_cache_slots(context, gfx->MaxCacheSlots, gfx->CacheSlots);
2725 zgfx_context_free(gfx->zgfx);
2726 gfx->zgfx =
nullptr;
2729 HashTable_Free(gfx->SurfaceTable);
2733static const IWTSVirtualChannelCallback rdpgfx_callbacks = { rdpgfx_on_data_received,
2734 rdpgfx_on_open, rdpgfx_on_close,
2742FREERDP_ENTRY_POINT(UINT VCAPITYPE rdpgfx_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))
2744 return freerdp_generic_DVCPluginEntry(pEntryPoints, GFXTAG, RDPGFX_DVC_CHANNEL_NAME,
2746 &rdpgfx_callbacks, init_plugin_cb, terminate_plugin_cb);
WINPR_ATTR_NODISCARD FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string 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.