Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
9.4 KiB

  1. /****************************************************************************/
  2. // oe2.h
  3. //
  4. // Header for RDP field compression.
  5. //
  6. // Copyright (C) 1997-2000 Microsoft Corporation
  7. /****************************************************************************/
  8. #ifndef __OE2_H
  9. #define __OE2_H
  10. /****************************************************************************/
  11. // Field compression (OE2) overview
  12. //
  13. // OE2 compression maintains a copy of each field value of the last order
  14. // sent, plus other state information like the last bounding rectangle used
  15. // and the last order type. OE2 encoding involves comparing a new display
  16. // order to the last copy, and sending only the fields which have changed.
  17. // Other specialized encoding occurs for certain fields declared to be of
  18. // "coord" type, meaning that a one-byte delta can be sent instead of a
  19. // 2-byte value, if the delta will fit into 8 bits.
  20. //
  21. // The wire format for OE2 encoded orders consists of the following fields:
  22. //
  23. // +------------+------+-------------+--------+----------------+
  24. // | Ctrl flags | Type | Field flags | Bounds | Encoded Fields |
  25. // +------------+------+-------------+--------+----------------+
  26. //
  27. // Control flags: Required byte, corresponding to a TS_ORDER_HEADER and
  28. // available flags. Always contains at least TS_STANDARD flag. These
  29. // flags describe the following encoding; flag meanings are discussed
  30. // below.
  31. //
  32. // Type: If TS_TYPE_CHANGE is present in the control flags, this is a one-
  33. // byte order type value. The initial value agreed-on by both server
  34. // and client is TS_ENC_PATBLT_ORDER.
  35. //
  36. // Field flags: One or more bytes, where the number of bytes is ceil(((number
  37. // of order fields) + 1) / 8). The "+ 1" in that equation is historical
  38. // and means that the first byte of field flags can only encompass 7
  39. // flag bits. The presence of these flags is also governed by the control
  40. // flags TS_ZERO_FIELD_BYTE_BIT0 and TS_ZERO_FIELD_BYTE_BIT1
  41. // (see at128.h description). The ordering of the bytes is as a DWORD
  42. // -- the low order byte is first. The field flags indicate the presence
  43. // of an order field in the encoded fields portion of the packet.
  44. // The ordering of the flags proceeds from 0x01 corresponding to the
  45. // first order field, 0x02 the second, 0x04 the third, etc.
  46. //
  47. // Bounds: The presence of this field is governed by the TS_BOUNDS control
  48. // flag, which indicates the order must have a bounding region applied.
  49. // If control flag TS_ZERO_BOUNDS_DELTAS is set, the bound rect to be
  50. // used is the same as the last bound rect used. Otherwise, the
  51. // bounds are encoded as an encoding description byte followed by one
  52. // or more encoded bounds. The description byte contains two flags
  53. // for each of the left, top, right, and bottom rect components.
  54. // One flag (TS_BOUND_XXX) indicates that the component is present
  55. // and encoded as a 2-byte Intel-ordering value. The other flag
  56. // (TS_BOUND_DELTA_XXX) indicates the component is present and encoded
  57. // as a one-byte value used as an offset (-128 to 127) from the previous
  58. // value of the component. If neither flag is present the component
  59. // value is the same as used last. The initial value for the bounds
  60. // agreed-on by both server and client is the zero rect (0, 0, 0, 0).
  61. //
  62. // Encoded fields: These are the encoded order field values whose presence
  63. // is governed by the field flags. The fields are encoded in order if
  64. // present. The control flag TS_DELTA_COORDINATES is set if all COORD
  65. // type fields in the order can be specified as a one-byte delta from
  66. // their last values. If a field is not present its value is the same
  67. // as the last value sent. The initial values the client and server
  68. // use for all fields is zero. See the order field description tables in
  69. // noe2disp.c for specific order information.
  70. /****************************************************************************/
  71. /****************************************************************************/
  72. // Defines
  73. /****************************************************************************/
  74. #define MAX_BOUNDS_ENCODE_SIZE 9
  75. #define MAX_REPLAY_CLIPPED_ORDER_SIZE (1 + MAX_BOUNDS_ENCODE_SIZE)
  76. #define OE2_CONTROL_FLAGS_FIELD_SIZE 1
  77. #define OE2_TYPE_FIELD_SIZE 1
  78. #define OE2_MAX_FIELD_FLAG_BYTES 3
  79. #define MAX_ENCODED_ORDER_PREFIX_BYTES (OE2_CONTROL_FLAGS_FIELD_SIZE + \
  80. OE2_TYPE_FIELD_SIZE + OE2_MAX_FIELD_FLAG_BYTES + \
  81. MAX_BOUNDS_ENCODE_SIZE)
  82. // Max size: 1 control flag + 1 type change byte + num field flag bytes +
  83. // 9 bounds bytes + fields.
  84. #define MAX_ORDER_SIZE(_NumRects, _NumFieldFlagBytes, _MaxFieldSize) \
  85. (2 + (_NumFieldFlagBytes) + ((_NumRects == 0) ? 0 : 9) + \
  86. (_MaxFieldSize))
  87. /****************************************************************************/
  88. // Types
  89. /****************************************************************************/
  90. // INT_FMT_FIELD: Const data definitions for table-based OE2 order translation.
  91. // Describes the source intermediate and destination wire data formats.
  92. //
  93. // FieldPos: Byte offset into the source intermediate format for the field.
  94. // FieldUnencodedLen: Length of the source field.
  95. // FieldEncodedLen: Length of the destination field (wore format).
  96. // FieldSigned: Flag for signed field value.
  97. // FieldType: Descriptor that specifies how to translate the field.
  98. typedef struct
  99. {
  100. unsigned FieldPos;
  101. unsigned FieldUnencodedLen;
  102. unsigned FieldEncodedLen;
  103. BOOL FieldSigned;
  104. unsigned FieldType;
  105. } INT_FMT_FIELD;
  106. typedef INT_FMT_FIELD const *PINT_FMT_FIELD;
  107. /****************************************************************************/
  108. // Prototypes and inlines
  109. /****************************************************************************/
  110. void OE2_Reset(void);
  111. void OE2_EncodeBounds(BYTE *, BYTE **, RECTL *);
  112. unsigned OE2_CheckZeroFlagBytes(BYTE *, BYTE *, unsigned, unsigned);
  113. void OE2_TableEncodeOrderFields(BYTE *, PUINT32_UA, BYTE **, PINT_FMT_FIELD,
  114. unsigned, BYTE *, BYTE *);
  115. unsigned OE2_EncodeOrder(BYTE *, unsigned, unsigned, BYTE *, BYTE *,
  116. PINT_FMT_FIELD, RECTL *);
  117. /****************************************************************************/
  118. // OE2_EncodeOrderType
  119. //
  120. // Used by order encoding paths to encode the order type byte if different
  121. // from the last order.
  122. //
  123. // void OE2_EncodeOrderType(
  124. // BYTE *pControlFlags,
  125. // BYTE **ppBuffer,
  126. // unsigned OrderType);
  127. /****************************************************************************/
  128. #define OE2_EncodeOrderType(_pControlFlags, _ppBuffer, _OrderType) \
  129. { \
  130. if (oe2LastOrderType != (_OrderType)) { \
  131. *(_pControlFlags) |= TS_TYPE_CHANGE; \
  132. **(_ppBuffer) = (BYTE)(_OrderType); \
  133. (*(_ppBuffer))++; \
  134. oe2LastOrderType = (_OrderType); \
  135. } \
  136. }
  137. /****************************************************************************/
  138. // OE2_CheckOneZeroFlagByte
  139. //
  140. // 1-field-flag-byte version of OE2_CheckZeroFlagBytes(), optimizes out the
  141. // generalized loop.
  142. /****************************************************************************/
  143. __inline unsigned OE2_CheckOneZeroFlagByte(
  144. BYTE *pControlFlags,
  145. BYTE *pFieldFlag,
  146. unsigned PostFlagsDataLength)
  147. {
  148. if (*pFieldFlag != 0) {
  149. return 0;
  150. }
  151. else {
  152. *pControlFlags |= (1 << TS_ZERO_FIELD_COUNT_SHIFT);
  153. memmove(pFieldFlag, pFieldFlag + 1, PostFlagsDataLength);
  154. return 1;
  155. }
  156. }
  157. /****************************************************************************/
  158. // OE2_CheckTwoZeroFlagBytes
  159. //
  160. // 2-field-flag-byte version of OE2_CheckZeroFlagBytes(), optimizes out the
  161. // generalized loop.
  162. /****************************************************************************/
  163. __inline unsigned OE2_CheckTwoZeroFlagBytes(
  164. BYTE *pControlFlags,
  165. BYTE *pFieldFlags,
  166. unsigned PostFlagsDataLength)
  167. {
  168. if (pFieldFlags[1] != 0) {
  169. return 0;
  170. }
  171. else if (pFieldFlags[0] != 0) {
  172. *pControlFlags |= (1 << TS_ZERO_FIELD_COUNT_SHIFT);
  173. memmove(pFieldFlags + 1, pFieldFlags + 2, PostFlagsDataLength);
  174. return 1;
  175. }
  176. else {
  177. *pControlFlags |= (2 << TS_ZERO_FIELD_COUNT_SHIFT);
  178. memmove(pFieldFlags, pFieldFlags + 2, PostFlagsDataLength);
  179. return 2;
  180. }
  181. }
  182. /****************************************************************************/
  183. // OE2_EmitClippedReplayOrder
  184. //
  185. // Creates a "play-it-again" order -- same order type and all fields
  186. // the same as previous, except with a different bound rect.
  187. //
  188. // void OE2_EmitClippedReplayOrder(
  189. // BYTE **ppBuffer,
  190. // unsigned NumFieldFlagBytes,
  191. // RECTL *pClipRect)
  192. /****************************************************************************/
  193. #define OE2_EmitClippedReplayOrder(_ppBuffer, _NumFieldFlagBytes, _pClipRect) \
  194. { \
  195. BYTE *pBuffer = *(_ppBuffer); \
  196. \
  197. /* Control flags are primary order plus all field flags bytes zero. */ \
  198. *pBuffer++ = TS_STANDARD | TS_BOUNDS | \
  199. ((_NumFieldFlagBytes) << TS_ZERO_FIELD_COUNT_SHIFT); \
  200. \
  201. /* Construct the new bounds rect just after this. */ \
  202. OE2_EncodeBounds(pBuffer - 1, &pBuffer, (_pClipRect)); \
  203. \
  204. *(_ppBuffer) = pBuffer; \
  205. }
  206. #endif // __OE2_H