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.

260 lines
6.6 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * DpBitmap
  8. *
  9. * Notes:
  10. *
  11. * Abstract:
  12. *
  13. * This is a DDI-level surface. Its name should really be 'surface'.
  14. * Unlike many other DDI objects, there isn't a one-to-one mapping between
  15. * a DpBitmap and a GpBitmap. Rather, this is like a GDI surface - it
  16. * represents any rectangular area to which one can draw.
  17. *
  18. * Created:
  19. *
  20. * 12/01/1998 andrewgo
  21. * Created it.
  22. * 03/24/1999 agodfrey
  23. * Moved into separate file.
  24. *
  25. \**************************************************************************/
  26. #ifndef _DPBITMAP_HPP
  27. #define _DPBITMAP_HPP
  28. // DpTransparency:
  29. // Characterizes the alpha values in a surface. Perf optimizations can
  30. // take advantage of this knowledge.
  31. enum DpTransparency
  32. {
  33. TransparencyUnknown, // We know nothing about the alpha values
  34. TransparencyComplex, // We have alpha values between 0 and 1
  35. TransparencySimple, // All alpha values are either 0 or 1
  36. TransparencyOpaque, // All alpha values are 1
  37. TransparencyNearConstant, // we have near constant alpha
  38. TransparencyNoAlpha // All pixels are opaque because the surface doesn't
  39. // support alpha.
  40. };
  41. // Define PixelFormatID in terms of the PixelFormat enum
  42. typedef PixelFormat PixelFormatID;
  43. // Passthrough compressed bitmaps to driver
  44. class DpCompressedData
  45. {
  46. public:
  47. DpCompressedData()
  48. {
  49. format = 0;
  50. bufferSize = 0;
  51. buffer = NULL;
  52. }
  53. ~DpCompressedData()
  54. {
  55. ASSERT(buffer == NULL);
  56. }
  57. public:
  58. INT format;
  59. UINT bufferSize;
  60. VOID* buffer;
  61. };
  62. //--------------------------------------------------------------------------
  63. // Represent surface information
  64. //--------------------------------------------------------------------------
  65. class EpScanBitmap;
  66. struct ImageInfo;
  67. class DpBitmap
  68. {
  69. private:
  70. // We now use an ObjectTag to determine if the object is valid
  71. // instead of using a BOOL. This is much more robust and helps
  72. // with debugging. It also enables us to version our objects
  73. // more easily with a version number in the ObjectTag.
  74. ObjectTag Tag; // Keep this as the 1st value in the object!
  75. protected:
  76. VOID SetValid(BOOL valid)
  77. {
  78. Tag = valid ? ObjectTagDpBitmap : ObjectTagInvalid;
  79. }
  80. public:
  81. enum CreationType
  82. {
  83. GDI,
  84. GDIDIBSECTION,
  85. GPBITMAP,
  86. D3D
  87. };
  88. INT Width;
  89. INT Height;
  90. PixelFormatID PixelFormat; // bits per pixel, pre/post multiplied alpha, etc.
  91. INT NumBytes; // Number of bytes
  92. REAL DpiX; // actual horizontal resolution in dots per inch
  93. REAL DpiY; // actual vertical resolution in dots per inch
  94. UINT Uniqueness; // Incremented every time it's drawn on
  95. DpTransparency SurfaceTransparency;
  96. BYTE MinAlpha;
  97. BYTE MaxAlpha;
  98. // The following is true only for RGB format bitmaps:
  99. ColorPalette* PaletteTable;
  100. // These masks are no longer used for determining the pixel format
  101. // Use the PixelFormat member above instead.
  102. // In fact, there's never been any garantee that these fields were
  103. // set up correctly anyway. They should be removed soon.
  104. INT RedMask;
  105. INT GreenMask;
  106. INT BlueMask;
  107. INT AlphaMask;
  108. LPDIRECTDRAWSURFACE DdrawSurface;
  109. IDirectDrawSurface7 * DdrawSurface7;
  110. BOOL IsDisplay; // Is this bitmap associated with a display?
  111. CreationType Type;
  112. // short lived, so don't include statically
  113. DpCompressedData *CompressedData;
  114. public:
  115. BOOL IsDesktopSurface() const
  116. {
  117. return (this == Globals::DesktopSurface);
  118. }
  119. BOOL IsValid() const
  120. {
  121. ASSERT((Tag == ObjectTagDpBitmap) || (Tag == ObjectTagInvalid));
  122. #if DBG
  123. if (Tag == ObjectTagInvalid)
  124. {
  125. WARNING1("Invalid DpBitmap");
  126. }
  127. #endif
  128. return (Tag == ObjectTagDpBitmap);
  129. }
  130. public: // GDI+ INTERNAL
  131. VOID *Bits; // Points to surface bits
  132. VOID *CompBits;
  133. INT Delta; // Stride in bytes
  134. // Private data for the software rasterizer.
  135. EpScan *Scan;
  136. public: // GDI+ INTERNAL
  137. DpBitmap(HDC hdc = NULL)
  138. {
  139. SetValid(TRUE); // set to valid state
  140. if ((hdc == NULL) ||
  141. ((DpiX = (REAL)GetDeviceCaps(hdc, LOGPIXELSX)) <= 0.0f) ||
  142. ((DpiY = (REAL)GetDeviceCaps(hdc, LOGPIXELSY)) <= 0.0f))
  143. {
  144. // Assume this is a display surface with the display DPI for now
  145. IsDisplay = TRUE;
  146. DpiX = Globals::DesktopDpiX;
  147. DpiY = Globals::DesktopDpiY;
  148. }
  149. else
  150. {
  151. IsDisplay = (GetDeviceCaps(hdc, TECHNOLOGY) == DT_RASDISPLAY);
  152. }
  153. Scan = NULL;
  154. DdrawSurface = NULL;
  155. DdrawSurface7 = NULL;
  156. PaletteTable = NULL;
  157. CompressedData = NULL;
  158. SurfaceTransparency = TransparencyUnknown;
  159. }
  160. ~DpBitmap();
  161. VOID InitializeForMetafile(GpDevice *device)
  162. {
  163. InitializeForGdiBitmap(device, 0, 0);
  164. }
  165. VOID InitializeForGdiBitmap(
  166. GpDevice *device,
  167. INT width,
  168. INT height
  169. );
  170. VOID InitializeForGdiScreen(
  171. GpDevice *device,
  172. INT width,
  173. INT height
  174. );
  175. BOOL InitializeForD3D(
  176. HDC hdc,
  177. INT *width,
  178. INT *height,
  179. DpDriver** driver
  180. );
  181. BOOL InitializeForD3D(
  182. IDirectDrawSurface7* surface,
  183. INT *width,
  184. INT *height,
  185. DpDriver** driver
  186. );
  187. BOOL InitializeForDibsection(
  188. HDC hdc,
  189. HBITMAP hbitmap,
  190. GpDevice *device,
  191. DIBSECTION *dib,
  192. INT *width,
  193. INT *height,
  194. DpDriver **driver
  195. );
  196. VOID InitializeForGdipBitmap(
  197. INT width,
  198. INT height,
  199. ImageInfo * imageInfo,
  200. EpScanBitmap * scanBitmap,
  201. BOOL isDisplay
  202. );
  203. BOOL InitializeForPrinter(GpPrinterDevice *device, INT width, INT height);
  204. BOOL StandardFormat();
  205. PixelFormatID GetPixelFormatFromBitDepth(INT bits);
  206. // Flush any pending rendering to this surface:
  207. VOID Flush(GpFlushIntention intention);
  208. REAL GetDpiX() const { return DpiX; }
  209. REAL GetDpiY() const { return DpiY; }
  210. };
  211. #endif