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 UINT16
id = (UINT16)(uintptr_t)(key);
136 RdpgfxClientContext* context = arg;
143 UINT error = CHANNEL_RC_OK;
144 IFCALLRET(context->DeleteSurface, error, context, &pdu);
150 WLog_Print(gfx->base.log, WLOG_ERROR,
151 "context->DeleteSurface failed with error %" PRIu32
"", error);
157static void free_surfaces(RdpgfxClientContext* context, wHashTable* SurfaceTable)
159 WINPR_ASSERT(context);
160 if (!HashTable_Foreach(SurfaceTable, delete_surface, context))
164 WLog_Print(gfx->base.log, WLOG_WARN,
"delete_surface failed");
168static UINT evict_cache_slots(RdpgfxClientContext* context, UINT16 MaxCacheSlots,
void** CacheSlots)
170 UINT error = CHANNEL_RC_OK;
172 WINPR_ASSERT(CacheSlots);
173 for (UINT16 index = 0; index < MaxCacheSlots; index++)
175 if (CacheSlots[index])
179 if (context && context->EvictCacheEntry)
181 const UINT rc = context->EvictCacheEntry(context, &pdu);
182 if (rc != CHANNEL_RC_OK)
186 CacheSlots[index] =
nullptr;
197static UINT rdpgfx_send_caps_advertise_pdu(RdpgfxClientContext* context,
200 UINT error = CHANNEL_RC_OK;
203 WINPR_ASSERT(context);
207 if (!gfx || !gfx->base.listener_callback)
208 return ERROR_BAD_ARGUMENTS;
213 .cmdId = RDPGFX_CMDID_CAPSADVERTISE,
214 .pduLength = RDPGFX_HEADER_SIZE + 2 };
216 for (UINT16 index = 0; index < pdu->capsSetCount; index++)
219 header.pduLength += RDPGFX_CAPSET_BASE_SIZE + capsSet->length;
222 WLog_Print(gfx->base.log, WLOG_DEBUG,
"SendCapsAdvertisePdu %" PRIu16
"", pdu->capsSetCount);
223 wStream* s = Stream_New(
nullptr, header.pduLength);
227 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
228 return CHANNEL_RC_NO_MEMORY;
231 if ((error = rdpgfx_write_header(s, &header)))
235 Stream_Write_UINT16(s, pdu->capsSetCount);
237 for (UINT16 index = 0; index < pdu->capsSetCount; index++)
241 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Sending %s [0x%08" PRIx32
"] flags=0x%08" PRIx32,
242 rdpgfx_caps_version_str(capsSet->version), capsSet->version, capsSet->flags);
244 Stream_Write_UINT32(s, capsSet->version);
245 Stream_Write_UINT32(s, capsSet->length);
246 Stream_Write_UINT32(s, capsSet->flags);
247 if (capsSet->length < 4)
249 Stream_Zero(s, capsSet->length - 4);
252 Stream_SealLength(s);
253 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
256 Stream_Free(s, TRUE);
260static BOOL rdpgfx_is_capability_filtered(
RDPGFX_PLUGIN* gfx, UINT32 caps)
263 const UINT32 filter =
265 const UINT32 capList[] = {
266#if defined(WITH_GFX_AV1)
267 RDPGFX_CAPVERSION_FRDP_1,
270 RDPGFX_CAPVERSION_81,
271 RDPGFX_CAPVERSION_10,
272 RDPGFX_CAPVERSION_101,
273 RDPGFX_CAPVERSION_102,
274 RDPGFX_CAPVERSION_103,
275 RDPGFX_CAPVERSION_104,
276 RDPGFX_CAPVERSION_105,
277 RDPGFX_CAPVERSION_106,
278 RDPGFX_CAPVERSION_106_ERR,
279 RDPGFX_CAPVERSION_107
280#if defined(WITH_GFX_AZURE)
282 RDPGFX_CAPVERSION_111,
283 RDPGFX_CAPVERSION_112,
284 RDPGFX_CAPVERSION_113
288 for (
size_t x = 0; x < ARRAYSIZE(capList); x++)
290 if (caps == capList[x])
291 return (filter & (1u << x)) != 0;
301 WINPR_ASSERT(pdu->capsSets);
302 WINPR_ASSERT(count > 0);
303 WINPR_ASSERT(pdu->capsSetCount < count);
304 if (pdu->capsSetCount >= count)
306 return &pdu->capsSets[pdu->capsSetCount++];
316 RDPGFX_CAPSET capsSets[RDPGFX_NUMBER_CAPSETS] = WINPR_C_ARRAY_INIT;
319 return ERROR_BAD_ARGUMENTS;
324 return ERROR_BAD_CONFIGURATION;
326 RdpgfxClientContext* context = gfx->context;
329 return ERROR_BAD_CONFIGURATION;
333 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_8))
335 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
337 return ERROR_BAD_CONFIGURATION;
338 capsSet->version = RDPGFX_CAPVERSION_8;
343 capsSet->flags |= RDPGFX_CAPS_FLAG_THINCLIENT;
350 capsSet->flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE;
353 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_81))
355 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
357 return ERROR_BAD_CONFIGURATION;
358 capsSet->version = RDPGFX_CAPVERSION_81;
363 capsSet->flags |= RDPGFX_CAPS_FLAG_THINCLIENT;
366 capsSet->flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE;
371 capsSet->flags |= RDPGFX_CAPS_FLAG_AVC420_ENABLED;
376 UINT32 caps10Flags = 0;
381 caps10Flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE;
386 caps10Flags |= RDPGFX_CAPS_FLAG_AVC_DISABLED;
389 caps10Flags |= RDPGFX_CAPS_FLAG_AVC_DISABLED;
392 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_10))
394 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
396 return ERROR_BAD_CONFIGURATION;
397 capsSet->version = RDPGFX_CAPVERSION_10;
399 capsSet->flags = caps10Flags;
402 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_101))
404 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
406 return ERROR_BAD_CONFIGURATION;
407 capsSet->version = RDPGFX_CAPVERSION_101;
408 capsSet->length = 0x10;
412 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_102))
414 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
416 return ERROR_BAD_CONFIGURATION;
417 capsSet->version = RDPGFX_CAPVERSION_102;
418 capsSet->length = 0x4;
419 capsSet->flags = caps10Flags;
424 if ((caps10Flags & RDPGFX_CAPS_FLAG_AVC_DISABLED) == 0)
425 caps10Flags |= RDPGFX_CAPS_FLAG_AVC_THINCLIENT;
428 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_103))
430 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
432 return ERROR_BAD_CONFIGURATION;
433 capsSet->version = RDPGFX_CAPVERSION_103;
434 capsSet->length = 0x4;
435 capsSet->flags = caps10Flags & ~RDPGFX_CAPS_FLAG_SMALL_CACHE;
438 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_104))
440 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
442 return ERROR_BAD_CONFIGURATION;
443 capsSet->version = RDPGFX_CAPVERSION_104;
444 capsSet->length = 0x4;
445 capsSet->flags = caps10Flags;
451#if defined(WITH_CAIRO) || defined(WITH_SWSCALE)
452 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_105))
454 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
456 return ERROR_BAD_CONFIGURATION;
457 capsSet->version = RDPGFX_CAPVERSION_105;
458 capsSet->length = 0x4;
459 capsSet->flags = caps10Flags;
462 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_106))
464 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
466 return ERROR_BAD_CONFIGURATION;
467 capsSet->version = RDPGFX_CAPVERSION_106;
468 capsSet->length = 0x4;
469 capsSet->flags = caps10Flags;
472 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_106_ERR))
474 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
476 return ERROR_BAD_CONFIGURATION;
477 capsSet->version = RDPGFX_CAPVERSION_106_ERR;
478 capsSet->length = 0x4;
479 capsSet->flags = caps10Flags;
483 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_107))
485 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
487 return ERROR_BAD_CONFIGURATION;
488 capsSet->version = RDPGFX_CAPVERSION_107;
489 capsSet->length = 0x4;
490 capsSet->flags = caps10Flags;
491#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
492 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
496#if defined(WITH_GFX_AZURE)
497 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_111))
499 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
501 return ERROR_BAD_CONFIGURATION;
502 capsSet->version = RDPGFX_CAPVERSION_111;
503 capsSet->length = 0x4;
504 capsSet->flags = caps10Flags;
505#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
506 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
510 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_112))
512 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
514 return ERROR_BAD_CONFIGURATION;
515 capsSet->version = RDPGFX_CAPVERSION_112;
516 capsSet->length = 0x4;
517 capsSet->flags = caps10Flags;
518#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
519 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
523 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_113))
525 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
527 return ERROR_BAD_CONFIGURATION;
528 capsSet->version = RDPGFX_CAPVERSION_113;
529 capsSet->length = 0x4;
530 capsSet->flags = caps10Flags;
531#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
532 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
538#if defined(WITH_GFX_AV1)
541 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_FRDP_1))
543 RDPGFX_CAPSET* capsSet = nextCapset(&pdu, ARRAYSIZE(capsSets));
545 return ERROR_BAD_CONFIGURATION;
546 capsSet->version = RDPGFX_CAPVERSION_FRDP_1;
547 capsSet->length = 0x4;
549 capsSet->flags = caps10Flags | RDPGFX_CAPS_FLAG_AV1_I444_SUPPORTED;
550 const UINT32 profile =
553 capsSet->flags |= RDPGFX_CAPS_FLAG_AV1_I444_DISABLED;
555#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
556 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
562 return IFCALLRESULT(ERROR_BAD_CONFIGURATION, context->CapsAdvertise, context, &pdu);
572 WINPR_ASSERT(callback);
576 RdpgfxClientContext* context = gfx->context;
581 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 12))
582 return ERROR_INVALID_DATA;
584 Stream_Read_UINT32(s, capsSet.version);
585 Stream_Read_UINT32(s, capsSet.length);
586 Stream_Read_UINT32(s, capsSet.flags);
587 gfx->TotalDecodedFrames = 0;
588 gfx->ConnectionCaps = capsSet;
589 WLog_Print(gfx->base.log, WLOG_DEBUG,
590 "RecvCapsConfirmPdu: version: %s [0x%08" PRIX32
"] flags: 0x%08" PRIX32
"",
591 rdpgfx_caps_version_str(capsSet.version), capsSet.version, capsSet.flags);
594 return ERROR_BAD_CONFIGURATION;
596 return IFCALLRESULT(CHANNEL_RC_OK, context->CapsConfirm, context, &pdu);
604static UINT rdpgfx_send_frame_acknowledge_pdu(RdpgfxClientContext* context,
609 if (!context || !pdu)
610 return ERROR_BAD_ARGUMENTS;
614 if (!gfx || !gfx->base.listener_callback)
615 return ERROR_BAD_CONFIGURATION;
620 return ERROR_BAD_CONFIGURATION;
623 .cmdId = RDPGFX_CMDID_FRAMEACKNOWLEDGE,
624 .pduLength = RDPGFX_HEADER_SIZE + 12 };
626 WLog_Print(gfx->base.log, WLOG_TRACE,
"SendFrameAcknowledgePdu: %" PRIu32
"", pdu->frameId);
628 wStream* s = Stream_New(
nullptr, header.pduLength);
632 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
633 return CHANNEL_RC_NO_MEMORY;
636 if ((error = rdpgfx_write_header(s, &header)))
640 Stream_Write_UINT32(s, pdu->queueDepth);
641 Stream_Write_UINT32(s, pdu->frameId);
642 Stream_Write_UINT32(s, pdu->totalFramesDecoded);
643 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
646 if (error == CHANNEL_RC_OK)
647 gfx->UnacknowledgedFrames--;
650 Stream_Free(s, TRUE);
654static UINT rdpgfx_send_qoe_frame_acknowledge_pdu(RdpgfxClientContext* context,
657 UINT error = CHANNEL_RC_OK;
659 .cmdId = RDPGFX_CMDID_QOEFRAMEACKNOWLEDGE,
660 .pduLength = RDPGFX_HEADER_SIZE + 12 };
662 if (!context || !pdu)
663 return ERROR_BAD_ARGUMENTS;
667 if (!gfx || !gfx->base.listener_callback)
668 return ERROR_BAD_CONFIGURATION;
673 return ERROR_BAD_CONFIGURATION;
675 WLog_Print(gfx->base.log, WLOG_TRACE,
"SendQoeFrameAcknowledgePdu: %" PRIu32
"", pdu->frameId);
676 wStream* s = Stream_New(
nullptr, header.pduLength);
680 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
681 return CHANNEL_RC_NO_MEMORY;
684 if ((error = rdpgfx_write_header(s, &header)))
688 Stream_Write_UINT32(s, pdu->frameId);
689 Stream_Write_UINT32(s, pdu->timestamp);
690 Stream_Write_UINT16(s, pdu->timeDiffSE);
691 Stream_Write_UINT16(s, pdu->timeDiffEDR);
692 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
695 Stream_Free(s, TRUE);
707 WINPR_ASSERT(callback);
713 RdpgfxClientContext* context = gfx->context;
714 UINT error = CHANNEL_RC_OK;
715 GraphicsResetEventArgs graphicsReset = WINPR_C_ARRAY_INIT;
717 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 12))
718 return ERROR_INVALID_DATA;
720 Stream_Read_UINT32(s, pdu.width);
721 Stream_Read_UINT32(s, pdu.height);
722 Stream_Read_UINT32(s, pdu.monitorCount);
724 if ((pdu.width > MAX_SURFACE_SIZE) || (pdu.height > MAX_SURFACE_SIZE) ||
725 (pdu.monitorCount > MAX_MONITOR_COUNT))
727 WLog_Print(gfx->base.log, WLOG_ERROR,
728 "context->ResetGraphics Width[%" PRIu32
"], Height[%" PRIu32
"] > %" PRIu32
729 " or monitorCount[%" PRIu32
" > %" PRIu32,
730 pdu.width, pdu.width, MAX_SURFACE_SIZE, pdu.monitorCount, MAX_MONITOR_COUNT);
731 return ERROR_INVALID_DATA;
734 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.monitorCount, 20ull))
735 return ERROR_INVALID_DATA;
739 if (!pdu.monitorDefArray)
741 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
742 return CHANNEL_RC_NO_MEMORY;
745 for (UINT32 index = 0; index < pdu.monitorCount; index++)
747 MONITOR_DEF* monitor = &(pdu.monitorDefArray[index]);
748 Stream_Read_INT32(s, monitor->left);
749 Stream_Read_INT32(s, monitor->top);
750 Stream_Read_INT32(s, monitor->right);
751 Stream_Read_INT32(s, monitor->bottom);
752 Stream_Read_UINT32(s, monitor->flags);
755 const size_t size = (RDPGFX_HEADER_SIZE + 12ULL + (pdu.monitorCount * 20ULL));
758 free(pdu.monitorDefArray);
759 return CHANNEL_RC_NULL_DATA;
761 const size_t pad = 340ULL - size;
763 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, (
size_t)pad))
765 free(pdu.monitorDefArray);
766 return CHANNEL_RC_NO_MEMORY;
770 WLog_Print(gfx->base.log, WLOG_DEBUG,
771 "RecvResetGraphicsPdu: width: %" PRIu32
" height: %" PRIu32
" count: %" PRIu32
"",
772 pdu.width, pdu.height, pdu.monitorCount);
774 for (UINT32 index = 0; index < pdu.monitorCount; index++)
776 MONITOR_DEF* monitor = &(pdu.monitorDefArray[index]);
777 WLog_Print(gfx->base.log, WLOG_TRACE,
778 "RecvResetGraphicsPdu: monitor left:%" PRIi32
" top:%" PRIi32
" right:%" PRIi32
779 " bottom:%" PRIi32
" flags:0x%" PRIx32
"",
780 monitor->left, monitor->top, monitor->right, monitor->bottom, monitor->flags);
785 IFCALLRET(context->ResetGraphics, error, context, &pdu);
788 WLog_Print(gfx->base.log, WLOG_ERROR,
789 "context->ResetGraphics failed with error %" PRIu32
"", error);
792 free(pdu.monitorDefArray);
795 EventArgsInit(&graphicsReset,
"libfreerdp");
796 graphicsReset.width = pdu.width;
797 graphicsReset.height = pdu.height;
798 if (PubSub_OnGraphicsReset(gfx->rdpcontext->pubSub, gfx->rdpcontext, &graphicsReset) < 0)
799 return ERROR_INTERNAL_ERROR;
811 WINPR_ASSERT(callback);
814 RdpgfxClientContext* context = gfx->context;
815 UINT error = CHANNEL_RC_OK;
817 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 2))
818 return ERROR_INVALID_DATA;
820 Stream_Read_UINT16(s, pdu.cacheSlot);
821 WLog_Print(gfx->base.log, WLOG_DEBUG,
"RecvEvictCacheEntryPdu: cacheSlot: %" PRIu16
"",
826 IFCALLRET(context->EvictCacheEntry, error, context, &pdu);
829 WLog_Print(gfx->base.log, WLOG_ERROR,
830 "context->EvictCacheEntry failed with error %" PRIu32
"", error);
843 UINT error = CHANNEL_RC_OK;
846 WINPR_ASSERT(gfx->rdpcontext);
847 rdpSettings* settings = gfx->rdpcontext->settings;
848 RdpgfxClientContext* context = gfx->context;
850 WINPR_ASSERT(context);
851 WINPR_ASSERT(settings);
854 return CHANNEL_RC_OK;
856 const char* BitmapCachePersistFile =
858 if (!BitmapCachePersistFile)
859 return CHANNEL_RC_OK;
861 if (!context->ExportCacheEntry)
862 return CHANNEL_RC_INITIALIZATION_ERROR;
864 rdpPersistentCache* persistent = persistent_cache_new();
867 return CHANNEL_RC_NO_MEMORY;
869 if (persistent_cache_open(persistent, BitmapCachePersistFile, TRUE, 3) < 1)
871 error = CHANNEL_RC_INITIALIZATION_ERROR;
875 for (UINT16 idx = 0; idx < gfx->MaxCacheSlots; idx++)
877 if (gfx->CacheSlots[idx])
879 const UINT16 cacheSlot = idx;
882 if (context->ExportCacheEntry(context, cacheSlot, &cacheEntry) != CHANNEL_RC_OK)
885 if (persistent_cache_write_entry(persistent, &cacheEntry) < 0)
890 persistent_cache_free(persistent);
894 persistent_cache_free(persistent);
903static UINT rdpgfx_send_cache_import_offer_pdu(RdpgfxClientContext* context,
906 UINT error = CHANNEL_RC_OK;
908 if (!context || !pdu)
909 return ERROR_BAD_ARGUMENTS;
913 if (!gfx || !gfx->base.listener_callback)
914 return ERROR_BAD_CONFIGURATION;
919 return ERROR_BAD_CONFIGURATION;
922 .cmdId = RDPGFX_CMDID_CACHEIMPORTOFFER,
924 RDPGFX_HEADER_SIZE + 2ul + pdu->cacheEntriesCount * 12ul };
926 WLog_Print(gfx->base.log, WLOG_DEBUG,
"SendCacheImportOfferPdu: cacheEntriesCount: %" PRIu16
"",
927 pdu->cacheEntriesCount);
928 wStream* s = Stream_New(
nullptr, header.pduLength);
932 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
933 return CHANNEL_RC_NO_MEMORY;
936 if ((error = rdpgfx_write_header(s, &header)))
939 if (pdu->cacheEntriesCount <= 0)
941 WLog_Print(gfx->base.log, WLOG_ERROR,
"Invalid cacheEntriesCount: %" PRIu16
"",
942 pdu->cacheEntriesCount);
943 error = ERROR_INVALID_DATA;
948 Stream_Write_UINT16(s, pdu->cacheEntriesCount);
950 for (UINT16 index = 0; index < pdu->cacheEntriesCount; index++)
953 Stream_Write_UINT64(s, cacheEntry->cacheKey);
954 Stream_Write_UINT32(s, cacheEntry->bitmapLength);
957 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
961 Stream_Free(s, TRUE);
973 UINT error = CHANNEL_RC_OK;
978 WINPR_ASSERT(gfx->rdpcontext);
980 RdpgfxClientContext* context = gfx->context;
981 rdpSettings* settings = gfx->rdpcontext->settings;
984 return CHANNEL_RC_OK;
986 const char* BitmapCachePersistFile =
988 if (!BitmapCachePersistFile)
989 return CHANNEL_RC_OK;
991 rdpPersistentCache* persistent = persistent_cache_new();
994 return CHANNEL_RC_NO_MEMORY;
996 if (persistent_cache_open(persistent, BitmapCachePersistFile, FALSE, 3) < 1)
998 error = CHANNEL_RC_INITIALIZATION_ERROR;
1002 if (persistent_cache_get_version(persistent) != 3)
1004 error = ERROR_INVALID_DATA;
1008 count = persistent_cache_get_count(persistent);
1011 error = ERROR_INVALID_DATA;
1015 if (count >= RDPGFX_CACHE_ENTRY_MAX_COUNT)
1016 count = RDPGFX_CACHE_ENTRY_MAX_COUNT - 1;
1018 if (count > gfx->MaxCacheSlots)
1019 count = gfx->MaxCacheSlots;
1024 error = CHANNEL_RC_NO_MEMORY;
1028 WINPR_ASSERT(count <= UINT16_MAX);
1029 offer->cacheEntriesCount = (UINT16)count;
1031 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Sending Cache Import Offer: %d", count);
1033 for (
int idx = 0; idx < count; idx++)
1035 if (persistent_cache_read_entry(persistent, &entry) < 1)
1037 error = ERROR_INVALID_DATA;
1041 offer->cacheEntries[idx].cacheKey = entry.key64;
1042 offer->cacheEntries[idx].bitmapLength = entry.size;
1045 if (offer->cacheEntriesCount > 0)
1047 error = rdpgfx_send_cache_import_offer_pdu(context, offer);
1048 if (error != CHANNEL_RC_OK)
1050 WLog_Print(gfx->base.log, WLOG_ERROR,
"Failed to send cache import offer PDU");
1056 persistent_cache_free(persistent);
1066static UINT rdpgfx_load_cache_import_reply(
RDPGFX_PLUGIN* gfx,
1069 UINT error = CHANNEL_RC_OK;
1070 rdpPersistentCache* persistent =
nullptr;
1072 WINPR_ASSERT(gfx->rdpcontext);
1073 rdpSettings* settings = gfx->rdpcontext->settings;
1074 RdpgfxClientContext* context = gfx->context;
1076 WINPR_ASSERT(settings);
1077 WINPR_ASSERT(reply);
1079 return CHANNEL_RC_OK;
1081 const char* BitmapCachePersistFile =
1083 if (!BitmapCachePersistFile)
1084 return CHANNEL_RC_OK;
1086 persistent = persistent_cache_new();
1089 return CHANNEL_RC_NO_MEMORY;
1091 if (persistent_cache_open(persistent, BitmapCachePersistFile, FALSE, 3) < 1)
1093 error = CHANNEL_RC_INITIALIZATION_ERROR;
1097 if (persistent_cache_get_version(persistent) != 3)
1099 error = ERROR_INVALID_DATA;
1103 int count = persistent_cache_get_count(persistent);
1105 count = (count < reply->importedEntriesCount) ? count : reply->importedEntriesCount;
1107 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Receiving Cache Import Reply: %d", count);
1109 for (
int idx = 0; idx < count; idx++)
1112 if (persistent_cache_read_entry(persistent, &entry) < 1)
1114 error = ERROR_INVALID_DATA;
1118 const UINT16 cacheSlot = reply->cacheSlots[idx];
1119 if (context && context->ImportCacheEntry)
1121 error = context->ImportCacheEntry(context, cacheSlot, &entry);
1122 if (error != CHANNEL_RC_OK)
1127 persistent_cache_free(persistent);
1131 persistent_cache_free(persistent);
1143 WINPR_ASSERT(callback);
1146 RdpgfxClientContext* context = gfx->context;
1147 UINT error = CHANNEL_RC_OK;
1149 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 2))
1150 return ERROR_INVALID_DATA;
1152 Stream_Read_UINT16(s, pdu.importedEntriesCount);
1154 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.importedEntriesCount,
1156 return ERROR_INVALID_DATA;
1158 if (pdu.importedEntriesCount > RDPGFX_CACHE_ENTRY_MAX_COUNT)
1159 return ERROR_INVALID_DATA;
1161 for (UINT16 idx = 0; idx < pdu.importedEntriesCount; idx++)
1163 Stream_Read_UINT16(s, pdu.cacheSlots[idx]);
1166 WLog_Print(gfx->base.log, WLOG_TRACE,
1167 "RecvCacheImportReplyPdu: importedEntriesCount: %" PRIu16
"",
1168 pdu.importedEntriesCount);
1170 error = rdpgfx_load_cache_import_reply(gfx, &pdu);
1174 WLog_Print(gfx->base.log, WLOG_ERROR,
1175 "rdpgfx_load_cache_import_reply failed with error %" PRIu32
"", error);
1181 IFCALLRET(context->CacheImportReply, error, context, &pdu);
1184 WLog_Print(gfx->base.log, WLOG_ERROR,
1185 "context->CacheImportReply failed with error %" PRIu32
"", error);
1199 WINPR_ASSERT(callback);
1202 RdpgfxClientContext* context = gfx->context;
1203 UINT error = CHANNEL_RC_OK;
1205 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 7))
1206 return ERROR_INVALID_DATA;
1208 Stream_Read_UINT16(s, pdu.surfaceId);
1209 Stream_Read_UINT16(s, pdu.width);
1210 Stream_Read_UINT16(s, pdu.height);
1211 Stream_Read_UINT8(s, pdu.pixelFormat);
1213 if ((pdu.width > MAX_SURFACE_SIZE) || (pdu.height > MAX_SURFACE_SIZE))
1215 WLog_Print(gfx->base.log, WLOG_ERROR,
1216 "context->RecvCreateSurfacePdu Width[%" PRIu32
"], Height[%" PRIu32
1218 pdu.width, pdu.height, MAX_SURFACE_SIZE);
1219 return ERROR_INVALID_DATA;
1222 WLog_Print(gfx->base.log, WLOG_DEBUG,
1223 "RecvCreateSurfacePdu: surfaceId: %" PRIu16
" width: %" PRIu16
" height: %" PRIu16
1224 " pixelFormat: 0x%02" PRIX8
"",
1225 pdu.surfaceId, pdu.width, pdu.height, pdu.pixelFormat);
1234 const UINT drc = IFCALLRESULT(CHANNEL_RC_OK, context->DeleteSurface, context, &deletePdu);
1235 if (drc != CHANNEL_RC_OK)
1236 WLog_Print(gfx->base.log, WLOG_WARN,
1237 "context->DeleteSurface failed with error %" PRIu32
", ignoring", drc);
1239 IFCALLRET(context->CreateSurface, error, context, &pdu);
1242 WLog_Print(gfx->base.log, WLOG_ERROR,
1243 "context->CreateSurface failed with error %" PRIu32
"", error);
1257 WINPR_ASSERT(callback);
1260 RdpgfxClientContext* context = gfx->context;
1261 UINT error = CHANNEL_RC_OK;
1263 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 2))
1264 return ERROR_INVALID_DATA;
1266 Stream_Read_UINT16(s, pdu.surfaceId);
1267 WLog_Print(gfx->base.log, WLOG_DEBUG,
"RecvDeleteSurfacePdu: surfaceId: %" PRIu16
"",
1272 IFCALLRET(context->DeleteSurface, error, context, &pdu);
1275 WLog_Print(gfx->base.log, WLOG_ERROR,
1276 "context->DeleteSurface failed with error %" PRIu32
"", error);
1290 WINPR_ASSERT(callback);
1293 RdpgfxClientContext* context = gfx->context;
1294 UINT error = CHANNEL_RC_OK;
1296 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_START_FRAME_PDU_SIZE))
1297 return ERROR_INVALID_DATA;
1299 Stream_Read_UINT32(s, pdu.timestamp);
1300 Stream_Read_UINT32(s, pdu.frameId);
1301 WLog_Print(gfx->base.log, WLOG_TRACE,
1302 "RecvStartFramePdu: frameId: %" PRIu32
" timestamp: 0x%08" PRIX32
"", pdu.frameId,
1304 gfx->StartDecodingTime = GetTickCount64();
1308 IFCALLRET(context->StartFrame, error, context, &pdu);
1311 WLog_Print(gfx->base.log, WLOG_ERROR,
1312 "context->StartFrame failed with error %" PRIu32
"", error);
1315 gfx->UnacknowledgedFrames++;
1328 WINPR_ASSERT(callback);
1331 RdpgfxClientContext* context = gfx->context;
1332 UINT error = CHANNEL_RC_OK;
1334 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_END_FRAME_PDU_SIZE))
1335 return ERROR_INVALID_DATA;
1337 Stream_Read_UINT32(s, pdu.frameId);
1338 WLog_Print(gfx->base.log, WLOG_TRACE,
"RecvEndFramePdu: frameId: %" PRIu32
"", pdu.frameId);
1340 const UINT64 start = GetTickCount64();
1343 IFCALLRET(context->EndFrame, error, context, &pdu);
1347 WLog_Print(gfx->base.log, WLOG_ERROR,
"context->EndFrame failed with error %" PRIu32
"",
1352 const UINT64 end = GetTickCount64();
1353 const UINT64 EndFrameTime = end - start;
1354 gfx->TotalDecodedFrames++;
1356 if (!gfx->sendFrameAcks)
1359 ack.frameId = pdu.frameId;
1360 ack.totalFramesDecoded = gfx->TotalDecodedFrames;
1362 if (gfx->suspendFrameAcks)
1364 ack.queueDepth = SUSPEND_FRAME_ACKNOWLEDGEMENT;
1366 if (gfx->TotalDecodedFrames == 1)
1367 if ((error = rdpgfx_send_frame_acknowledge_pdu(context, &ack)))
1368 WLog_Print(gfx->base.log, WLOG_ERROR,
1369 "rdpgfx_send_frame_acknowledge_pdu failed with error %" PRIu32
"",
1374 ack.queueDepth = QUEUE_DEPTH_UNAVAILABLE;
1376 if ((error = rdpgfx_send_frame_acknowledge_pdu(context, &ack)))
1377 WLog_Print(gfx->base.log, WLOG_ERROR,
1378 "rdpgfx_send_frame_acknowledge_pdu failed with error %" PRIu32
"", error);
1381 switch (gfx->ConnectionCaps.version)
1383#if defined(WITH_GFX_AV1)
1384 case RDPGFX_CAPVERSION_FRDP_1:
1386 case RDPGFX_CAPVERSION_10:
1387 case RDPGFX_CAPVERSION_102:
1388 case RDPGFX_CAPVERSION_103:
1389 case RDPGFX_CAPVERSION_104:
1390 case RDPGFX_CAPVERSION_105:
1391 case RDPGFX_CAPVERSION_106:
1392 case RDPGFX_CAPVERSION_106_ERR:
1393 case RDPGFX_CAPVERSION_107:
1394#if defined(WITH_GFX_AZURE)
1395 case RDPGFX_CAPVERSION_111:
1396 case RDPGFX_CAPVERSION_112:
1397 case RDPGFX_CAPVERSION_113:
1402 UINT64 diff = (GetTickCount64() - gfx->StartDecodingTime);
1407 qoe.frameId = pdu.frameId;
1408 qoe.timestamp = gfx->StartDecodingTime % UINT32_MAX;
1409 qoe.timeDiffSE = WINPR_ASSERTING_INT_CAST(UINT16, diff);
1410 qoe.timeDiffEDR = WINPR_ASSERTING_INT_CAST(UINT16, EndFrameTime);
1412 if ((error = rdpgfx_send_qoe_frame_acknowledge_pdu(context, &qoe)))
1413 WLog_Print(gfx->base.log, WLOG_ERROR,
1414 "rdpgfx_send_qoe_frame_acknowledge_pdu failed with error %" PRIu32
1437 WINPR_ASSERT(callback);
1442 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_WIRE_TO_SURFACE_PDU_1_SIZE))
1443 return ERROR_INVALID_DATA;
1445 Stream_Read_UINT16(s, pdu.surfaceId);
1446 Stream_Read_UINT16(s, pdu.codecId);
1447 Stream_Read_UINT8(s, pdu.pixelFormat);
1449 if ((error = rdpgfx_read_rect16(gfx->base.log, s, &(pdu.destRect))))
1451 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_rect16 failed with error %" PRIu32
"",
1456 Stream_Read_UINT32(s, pdu.bitmapDataLength);
1458 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, pdu.bitmapDataLength))
1459 return ERROR_INVALID_DATA;
1461 pdu.bitmapData = Stream_Pointer(s);
1462 Stream_Seek(s, pdu.bitmapDataLength);
1464 WLog_Print(gfx->base.log, WLOG_TRACE,
1465 "RecvWireToSurface1Pdu: surfaceId: %" PRIu16
" codecId: %s (0x%04" PRIX16
1466 ") pixelFormat: 0x%02" PRIX8
" "
1467 "destRect: left: %" PRIu16
" top: %" PRIu16
" right: %" PRIu16
" bottom: %" PRIu16
1468 " bitmapDataLength: %" PRIu32
"",
1469 pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId, pdu.pixelFormat,
1470 pdu.destRect.left, pdu.destRect.top, pdu.destRect.right, pdu.destRect.bottom,
1471 pdu.bitmapDataLength);
1472 cmd.surfaceId = pdu.surfaceId;
1473 cmd.codecId = pdu.codecId;
1476 switch (pdu.pixelFormat)
1478 case GFX_PIXEL_FORMAT_XRGB_8888:
1479 cmd.format = PIXEL_FORMAT_BGRX32;
1482 case GFX_PIXEL_FORMAT_ARGB_8888:
1483 cmd.format = PIXEL_FORMAT_BGRA32;
1487 return ERROR_INVALID_DATA;
1490 cmd.left = pdu.destRect.left;
1491 cmd.top = pdu.destRect.top;
1492 cmd.right = pdu.destRect.right;
1493 cmd.bottom = pdu.destRect.bottom;
1494 cmd.width = cmd.right - cmd.left;
1495 cmd.height = cmd.bottom - cmd.top;
1496 cmd.length = pdu.bitmapDataLength;
1497 cmd.data = pdu.bitmapData;
1498 cmd.extra =
nullptr;
1500 if (cmd.right < cmd.left)
1502 WLog_Print(gfx->base.log, WLOG_ERROR,
1503 "RecvWireToSurface1Pdu right=%" PRIu32
" < left=%" PRIu32, cmd.right, cmd.left);
1504 return ERROR_INVALID_DATA;
1506 if (cmd.bottom < cmd.top)
1508 WLog_Print(gfx->base.log, WLOG_ERROR,
1509 "RecvWireToSurface1Pdu bottom=%" PRIu32
" < top=%" PRIu32, cmd.bottom, cmd.top);
1510 return ERROR_INVALID_DATA;
1513 if ((error = rdpgfx_decode(gfx, &cmd)))
1514 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_decode failed with error %" PRIu32
"!",
1523 switch (cmd->codecId)
1525 case RDPGFX_CODECID_UNCOMPRESSED:
1526 case RDPGFX_CODECID_CAVIDEO:
1527 case RDPGFX_CODECID_CLEARCODEC:
1528 case RDPGFX_CODECID_PLANAR:
1529 case RDPGFX_CODECID_AVC420:
1530 case RDPGFX_CODECID_ALPHA:
1531 case RDPGFX_CODECID_AVC444:
1532 case RDPGFX_CODECID_AVC444v2:
1533 case RDPGFX_CODECID_CAPROGRESSIVE:
1534 case RDPGFX_CODECID_CAPROGRESSIVE_V2:
1536#if defined(WITH_GFX_AV1)
1537 case RDPGFX_CODECID_AV1:
1538 if (gfx->ConnectionCaps.version != RDPGFX_CAPVERSION_FRDP_1)
1540 WLog_Print(gfx->base.log, WLOG_ERROR,
1541 "RDPGFX_SURFACE_COMMAND::codecId %" PRIu32
1542 " only supported with %s but connection uses %s [0x%08" PRIx32
"]",
1543 cmd->codecId, rdpgfx_caps_version_str(RDPGFX_CAPVERSION_FRDP_1),
1544 rdpgfx_caps_version_str(gfx->ConnectionCaps.version),
1545 gfx->ConnectionCaps.version);
1551 WLog_Print(gfx->base.log, WLOG_ERROR,
1552 "Unknown RDPGFX_SURFACE_COMMAND::codecId %" PRIu32, cmd->codecId);
1561 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Got GFX %s",
1562 rdpgfx_get_codec_id_string(WINPR_ASSERTING_INT_CAST(UINT16, cmd->codecId)));
1564 RdpgfxClientContext* context = gfx->context;
1566 return CHANNEL_RC_OK;
1568 if (!checkSurfaceCommand(gfx, cmd))
1569 return CHANNEL_RC_NULL_DATA;
1571 const UINT error = IFCALLRESULT(CHANNEL_RC_OK, context->SurfaceCommand, context, cmd);
1574 WLog_Print(gfx->base.log, WLOG_ERROR,
1575 "context->SurfaceCommand failed with error %" PRIu32
"", error);
1577 rdpgfx_codecid_event(context, cmd->codecId);
1591 WINPR_ASSERT(callback);
1595 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_WIRE_TO_SURFACE_PDU_2_SIZE))
1596 return ERROR_INVALID_DATA;
1598 Stream_Read_UINT16(s, pdu.surfaceId);
1599 Stream_Read_UINT16(s, pdu.codecId);
1600 Stream_Read_UINT32(s, pdu.codecContextId);
1601 Stream_Read_UINT8(s, pdu.pixelFormat);
1602 Stream_Read_UINT32(s, pdu.bitmapDataLength);
1603 pdu.bitmapData = Stream_Pointer(s);
1604 if (!Stream_SafeSeek(s, pdu.bitmapDataLength))
1605 return ERROR_INVALID_DATA;
1607 WLog_Print(gfx->base.log, WLOG_TRACE,
1608 "RecvWireToSurface2Pdu: surfaceId: %" PRIu16
" codecId: %s (0x%04" PRIX16
") "
1609 "codecContextId: %" PRIu32
" pixelFormat: 0x%02" PRIX8
" bitmapDataLength: %" PRIu32
1611 pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId,
1612 pdu.codecContextId, pdu.pixelFormat, pdu.bitmapDataLength);
1614 cmd.surfaceId = pdu.surfaceId;
1615 cmd.codecId = pdu.codecId;
1616 cmd.contextId = pdu.codecContextId;
1618 switch (pdu.pixelFormat)
1620 case GFX_PIXEL_FORMAT_XRGB_8888:
1621 cmd.format = PIXEL_FORMAT_BGRX32;
1624 case GFX_PIXEL_FORMAT_ARGB_8888:
1625 cmd.format = PIXEL_FORMAT_BGRA32;
1629 return ERROR_INVALID_DATA;
1632 cmd.length = pdu.bitmapDataLength;
1633 cmd.data = pdu.bitmapData;
1634 cmd.extra =
nullptr;
1636 return logSurfaceCommand(gfx, &cmd);
1647 WINPR_ASSERT(callback);
1650 RdpgfxClientContext* context = gfx->context;
1651 UINT error = CHANNEL_RC_OK;
1653 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 6))
1654 return ERROR_INVALID_DATA;
1656 Stream_Read_UINT16(s, pdu.surfaceId);
1657 Stream_Read_UINT32(s, pdu.codecContextId);
1659 WLog_Print(gfx->base.log, WLOG_DEBUG,
1660 "RecvDeleteEncodingContextPdu: surfaceId: %" PRIu16
" codecContextId: %" PRIu32
"",
1661 pdu.surfaceId, pdu.codecContextId);
1665 IFCALLRET(context->DeleteEncodingContext, error, context, &pdu);
1668 WLog_Print(gfx->base.log, WLOG_ERROR,
1669 "context->DeleteEncodingContext failed with error %" PRIu32
"", error);
1683 WINPR_ASSERT(callback);
1686 RdpgfxClientContext* context = gfx->context;
1688 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 8))
1689 return ERROR_INVALID_DATA;
1691 Stream_Read_UINT16(s, pdu.surfaceId);
1693 UINT error = rdpgfx_read_color32(gfx->base.log, s, &(pdu.fillPixel));
1694 if (error != CHANNEL_RC_OK)
1696 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_color32 failed with error %" PRIu32
"!",
1701 Stream_Read_UINT16(s, pdu.fillRectCount);
1703 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.fillRectCount, 8ull))
1704 return ERROR_INVALID_DATA;
1710 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
1711 return CHANNEL_RC_NO_MEMORY;
1714 for (UINT16 index = 0; index < pdu.fillRectCount; index++)
1718 if ((error = rdpgfx_read_rect16(gfx->base.log, s, fillRect)))
1720 WLog_Print(gfx->base.log, WLOG_ERROR,
1721 "rdpgfx_read_rect16 failed with error %" PRIu32
"!", error);
1722 free(pdu.fillRects);
1726 WLog_Print(gfx->base.log, WLOG_TRACE,
1727 "RecvSolidFillPdu: surfaceId: %" PRIu16
" fillRectCount: %" PRIu16
"", pdu.surfaceId,
1732 IFCALLRET(context->SolidFill, error, context, &pdu);
1735 WLog_Print(gfx->base.log, WLOG_ERROR,
1736 "context->SolidFill failed with error %" PRIu32
"", error);
1739 free(pdu.fillRects);
1751 WINPR_ASSERT(callback);
1754 RdpgfxClientContext* context = gfx->context;
1757 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 14))
1758 return ERROR_INVALID_DATA;
1760 Stream_Read_UINT16(s, pdu.surfaceIdSrc);
1761 Stream_Read_UINT16(s, pdu.surfaceIdDest);
1763 if ((error = rdpgfx_read_rect16(gfx->base.log, s, &(pdu.rectSrc))))
1765 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_rect16 failed with error %" PRIu32
"!",
1770 Stream_Read_UINT16(s, pdu.destPtsCount);
1772 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.destPtsCount, 4ull))
1773 return ERROR_INVALID_DATA;
1779 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
1780 return CHANNEL_RC_NO_MEMORY;
1783 for (UINT16 index = 0; index < pdu.destPtsCount; index++)
1787 if ((error = rdpgfx_read_point16(gfx->base.log, s, destPt)))
1789 WLog_Print(gfx->base.log, WLOG_ERROR,
1790 "rdpgfx_read_point16 failed with error %" PRIu32
"!", error);
1796 WLog_Print(gfx->base.log, WLOG_TRACE,
1797 "RecvSurfaceToSurfacePdu: surfaceIdSrc: %" PRIu16
" surfaceIdDest: %" PRIu16
" "
1798 "left: %" PRIu16
" top: %" PRIu16
" right: %" PRIu16
" bottom: %" PRIu16
1799 " destPtsCount: %" PRIu16
"",
1800 pdu.surfaceIdSrc, pdu.surfaceIdDest, pdu.rectSrc.left, pdu.rectSrc.top,
1801 pdu.rectSrc.right, pdu.rectSrc.bottom, pdu.destPtsCount);
1805 IFCALLRET(context->SurfaceToSurface, error, context, &pdu);
1808 WLog_Print(gfx->base.log, WLOG_ERROR,
1809 "context->SurfaceToSurface failed with error %" PRIu32
"", error);
1824 WINPR_ASSERT(callback);
1828 RdpgfxClientContext* context = gfx->context;
1830 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 20))
1831 return ERROR_INVALID_DATA;
1833 Stream_Read_UINT16(s, pdu.surfaceId);
1834 Stream_Read_UINT64(s, pdu.cacheKey);
1835 Stream_Read_UINT16(s, pdu.cacheSlot);
1837 UINT error = rdpgfx_read_rect16(gfx->base.log, s, &(pdu.rectSrc));
1838 if (error != CHANNEL_RC_OK)
1840 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_rect16 failed with error %" PRIu32
"!",
1845 WLog_Print(gfx->base.log, WLOG_TRACE,
1846 "RecvSurfaceToCachePdu: surfaceId: %" PRIu16
" cacheKey: 0x%016" PRIX64
1847 " cacheSlot: %" PRIu16
" "
1848 "left: %" PRIu16
" top: %" PRIu16
" right: %" PRIu16
" bottom: %" PRIu16
"",
1849 pdu.surfaceId, pdu.cacheKey, pdu.cacheSlot, pdu.rectSrc.left, pdu.rectSrc.top,
1850 pdu.rectSrc.right, pdu.rectSrc.bottom);
1854 IFCALLRET(context->SurfaceToCache, error, context, &pdu);
1857 WLog_Print(gfx->base.log, WLOG_ERROR,
1858 "context->SurfaceToCache failed with error %" PRIu32
"", error);
1872 WINPR_ASSERT(callback);
1876 RdpgfxClientContext* context = gfx->context;
1877 UINT error = CHANNEL_RC_OK;
1879 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 6))
1880 return ERROR_INVALID_DATA;
1882 Stream_Read_UINT16(s, pdu.cacheSlot);
1883 Stream_Read_UINT16(s, pdu.surfaceId);
1884 Stream_Read_UINT16(s, pdu.destPtsCount);
1886 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.destPtsCount, 4ull))
1887 return ERROR_INVALID_DATA;
1893 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
1894 return CHANNEL_RC_NO_MEMORY;
1897 for (UINT16 index = 0; index < pdu.destPtsCount; index++)
1901 if ((error = rdpgfx_read_point16(gfx->base.log, s, destPt)))
1903 WLog_Print(gfx->base.log, WLOG_ERROR,
1904 "rdpgfx_read_point16 failed with error %" PRIu32
"", error);
1910 WLog_Print(gfx->base.log, WLOG_TRACE,
1911 "RdpGfxRecvCacheToSurfacePdu: cacheSlot: %" PRIu16
" surfaceId: %" PRIu16
1912 " destPtsCount: %" PRIu16
"",
1913 pdu.cacheSlot, pdu.surfaceId, pdu.destPtsCount);
1917 IFCALLRET(context->CacheToSurface, error, context, &pdu);
1920 WLog_Print(gfx->base.log, WLOG_ERROR,
1921 "context->CacheToSurface failed with error %" PRIu32
"", error);
1936 WINPR_ASSERT(callback);
1940 RdpgfxClientContext* context = gfx->context;
1941 UINT error = CHANNEL_RC_OK;
1943 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 12))
1944 return ERROR_INVALID_DATA;
1946 Stream_Read_UINT16(s, pdu.surfaceId);
1947 Stream_Read_UINT16(s, pdu.reserved);
1948 Stream_Read_UINT32(s, pdu.outputOriginX);
1949 Stream_Read_UINT32(s, pdu.outputOriginY);
1950 WLog_Print(gfx->base.log, WLOG_DEBUG,
1951 "RecvMapSurfaceToOutputPdu: surfaceId: %" PRIu16
" outputOriginX: %" PRIu32
1952 " outputOriginY: %" PRIu32
"",
1953 pdu.surfaceId, pdu.outputOriginX, pdu.outputOriginY);
1957 IFCALLRET(context->MapSurfaceToOutput, error, context, &pdu);
1960 WLog_Print(gfx->base.log, WLOG_ERROR,
1961 "context->MapSurfaceToOutput failed with error %" PRIu32
"", error);
1971 WINPR_ASSERT(callback);
1975 RdpgfxClientContext* context = gfx->context;
1976 UINT error = CHANNEL_RC_OK;
1978 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 20))
1979 return ERROR_INVALID_DATA;
1981 Stream_Read_UINT16(s, pdu.surfaceId);
1982 Stream_Read_UINT16(s, pdu.reserved);
1983 Stream_Read_UINT32(s, pdu.outputOriginX);
1984 Stream_Read_UINT32(s, pdu.outputOriginY);
1985 Stream_Read_UINT32(s, pdu.targetWidth);
1986 Stream_Read_UINT32(s, pdu.targetHeight);
1987 WLog_Print(gfx->base.log, WLOG_DEBUG,
1988 "RecvMapSurfaceToScaledOutputPdu: surfaceId: %" PRIu16
" outputOriginX: %" PRIu32
1989 " outputOriginY: %" PRIu32
" targetWidth: %" PRIu32
" targetHeight: %" PRIu32,
1990 pdu.surfaceId, pdu.outputOriginX, pdu.outputOriginY, pdu.targetWidth,
1995 IFCALLRET(context->MapSurfaceToScaledOutput, error, context, &pdu);
1998 WLog_Print(gfx->base.log, WLOG_ERROR,
1999 "context->MapSurfaceToScaledOutput failed with error %" PRIu32
"", error);
2013 WINPR_ASSERT(callback);
2017 RdpgfxClientContext* context = gfx->context;
2018 UINT error = CHANNEL_RC_OK;
2020 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 18))
2021 return ERROR_INVALID_DATA;
2023 Stream_Read_UINT16(s, pdu.surfaceId);
2024 Stream_Read_UINT64(s, pdu.windowId);
2025 Stream_Read_UINT32(s, pdu.mappedWidth);
2026 Stream_Read_UINT32(s, pdu.mappedHeight);
2028 if ((pdu.mappedWidth > MAX_SURFACE_SIZE) || (pdu.mappedHeight > MAX_SURFACE_SIZE))
2030 WLog_Print(gfx->base.log, WLOG_ERROR,
2031 "context->MapSurfaceToWindow mappedWidth[%" PRIu32
"], mappedHeight[%" PRIu32
2033 pdu.mappedWidth, pdu.mappedHeight, MAX_SURFACE_SIZE);
2034 return ERROR_INVALID_DATA;
2037 WLog_Print(gfx->base.log, WLOG_DEBUG,
2038 "RecvMapSurfaceToWindowPdu: surfaceId: %" PRIu16
" windowId: 0x%016" PRIX64
2039 " mappedWidth: %" PRIu32
" mappedHeight: %" PRIu32
"",
2040 pdu.surfaceId, pdu.windowId, pdu.mappedWidth, pdu.mappedHeight);
2042 if (context && context->MapSurfaceToWindow)
2044 IFCALLRET(context->MapSurfaceToWindow, error, context, &pdu);
2047 WLog_Print(gfx->base.log, WLOG_ERROR,
2048 "context->MapSurfaceToWindow failed with error %" PRIu32
"", error);
2058 WINPR_ASSERT(callback);
2061 RdpgfxClientContext* context = gfx->context;
2062 UINT error = CHANNEL_RC_OK;
2064 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 26))
2065 return ERROR_INVALID_DATA;
2067 Stream_Read_UINT16(s, pdu.surfaceId);
2068 Stream_Read_UINT64(s, pdu.windowId);
2069 Stream_Read_UINT32(s, pdu.mappedWidth);
2070 Stream_Read_UINT32(s, pdu.mappedHeight);
2071 Stream_Read_UINT32(s, pdu.targetWidth);
2072 Stream_Read_UINT32(s, pdu.targetHeight);
2074 if ((pdu.mappedWidth > MAX_SURFACE_SIZE) || (pdu.mappedHeight > MAX_SURFACE_SIZE))
2076 WLog_Print(gfx->base.log, WLOG_ERROR,
2077 "context->RecvMapSurfaceToScaledWindowPdu mappedWidth[%" PRIu32
2078 "], mappedHeight[%" PRIu32
"] > %" PRIu32,
2079 pdu.mappedWidth, pdu.mappedHeight, MAX_SURFACE_SIZE);
2080 return ERROR_INVALID_DATA;
2083 WLog_Print(gfx->base.log, WLOG_DEBUG,
2084 "RecvMapSurfaceToScaledWindowPdu: surfaceId: %" PRIu16
" windowId: 0x%016" PRIX64
2085 " mappedWidth: %" PRIu32
" mappedHeight: %" PRIu32
" targetWidth: %" PRIu32
2086 " targetHeight: %" PRIu32
"",
2087 pdu.surfaceId, pdu.windowId, pdu.mappedWidth, pdu.mappedHeight, pdu.targetWidth,
2090 if (context && context->MapSurfaceToScaledWindow)
2092 IFCALLRET(context->MapSurfaceToScaledWindow, error, context, &pdu);
2095 WLog_Print(gfx->base.log, WLOG_ERROR,
2096 "context->MapSurfaceToScaledWindow failed with error %" PRIu32
"", error);
2111 WINPR_ASSERT(callback);
2113 const size_t beg = Stream_GetPosition(s);
2117 size_t packetlen = 0;
2118 UINT error = rdpgfx_read_header(gfx->base.log, s, &header, &packetlen);
2119 if (error != CHANNEL_RC_OK)
2121 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_header failed with error %" PRIu32
"!",
2126 WLog_Print(gfx->base.log, WLOG_TRACE,
2127 "cmdId: %s (0x%04" PRIX16
") flags: 0x%04" PRIX16
" pduLength: %" PRIu32
"",
2128 rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId, header.flags,
2131 rdpgfx_stats_cmdid_event(gfx->context, header.cmdId);
2132 switch (header.cmdId)
2134 case RDPGFX_CMDID_WIRETOSURFACE_1:
2135 if ((error = rdpgfx_recv_wire_to_surface_1_pdu(callback, s)))
2136 WLog_Print(gfx->base.log, WLOG_ERROR,
2137 "rdpgfx_recv_wire_to_surface_1_pdu failed with error %" PRIu32
"!",
2142 case RDPGFX_CMDID_WIRETOSURFACE_2:
2143 if ((error = rdpgfx_recv_wire_to_surface_2_pdu(callback, s)))
2144 WLog_Print(gfx->base.log, WLOG_ERROR,
2145 "rdpgfx_recv_wire_to_surface_2_pdu failed with error %" PRIu32
"!",
2150 case RDPGFX_CMDID_DELETEENCODINGCONTEXT:
2151 if ((error = rdpgfx_recv_delete_encoding_context_pdu(callback, s)))
2152 WLog_Print(gfx->base.log, WLOG_ERROR,
2153 "rdpgfx_recv_delete_encoding_context_pdu failed with error %" PRIu32
"!",
2158 case RDPGFX_CMDID_SOLIDFILL:
2159 if ((error = rdpgfx_recv_solid_fill_pdu(callback, s)))
2160 WLog_Print(gfx->base.log, WLOG_ERROR,
2161 "rdpgfx_recv_solid_fill_pdu failed with error %" PRIu32
"!", error);
2165 case RDPGFX_CMDID_SURFACETOSURFACE:
2166 if ((error = rdpgfx_recv_surface_to_surface_pdu(callback, s)))
2167 WLog_Print(gfx->base.log, WLOG_ERROR,
2168 "rdpgfx_recv_surface_to_surface_pdu failed with error %" PRIu32
"!",
2173 case RDPGFX_CMDID_SURFACETOCACHE:
2174 if ((error = rdpgfx_recv_surface_to_cache_pdu(callback, s)))
2175 WLog_Print(gfx->base.log, WLOG_ERROR,
2176 "rdpgfx_recv_surface_to_cache_pdu failed with error %" PRIu32
"!",
2181 case RDPGFX_CMDID_CACHETOSURFACE:
2182 if ((error = rdpgfx_recv_cache_to_surface_pdu(callback, s)))
2183 WLog_Print(gfx->base.log, WLOG_ERROR,
2184 "rdpgfx_recv_cache_to_surface_pdu failed with error %" PRIu32
"!",
2189 case RDPGFX_CMDID_EVICTCACHEENTRY:
2190 if ((error = rdpgfx_recv_evict_cache_entry_pdu(callback, s)))
2191 WLog_Print(gfx->base.log, WLOG_ERROR,
2192 "rdpgfx_recv_evict_cache_entry_pdu failed with error %" PRIu32
"!",
2197 case RDPGFX_CMDID_CREATESURFACE:
2198 if ((error = rdpgfx_recv_create_surface_pdu(callback, s)))
2199 WLog_Print(gfx->base.log, WLOG_ERROR,
2200 "rdpgfx_recv_create_surface_pdu failed with error %" PRIu32
"!", error);
2204 case RDPGFX_CMDID_DELETESURFACE:
2205 if ((error = rdpgfx_recv_delete_surface_pdu(callback, s)))
2206 WLog_Print(gfx->base.log, WLOG_ERROR,
2207 "rdpgfx_recv_delete_surface_pdu failed with error %" PRIu32
"!", error);
2211 case RDPGFX_CMDID_STARTFRAME:
2212 if ((error = rdpgfx_recv_start_frame_pdu(callback, s)))
2213 WLog_Print(gfx->base.log, WLOG_ERROR,
2214 "rdpgfx_recv_start_frame_pdu failed with error %" PRIu32
"!", error);
2218 case RDPGFX_CMDID_ENDFRAME:
2219 if ((error = rdpgfx_recv_end_frame_pdu(callback, s)))
2220 WLog_Print(gfx->base.log, WLOG_ERROR,
2221 "rdpgfx_recv_end_frame_pdu failed with error %" PRIu32
"!", error);
2225 case RDPGFX_CMDID_RESETGRAPHICS:
2226 if ((error = rdpgfx_recv_reset_graphics_pdu(callback, s)))
2227 WLog_Print(gfx->base.log, WLOG_ERROR,
2228 "rdpgfx_recv_reset_graphics_pdu failed with error %" PRIu32
"!", error);
2232 case RDPGFX_CMDID_MAPSURFACETOOUTPUT:
2233 if ((error = rdpgfx_recv_map_surface_to_output_pdu(callback, s)))
2234 WLog_Print(gfx->base.log, WLOG_ERROR,
2235 "rdpgfx_recv_map_surface_to_output_pdu failed with error %" PRIu32
"!",
2240 case RDPGFX_CMDID_CACHEIMPORTREPLY:
2241 if ((error = rdpgfx_recv_cache_import_reply_pdu(callback, s)))
2242 WLog_Print(gfx->base.log, WLOG_ERROR,
2243 "rdpgfx_recv_cache_import_reply_pdu failed with error %" PRIu32
"!",
2248 case RDPGFX_CMDID_CAPSCONFIRM:
2249 if ((error = rdpgfx_recv_caps_confirm_pdu(callback, s)))
2250 WLog_Print(gfx->base.log, WLOG_ERROR,
2251 "rdpgfx_recv_caps_confirm_pdu failed with error %" PRIu32
"!", error);
2253 if ((error = rdpgfx_send_cache_offer(gfx)))
2254 WLog_Print(gfx->base.log, WLOG_ERROR,
2255 "rdpgfx_send_cache_offer failed with error %" PRIu32
"!", error);
2259 case RDPGFX_CMDID_MAPSURFACETOWINDOW:
2260 if ((error = rdpgfx_recv_map_surface_to_window_pdu(callback, s)))
2261 WLog_Print(gfx->base.log, WLOG_ERROR,
2262 "rdpgfx_recv_map_surface_to_window_pdu failed with error %" PRIu32
"!",
2267 case RDPGFX_CMDID_MAPSURFACETOSCALEDWINDOW:
2268 if ((error = rdpgfx_recv_map_surface_to_scaled_window_pdu(callback, s)))
2269 WLog_Print(gfx->base.log, WLOG_ERROR,
2270 "rdpgfx_recv_map_surface_to_scaled_window_pdu failed with error %" PRIu32
2276 case RDPGFX_CMDID_MAPSURFACETOSCALEDOUTPUT:
2277 if ((error = rdpgfx_recv_map_surface_to_scaled_output_pdu(callback, s)))
2278 WLog_Print(gfx->base.log, WLOG_ERROR,
2279 "rdpgfx_recv_map_surface_to_scaled_output_pdu failed with error %" PRIu32
2285 case RDPGFX_CMDID_PROTECT_SURFACE:
2286 case RDPGFX_CMDID_WATERMARK:
2287 WLog_Print(gfx->base.log, WLOG_WARN,
2288 "Command %s not implemented, skipping %" PRIu32
" bytes",
2289 rdpgfx_get_cmd_id_string(header.cmdId), header.pduLength);
2290 if (!Stream_SafeSeek(s, packetlen))
2291 error = ERROR_INVALID_DATA;
2294 error = CHANNEL_RC_BAD_PROC;
2300 WLog_Print(gfx->base.log, WLOG_ERROR,
2301 "Error while processing GFX cmdId: %s (0x%04" PRIX16
")",
2302 rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId);
2303 if (!Stream_SetPosition(s, (beg + header.pduLength)))
2304 return ERROR_INVALID_DATA;
2308 const size_t end = Stream_GetPosition(s);
2310 if (end != (beg + header.pduLength))
2312 WLog_Print(gfx->base.log, WLOG_ERROR,
2313 "Unexpected gfx pdu end: Actual: %" PRIuz
", Expected: %" PRIuz, end,
2314 (beg + header.pduLength));
2315 if (!Stream_SetPosition(s, (beg + header.pduLength)))
2316 return ERROR_INVALID_DATA;
2327static UINT rdpgfx_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
wStream* data)
2330 BYTE* pDstData =
nullptr;
2332 WINPR_ASSERT(callback);
2334 UINT error = CHANNEL_RC_OK;
2337 int status = zgfx_decompress(gfx->zgfx, Stream_ConstPointer(data),
2338 (UINT32)Stream_GetRemainingLength(data), &pDstData, &DstSize, 0);
2342 WLog_Print(gfx->base.log, WLOG_ERROR,
"zgfx_decompress failure! status: %d", status);
2344 return ERROR_INTERNAL_ERROR;
2347 wStream sbuffer = WINPR_C_ARRAY_INIT;
2348 wStream* s = Stream_StaticConstInit(&sbuffer, pDstData, DstSize);
2352 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
2354 return CHANNEL_RC_NO_MEMORY;
2357 while (Stream_GetPosition(s) < Stream_Length(s))
2359 if ((error = rdpgfx_recv_pdu(callback, s)))
2361 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_recv_pdu failed with error %" PRIu32
"!",
2376static UINT rdpgfx_on_open(IWTSVirtualChannelCallback* pChannelCallback)
2379 WINPR_ASSERT(callback);
2382 RdpgfxClientContext* context = gfx->context;
2383 UINT error = CHANNEL_RC_OK;
2384 BOOL do_caps_advertise = TRUE;
2386 gfx->sendFrameAcks = TRUE;
2390 IFCALLRET(context->OnOpen, error, context, &do_caps_advertise, &gfx->sendFrameAcks);
2393 WLog_Print(gfx->base.log, WLOG_ERROR,
"context->OnOpen failed with error %" PRIu32
"",
2396 RdpgfxClientContextInt* ctx = (RdpgfxClientContextInt*)context;
2397 const RdpgfxClientContextStats empty = WINPR_C_ARRAY_INIT;
2401 if (do_caps_advertise)
2402 error = rdpgfx_send_supported_caps(callback);
2407static void rdpgfx_dump_stats(RdpgfxClientContext* context)
2409 WINPR_ASSERT(context);
2414 wLog* log = gfx->base.log;
2415 const DWORD level = WLOG_TRACE;
2416 if (!WLog_IsLevelActive(log, level))
2419 WLog_Print(log, level,
"RdpgfxClientContextStats");
2420 for (
size_t x = 0; x < rdpgfx_stats_max_index(); x++)
2422 const char* name = rdpgfx_stats_name_for_index(x);
2423 const uint64_t val = rdpgfx_stats_value_for_index(context, x);
2424 WLog_Print(log, level,
"%s: %" PRIu64, name, val);
2433static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback)
2435 UINT error = CHANNEL_RC_OK;
2437 WINPR_ASSERT(callback);
2443 RdpgfxClientContext* context = gfx->context;
2445 WLog_Print(gfx->base.log, WLOG_DEBUG,
"OnClose");
2446 error = rdpgfx_save_persistent_cache(gfx);
2451 WLog_Print(gfx->base.log, WLOG_ERROR,
2452 "rdpgfx_save_persistent_cache failed with error %" PRIu32
"", error);
2455 free_surfaces(context, gfx->SurfaceTable);
2456 error = evict_cache_slots(context, gfx->MaxCacheSlots, gfx->CacheSlots);
2460 WLog_Print(gfx->base.log, WLOG_ERROR,
"evict_cache_slots failed with error %" PRIu32
"",
2465 gfx->UnacknowledgedFrames = 0;
2466 gfx->TotalDecodedFrames = 0;
2470 error = IFCALLRESULT(CHANNEL_RC_OK, context->OnClose, context);
2474 WLog_Print(gfx->base.log, WLOG_ERROR,
"context->OnClose failed with error %" PRIu32
"",
2477 rdpgfx_dump_stats(context);
2481 return CHANNEL_RC_OK;
2488 RdpgfxClientContext* context = gfx->context;
2490 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Terminated");
2491 rdpgfx_client_context_free(context);
2499static UINT rdpgfx_set_surface_data(RdpgfxClientContext* context, UINT16 surfaceId,
void* pData)
2501 WINPR_ASSERT(context);
2504 ULONG_PTR key = ((ULONG_PTR)surfaceId) + 1;
2508 if (!HashTable_Insert(gfx->SurfaceTable, (
void*)key, pData))
2509 return ERROR_BAD_ARGUMENTS;
2512 HashTable_Remove(gfx->SurfaceTable, (
void*)key);
2514 return CHANNEL_RC_OK;
2522static UINT rdpgfx_get_surface_ids(RdpgfxClientContext* context, UINT16** ppSurfaceIds,
2525 ULONG_PTR* pKeys =
nullptr;
2526 WINPR_ASSERT(context);
2529 size_t count = HashTable_GetKeys(gfx->SurfaceTable, &pKeys);
2531 WINPR_ASSERT(ppSurfaceIds);
2532 WINPR_ASSERT(count_out);
2536 return CHANNEL_RC_OK;
2539 UINT16* pSurfaceIds = (UINT16*)calloc(count,
sizeof(UINT16));
2543 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
2545 return CHANNEL_RC_NO_MEMORY;
2548 for (
size_t index = 0; index < count; index++)
2550 pSurfaceIds[index] = (UINT16)(pKeys[index] - 1);
2554 *ppSurfaceIds = pSurfaceIds;
2555 *count_out = (UINT16)count;
2556 return CHANNEL_RC_OK;
2559static void* rdpgfx_get_surface_data(RdpgfxClientContext* context, UINT16 surfaceId)
2561 WINPR_ASSERT(context);
2564 ULONG_PTR key = ((ULONG_PTR)surfaceId) + 1;
2565 return HashTable_GetItemValue(gfx->SurfaceTable, (
void*)key);
2573static UINT rdpgfx_set_cache_slot_data(RdpgfxClientContext* context, UINT16 cacheSlot,
void* pData)
2575 WINPR_ASSERT(context);
2580 if (cacheSlot == 0 || cacheSlot > gfx->MaxCacheSlots)
2582 WLog_Print(gfx->base.log, WLOG_ERROR,
2583 "invalid cache slot %" PRIu16
", must be between 1 and %" PRIu16
"", cacheSlot,
2584 gfx->MaxCacheSlots);
2585 return ERROR_INVALID_INDEX;
2588 gfx->CacheSlots[cacheSlot - 1] = pData;
2589 return CHANNEL_RC_OK;
2592static void* rdpgfx_get_cache_slot_data(RdpgfxClientContext* context, UINT16 cacheSlot)
2594 WINPR_ASSERT(context);
2598 if (cacheSlot == 0 || cacheSlot > gfx->MaxCacheSlots)
2600 WLog_Print(gfx->base.log, WLOG_ERROR,
2601 "invalid cache slot %" PRIu16
", must be between 1 and %" PRIu16
"", cacheSlot,
2602 gfx->MaxCacheSlots);
2606 return gfx->CacheSlots[cacheSlot - 1];
2610 WINPR_ATTR_UNUSED rdpSettings* settings)
2615 gfx->rdpcontext = rcontext;
2617 gfx->SurfaceTable = HashTable_New(TRUE);
2618 if (!gfx->SurfaceTable)
2620 WLog_Print(gfx->base.log, WLOG_ERROR,
"HashTable_New for surfaces failed !");
2621 return CHANNEL_RC_NO_MEMORY;
2624 gfx->suspendFrameAcks =
2626 gfx->MaxCacheSlots =
2629 RdpgfxClientContextInt* context =
2630 (RdpgfxClientContextInt*)calloc(1,
sizeof(RdpgfxClientContextInt));
2633 WLog_Print(gfx->base.log, WLOG_ERROR,
"context calloc failed!");
2634 HashTable_Free(gfx->SurfaceTable);
2635 gfx->SurfaceTable =
nullptr;
2636 return CHANNEL_RC_NO_MEMORY;
2639 gfx->zgfx = zgfx_context_new(FALSE);
2642 WLog_Print(gfx->base.log, WLOG_ERROR,
"zgfx_context_new failed!");
2643 HashTable_Free(gfx->SurfaceTable);
2644 gfx->SurfaceTable =
nullptr;
2646 return CHANNEL_RC_NO_MEMORY;
2649 context->common.handle = (
void*)gfx;
2650 context->common.GetSurfaceIds = rdpgfx_get_surface_ids;
2651 context->common.SetSurfaceData = rdpgfx_set_surface_data;
2652 context->common.GetSurfaceData = rdpgfx_get_surface_data;
2653 context->common.SetCacheSlotData = rdpgfx_set_cache_slot_data;
2654 context->common.GetCacheSlotData = rdpgfx_get_cache_slot_data;
2655 context->common.CapsAdvertise = rdpgfx_send_caps_advertise_pdu;
2656 context->common.FrameAcknowledge = rdpgfx_send_frame_acknowledge_pdu;
2657 context->common.CacheImportOffer = rdpgfx_send_cache_import_offer_pdu;
2658 context->common.QoeFrameAcknowledge = rdpgfx_send_qoe_frame_acknowledge_pdu;
2660 gfx->base.iface.pInterface = (
void*)context;
2661 gfx->context = &context->common;
2662 return CHANNEL_RC_OK;
2665void rdpgfx_client_context_free(RdpgfxClientContext* context)
2672 free_surfaces(context, gfx->SurfaceTable);
2673 evict_cache_slots(context, gfx->MaxCacheSlots, gfx->CacheSlots);
2677 zgfx_context_free(gfx->zgfx);
2678 gfx->zgfx =
nullptr;
2681 HashTable_Free(gfx->SurfaceTable);
2685static const IWTSVirtualChannelCallback rdpgfx_callbacks = { rdpgfx_on_data_received,
2686 rdpgfx_on_open, rdpgfx_on_close,
2694FREERDP_ENTRY_POINT(UINT VCAPITYPE rdpgfx_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))
2696 return freerdp_generic_DVCPluginEntry(pEntryPoints, GFXTAG, RDPGFX_DVC_CHANNEL_NAME,
2698 &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.