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.

190 lines
8.1 KiB

  1. /****************************************************************************/
  2. /* apmapi.cpp */
  3. /* */
  4. /* Palette Manager API Functions. */
  5. /* */
  6. /* Copyright(c) Microsoft, PictureTel 1992-1997 */
  7. /* Copyright (c) Microsoft 1997 - 2000 */
  8. /****************************************************************************/
  9. #include <precomp.h>
  10. #pragma hdrstop
  11. #define TRC_FILE "apmapi"
  12. #include <as_conf.hpp>
  13. /****************************************************************************/
  14. /* PM_Init() */
  15. /* */
  16. /* Initializes the Palette Manager. */
  17. /****************************************************************************/
  18. void RDPCALL SHCLASS PM_Init(void)
  19. {
  20. TS_COLORTABLECACHE_CAPABILITYSET ColorTableCaps;
  21. DC_BEGIN_FN("PM_Init");
  22. #define DC_INIT_DATA
  23. #include <apmdata.c>
  24. #undef DC_INIT_DATA
  25. // Set up the PM capabilities.
  26. ColorTableCaps.capabilitySetType = TS_CAPSETTYPE_COLORCACHE;
  27. ColorTableCaps.colorTableCacheSize = SBC_NUM_COLOR_TABLE_CACHE_ENTRIES;
  28. ColorTableCaps.pad2octets = 0;
  29. CPC_RegisterCapabilities((PTS_CAPABILITYHEADER)&ColorTableCaps,
  30. sizeof(TS_COLORTABLECACHE_CAPABILITYSET));
  31. DC_END_FN();
  32. }
  33. /****************************************************************************/
  34. /* PM_MaybeSendPalettePacket() */
  35. /* */
  36. /* Tries to broadcast a palette packet to all remote people in a share if */
  37. /* necessary. */
  38. /* */
  39. /* PM_MaybeSendPalettePacket returns a boolean indicating whether it has */
  40. /* successfully sent a palette packet. We only send further updates if */
  41. /* the palette packet is successfully sent. */
  42. /* */
  43. /* RETURNS: TRUE if palette packet was successfully sent, or if no packet */
  44. /* needs to be sent. FALSE if a packet needs to be sent but could not be. */
  45. /****************************************************************************/
  46. BOOL RDPCALL SHCLASS PM_MaybeSendPalettePacket(PPDU_PACKAGE_INFO pPkgInfo)
  47. {
  48. BOOL rc = TRUE;
  49. unsigned i;
  50. unsigned cbPalettePacketSize;
  51. BYTE *pPackageSpace;
  52. DC_BEGIN_FN("PM_MaybeSendPalettePacket");
  53. if (m_pShm->pm.paletteChanged || pmMustSendPalette) {
  54. TRC_NRM((TB, "Send palette packet"));
  55. // Set up a palette packet. First calculate the packet size.
  56. cbPalettePacketSize = scUpdatePDUHeaderSpace +
  57. sizeof(TS_UPDATE_PALETTE_PDU_DATA) +
  58. ((PM_NUM_8BPP_PAL_ENTRIES - 1) * sizeof(TS_COLOR));
  59. // Get space in the PDU package.
  60. pPackageSpace = SC_GetSpaceInPackage(pPkgInfo, cbPalettePacketSize);
  61. if (pPackageSpace != NULL) {
  62. TS_UPDATE_PALETTE_PDU_DATA UNALIGNED *pData;
  63. BYTE *pEncode;
  64. // Fill in the packet header.
  65. if (scUseFastPathOutput) {
  66. pPackageSpace[0] = scCompressionUsedValue |
  67. TS_UPDATETYPE_PALETTE;
  68. pData = (TS_UPDATE_PALETTE_PDU_DATA UNALIGNED *)
  69. (pPackageSpace + scUpdatePDUHeaderSpace);
  70. }
  71. else {
  72. TS_UPDATE_PALETTE_PDU UNALIGNED *pPalettePDU;
  73. pPalettePDU = (PTS_UPDATE_PALETTE_PDU)pPackageSpace;
  74. pPalettePDU->shareDataHeader.pduType2 = TS_PDUTYPE2_UPDATE;
  75. pData = &pPalettePDU->data;
  76. }
  77. pData->updateType = TS_UPDATETYPE_PALETTE;
  78. pData->numberColors = PM_NUM_8BPP_PAL_ENTRIES;
  79. // Convert the DCRGBQUADs in the color table to DCCOLORs as we copy
  80. // them into the packet.
  81. for (i = 0; i < PM_NUM_8BPP_PAL_ENTRIES; i++) {
  82. // Convert each RGBQUAD entry in the palette to a DCCOLOR entry
  83. // in the palette PDU. We swap the elements because the client
  84. // wants to treat the palette entries as DWORDs and lift them
  85. // straight out of the packet.
  86. pData->palette[i].red = m_pShm->pm.palette[i].rgbBlue;
  87. pData->palette[i].green = m_pShm->pm.palette[i].rgbGreen;
  88. pData->palette[i].blue = m_pShm->pm.palette[i].rgbRed;
  89. }
  90. // Now send the packet to the remote application.
  91. SC_AddToPackage(pPkgInfo, cbPalettePacketSize, TRUE);
  92. // We no longer need to send a palette packet.
  93. m_pShm->pm.paletteChanged = FALSE;
  94. pmMustSendPalette = FALSE;
  95. }
  96. else {
  97. TRC_ALT((TB, "Failed to allocate packet"));
  98. rc = FALSE;
  99. }
  100. }
  101. DC_END_FN();
  102. return rc;
  103. }
  104. /****************************************************************************/
  105. /* API FUNCTION: PM_SyncNow */
  106. /* */
  107. /* Resyncs to the remote PM by ensuring that the datastream does not refer */
  108. /* to any previously sent data. */
  109. /****************************************************************************/
  110. void RDPCALL SHCLASS PM_SyncNow(void)
  111. {
  112. DC_BEGIN_FN("PM_SyncNow");
  113. // Ensure we send a palette to the remote PM next time we are called.
  114. TRC_NRM((TB, "Palette sync"));
  115. pmMustSendPalette = TRUE;
  116. DC_END_FN();
  117. }
  118. #ifdef NotUsed
  119. /****************************************************************************/
  120. /* FUNCTION: PMEnumPMCaps */
  121. /* */
  122. /* PM callback function for CPC capabilities enumeration. */
  123. /* */
  124. /* PARAMETERS: */
  125. /* personID - ID of this person */
  126. /* pCapabilities - pointer to this person's cursor capabilites */
  127. /****************************************************************************/
  128. void CALLBACK SHCLASS PMEnumPMCaps(
  129. LOCALPERSONID locPersonID,
  130. UINT_PTR UserData,
  131. PTS_CAPABILITYHEADER pCapabilities)
  132. {
  133. PTS_COLORTABLECACHE_CAPABILITYSET pColorCacheCaps;
  134. unsigned cTxCacheSize;
  135. DC_BEGIN_FN("PMEnumPMCaps");
  136. DC_IGNORE_PARAMETER(UserData);
  137. pColorCacheCaps = (PTS_COLORTABLECACHE_CAPABILITYSET)pCapabilities;
  138. // If the person does not have any color table caching capabilites we
  139. // still get called, but the sizeOfCapabilities field is zero.
  140. if (pColorCacheCaps->lengthCapability <
  141. sizeof(PTS_COLORTABLECACHE_CAPABILITYSET)) {
  142. TRC_NRM((TB, "[%u] No color cache caps", (unsigned)locPersonID));
  143. cTxCacheSize = 1;
  144. }
  145. else {
  146. TRC_NRM((TB, "[%u] capsID(%u) size(%u) CacheSize(%u)",
  147. (unsigned)locPersonID,
  148. pColorCacheCaps->capabilitySetType,
  149. pColorCacheCaps->lengthCapability,
  150. pColorCacheCaps->colorTableCacheSize));
  151. cTxCacheSize = pColorCacheCaps->colorTableCacheSize;
  152. }
  153. pmNewTxCacheSize = min(pmNewTxCacheSize, cTxCacheSize);
  154. DC_END_FN();
  155. }
  156. #endif // NotUsed