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.

202 lines
6.8 KiB

  1. /****************************************************************************/
  2. // npmdisp.c
  3. //
  4. // RDP Palette Manager display driver code.
  5. //
  6. // Copyright (C) 1997-2000 Microsoft Corporation
  7. /****************************************************************************/
  8. #include <precmpdd.h>
  9. #define hdrstop
  10. #define TRC_FILE "npmdisp"
  11. #include <adcg.h>
  12. #include <atrcapi.h>
  13. #include <apmapi.h>
  14. #include <nddapi.h>
  15. #include <npmdisp.h>
  16. #include <nsbcdisp.h>
  17. #define DC_INCLUDE_DATA
  18. #include <ndddata.c>
  19. #undef DC_INCLUDE_DATA
  20. #include <nsbcinl.h>
  21. /****************************************************************************/
  22. // PM_InitShm
  23. //
  24. // Alloc-time SHM init.
  25. /****************************************************************************/
  26. void RDPCALL PM_InitShm(PDD_PDEV pPDev)
  27. {
  28. int i;
  29. DC_BEGIN_FN("PM_InitShm");
  30. DC_IGNORE_PARAMETER(pPDev);
  31. // There are several options here:
  32. // - Connecting or reconnecting to a 4bpp client: we need to create a
  33. // default VGA palette.
  34. // - Connecting or reconnecting to an 8bpp client: it doesn't really
  35. // matter what we do here as the first call to DrvSetPalette() will
  36. // overwrite anything we set up.
  37. // - Shadowing a console session: if the console's primary monitor is
  38. // >8bpp, DrvSetPalette will never get called. Our chained console DD
  39. // always runs at 8bpp so we set up an 8bpp rainbow palette which also
  40. // contains the standard windows colors.
  41. if (!ddConsole) {
  42. // This is a connect or reconnect to a non-console session.
  43. TRC_NRM((TB, "Create default 4BPP palette"));
  44. for (i = 16; i < 248; i++) {
  45. // Fill unused slots with some shade of pink.
  46. pddShm->pm.palette[i].rgbBlue = 255;
  47. pddShm->pm.palette[i].rgbGreen = 128;
  48. pddShm->pm.palette[i].rgbRed = 128;
  49. }
  50. // Copy real VGA colors
  51. // - copy entire 16-color palette into slots 0-15
  52. // - copy high colors (8-15) into high end of palette (240-255)
  53. memcpy(&(pddShm->pm.palette[0]),
  54. ddDefaultVgaPalette,
  55. sizeof(ddDefaultVgaPalette));
  56. memcpy(&(pddShm->pm.palette[248]),
  57. &(ddDefaultVgaPalette[8]),
  58. sizeof(* ddDefaultVgaPalette) * 8);
  59. }
  60. else {
  61. // This is a chained console DD -- this always runs at 8bpp and we
  62. // must create a default rainbow palette.
  63. PALETTEENTRY *ppalTmp;
  64. ULONG ulLoop;
  65. BYTE jRed;
  66. BYTE jGre;
  67. BYTE jBlu;
  68. TRC_NRM((TB, "Create default 8BPP rainbow palette"));
  69. // cColors == 256
  70. // Generate 256 (8*8*4) RGB combinations to fill the palette
  71. jRed = 0;
  72. jGre = 0;
  73. jBlu = 0;
  74. ppalTmp = (PALETTEENTRY *)(pddShm->pm.palette);
  75. for (ulLoop = 256; ulLoop != 0; ulLoop--) {
  76. // JPB: The values used in the default rainbow set of colors do
  77. // not particularly matter. However, we do not want any of the
  78. // entries to match entries in the default VGA colors.
  79. // Therefore we tweak the color values slightly to ensure that
  80. // there are no matches.
  81. ppalTmp->peRed = ((jRed == 0) ? (jRed+1) : (jRed-1));
  82. ppalTmp->peGreen = ((jGre == 0) ? (jGre+1) : (jGre-1));
  83. ppalTmp->peBlue = ((jBlu == 0) ? (jBlu+1) : (jBlu-1));
  84. ppalTmp->peFlags = 0;
  85. ppalTmp++;
  86. if (!(jRed += 32))
  87. if (!(jGre += 32))
  88. jBlu += 64;
  89. }
  90. // Now copy in the system colors.
  91. memcpy(&(pddShm->pm.palette[0]),
  92. ddDefaultPalette,
  93. sizeof(* ddDefaultPalette) * 10);
  94. memcpy(&(pddShm->pm.palette[246]),
  95. &(ddDefaultPalette[10]),
  96. sizeof(* ddDefaultPalette) * 10);
  97. }
  98. pddShm->pm.paletteChanged = TRUE;
  99. DC_END_FN();
  100. }
  101. /****************************************************************************/
  102. // DrvSetPalette - see NT DDK documentation.
  103. /****************************************************************************/
  104. BOOL DrvSetPalette(
  105. DHPDEV dhpdev,
  106. PALOBJ *ppalo,
  107. FLONG fl,
  108. ULONG iStart,
  109. ULONG cColors)
  110. {
  111. BOOL rc = FALSE;
  112. PDD_PDEV ppdev = (PDD_PDEV)dhpdev;
  113. unsigned numColorsReturned;
  114. UINT32 length;
  115. DC_BEGIN_FN("DrvSetPalette");
  116. #ifdef DC_DEBUG
  117. if (ppdev->cClientBitsPerPel > 8) {
  118. TRC_ERR((TB, "Unexpected palette operation when in high color mode"));
  119. }
  120. #endif
  121. if (ddConnected && pddShm != NULL) {
  122. // Check that the parameters are within range.
  123. if ((iStart + cColors) <= PM_NUM_8BPP_PAL_ENTRIES) {
  124. // Get the palette colors into PDEV.
  125. numColorsReturned = PALOBJ_cGetColors(ppalo, iStart, cColors,
  126. (ULONG*)&(ppdev->Palette[iStart]));
  127. if (numColorsReturned == cColors) {
  128. // See if these new entries are actually different to the old
  129. // ones by comparing the colors we've just put in the PDEV with
  130. // the ones that we're about to update in the shared memory.
  131. length = cColors * sizeof(PALETTEENTRY);
  132. if (memcmp(&(pddShm->pm.palette[iStart]),
  133. &(ppdev->Palette[iStart]), length)) {
  134. // The colors have changed - copy them into the shared
  135. // memory.
  136. memcpy(&(pddShm->pm.palette[iStart]),
  137. &(ppdev->Palette[iStart]), length);
  138. // Set flags to indicate that the palette has changed.
  139. pddShm->pm.paletteChanged = TRUE;
  140. // Inform the SBC.
  141. SBC_PaletteChanged();
  142. TRC_ALT((TB, "Palette changed"));
  143. }
  144. else {
  145. // The palette hasn't actually changed at all. This is
  146. // slightly unusual, but not an error condition, so we
  147. // return TRUE.
  148. TRC_ALT((TB, "%lu new colors at index %lu haven't changed "
  149. "palette - not sending.", cColors, iStart));
  150. }
  151. rc = TRUE;
  152. }
  153. else {
  154. TRC_ERR((TB, "numColorsReturned(%u) cColors(%u)",
  155. numColorsReturned, cColors));
  156. }
  157. }
  158. else {
  159. TRC_ERR((TB, "Invalid params: iStart(%u) cColors(%u)",
  160. iStart, cColors));
  161. }
  162. }
  163. else {
  164. TRC_ERR((TB, "Called when disconnected"));
  165. }
  166. DC_END_FN();
  167. return rc;
  168. }