22 #include <freerdp/config.h>
24 #include <winpr/crt.h>
25 #include <winpr/print.h>
26 #include <winpr/synch.h>
27 #include <winpr/thread.h>
28 #include <winpr/collections.h>
37 #include <freerdp/log.h>
38 #include <freerdp/peer.h>
39 #include <freerdp/codec/bitmap.h>
41 #include "../cache/pointer.h"
42 #include "../cache/palette.h"
43 #include "../cache/bitmap.h"
45 #define TAG FREERDP_TAG("core.update")
47 #define FORCE_ASYNC_UPDATE_OFF
49 static const char*
const UPDATE_TYPE_STRINGS[] = {
"Orders",
"Bitmap",
"Palette",
"Synchronize" };
51 static const char* update_type_to_string(UINT16 updateType)
53 if (updateType >= ARRAYSIZE(UPDATE_TYPE_STRINGS))
56 return UPDATE_TYPE_STRINGS[updateType];
59 static BOOL update_recv_orders(rdpUpdate* update,
wStream* s)
61 UINT16 numberOrders = 0;
65 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
68 Stream_Seek_UINT16(s);
69 Stream_Read_UINT16(s, numberOrders);
70 Stream_Seek_UINT16(s);
72 while (numberOrders > 0)
74 if (!update_recv_order(update, s))
76 WLog_ERR(TAG,
"update_recv_order() failed");
86 static BOOL update_read_bitmap_data(rdpUpdate* update,
wStream* s,
BITMAP_DATA* bitmapData)
89 WINPR_ASSERT(bitmapData);
91 if (!Stream_CheckAndLogRequiredLength(TAG, s, 18))
94 Stream_Read_UINT16(s, bitmapData->destLeft);
95 Stream_Read_UINT16(s, bitmapData->destTop);
96 Stream_Read_UINT16(s, bitmapData->destRight);
97 Stream_Read_UINT16(s, bitmapData->destBottom);
98 Stream_Read_UINT16(s, bitmapData->width);
99 Stream_Read_UINT16(s, bitmapData->height);
100 Stream_Read_UINT16(s, bitmapData->bitsPerPixel);
101 Stream_Read_UINT16(s, bitmapData->flags);
102 Stream_Read_UINT16(s, bitmapData->bitmapLength);
104 if ((bitmapData->width == 0) || (bitmapData->height == 0))
106 WLog_ERR(TAG,
"Invalid BITMAP_DATA: width=%" PRIu16
", height=%" PRIu16, bitmapData->width,
111 if (bitmapData->flags & BITMAP_COMPRESSION)
113 if (!(bitmapData->flags & NO_BITMAP_COMPRESSION_HDR))
115 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
118 Stream_Read_UINT16(s,
119 bitmapData->cbCompFirstRowSize);
120 Stream_Read_UINT16(s,
121 bitmapData->cbCompMainBodySize);
122 Stream_Read_UINT16(s, bitmapData->cbScanWidth);
123 Stream_Read_UINT16(s,
124 bitmapData->cbUncompressedSize);
125 bitmapData->bitmapLength = bitmapData->cbCompMainBodySize;
128 bitmapData->compressed = TRUE;
131 bitmapData->compressed = FALSE;
133 if (!Stream_CheckAndLogRequiredLength(TAG, s, bitmapData->bitmapLength))
136 if (bitmapData->bitmapLength > 0)
138 bitmapData->bitmapDataStream = malloc(bitmapData->bitmapLength);
140 if (!bitmapData->bitmapDataStream)
143 memcpy(bitmapData->bitmapDataStream, Stream_ConstPointer(s), bitmapData->bitmapLength);
144 Stream_Seek(s, bitmapData->bitmapLength);
150 static BOOL update_write_bitmap_data(rdpUpdate* update_pub,
wStream* s,
BITMAP_DATA* bitmapData)
154 WINPR_ASSERT(bitmapData);
156 if (!Stream_EnsureRemainingCapacity(s, 64 + bitmapData->bitmapLength))
159 if (update->common.autoCalculateBitmapData)
161 bitmapData->flags = 0;
162 bitmapData->cbCompFirstRowSize = 0;
164 if (bitmapData->compressed)
165 bitmapData->flags |= BITMAP_COMPRESSION;
167 if (update->common.context->settings->NoBitmapCompressionHeader)
169 bitmapData->flags |= NO_BITMAP_COMPRESSION_HDR;
170 bitmapData->cbCompMainBodySize = bitmapData->bitmapLength;
174 Stream_Write_UINT16(s, bitmapData->destLeft);
175 Stream_Write_UINT16(s, bitmapData->destTop);
176 Stream_Write_UINT16(s, bitmapData->destRight);
177 Stream_Write_UINT16(s, bitmapData->destBottom);
178 Stream_Write_UINT16(s, bitmapData->width);
179 Stream_Write_UINT16(s, bitmapData->height);
180 Stream_Write_UINT16(s, bitmapData->bitsPerPixel);
181 Stream_Write_UINT16(s, bitmapData->flags);
182 Stream_Write_UINT16(s, bitmapData->bitmapLength);
184 if (bitmapData->flags & BITMAP_COMPRESSION)
186 if (!(bitmapData->flags & NO_BITMAP_COMPRESSION_HDR))
188 Stream_Write_UINT16(s,
189 bitmapData->cbCompFirstRowSize);
190 Stream_Write_UINT16(s,
191 bitmapData->cbCompMainBodySize);
192 Stream_Write_UINT16(s, bitmapData->cbScanWidth);
193 Stream_Write_UINT16(s,
194 bitmapData->cbUncompressedSize);
197 Stream_Write(s, bitmapData->bitmapDataStream, bitmapData->bitmapLength);
201 Stream_Write(s, bitmapData->bitmapDataStream, bitmapData->bitmapLength);
215 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
218 Stream_Read_UINT16(s, bitmapUpdate->number);
219 WLog_Print(up->log, WLOG_TRACE,
"BitmapUpdate: %" PRIu32
"", bitmapUpdate->number);
223 if (!bitmapUpdate->rectangles)
227 for (UINT32 i = 0; i < bitmapUpdate->number; i++)
229 if (!update_read_bitmap_data(update, s, &bitmapUpdate->rectangles[i]))
235 WINPR_PRAGMA_DIAG_PUSH
236 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
237 free_bitmap_update(update->context, bitmapUpdate);
238 WINPR_PRAGMA_DIAG_POP
242 static BOOL update_write_bitmap_update(rdpUpdate* update,
wStream* s,
245 WINPR_ASSERT(update);
246 WINPR_ASSERT(bitmapUpdate);
248 if (!Stream_EnsureRemainingCapacity(s, 32))
251 Stream_Write_UINT16(s, UPDATE_TYPE_BITMAP);
252 Stream_Write_UINT16(s, bitmapUpdate->number);
255 for (UINT32 i = 0; i < bitmapUpdate->number; i++)
257 if (!update_write_bitmap_data(update, s, &bitmapUpdate->rectangles[i]))
271 if (!Stream_CheckAndLogRequiredLength(TAG, s, 6))
274 Stream_Seek_UINT16(s);
275 Stream_Read_UINT32(s, palette_update->number);
277 if (palette_update->number > 256)
278 palette_update->number = 256;
280 if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, palette_update->number, 3ull))
284 for (UINT32 i = 0; i < palette_update->number; i++)
287 Stream_Read_UINT8(s, entry->red);
288 Stream_Read_UINT8(s, entry->green);
289 Stream_Read_UINT8(s, entry->blue);
292 return palette_update;
294 WINPR_PRAGMA_DIAG_PUSH
295 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
296 free_palette_update(update->context, palette_update);
297 WINPR_PRAGMA_DIAG_POP
301 static BOOL update_read_synchronize(rdpUpdate* update,
wStream* s)
303 WINPR_UNUSED(update);
304 return Stream_SafeSeek(s, 2);
313 WINPR_ASSERT(play_sound);
315 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
318 Stream_Read_UINT32(s, play_sound->duration);
319 Stream_Read_UINT32(s, play_sound->frequency);
323 BOOL update_recv_play_sound(rdpUpdate* update,
wStream* s)
327 WINPR_ASSERT(update);
329 if (!update_read_play_sound(s, &play_sound))
332 return IFCALLRESULT(FALSE, update->PlaySound, update->context, &play_sound);
339 WINPR_ASSERT(update);
341 if (!pointer_position)
344 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
347 Stream_Read_UINT16(s, pointer_position->xPos);
348 Stream_Read_UINT16(s, pointer_position->yPos);
349 return pointer_position;
351 WINPR_PRAGMA_DIAG_PUSH
352 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
353 free_pointer_position_update(update->context, pointer_position);
354 WINPR_PRAGMA_DIAG_POP
362 WINPR_ASSERT(update);
367 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
370 Stream_Read_UINT32(s, pointer_system->type);
371 return pointer_system;
373 WINPR_PRAGMA_DIAG_PUSH
374 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
375 free_pointer_system_update(update->context, pointer_system);
376 WINPR_PRAGMA_DIAG_POP
381 BYTE xorBpp, UINT32 flags)
383 BYTE* newMask = NULL;
384 UINT32 scanlineSize = 0;
387 WINPR_ASSERT(pointer_color);
389 if (flags & LARGE_POINTER_FLAG_96x96)
395 if (!Stream_CheckAndLogRequiredLength(TAG, s, 14))
398 Stream_Read_UINT16(s, pointer_color->cacheIndex);
399 Stream_Read_UINT16(s, pointer_color->hotSpotX);
400 Stream_Read_UINT16(s, pointer_color->hotSpotY);
410 Stream_Read_UINT16(s, pointer_color->width);
411 Stream_Read_UINT16(s, pointer_color->height);
413 if ((pointer_color->width > max) || (pointer_color->height > max))
416 Stream_Read_UINT16(s, pointer_color->lengthAndMask);
417 Stream_Read_UINT16(s, pointer_color->lengthXorMask);
425 if (pointer_color->hotSpotX >= pointer_color->width)
426 pointer_color->hotSpotX = 0;
428 if (pointer_color->hotSpotY >= pointer_color->height)
429 pointer_color->hotSpotY = 0;
431 if (pointer_color->lengthXorMask > 0)
444 if (!Stream_CheckAndLogRequiredLength(TAG, s, pointer_color->lengthXorMask))
447 scanlineSize = (7 + xorBpp * pointer_color->width) / 8;
448 scanlineSize = ((scanlineSize + 1) / 2) * 2;
450 if (scanlineSize * pointer_color->height != pointer_color->lengthXorMask)
453 "invalid lengthXorMask: width=%" PRIu32
" height=%" PRIu32
", %" PRIu32
454 " instead of %" PRIu32
"",
455 pointer_color->width, pointer_color->height, pointer_color->lengthXorMask,
456 scanlineSize * pointer_color->height);
460 newMask = realloc(pointer_color->xorMaskData, pointer_color->lengthXorMask);
465 pointer_color->xorMaskData = newMask;
466 Stream_Read(s, pointer_color->xorMaskData, pointer_color->lengthXorMask);
469 if (pointer_color->lengthAndMask > 0)
478 if (!Stream_CheckAndLogRequiredLength(TAG, s, pointer_color->lengthAndMask))
481 scanlineSize = ((7 + pointer_color->width) / 8);
482 scanlineSize = ((1 + scanlineSize) / 2) * 2;
484 if (scanlineSize * pointer_color->height != pointer_color->lengthAndMask)
486 WLog_ERR(TAG,
"invalid lengthAndMask: %" PRIu32
" instead of %" PRIu32
"",
487 pointer_color->lengthAndMask, scanlineSize * pointer_color->height);
491 newMask = realloc(pointer_color->andMaskData, pointer_color->lengthAndMask);
496 pointer_color->andMaskData = newMask;
497 Stream_Read(s, pointer_color->andMaskData, pointer_color->lengthAndMask);
500 if (Stream_GetRemainingLength(s) > 0)
501 Stream_Seek_UINT8(s);
512 WINPR_ASSERT(update);
517 if (!s_update_read_pointer_color(s, pointer_color, xorBpp,
518 update->context->settings->LargePointerFlag))
521 return pointer_color;
523 WINPR_PRAGMA_DIAG_PUSH
524 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
525 free_pointer_color_update(update->context, pointer_color);
526 WINPR_PRAGMA_DIAG_POP
532 BYTE* newMask = NULL;
533 UINT32 scanlineSize = 0;
538 if (!Stream_CheckAndLogRequiredLength(TAG, s, 20))
541 Stream_Read_UINT16(s, pointer->xorBpp);
542 Stream_Read_UINT16(s, pointer->cacheIndex);
543 Stream_Read_UINT16(s, pointer->hotSpotX);
544 Stream_Read_UINT16(s, pointer->hotSpotY);
546 Stream_Read_UINT16(s, pointer->width);
547 Stream_Read_UINT16(s, pointer->height);
549 if ((pointer->width > 384) || (pointer->height > 384))
552 Stream_Read_UINT32(s, pointer->lengthAndMask);
553 Stream_Read_UINT32(s, pointer->lengthXorMask);
555 if (pointer->hotSpotX >= pointer->width)
556 pointer->hotSpotX = 0;
558 if (pointer->hotSpotY >= pointer->height)
559 pointer->hotSpotY = 0;
561 if (pointer->lengthXorMask > 0)
574 if (!Stream_CheckAndLogRequiredLength(TAG, s, pointer->lengthXorMask))
577 scanlineSize = (7 + pointer->xorBpp * pointer->width) / 8;
578 scanlineSize = ((scanlineSize + 1) / 2) * 2;
580 if (scanlineSize * pointer->height != pointer->lengthXorMask)
583 "invalid lengthXorMask: width=%" PRIu32
" height=%" PRIu32
", %" PRIu32
584 " instead of %" PRIu32
"",
585 pointer->width, pointer->height, pointer->lengthXorMask,
586 scanlineSize * pointer->height);
590 newMask = realloc(pointer->xorMaskData, pointer->lengthXorMask);
595 pointer->xorMaskData = newMask;
596 Stream_Read(s, pointer->xorMaskData, pointer->lengthXorMask);
599 if (pointer->lengthAndMask > 0)
608 if (!Stream_CheckAndLogRequiredLength(TAG, s, pointer->lengthAndMask))
611 scanlineSize = ((7 + pointer->width) / 8);
612 scanlineSize = ((1 + scanlineSize) / 2) * 2;
614 if (scanlineSize * pointer->height != pointer->lengthAndMask)
616 WLog_ERR(TAG,
"invalid lengthAndMask: %" PRIu32
" instead of %" PRIu32
"",
617 pointer->lengthAndMask, scanlineSize * pointer->height);
621 newMask = realloc(pointer->andMaskData, pointer->lengthAndMask);
626 pointer->andMaskData = newMask;
627 Stream_Read(s, pointer->andMaskData, pointer->lengthAndMask);
630 if (Stream_GetRemainingLength(s) > 0)
631 Stream_Seek_UINT8(s);
642 WINPR_ASSERT(update);
647 if (!s_update_read_pointer_large(s, pointer))
652 WINPR_PRAGMA_DIAG_PUSH
653 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
654 free_pointer_large_update(update->context, pointer);
655 WINPR_PRAGMA_DIAG_POP
663 WINPR_ASSERT(update);
668 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
671 Stream_Read_UINT16(s, pointer_new->xorBpp);
673 if ((pointer_new->xorBpp < 1) || (pointer_new->xorBpp > 32))
675 WLog_ERR(TAG,
"invalid xorBpp %" PRIu32
"", pointer_new->xorBpp);
679 if (!s_update_read_pointer_color(
680 s, &pointer_new->colorPtrAttr, pointer_new->xorBpp,
681 update->context->settings->LargePointerFlag))
686 WINPR_PRAGMA_DIAG_PUSH
687 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
688 free_pointer_new_update(update->context, pointer_new);
689 WINPR_PRAGMA_DIAG_POP
697 WINPR_ASSERT(update);
702 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
705 Stream_Read_UINT16(s, pointer->cacheIndex);
708 WINPR_PRAGMA_DIAG_PUSH
709 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
710 free_pointer_cached_update(update->context, pointer);
711 WINPR_PRAGMA_DIAG_POP
715 BOOL update_recv_pointer(rdpUpdate* update,
wStream* s)
718 UINT16 messageType = 0;
720 WINPR_ASSERT(update);
722 rdpContext* context = update->context;
723 rdpPointerUpdate* pointer = update->pointer;
725 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2 + 2))
728 Stream_Read_UINT16(s, messageType);
729 Stream_Seek_UINT16(s);
733 case PTR_MSG_TYPE_POSITION:
737 if (pointer_position)
739 rc = IFCALLRESULT(FALSE, pointer->PointerPosition, context, pointer_position);
740 free_pointer_position_update(context, pointer_position);
745 case PTR_MSG_TYPE_SYSTEM:
751 rc = IFCALLRESULT(FALSE, pointer->PointerSystem, context, pointer_system);
752 free_pointer_system_update(context, pointer_system);
757 case PTR_MSG_TYPE_COLOR:
763 rc = IFCALLRESULT(FALSE, pointer->PointerColor, context, pointer_color);
764 free_pointer_color_update(context, pointer_color);
769 case PTR_MSG_TYPE_POINTER_LARGE:
775 rc = IFCALLRESULT(FALSE, pointer->PointerLarge, context, pointer_large);
776 free_pointer_large_update(context, pointer_large);
781 case PTR_MSG_TYPE_POINTER:
787 rc = IFCALLRESULT(FALSE, pointer->PointerNew, context, pointer_new);
788 free_pointer_new_update(context, pointer_new);
793 case PTR_MSG_TYPE_CACHED:
799 rc = IFCALLRESULT(FALSE, pointer->PointerCached, context, pointer_cached);
800 free_pointer_cached_update(context, pointer_cached);
812 BOOL update_recv(rdpUpdate* update,
wStream* s)
815 UINT16 updateType = 0;
817 rdpContext* context = update->context;
819 WINPR_ASSERT(context);
821 if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
824 Stream_Read_UINT16(s, updateType);
825 WLog_Print(up->log, WLOG_TRACE,
"%s Update Data PDU", update_type_to_string(updateType));
827 if (!update_begin_paint(update))
832 case UPDATE_TYPE_ORDERS:
833 rc = update_recv_orders(update, s);
836 case UPDATE_TYPE_BITMAP:
838 BITMAP_UPDATE* bitmap_update = update_read_bitmap_update(update, s);
842 WLog_ERR(TAG,
"UPDATE_TYPE_BITMAP - update_read_bitmap_update() failed");
846 rc = IFCALLRESULT(FALSE, update->BitmapUpdate, context, bitmap_update);
847 free_bitmap_update(context, bitmap_update);
851 case UPDATE_TYPE_PALETTE:
857 WLog_ERR(TAG,
"UPDATE_TYPE_PALETTE - update_read_palette() failed");
861 rc = IFCALLRESULT(FALSE, update->Palette, context, palette_update);
862 free_palette_update(context, palette_update);
866 case UPDATE_TYPE_SYNCHRONIZE:
867 if (!update_read_synchronize(update, s))
869 rc = IFCALLRESULT(TRUE, update->Synchronize, context);
878 if (!update_end_paint(update))
883 WLog_ERR(TAG,
"UPDATE_TYPE %s [%" PRIu16
"] failed", update_type_to_string(updateType),
891 void update_reset_state(rdpUpdate* update)
896 WINPR_ASSERT(primary);
898 ZeroMemory(&primary->order_info,
sizeof(
ORDER_INFO));
911 free(primary->polyline.points);
920 free(primary->fast_glyph.glyphData.aj);
923 free(primary->polygon_sc.points);
926 free(primary->polygon_cb.points);
931 primary->order_info.orderType = ORDER_TYPE_PATBLT;
933 if (!up->initialState)
936 WINPR_ASSERT(altsec);
938 altsec->switch_surface.bitmapId = SCREEN_BITMAP_SURFACE;
939 IFCALL(altsec->common.SwitchSurface, update->context, &(altsec->switch_surface));
943 BOOL update_post_connect(rdpUpdate* update)
948 WINPR_ASSERT(update->context);
949 WINPR_ASSERT(update->context->settings);
950 up->asynchronous = update->context->settings->AsyncUpdate;
952 if (up->asynchronous)
954 #if defined(FORCE_ASYNC_UPDATE_OFF)
955 WLog_WARN(TAG,
"AsyncUpdate requested, but forced deactivated");
956 WLog_WARN(TAG,
"see https://github.com/FreeRDP/FreeRDP/issues/10153 for details");
958 if (!(up->proxy = update_message_proxy_new(update)))
963 altsec->switch_surface.bitmapId = SCREEN_BITMAP_SURFACE;
964 IFCALL(update->altsec->SwitchSurface, update->context, &(altsec->switch_surface));
965 up->initialState = FALSE;
969 void update_post_disconnect(rdpUpdate* update)
973 WINPR_ASSERT(update->context);
974 WINPR_ASSERT(update->context->settings);
976 up->asynchronous = update->context->settings->AsyncUpdate;
978 if (up->asynchronous)
980 #if !defined(FORCE_ASYNC_UPDATE_OFF)
981 update_message_proxy_free(up->proxy);
985 up->initialState = TRUE;
988 static BOOL s_update_begin_paint(rdpContext* context)
991 WINPR_ASSERT(context);
996 if (!update_end_paint(&update->common))
1000 WINPR_ASSERT(context->rdp);
1001 s = fastpath_update_pdu_init_new(context->rdp->fastpath);
1006 Stream_SealLength(s);
1007 Stream_GetLength(s, update->offsetOrders);
1009 update->combineUpdates = TRUE;
1010 update->numberOrders = 0;
1015 static BOOL s_update_end_paint(rdpContext* context)
1018 WINPR_ASSERT(context);
1025 Stream_SealLength(s);
1026 Stream_SetPosition(s, update->offsetOrders);
1027 Stream_Write_UINT16(s, update->numberOrders);
1028 Stream_SetPosition(s, Stream_Length(s));
1030 if (update->numberOrders > 0)
1032 WLog_DBG(TAG,
"sending %" PRIu16
" orders", update->numberOrders);
1033 fastpath_send_update_pdu(context->rdp->fastpath, FASTPATH_UPDATETYPE_ORDERS, s, FALSE);
1036 update->combineUpdates = FALSE;
1037 update->numberOrders = 0;
1038 update->offsetOrders = 0;
1040 Stream_Free(s, TRUE);
1044 static void update_flush(rdpContext* context)
1048 WINPR_ASSERT(context);
1049 update = update_cast(context->update);
1051 if (update->numberOrders > 0)
1053 update_end_paint(&update->common);
1054 update_begin_paint(&update->common);
1058 static void update_force_flush(rdpContext* context)
1060 update_flush(context);
1063 static BOOL update_check_flush(rdpContext* context,
size_t size)
1065 WINPR_ASSERT(context);
1072 update_begin_paint(&update->common);
1076 if (Stream_GetPosition(s) + size + 64 >= 0x3FFF)
1078 update_flush(context);
1085 static BOOL update_set_bounds(rdpContext* context,
const rdpBounds* bounds)
1089 WINPR_ASSERT(context);
1091 update = update_cast(context->update);
1093 CopyMemory(&update->previousBounds, &update->currentBounds,
sizeof(rdpBounds));
1096 ZeroMemory(&update->currentBounds,
sizeof(rdpBounds));
1098 CopyMemory(&update->currentBounds, bounds,
sizeof(rdpBounds));
1103 static BOOL update_bounds_is_null(rdpBounds* bounds)
1105 WINPR_ASSERT(bounds);
1106 if ((bounds->left == 0) && (bounds->top == 0) && (bounds->right == 0) && (bounds->bottom == 0))
1112 static BOOL update_bounds_equals(rdpBounds* bounds1, rdpBounds* bounds2)
1114 WINPR_ASSERT(bounds1);
1115 WINPR_ASSERT(bounds2);
1117 if ((bounds1->left == bounds2->left) && (bounds1->top == bounds2->top) &&
1118 (bounds1->right == bounds2->right) && (bounds1->bottom == bounds2->bottom))
1124 static int update_prepare_bounds(rdpContext* context,
ORDER_INFO* orderInfo)
1129 WINPR_ASSERT(context);
1130 WINPR_ASSERT(orderInfo);
1132 update = update_cast(context->update);
1134 orderInfo->boundsFlags = 0;
1136 if (update_bounds_is_null(&update->currentBounds))
1139 orderInfo->controlFlags |= ORDER_BOUNDS;
1141 if (update_bounds_equals(&update->previousBounds, &update->currentBounds))
1143 orderInfo->controlFlags |= ORDER_ZERO_BOUNDS_DELTAS;
1150 if (update->previousBounds.left != update->currentBounds.left)
1152 orderInfo->bounds.left = update->currentBounds.left;
1153 orderInfo->boundsFlags |= BOUND_LEFT;
1157 if (update->previousBounds.top != update->currentBounds.top)
1159 orderInfo->bounds.top = update->currentBounds.top;
1160 orderInfo->boundsFlags |= BOUND_TOP;
1164 if (update->previousBounds.right != update->currentBounds.right)
1166 orderInfo->bounds.right = update->currentBounds.right;
1167 orderInfo->boundsFlags |= BOUND_RIGHT;
1171 if (update->previousBounds.bottom != update->currentBounds.bottom)
1173 orderInfo->bounds.bottom = update->currentBounds.bottom;
1174 orderInfo->boundsFlags |= BOUND_BOTTOM;
1182 static size_t update_prepare_order_info(rdpContext* context,
ORDER_INFO* orderInfo,
1185 WINPR_ASSERT(context);
1186 WINPR_ASSERT(orderInfo);
1188 orderInfo->fieldFlags = 0;
1189 orderInfo->orderType = orderType;
1190 orderInfo->controlFlags = ORDER_STANDARD;
1191 orderInfo->controlFlags |= ORDER_TYPE_CHANGE;
1193 length += get_primary_drawing_order_field_bytes(orderInfo->orderType, NULL);
1194 length += update_prepare_bounds(context, orderInfo);
1198 static int update_write_order_info(rdpContext* context,
wStream* s,
ORDER_INFO* orderInfo,
1201 size_t position = 0;
1203 WINPR_UNUSED(context);
1204 WINPR_ASSERT(orderInfo);
1206 position = Stream_GetPosition(s);
1207 Stream_SetPosition(s, offset);
1208 Stream_Write_UINT8(s, orderInfo->controlFlags);
1210 if (orderInfo->controlFlags & ORDER_TYPE_CHANGE)
1211 Stream_Write_UINT8(s, orderInfo->orderType);
1213 if (!update_write_field_flags(
1214 s, orderInfo->fieldFlags, orderInfo->controlFlags,
1215 get_primary_drawing_order_field_bytes(orderInfo->orderType, NULL)))
1217 if (!update_write_bounds(s, orderInfo))
1219 Stream_SetPosition(s, position);
1226 WINPR_ASSERT(areas || (count == 0));
1228 Stream_Write_UINT8(s, count);
1231 for (BYTE i = 0; i < count; i++)
1233 Stream_Write_UINT16(s, areas[i].left);
1234 Stream_Write_UINT16(s, areas[i].top);
1235 Stream_Write_UINT16(s, areas[i].right);
1236 Stream_Write_UINT16(s, areas[i].bottom);
1240 static BOOL update_send_refresh_rect(rdpContext* context, BYTE count,
const RECTANGLE_16* areas)
1242 WINPR_ASSERT(context);
1243 rdpRdp* rdp = context->rdp;
1245 WINPR_ASSERT(rdp->settings);
1246 if (rdp->settings->RefreshRect)
1248 wStream* s = rdp_data_pdu_init(rdp);
1253 update_write_refresh_rect(s, count, areas);
1254 return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_REFRESH_RECT, rdp->mcs->userId);
1260 static void update_write_suppress_output(
wStream* s, BYTE allow,
const RECTANGLE_16* area)
1264 Stream_Write_UINT8(s, allow);
1271 Stream_Write_UINT16(s, area->left);
1272 Stream_Write_UINT16(s, area->top);
1273 Stream_Write_UINT16(s, area->right);
1274 Stream_Write_UINT16(s, area->bottom);
1278 static BOOL update_send_suppress_output(rdpContext* context, BYTE allow,
const RECTANGLE_16* area)
1280 WINPR_ASSERT(context);
1281 rdpRdp* rdp = context->rdp;
1284 WINPR_ASSERT(rdp->settings);
1285 if (rdp->settings->SuppressOutput)
1287 wStream* s = rdp_data_pdu_init(rdp);
1292 update_write_suppress_output(s, allow, area);
1293 WINPR_ASSERT(rdp->mcs);
1294 return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SUPPRESS_OUTPUT, rdp->mcs->userId);
1300 static BOOL update_send_surface_command(rdpContext* context,
wStream* s)
1303 WINPR_ASSERT(context);
1304 rdpRdp* rdp = context->rdp;
1308 update = fastpath_update_pdu_init(rdp->fastpath);
1313 if (!Stream_EnsureRemainingCapacity(update, Stream_GetPosition(s)))
1319 Stream_Write(update, Stream_Buffer(s), Stream_GetPosition(s));
1320 ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, update, FALSE);
1322 Stream_Release(update);
1326 static BOOL update_send_surface_bits(rdpContext* context,
1330 WINPR_ASSERT(context);
1331 rdpRdp* rdp = context->rdp;
1334 WINPR_ASSERT(surfaceBitsCommand);
1337 update_force_flush(context);
1338 s = fastpath_update_pdu_init(rdp->fastpath);
1343 if (!update_write_surfcmd_surface_bits(s, surfaceBitsCommand))
1346 if (!fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s,
1347 surfaceBitsCommand->skipCompression))
1350 update_force_flush(context);
1357 static BOOL update_send_surface_frame_marker(rdpContext* context,
1361 WINPR_ASSERT(context);
1362 rdpRdp* rdp = context->rdp;
1364 update_force_flush(context);
1367 s = fastpath_update_pdu_init(rdp->fastpath);
1372 if (!update_write_surfcmd_frame_marker(s, surfaceFrameMarker->frameAction,
1373 surfaceFrameMarker->frameId) ||
1374 !fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s, FALSE))
1377 update_force_flush(context);
1384 static BOOL update_send_surface_frame_bits(rdpContext* context,
const SURFACE_BITS_COMMAND* cmd,
1385 BOOL first, BOOL last, UINT32 frameId)
1389 WINPR_ASSERT(context);
1390 rdpRdp* rdp = context->rdp;
1393 update_force_flush(context);
1396 s = fastpath_update_pdu_init(rdp->fastpath);
1403 if (!update_write_surfcmd_frame_marker(s, SURFACECMD_FRAMEACTION_BEGIN, frameId))
1407 if (!update_write_surfcmd_surface_bits(s, cmd))
1412 if (!update_write_surfcmd_frame_marker(s, SURFACECMD_FRAMEACTION_END, frameId))
1416 ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s,
1417 cmd->skipCompression);
1418 update_force_flush(context);
1424 static BOOL update_send_frame_acknowledge(rdpContext* context, UINT32 frameId)
1426 WINPR_ASSERT(context);
1427 rdpRdp* rdp = context->rdp;
1430 WINPR_ASSERT(rdp->settings);
1431 if (rdp->settings->ReceivedCapabilities[CAPSET_TYPE_FRAME_ACKNOWLEDGE])
1433 wStream* s = rdp_data_pdu_init(rdp);
1438 Stream_Write_UINT32(s, frameId);
1439 return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FRAME_ACKNOWLEDGE, rdp->mcs->userId);
1445 static BOOL update_send_synchronize(rdpContext* context)
1448 WINPR_ASSERT(context);
1449 rdpRdp* rdp = context->rdp;
1453 s = fastpath_update_pdu_init(rdp->fastpath);
1459 ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SYNCHRONIZE, s, FALSE);
1464 static BOOL update_send_desktop_resize(rdpContext* context)
1466 WINPR_ASSERT(context);
1467 return rdp_server_reactivate(context->rdp);
1470 static BOOL update_send_bitmap_update(rdpContext* context,
const BITMAP_UPDATE* bitmapUpdate)
1473 WINPR_ASSERT(context);
1474 rdpRdp* rdp = context->rdp;
1475 rdpUpdate* update = context->update;
1478 update_force_flush(context);
1481 s = fastpath_update_pdu_init(rdp->fastpath);
1486 if (!update_write_bitmap_update(update, s, bitmapUpdate) ||
1487 !fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_BITMAP, s,
1488 bitmapUpdate->skipCompression))
1494 update_force_flush(context);
1500 static BOOL update_send_play_sound(rdpContext* context,
const PLAY_SOUND_UPDATE* play_sound)
1503 WINPR_ASSERT(context);
1504 rdpRdp* rdp = context->rdp;
1507 WINPR_ASSERT(rdp->settings);
1508 WINPR_ASSERT(play_sound);
1509 if (!rdp->settings->ReceivedCapabilities[CAPSET_TYPE_SOUND])
1514 s = rdp_data_pdu_init(rdp);
1519 Stream_Write_UINT32(s, play_sound->duration);
1520 Stream_Write_UINT32(s, play_sound->frequency);
1521 return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_PLAY_SOUND, rdp->mcs->userId);
1528 static BOOL update_send_dstblt(rdpContext* context,
const DSTBLT_ORDER* dstblt)
1532 WINPR_ASSERT(context);
1533 WINPR_ASSERT(dstblt);
1537 const size_t headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_DSTBLT);
1538 const size_t inf = update_approximate_dstblt_order(&orderInfo, dstblt);
1539 if (!update_check_flush(context, headerLength + inf))
1547 const size_t offset = Stream_GetPosition(s);
1549 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1552 Stream_Seek(s, headerLength);
1554 if (!update_write_dstblt_order(s, &orderInfo, dstblt))
1557 update_write_order_info(context, s, &orderInfo, offset);
1558 update->numberOrders++;
1562 static BOOL update_send_patblt(rdpContext* context,
PATBLT_ORDER* patblt)
1567 WINPR_ASSERT(context);
1568 WINPR_ASSERT(patblt);
1571 const size_t headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_PATBLT);
1572 if (!update_check_flush(context,
1573 headerLength + update_approximate_patblt_order(&orderInfo, patblt)))
1581 offset = Stream_GetPosition(s);
1583 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1586 Stream_Seek(s, headerLength);
1587 update_write_patblt_order(s, &orderInfo, patblt);
1588 update_write_order_info(context, s, &orderInfo, offset);
1589 update->numberOrders++;
1593 static BOOL update_send_scrblt(rdpContext* context,
const SCRBLT_ORDER* scrblt)
1597 WINPR_ASSERT(context);
1598 WINPR_ASSERT(scrblt);
1601 const size_t headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_SCRBLT);
1602 const size_t inf = update_approximate_scrblt_order(&orderInfo, scrblt);
1603 if (!update_check_flush(context, headerLength + inf))
1611 const size_t offset = Stream_GetPosition(s);
1613 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1616 Stream_Seek(s, headerLength);
1617 update_write_scrblt_order(s, &orderInfo, scrblt);
1618 update_write_order_info(context, s, &orderInfo, offset);
1619 update->numberOrders++;
1623 static BOOL update_send_opaque_rect(rdpContext* context,
const OPAQUE_RECT_ORDER* opaque_rect)
1628 WINPR_ASSERT(context);
1629 WINPR_ASSERT(opaque_rect);
1632 const size_t headerLength =
1633 update_prepare_order_info(context, &orderInfo, ORDER_TYPE_OPAQUE_RECT);
1634 if (!update_check_flush(
1635 context, headerLength + update_approximate_opaque_rect_order(&orderInfo, opaque_rect)))
1643 offset = Stream_GetPosition(s);
1645 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1648 Stream_Seek(s, headerLength);
1649 update_write_opaque_rect_order(s, &orderInfo, opaque_rect);
1650 update_write_order_info(context, s, &orderInfo, offset);
1651 update->numberOrders++;
1655 static BOOL update_send_line_to(rdpContext* context,
const LINE_TO_ORDER* line_to)
1659 WINPR_ASSERT(context);
1660 WINPR_ASSERT(line_to);
1662 const size_t headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_LINE_TO);
1663 const size_t inf = update_approximate_line_to_order(&orderInfo, line_to);
1664 if (!update_check_flush(context, headerLength + inf))
1672 const size_t offset = Stream_GetPosition(s);
1674 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1677 Stream_Seek(s, headerLength);
1678 update_write_line_to_order(s, &orderInfo, line_to);
1679 update_write_order_info(context, s, &orderInfo, offset);
1680 update->numberOrders++;
1684 static BOOL update_send_memblt(rdpContext* context,
MEMBLT_ORDER* memblt)
1689 WINPR_ASSERT(context);
1690 WINPR_ASSERT(memblt);
1692 const size_t headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_MEMBLT);
1693 if (!update_check_flush(context,
1694 headerLength + update_approximate_memblt_order(&orderInfo, memblt)))
1702 offset = Stream_GetPosition(s);
1704 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1707 Stream_Seek(s, headerLength);
1708 update_write_memblt_order(s, &orderInfo, memblt);
1709 update_write_order_info(context, s, &orderInfo, offset);
1710 update->numberOrders++;
1714 static BOOL update_send_glyph_index(rdpContext* context,
GLYPH_INDEX_ORDER* glyph_index)
1718 WINPR_ASSERT(context);
1719 WINPR_ASSERT(glyph_index);
1722 const size_t headerLength =
1723 update_prepare_order_info(context, &orderInfo, ORDER_TYPE_GLYPH_INDEX);
1724 const size_t inf = update_approximate_glyph_index_order(&orderInfo, glyph_index);
1725 if (!update_check_flush(context, headerLength + inf))
1733 const size_t offset = Stream_GetPosition(s);
1735 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1738 Stream_Seek(s, headerLength);
1739 update_write_glyph_index_order(s, &orderInfo, glyph_index);
1740 update_write_order_info(context, s, &orderInfo, offset);
1741 update->numberOrders++;
1749 static BOOL update_send_cache_bitmap(rdpContext* context,
const CACHE_BITMAP_ORDER* cache_bitmap)
1751 const size_t headerLength = 6;
1752 UINT16 extraFlags = 0;
1754 WINPR_ASSERT(context);
1755 WINPR_ASSERT(cache_bitmap);
1758 const BYTE orderType = cache_bitmap->compressed ? ORDER_TYPE_CACHE_BITMAP_COMPRESSED
1759 : ORDER_TYPE_BITMAP_UNCOMPRESSED;
1761 update_approximate_cache_bitmap_order(cache_bitmap, cache_bitmap->compressed, &extraFlags);
1762 if (!update_check_flush(context, headerLength + inf))
1770 const size_t bm = Stream_GetPosition(s);
1772 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1775 Stream_Seek(s, headerLength);
1777 if (!update_write_cache_bitmap_order(s, cache_bitmap, cache_bitmap->compressed, &extraFlags))
1780 const size_t em = Stream_GetPosition(s);
1781 WINPR_ASSERT(em >= bm + 13);
1782 const size_t orderLength = (em - bm) - 13;
1783 WINPR_ASSERT(orderLength <= UINT16_MAX);
1785 Stream_SetPosition(s, bm);
1786 Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY);
1787 Stream_Write_UINT16(s, (UINT16)orderLength);
1788 Stream_Write_UINT16(s, extraFlags);
1789 Stream_Write_UINT8(s, orderType);
1790 Stream_SetPosition(s, em);
1791 update->numberOrders++;
1795 static BOOL update_send_cache_bitmap_v2(rdpContext* context,
CACHE_BITMAP_V2_ORDER* cache_bitmap_v2)
1797 const size_t headerLength = 6;
1798 UINT16 extraFlags = 0;
1800 WINPR_ASSERT(context);
1801 WINPR_ASSERT(cache_bitmap_v2);
1804 const BYTE orderType = cache_bitmap_v2->compressed ? ORDER_TYPE_BITMAP_COMPRESSED_V2
1805 : ORDER_TYPE_BITMAP_UNCOMPRESSED_V2;
1807 if (context->settings->NoBitmapCompressionHeader)
1808 cache_bitmap_v2->flags |= CBR2_NO_BITMAP_COMPRESSION_HDR;
1810 if (!update_check_flush(
1811 context, headerLength + update_approximate_cache_bitmap_v2_order(
1812 cache_bitmap_v2, cache_bitmap_v2->compressed, &extraFlags)))
1820 const size_t bm = Stream_GetPosition(s);
1822 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1825 Stream_Seek(s, headerLength);
1827 if (!update_write_cache_bitmap_v2_order(s, cache_bitmap_v2, cache_bitmap_v2->compressed,
1831 const size_t em = Stream_GetPosition(s);
1832 WINPR_ASSERT(em >= bm + 13);
1833 const size_t orderLength = (em - bm) - 13;
1834 WINPR_ASSERT(orderLength <= UINT16_MAX);
1836 Stream_SetPosition(s, bm);
1837 Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY);
1838 Stream_Write_UINT16(s, (UINT16)orderLength);
1839 Stream_Write_UINT16(s, extraFlags);
1840 Stream_Write_UINT8(s, orderType);
1841 Stream_SetPosition(s, em);
1842 update->numberOrders++;
1846 static BOOL update_send_cache_bitmap_v3(rdpContext* context,
CACHE_BITMAP_V3_ORDER* cache_bitmap_v3)
1848 const size_t headerLength = 6;
1849 UINT16 extraFlags = 0;
1851 WINPR_ASSERT(context);
1852 WINPR_ASSERT(cache_bitmap_v3);
1855 const BYTE orderType = ORDER_TYPE_BITMAP_COMPRESSED_V3;
1856 if (!update_check_flush(context, headerLength + update_approximate_cache_bitmap_v3_order(
1857 cache_bitmap_v3, &extraFlags)))
1865 const size_t bm = Stream_GetPosition(s);
1867 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1870 Stream_Seek(s, headerLength);
1872 if (!update_write_cache_bitmap_v3_order(s, cache_bitmap_v3, &extraFlags))
1875 const size_t em = Stream_GetPosition(s);
1876 WINPR_ASSERT(em >= bm + 13);
1877 const size_t orderLength = (em - bm) - 13;
1878 WINPR_ASSERT(orderLength <= UINT16_MAX);
1880 Stream_SetPosition(s, bm);
1881 Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY);
1882 Stream_Write_UINT16(s, (UINT16)orderLength);
1883 Stream_Write_UINT16(s, extraFlags);
1884 Stream_Write_UINT8(s, orderType);
1885 Stream_SetPosition(s, em);
1886 update->numberOrders++;
1890 static BOOL update_send_cache_color_table(rdpContext* context,
1894 size_t headerLength = 6;
1896 WINPR_ASSERT(context);
1897 WINPR_ASSERT(cache_color_table);
1900 const size_t inf = update_approximate_cache_color_table_order(cache_color_table, &flags);
1901 if (!update_check_flush(context, headerLength + inf))
1909 const size_t bm = Stream_GetPosition(s);
1911 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1914 Stream_Seek(s, headerLength);
1916 if (!update_write_cache_color_table_order(s, cache_color_table, &flags))
1919 const size_t em = Stream_GetPosition(s);
1920 WINPR_ASSERT(em >= bm + 13);
1921 const size_t orderLength = (em - bm) - 13;
1922 WINPR_ASSERT(orderLength <= UINT16_MAX);
1923 Stream_SetPosition(s, bm);
1924 Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY);
1925 Stream_Write_UINT16(s, (UINT16)orderLength);
1926 Stream_Write_UINT16(s, flags);
1927 Stream_Write_UINT8(s, ORDER_TYPE_CACHE_COLOR_TABLE);
1928 Stream_SetPosition(s, em);
1929 update->numberOrders++;
1933 static BOOL update_send_cache_glyph(rdpContext* context,
const CACHE_GLYPH_ORDER* cache_glyph)
1936 const size_t headerLength = 6;
1938 WINPR_ASSERT(context);
1939 WINPR_ASSERT(cache_glyph);
1942 const size_t inf = update_approximate_cache_glyph_order(cache_glyph, &flags);
1943 if (!update_check_flush(context, headerLength + inf))
1951 const size_t bm = Stream_GetPosition(s);
1953 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1956 Stream_Seek(s, headerLength);
1958 if (!update_write_cache_glyph_order(s, cache_glyph, &flags))
1961 const size_t em = Stream_GetPosition(s);
1962 WINPR_ASSERT(em >= bm + 13);
1963 const size_t orderLength = (em - bm) - 13;
1964 WINPR_ASSERT(orderLength <= UINT16_MAX);
1965 Stream_SetPosition(s, bm);
1966 Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY);
1967 Stream_Write_UINT16(s, (UINT16)orderLength);
1968 Stream_Write_UINT16(s, flags);
1969 Stream_Write_UINT8(s, ORDER_TYPE_CACHE_GLYPH);
1970 Stream_SetPosition(s, em);
1971 update->numberOrders++;
1975 static BOOL update_send_cache_glyph_v2(rdpContext* context,
1979 const size_t headerLength = 6;
1981 WINPR_ASSERT(context);
1982 WINPR_ASSERT(cache_glyph_v2);
1985 const size_t inf = update_approximate_cache_glyph_v2_order(cache_glyph_v2, &flags);
1986 if (!update_check_flush(context, headerLength + inf))
1994 const size_t bm = Stream_GetPosition(s);
1996 if (!Stream_EnsureRemainingCapacity(s, headerLength))
1999 Stream_Seek(s, headerLength);
2001 if (!update_write_cache_glyph_v2_order(s, cache_glyph_v2, &flags))
2004 const size_t em = Stream_GetPosition(s);
2005 WINPR_ASSERT(em >= bm + 13);
2006 const size_t orderLength = (em - bm) - 13;
2007 WINPR_ASSERT(orderLength <= UINT16_MAX);
2008 Stream_SetPosition(s, bm);
2009 Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY);
2010 Stream_Write_UINT16(s, (UINT16)orderLength);
2011 Stream_Write_UINT16(s, flags);
2012 Stream_Write_UINT8(s, ORDER_TYPE_CACHE_GLYPH);
2013 Stream_SetPosition(s, em);
2014 update->numberOrders++;
2018 static BOOL update_send_cache_brush(rdpContext* context,
const CACHE_BRUSH_ORDER* cache_brush)
2021 const size_t headerLength = 6;
2023 WINPR_ASSERT(context);
2024 WINPR_ASSERT(cache_brush);
2027 const size_t inf = update_approximate_cache_brush_order(cache_brush, &flags);
2028 if (!update_check_flush(context, headerLength + inf))
2036 const size_t bm = Stream_GetPosition(s);
2038 if (!Stream_EnsureRemainingCapacity(s, headerLength))
2041 Stream_Seek(s, headerLength);
2043 if (!update_write_cache_brush_order(s, cache_brush, &flags))
2046 const size_t em = Stream_GetPosition(s);
2050 const size_t orderLength = (em - bm) - 13;
2051 WINPR_ASSERT(orderLength <= UINT16_MAX);
2052 Stream_SetPosition(s, bm);
2053 Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY);
2054 Stream_Write_UINT16(s, (UINT16)orderLength);
2055 Stream_Write_UINT16(s, flags);
2056 Stream_Write_UINT8(s, ORDER_TYPE_CACHE_BRUSH);
2057 Stream_SetPosition(s, em);
2058 update->numberOrders++;
2066 static BOOL update_send_create_offscreen_bitmap_order(
2069 WINPR_ASSERT(context);
2070 WINPR_ASSERT(create_offscreen_bitmap);
2073 const size_t headerLength = 1;
2074 const size_t orderType = ORDER_TYPE_CREATE_OFFSCREEN_BITMAP;
2075 const size_t controlFlags = ORDER_SECONDARY | (orderType << 2);
2076 const size_t inf = update_approximate_create_offscreen_bitmap_order(create_offscreen_bitmap);
2077 if (!update_check_flush(context, headerLength + inf))
2085 const size_t bm = Stream_GetPosition(s);
2087 if (!Stream_EnsureRemainingCapacity(s, headerLength))
2090 Stream_Seek(s, headerLength);
2092 if (!update_write_create_offscreen_bitmap_order(s, create_offscreen_bitmap))
2095 const size_t em = Stream_GetPosition(s);
2096 Stream_SetPosition(s, bm);
2097 Stream_Write_UINT8(s, controlFlags);
2098 Stream_SetPosition(s, em);
2099 update->numberOrders++;
2103 static BOOL update_send_switch_surface_order(rdpContext* context,
2106 WINPR_ASSERT(context);
2107 WINPR_ASSERT(switch_surface);
2110 const size_t headerLength = 1;
2111 const size_t orderType = ORDER_TYPE_SWITCH_SURFACE;
2112 const size_t controlFlags = ORDER_SECONDARY | (orderType << 2);
2113 const size_t inf = update_approximate_switch_surface_order(switch_surface);
2114 if (!update_check_flush(context, headerLength + inf))
2122 const size_t bm = Stream_GetPosition(s);
2124 if (!Stream_EnsureRemainingCapacity(s, headerLength))
2127 Stream_Seek(s, headerLength);
2129 if (!update_write_switch_surface_order(s, switch_surface))
2132 const size_t em = Stream_GetPosition(s);
2133 Stream_SetPosition(s, bm);
2134 Stream_Write_UINT8(s, controlFlags);
2135 Stream_SetPosition(s, em);
2136 update->numberOrders++;
2140 static BOOL update_send_pointer_system(rdpContext* context,
2144 BYTE updateCode = 0;
2146 WINPR_ASSERT(context);
2147 rdpRdp* rdp = context->rdp;
2151 s = fastpath_update_pdu_init(rdp->fastpath);
2156 if (pointer_system->type == SYSPTR_NULL)
2157 updateCode = FASTPATH_UPDATETYPE_PTR_NULL;
2159 updateCode = FASTPATH_UPDATETYPE_PTR_DEFAULT;
2161 ret = fastpath_send_update_pdu(rdp->fastpath, updateCode, s, FALSE);
2166 static BOOL update_send_pointer_position(rdpContext* context,
2170 WINPR_ASSERT(context);
2171 rdpRdp* rdp = context->rdp;
2175 s = fastpath_update_pdu_init(rdp->fastpath);
2180 if (!Stream_EnsureRemainingCapacity(s, 16))
2183 Stream_Write_UINT16(s, pointerPosition->xPos);
2184 Stream_Write_UINT16(s, pointerPosition->yPos);
2185 ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_PTR_POSITION, s, FALSE);
2193 WINPR_ASSERT(pointer_color);
2194 if (!Stream_EnsureRemainingCapacity(s, 32 + pointer_color->lengthAndMask +
2195 pointer_color->lengthXorMask))
2198 Stream_Write_UINT16(s, pointer_color->cacheIndex);
2199 Stream_Write_UINT16(s, pointer_color->hotSpotX);
2200 Stream_Write_UINT16(s, pointer_color->hotSpotY);
2201 Stream_Write_UINT16(s, pointer_color->width);
2202 Stream_Write_UINT16(s, pointer_color->height);
2203 Stream_Write_UINT16(s, pointer_color->lengthAndMask);
2204 Stream_Write_UINT16(s, pointer_color->lengthXorMask);
2206 if (pointer_color->lengthXorMask > 0)
2207 Stream_Write(s, pointer_color->xorMaskData, pointer_color->lengthXorMask);
2209 if (pointer_color->lengthAndMask > 0)
2210 Stream_Write(s, pointer_color->andMaskData, pointer_color->lengthAndMask);
2212 Stream_Write_UINT8(s, 0);
2216 static BOOL update_send_pointer_color(rdpContext* context,
2221 WINPR_ASSERT(context);
2222 rdpRdp* rdp = context->rdp;
2226 WINPR_ASSERT(pointer_color);
2227 s = fastpath_update_pdu_init(rdp->fastpath);
2232 if (!update_write_pointer_color(s, pointer_color))
2235 ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_COLOR, s, FALSE);
2243 WINPR_ASSERT(pointer);
2245 if (!Stream_EnsureRemainingCapacity(s, 32 + pointer->lengthAndMask + pointer->lengthXorMask))
2248 Stream_Write_UINT16(s, pointer->xorBpp);
2249 Stream_Write_UINT16(s, pointer->cacheIndex);
2250 Stream_Write_UINT16(s, pointer->hotSpotX);
2251 Stream_Write_UINT16(s, pointer->hotSpotY);
2252 Stream_Write_UINT16(s, pointer->width);
2253 Stream_Write_UINT16(s, pointer->height);
2254 Stream_Write_UINT32(s, pointer->lengthAndMask);
2255 Stream_Write_UINT32(s, pointer->lengthXorMask);
2256 Stream_Write(s, pointer->xorMaskData, pointer->lengthXorMask);
2257 Stream_Write(s, pointer->andMaskData, pointer->lengthAndMask);
2258 Stream_Write_UINT8(s, 0);
2262 static BOOL update_send_pointer_large(rdpContext* context,
const POINTER_LARGE_UPDATE* pointer)
2265 WINPR_ASSERT(context);
2266 rdpRdp* rdp = context->rdp;
2270 WINPR_ASSERT(pointer);
2271 s = fastpath_update_pdu_init(rdp->fastpath);
2276 if (!update_write_pointer_large(s, pointer))
2279 ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_LARGE_POINTER, s, FALSE);
2285 static BOOL update_send_pointer_new(rdpContext* context,
const POINTER_NEW_UPDATE* pointer_new)
2289 WINPR_ASSERT(context);
2290 rdpRdp* rdp = context->rdp;
2294 WINPR_ASSERT(pointer_new);
2295 s = fastpath_update_pdu_init(rdp->fastpath);
2300 if (!Stream_EnsureRemainingCapacity(s, 16))
2303 Stream_Write_UINT16(s, pointer_new->xorBpp);
2304 update_write_pointer_color(s, &pointer_new->colorPtrAttr);
2305 ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_POINTER, s, FALSE);
2311 static BOOL update_send_pointer_cached(rdpContext* context,
2316 WINPR_ASSERT(context);
2317 rdpRdp* rdp = context->rdp;
2321 WINPR_ASSERT(pointer_cached);
2322 s = fastpath_update_pdu_init(rdp->fastpath);
2327 Stream_Write_UINT16(s, pointer_cached->cacheIndex);
2328 ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_CACHED, s, FALSE);
2333 BOOL update_read_refresh_rect(rdpUpdate* update,
wStream* s)
2335 BYTE numberOfAreas = 0;
2339 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
2342 Stream_Read_UINT8(s, numberOfAreas);
2345 if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, numberOfAreas, 8ull))
2348 for (BYTE index = 0; index < numberOfAreas; index++)
2352 Stream_Read_UINT16(s, area->left);
2353 Stream_Read_UINT16(s, area->top);
2354 Stream_Read_UINT16(s, area->right);
2355 Stream_Read_UINT16(s, area->bottom);
2358 WINPR_ASSERT(update->context);
2359 WINPR_ASSERT(update->context->settings);
2360 if (update->context->settings->RefreshRect)
2361 IFCALL(update->RefreshRect, update->context, numberOfAreas, areas);
2363 WLog_Print(up->log, WLOG_WARN,
"ignoring refresh rect request from client");
2368 BOOL update_read_suppress_output(rdpUpdate* update,
wStream* s)
2373 BYTE allowDisplayUpdates = 0;
2378 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
2381 Stream_Read_UINT8(s, allowDisplayUpdates);
2384 if (allowDisplayUpdates > 0)
2386 if (!Stream_CheckAndLogRequiredLength(TAG, s,
sizeof(
RECTANGLE_16)))
2389 Stream_Read_UINT16(s, rect.left);
2390 Stream_Read_UINT16(s, rect.top);
2391 Stream_Read_UINT16(s, rect.right);
2392 Stream_Read_UINT16(s, rect.bottom);
2397 WINPR_ASSERT(update->context);
2398 WINPR_ASSERT(update->context->settings);
2399 if (update->context->settings->SuppressOutput)
2400 IFCALL(update->SuppressOutput, update->context, allowDisplayUpdates, prect);
2402 WLog_Print(up->log, WLOG_WARN,
"ignoring suppress output request from client");
2407 static BOOL update_send_set_keyboard_indicators(rdpContext* context, UINT16 led_flags)
2411 WINPR_ASSERT(context);
2412 rdpRdp* rdp = context->rdp;
2413 s = rdp_data_pdu_init(rdp);
2418 Stream_Write_UINT16(s, 0);
2419 Stream_Write_UINT16(s, led_flags);
2421 WINPR_ASSERT(rdp->mcs);
2422 return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS, rdp->mcs->userId);
2425 static BOOL update_send_set_keyboard_ime_status(rdpContext* context, UINT16 imeId, UINT32 imeState,
2430 WINPR_ASSERT(context);
2431 rdpRdp* rdp = context->rdp;
2432 s = rdp_data_pdu_init(rdp);
2438 Stream_Write_UINT16(s, imeId);
2439 Stream_Write_UINT32(s, imeState);
2440 Stream_Write_UINT32(s, imeConvMode);
2442 WINPR_ASSERT(rdp->mcs);
2443 return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS, rdp->mcs->userId);
2446 static UINT16 update_calculate_new_or_existing_window(
const WINDOW_ORDER_INFO* orderInfo,
2449 UINT16 orderSize = 11;
2451 WINPR_ASSERT(orderInfo);
2452 WINPR_ASSERT(stateOrder);
2454 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OWNER) != 0)
2457 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_STYLE) != 0)
2460 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_SHOW) != 0)
2463 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TITLE) != 0)
2464 orderSize += 2 + stateOrder->titleInfo.length;
2466 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET) != 0)
2469 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE) != 0)
2472 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RESIZE_MARGIN_X) != 0)
2475 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RESIZE_MARGIN_Y) != 0)
2478 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RP_CONTENT) != 0)
2481 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ROOT_PARENT) != 0)
2484 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) != 0)
2487 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA) != 0)
2490 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE) != 0)
2493 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS) != 0)
2494 orderSize += 2 + stateOrder->numWindowRects *
sizeof(
RECTANGLE_16);
2496 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET) != 0)
2499 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY) != 0)
2500 orderSize += 2 + stateOrder->numVisibilityRects *
sizeof(
RECTANGLE_16);
2502 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OVERLAY_DESCRIPTION) != 0)
2503 orderSize += 2 + stateOrder->OverlayDescription.length;
2505 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TASKBAR_BUTTON) != 0)
2508 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ENFORCE_SERVER_ZORDER) != 0)
2511 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_APPBAR_STATE) != 0)
2514 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_APPBAR_EDGE) != 0)
2520 static BOOL update_send_new_or_existing_window(rdpContext* context,
2524 BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
2525 UINT16 orderSize = update_calculate_new_or_existing_window(orderInfo, stateOrder);
2527 WINPR_ASSERT(context);
2528 WINPR_ASSERT(orderInfo);
2529 WINPR_ASSERT(stateOrder);
2533 if (!update_check_flush(context, orderSize))
2541 if (!Stream_EnsureRemainingCapacity(s, orderSize))
2544 Stream_Write_UINT8(s, controlFlags);
2545 Stream_Write_UINT16(s, orderSize);
2546 Stream_Write_UINT32(s, orderInfo->fieldFlags);
2547 Stream_Write_UINT32(s, orderInfo->windowId);
2549 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OWNER) != 0)
2550 Stream_Write_UINT32(s, stateOrder->ownerWindowId);
2552 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_STYLE) != 0)
2554 Stream_Write_UINT32(s, stateOrder->style);
2555 Stream_Write_UINT32(s, stateOrder->extendedStyle);
2558 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_SHOW) != 0)
2560 Stream_Write_UINT8(s, stateOrder->showState);
2563 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TITLE) != 0)
2565 Stream_Write_UINT16(s, stateOrder->titleInfo.length);
2566 Stream_Write(s, stateOrder->titleInfo.string, stateOrder->titleInfo.length);
2569 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET) != 0)
2571 Stream_Write_INT32(s, stateOrder->clientOffsetX);
2572 Stream_Write_INT32(s, stateOrder->clientOffsetY);
2575 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE) != 0)
2577 Stream_Write_UINT32(s, stateOrder->clientAreaWidth);
2578 Stream_Write_UINT32(s, stateOrder->clientAreaHeight);
2581 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RESIZE_MARGIN_X) != 0)
2583 Stream_Write_UINT32(s, stateOrder->resizeMarginLeft);
2584 Stream_Write_UINT32(s, stateOrder->resizeMarginRight);
2587 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RESIZE_MARGIN_Y) != 0)
2589 Stream_Write_UINT32(s, stateOrder->resizeMarginTop);
2590 Stream_Write_UINT32(s, stateOrder->resizeMarginBottom);
2593 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RP_CONTENT) != 0)
2595 Stream_Write_UINT8(s, stateOrder->RPContent);
2598 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ROOT_PARENT) != 0)
2600 Stream_Write_UINT32(s, stateOrder->rootParentHandle);
2603 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) != 0)
2605 Stream_Write_INT32(s, stateOrder->windowOffsetX);
2606 Stream_Write_INT32(s, stateOrder->windowOffsetY);
2609 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA) != 0)
2611 Stream_Write_INT32(s, stateOrder->windowClientDeltaX);
2612 Stream_Write_INT32(s, stateOrder->windowClientDeltaY);
2615 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE) != 0)
2617 Stream_Write_UINT32(s, stateOrder->windowWidth);
2618 Stream_Write_UINT32(s, stateOrder->windowHeight);
2621 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS) != 0)
2623 Stream_Write_UINT16(s, stateOrder->numWindowRects);
2624 Stream_Write(s, stateOrder->windowRects, stateOrder->numWindowRects *
sizeof(
RECTANGLE_16));
2627 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET) != 0)
2629 Stream_Write_INT32(s, stateOrder->visibleOffsetX);
2630 Stream_Write_INT32(s, stateOrder->visibleOffsetY);
2633 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY) != 0)
2635 Stream_Write_UINT16(s, stateOrder->numVisibilityRects);
2636 Stream_Write(s, stateOrder->visibilityRects,
2637 stateOrder->numVisibilityRects *
sizeof(
RECTANGLE_16));
2640 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OVERLAY_DESCRIPTION) != 0)
2642 Stream_Write_UINT16(s, stateOrder->OverlayDescription.length);
2643 Stream_Write(s, stateOrder->OverlayDescription.string,
2644 stateOrder->OverlayDescription.length);
2647 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TASKBAR_BUTTON) != 0)
2649 Stream_Write_UINT8(s, stateOrder->TaskbarButton);
2652 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ENFORCE_SERVER_ZORDER) != 0)
2654 Stream_Write_UINT8(s, stateOrder->EnforceServerZOrder);
2657 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_APPBAR_STATE) != 0)
2659 Stream_Write_UINT8(s, stateOrder->AppBarState);
2662 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_APPBAR_EDGE) != 0)
2664 Stream_Write_UINT8(s, stateOrder->AppBarEdge);
2667 update->numberOrders++;
2671 static BOOL update_send_window_create(rdpContext* context,
const WINDOW_ORDER_INFO* orderInfo,
2674 return update_send_new_or_existing_window(context, orderInfo, stateOrder);
2677 static BOOL update_send_window_update(rdpContext* context,
const WINDOW_ORDER_INFO* orderInfo,
2680 return update_send_new_or_existing_window(context, orderInfo, stateOrder);
2683 static UINT16 update_calculate_window_icon_order(
const WINDOW_ORDER_INFO* orderInfo,
2686 UINT16 orderSize = 23;
2688 WINPR_ASSERT(iconOrder);
2689 ICON_INFO* iconInfo = iconOrder->iconInfo;
2690 WINPR_ASSERT(iconInfo);
2692 orderSize += iconInfo->cbBitsColor + iconInfo->cbBitsMask;
2694 if (iconInfo->bpp <= 8)
2695 orderSize += 2 + iconInfo->cbColorTable;
2700 static BOOL update_send_window_icon(rdpContext* context,
const WINDOW_ORDER_INFO* orderInfo,
2703 BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
2705 WINPR_ASSERT(iconOrder);
2706 ICON_INFO* iconInfo = iconOrder->iconInfo;
2707 UINT16 orderSize = update_calculate_window_icon_order(orderInfo, iconOrder);
2709 WINPR_ASSERT(context);
2710 WINPR_ASSERT(orderInfo);
2711 WINPR_ASSERT(iconInfo);
2715 if (!update_check_flush(context, orderSize))
2720 if (!s || !iconInfo)
2723 if (!Stream_EnsureRemainingCapacity(s, orderSize))
2727 Stream_Write_UINT8(s, controlFlags);
2728 Stream_Write_UINT16(s, orderSize);
2729 Stream_Write_UINT32(s, orderInfo->fieldFlags);
2730 Stream_Write_UINT32(s, orderInfo->windowId);
2732 Stream_Write_UINT16(s, iconInfo->cacheEntry);
2733 Stream_Write_UINT8(s, iconInfo->cacheId);
2734 Stream_Write_UINT8(s, iconInfo->bpp);
2735 Stream_Write_UINT16(s, iconInfo->width);
2736 Stream_Write_UINT16(s, iconInfo->height);
2738 if (iconInfo->bpp <= 8)
2740 Stream_Write_UINT16(s, iconInfo->cbColorTable);
2743 Stream_Write_UINT16(s, iconInfo->cbBitsMask);
2744 Stream_Write_UINT16(s, iconInfo->cbBitsColor);
2745 Stream_Write(s, iconInfo->bitsMask, iconInfo->cbBitsMask);
2747 if (iconInfo->bpp <= 8)
2749 Stream_Write(s, iconInfo->colorTable, iconInfo->cbColorTable);
2752 Stream_Write(s, iconInfo->bitsColor, iconInfo->cbBitsColor);
2754 update->numberOrders++;
2758 static BOOL update_send_window_cached_icon(rdpContext* context,
const WINDOW_ORDER_INFO* orderInfo,
2761 BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
2762 UINT16 orderSize = 14;
2764 WINPR_ASSERT(cachedIconOrder);
2767 WINPR_ASSERT(context);
2768 WINPR_ASSERT(orderInfo);
2769 WINPR_ASSERT(cachedIcon);
2773 if (!update_check_flush(context, orderSize))
2780 if (!Stream_EnsureRemainingCapacity(s, orderSize))
2784 Stream_Write_UINT8(s, controlFlags);
2785 Stream_Write_UINT16(s, orderSize);
2786 Stream_Write_UINT32(s, orderInfo->fieldFlags);
2787 Stream_Write_UINT32(s, orderInfo->windowId);
2789 Stream_Write_UINT16(s, cachedIcon->cacheEntry);
2790 Stream_Write_UINT8(s, cachedIcon->cacheId);
2791 update->numberOrders++;
2795 static BOOL update_send_window_delete(rdpContext* context,
const WINDOW_ORDER_INFO* orderInfo)
2797 BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
2798 UINT16 orderSize = 11;
2800 WINPR_ASSERT(context);
2801 WINPR_ASSERT(orderInfo);
2804 if (!update_check_flush(context, orderSize))
2812 if (!Stream_EnsureRemainingCapacity(s, orderSize))
2816 Stream_Write_UINT8(s, controlFlags);
2817 Stream_Write_UINT16(s, orderSize);
2818 Stream_Write_UINT32(s, orderInfo->fieldFlags);
2819 Stream_Write_UINT32(s, orderInfo->windowId);
2820 update->numberOrders++;
2824 static UINT16 update_calculate_new_or_existing_notification_icons_order(
2827 UINT16 orderSize = 15;
2829 WINPR_ASSERT(orderInfo);
2830 WINPR_ASSERT(iconStateOrder);
2832 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_VERSION) != 0)
2835 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_TIP) != 0)
2837 orderSize += 2 + iconStateOrder->toolTip.length;
2840 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_INFO_TIP) != 0)
2843 orderSize += 12 + infoTip.text.length + infoTip.title.length;
2846 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_STATE) != 0)
2851 if ((orderInfo->fieldFlags & WINDOW_ORDER_ICON) != 0)
2853 ICON_INFO iconInfo = iconStateOrder->icon;
2856 if (iconInfo.bpp <= 8)
2857 orderSize += 2 + iconInfo.cbColorTable;
2859 orderSize += iconInfo.cbBitsMask + iconInfo.cbBitsColor;
2861 else if ((orderInfo->fieldFlags & WINDOW_ORDER_CACHED_ICON) != 0)
2870 update_send_new_or_existing_notification_icons(rdpContext* context,
2874 BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
2875 BOOL versionFieldPresent = FALSE;
2876 const UINT16 orderSize =
2877 update_calculate_new_or_existing_notification_icons_order(orderInfo, iconStateOrder);
2879 WINPR_ASSERT(context);
2880 WINPR_ASSERT(orderInfo);
2881 WINPR_ASSERT(iconStateOrder);
2884 if (!update_check_flush(context, orderSize))
2891 if (!Stream_EnsureRemainingCapacity(s, orderSize))
2895 Stream_Write_UINT8(s, controlFlags);
2896 Stream_Write_UINT16(s, orderSize);
2897 Stream_Write_UINT32(s, orderInfo->fieldFlags);
2898 Stream_Write_UINT32(s, orderInfo->windowId);
2899 Stream_Write_UINT32(s, orderInfo->notifyIconId);
2902 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_VERSION) != 0)
2904 versionFieldPresent = TRUE;
2905 Stream_Write_UINT32(s, iconStateOrder->version);
2908 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_TIP) != 0)
2910 Stream_Write_UINT16(s, iconStateOrder->toolTip.length);
2911 Stream_Write(s, iconStateOrder->toolTip.string, iconStateOrder->toolTip.length);
2914 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_INFO_TIP) != 0)
2919 if (versionFieldPresent && iconStateOrder->version == 0)
2922 Stream_Write_UINT32(s, infoTip.timeout);
2923 Stream_Write_UINT32(s, infoTip.flags);
2924 Stream_Write_UINT16(s, infoTip.text.length);
2925 Stream_Write(s, infoTip.text.string, infoTip.text.length);
2926 Stream_Write_UINT16(s, infoTip.title.length);
2927 Stream_Write(s, infoTip.title.string, infoTip.title.length);
2930 if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_STATE) != 0)
2933 if (versionFieldPresent && iconStateOrder->version == 0)
2936 Stream_Write_UINT32(s, iconStateOrder->state);
2939 if ((orderInfo->fieldFlags & WINDOW_ORDER_ICON) != 0)
2941 ICON_INFO iconInfo = iconStateOrder->icon;
2942 Stream_Write_UINT16(s, iconInfo.cacheEntry);
2943 Stream_Write_UINT8(s, iconInfo.cacheId);
2944 Stream_Write_UINT8(s, iconInfo.bpp);
2945 Stream_Write_UINT16(s, iconInfo.width);
2946 Stream_Write_UINT16(s, iconInfo.height);
2948 if (iconInfo.bpp <= 8)
2950 Stream_Write_UINT16(s, iconInfo.cbColorTable);
2953 Stream_Write_UINT16(s, iconInfo.cbBitsMask);
2954 Stream_Write_UINT16(s, iconInfo.cbBitsColor);
2955 Stream_Write(s, iconInfo.bitsMask, iconInfo.cbBitsMask);
2957 if (iconInfo.bpp <= 8)
2959 Stream_Write(s, iconInfo.colorTable, iconInfo.cbColorTable);
2962 Stream_Write(s, iconInfo.bitsColor, iconInfo.cbBitsColor);
2964 else if ((orderInfo->fieldFlags & WINDOW_ORDER_CACHED_ICON) != 0)
2967 Stream_Write_UINT16(s, cachedIcon.cacheEntry);
2968 Stream_Write_UINT8(s, cachedIcon.cacheId);
2971 update->numberOrders++;
2975 static BOOL update_send_notify_icon_create(rdpContext* context,
const WINDOW_ORDER_INFO* orderInfo,
2978 return update_send_new_or_existing_notification_icons(context, orderInfo, iconStateOrder);
2981 static BOOL update_send_notify_icon_update(rdpContext* context,
const WINDOW_ORDER_INFO* orderInfo,
2984 return update_send_new_or_existing_notification_icons(context, orderInfo, iconStateOrder);
2987 static BOOL update_send_notify_icon_delete(rdpContext* context,
const WINDOW_ORDER_INFO* orderInfo)
2989 BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
2990 UINT16 orderSize = 15;
2992 WINPR_ASSERT(context);
2993 WINPR_ASSERT(orderInfo);
2996 if (!update_check_flush(context, orderSize))
3005 Stream_Write_UINT8(s, controlFlags);
3006 Stream_Write_UINT16(s, orderSize);
3007 Stream_Write_UINT32(s, orderInfo->fieldFlags);
3008 Stream_Write_UINT32(s, orderInfo->windowId);
3009 Stream_Write_UINT32(s, orderInfo->notifyIconId);
3010 update->numberOrders++;
3014 static UINT16 update_calculate_monitored_desktop(
const WINDOW_ORDER_INFO* orderInfo,
3017 UINT16 orderSize = 7;
3019 WINPR_ASSERT(orderInfo);
3020 WINPR_ASSERT(monitoredDesktop);
3022 if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_DESKTOP_ACTIVE_WND)
3027 if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_DESKTOP_ZORDER)
3029 orderSize += 1 + (4 * monitoredDesktop->numWindowIds);
3035 static BOOL update_send_monitored_desktop(rdpContext* context,
const WINDOW_ORDER_INFO* orderInfo,
3038 BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
3039 UINT16 orderSize = update_calculate_monitored_desktop(orderInfo, monitoredDesktop);
3041 WINPR_ASSERT(context);
3042 WINPR_ASSERT(orderInfo);
3043 WINPR_ASSERT(monitoredDesktop);
3047 if (!update_check_flush(context, orderSize))
3055 Stream_Write_UINT8(s, controlFlags);
3056 Stream_Write_UINT16(s, orderSize);
3057 Stream_Write_UINT32(s, orderInfo->fieldFlags);
3059 if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_DESKTOP_ACTIVE_WND)
3061 Stream_Write_UINT32(s, monitoredDesktop->activeWindowId);
3064 if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_DESKTOP_ZORDER)
3066 Stream_Write_UINT8(s, monitoredDesktop->numWindowIds);
3069 for (UINT32 i = 0; i < monitoredDesktop->numWindowIds; i++)
3071 Stream_Write_UINT32(s, monitoredDesktop->windowIds[i]);
3075 update->numberOrders++;
3079 static BOOL update_send_non_monitored_desktop(rdpContext* context,
3082 BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
3083 UINT16 orderSize = 7;
3085 WINPR_ASSERT(context);
3086 WINPR_ASSERT(orderInfo);
3089 if (!update_check_flush(context, orderSize))
3097 Stream_Write_UINT8(s, controlFlags);
3098 Stream_Write_UINT16(s, orderSize);
3099 Stream_Write_UINT32(s, orderInfo->fieldFlags);
3100 update->numberOrders++;
3104 void update_register_server_callbacks(rdpUpdate* update)
3106 WINPR_ASSERT(update);
3108 update->BeginPaint = s_update_begin_paint;
3109 update->EndPaint = s_update_end_paint;
3110 update->SetBounds = update_set_bounds;
3111 update->Synchronize = update_send_synchronize;
3112 update->DesktopResize = update_send_desktop_resize;
3113 update->BitmapUpdate = update_send_bitmap_update;
3114 update->SurfaceBits = update_send_surface_bits;
3115 update->SurfaceFrameMarker = update_send_surface_frame_marker;
3116 update->SurfaceCommand = update_send_surface_command;
3117 update->SurfaceFrameBits = update_send_surface_frame_bits;
3118 update->PlaySound = update_send_play_sound;
3119 update->SetKeyboardIndicators = update_send_set_keyboard_indicators;
3120 update->SetKeyboardImeStatus = update_send_set_keyboard_ime_status;
3121 update->SaveSessionInfo = rdp_send_save_session_info;
3122 update->ServerStatusInfo = rdp_send_server_status_info;
3123 update->primary->DstBlt = update_send_dstblt;
3124 update->primary->PatBlt = update_send_patblt;
3125 update->primary->ScrBlt = update_send_scrblt;
3126 update->primary->OpaqueRect = update_send_opaque_rect;
3127 update->primary->LineTo = update_send_line_to;
3128 update->primary->MemBlt = update_send_memblt;
3129 update->primary->GlyphIndex = update_send_glyph_index;
3130 update->secondary->CacheBitmap = update_send_cache_bitmap;
3131 update->secondary->CacheBitmapV2 = update_send_cache_bitmap_v2;
3132 update->secondary->CacheBitmapV3 = update_send_cache_bitmap_v3;
3133 update->secondary->CacheColorTable = update_send_cache_color_table;
3134 update->secondary->CacheGlyph = update_send_cache_glyph;
3135 update->secondary->CacheGlyphV2 = update_send_cache_glyph_v2;
3136 update->secondary->CacheBrush = update_send_cache_brush;
3137 update->altsec->CreateOffscreenBitmap = update_send_create_offscreen_bitmap_order;
3138 update->altsec->SwitchSurface = update_send_switch_surface_order;
3139 update->pointer->PointerSystem = update_send_pointer_system;
3140 update->pointer->PointerPosition = update_send_pointer_position;
3141 update->pointer->PointerColor = update_send_pointer_color;
3142 update->pointer->PointerLarge = update_send_pointer_large;
3143 update->pointer->PointerNew = update_send_pointer_new;
3144 update->pointer->PointerCached = update_send_pointer_cached;
3145 update->window->WindowCreate = update_send_window_create;
3146 update->window->WindowUpdate = update_send_window_update;
3147 update->window->WindowIcon = update_send_window_icon;
3148 update->window->WindowCachedIcon = update_send_window_cached_icon;
3149 update->window->WindowDelete = update_send_window_delete;
3150 update->window->NotifyIconCreate = update_send_notify_icon_create;
3151 update->window->NotifyIconUpdate = update_send_notify_icon_update;
3152 update->window->NotifyIconDelete = update_send_notify_icon_delete;
3153 update->window->MonitoredDesktop = update_send_monitored_desktop;
3154 update->window->NonMonitoredDesktop = update_send_non_monitored_desktop;
3157 void update_register_client_callbacks(rdpUpdate* update)
3159 WINPR_ASSERT(update);
3161 update->RefreshRect = update_send_refresh_rect;
3162 update->SuppressOutput = update_send_suppress_output;
3163 update->SurfaceFrameAcknowledge = update_send_frame_acknowledge;
3166 int update_process_messages(rdpUpdate* update)
3168 return update_message_queue_process_pending_messages(update);
3171 static void update_free_queued_message(
void* obj)
3173 wMessage* msg = (wMessage*)obj;
3174 update_message_queue_free_message(msg);
3182 free(window_state->OverlayDescription.string);
3183 free(window_state->titleInfo.string);
3184 free(window_state->windowRects);
3185 free(window_state->visibilityRects);
3189 rdpUpdate* update_new(rdpRdp* rdp)
3191 const wObject cb = { NULL, NULL, NULL, update_free_queued_message, NULL };
3194 WINPR_ASSERT(rdp->context);
3201 update->common.context = rdp->context;
3202 update->log = WLog_Get(
"com.freerdp.core.update");
3203 InitializeCriticalSection(&(update->mux));
3204 update->common.pointer = (rdpPointerUpdate*)calloc(1,
sizeof(rdpPointerUpdate));
3206 if (!update->common.pointer)
3214 update->common.primary = &primary->common;
3221 update->common.secondary = &secondary->common;
3229 update->common.altsec = &altsec->common;
3230 update->common.window = (rdpWindowUpdate*)calloc(1,
sizeof(rdpWindowUpdate));
3232 if (!update->common.window)
3236 deleteList->sIndices = 64;
3237 deleteList->indices = calloc(deleteList->sIndices, 2);
3239 if (!deleteList->indices)
3242 deleteList->cIndices = 0;
3243 update->common.SuppressOutput = update_send_suppress_output;
3244 update->initialState = TRUE;
3245 update->common.autoCalculateBitmapData = TRUE;
3246 update->queue = MessageQueue_New(&cb);
3251 return &update->common;
3253 WINPR_PRAGMA_DIAG_PUSH
3254 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
3255 update_free(&update->common);
3256 WINPR_PRAGMA_DIAG_POP
3260 void update_free(rdpUpdate* update)
3269 free(deleteList->indices);
3271 free(update->pointer);
3273 if (update->primary)
3277 free(primary->polygon_cb.points);
3278 free(primary->polyline.points);
3279 free(primary->polygon_sc.points);
3280 free(primary->fast_glyph.glyphData.aj);
3284 free(update->secondary);
3288 free(update->window);
3290 MessageQueue_Free(up->queue);
3291 DeleteCriticalSection(&up->mux);
3294 Stream_Free(up->us, TRUE);
3299 void rdp_update_lock(rdpUpdate* update)
3302 EnterCriticalSection(&up->mux);
3305 void rdp_update_unlock(rdpUpdate* update)
3308 LeaveCriticalSection(&up->mux);
3311 BOOL update_begin_paint(rdpUpdate* update)
3314 WINPR_ASSERT(update);
3315 rdp_update_lock(update);
3317 up->withinBeginEndPaint = TRUE;
3319 WINPR_ASSERT(update->context);
3321 BOOL rc = IFCALLRESULT(TRUE, update->BeginPaint, update->context);
3323 WLog_WARN(TAG,
"BeginPaint call failed");
3326 rdpGdi* gdi = update->context->gdi;
3330 if (gdi->hdc && gdi->primary && gdi->primary->hdc)
3332 HGDI_WND hwnd = gdi->primary->hdc->hwnd;
3334 WINPR_ASSERT(hwnd->invalid);
3336 hwnd->invalid->null = TRUE;
3343 BOOL update_end_paint(rdpUpdate* update)
3347 WINPR_ASSERT(update);
3348 IFCALLRET(update->EndPaint, rc, update->context);
3350 WLog_WARN(TAG,
"EndPaint call failed");
3354 if (!up->withinBeginEndPaint)
3356 up->withinBeginEndPaint = FALSE;
3358 rdp_update_unlock(update);
This struct contains function pointer to initialize/free objects.