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,
286 RDPGFX_CAPVERSION_115
290 for (
size_t x = 0; x < ARRAYSIZE(capList); x++)
292 if (caps == capList[x])
293 return (filter & (1u << x)) != 0;
303 WINPR_ASSERT(pdu->capsSets);
304 WINPR_ASSERT(count > 0);
305 WINPR_ASSERT(pdu->capsSetCount < count);
306 if (pdu->capsSetCount >= count)
308 return &pdu->capsSets[pdu->capsSetCount++];
318 RDPGFX_CAPSET capsSets[RDPGFX_NUMBER_CAPSETS] = WINPR_C_ARRAY_INIT;
321 return ERROR_BAD_ARGUMENTS;
326 return ERROR_BAD_CONFIGURATION;
328 RdpgfxClientContext* context = gfx->context;
331 return ERROR_BAD_CONFIGURATION;
335 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_8))
337 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
339 return ERROR_BAD_CONFIGURATION;
340 capsSet->version = RDPGFX_CAPVERSION_8;
345 capsSet->flags |= RDPGFX_CAPS_FLAG_THINCLIENT;
352 capsSet->flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE;
355 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_81))
357 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
359 return ERROR_BAD_CONFIGURATION;
360 capsSet->version = RDPGFX_CAPVERSION_81;
365 capsSet->flags |= RDPGFX_CAPS_FLAG_THINCLIENT;
368 capsSet->flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE;
373 capsSet->flags |= RDPGFX_CAPS_FLAG_AVC420_ENABLED;
378 UINT32 caps10Flags = 0;
383 caps10Flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE;
388 caps10Flags |= RDPGFX_CAPS_FLAG_AVC_DISABLED;
391 caps10Flags |= RDPGFX_CAPS_FLAG_AVC_DISABLED;
394 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_10))
396 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
398 return ERROR_BAD_CONFIGURATION;
399 capsSet->version = RDPGFX_CAPVERSION_10;
401 capsSet->flags = caps10Flags;
404 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_101))
406 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
408 return ERROR_BAD_CONFIGURATION;
409 capsSet->version = RDPGFX_CAPVERSION_101;
410 capsSet->length = 0x10;
414 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_102))
416 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
418 return ERROR_BAD_CONFIGURATION;
419 capsSet->version = RDPGFX_CAPVERSION_102;
420 capsSet->length = 0x4;
421 capsSet->flags = caps10Flags;
426 if ((caps10Flags & RDPGFX_CAPS_FLAG_AVC_DISABLED) == 0)
427 caps10Flags |= RDPGFX_CAPS_FLAG_AVC_THINCLIENT;
430 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_103))
432 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
434 return ERROR_BAD_CONFIGURATION;
435 capsSet->version = RDPGFX_CAPVERSION_103;
436 capsSet->length = 0x4;
437 capsSet->flags = caps10Flags & ~RDPGFX_CAPS_FLAG_SMALL_CACHE;
440 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_104))
442 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
444 return ERROR_BAD_CONFIGURATION;
445 capsSet->version = RDPGFX_CAPVERSION_104;
446 capsSet->length = 0x4;
447 capsSet->flags = caps10Flags;
453#if defined(WITH_CAIRO) || defined(WITH_SWSCALE)
454 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_105))
456 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
458 return ERROR_BAD_CONFIGURATION;
459 capsSet->version = RDPGFX_CAPVERSION_105;
460 capsSet->length = 0x4;
461 capsSet->flags = caps10Flags;
464 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_106))
466 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
468 return ERROR_BAD_CONFIGURATION;
469 capsSet->version = RDPGFX_CAPVERSION_106;
470 capsSet->length = 0x4;
471 capsSet->flags = caps10Flags;
474 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_106_ERR))
476 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
478 return ERROR_BAD_CONFIGURATION;
479 capsSet->version = RDPGFX_CAPVERSION_106_ERR;
480 capsSet->length = 0x4;
481 capsSet->flags = caps10Flags;
485 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_107))
487 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
489 return ERROR_BAD_CONFIGURATION;
490 capsSet->version = RDPGFX_CAPVERSION_107;
491 capsSet->length = 0x4;
492 capsSet->flags = caps10Flags;
493#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
494 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
498#if defined(WITH_GFX_AZURE)
499 const UINT32 caps[] = { RDPGFX_CAPVERSION_111, RDPGFX_CAPVERSION_112, RDPGFX_CAPVERSION_113,
500 RDPGFX_CAPVERSION_115 };
502 for (
size_t x = 0; x < ARRAYSIZE(caps); x++)
504 const UINT32 cap = caps[x];
505 if (!rdpgfx_is_capability_filtered(gfx, cap))
507 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
509 return ERROR_BAD_CONFIGURATION;
510 capsSet->version = cap;
511 capsSet->length = 0x4;
512 capsSet->flags = caps10Flags;
513#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
514 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
521#if defined(WITH_GFX_AV1)
524 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_FRDP_1))
526 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
528 return ERROR_BAD_CONFIGURATION;
529 capsSet->version = RDPGFX_CAPVERSION_FRDP_1;
530 capsSet->length = 0x4;
532 capsSet->flags = caps10Flags | RDPGFX_CAPS_FLAG_AV1_I444_SUPPORTED;
533 const UINT32 profile =
536 capsSet->flags |= RDPGFX_CAPS_FLAG_AV1_I444_DISABLED;
538#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
539 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
545 return IFCALLRESULT(ERROR_BAD_CONFIGURATION, context->CapsAdvertise, context, &pdu);
555 WINPR_ASSERT(callback);
559 RdpgfxClientContext* context = gfx->context;
564 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 12))
565 return ERROR_INVALID_DATA;
567 Stream_Read_UINT32(s, capsSet.version);
568 Stream_Read_UINT32(s, capsSet.length);
569 Stream_Read_UINT32(s, capsSet.flags);
570 gfx->TotalDecodedFrames = 0;
571 gfx->ConnectionCaps = capsSet;
572 WLog_Print(gfx->base.log, WLOG_DEBUG,
573 "RecvCapsConfirmPdu: version: %s [0x%08" PRIX32
"] flags: 0x%08" PRIX32
"",
574 rdpgfx_caps_version_str(capsSet.version), capsSet.version, capsSet.flags);
577 return ERROR_BAD_CONFIGURATION;
579 return IFCALLRESULT(CHANNEL_RC_OK, context->CapsConfirm, context, &pdu);
587static UINT rdpgfx_send_frame_acknowledge_pdu(RdpgfxClientContext* context,
592 if (!context || !pdu)
593 return ERROR_BAD_ARGUMENTS;
597 if (!gfx || !gfx->base.listener_callback)
598 return ERROR_BAD_CONFIGURATION;
603 return ERROR_BAD_CONFIGURATION;
606 .cmdId = RDPGFX_CMDID_FRAMEACKNOWLEDGE,
607 .pduLength = RDPGFX_HEADER_SIZE + 12 };
609 WLog_Print(gfx->base.log, WLOG_TRACE,
"SendFrameAcknowledgePdu: %" PRIu32
"", pdu->frameId);
611 wStream* s = Stream_New(
nullptr, header.pduLength);
615 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
616 return CHANNEL_RC_NO_MEMORY;
619 if ((error = rdpgfx_write_header(s, &header)))
623 Stream_Write_UINT32(s, pdu->queueDepth);
624 Stream_Write_UINT32(s, pdu->frameId);
625 Stream_Write_UINT32(s, pdu->totalFramesDecoded);
626 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
629 if (error == CHANNEL_RC_OK)
630 gfx->UnacknowledgedFrames--;
633 Stream_Free(s, TRUE);
637static UINT rdpgfx_send_qoe_frame_acknowledge_pdu(RdpgfxClientContext* context,
640 UINT error = CHANNEL_RC_OK;
642 .cmdId = RDPGFX_CMDID_QOEFRAMEACKNOWLEDGE,
643 .pduLength = RDPGFX_HEADER_SIZE + 12 };
645 if (!context || !pdu)
646 return ERROR_BAD_ARGUMENTS;
650 if (!gfx || !gfx->base.listener_callback)
651 return ERROR_BAD_CONFIGURATION;
656 return ERROR_BAD_CONFIGURATION;
658 WLog_Print(gfx->base.log, WLOG_TRACE,
"SendQoeFrameAcknowledgePdu: %" PRIu32
"", pdu->frameId);
659 wStream* s = Stream_New(
nullptr, header.pduLength);
663 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
664 return CHANNEL_RC_NO_MEMORY;
667 if ((error = rdpgfx_write_header(s, &header)))
671 Stream_Write_UINT32(s, pdu->frameId);
672 Stream_Write_UINT32(s, pdu->timestamp);
673 Stream_Write_UINT16(s, pdu->timeDiffSE);
674 Stream_Write_UINT16(s, pdu->timeDiffEDR);
675 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
678 Stream_Free(s, TRUE);
690 WINPR_ASSERT(callback);
696 RdpgfxClientContext* context = gfx->context;
697 UINT error = CHANNEL_RC_OK;
698 GraphicsResetEventArgs graphicsReset = WINPR_C_ARRAY_INIT;
700 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 12))
701 return ERROR_INVALID_DATA;
703 Stream_Read_UINT32(s, pdu.width);
704 Stream_Read_UINT32(s, pdu.height);
705 Stream_Read_UINT32(s, pdu.monitorCount);
707 if ((pdu.width == 0) || (pdu.height == 0) || (pdu.monitorCount == 0))
709 WLog_Print(gfx->base.log, WLOG_ERROR,
710 "context->ResetGraphics Width[%" PRIu32
"], Height[%" PRIu32
711 "] or monitorCount[%" PRIu32
" is 0",
712 pdu.width, pdu.height, pdu.monitorCount);
713 return ERROR_INVALID_DATA;
715 if ((pdu.width > MAX_SURFACE_SIZE) || (pdu.height > MAX_SURFACE_SIZE) ||
716 (pdu.monitorCount > MAX_MONITOR_COUNT))
718 WLog_Print(gfx->base.log, WLOG_ERROR,
719 "context->ResetGraphics Width[%" PRIu32
"], Height[%" PRIu32
"] > %" PRIu32
720 " or monitorCount[%" PRIu32
" > %" PRIu32,
721 pdu.width, pdu.height, MAX_SURFACE_SIZE, pdu.monitorCount, MAX_MONITOR_COUNT);
722 return ERROR_INVALID_DATA;
725 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.monitorCount, 20ull))
726 return ERROR_INVALID_DATA;
730 if (!pdu.monitorDefArray)
732 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
733 return CHANNEL_RC_NO_MEMORY;
736 for (UINT32 index = 0; index < pdu.monitorCount; index++)
738 MONITOR_DEF* monitor = &(pdu.monitorDefArray[index]);
739 Stream_Read_INT32(s, monitor->left);
740 Stream_Read_INT32(s, monitor->top);
741 Stream_Read_INT32(s, monitor->right);
742 Stream_Read_INT32(s, monitor->bottom);
743 Stream_Read_UINT32(s, monitor->flags);
746 const size_t size = (RDPGFX_HEADER_SIZE + 12ULL + (pdu.monitorCount * 20ULL));
749 free(pdu.monitorDefArray);
750 return CHANNEL_RC_NULL_DATA;
752 const size_t pad = 340ULL - size;
754 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, (
size_t)pad))
756 free(pdu.monitorDefArray);
757 return CHANNEL_RC_NO_MEMORY;
761 WLog_Print(gfx->base.log, WLOG_DEBUG,
762 "RecvResetGraphicsPdu: width: %" PRIu32
" height: %" PRIu32
" count: %" PRIu32
"",
763 pdu.width, pdu.height, pdu.monitorCount);
765 for (UINT32 index = 0; index < pdu.monitorCount; index++)
767 MONITOR_DEF* monitor = &(pdu.monitorDefArray[index]);
768 WLog_Print(gfx->base.log, WLOG_TRACE,
769 "RecvResetGraphicsPdu: monitor left:%" PRIi32
" top:%" PRIi32
" right:%" PRIi32
770 " bottom:%" PRIi32
" flags:0x%" PRIx32
"",
771 monitor->left, monitor->top, monitor->right, monitor->bottom, monitor->flags);
776 IFCALLRET(context->ResetGraphics, error, context, &pdu);
779 WLog_Print(gfx->base.log, WLOG_ERROR,
780 "context->ResetGraphics failed with error %" PRIu32
"", error);
783 free(pdu.monitorDefArray);
786 if (error == CHANNEL_RC_OK)
788 EventArgsInit(&graphicsReset,
"libfreerdp");
789 graphicsReset.width = pdu.width;
790 graphicsReset.height = pdu.height;
791 if (PubSub_OnGraphicsReset(gfx->rdpcontext->pubSub, gfx->rdpcontext, &graphicsReset) < 0)
792 return ERROR_INTERNAL_ERROR;
805 WINPR_ASSERT(callback);
808 RdpgfxClientContext* context = gfx->context;
809 UINT error = CHANNEL_RC_OK;
811 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 2))
812 return ERROR_INVALID_DATA;
814 Stream_Read_UINT16(s, pdu.cacheSlot);
815 WLog_Print(gfx->base.log, WLOG_DEBUG,
"RecvEvictCacheEntryPdu: cacheSlot: %" PRIu16
"",
820 IFCALLRET(context->EvictCacheEntry, error, context, &pdu);
823 WLog_Print(gfx->base.log, WLOG_ERROR,
824 "context->EvictCacheEntry failed with error %" PRIu32
"", error);
837 UINT error = CHANNEL_RC_OK;
840 WINPR_ASSERT(gfx->rdpcontext);
841 rdpSettings* settings = gfx->rdpcontext->settings;
842 RdpgfxClientContext* context = gfx->context;
844 WINPR_ASSERT(context);
845 WINPR_ASSERT(settings);
848 return CHANNEL_RC_OK;
850 const char* BitmapCachePersistFile =
852 if (!BitmapCachePersistFile)
853 return CHANNEL_RC_OK;
855 if (!context->ExportCacheEntry)
856 return CHANNEL_RC_INITIALIZATION_ERROR;
858 rdpPersistentCache* persistent = persistent_cache_new();
861 return CHANNEL_RC_NO_MEMORY;
863 if (persistent_cache_open(persistent, BitmapCachePersistFile, TRUE, 3) < 1)
865 error = CHANNEL_RC_INITIALIZATION_ERROR;
869 for (UINT16 idx = 0; idx < gfx->MaxCacheSlots; idx++)
871 if (gfx->CacheSlots[idx])
873 const UINT16 cacheSlot = idx;
876 if (context->ExportCacheEntry(context, cacheSlot, &cacheEntry) != CHANNEL_RC_OK)
879 if (persistent_cache_write_entry(persistent, &cacheEntry) < 0)
884 persistent_cache_free(persistent);
888 persistent_cache_free(persistent);
897static UINT rdpgfx_send_cache_import_offer_pdu(RdpgfxClientContext* context,
900 UINT error = CHANNEL_RC_OK;
902 if (!context || !pdu)
903 return ERROR_BAD_ARGUMENTS;
907 if (!gfx || !gfx->base.listener_callback)
908 return ERROR_BAD_CONFIGURATION;
913 return ERROR_BAD_CONFIGURATION;
916 .cmdId = RDPGFX_CMDID_CACHEIMPORTOFFER,
918 RDPGFX_HEADER_SIZE + 2ul + pdu->cacheEntriesCount * 12ul };
920 WLog_Print(gfx->base.log, WLOG_DEBUG,
"SendCacheImportOfferPdu: cacheEntriesCount: %" PRIu16
"",
921 pdu->cacheEntriesCount);
922 wStream* s = Stream_New(
nullptr, header.pduLength);
926 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
927 return CHANNEL_RC_NO_MEMORY;
930 if ((error = rdpgfx_write_header(s, &header)))
933 if (pdu->cacheEntriesCount <= 0)
935 WLog_Print(gfx->base.log, WLOG_ERROR,
"Invalid cacheEntriesCount: %" PRIu16
"",
936 pdu->cacheEntriesCount);
937 error = ERROR_INVALID_DATA;
942 Stream_Write_UINT16(s, pdu->cacheEntriesCount);
944 for (UINT16 index = 0; index < pdu->cacheEntriesCount; index++)
947 Stream_Write_UINT64(s, cacheEntry->cacheKey);
948 Stream_Write_UINT32(s, cacheEntry->bitmapLength);
951 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
955 Stream_Free(s, TRUE);
967 UINT error = CHANNEL_RC_OK;
972 WINPR_ASSERT(gfx->rdpcontext);
974 RdpgfxClientContext* context = gfx->context;
975 rdpSettings* settings = gfx->rdpcontext->settings;
978 return CHANNEL_RC_OK;
980 const char* BitmapCachePersistFile =
982 if (!BitmapCachePersistFile)
983 return CHANNEL_RC_OK;
985 rdpPersistentCache* persistent = persistent_cache_new();
988 return CHANNEL_RC_NO_MEMORY;
990 if (persistent_cache_open(persistent, BitmapCachePersistFile, FALSE, 3) < 1)
992 error = CHANNEL_RC_INITIALIZATION_ERROR;
996 if (persistent_cache_get_version(persistent) != 3)
998 error = ERROR_INVALID_DATA;
1002 count = persistent_cache_get_count(persistent);
1005 error = ERROR_INVALID_DATA;
1009 if (count >= RDPGFX_CACHE_ENTRY_MAX_COUNT)
1010 count = RDPGFX_CACHE_ENTRY_MAX_COUNT - 1;
1012 if (count > gfx->MaxCacheSlots)
1013 count = gfx->MaxCacheSlots;
1018 error = CHANNEL_RC_NO_MEMORY;
1022 WINPR_ASSERT(count <= UINT16_MAX);
1023 offer->cacheEntriesCount = (UINT16)count;
1025 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Sending Cache Import Offer: %d", count);
1027 for (
int idx = 0; idx < count; idx++)
1029 if (persistent_cache_read_entry(persistent, &entry) < 1)
1031 error = ERROR_INVALID_DATA;
1035 offer->cacheEntries[idx].cacheKey = entry.key64;
1036 offer->cacheEntries[idx].bitmapLength = entry.size;
1039 if (offer->cacheEntriesCount > 0)
1041 error = rdpgfx_send_cache_import_offer_pdu(context, offer);
1042 if (error != CHANNEL_RC_OK)
1044 WLog_Print(gfx->base.log, WLOG_ERROR,
"Failed to send cache import offer PDU");
1050 persistent_cache_free(persistent);
1060static UINT rdpgfx_load_cache_import_reply(
RDPGFX_PLUGIN* gfx,
1063 UINT error = CHANNEL_RC_OK;
1064 rdpPersistentCache* persistent =
nullptr;
1066 WINPR_ASSERT(gfx->rdpcontext);
1067 rdpSettings* settings = gfx->rdpcontext->settings;
1068 RdpgfxClientContext* context = gfx->context;
1070 WINPR_ASSERT(settings);
1071 WINPR_ASSERT(reply);
1073 return CHANNEL_RC_OK;
1075 const char* BitmapCachePersistFile =
1077 if (!BitmapCachePersistFile)
1078 return CHANNEL_RC_OK;
1080 persistent = persistent_cache_new();
1083 return CHANNEL_RC_NO_MEMORY;
1085 if (persistent_cache_open(persistent, BitmapCachePersistFile, FALSE, 3) < 1)
1087 error = CHANNEL_RC_INITIALIZATION_ERROR;
1091 if (persistent_cache_get_version(persistent) != 3)
1093 error = ERROR_INVALID_DATA;
1097 int count = persistent_cache_get_count(persistent);
1099 count = (count < reply->importedEntriesCount) ? count : reply->importedEntriesCount;
1101 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Receiving Cache Import Reply: %d", count);
1103 for (
int idx = 0; idx < count; idx++)
1106 if (persistent_cache_read_entry(persistent, &entry) < 1)
1108 error = ERROR_INVALID_DATA;
1112 const UINT16 cacheSlot = reply->cacheSlots[idx];
1113 if (context && context->ImportCacheEntry)
1115 error = context->ImportCacheEntry(context, cacheSlot, &entry);
1116 if (error != CHANNEL_RC_OK)
1121 persistent_cache_free(persistent);
1125 persistent_cache_free(persistent);
1137 WINPR_ASSERT(callback);
1140 RdpgfxClientContext* context = gfx->context;
1141 UINT error = CHANNEL_RC_OK;
1143 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 2))
1144 return ERROR_INVALID_DATA;
1146 Stream_Read_UINT16(s, pdu.importedEntriesCount);
1148 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.importedEntriesCount,
1150 return ERROR_INVALID_DATA;
1152 if (pdu.importedEntriesCount > RDPGFX_CACHE_ENTRY_MAX_COUNT)
1153 return ERROR_INVALID_DATA;
1155 for (UINT16 idx = 0; idx < pdu.importedEntriesCount; idx++)
1157 Stream_Read_UINT16(s, pdu.cacheSlots[idx]);
1160 WLog_Print(gfx->base.log, WLOG_TRACE,
1161 "RecvCacheImportReplyPdu: importedEntriesCount: %" PRIu16
"",
1162 pdu.importedEntriesCount);
1164 error = rdpgfx_load_cache_import_reply(gfx, &pdu);
1168 WLog_Print(gfx->base.log, WLOG_ERROR,
1169 "rdpgfx_load_cache_import_reply failed with error %" PRIu32
"", error);
1175 IFCALLRET(context->CacheImportReply, error, context, &pdu);
1178 WLog_Print(gfx->base.log, WLOG_ERROR,
1179 "context->CacheImportReply failed with error %" PRIu32
"", error);
1193 WINPR_ASSERT(callback);
1196 RdpgfxClientContext* context = gfx->context;
1197 UINT error = CHANNEL_RC_OK;
1199 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 7))
1200 return ERROR_INVALID_DATA;
1202 Stream_Read_UINT16(s, pdu.surfaceId);
1203 Stream_Read_UINT16(s, pdu.width);
1204 Stream_Read_UINT16(s, pdu.height);
1205 Stream_Read_UINT8(s, pdu.pixelFormat);
1207 if ((pdu.width == 0) || (pdu.height == 0))
1209 WLog_Print(gfx->base.log, WLOG_ERROR,
1210 "context->RecvCreateSurfacePdu Width[%" PRIu32
"], Height[%" PRIu32
"] is 0",
1211 pdu.width, pdu.height);
1212 return ERROR_INVALID_DATA;
1214 if ((pdu.width > MAX_SURFACE_SIZE) || (pdu.height > MAX_SURFACE_SIZE))
1216 WLog_Print(gfx->base.log, WLOG_ERROR,
1217 "context->RecvCreateSurfacePdu Width[%" PRIu32
"], Height[%" PRIu32
1219 pdu.width, pdu.height, MAX_SURFACE_SIZE);
1220 return ERROR_INVALID_DATA;
1223 WLog_Print(gfx->base.log, WLOG_DEBUG,
1224 "RecvCreateSurfacePdu: surfaceId: %" PRIu16
" width: %" PRIu16
" height: %" PRIu16
1225 " pixelFormat: 0x%02" PRIX8
"",
1226 pdu.surfaceId, pdu.width, pdu.height, pdu.pixelFormat);
1235 const UINT drc = IFCALLRESULT(CHANNEL_RC_OK, context->DeleteSurface, context, &deletePdu);
1236 if (drc != CHANNEL_RC_OK)
1237 WLog_Print(gfx->base.log, WLOG_WARN,
1238 "context->DeleteSurface failed with error %" PRIu32
", ignoring", drc);
1240 IFCALLRET(context->CreateSurface, error, context, &pdu);
1243 WLog_Print(gfx->base.log, WLOG_ERROR,
1244 "context->CreateSurface failed with error %" PRIu32
"", error);
1258 WINPR_ASSERT(callback);
1261 RdpgfxClientContext* context = gfx->context;
1262 UINT error = CHANNEL_RC_OK;
1264 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 2))
1265 return ERROR_INVALID_DATA;
1267 Stream_Read_UINT16(s, pdu.surfaceId);
1268 WLog_Print(gfx->base.log, WLOG_DEBUG,
"RecvDeleteSurfacePdu: surfaceId: %" PRIu16
"",
1273 IFCALLRET(context->DeleteSurface, error, context, &pdu);
1276 WLog_Print(gfx->base.log, WLOG_ERROR,
1277 "context->DeleteSurface failed with error %" PRIu32
"", error);
1291 WINPR_ASSERT(callback);
1294 RdpgfxClientContext* context = gfx->context;
1295 UINT error = CHANNEL_RC_OK;
1297 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_START_FRAME_PDU_SIZE))
1298 return ERROR_INVALID_DATA;
1300 Stream_Read_UINT32(s, pdu.timestamp);
1301 Stream_Read_UINT32(s, pdu.frameId);
1302 WLog_Print(gfx->base.log, WLOG_TRACE,
1303 "RecvStartFramePdu: frameId: %" PRIu32
" timestamp: 0x%08" PRIX32
"", pdu.frameId,
1305 gfx->StartDecodingTime = GetTickCount64();
1309 IFCALLRET(context->StartFrame, error, context, &pdu);
1312 WLog_Print(gfx->base.log, WLOG_ERROR,
1313 "context->StartFrame failed with error %" PRIu32
"", error);
1316 gfx->UnacknowledgedFrames++;
1329 WINPR_ASSERT(callback);
1332 RdpgfxClientContext* context = gfx->context;
1333 UINT error = CHANNEL_RC_OK;
1335 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_END_FRAME_PDU_SIZE))
1336 return ERROR_INVALID_DATA;
1338 Stream_Read_UINT32(s, pdu.frameId);
1339 WLog_Print(gfx->base.log, WLOG_TRACE,
"RecvEndFramePdu: frameId: %" PRIu32
"", pdu.frameId);
1341 const UINT64 start = GetTickCount64();
1344 IFCALLRET(context->EndFrame, error, context, &pdu);
1348 WLog_Print(gfx->base.log, WLOG_ERROR,
"context->EndFrame failed with error %" PRIu32
"",
1353 const UINT64 end = GetTickCount64();
1354 const UINT64 EndFrameTime = end - start;
1355 gfx->TotalDecodedFrames++;
1357 if (!gfx->sendFrameAcks)
1360 ack.frameId = pdu.frameId;
1361 ack.totalFramesDecoded = gfx->TotalDecodedFrames;
1363 if (gfx->suspendFrameAcks)
1365 ack.queueDepth = SUSPEND_FRAME_ACKNOWLEDGEMENT;
1367 if (gfx->TotalDecodedFrames == 1)
1368 if ((error = rdpgfx_send_frame_acknowledge_pdu(context, &ack)))
1369 WLog_Print(gfx->base.log, WLOG_ERROR,
1370 "rdpgfx_send_frame_acknowledge_pdu failed with error %" PRIu32
"",
1375 ack.queueDepth = QUEUE_DEPTH_UNAVAILABLE;
1377 if ((error = rdpgfx_send_frame_acknowledge_pdu(context, &ack)))
1378 WLog_Print(gfx->base.log, WLOG_ERROR,
1379 "rdpgfx_send_frame_acknowledge_pdu failed with error %" PRIu32
"", error);
1382 switch (gfx->ConnectionCaps.version)
1384#if defined(WITH_GFX_AV1)
1385 case RDPGFX_CAPVERSION_FRDP_1:
1387 case RDPGFX_CAPVERSION_10:
1388 case RDPGFX_CAPVERSION_102:
1389 case RDPGFX_CAPVERSION_103:
1390 case RDPGFX_CAPVERSION_104:
1391 case RDPGFX_CAPVERSION_105:
1392 case RDPGFX_CAPVERSION_106:
1393 case RDPGFX_CAPVERSION_106_ERR:
1394 case RDPGFX_CAPVERSION_107:
1395#if defined(WITH_GFX_AZURE)
1396 case RDPGFX_CAPVERSION_111:
1397 case RDPGFX_CAPVERSION_112:
1398 case RDPGFX_CAPVERSION_113:
1399 case RDPGFX_CAPVERSION_115:
1404 UINT64 diff = (GetTickCount64() - gfx->StartDecodingTime);
1409 qoe.frameId = pdu.frameId;
1410 qoe.timestamp = gfx->StartDecodingTime % UINT32_MAX;
1411 qoe.timeDiffSE = WINPR_ASSERTING_INT_CAST(UINT16, diff);
1412 qoe.timeDiffEDR = WINPR_ASSERTING_INT_CAST(UINT16, EndFrameTime);
1414 if ((error = rdpgfx_send_qoe_frame_acknowledge_pdu(context, &qoe)))
1415 WLog_Print(gfx->base.log, WLOG_ERROR,
1416 "rdpgfx_send_qoe_frame_acknowledge_pdu failed with error %" PRIu32
1439 WINPR_ASSERT(callback);
1444 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_WIRE_TO_SURFACE_PDU_1_SIZE))
1445 return ERROR_INVALID_DATA;
1447 Stream_Read_UINT16(s, pdu.surfaceId);
1448 Stream_Read_UINT16(s, pdu.codecId);
1449 Stream_Read_UINT8(s, pdu.pixelFormat);
1451 if ((error = rdpgfx_read_rect16(gfx->base.log, s, &(pdu.destRect))))
1453 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_rect16 failed with error %" PRIu32
"",
1458 Stream_Read_UINT32(s, pdu.bitmapDataLength);
1460 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, pdu.bitmapDataLength))
1461 return ERROR_INVALID_DATA;
1463 pdu.bitmapData = Stream_Pointer(s);
1464 Stream_Seek(s, pdu.bitmapDataLength);
1466 WLog_Print(gfx->base.log, WLOG_TRACE,
1467 "RecvWireToSurface1Pdu: surfaceId: %" PRIu16
" codecId: %s (0x%04" PRIX16
1468 ") pixelFormat: 0x%02" PRIX8
" "
1469 "destRect: left: %" PRIu16
" top: %" PRIu16
" right: %" PRIu16
" bottom: %" PRIu16
1470 " bitmapDataLength: %" PRIu32
"",
1471 pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId, pdu.pixelFormat,
1472 pdu.destRect.left, pdu.destRect.top, pdu.destRect.right, pdu.destRect.bottom,
1473 pdu.bitmapDataLength);
1474 cmd.surfaceId = pdu.surfaceId;
1475 cmd.codecId = pdu.codecId;
1478 switch (pdu.pixelFormat)
1480 case GFX_PIXEL_FORMAT_XRGB_8888:
1481 cmd.format = PIXEL_FORMAT_BGRX32;
1484 case GFX_PIXEL_FORMAT_ARGB_8888:
1485 cmd.format = PIXEL_FORMAT_BGRA32;
1489 return ERROR_INVALID_DATA;
1492 cmd.left = pdu.destRect.left;
1493 cmd.top = pdu.destRect.top;
1494 cmd.right = pdu.destRect.right;
1495 cmd.bottom = pdu.destRect.bottom;
1496 cmd.width = cmd.right - cmd.left;
1497 cmd.height = cmd.bottom - cmd.top;
1498 cmd.length = pdu.bitmapDataLength;
1499 cmd.data = pdu.bitmapData;
1500 cmd.extra =
nullptr;
1502 if (cmd.right < cmd.left)
1504 WLog_Print(gfx->base.log, WLOG_ERROR,
1505 "RecvWireToSurface1Pdu right=%" PRIu32
" < left=%" PRIu32, cmd.right, cmd.left);
1506 return ERROR_INVALID_DATA;
1508 if (cmd.bottom < cmd.top)
1510 WLog_Print(gfx->base.log, WLOG_ERROR,
1511 "RecvWireToSurface1Pdu bottom=%" PRIu32
" < top=%" PRIu32, cmd.bottom, cmd.top);
1512 return ERROR_INVALID_DATA;
1515 if ((error = rdpgfx_decode(gfx, &cmd)))
1516 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_decode failed with error %" PRIu32
"!",
1525 switch (cmd->codecId)
1527 case RDPGFX_CODECID_UNCOMPRESSED:
1528 case RDPGFX_CODECID_CAVIDEO:
1529 case RDPGFX_CODECID_CLEARCODEC:
1530 case RDPGFX_CODECID_PLANAR:
1531 case RDPGFX_CODECID_AVC420:
1532 case RDPGFX_CODECID_ALPHA:
1533 case RDPGFX_CODECID_AVC444:
1534 case RDPGFX_CODECID_AVC444v2:
1535 case RDPGFX_CODECID_CAPROGRESSIVE:
1536 case RDPGFX_CODECID_CAPROGRESSIVE_V2:
1538#if defined(WITH_GFX_AV1)
1539 case RDPGFX_CODECID_AV1:
1540 if (gfx->ConnectionCaps.version != RDPGFX_CAPVERSION_FRDP_1)
1542 WLog_Print(gfx->base.log, WLOG_ERROR,
1543 "RDPGFX_SURFACE_COMMAND::codecId %" PRIu32
1544 " only supported with %s but connection uses %s [0x%08" PRIx32
"]",
1545 cmd->codecId, rdpgfx_caps_version_str(RDPGFX_CAPVERSION_FRDP_1),
1546 rdpgfx_caps_version_str(gfx->ConnectionCaps.version),
1547 gfx->ConnectionCaps.version);
1553 WLog_Print(gfx->base.log, WLOG_ERROR,
1554 "Unknown RDPGFX_SURFACE_COMMAND::codecId %" PRIu32, cmd->codecId);
1563 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Got GFX %s",
1564 rdpgfx_get_codec_id_string(WINPR_ASSERTING_INT_CAST(UINT16, cmd->codecId)));
1566 RdpgfxClientContext* context = gfx->context;
1568 return CHANNEL_RC_OK;
1570 if (!checkSurfaceCommand(gfx, cmd))
1571 return CHANNEL_RC_NULL_DATA;
1573 const UINT error = IFCALLRESULT(CHANNEL_RC_OK, context->SurfaceCommand, context, cmd);
1576 WLog_Print(gfx->base.log, WLOG_ERROR,
1577 "context->SurfaceCommand failed with error %" PRIu32
"", error);
1579 rdpgfx_codecid_event(context, cmd->codecId);
1593 WINPR_ASSERT(callback);
1597 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_WIRE_TO_SURFACE_PDU_2_SIZE))
1598 return ERROR_INVALID_DATA;
1600 Stream_Read_UINT16(s, pdu.surfaceId);
1601 Stream_Read_UINT16(s, pdu.codecId);
1602 Stream_Read_UINT32(s, pdu.codecContextId);
1603 Stream_Read_UINT8(s, pdu.pixelFormat);
1604 Stream_Read_UINT32(s, pdu.bitmapDataLength);
1605 pdu.bitmapData = Stream_Pointer(s);
1606 if (!Stream_SafeSeek(s, pdu.bitmapDataLength))
1607 return ERROR_INVALID_DATA;
1609 WLog_Print(gfx->base.log, WLOG_TRACE,
1610 "RecvWireToSurface2Pdu: surfaceId: %" PRIu16
" codecId: %s (0x%04" PRIX16
") "
1611 "codecContextId: %" PRIu32
" pixelFormat: 0x%02" PRIX8
" bitmapDataLength: %" PRIu32
1613 pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId,
1614 pdu.codecContextId, pdu.pixelFormat, pdu.bitmapDataLength);
1616 cmd.surfaceId = pdu.surfaceId;
1617 cmd.codecId = pdu.codecId;
1618 cmd.contextId = pdu.codecContextId;
1620 switch (pdu.pixelFormat)
1622 case GFX_PIXEL_FORMAT_XRGB_8888:
1623 cmd.format = PIXEL_FORMAT_BGRX32;
1626 case GFX_PIXEL_FORMAT_ARGB_8888:
1627 cmd.format = PIXEL_FORMAT_BGRA32;
1631 return ERROR_INVALID_DATA;
1634 cmd.length = pdu.bitmapDataLength;
1635 cmd.data = pdu.bitmapData;
1636 cmd.extra =
nullptr;
1638 if (cmd.codecId != RDPGFX_CODECID_CAPROGRESSIVE)
1639 return ERROR_INVALID_DATA;
1641 return logSurfaceCommand(gfx, &cmd);
1652 WINPR_ASSERT(callback);
1655 RdpgfxClientContext* context = gfx->context;
1656 UINT error = CHANNEL_RC_OK;
1658 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 6))
1659 return ERROR_INVALID_DATA;
1661 Stream_Read_UINT16(s, pdu.surfaceId);
1662 Stream_Read_UINT32(s, pdu.codecContextId);
1664 WLog_Print(gfx->base.log, WLOG_DEBUG,
1665 "RecvDeleteEncodingContextPdu: surfaceId: %" PRIu16
" codecContextId: %" PRIu32
"",
1666 pdu.surfaceId, pdu.codecContextId);
1670 IFCALLRET(context->DeleteEncodingContext, error, context, &pdu);
1673 WLog_Print(gfx->base.log, WLOG_ERROR,
1674 "context->DeleteEncodingContext failed with error %" PRIu32
"", error);
1688 WINPR_ASSERT(callback);
1691 RdpgfxClientContext* context = gfx->context;
1693 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 8))
1694 return ERROR_INVALID_DATA;
1696 Stream_Read_UINT16(s, pdu.surfaceId);
1698 UINT error = rdpgfx_read_color32(gfx->base.log, s, &(pdu.fillPixel));
1699 if (error != CHANNEL_RC_OK)
1701 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_color32 failed with error %" PRIu32
"!",
1706 Stream_Read_UINT16(s, pdu.fillRectCount);
1708 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.fillRectCount, 8ull))
1709 return ERROR_INVALID_DATA;
1715 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
1716 return CHANNEL_RC_NO_MEMORY;
1719 for (UINT16 index = 0; index < pdu.fillRectCount; index++)
1723 if ((error = rdpgfx_read_rect16(gfx->base.log, s, fillRect)))
1725 WLog_Print(gfx->base.log, WLOG_ERROR,
1726 "rdpgfx_read_rect16 failed with error %" PRIu32
"!", error);
1727 free(pdu.fillRects);
1731 WLog_Print(gfx->base.log, WLOG_TRACE,
1732 "RecvSolidFillPdu: surfaceId: %" PRIu16
" fillRectCount: %" PRIu16
"", pdu.surfaceId,
1737 IFCALLRET(context->SolidFill, error, context, &pdu);
1740 WLog_Print(gfx->base.log, WLOG_ERROR,
1741 "context->SolidFill failed with error %" PRIu32
"", error);
1744 free(pdu.fillRects);
1756 WINPR_ASSERT(callback);
1759 RdpgfxClientContext* context = gfx->context;
1762 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 14))
1763 return ERROR_INVALID_DATA;
1765 Stream_Read_UINT16(s, pdu.surfaceIdSrc);
1766 Stream_Read_UINT16(s, pdu.surfaceIdDest);
1768 if ((error = rdpgfx_read_rect16(gfx->base.log, s, &(pdu.rectSrc))))
1770 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_rect16 failed with error %" PRIu32
"!",
1775 Stream_Read_UINT16(s, pdu.destPtsCount);
1777 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.destPtsCount, 4ull))
1778 return ERROR_INVALID_DATA;
1784 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
1785 return CHANNEL_RC_NO_MEMORY;
1788 for (UINT16 index = 0; index < pdu.destPtsCount; index++)
1792 if ((error = rdpgfx_read_point16(gfx->base.log, s, destPt)))
1794 WLog_Print(gfx->base.log, WLOG_ERROR,
1795 "rdpgfx_read_point16 failed with error %" PRIu32
"!", error);
1801 WLog_Print(gfx->base.log, WLOG_TRACE,
1802 "RecvSurfaceToSurfacePdu: surfaceIdSrc: %" PRIu16
" surfaceIdDest: %" PRIu16
" "
1803 "left: %" PRIu16
" top: %" PRIu16
" right: %" PRIu16
" bottom: %" PRIu16
1804 " destPtsCount: %" PRIu16
"",
1805 pdu.surfaceIdSrc, pdu.surfaceIdDest, pdu.rectSrc.left, pdu.rectSrc.top,
1806 pdu.rectSrc.right, pdu.rectSrc.bottom, pdu.destPtsCount);
1810 IFCALLRET(context->SurfaceToSurface, error, context, &pdu);
1813 WLog_Print(gfx->base.log, WLOG_ERROR,
1814 "context->SurfaceToSurface failed with error %" PRIu32
"", error);
1829 WINPR_ASSERT(callback);
1833 RdpgfxClientContext* context = gfx->context;
1835 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 20))
1836 return ERROR_INVALID_DATA;
1838 Stream_Read_UINT16(s, pdu.surfaceId);
1839 Stream_Read_UINT64(s, pdu.cacheKey);
1840 Stream_Read_UINT16(s, pdu.cacheSlot);
1842 UINT error = rdpgfx_read_rect16(gfx->base.log, s, &(pdu.rectSrc));
1843 if (error != CHANNEL_RC_OK)
1845 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_rect16 failed with error %" PRIu32
"!",
1850 WLog_Print(gfx->base.log, WLOG_TRACE,
1851 "RecvSurfaceToCachePdu: surfaceId: %" PRIu16
" cacheKey: 0x%016" PRIX64
1852 " cacheSlot: %" PRIu16
" "
1853 "left: %" PRIu16
" top: %" PRIu16
" right: %" PRIu16
" bottom: %" PRIu16
"",
1854 pdu.surfaceId, pdu.cacheKey, pdu.cacheSlot, pdu.rectSrc.left, pdu.rectSrc.top,
1855 pdu.rectSrc.right, pdu.rectSrc.bottom);
1859 IFCALLRET(context->SurfaceToCache, error, context, &pdu);
1862 WLog_Print(gfx->base.log, WLOG_ERROR,
1863 "context->SurfaceToCache failed with error %" PRIu32
"", error);
1877 WINPR_ASSERT(callback);
1881 RdpgfxClientContext* context = gfx->context;
1882 UINT error = CHANNEL_RC_OK;
1884 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 6))
1885 return ERROR_INVALID_DATA;
1887 Stream_Read_UINT16(s, pdu.cacheSlot);
1888 Stream_Read_UINT16(s, pdu.surfaceId);
1889 Stream_Read_UINT16(s, pdu.destPtsCount);
1891 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.destPtsCount, 4ull))
1892 return ERROR_INVALID_DATA;
1898 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
1899 return CHANNEL_RC_NO_MEMORY;
1902 for (UINT16 index = 0; index < pdu.destPtsCount; index++)
1906 if ((error = rdpgfx_read_point16(gfx->base.log, s, destPt)))
1908 WLog_Print(gfx->base.log, WLOG_ERROR,
1909 "rdpgfx_read_point16 failed with error %" PRIu32
"", error);
1915 WLog_Print(gfx->base.log, WLOG_TRACE,
1916 "RdpGfxRecvCacheToSurfacePdu: cacheSlot: %" PRIu16
" surfaceId: %" PRIu16
1917 " destPtsCount: %" PRIu16
"",
1918 pdu.cacheSlot, pdu.surfaceId, pdu.destPtsCount);
1922 IFCALLRET(context->CacheToSurface, error, context, &pdu);
1925 WLog_Print(gfx->base.log, WLOG_ERROR,
1926 "context->CacheToSurface failed with error %" PRIu32
"", error);
1941 WINPR_ASSERT(callback);
1945 RdpgfxClientContext* context = gfx->context;
1946 UINT error = CHANNEL_RC_OK;
1948 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 12))
1949 return ERROR_INVALID_DATA;
1951 Stream_Read_UINT16(s, pdu.surfaceId);
1952 Stream_Read_UINT16(s, pdu.reserved);
1953 Stream_Read_UINT32(s, pdu.outputOriginX);
1954 Stream_Read_UINT32(s, pdu.outputOriginY);
1955 WLog_Print(gfx->base.log, WLOG_DEBUG,
1956 "RecvMapSurfaceToOutputPdu: surfaceId: %" PRIu16
" outputOriginX: %" PRIu32
1957 " outputOriginY: %" PRIu32
"",
1958 pdu.surfaceId, pdu.outputOriginX, pdu.outputOriginY);
1962 IFCALLRET(context->MapSurfaceToOutput, error, context, &pdu);
1965 WLog_Print(gfx->base.log, WLOG_ERROR,
1966 "context->MapSurfaceToOutput failed with error %" PRIu32
"", error);
1976 WINPR_ASSERT(callback);
1980 RdpgfxClientContext* context = gfx->context;
1981 UINT error = CHANNEL_RC_OK;
1983 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 20))
1984 return ERROR_INVALID_DATA;
1986 Stream_Read_UINT16(s, pdu.surfaceId);
1987 Stream_Read_UINT16(s, pdu.reserved);
1988 Stream_Read_UINT32(s, pdu.outputOriginX);
1989 Stream_Read_UINT32(s, pdu.outputOriginY);
1990 Stream_Read_UINT32(s, pdu.targetWidth);
1991 Stream_Read_UINT32(s, pdu.targetHeight);
1992 WLog_Print(gfx->base.log, WLOG_DEBUG,
1993 "RecvMapSurfaceToScaledOutputPdu: surfaceId: %" PRIu16
" outputOriginX: %" PRIu32
1994 " outputOriginY: %" PRIu32
" targetWidth: %" PRIu32
" targetHeight: %" PRIu32,
1995 pdu.surfaceId, pdu.outputOriginX, pdu.outputOriginY, pdu.targetWidth,
2000 IFCALLRET(context->MapSurfaceToScaledOutput, error, context, &pdu);
2003 WLog_Print(gfx->base.log, WLOG_ERROR,
2004 "context->MapSurfaceToScaledOutput failed with error %" PRIu32
"", error);
2018 WINPR_ASSERT(callback);
2022 RdpgfxClientContext* context = gfx->context;
2023 UINT error = CHANNEL_RC_OK;
2025 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 18))
2026 return ERROR_INVALID_DATA;
2028 Stream_Read_UINT16(s, pdu.surfaceId);
2029 Stream_Read_UINT64(s, pdu.windowId);
2030 Stream_Read_UINT32(s, pdu.mappedWidth);
2031 Stream_Read_UINT32(s, pdu.mappedHeight);
2033 if ((pdu.mappedWidth == 0) || (pdu.mappedHeight == 0))
2035 WLog_Print(gfx->base.log, WLOG_ERROR,
2036 "context->MapSurfaceToWindow mappedWidth[%" PRIu32
"], mappedHeight[%" PRIu32
2038 pdu.mappedWidth, pdu.mappedHeight);
2039 return ERROR_INVALID_DATA;
2041 if ((pdu.mappedWidth > MAX_SURFACE_SIZE) || (pdu.mappedHeight > MAX_SURFACE_SIZE))
2043 WLog_Print(gfx->base.log, WLOG_ERROR,
2044 "context->MapSurfaceToWindow mappedWidth[%" PRIu32
"], mappedHeight[%" PRIu32
2046 pdu.mappedWidth, pdu.mappedHeight, MAX_SURFACE_SIZE);
2047 return ERROR_INVALID_DATA;
2050 WLog_Print(gfx->base.log, WLOG_DEBUG,
2051 "RecvMapSurfaceToWindowPdu: surfaceId: %" PRIu16
" windowId: 0x%016" PRIX64
2052 " mappedWidth: %" PRIu32
" mappedHeight: %" PRIu32
"",
2053 pdu.surfaceId, pdu.windowId, pdu.mappedWidth, pdu.mappedHeight);
2055 if (context && context->MapSurfaceToWindow)
2057 IFCALLRET(context->MapSurfaceToWindow, error, context, &pdu);
2060 WLog_Print(gfx->base.log, WLOG_ERROR,
2061 "context->MapSurfaceToWindow failed with error %" PRIu32
"", error);
2071 WINPR_ASSERT(callback);
2074 RdpgfxClientContext* context = gfx->context;
2075 UINT error = CHANNEL_RC_OK;
2077 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 26))
2078 return ERROR_INVALID_DATA;
2080 Stream_Read_UINT16(s, pdu.surfaceId);
2081 Stream_Read_UINT64(s, pdu.windowId);
2082 Stream_Read_UINT32(s, pdu.mappedWidth);
2083 Stream_Read_UINT32(s, pdu.mappedHeight);
2084 Stream_Read_UINT32(s, pdu.targetWidth);
2085 Stream_Read_UINT32(s, pdu.targetHeight);
2087 if ((pdu.mappedWidth == 0) || (pdu.mappedHeight == 0))
2089 WLog_Print(gfx->base.log, WLOG_ERROR,
2090 "context->RecvMapSurfaceToScaledWindowPdu mappedWidth[%" PRIu32
2091 "], mappedHeight[%" PRIu32
"] is 0",
2092 pdu.mappedWidth, pdu.mappedHeight);
2093 return ERROR_INVALID_DATA;
2095 if ((pdu.targetWidth == 0) || (pdu.targetHeight == 0))
2097 WLog_Print(gfx->base.log, WLOG_ERROR,
2098 "context->RecvMapSurfaceToScaledWindowPdu targetWidth[%" PRIu32
2099 "], targetHeight[%" PRIu32
"] is 0",
2100 pdu.targetWidth, pdu.targetHeight);
2101 return ERROR_INVALID_DATA;
2104 if ((pdu.mappedWidth > MAX_SURFACE_SIZE) || (pdu.mappedHeight > MAX_SURFACE_SIZE))
2106 WLog_Print(gfx->base.log, WLOG_ERROR,
2107 "context->RecvMapSurfaceToScaledWindowPdu mappedWidth[%" PRIu32
2108 "], mappedHeight[%" PRIu32
"] > %" PRIu32,
2109 pdu.mappedWidth, pdu.mappedHeight, MAX_SURFACE_SIZE);
2110 return ERROR_INVALID_DATA;
2113 WLog_Print(gfx->base.log, WLOG_DEBUG,
2114 "RecvMapSurfaceToScaledWindowPdu: surfaceId: %" PRIu16
" windowId: 0x%016" PRIX64
2115 " mappedWidth: %" PRIu32
" mappedHeight: %" PRIu32
" targetWidth: %" PRIu32
2116 " targetHeight: %" PRIu32
"",
2117 pdu.surfaceId, pdu.windowId, pdu.mappedWidth, pdu.mappedHeight, pdu.targetWidth,
2120 if (context && context->MapSurfaceToScaledWindow)
2122 IFCALLRET(context->MapSurfaceToScaledWindow, error, context, &pdu);
2125 WLog_Print(gfx->base.log, WLOG_ERROR,
2126 "context->MapSurfaceToScaledWindow failed with error %" PRIu32
"", error);
2141 WINPR_ASSERT(callback);
2143 const size_t beg = Stream_GetPosition(s);
2147 size_t packetlen = 0;
2148 UINT error = rdpgfx_read_header(gfx->base.log, s, &header, &packetlen);
2149 if (error != CHANNEL_RC_OK)
2151 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_header failed with error %" PRIu32
"!",
2156 WLog_Print(gfx->base.log, WLOG_TRACE,
2157 "cmdId: %s (0x%04" PRIX16
") flags: 0x%04" PRIX16
" pduLength: %" PRIu32
"",
2158 rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId, header.flags,
2161 rdpgfx_stats_cmdid_event(gfx->context, header.cmdId);
2162 switch (header.cmdId)
2164 case RDPGFX_CMDID_WIRETOSURFACE_1:
2165 if ((error = rdpgfx_recv_wire_to_surface_1_pdu(callback, s)))
2166 WLog_Print(gfx->base.log, WLOG_ERROR,
2167 "rdpgfx_recv_wire_to_surface_1_pdu failed with error %" PRIu32
"!",
2172 case RDPGFX_CMDID_WIRETOSURFACE_2:
2173 if ((error = rdpgfx_recv_wire_to_surface_2_pdu(callback, s)))
2174 WLog_Print(gfx->base.log, WLOG_ERROR,
2175 "rdpgfx_recv_wire_to_surface_2_pdu failed with error %" PRIu32
"!",
2180 case RDPGFX_CMDID_DELETEENCODINGCONTEXT:
2181 if ((error = rdpgfx_recv_delete_encoding_context_pdu(callback, s)))
2182 WLog_Print(gfx->base.log, WLOG_ERROR,
2183 "rdpgfx_recv_delete_encoding_context_pdu failed with error %" PRIu32
"!",
2188 case RDPGFX_CMDID_SOLIDFILL:
2189 if ((error = rdpgfx_recv_solid_fill_pdu(callback, s)))
2190 WLog_Print(gfx->base.log, WLOG_ERROR,
2191 "rdpgfx_recv_solid_fill_pdu failed with error %" PRIu32
"!", error);
2195 case RDPGFX_CMDID_SURFACETOSURFACE:
2196 if ((error = rdpgfx_recv_surface_to_surface_pdu(callback, s)))
2197 WLog_Print(gfx->base.log, WLOG_ERROR,
2198 "rdpgfx_recv_surface_to_surface_pdu failed with error %" PRIu32
"!",
2203 case RDPGFX_CMDID_SURFACETOCACHE:
2204 if ((error = rdpgfx_recv_surface_to_cache_pdu(callback, s)))
2205 WLog_Print(gfx->base.log, WLOG_ERROR,
2206 "rdpgfx_recv_surface_to_cache_pdu failed with error %" PRIu32
"!",
2211 case RDPGFX_CMDID_CACHETOSURFACE:
2212 if ((error = rdpgfx_recv_cache_to_surface_pdu(callback, s)))
2213 WLog_Print(gfx->base.log, WLOG_ERROR,
2214 "rdpgfx_recv_cache_to_surface_pdu failed with error %" PRIu32
"!",
2219 case RDPGFX_CMDID_EVICTCACHEENTRY:
2220 if ((error = rdpgfx_recv_evict_cache_entry_pdu(callback, s)))
2221 WLog_Print(gfx->base.log, WLOG_ERROR,
2222 "rdpgfx_recv_evict_cache_entry_pdu failed with error %" PRIu32
"!",
2227 case RDPGFX_CMDID_CREATESURFACE:
2228 if ((error = rdpgfx_recv_create_surface_pdu(callback, s)))
2229 WLog_Print(gfx->base.log, WLOG_ERROR,
2230 "rdpgfx_recv_create_surface_pdu failed with error %" PRIu32
"!", error);
2234 case RDPGFX_CMDID_DELETESURFACE:
2235 if ((error = rdpgfx_recv_delete_surface_pdu(callback, s)))
2236 WLog_Print(gfx->base.log, WLOG_ERROR,
2237 "rdpgfx_recv_delete_surface_pdu failed with error %" PRIu32
"!", error);
2241 case RDPGFX_CMDID_STARTFRAME:
2242 if ((error = rdpgfx_recv_start_frame_pdu(callback, s)))
2243 WLog_Print(gfx->base.log, WLOG_ERROR,
2244 "rdpgfx_recv_start_frame_pdu failed with error %" PRIu32
"!", error);
2248 case RDPGFX_CMDID_ENDFRAME:
2249 if ((error = rdpgfx_recv_end_frame_pdu(callback, s)))
2250 WLog_Print(gfx->base.log, WLOG_ERROR,
2251 "rdpgfx_recv_end_frame_pdu failed with error %" PRIu32
"!", error);
2255 case RDPGFX_CMDID_RESETGRAPHICS:
2256 if ((error = rdpgfx_recv_reset_graphics_pdu(callback, s)))
2257 WLog_Print(gfx->base.log, WLOG_ERROR,
2258 "rdpgfx_recv_reset_graphics_pdu failed with error %" PRIu32
"!", error);
2262 case RDPGFX_CMDID_MAPSURFACETOOUTPUT:
2263 if ((error = rdpgfx_recv_map_surface_to_output_pdu(callback, s)))
2264 WLog_Print(gfx->base.log, WLOG_ERROR,
2265 "rdpgfx_recv_map_surface_to_output_pdu failed with error %" PRIu32
"!",
2270 case RDPGFX_CMDID_CACHEIMPORTREPLY:
2271 if ((error = rdpgfx_recv_cache_import_reply_pdu(callback, s)))
2272 WLog_Print(gfx->base.log, WLOG_ERROR,
2273 "rdpgfx_recv_cache_import_reply_pdu failed with error %" PRIu32
"!",
2278 case RDPGFX_CMDID_CAPSCONFIRM:
2279 if ((error = rdpgfx_recv_caps_confirm_pdu(callback, s)))
2280 WLog_Print(gfx->base.log, WLOG_ERROR,
2281 "rdpgfx_recv_caps_confirm_pdu failed with error %" PRIu32
"!", error);
2283 if ((error = rdpgfx_send_cache_offer(gfx)))
2284 WLog_Print(gfx->base.log, WLOG_ERROR,
2285 "rdpgfx_send_cache_offer failed with error %" PRIu32
"!", error);
2289 case RDPGFX_CMDID_MAPSURFACETOWINDOW:
2290 if ((error = rdpgfx_recv_map_surface_to_window_pdu(callback, s)))
2291 WLog_Print(gfx->base.log, WLOG_ERROR,
2292 "rdpgfx_recv_map_surface_to_window_pdu failed with error %" PRIu32
"!",
2297 case RDPGFX_CMDID_MAPSURFACETOSCALEDWINDOW:
2298 if ((error = rdpgfx_recv_map_surface_to_scaled_window_pdu(callback, s)))
2299 WLog_Print(gfx->base.log, WLOG_ERROR,
2300 "rdpgfx_recv_map_surface_to_scaled_window_pdu failed with error %" PRIu32
2306 case RDPGFX_CMDID_MAPSURFACETOSCALEDOUTPUT:
2307 if ((error = rdpgfx_recv_map_surface_to_scaled_output_pdu(callback, s)))
2308 WLog_Print(gfx->base.log, WLOG_ERROR,
2309 "rdpgfx_recv_map_surface_to_scaled_output_pdu failed with error %" PRIu32
2315 case RDPGFX_CMDID_PROTECT_SURFACE:
2316 case RDPGFX_CMDID_WATERMARK:
2317 WLog_Print(gfx->base.log, WLOG_WARN,
2318 "Command %s not implemented, skipping %" PRIu32
" bytes",
2319 rdpgfx_get_cmd_id_string(header.cmdId), header.pduLength);
2320 if (!Stream_SafeSeek(s, packetlen))
2321 error = ERROR_INVALID_DATA;
2324 error = CHANNEL_RC_BAD_PROC;
2330 WLog_Print(gfx->base.log, WLOG_ERROR,
2331 "Error while processing GFX cmdId: %s (0x%04" PRIX16
")",
2332 rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId);
2333 if (!Stream_SetPosition(s, (beg + header.pduLength)))
2334 return ERROR_INVALID_DATA;
2338 const size_t end = Stream_GetPosition(s);
2340 if (end != (beg + header.pduLength))
2342 WLog_Print(gfx->base.log, WLOG_ERROR,
2343 "Unexpected gfx pdu end: Actual: %" PRIuz
", Expected: %" PRIuz, end,
2344 (beg + header.pduLength));
2345 if (!Stream_SetPosition(s, (beg + header.pduLength)))
2346 return ERROR_INVALID_DATA;
2357static UINT rdpgfx_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
wStream* data)
2360 BYTE* pDstData =
nullptr;
2362 WINPR_ASSERT(callback);
2364 UINT error = CHANNEL_RC_OK;
2367 int status = zgfx_decompress(gfx->zgfx, Stream_ConstPointer(data),
2368 (UINT32)Stream_GetRemainingLength(data), &pDstData, &DstSize, 0);
2370 if ((status < 0) || (DstSize == 0))
2372 WLog_Print(gfx->base.log, WLOG_ERROR,
2373 "zgfx_decompress failure! status: %d, DstSize=%" PRIu32, status, DstSize);
2375 return ERROR_INTERNAL_ERROR;
2378 wStream sbuffer = WINPR_C_ARRAY_INIT;
2379 wStream* s = Stream_StaticConstInit(&sbuffer, pDstData, DstSize);
2383 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
2385 return CHANNEL_RC_NO_MEMORY;
2388 while (Stream_GetPosition(s) < Stream_Length(s))
2390 if ((error = rdpgfx_recv_pdu(callback, s)))
2392 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_recv_pdu failed with error %" PRIu32
"!",
2407static UINT rdpgfx_on_open(IWTSVirtualChannelCallback* pChannelCallback)
2410 WINPR_ASSERT(callback);
2413 RdpgfxClientContext* context = gfx->context;
2414 UINT error = CHANNEL_RC_OK;
2415 BOOL do_caps_advertise = TRUE;
2417 gfx->sendFrameAcks = TRUE;
2421 IFCALLRET(context->OnOpen, error, context, &do_caps_advertise, &gfx->sendFrameAcks);
2424 WLog_Print(gfx->base.log, WLOG_ERROR,
"context->OnOpen failed with error %" PRIu32
"",
2427 RdpgfxClientContextInt* ctx = (RdpgfxClientContextInt*)context;
2428 const RdpgfxClientContextStats empty = WINPR_C_ARRAY_INIT;
2432 if (do_caps_advertise)
2433 error = rdpgfx_send_supported_caps(callback);
2438static void rdpgfx_dump_stats(RdpgfxClientContext* context)
2440 WINPR_ASSERT(context);
2445 wLog* log = gfx->base.log;
2446 const DWORD level = WLOG_TRACE;
2447 if (!WLog_IsLevelActive(log, level))
2450 WLog_Print(log, level,
"RdpgfxClientContextStats");
2451 for (
size_t x = 0; x < rdpgfx_stats_max_index(); x++)
2453 const char* name = rdpgfx_stats_name_for_index(x);
2454 const uint64_t val = rdpgfx_stats_value_for_index(context, x);
2455 WLog_Print(log, level,
"%s: %" PRIu64, name, val);
2464static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback)
2466 UINT error = CHANNEL_RC_OK;
2468 WINPR_ASSERT(callback);
2474 RdpgfxClientContext* context = gfx->context;
2476 WLog_Print(gfx->base.log, WLOG_DEBUG,
"OnClose");
2477 error = rdpgfx_save_persistent_cache(gfx);
2482 WLog_Print(gfx->base.log, WLOG_ERROR,
2483 "rdpgfx_save_persistent_cache failed with error %" PRIu32
"", error);
2486 free_surfaces(context, gfx->SurfaceTable);
2487 error = evict_cache_slots(context, gfx->MaxCacheSlots, gfx->CacheSlots);
2491 WLog_Print(gfx->base.log, WLOG_ERROR,
"evict_cache_slots failed with error %" PRIu32
"",
2496 gfx->UnacknowledgedFrames = 0;
2497 gfx->TotalDecodedFrames = 0;
2501 error = IFCALLRESULT(CHANNEL_RC_OK, context->OnClose, context);
2505 WLog_Print(gfx->base.log, WLOG_ERROR,
"context->OnClose failed with error %" PRIu32
"",
2508 rdpgfx_dump_stats(context);
2512 return CHANNEL_RC_OK;
2519 RdpgfxClientContext* context = gfx->context;
2521 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Terminated");
2522 rdpgfx_client_context_free(context);
2530static UINT rdpgfx_set_surface_data(RdpgfxClientContext* context, UINT16 surfaceId,
void* pData)
2532 WINPR_ASSERT(context);
2535 ULONG_PTR key = ((ULONG_PTR)surfaceId) + 1;
2539 if (!HashTable_Insert(gfx->SurfaceTable, (
void*)key, pData))
2540 return ERROR_BAD_ARGUMENTS;
2543 HashTable_Remove(gfx->SurfaceTable, (
void*)key);
2545 return CHANNEL_RC_OK;
2553static UINT rdpgfx_get_surface_ids(RdpgfxClientContext* context, UINT16** ppSurfaceIds,
2556 ULONG_PTR* pKeys =
nullptr;
2557 WINPR_ASSERT(context);
2560 size_t count = HashTable_GetKeys(gfx->SurfaceTable, &pKeys);
2562 WINPR_ASSERT(ppSurfaceIds);
2563 WINPR_ASSERT(count_out);
2567 return CHANNEL_RC_OK;
2570 UINT16* pSurfaceIds = (UINT16*)calloc(count,
sizeof(UINT16));
2574 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
2576 return CHANNEL_RC_NO_MEMORY;
2579 for (
size_t index = 0; index < count; index++)
2581 pSurfaceIds[index] = (UINT16)(pKeys[index] - 1);
2585 *ppSurfaceIds = pSurfaceIds;
2586 *count_out = (UINT16)count;
2587 return CHANNEL_RC_OK;
2590static void* rdpgfx_get_surface_data(RdpgfxClientContext* context, UINT16 surfaceId)
2592 WINPR_ASSERT(context);
2595 ULONG_PTR key = ((ULONG_PTR)surfaceId) + 1;
2596 return HashTable_GetItemValue(gfx->SurfaceTable, (
void*)key);
2604static UINT rdpgfx_set_cache_slot_data(RdpgfxClientContext* context, UINT16 cacheSlot,
void* pData)
2606 WINPR_ASSERT(context);
2611 if (cacheSlot == 0 || cacheSlot > gfx->MaxCacheSlots)
2613 WLog_Print(gfx->base.log, WLOG_ERROR,
2614 "invalid cache slot %" PRIu16
", must be between 1 and %" PRIu16
"", cacheSlot,
2615 gfx->MaxCacheSlots);
2616 return ERROR_INVALID_INDEX;
2619 gfx->CacheSlots[cacheSlot - 1] = pData;
2620 return CHANNEL_RC_OK;
2623static void* rdpgfx_get_cache_slot_data(RdpgfxClientContext* context, UINT16 cacheSlot)
2625 WINPR_ASSERT(context);
2629 if (cacheSlot == 0 || cacheSlot > gfx->MaxCacheSlots)
2631 WLog_Print(gfx->base.log, WLOG_ERROR,
2632 "invalid cache slot %" PRIu16
", must be between 1 and %" PRIu16
"", cacheSlot,
2633 gfx->MaxCacheSlots);
2637 return gfx->CacheSlots[cacheSlot - 1];
2641 WINPR_ATTR_UNUSED rdpSettings* settings)
2646 gfx->rdpcontext = rcontext;
2648 gfx->SurfaceTable = HashTable_New(TRUE);
2649 if (!gfx->SurfaceTable)
2651 WLog_Print(gfx->base.log, WLOG_ERROR,
"HashTable_New for surfaces failed !");
2652 return CHANNEL_RC_NO_MEMORY;
2655 gfx->suspendFrameAcks =
2657 gfx->MaxCacheSlots =
2660 RdpgfxClientContextInt* context =
2661 (RdpgfxClientContextInt*)calloc(1,
sizeof(RdpgfxClientContextInt));
2664 WLog_Print(gfx->base.log, WLOG_ERROR,
"context calloc failed!");
2665 HashTable_Free(gfx->SurfaceTable);
2666 gfx->SurfaceTable =
nullptr;
2667 return CHANNEL_RC_NO_MEMORY;
2670 gfx->zgfx = zgfx_context_new(FALSE);
2673 WLog_Print(gfx->base.log, WLOG_ERROR,
"zgfx_context_new failed!");
2674 HashTable_Free(gfx->SurfaceTable);
2675 gfx->SurfaceTable =
nullptr;
2677 return CHANNEL_RC_NO_MEMORY;
2680 context->common.handle = (
void*)gfx;
2681 context->common.GetSurfaceIds = rdpgfx_get_surface_ids;
2682 context->common.SetSurfaceData = rdpgfx_set_surface_data;
2683 context->common.GetSurfaceData = rdpgfx_get_surface_data;
2684 context->common.SetCacheSlotData = rdpgfx_set_cache_slot_data;
2685 context->common.GetCacheSlotData = rdpgfx_get_cache_slot_data;
2686 context->common.CapsAdvertise = rdpgfx_send_caps_advertise_pdu;
2687 context->common.FrameAcknowledge = rdpgfx_send_frame_acknowledge_pdu;
2688 context->common.CacheImportOffer = rdpgfx_send_cache_import_offer_pdu;
2689 context->common.QoeFrameAcknowledge = rdpgfx_send_qoe_frame_acknowledge_pdu;
2691 gfx->base.iface.pInterface = (
void*)context;
2692 gfx->context = &context->common;
2693 return CHANNEL_RC_OK;
2696void rdpgfx_client_context_free(RdpgfxClientContext* context)
2703 free_surfaces(context, gfx->SurfaceTable);
2704 evict_cache_slots(context, gfx->MaxCacheSlots, gfx->CacheSlots);
2708 zgfx_context_free(gfx->zgfx);
2709 gfx->zgfx =
nullptr;
2712 HashTable_Free(gfx->SurfaceTable);
2716static const IWTSVirtualChannelCallback rdpgfx_callbacks = { rdpgfx_on_data_received,
2717 rdpgfx_on_open, rdpgfx_on_close,
2725FREERDP_ENTRY_POINT(UINT VCAPITYPE rdpgfx_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))
2727 return freerdp_generic_DVCPluginEntry(pEntryPoints, GFXTAG, RDPGFX_DVC_CHANNEL_NAME,
2729 &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.