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")
49static BOOL delete_surface(
const void* key,
void* value,
void* arg)
51 const UINT16
id = (UINT16)(uintptr_t)(key);
55 RdpgfxClientContext* context = arg;
62 UINT error = CHANNEL_RC_OK;
63 IFCALLRET(context->DeleteSurface, error, context, &pdu);
69 WLog_Print(gfx->base.log, WLOG_ERROR,
70 "context->DeleteSurface failed with error %" PRIu32
"", error);
76static void free_surfaces(RdpgfxClientContext* context, wHashTable* SurfaceTable)
78 WINPR_ASSERT(context);
79 if (!HashTable_Foreach(SurfaceTable, delete_surface, context))
83 WLog_Print(gfx->base.log, WLOG_WARN,
"delete_surface failed");
87static UINT evict_cache_slots(RdpgfxClientContext* context, UINT16 MaxCacheSlots,
void** CacheSlots)
89 UINT error = CHANNEL_RC_OK;
91 WINPR_ASSERT(CacheSlots);
92 for (UINT16 index = 0; index < MaxCacheSlots; index++)
94 if (CacheSlots[index])
98 if (context && context->EvictCacheEntry)
100 const UINT rc = context->EvictCacheEntry(context, &pdu);
101 if (rc != CHANNEL_RC_OK)
105 CacheSlots[index] =
nullptr;
116static UINT rdpgfx_send_caps_advertise_pdu(RdpgfxClientContext* context,
119 UINT error = CHANNEL_RC_OK;
122 WINPR_ASSERT(context);
126 if (!gfx || !gfx->base.listener_callback)
127 return ERROR_BAD_ARGUMENTS;
132 .cmdId = RDPGFX_CMDID_CAPSADVERTISE,
133 .pduLength = RDPGFX_HEADER_SIZE + 2 };
135 for (UINT16 index = 0; index < pdu->capsSetCount; index++)
138 header.pduLength += RDPGFX_CAPSET_BASE_SIZE + capsSet->length;
141 WLog_Print(gfx->base.log, WLOG_DEBUG,
"SendCapsAdvertisePdu %" PRIu16
"", pdu->capsSetCount);
142 wStream* s = Stream_New(
nullptr, header.pduLength);
146 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
147 return CHANNEL_RC_NO_MEMORY;
150 if ((error = rdpgfx_write_header(s, &header)))
154 Stream_Write_UINT16(s, pdu->capsSetCount);
156 for (UINT16 index = 0; index < pdu->capsSetCount; index++)
160 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Sending %s [0x%08" PRIx32
"] flags=0x%08" PRIx32,
161 rdpgfx_caps_version_str(capsSet->version), capsSet->version, capsSet->flags);
163 Stream_Write_UINT32(s, capsSet->version);
164 Stream_Write_UINT32(s, capsSet->length);
165 Stream_Write_UINT32(s, capsSet->flags);
166 Stream_Zero(s, capsSet->length - 4);
169 Stream_SealLength(s);
170 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
173 Stream_Free(s, TRUE);
177static BOOL rdpgfx_is_capability_filtered(
RDPGFX_PLUGIN* gfx, UINT32 caps)
180 const UINT32 filter =
182 const UINT32 capList[] = { RDPGFX_CAPVERSION_8, RDPGFX_CAPVERSION_81,
183 RDPGFX_CAPVERSION_10, RDPGFX_CAPVERSION_101,
184 RDPGFX_CAPVERSION_102, RDPGFX_CAPVERSION_103,
185 RDPGFX_CAPVERSION_104, RDPGFX_CAPVERSION_105,
186 RDPGFX_CAPVERSION_106, RDPGFX_CAPVERSION_106_ERR,
187 RDPGFX_CAPVERSION_107 };
189 for (
size_t x = 0; x < ARRAYSIZE(capList); x++)
191 if (caps == capList[x])
192 return (filter & (1u << x)) != 0;
205 RDPGFX_CAPSET capsSets[RDPGFX_NUMBER_CAPSETS] = WINPR_C_ARRAY_INIT;
208 return ERROR_BAD_ARGUMENTS;
213 return ERROR_BAD_CONFIGURATION;
215 RdpgfxClientContext* context = gfx->context;
218 return ERROR_BAD_CONFIGURATION;
222 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_8))
225 capsSet->version = RDPGFX_CAPVERSION_8;
230 capsSet->flags |= RDPGFX_CAPS_FLAG_THINCLIENT;
237 capsSet->flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE;
240 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_81))
243 capsSet->version = RDPGFX_CAPVERSION_81;
248 capsSet->flags |= RDPGFX_CAPS_FLAG_THINCLIENT;
251 capsSet->flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE;
256 capsSet->flags |= RDPGFX_CAPS_FLAG_AVC420_ENABLED;
264 UINT32 caps10Flags = 0;
267 caps10Flags |= RDPGFX_CAPS_FLAG_SMALL_CACHE;
272 caps10Flags |= RDPGFX_CAPS_FLAG_AVC_DISABLED;
275 caps10Flags |= RDPGFX_CAPS_FLAG_AVC_DISABLED;
278 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_10))
281 capsSet->version = RDPGFX_CAPVERSION_10;
283 capsSet->flags = caps10Flags;
286 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_101))
289 capsSet->version = RDPGFX_CAPVERSION_101;
290 capsSet->length = 0x10;
294 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_102))
297 capsSet->version = RDPGFX_CAPVERSION_102;
298 capsSet->length = 0x4;
299 capsSet->flags = caps10Flags;
304 if ((caps10Flags & RDPGFX_CAPS_FLAG_AVC_DISABLED) == 0)
305 caps10Flags |= RDPGFX_CAPS_FLAG_AVC_THINCLIENT;
308 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_103))
311 capsSet->version = RDPGFX_CAPVERSION_103;
312 capsSet->length = 0x4;
313 capsSet->flags = caps10Flags & ~RDPGFX_CAPS_FLAG_SMALL_CACHE;
316 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_104))
319 capsSet->version = RDPGFX_CAPVERSION_104;
320 capsSet->length = 0x4;
321 capsSet->flags = caps10Flags;
327#if defined(WITH_CAIRO) || defined(WITH_SWSCALE)
328 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_105))
331 capsSet->version = RDPGFX_CAPVERSION_105;
332 capsSet->length = 0x4;
333 capsSet->flags = caps10Flags;
336 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_106))
339 capsSet->version = RDPGFX_CAPVERSION_106;
340 capsSet->length = 0x4;
341 capsSet->flags = caps10Flags;
344 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_106_ERR))
347 capsSet->version = RDPGFX_CAPVERSION_106_ERR;
348 capsSet->length = 0x4;
349 capsSet->flags = caps10Flags;
353 if (!rdpgfx_is_capability_filtered(gfx, RDPGFX_CAPVERSION_107))
356 capsSet->version = RDPGFX_CAPVERSION_107;
357 capsSet->length = 0x4;
358 capsSet->flags = caps10Flags;
359#if !defined(WITH_CAIRO) && !defined(WITH_SWSCALE)
360 capsSet->flags |= RDPGFX_CAPS_FLAG_SCALEDMAP_DISABLE;
365 return IFCALLRESULT(ERROR_BAD_CONFIGURATION, context->CapsAdvertise, context, &pdu);
375 WINPR_ASSERT(callback);
379 RdpgfxClientContext* context = gfx->context;
384 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 12))
385 return ERROR_INVALID_DATA;
387 Stream_Read_UINT32(s, capsSet.version);
388 Stream_Read_UINT32(s, capsSet.length);
389 Stream_Read_UINT32(s, capsSet.flags);
390 gfx->TotalDecodedFrames = 0;
391 gfx->ConnectionCaps = capsSet;
392 WLog_Print(gfx->base.log, WLOG_DEBUG,
393 "RecvCapsConfirmPdu: version: %s [0x%08" PRIX32
"] flags: 0x%08" PRIX32
"",
394 rdpgfx_caps_version_str(capsSet.version), capsSet.version, capsSet.flags);
397 return ERROR_BAD_CONFIGURATION;
399 return IFCALLRESULT(CHANNEL_RC_OK, context->CapsConfirm, context, &pdu);
407static UINT rdpgfx_send_frame_acknowledge_pdu(RdpgfxClientContext* context,
412 if (!context || !pdu)
413 return ERROR_BAD_ARGUMENTS;
417 if (!gfx || !gfx->base.listener_callback)
418 return ERROR_BAD_CONFIGURATION;
423 return ERROR_BAD_CONFIGURATION;
426 .cmdId = RDPGFX_CMDID_FRAMEACKNOWLEDGE,
427 .pduLength = RDPGFX_HEADER_SIZE + 12 };
429 WLog_Print(gfx->base.log, WLOG_TRACE,
"SendFrameAcknowledgePdu: %" PRIu32
"", pdu->frameId);
431 wStream* s = Stream_New(
nullptr, header.pduLength);
435 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
436 return CHANNEL_RC_NO_MEMORY;
439 if ((error = rdpgfx_write_header(s, &header)))
443 Stream_Write_UINT32(s, pdu->queueDepth);
444 Stream_Write_UINT32(s, pdu->frameId);
445 Stream_Write_UINT32(s, pdu->totalFramesDecoded);
446 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
449 if (error == CHANNEL_RC_OK)
450 gfx->UnacknowledgedFrames--;
453 Stream_Free(s, TRUE);
457static UINT rdpgfx_send_qoe_frame_acknowledge_pdu(RdpgfxClientContext* context,
460 UINT error = CHANNEL_RC_OK;
462 .cmdId = RDPGFX_CMDID_QOEFRAMEACKNOWLEDGE,
463 .pduLength = RDPGFX_HEADER_SIZE + 12 };
465 if (!context || !pdu)
466 return ERROR_BAD_ARGUMENTS;
470 if (!gfx || !gfx->base.listener_callback)
471 return ERROR_BAD_CONFIGURATION;
476 return ERROR_BAD_CONFIGURATION;
478 WLog_Print(gfx->base.log, WLOG_TRACE,
"SendQoeFrameAcknowledgePdu: %" PRIu32
"", pdu->frameId);
479 wStream* s = Stream_New(
nullptr, header.pduLength);
483 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
484 return CHANNEL_RC_NO_MEMORY;
487 if ((error = rdpgfx_write_header(s, &header)))
491 Stream_Write_UINT32(s, pdu->frameId);
492 Stream_Write_UINT32(s, pdu->timestamp);
493 Stream_Write_UINT16(s, pdu->timeDiffSE);
494 Stream_Write_UINT16(s, pdu->timeDiffEDR);
495 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
498 Stream_Free(s, TRUE);
510 WINPR_ASSERT(callback);
516 RdpgfxClientContext* context = gfx->context;
517 UINT error = CHANNEL_RC_OK;
518 GraphicsResetEventArgs graphicsReset = WINPR_C_ARRAY_INIT;
520 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 12))
521 return ERROR_INVALID_DATA;
523 Stream_Read_UINT32(s, pdu.width);
524 Stream_Read_UINT32(s, pdu.height);
525 Stream_Read_UINT32(s, pdu.monitorCount);
527 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.monitorCount, 20ull))
528 return ERROR_INVALID_DATA;
532 if (!pdu.monitorDefArray)
534 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
535 return CHANNEL_RC_NO_MEMORY;
538 for (UINT32 index = 0; index < pdu.monitorCount; index++)
540 MONITOR_DEF* monitor = &(pdu.monitorDefArray[index]);
541 Stream_Read_INT32(s, monitor->left);
542 Stream_Read_INT32(s, monitor->top);
543 Stream_Read_INT32(s, monitor->right);
544 Stream_Read_INT32(s, monitor->bottom);
545 Stream_Read_UINT32(s, monitor->flags);
548 const size_t size = (RDPGFX_HEADER_SIZE + 12ULL + (pdu.monitorCount * 20ULL));
551 free(pdu.monitorDefArray);
552 return CHANNEL_RC_NULL_DATA;
554 const size_t pad = 340ULL - size;
556 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, (
size_t)pad))
558 free(pdu.monitorDefArray);
559 return CHANNEL_RC_NO_MEMORY;
563 WLog_Print(gfx->base.log, WLOG_DEBUG,
564 "RecvResetGraphicsPdu: width: %" PRIu32
" height: %" PRIu32
" count: %" PRIu32
"",
565 pdu.width, pdu.height, pdu.monitorCount);
567 for (UINT32 index = 0; index < pdu.monitorCount; index++)
569 MONITOR_DEF* monitor = &(pdu.monitorDefArray[index]);
570 WLog_Print(gfx->base.log, WLOG_TRACE,
571 "RecvResetGraphicsPdu: monitor left:%" PRIi32
" top:%" PRIi32
" right:%" PRIi32
572 " bottom:%" PRIi32
" flags:0x%" PRIx32
"",
573 monitor->left, monitor->top, monitor->right, monitor->bottom, monitor->flags);
578 IFCALLRET(context->ResetGraphics, error, context, &pdu);
581 WLog_Print(gfx->base.log, WLOG_ERROR,
582 "context->ResetGraphics failed with error %" PRIu32
"", error);
585 free(pdu.monitorDefArray);
588 EventArgsInit(&graphicsReset,
"libfreerdp");
589 graphicsReset.width = pdu.width;
590 graphicsReset.height = pdu.height;
591 if (PubSub_OnGraphicsReset(gfx->rdpcontext->pubSub, gfx->rdpcontext, &graphicsReset) < 0)
592 return ERROR_INTERNAL_ERROR;
604 WINPR_ASSERT(callback);
607 RdpgfxClientContext* context = gfx->context;
608 UINT error = CHANNEL_RC_OK;
610 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 2))
611 return ERROR_INVALID_DATA;
613 Stream_Read_UINT16(s, pdu.cacheSlot);
614 WLog_Print(gfx->base.log, WLOG_DEBUG,
"RecvEvictCacheEntryPdu: cacheSlot: %" PRIu16
"",
619 IFCALLRET(context->EvictCacheEntry, error, context, &pdu);
622 WLog_Print(gfx->base.log, WLOG_ERROR,
623 "context->EvictCacheEntry failed with error %" PRIu32
"", error);
636 UINT error = CHANNEL_RC_OK;
639 WINPR_ASSERT(gfx->rdpcontext);
640 rdpSettings* settings = gfx->rdpcontext->settings;
641 RdpgfxClientContext* context = gfx->context;
643 WINPR_ASSERT(context);
644 WINPR_ASSERT(settings);
647 return CHANNEL_RC_OK;
649 const char* BitmapCachePersistFile =
651 if (!BitmapCachePersistFile)
652 return CHANNEL_RC_OK;
654 if (!context->ExportCacheEntry)
655 return CHANNEL_RC_INITIALIZATION_ERROR;
657 rdpPersistentCache* persistent = persistent_cache_new();
660 return CHANNEL_RC_NO_MEMORY;
662 if (persistent_cache_open(persistent, BitmapCachePersistFile, TRUE, 3) < 1)
664 error = CHANNEL_RC_INITIALIZATION_ERROR;
668 for (UINT16 idx = 0; idx < gfx->MaxCacheSlots; idx++)
670 if (gfx->CacheSlots[idx])
672 const UINT16 cacheSlot = idx;
675 if (context->ExportCacheEntry(context, cacheSlot, &cacheEntry) != CHANNEL_RC_OK)
678 if (persistent_cache_write_entry(persistent, &cacheEntry) < 0)
683 persistent_cache_free(persistent);
687 persistent_cache_free(persistent);
696static UINT rdpgfx_send_cache_import_offer_pdu(RdpgfxClientContext* context,
699 UINT error = CHANNEL_RC_OK;
701 if (!context || !pdu)
702 return ERROR_BAD_ARGUMENTS;
706 if (!gfx || !gfx->base.listener_callback)
707 return ERROR_BAD_CONFIGURATION;
712 return ERROR_BAD_CONFIGURATION;
715 .cmdId = RDPGFX_CMDID_CACHEIMPORTOFFER,
717 RDPGFX_HEADER_SIZE + 2ul + pdu->cacheEntriesCount * 12ul };
719 WLog_Print(gfx->base.log, WLOG_DEBUG,
"SendCacheImportOfferPdu: cacheEntriesCount: %" PRIu16
"",
720 pdu->cacheEntriesCount);
721 wStream* s = Stream_New(
nullptr, header.pduLength);
725 WLog_Print(gfx->base.log, WLOG_ERROR,
"Stream_New failed!");
726 return CHANNEL_RC_NO_MEMORY;
729 if ((error = rdpgfx_write_header(s, &header)))
732 if (pdu->cacheEntriesCount <= 0)
734 WLog_Print(gfx->base.log, WLOG_ERROR,
"Invalid cacheEntriesCount: %" PRIu16
"",
735 pdu->cacheEntriesCount);
736 error = ERROR_INVALID_DATA;
741 Stream_Write_UINT16(s, pdu->cacheEntriesCount);
743 for (UINT16 index = 0; index < pdu->cacheEntriesCount; index++)
746 Stream_Write_UINT64(s, cacheEntry->cacheKey);
747 Stream_Write_UINT32(s, cacheEntry->bitmapLength);
750 error = callback->channel->Write(callback->channel, (UINT32)Stream_Length(s), Stream_Buffer(s),
754 Stream_Free(s, TRUE);
766 UINT error = CHANNEL_RC_OK;
771 WINPR_ASSERT(gfx->rdpcontext);
773 RdpgfxClientContext* context = gfx->context;
774 rdpSettings* settings = gfx->rdpcontext->settings;
777 return CHANNEL_RC_OK;
779 const char* BitmapCachePersistFile =
781 if (!BitmapCachePersistFile)
782 return CHANNEL_RC_OK;
784 rdpPersistentCache* persistent = persistent_cache_new();
787 return CHANNEL_RC_NO_MEMORY;
789 if (persistent_cache_open(persistent, BitmapCachePersistFile, FALSE, 3) < 1)
791 error = CHANNEL_RC_INITIALIZATION_ERROR;
795 if (persistent_cache_get_version(persistent) != 3)
797 error = ERROR_INVALID_DATA;
801 count = persistent_cache_get_count(persistent);
804 error = ERROR_INVALID_DATA;
808 if (count >= RDPGFX_CACHE_ENTRY_MAX_COUNT)
809 count = RDPGFX_CACHE_ENTRY_MAX_COUNT - 1;
811 if (count > gfx->MaxCacheSlots)
812 count = gfx->MaxCacheSlots;
817 error = CHANNEL_RC_NO_MEMORY;
821 WINPR_ASSERT(count <= UINT16_MAX);
822 offer->cacheEntriesCount = (UINT16)count;
824 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Sending Cache Import Offer: %d", count);
826 for (
int idx = 0; idx < count; idx++)
828 if (persistent_cache_read_entry(persistent, &entry) < 1)
830 error = ERROR_INVALID_DATA;
834 offer->cacheEntries[idx].cacheKey = entry.key64;
835 offer->cacheEntries[idx].bitmapLength = entry.size;
838 if (offer->cacheEntriesCount > 0)
840 error = rdpgfx_send_cache_import_offer_pdu(context, offer);
841 if (error != CHANNEL_RC_OK)
843 WLog_Print(gfx->base.log, WLOG_ERROR,
"Failed to send cache import offer PDU");
849 persistent_cache_free(persistent);
859static UINT rdpgfx_load_cache_import_reply(
RDPGFX_PLUGIN* gfx,
862 UINT error = CHANNEL_RC_OK;
863 rdpPersistentCache* persistent =
nullptr;
865 WINPR_ASSERT(gfx->rdpcontext);
866 rdpSettings* settings = gfx->rdpcontext->settings;
867 RdpgfxClientContext* context = gfx->context;
869 WINPR_ASSERT(settings);
872 return CHANNEL_RC_OK;
874 const char* BitmapCachePersistFile =
876 if (!BitmapCachePersistFile)
877 return CHANNEL_RC_OK;
879 persistent = persistent_cache_new();
882 return CHANNEL_RC_NO_MEMORY;
884 if (persistent_cache_open(persistent, BitmapCachePersistFile, FALSE, 3) < 1)
886 error = CHANNEL_RC_INITIALIZATION_ERROR;
890 if (persistent_cache_get_version(persistent) != 3)
892 error = ERROR_INVALID_DATA;
896 int count = persistent_cache_get_count(persistent);
898 count = (count < reply->importedEntriesCount) ? count : reply->importedEntriesCount;
900 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Receiving Cache Import Reply: %d", count);
902 for (
int idx = 0; idx < count; idx++)
905 if (persistent_cache_read_entry(persistent, &entry) < 1)
907 error = ERROR_INVALID_DATA;
911 const UINT16 cacheSlot = reply->cacheSlots[idx];
912 if (context && context->ImportCacheEntry)
914 error = context->ImportCacheEntry(context, cacheSlot, &entry);
915 if (error != CHANNEL_RC_OK)
920 persistent_cache_free(persistent);
924 persistent_cache_free(persistent);
936 WINPR_ASSERT(callback);
939 RdpgfxClientContext* context = gfx->context;
940 UINT error = CHANNEL_RC_OK;
942 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 2))
943 return ERROR_INVALID_DATA;
945 Stream_Read_UINT16(s, pdu.importedEntriesCount);
947 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.importedEntriesCount,
949 return ERROR_INVALID_DATA;
951 if (pdu.importedEntriesCount > RDPGFX_CACHE_ENTRY_MAX_COUNT)
952 return ERROR_INVALID_DATA;
954 for (UINT16 idx = 0; idx < pdu.importedEntriesCount; idx++)
956 Stream_Read_UINT16(s, pdu.cacheSlots[idx]);
959 WLog_Print(gfx->base.log, WLOG_TRACE,
960 "RecvCacheImportReplyPdu: importedEntriesCount: %" PRIu16
"",
961 pdu.importedEntriesCount);
963 error = rdpgfx_load_cache_import_reply(gfx, &pdu);
967 WLog_Print(gfx->base.log, WLOG_ERROR,
968 "rdpgfx_load_cache_import_reply failed with error %" PRIu32
"", error);
974 IFCALLRET(context->CacheImportReply, error, context, &pdu);
977 WLog_Print(gfx->base.log, WLOG_ERROR,
978 "context->CacheImportReply failed with error %" PRIu32
"", error);
992 WINPR_ASSERT(callback);
995 RdpgfxClientContext* context = gfx->context;
996 UINT error = CHANNEL_RC_OK;
998 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 7))
999 return ERROR_INVALID_DATA;
1001 Stream_Read_UINT16(s, pdu.surfaceId);
1002 Stream_Read_UINT16(s, pdu.width);
1003 Stream_Read_UINT16(s, pdu.height);
1004 Stream_Read_UINT8(s, pdu.pixelFormat);
1005 WLog_Print(gfx->base.log, WLOG_DEBUG,
1006 "RecvCreateSurfacePdu: surfaceId: %" PRIu16
" width: %" PRIu16
" height: %" PRIu16
1007 " pixelFormat: 0x%02" PRIX8
"",
1008 pdu.surfaceId, pdu.width, pdu.height, pdu.pixelFormat);
1017 const UINT drc = IFCALLRESULT(CHANNEL_RC_OK, context->DeleteSurface, context, &deletePdu);
1018 if (drc != CHANNEL_RC_OK)
1019 WLog_Print(gfx->base.log, WLOG_WARN,
1020 "context->DeleteSurface failed with error %" PRIu32
", ignoring", error);
1022 IFCALLRET(context->CreateSurface, error, context, &pdu);
1025 WLog_Print(gfx->base.log, WLOG_ERROR,
1026 "context->CreateSurface failed with error %" PRIu32
"", error);
1040 WINPR_ASSERT(callback);
1043 RdpgfxClientContext* context = gfx->context;
1044 UINT error = CHANNEL_RC_OK;
1046 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 2))
1047 return ERROR_INVALID_DATA;
1049 Stream_Read_UINT16(s, pdu.surfaceId);
1050 WLog_Print(gfx->base.log, WLOG_DEBUG,
"RecvDeleteSurfacePdu: surfaceId: %" PRIu16
"",
1055 IFCALLRET(context->DeleteSurface, error, context, &pdu);
1058 WLog_Print(gfx->base.log, WLOG_ERROR,
1059 "context->DeleteSurface failed with error %" PRIu32
"", error);
1073 WINPR_ASSERT(callback);
1076 RdpgfxClientContext* context = gfx->context;
1077 UINT error = CHANNEL_RC_OK;
1079 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_START_FRAME_PDU_SIZE))
1080 return ERROR_INVALID_DATA;
1082 Stream_Read_UINT32(s, pdu.timestamp);
1083 Stream_Read_UINT32(s, pdu.frameId);
1084 WLog_Print(gfx->base.log, WLOG_TRACE,
1085 "RecvStartFramePdu: frameId: %" PRIu32
" timestamp: 0x%08" PRIX32
"", pdu.frameId,
1087 gfx->StartDecodingTime = GetTickCount64();
1091 IFCALLRET(context->StartFrame, error, context, &pdu);
1094 WLog_Print(gfx->base.log, WLOG_ERROR,
1095 "context->StartFrame failed with error %" PRIu32
"", error);
1098 gfx->UnacknowledgedFrames++;
1111 WINPR_ASSERT(callback);
1114 RdpgfxClientContext* context = gfx->context;
1115 UINT error = CHANNEL_RC_OK;
1117 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_END_FRAME_PDU_SIZE))
1118 return ERROR_INVALID_DATA;
1120 Stream_Read_UINT32(s, pdu.frameId);
1121 WLog_Print(gfx->base.log, WLOG_TRACE,
"RecvEndFramePdu: frameId: %" PRIu32
"", pdu.frameId);
1123 const UINT64 start = GetTickCount64();
1126 IFCALLRET(context->EndFrame, error, context, &pdu);
1130 WLog_Print(gfx->base.log, WLOG_ERROR,
"context->EndFrame failed with error %" PRIu32
"",
1135 const UINT64 end = GetTickCount64();
1136 const UINT64 EndFrameTime = end - start;
1137 gfx->TotalDecodedFrames++;
1139 if (!gfx->sendFrameAcks)
1142 ack.frameId = pdu.frameId;
1143 ack.totalFramesDecoded = gfx->TotalDecodedFrames;
1145 if (gfx->suspendFrameAcks)
1147 ack.queueDepth = SUSPEND_FRAME_ACKNOWLEDGEMENT;
1149 if (gfx->TotalDecodedFrames == 1)
1150 if ((error = rdpgfx_send_frame_acknowledge_pdu(context, &ack)))
1151 WLog_Print(gfx->base.log, WLOG_ERROR,
1152 "rdpgfx_send_frame_acknowledge_pdu failed with error %" PRIu32
"",
1157 ack.queueDepth = QUEUE_DEPTH_UNAVAILABLE;
1159 if ((error = rdpgfx_send_frame_acknowledge_pdu(context, &ack)))
1160 WLog_Print(gfx->base.log, WLOG_ERROR,
1161 "rdpgfx_send_frame_acknowledge_pdu failed with error %" PRIu32
"", error);
1164 switch (gfx->ConnectionCaps.version)
1166 case RDPGFX_CAPVERSION_10:
1167 case RDPGFX_CAPVERSION_102:
1168 case RDPGFX_CAPVERSION_103:
1169 case RDPGFX_CAPVERSION_104:
1170 case RDPGFX_CAPVERSION_105:
1171 case RDPGFX_CAPVERSION_106:
1172 case RDPGFX_CAPVERSION_106_ERR:
1173 case RDPGFX_CAPVERSION_107:
1177 UINT64 diff = (GetTickCount64() - gfx->StartDecodingTime);
1182 qoe.frameId = pdu.frameId;
1183 qoe.timestamp = gfx->StartDecodingTime % UINT32_MAX;
1184 qoe.timeDiffSE = WINPR_ASSERTING_INT_CAST(UINT16, diff);
1185 qoe.timeDiffEDR = WINPR_ASSERTING_INT_CAST(UINT16, EndFrameTime);
1187 if ((error = rdpgfx_send_qoe_frame_acknowledge_pdu(context, &qoe)))
1188 WLog_Print(gfx->base.log, WLOG_ERROR,
1189 "rdpgfx_send_qoe_frame_acknowledge_pdu failed with error %" PRIu32
1212 WINPR_ASSERT(callback);
1217 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_WIRE_TO_SURFACE_PDU_1_SIZE))
1218 return ERROR_INVALID_DATA;
1220 Stream_Read_UINT16(s, pdu.surfaceId);
1221 Stream_Read_UINT16(s, pdu.codecId);
1222 Stream_Read_UINT8(s, pdu.pixelFormat);
1224 if ((error = rdpgfx_read_rect16(gfx->base.log, s, &(pdu.destRect))))
1226 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_rect16 failed with error %" PRIu32
"",
1231 Stream_Read_UINT32(s, pdu.bitmapDataLength);
1233 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, pdu.bitmapDataLength))
1234 return ERROR_INVALID_DATA;
1236 pdu.bitmapData = Stream_Pointer(s);
1237 Stream_Seek(s, pdu.bitmapDataLength);
1239 WLog_Print(gfx->base.log, WLOG_TRACE,
1240 "RecvWireToSurface1Pdu: surfaceId: %" PRIu16
" codecId: %s (0x%04" PRIX16
1241 ") pixelFormat: 0x%02" PRIX8
" "
1242 "destRect: left: %" PRIu16
" top: %" PRIu16
" right: %" PRIu16
" bottom: %" PRIu16
1243 " bitmapDataLength: %" PRIu32
"",
1244 pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId, pdu.pixelFormat,
1245 pdu.destRect.left, pdu.destRect.top, pdu.destRect.right, pdu.destRect.bottom,
1246 pdu.bitmapDataLength);
1247 cmd.surfaceId = pdu.surfaceId;
1248 cmd.codecId = pdu.codecId;
1251 switch (pdu.pixelFormat)
1253 case GFX_PIXEL_FORMAT_XRGB_8888:
1254 cmd.format = PIXEL_FORMAT_BGRX32;
1257 case GFX_PIXEL_FORMAT_ARGB_8888:
1258 cmd.format = PIXEL_FORMAT_BGRA32;
1262 return ERROR_INVALID_DATA;
1265 cmd.left = pdu.destRect.left;
1266 cmd.top = pdu.destRect.top;
1267 cmd.right = pdu.destRect.right;
1268 cmd.bottom = pdu.destRect.bottom;
1269 cmd.width = cmd.right - cmd.left;
1270 cmd.height = cmd.bottom - cmd.top;
1271 cmd.length = pdu.bitmapDataLength;
1272 cmd.data = pdu.bitmapData;
1273 cmd.extra =
nullptr;
1275 if (cmd.right < cmd.left)
1277 WLog_Print(gfx->base.log, WLOG_ERROR,
1278 "RecvWireToSurface1Pdu right=%" PRIu32
" < left=%" PRIu32, cmd.right, cmd.left);
1279 return ERROR_INVALID_DATA;
1281 if (cmd.bottom < cmd.top)
1283 WLog_Print(gfx->base.log, WLOG_ERROR,
1284 "RecvWireToSurface1Pdu bottom=%" PRIu32
" < top=%" PRIu32, cmd.bottom, cmd.top);
1285 return ERROR_INVALID_DATA;
1288 if ((error = rdpgfx_decode(gfx, &cmd)))
1289 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_decode failed with error %" PRIu32
"!",
1305 WINPR_ASSERT(callback);
1308 RdpgfxClientContext* context = gfx->context;
1309 UINT error = CHANNEL_RC_OK;
1311 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, RDPGFX_WIRE_TO_SURFACE_PDU_2_SIZE))
1312 return ERROR_INVALID_DATA;
1314 Stream_Read_UINT16(s, pdu.surfaceId);
1315 Stream_Read_UINT16(s, pdu.codecId);
1316 Stream_Read_UINT32(s, pdu.codecContextId);
1317 Stream_Read_UINT8(s, pdu.pixelFormat);
1318 Stream_Read_UINT32(s, pdu.bitmapDataLength);
1319 pdu.bitmapData = Stream_Pointer(s);
1320 if (!Stream_SafeSeek(s, pdu.bitmapDataLength))
1321 return ERROR_INVALID_DATA;
1323 WLog_Print(gfx->base.log, WLOG_TRACE,
1324 "RecvWireToSurface2Pdu: surfaceId: %" PRIu16
" codecId: %s (0x%04" PRIX16
") "
1325 "codecContextId: %" PRIu32
" pixelFormat: 0x%02" PRIX8
" bitmapDataLength: %" PRIu32
1327 pdu.surfaceId, rdpgfx_get_codec_id_string(pdu.codecId), pdu.codecId,
1328 pdu.codecContextId, pdu.pixelFormat, pdu.bitmapDataLength);
1330 cmd.surfaceId = pdu.surfaceId;
1331 cmd.codecId = pdu.codecId;
1332 cmd.contextId = pdu.codecContextId;
1334 switch (pdu.pixelFormat)
1336 case GFX_PIXEL_FORMAT_XRGB_8888:
1337 cmd.format = PIXEL_FORMAT_BGRX32;
1340 case GFX_PIXEL_FORMAT_ARGB_8888:
1341 cmd.format = PIXEL_FORMAT_BGRA32;
1345 return ERROR_INVALID_DATA;
1348 cmd.length = pdu.bitmapDataLength;
1349 cmd.data = pdu.bitmapData;
1350 cmd.extra =
nullptr;
1354 IFCALLRET(context->SurfaceCommand, error, context, &cmd);
1357 WLog_Print(gfx->base.log, WLOG_ERROR,
1358 "context->SurfaceCommand failed with error %" PRIu32
"", error);
1372 WINPR_ASSERT(callback);
1375 RdpgfxClientContext* context = gfx->context;
1376 UINT error = CHANNEL_RC_OK;
1378 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 6))
1379 return ERROR_INVALID_DATA;
1381 Stream_Read_UINT16(s, pdu.surfaceId);
1382 Stream_Read_UINT32(s, pdu.codecContextId);
1384 WLog_Print(gfx->base.log, WLOG_DEBUG,
1385 "RecvDeleteEncodingContextPdu: surfaceId: %" PRIu16
" codecContextId: %" PRIu32
"",
1386 pdu.surfaceId, pdu.codecContextId);
1390 IFCALLRET(context->DeleteEncodingContext, error, context, &pdu);
1393 WLog_Print(gfx->base.log, WLOG_ERROR,
1394 "context->DeleteEncodingContext failed with error %" PRIu32
"", error);
1408 WINPR_ASSERT(callback);
1411 RdpgfxClientContext* context = gfx->context;
1413 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 8))
1414 return ERROR_INVALID_DATA;
1416 Stream_Read_UINT16(s, pdu.surfaceId);
1418 UINT error = rdpgfx_read_color32(gfx->base.log, s, &(pdu.fillPixel));
1419 if (error != CHANNEL_RC_OK)
1421 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_color32 failed with error %" PRIu32
"!",
1426 Stream_Read_UINT16(s, pdu.fillRectCount);
1428 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.fillRectCount, 8ull))
1429 return ERROR_INVALID_DATA;
1435 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
1436 return CHANNEL_RC_NO_MEMORY;
1439 for (UINT16 index = 0; index < pdu.fillRectCount; index++)
1443 if ((error = rdpgfx_read_rect16(gfx->base.log, s, fillRect)))
1445 WLog_Print(gfx->base.log, WLOG_ERROR,
1446 "rdpgfx_read_rect16 failed with error %" PRIu32
"!", error);
1447 free(pdu.fillRects);
1451 WLog_Print(gfx->base.log, WLOG_TRACE,
1452 "RecvSolidFillPdu: surfaceId: %" PRIu16
" fillRectCount: %" PRIu16
"", pdu.surfaceId,
1457 IFCALLRET(context->SolidFill, error, context, &pdu);
1460 WLog_Print(gfx->base.log, WLOG_ERROR,
1461 "context->SolidFill failed with error %" PRIu32
"", error);
1464 free(pdu.fillRects);
1476 WINPR_ASSERT(callback);
1479 RdpgfxClientContext* context = gfx->context;
1482 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 14))
1483 return ERROR_INVALID_DATA;
1485 Stream_Read_UINT16(s, pdu.surfaceIdSrc);
1486 Stream_Read_UINT16(s, pdu.surfaceIdDest);
1488 if ((error = rdpgfx_read_rect16(gfx->base.log, s, &(pdu.rectSrc))))
1490 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_rect16 failed with error %" PRIu32
"!",
1495 Stream_Read_UINT16(s, pdu.destPtsCount);
1497 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.destPtsCount, 4ull))
1498 return ERROR_INVALID_DATA;
1504 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
1505 return CHANNEL_RC_NO_MEMORY;
1508 for (UINT16 index = 0; index < pdu.destPtsCount; index++)
1512 if ((error = rdpgfx_read_point16(gfx->base.log, s, destPt)))
1514 WLog_Print(gfx->base.log, WLOG_ERROR,
1515 "rdpgfx_read_point16 failed with error %" PRIu32
"!", error);
1521 WLog_Print(gfx->base.log, WLOG_TRACE,
1522 "RecvSurfaceToSurfacePdu: surfaceIdSrc: %" PRIu16
" surfaceIdDest: %" PRIu16
" "
1523 "left: %" PRIu16
" top: %" PRIu16
" right: %" PRIu16
" bottom: %" PRIu16
1524 " destPtsCount: %" PRIu16
"",
1525 pdu.surfaceIdSrc, pdu.surfaceIdDest, pdu.rectSrc.left, pdu.rectSrc.top,
1526 pdu.rectSrc.right, pdu.rectSrc.bottom, pdu.destPtsCount);
1530 IFCALLRET(context->SurfaceToSurface, error, context, &pdu);
1533 WLog_Print(gfx->base.log, WLOG_ERROR,
1534 "context->SurfaceToSurface failed with error %" PRIu32
"", error);
1549 WINPR_ASSERT(callback);
1553 RdpgfxClientContext* context = gfx->context;
1555 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 20))
1556 return ERROR_INVALID_DATA;
1558 Stream_Read_UINT16(s, pdu.surfaceId);
1559 Stream_Read_UINT64(s, pdu.cacheKey);
1560 Stream_Read_UINT16(s, pdu.cacheSlot);
1562 UINT error = rdpgfx_read_rect16(gfx->base.log, s, &(pdu.rectSrc));
1563 if (error != CHANNEL_RC_OK)
1565 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_rect16 failed with error %" PRIu32
"!",
1570 WLog_Print(gfx->base.log, WLOG_TRACE,
1571 "RecvSurfaceToCachePdu: surfaceId: %" PRIu16
" cacheKey: 0x%016" PRIX64
1572 " cacheSlot: %" PRIu16
" "
1573 "left: %" PRIu16
" top: %" PRIu16
" right: %" PRIu16
" bottom: %" PRIu16
"",
1574 pdu.surfaceId, pdu.cacheKey, pdu.cacheSlot, pdu.rectSrc.left, pdu.rectSrc.top,
1575 pdu.rectSrc.right, pdu.rectSrc.bottom);
1579 IFCALLRET(context->SurfaceToCache, error, context, &pdu);
1582 WLog_Print(gfx->base.log, WLOG_ERROR,
1583 "context->SurfaceToCache failed with error %" PRIu32
"", error);
1597 WINPR_ASSERT(callback);
1601 RdpgfxClientContext* context = gfx->context;
1602 UINT error = CHANNEL_RC_OK;
1604 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 6))
1605 return ERROR_INVALID_DATA;
1607 Stream_Read_UINT16(s, pdu.cacheSlot);
1608 Stream_Read_UINT16(s, pdu.surfaceId);
1609 Stream_Read_UINT16(s, pdu.destPtsCount);
1611 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(gfx->base.log, s, pdu.destPtsCount, 4ull))
1612 return ERROR_INVALID_DATA;
1618 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
1619 return CHANNEL_RC_NO_MEMORY;
1622 for (UINT16 index = 0; index < pdu.destPtsCount; index++)
1626 if ((error = rdpgfx_read_point16(gfx->base.log, s, destPt)))
1628 WLog_Print(gfx->base.log, WLOG_ERROR,
1629 "rdpgfx_read_point16 failed with error %" PRIu32
"", error);
1635 WLog_Print(gfx->base.log, WLOG_TRACE,
1636 "RdpGfxRecvCacheToSurfacePdu: cacheSlot: %" PRIu16
" surfaceId: %" PRIu16
1637 " destPtsCount: %" PRIu16
"",
1638 pdu.cacheSlot, pdu.surfaceId, pdu.destPtsCount);
1642 IFCALLRET(context->CacheToSurface, error, context, &pdu);
1645 WLog_Print(gfx->base.log, WLOG_ERROR,
1646 "context->CacheToSurface failed with error %" PRIu32
"", error);
1661 WINPR_ASSERT(callback);
1665 RdpgfxClientContext* context = gfx->context;
1666 UINT error = CHANNEL_RC_OK;
1668 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 12))
1669 return ERROR_INVALID_DATA;
1671 Stream_Read_UINT16(s, pdu.surfaceId);
1672 Stream_Read_UINT16(s, pdu.reserved);
1673 Stream_Read_UINT32(s, pdu.outputOriginX);
1674 Stream_Read_UINT32(s, pdu.outputOriginY);
1675 WLog_Print(gfx->base.log, WLOG_DEBUG,
1676 "RecvMapSurfaceToOutputPdu: surfaceId: %" PRIu16
" outputOriginX: %" PRIu32
1677 " outputOriginY: %" PRIu32
"",
1678 pdu.surfaceId, pdu.outputOriginX, pdu.outputOriginY);
1682 IFCALLRET(context->MapSurfaceToOutput, error, context, &pdu);
1685 WLog_Print(gfx->base.log, WLOG_ERROR,
1686 "context->MapSurfaceToOutput failed with error %" PRIu32
"", error);
1696 WINPR_ASSERT(callback);
1700 RdpgfxClientContext* context = gfx->context;
1701 UINT error = CHANNEL_RC_OK;
1703 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 20))
1704 return ERROR_INVALID_DATA;
1706 Stream_Read_UINT16(s, pdu.surfaceId);
1707 Stream_Read_UINT16(s, pdu.reserved);
1708 Stream_Read_UINT32(s, pdu.outputOriginX);
1709 Stream_Read_UINT32(s, pdu.outputOriginY);
1710 Stream_Read_UINT32(s, pdu.targetWidth);
1711 Stream_Read_UINT32(s, pdu.targetHeight);
1712 WLog_Print(gfx->base.log, WLOG_DEBUG,
1713 "RecvMapSurfaceToScaledOutputPdu: surfaceId: %" PRIu16
" outputOriginX: %" PRIu32
1714 " outputOriginY: %" PRIu32
" targetWidth: %" PRIu32
" targetHeight: %" PRIu32,
1715 pdu.surfaceId, pdu.outputOriginX, pdu.outputOriginY, pdu.targetWidth,
1720 IFCALLRET(context->MapSurfaceToScaledOutput, error, context, &pdu);
1723 WLog_Print(gfx->base.log, WLOG_ERROR,
1724 "context->MapSurfaceToScaledOutput failed with error %" PRIu32
"", error);
1738 WINPR_ASSERT(callback);
1742 RdpgfxClientContext* context = gfx->context;
1743 UINT error = CHANNEL_RC_OK;
1745 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 18))
1746 return ERROR_INVALID_DATA;
1748 Stream_Read_UINT16(s, pdu.surfaceId);
1749 Stream_Read_UINT64(s, pdu.windowId);
1750 Stream_Read_UINT32(s, pdu.mappedWidth);
1751 Stream_Read_UINT32(s, pdu.mappedHeight);
1752 WLog_Print(gfx->base.log, WLOG_DEBUG,
1753 "RecvMapSurfaceToWindowPdu: surfaceId: %" PRIu16
" windowId: 0x%016" PRIX64
1754 " mappedWidth: %" PRIu32
" mappedHeight: %" PRIu32
"",
1755 pdu.surfaceId, pdu.windowId, pdu.mappedWidth, pdu.mappedHeight);
1757 if (context && context->MapSurfaceToWindow)
1759 IFCALLRET(context->MapSurfaceToWindow, error, context, &pdu);
1762 WLog_Print(gfx->base.log, WLOG_ERROR,
1763 "context->MapSurfaceToWindow failed with error %" PRIu32
"", error);
1773 WINPR_ASSERT(callback);
1776 RdpgfxClientContext* context = gfx->context;
1777 UINT error = CHANNEL_RC_OK;
1779 if (!Stream_CheckAndLogRequiredLengthWLog(gfx->base.log, s, 26))
1780 return ERROR_INVALID_DATA;
1782 Stream_Read_UINT16(s, pdu.surfaceId);
1783 Stream_Read_UINT64(s, pdu.windowId);
1784 Stream_Read_UINT32(s, pdu.mappedWidth);
1785 Stream_Read_UINT32(s, pdu.mappedHeight);
1786 Stream_Read_UINT32(s, pdu.targetWidth);
1787 Stream_Read_UINT32(s, pdu.targetHeight);
1788 WLog_Print(gfx->base.log, WLOG_DEBUG,
1789 "RecvMapSurfaceToScaledWindowPdu: surfaceId: %" PRIu16
" windowId: 0x%016" PRIX64
1790 " mappedWidth: %" PRIu32
" mappedHeight: %" PRIu32
" targetWidth: %" PRIu32
1791 " targetHeight: %" PRIu32
"",
1792 pdu.surfaceId, pdu.windowId, pdu.mappedWidth, pdu.mappedHeight, pdu.targetWidth,
1795 if (context && context->MapSurfaceToScaledWindow)
1797 IFCALLRET(context->MapSurfaceToScaledWindow, error, context, &pdu);
1800 WLog_Print(gfx->base.log, WLOG_ERROR,
1801 "context->MapSurfaceToScaledWindow failed with error %" PRIu32
"", error);
1816 WINPR_ASSERT(callback);
1818 const size_t beg = Stream_GetPosition(s);
1822 UINT error = rdpgfx_read_header(gfx->base.log, s, &header);
1823 if (error != CHANNEL_RC_OK)
1825 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_read_header failed with error %" PRIu32
"!",
1830 WLog_Print(gfx->base.log, WLOG_TRACE,
1831 "cmdId: %s (0x%04" PRIX16
") flags: 0x%04" PRIX16
" pduLength: %" PRIu32
"",
1832 rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId, header.flags,
1835 switch (header.cmdId)
1837 case RDPGFX_CMDID_WIRETOSURFACE_1:
1838 if ((error = rdpgfx_recv_wire_to_surface_1_pdu(callback, s)))
1839 WLog_Print(gfx->base.log, WLOG_ERROR,
1840 "rdpgfx_recv_wire_to_surface_1_pdu failed with error %" PRIu32
"!",
1845 case RDPGFX_CMDID_WIRETOSURFACE_2:
1846 if ((error = rdpgfx_recv_wire_to_surface_2_pdu(callback, s)))
1847 WLog_Print(gfx->base.log, WLOG_ERROR,
1848 "rdpgfx_recv_wire_to_surface_2_pdu failed with error %" PRIu32
"!",
1853 case RDPGFX_CMDID_DELETEENCODINGCONTEXT:
1854 if ((error = rdpgfx_recv_delete_encoding_context_pdu(callback, s)))
1855 WLog_Print(gfx->base.log, WLOG_ERROR,
1856 "rdpgfx_recv_delete_encoding_context_pdu failed with error %" PRIu32
"!",
1861 case RDPGFX_CMDID_SOLIDFILL:
1862 if ((error = rdpgfx_recv_solid_fill_pdu(callback, s)))
1863 WLog_Print(gfx->base.log, WLOG_ERROR,
1864 "rdpgfx_recv_solid_fill_pdu failed with error %" PRIu32
"!", error);
1868 case RDPGFX_CMDID_SURFACETOSURFACE:
1869 if ((error = rdpgfx_recv_surface_to_surface_pdu(callback, s)))
1870 WLog_Print(gfx->base.log, WLOG_ERROR,
1871 "rdpgfx_recv_surface_to_surface_pdu failed with error %" PRIu32
"!",
1876 case RDPGFX_CMDID_SURFACETOCACHE:
1877 if ((error = rdpgfx_recv_surface_to_cache_pdu(callback, s)))
1878 WLog_Print(gfx->base.log, WLOG_ERROR,
1879 "rdpgfx_recv_surface_to_cache_pdu failed with error %" PRIu32
"!",
1884 case RDPGFX_CMDID_CACHETOSURFACE:
1885 if ((error = rdpgfx_recv_cache_to_surface_pdu(callback, s)))
1886 WLog_Print(gfx->base.log, WLOG_ERROR,
1887 "rdpgfx_recv_cache_to_surface_pdu failed with error %" PRIu32
"!",
1892 case RDPGFX_CMDID_EVICTCACHEENTRY:
1893 if ((error = rdpgfx_recv_evict_cache_entry_pdu(callback, s)))
1894 WLog_Print(gfx->base.log, WLOG_ERROR,
1895 "rdpgfx_recv_evict_cache_entry_pdu failed with error %" PRIu32
"!",
1900 case RDPGFX_CMDID_CREATESURFACE:
1901 if ((error = rdpgfx_recv_create_surface_pdu(callback, s)))
1902 WLog_Print(gfx->base.log, WLOG_ERROR,
1903 "rdpgfx_recv_create_surface_pdu failed with error %" PRIu32
"!", error);
1907 case RDPGFX_CMDID_DELETESURFACE:
1908 if ((error = rdpgfx_recv_delete_surface_pdu(callback, s)))
1909 WLog_Print(gfx->base.log, WLOG_ERROR,
1910 "rdpgfx_recv_delete_surface_pdu failed with error %" PRIu32
"!", error);
1914 case RDPGFX_CMDID_STARTFRAME:
1915 if ((error = rdpgfx_recv_start_frame_pdu(callback, s)))
1916 WLog_Print(gfx->base.log, WLOG_ERROR,
1917 "rdpgfx_recv_start_frame_pdu failed with error %" PRIu32
"!", error);
1921 case RDPGFX_CMDID_ENDFRAME:
1922 if ((error = rdpgfx_recv_end_frame_pdu(callback, s)))
1923 WLog_Print(gfx->base.log, WLOG_ERROR,
1924 "rdpgfx_recv_end_frame_pdu failed with error %" PRIu32
"!", error);
1928 case RDPGFX_CMDID_RESETGRAPHICS:
1929 if ((error = rdpgfx_recv_reset_graphics_pdu(callback, s)))
1930 WLog_Print(gfx->base.log, WLOG_ERROR,
1931 "rdpgfx_recv_reset_graphics_pdu failed with error %" PRIu32
"!", error);
1935 case RDPGFX_CMDID_MAPSURFACETOOUTPUT:
1936 if ((error = rdpgfx_recv_map_surface_to_output_pdu(callback, s)))
1937 WLog_Print(gfx->base.log, WLOG_ERROR,
1938 "rdpgfx_recv_map_surface_to_output_pdu failed with error %" PRIu32
"!",
1943 case RDPGFX_CMDID_CACHEIMPORTREPLY:
1944 if ((error = rdpgfx_recv_cache_import_reply_pdu(callback, s)))
1945 WLog_Print(gfx->base.log, WLOG_ERROR,
1946 "rdpgfx_recv_cache_import_reply_pdu failed with error %" PRIu32
"!",
1951 case RDPGFX_CMDID_CAPSCONFIRM:
1952 if ((error = rdpgfx_recv_caps_confirm_pdu(callback, s)))
1953 WLog_Print(gfx->base.log, WLOG_ERROR,
1954 "rdpgfx_recv_caps_confirm_pdu failed with error %" PRIu32
"!", error);
1956 if ((error = rdpgfx_send_cache_offer(gfx)))
1957 WLog_Print(gfx->base.log, WLOG_ERROR,
1958 "rdpgfx_send_cache_offer failed with error %" PRIu32
"!", error);
1962 case RDPGFX_CMDID_MAPSURFACETOWINDOW:
1963 if ((error = rdpgfx_recv_map_surface_to_window_pdu(callback, s)))
1964 WLog_Print(gfx->base.log, WLOG_ERROR,
1965 "rdpgfx_recv_map_surface_to_window_pdu failed with error %" PRIu32
"!",
1970 case RDPGFX_CMDID_MAPSURFACETOSCALEDWINDOW:
1971 if ((error = rdpgfx_recv_map_surface_to_scaled_window_pdu(callback, s)))
1972 WLog_Print(gfx->base.log, WLOG_ERROR,
1973 "rdpgfx_recv_map_surface_to_scaled_window_pdu failed with error %" PRIu32
1979 case RDPGFX_CMDID_MAPSURFACETOSCALEDOUTPUT:
1980 if ((error = rdpgfx_recv_map_surface_to_scaled_output_pdu(callback, s)))
1981 WLog_Print(gfx->base.log, WLOG_ERROR,
1982 "rdpgfx_recv_map_surface_to_scaled_output_pdu failed with error %" PRIu32
1989 error = CHANNEL_RC_BAD_PROC;
1995 WLog_Print(gfx->base.log, WLOG_ERROR,
1996 "Error while processing GFX cmdId: %s (0x%04" PRIX16
")",
1997 rdpgfx_get_cmd_id_string(header.cmdId), header.cmdId);
1998 if (!Stream_SetPosition(s, (beg + header.pduLength)))
1999 return ERROR_INVALID_DATA;
2003 const size_t end = Stream_GetPosition(s);
2005 if (end != (beg + header.pduLength))
2007 WLog_Print(gfx->base.log, WLOG_ERROR,
2008 "Unexpected gfx pdu end: Actual: %" PRIuz
", Expected: %" PRIuz, end,
2009 (beg + header.pduLength));
2010 if (!Stream_SetPosition(s, (beg + header.pduLength)))
2011 return ERROR_INVALID_DATA;
2022static UINT rdpgfx_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
wStream* data)
2025 BYTE* pDstData =
nullptr;
2027 WINPR_ASSERT(callback);
2029 UINT error = CHANNEL_RC_OK;
2032 int status = zgfx_decompress(gfx->zgfx, Stream_ConstPointer(data),
2033 (UINT32)Stream_GetRemainingLength(data), &pDstData, &DstSize, 0);
2037 WLog_Print(gfx->base.log, WLOG_ERROR,
"zgfx_decompress failure! status: %d", status);
2039 return ERROR_INTERNAL_ERROR;
2042 wStream sbuffer = WINPR_C_ARRAY_INIT;
2043 wStream* s = Stream_StaticConstInit(&sbuffer, pDstData, DstSize);
2047 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
2049 return CHANNEL_RC_NO_MEMORY;
2052 while (Stream_GetPosition(s) < Stream_Length(s))
2054 if ((error = rdpgfx_recv_pdu(callback, s)))
2056 WLog_Print(gfx->base.log, WLOG_ERROR,
"rdpgfx_recv_pdu failed with error %" PRIu32
"!",
2071static UINT rdpgfx_on_open(IWTSVirtualChannelCallback* pChannelCallback)
2074 WINPR_ASSERT(callback);
2077 RdpgfxClientContext* context = gfx->context;
2078 UINT error = CHANNEL_RC_OK;
2079 BOOL do_caps_advertise = TRUE;
2081 gfx->sendFrameAcks = TRUE;
2085 IFCALLRET(context->OnOpen, error, context, &do_caps_advertise, &gfx->sendFrameAcks);
2088 WLog_Print(gfx->base.log, WLOG_ERROR,
"context->OnOpen failed with error %" PRIu32
"",
2092 if (do_caps_advertise)
2093 error = rdpgfx_send_supported_caps(callback);
2103static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback)
2105 UINT error = CHANNEL_RC_OK;
2107 WINPR_ASSERT(callback);
2113 RdpgfxClientContext* context = gfx->context;
2115 WLog_Print(gfx->base.log, WLOG_DEBUG,
"OnClose");
2116 error = rdpgfx_save_persistent_cache(gfx);
2121 WLog_Print(gfx->base.log, WLOG_ERROR,
2122 "rdpgfx_save_persistent_cache failed with error %" PRIu32
"", error);
2125 free_surfaces(context, gfx->SurfaceTable);
2126 error = evict_cache_slots(context, gfx->MaxCacheSlots, gfx->CacheSlots);
2130 WLog_Print(gfx->base.log, WLOG_ERROR,
"evict_cache_slots failed with error %" PRIu32
"",
2135 gfx->UnacknowledgedFrames = 0;
2136 gfx->TotalDecodedFrames = 0;
2140 error = IFCALLRESULT(CHANNEL_RC_OK, context->OnClose, context);
2144 WLog_Print(gfx->base.log, WLOG_ERROR,
"context->OnClose failed with error %" PRIu32
"",
2150 return CHANNEL_RC_OK;
2157 RdpgfxClientContext* context = gfx->context;
2159 WLog_Print(gfx->base.log, WLOG_DEBUG,
"Terminated");
2160 rdpgfx_client_context_free(context);
2168static UINT rdpgfx_set_surface_data(RdpgfxClientContext* context, UINT16 surfaceId,
void* pData)
2170 WINPR_ASSERT(context);
2173 ULONG_PTR key = ((ULONG_PTR)surfaceId) + 1;
2177 if (!HashTable_Insert(gfx->SurfaceTable, (
void*)key, pData))
2178 return ERROR_BAD_ARGUMENTS;
2181 HashTable_Remove(gfx->SurfaceTable, (
void*)key);
2183 return CHANNEL_RC_OK;
2191static UINT rdpgfx_get_surface_ids(RdpgfxClientContext* context, UINT16** ppSurfaceIds,
2194 ULONG_PTR* pKeys =
nullptr;
2195 WINPR_ASSERT(context);
2198 size_t count = HashTable_GetKeys(gfx->SurfaceTable, &pKeys);
2200 WINPR_ASSERT(ppSurfaceIds);
2201 WINPR_ASSERT(count_out);
2205 return CHANNEL_RC_OK;
2208 UINT16* pSurfaceIds = (UINT16*)calloc(count,
sizeof(UINT16));
2212 WLog_Print(gfx->base.log, WLOG_ERROR,
"calloc failed!");
2214 return CHANNEL_RC_NO_MEMORY;
2217 for (
size_t index = 0; index < count; index++)
2219 pSurfaceIds[index] = (UINT16)(pKeys[index] - 1);
2223 *ppSurfaceIds = pSurfaceIds;
2224 *count_out = (UINT16)count;
2225 return CHANNEL_RC_OK;
2228static void* rdpgfx_get_surface_data(RdpgfxClientContext* context, UINT16 surfaceId)
2230 WINPR_ASSERT(context);
2233 ULONG_PTR key = ((ULONG_PTR)surfaceId) + 1;
2234 return HashTable_GetItemValue(gfx->SurfaceTable, (
void*)key);
2242static UINT rdpgfx_set_cache_slot_data(RdpgfxClientContext* context, UINT16 cacheSlot,
void* pData)
2244 WINPR_ASSERT(context);
2249 if (cacheSlot == 0 || cacheSlot > gfx->MaxCacheSlots)
2251 WLog_Print(gfx->base.log, WLOG_ERROR,
2252 "invalid cache slot %" PRIu16
", must be between 1 and %" PRIu16
"", cacheSlot,
2253 gfx->MaxCacheSlots);
2254 return ERROR_INVALID_INDEX;
2257 gfx->CacheSlots[cacheSlot - 1] = pData;
2258 return CHANNEL_RC_OK;
2261static void* rdpgfx_get_cache_slot_data(RdpgfxClientContext* context, UINT16 cacheSlot)
2263 WINPR_ASSERT(context);
2267 if (cacheSlot == 0 || cacheSlot > gfx->MaxCacheSlots)
2269 WLog_Print(gfx->base.log, WLOG_ERROR,
2270 "invalid cache slot %" PRIu16
", must be between 1 and %" PRIu16
"", cacheSlot,
2271 gfx->MaxCacheSlots);
2275 return gfx->CacheSlots[cacheSlot - 1];
2279 WINPR_ATTR_UNUSED rdpSettings* settings)
2284 gfx->rdpcontext = rcontext;
2286 gfx->SurfaceTable = HashTable_New(TRUE);
2287 if (!gfx->SurfaceTable)
2289 WLog_Print(gfx->base.log, WLOG_ERROR,
"HashTable_New for surfaces failed !");
2290 return CHANNEL_RC_NO_MEMORY;
2293 gfx->suspendFrameAcks =
2295 gfx->MaxCacheSlots =
2298 RdpgfxClientContext* context = (RdpgfxClientContext*)calloc(1,
sizeof(RdpgfxClientContext));
2301 WLog_Print(gfx->base.log, WLOG_ERROR,
"context calloc failed!");
2302 HashTable_Free(gfx->SurfaceTable);
2303 gfx->SurfaceTable =
nullptr;
2304 return CHANNEL_RC_NO_MEMORY;
2307 gfx->zgfx = zgfx_context_new(FALSE);
2310 WLog_Print(gfx->base.log, WLOG_ERROR,
"zgfx_context_new failed!");
2311 HashTable_Free(gfx->SurfaceTable);
2312 gfx->SurfaceTable =
nullptr;
2314 return CHANNEL_RC_NO_MEMORY;
2317 context->handle = (
void*)gfx;
2318 context->GetSurfaceIds = rdpgfx_get_surface_ids;
2319 context->SetSurfaceData = rdpgfx_set_surface_data;
2320 context->GetSurfaceData = rdpgfx_get_surface_data;
2321 context->SetCacheSlotData = rdpgfx_set_cache_slot_data;
2322 context->GetCacheSlotData = rdpgfx_get_cache_slot_data;
2323 context->CapsAdvertise = rdpgfx_send_caps_advertise_pdu;
2324 context->FrameAcknowledge = rdpgfx_send_frame_acknowledge_pdu;
2325 context->CacheImportOffer = rdpgfx_send_cache_import_offer_pdu;
2326 context->QoeFrameAcknowledge = rdpgfx_send_qoe_frame_acknowledge_pdu;
2328 gfx->base.iface.pInterface = (
void*)context;
2329 gfx->context = context;
2330 return CHANNEL_RC_OK;
2333void rdpgfx_client_context_free(RdpgfxClientContext* context)
2340 free_surfaces(context, gfx->SurfaceTable);
2341 evict_cache_slots(context, gfx->MaxCacheSlots, gfx->CacheSlots);
2345 zgfx_context_free(gfx->zgfx);
2346 gfx->zgfx =
nullptr;
2349 HashTable_Free(gfx->SurfaceTable);
2353static const IWTSVirtualChannelCallback rdpgfx_callbacks = { rdpgfx_on_data_received,
2354 rdpgfx_on_open, rdpgfx_on_close,
2362FREERDP_ENTRY_POINT(UINT VCAPITYPE rdpgfx_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))
2364 return freerdp_generic_DVCPluginEntry(pEntryPoints, GFXTAG, RDPGFX_DVC_CHANNEL_NAME,
2366 &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.