dsurface.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /G/wwlib/dsurface.h $*
  25. * *
  26. * $Author:: Neal_k $*
  27. * *
  28. * $Modtime:: 6/23/00 2:24p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #ifndef DSURFACE_H
  36. #define DSURFACE_H
  37. #include "palette.h"
  38. #include "win.h"
  39. #include "xsurface.h"
  40. #include <ddraw.h>
  41. /*
  42. ** This is a concrete surface class that is based on the DirectDraw
  43. ** API.
  44. */
  45. class DSurface : public XSurface
  46. {
  47. typedef XSurface BASECLASS;
  48. public:
  49. virtual ~DSurface(void);
  50. /*
  51. ** Default constructor.
  52. */
  53. DSurface(void);
  54. /*
  55. ** Constructs a working surface (not visible).
  56. */
  57. DSurface(int width, int height, bool system_memory = false, DDPIXELFORMAT *pixform=NULL);
  58. /*
  59. ** Creates a surface from a previously created DirectDraw surface object.
  60. */
  61. DSurface(LPDIRECTDRAWSURFACE surfaceptr);
  62. /*
  63. ** Get/Release a windows device context from a DirectX surface
  64. */
  65. HDC GetDC(void);
  66. int ReleaseDC(HDC hdc);
  67. /*
  68. ** Create a surface object that represents the currently visible screen.
  69. */
  70. static DSurface * Create_Primary(DSurface ** backsurface1=NULL);
  71. /*
  72. ** Copies regions from one surface to another.
  73. */
  74. virtual bool Blit_From(Rect const & dcliprect, Rect const & destrect, Surface const & source, Rect const & scliprect, Rect const & sourcerect, bool trans=false);
  75. virtual bool Blit_From(Rect const & destrect, Surface const & source, Rect const & sourcerect, bool trans=false);
  76. virtual bool Blit_From(Surface const & source, bool trans=false) {return(XSurface::Blit_From(source, trans));}
  77. /*
  78. ** Fills a region with a constant color.
  79. */
  80. virtual bool Fill_Rect(Rect const & rect, int color);
  81. virtual bool Fill_Rect(Rect const & cliprect, Rect const & fillrect, int color);
  82. /*
  83. ** Gets and frees a direct pointer to the video memory.
  84. */
  85. virtual void * Lock(Point2D point = Point2D(0, 0)) const;
  86. virtual bool Unlock(void) const;
  87. /*
  88. ** Queries information about the surface.
  89. */
  90. virtual int Bytes_Per_Pixel(void) const;
  91. virtual int Stride(void) const;
  92. bool In_Video_Ram(void) const {return(IsVideoRam);}
  93. /*
  94. ** Verifies that this is a direct draw enabled surface.
  95. */
  96. virtual bool Is_Direct_Draw(void) const {return(true);}
  97. static int Build_Hicolor_Pixel(int red, int green, int blue);
  98. static void Build_Remap_Table(unsigned short * table, PaletteClass const & palette);
  99. static unsigned short Get_Halfbright_Mask(void) {return(HalfbrightMask);}
  100. static unsigned short Get_Quarterbright_Mask(void) {return(QuarterbrightMask);}
  101. static unsigned short Get_Eighthbright_Mask(void) {return(EighthbrightMask);}
  102. protected:
  103. void Restore_Check(void) const;
  104. /*
  105. ** Convenient copy of the bytes per pixel value to speed accessing it. It
  106. ** gets accessed frequently.
  107. */
  108. mutable int BytesPerPixel;
  109. /*
  110. ** Lock count and pointer values. This is used to keep track of the levels
  111. ** of locking the graphic data. This is only here because DirectDraw prohibits
  112. ** the blitter from working on a surface that has been locked.
  113. */
  114. mutable void * LockPtr;
  115. /*
  116. ** If this surface object represents the one that is visible and associated
  117. ** with the system GDI, then this flag will be true.
  118. */
  119. bool IsPrimary;
  120. /*
  121. ** Is this surface represented in video ram?
  122. */
  123. bool IsVideoRam;
  124. /*
  125. ** Direct draw specific data.
  126. */
  127. LPDIRECTDRAWSURFACE SurfacePtr;
  128. DDSURFACEDESC * Description;
  129. /*
  130. ** Pointer to the clipper object that is attached to the primary
  131. ** surface.
  132. */
  133. static LPDIRECTDRAWCLIPPER Clipper;
  134. /*
  135. ** Pixel format of primary surface.
  136. */
  137. static DDPIXELFORMAT PixelFormat;
  138. /*
  139. ** Shift values to extract the gun value from a hicolor pixel such that the
  140. ** gun component is normalized to a byte value.
  141. */
  142. static int RedRight;
  143. static int RedLeft;
  144. static int BlueRight;
  145. static int BlueLeft;
  146. static int GreenRight;
  147. static int GreenLeft;
  148. public:
  149. /*
  150. ** Shift values specific to this surface (the above are for the primary surface)
  151. */
  152. int ThisRedRight;
  153. int ThisRedLeft;
  154. int ThisBlueRight;
  155. int ThisBlueLeft;
  156. int ThisGreenRight;
  157. int ThisGreenLeft;
  158. protected:
  159. static unsigned short HalfbrightMask;
  160. static unsigned short QuarterbrightMask;
  161. static unsigned short EighthbrightMask;
  162. /*
  163. ** Number of locks we had to remove in order to get the device context...
  164. */
  165. int DCUnlockCount;
  166. private:
  167. /*
  168. ** This prevents the creation of a surface in ways that are not
  169. ** supported.
  170. */
  171. DSurface(DSurface const & rvalue);
  172. DSurface const operator = (DSurface const & rvalue);
  173. };
  174. #endif