xsurface.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. ** Command & Conquer Renegade(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/xsurface.h $*
  25. * *
  26. * $Author:: Eric_c $*
  27. * *
  28. * $Modtime:: 4/02/99 12:01p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if _MSC_VER >= 1000
  36. #pragma once
  37. #endif // _MSC_VER >= 1000
  38. #ifndef XSURFACE_H
  39. #define XSURFACE_H
  40. #include "surface.h"
  41. /*
  42. ** This is a concrete (mostly) derived class that handles a surface. This layer presumes that
  43. ** pixels are compositied into a contiguous integral (usually a byte) linear array. The
  44. ** implemented routines do not use hardware assist. They are prime candidates to be converted
  45. ** to assembly language.
  46. */
  47. class XSurface : public Surface
  48. {
  49. public:
  50. XSurface(int width=0, int height=0) : Surface(width, height), LockCount(0) {}
  51. virtual ~XSurface(void) {}
  52. /*
  53. ** Copies regions from one surface to another.
  54. */
  55. virtual bool Blit_From(Rect const & dcliprect, Rect const & destrect, Surface const & source, Rect const & scliprect, Rect const & sourcerect, bool trans=false);
  56. virtual bool Blit_From(Rect const & destrect, Surface const & source, Rect const & sourcerect, bool trans=false);
  57. virtual bool Blit_From(Surface const & source, bool trans=false);
  58. /*
  59. ** Fills a region with a constant color.
  60. */
  61. virtual bool Fill_Rect(Rect const & rect, int color);
  62. virtual bool Fill_Rect(Rect const & cliprect, Rect const & fillrect, int color);
  63. virtual bool Fill(int color);
  64. /*
  65. ** Fetches and stores a pixel to the display (pixel is in surface format).
  66. */
  67. virtual bool Put_Pixel(Point2D const & point, int color);
  68. virtual int Get_Pixel(Point2D const & point) const;
  69. /*
  70. ** Draws lines onto the surface.
  71. */
  72. virtual bool Draw_Line(Point2D const & startpoint, Point2D const & endpoint, int color);
  73. virtual bool Draw_Line(Rect const & cliprect, Point2D const & startpoint, Point2D const & endpoint, int color);
  74. /*
  75. ** Draws rectangles onto the surface.
  76. */
  77. virtual bool Draw_Rect(Rect const & rect, int color);
  78. virtual bool Draw_Rect(Rect const & cliprect, Rect const & rect, int color);
  79. /*
  80. ** Gets and frees a direct pointer to the video memory.
  81. */
  82. virtual void * Lock(Point2D = Point2D(0, 0)) const {LockCount++;return(NULL);}
  83. virtual bool Unlock(void) const {LockCount--;return(true);}
  84. virtual bool Is_Locked(void) const {return(LockCount != 0);}
  85. /*
  86. ** Queries information about the surface.
  87. */
  88. virtual int Bytes_Per_Pixel(void) const = 0;
  89. virtual int Stride(void) const = 0;
  90. /*
  91. ** Hack function to serve the purpose that RTTI was invented for, but since
  92. ** the Watcom compiler doesn't support RTTI, we must resort to using this
  93. ** alternative.
  94. */
  95. virtual bool Is_Direct_Draw(void) const {return(false);}
  96. /*
  97. ** This routine is handy for preparing to perform some kind of manual blit
  98. ** operation.
  99. */
  100. static bool Prep_For_Blit(Surface & dest, Rect & drect, Surface const & source, Rect & srect, bool & overlapped, void * & dbuffer, void * & sbuffer);
  101. static bool Prep_For_Blit(Surface & dest, Rect const & dcliprect, Rect & drect, Surface const & source, Rect const & scliprect, Rect & srect, bool & overlapped, void * & dbuffer, void * & sbuffer);
  102. /*
  103. ** These are the exposed manual blit routines. They can be called directly if desired.
  104. */
  105. static bool Blit_Trans(Surface & dest, Rect const & destrect, Surface const & source, Rect const & sourcerect);
  106. static bool Blit_Plain(Surface & dest, Rect const & destrect, Surface const & source, Rect const & sourcerect);
  107. protected:
  108. /*
  109. ** Records the number of locks on this surface.
  110. */
  111. mutable int LockCount;
  112. };
  113. bool Blit_Clip(Rect & drect, Rect const & dwindow, Rect & srect, Rect const & swindow);
  114. #endif