PixelRenderer.hh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. #ifndef PIXELRENDERER_HH
  2. #define PIXELRENDERER_HH
  3. #include "Renderer.hh"
  4. #include "Observer.hh"
  5. #include "RenderSettings.hh"
  6. #include "openmsx.hh"
  7. #include <cstdint>
  8. #include <memory>
  9. namespace openmsx {
  10. class EventDistributor;
  11. class RealTime;
  12. class SpeedManager;
  13. class ThrottleManager;
  14. class Display;
  15. class Rasterizer;
  16. class VDP;
  17. class VDPVRAM;
  18. class SpriteChecker;
  19. class DisplayMode;
  20. class Setting;
  21. class VideoSourceSetting;
  22. /** Generic implementation of a pixel-based Renderer.
  23. * Uses a Rasterizer to plot actual pixels for a specific video system.
  24. */
  25. class PixelRenderer final : public Renderer, private Observer<Setting>
  26. {
  27. public:
  28. PixelRenderer(VDP& vdp, Display& display);
  29. ~PixelRenderer() override;
  30. // Renderer interface:
  31. PostProcessor* getPostProcessor() const override;
  32. void reInit() override;
  33. void frameStart(EmuTime::param time) override;
  34. void frameEnd(EmuTime::param time) override;
  35. void updateHorizontalScrollLow(byte scroll, EmuTime::param time) override;
  36. void updateHorizontalScrollHigh(byte scroll, EmuTime::param time) override;
  37. void updateBorderMask(bool masked, EmuTime::param time) override;
  38. void updateMultiPage(bool multiPage, EmuTime::param time) override;
  39. void updateTransparency(bool enabled, EmuTime::param time) override;
  40. void updateSuperimposing(const RawFrame* videoSource, EmuTime::param time) override;
  41. void updateForegroundColor(int color, EmuTime::param time) override;
  42. void updateBackgroundColor(int color, EmuTime::param time) override;
  43. void updateBlinkForegroundColor(int color, EmuTime::param time) override;
  44. void updateBlinkBackgroundColor(int color, EmuTime::param time) override;
  45. void updateBlinkState(bool enabled, EmuTime::param time) override;
  46. void updatePalette(int index, int grb, EmuTime::param time) override;
  47. void updateVerticalScroll(int scroll, EmuTime::param time) override;
  48. void updateHorizontalAdjust(int adjust, EmuTime::param time) override;
  49. void updateDisplayEnabled(bool enabled, EmuTime::param time) override;
  50. void updateDisplayMode(DisplayMode mode, EmuTime::param time) override;
  51. void updateNameBase(int addr, EmuTime::param time) override;
  52. void updatePatternBase(int addr, EmuTime::param time) override;
  53. void updateColorBase(int addr, EmuTime::param time) override;
  54. void updateSpritesEnabled(bool enabled, EmuTime::param time) override;
  55. void updateVRAM(unsigned offset, EmuTime::param time) override;
  56. void updateWindow(bool enabled, EmuTime::param time) override;
  57. private:
  58. /** Indicates whether the area to be drawn is border or display. */
  59. enum DrawType { DRAW_BORDER, DRAW_DISPLAY };
  60. // Observer<Setting> interface:
  61. void update(const Setting& setting) override;
  62. /** Call the right draw method in the subclass,
  63. * depending on passed drawType.
  64. */
  65. void draw(
  66. int startX, int startY, int endX, int endY, DrawType drawType,
  67. bool atEnd);
  68. /** Subdivide an area specified by two scan positions into a series of
  69. * rectangles.
  70. * Clips the rectangles to { (x,y) | clipL <= x < clipR }.
  71. * @param drawType
  72. * If DRAW_BORDER, draw rectangles using drawBorder;
  73. * if DRAW_DISPLAY, draw rectangles using drawDisplay.
  74. */
  75. void subdivide(
  76. int startX, int startY, int endX, int endY,
  77. int clipL, int clipR, DrawType drawType );
  78. inline bool checkSync(int offset, EmuTime::param time);
  79. /** Update renderer state to specified moment in time.
  80. * @param time Moment in emulated time to update to.
  81. * @param force When screen accuracy is used,
  82. * rendering is only performed if this parameter is true.
  83. */
  84. void sync(EmuTime::param time, bool force = false);
  85. /** Render lines until specified moment in time.
  86. * Unlike sync(), this method does not sync with VDPVRAM.
  87. * The VRAM should be to be up to date and remain unchanged
  88. * from the current time to the specified time.
  89. * @param time Moment in emulated time to render lines until.
  90. */
  91. void renderUntil(EmuTime::param time);
  92. /** The VDP of which the video output is being rendered.
  93. */
  94. VDP& vdp;
  95. /** The VRAM whose contents are rendered.
  96. */
  97. VDPVRAM& vram;
  98. EventDistributor& eventDistributor;
  99. RealTime& realTime;
  100. SpeedManager& speedManager;
  101. ThrottleManager& throttleManager;
  102. RenderSettings& renderSettings;
  103. VideoSourceSetting& videoSourceSetting;
  104. /** The sprite checker whose sprites are rendered.
  105. */
  106. SpriteChecker& spriteChecker;
  107. const std::unique_ptr<Rasterizer> rasterizer;
  108. float finishFrameDuration;
  109. float frameSkipCounter;
  110. /** Number of the next position within a line to render.
  111. * Expressed in VDP clock ticks since start of line.
  112. */
  113. int nextX;
  114. /** Number of the next line to render.
  115. * Expressed in number of lines since start of frame.
  116. */
  117. int nextY;
  118. // internal VDP counter, actually belongs in VDP
  119. int textModeCounter;
  120. /** Accuracy setting for current frame.
  121. */
  122. RenderSettings::Accuracy accuracy;
  123. /** Is display enabled?
  124. * Enabled means the current line is in the display area and
  125. * forced blanking is off.
  126. */
  127. bool displayEnabled;
  128. /** Should current frame be draw or can it be skipped.
  129. */
  130. bool renderFrame;
  131. bool prevRenderFrame;
  132. /** Should a rendered frame be painted to the window?
  133. * When renderFrame is false, paintFrame must be false as well.
  134. * But when recording, renderFrame will be true for every frame,
  135. * while paintFrame may not.
  136. */
  137. bool paintFrame;
  138. /** Timestamp (us, like Timer::getTime()) at which we last painted a frame.
  139. * Used to force a minimal paint rate when throttle is off.
  140. */
  141. uint64_t lastPaintTime = 0;
  142. };
  143. } // namespace openmsx
  144. #endif