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.

213 lines
6.4 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998 Microsoft Corporation
  4. *
  5. * Abstract:
  6. *
  7. * Internal class representing the device.
  8. *
  9. * Revision History:
  10. *
  11. * 12/04/1998 andrewgo
  12. * Created it.
  13. *
  14. \**************************************************************************/
  15. #ifndef _DEVICE_HPP
  16. #define _DEVICE_HPP
  17. //--------------------------------------------------------------------------
  18. // Represents the underlying physical device
  19. //--------------------------------------------------------------------------
  20. class GpDevice
  21. {
  22. private:
  23. // We now use an ObjectTag to determine if the object is valid
  24. // instead of using a BOOL. This is much more robust and helps
  25. // with debugging. It also enables us to version our objects
  26. // more easily with a version number in the ObjectTag.
  27. ObjectTag Tag; // Keep this as the 1st value in the object!
  28. protected:
  29. VOID SetValid(BOOL valid)
  30. {
  31. Tag = valid ? ObjectTagDevice : ObjectTagInvalid;
  32. }
  33. public:
  34. // Buffer data:
  35. INT BufferWidth; // Buffer width in pixels, 0 if there are no
  36. // buffers or they couldn't be allocated
  37. HBITMAP DIBSectionBitmap;
  38. HDC DIBSectionHdc;
  39. VOID *DIBSection;
  40. VOID *Buffers[5];
  41. PixelFormatID BufferFormat;
  42. // Scan interfaces:
  43. EpScanEngine ScanEngine; // For accessing bitmap formats that are
  44. // directly writeable by GDI+
  45. EpScanGdiDci *ScanGdi; // For accessing bitmap formats that are not
  46. // directly accessible by GDI+, via GDI
  47. // BitBlt calls
  48. EpScanGdiDci *ScanDci; // For accessing the screen directly
  49. HDC DeviceHdc; // Owned DC representing specific
  50. // device
  51. HMONITOR hMonitor; // Handle to monitor. This is set if the
  52. // device represents a physical device
  53. // associated with monitor on the system.
  54. // WARNING: current code uses hMonitor != NULL
  55. // to indicate that GpDevice was created via
  56. // GpDevice(HMONITOR) and that deletion of
  57. // DeviceHdc is owned by destructor. If
  58. // somebody wants to change this, then they
  59. // will need to fix how DeviceHdc is managed.
  60. INT ScreenOffsetX; // Offset to screen for this device. Needed
  61. INT ScreenOffsetY; // to support multimon. NOTE, currently we
  62. // have not found a good way to derive the
  63. // screen position of the monitor specific
  64. // hdc. If we find a way to get this
  65. // from the DeviceHdc then we can remove
  66. // this state.
  67. INT ScreenWidth; // Width and Height of screen space. There
  68. INT ScreenHeight; // is probably a better place to store this
  69. // information but we'll stick it here for
  70. // now. TODO - find a better place
  71. IDirectDraw7 * pdd; // Direct Draw Interface for device
  72. IDirect3D7 * pd3d; // Direct 3D Interface for device
  73. IDirectDrawSurface7 * pdds; // Direct draw primary surface of device
  74. IDirect3DDevice7 * pd3dDevice; // D3D device for monitor device
  75. IDirectDrawSurface7 * pddsRenderTarget;
  76. // Current render target that is
  77. // selected into the D3D device
  78. ColorPalette * Palette; // System palette color table
  79. public:
  80. GpDevice(HDC hdc);
  81. GpDevice(HMONITOR hMonitor);
  82. // Allow subclass devices to cleanup before deleting DC
  83. virtual ~GpDevice();
  84. virtual BOOL IsValid() const
  85. {
  86. ASSERT((Tag == ObjectTagDevice) || (Tag == ObjectTagInvalid));
  87. #if DBG
  88. if (Tag == ObjectTagInvalid)
  89. {
  90. WARNING1("Invalid Device");
  91. }
  92. #endif
  93. return (Tag == ObjectTagDevice);
  94. }
  95. BOOL
  96. GetScanBuffers(
  97. INT width,
  98. VOID **dibSection = NULL,
  99. HDC *hdcDibSection = NULL,
  100. PixelFormatID *dstFormat = NULL,
  101. VOID *buffers[5] = NULL
  102. );
  103. GpSemaphore DeviceLock;
  104. private:
  105. static BOOL EnumDirectDrawCallback(
  106. GUID * lpGUID,
  107. LPSTR lpDriverDescription,
  108. LPSTR lpDriverName,
  109. LPVOID lpContext,
  110. HMONITOR hMonitor);
  111. };
  112. class GpDeviceList
  113. {
  114. public:
  115. GpDeviceList(void);
  116. ~GpDeviceList(void);
  117. GpStatus AddDevice(GpDevice * device);
  118. GpDevice * FindD3DDevice(IDirectDrawSurface7 * surface);
  119. private:
  120. #if 0
  121. void Build(void);
  122. static HRESULT EnumD3DDevicesCallback(LPSTR lpDevDesc,
  123. LPSTR lpDevName,
  124. LPD3DDEVICEDESC7 * d3dDevDesc,
  125. LPVOID lpConetxt);
  126. #endif
  127. INT mNumDevices;
  128. GpDevice ** mDevices;
  129. };
  130. //--------------------------------------------------------------------------
  131. // Represents the underlying physical device
  132. //--------------------------------------------------------------------------
  133. class GpPrinterDevice : public GpDevice
  134. {
  135. public:
  136. // !! Split into two classes, we don't want to inherit the scan goop
  137. // from above. Don't forget DeviceLock->Initialize()
  138. EpScanDIB ScanPrint;
  139. public:
  140. GpPrinterDevice(HDC hdc) : GpDevice(hdc) {};
  141. virtual ~GpPrinterDevice()
  142. {
  143. // Don't delete the printer HDC
  144. DeviceHdc = NULL;
  145. };
  146. };
  147. //--------------------------------------------------------------------------
  148. // GpDevice lock
  149. //--------------------------------------------------------------------------
  150. class Devlock
  151. {
  152. private:
  153. GpSemaphore *DeviceLock;
  154. public:
  155. Devlock(GpDevice *device)
  156. {
  157. DeviceLock = &device->DeviceLock;
  158. DeviceLock->Lock();
  159. }
  160. ~Devlock()
  161. {
  162. DeviceLock->Unlock();
  163. }
  164. };
  165. #endif // !_DEVICE_HPP