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.

164 lines
4.7 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: palddi.cxx
  3. *
  4. * provides driver callbacks for palette management.
  5. *
  6. * Created: 06-Dec-1990 11:16:58
  7. * Author: Patrick Haluptzok patrickh
  8. *
  9. * Copyright (c) 1990-1999 Microsoft Corporation
  10. \**************************************************************************/
  11. #include "precomp.hxx"
  12. /******************************Public*Routine******************************\
  13. * EngCreatePalette
  14. *
  15. * This is the engine entry point for device drivers to create palettes.
  16. *
  17. * History:
  18. * 05-Feb-1991 -by- Patrick Haluptzok patrickh
  19. * Wrote it.
  20. \**************************************************************************/
  21. HPALETTE EngCreatePalette(
  22. ULONG iMode,
  23. ULONG cColors,
  24. PULONG pulColors,
  25. FLONG flRed,
  26. FLONG flGre,
  27. FLONG flBlu)
  28. {
  29. HPALETTE hpal = (HPALETTE) 0;
  30. BOOL bUMPD = iMode & UMPD_FLAG;
  31. PALMEMOBJ pal;
  32. iMode = iMode & ~UMPD_FLAG;
  33. // If PAL_BITFIELDS, check to see if we can substitute one of the
  34. // special cases PAL_RGB or PAL_BGR.
  35. if ( (iMode == PAL_BITFIELDS) && (flGre == 0x0000ff00) &&
  36. ( ((flRed == 0x000000ff) && (flBlu == 0x00ff0000)) ||
  37. ((flRed == 0x00ff0000) && (flBlu == 0x000000ff)) ) )
  38. {
  39. iMode = (flRed == 0x000000ff) ? PAL_RGB : PAL_BGR;
  40. }
  41. // We default to assuming it's fixed palette and then at EngAssociate
  42. // time we look at his pdev and decide if this guy is more capable
  43. // than that and set the palette up accordingly.
  44. if (pal.bCreatePalette(iMode, cColors, pulColors,
  45. flRed, flGre, flBlu, PAL_FIXED))
  46. {
  47. pal.vKeepIt();
  48. hpal = (HPALETTE)pal.hpal();
  49. pal.ppalSet(NULL); // Leave a reference count of 1 so that we
  50. // can do vUnrefPalette() in EngDeletePalette
  51. if (bUMPD)
  52. {
  53. GreSetPaletteOwner(hpal, OBJECT_OWNER_CURRENT);
  54. }
  55. }
  56. return(hpal);
  57. }
  58. /******************************Public*Routine******************************\
  59. * EngQueryPalette
  60. *
  61. * This is the engine entry point for device drivers to query palettes.
  62. * This is intended mostly for remote-control drivers such as NetMeeting
  63. * to determine the palette type of the primary display.
  64. *
  65. * Note that the driver has to look at GCAPS_PALMANAGED to determine
  66. * whether it's a fixed palette or not.
  67. *
  68. * History:
  69. * 04-Jan-1997 -by- J. Andrew Goossen andrewgo
  70. * Wrote it.
  71. \**************************************************************************/
  72. ULONG EngQueryPalette(
  73. HPALETTE hpal,
  74. ULONG *piMode,
  75. ULONG cColors,
  76. ULONG *pulColors)
  77. {
  78. ULONG ulRet = 0;
  79. EPALOBJ pal(hpal);
  80. if (pal.bValid())
  81. {
  82. *piMode
  83. = pal.flPal() & (PAL_INDEXED | PAL_BITFIELDS | PAL_RGB | PAL_BGR);
  84. if (pal.cEntries() != 0)
  85. {
  86. // It's palettized:
  87. ulRet = pal.ulGetEntries(0, cColors, (PALETTEENTRY*) pulColors, TRUE);
  88. }
  89. else
  90. {
  91. // It's bitfields:
  92. ulRet = 3;
  93. if ((cColors >= 3) && (pulColors != NULL))
  94. {
  95. *(pulColors) = pal.flRed();
  96. *(pulColors + 1) = pal.flGre();
  97. *(pulColors + 2) = pal.flBlu();
  98. }
  99. }
  100. }
  101. else
  102. {
  103. WARNING("EngQueryPalette -- Invalid palette");
  104. }
  105. return(ulRet);
  106. }
  107. /******************************Public*Routine******************************\
  108. * EngDeletePalette
  109. *
  110. * Driver entry point for deleting palettes it has created
  111. *
  112. * History:
  113. * 05-Feb-1991 -by- Patrick Haluptzok patrickh
  114. * Wrote it.
  115. \**************************************************************************/
  116. BOOL EngDeletePalette(HPALETTE hpal)
  117. {
  118. BOOL b = FALSE;
  119. EPALOBJ palobj(hpal);
  120. if (palobj.bValid() && !palobj.bIsPalDC())
  121. {
  122. // First, undo the alt-lock we just did by invoking EPALOBJ:
  123. DEC_SHARE_REF_CNT(palobj.ppalGet());
  124. // Device dependent bitmaps for RGB colour depths have their palettes
  125. // pointing to the surface's primary palette. With dynamic colour
  126. // depth changing, we want to keep those palette references around
  127. // even after the primary surface is deleted.
  128. //
  129. // This means that during the dynamic mode change, the palette should
  130. // not be deleted when the old instance of the driver asks it to be
  131. // deleted, but instead when the last bitmap referencing the palette
  132. // is deleted. Having everyone use 'vUnrefPalette' makes this Just
  133. // Work.
  134. palobj.vUnrefPalette();
  135. b = TRUE;
  136. }
  137. return(b);
  138. }
  139.