RawFrame.hh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef RAWFRAME_HH
  2. #define RAWFRAME_HH
  3. #include "FrameSource.hh"
  4. #include "MemBuffer.hh"
  5. #include "openmsx.hh"
  6. #include <cassert>
  7. namespace openmsx {
  8. // Used by SDLRasterizer to implement left/right border drawing optimization.
  9. struct V9958RasterizerBorderInfo
  10. {
  11. uint32_t color0, color1;
  12. byte mode = 0xff; // invalid mode
  13. byte adjust;
  14. byte scroll;
  15. bool masked;
  16. };
  17. /** A video frame as output by the VDP scanline conversion unit,
  18. * before any postprocessing filters are applied.
  19. */
  20. class RawFrame final : public FrameSource
  21. {
  22. public:
  23. RawFrame(const PixelFormat& format, unsigned maxWidth, unsigned height);
  24. template<typename Pixel>
  25. Pixel* getLinePtrDirect(unsigned y) {
  26. return reinterpret_cast<Pixel*>(data.data() + y * pitch);
  27. }
  28. unsigned getLineWidthDirect(unsigned y) const {
  29. return lineWidths[y];
  30. }
  31. inline void setLineWidth(unsigned line, unsigned width) {
  32. assert(line < getHeight());
  33. assert(width <= maxWidth);
  34. lineWidths[line] = width;
  35. }
  36. template <class Pixel>
  37. inline void setBlank(unsigned line, Pixel color) {
  38. assert(line < getHeight());
  39. auto* pixels = getLinePtrDirect<Pixel>(line);
  40. pixels[0] = color;
  41. lineWidths[line] = 1;
  42. }
  43. unsigned getRowLength() const override;
  44. // RawFrame is mostly agnostic of the border info struct. The only
  45. // thing it does is store the information and give access to it.
  46. V9958RasterizerBorderInfo& getBorderInfo() { return borderInfo; }
  47. protected:
  48. unsigned getLineWidth(unsigned line) const override;
  49. const void* getLineInfo(
  50. unsigned line, unsigned& width,
  51. void* buf, unsigned bufWidth) const override;
  52. bool hasContiguousStorage() const override;
  53. private:
  54. MemBuffer<char, 64> data;
  55. MemBuffer<unsigned> lineWidths;
  56. unsigned maxWidth;
  57. unsigned pitch;
  58. V9958RasterizerBorderInfo borderInfo;
  59. };
  60. } // namespace openmsx
  61. #endif