openMSX
PixelRenderer.hh
Go to the documentation of this file.
1 #ifndef PIXELRENDERER_HH
2 #define PIXELRENDERER_HH
3 
4 #include "Renderer.hh"
5 #include "Observer.hh"
6 #include "RenderSettings.hh"
7 #include "openmsx.hh"
8 #include <memory>
9 
10 namespace openmsx {
11 
12 class EventDistributor;
13 class RealTime;
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 
23 /** Generic implementation of a pixel-based Renderer.
24  * Uses a Rasterizer to plot actual pixels for a specific video system.
25  */
26 class PixelRenderer final : public Renderer, private Observer<Setting>
27 {
28 public:
29  PixelRenderer(VDP& vdp, Display& display);
30  ~PixelRenderer() override;
31 
32  // Renderer interface:
33  PostProcessor* getPostProcessor() const override;
34  void reInit() override;
35  void frameStart(EmuTime::param time) override;
36  void frameEnd(EmuTime::param time) override;
37  void updateHorizontalScrollLow(byte scroll, EmuTime::param time) override;
38  void updateHorizontalScrollHigh(byte scroll, EmuTime::param time) override;
39  void updateBorderMask(bool masked, EmuTime::param time) override;
40  void updateMultiPage(bool multiPage, EmuTime::param time) override;
41  void updateTransparency(bool enabled, EmuTime::param time) override;
42  void updateSuperimposing(const RawFrame* videoSource, EmuTime::param time) override;
43  void updateForegroundColor(int color, EmuTime::param time) override;
44  void updateBackgroundColor(int color, EmuTime::param time) override;
45  void updateBlinkForegroundColor(int color, EmuTime::param time) override;
46  void updateBlinkBackgroundColor(int color, EmuTime::param time) override;
47  void updateBlinkState(bool enabled, EmuTime::param time) override;
48  void updatePalette(int index, int grb, EmuTime::param time) override;
49  void updateVerticalScroll(int scroll, EmuTime::param time) override;
50  void updateHorizontalAdjust(int adjust, EmuTime::param time) override;
51  void updateDisplayEnabled(bool enabled, EmuTime::param time) override;
52  void updateDisplayMode(DisplayMode mode, EmuTime::param time) override;
53  void updateNameBase(int addr, EmuTime::param time) override;
54  void updatePatternBase(int addr, EmuTime::param time) override;
55  void updateColorBase(int addr, EmuTime::param time) override;
56  void updateSpritesEnabled(bool enabled, EmuTime::param time) override;
57  void updateVRAM(unsigned offset, EmuTime::param time) override;
58  void updateWindow(bool enabled, EmuTime::param time) override;
59 
60 private:
61  /** Indicates whether the area to be drawn is border or display. */
62  enum DrawType { DRAW_BORDER, DRAW_DISPLAY };
63 
64  // Observer<Setting> interface:
65  void update(const Setting& setting) override;
66 
67  /** Call the right draw method in the subclass,
68  * depending on passed drawType.
69  */
70  void draw(
71  int startX, int startY, int endX, int endY, DrawType drawType,
72  bool atEnd);
73 
74  /** Subdivide an area specified by two scan positions into a series of
75  * rectangles.
76  * Clips the rectangles to { (x,y) | clipL <= x < clipR }.
77  * @param drawType
78  * If DRAW_BORDER, draw rectangles using drawBorder;
79  * if DRAW_DISPLAY, draw rectangles using drawDisplay.
80  */
81  void subdivide(
82  int startX, int startY, int endX, int endY,
83  int clipL, int clipR, DrawType drawType );
84 
85  inline bool checkSync(int offset, EmuTime::param time);
86 
87  /** Update renderer state to specified moment in time.
88  * @param time Moment in emulated time to update to.
89  * @param force When screen accuracy is used,
90  * rendering is only performed if this parameter is true.
91  */
92  void sync(EmuTime::param time, bool force = false);
93 
94  /** Render lines until specified moment in time.
95  * Unlike sync(), this method does not sync with VDPVRAM.
96  * The VRAM should be to be up to date and remain unchanged
97  * from the current time to the specified time.
98  * @param time Moment in emulated time to render lines until.
99  */
100  void renderUntil(EmuTime::param time);
101 
102  /** The VDP of which the video output is being rendered.
103  */
104  VDP& vdp;
105 
106  /** The VRAM whose contents are rendered.
107  */
108  VDPVRAM& vram;
109 
110  EventDistributor& eventDistributor;
111  RealTime& realTime;
112  RenderSettings& renderSettings;
113  VideoSourceSetting& videoSourceSetting;
114 
115  /** The sprite checker whose sprites are rendered.
116  */
117  SpriteChecker& spriteChecker;
118 
119  const std::unique_ptr<Rasterizer> rasterizer;
120 
121  float finishFrameDuration;
122  int frameSkipCounter;
123 
124  /** Number of the next position within a line to render.
125  * Expressed in VDP clock ticks since start of line.
126  */
127  int nextX;
128 
129  /** Number of the next line to render.
130  * Expressed in number of lines since start of frame.
131  */
132  int nextY;
133 
134  // internal VDP counter, actually belongs in VDP
135  int textModeCounter;
136 
137  /** Accuracy setting for current frame.
138  */
139  RenderSettings::Accuracy accuracy;
140 
141  /** Is display enabled?
142  * Enabled means the current line is in the display area and
143  * forced blanking is off.
144  */
145  bool displayEnabled;
146 
147  /** Should current frame be draw or can it be skipped.
148  */
149  bool renderFrame;
150  bool prevRenderFrame;
151 };
152 
153 } // namespace openmsx
154 
155 #endif
void updateSuperimposing(const RawFrame *videoSource, EmuTime::param time) override
Informs the renderer of a VDP superimposing change.
bool getEnum() const noexcept
Definition: EnumSetting.hh:96
void updateHorizontalAdjust(int adjust, EmuTime::param time) override
Informs the renderer of a horizontal adjust change.
void updatePalette(int index, int grb, EmuTime::param time) override
Informs the renderer of a VDP palette change.
PostProcessor * getPostProcessor() const override
See VDP::getPostProcessor.
void updateBorderMask(bool masked, EmuTime::param time) override
Informs the renderer of a horizontal scroll change: the border mask has been enabled/disabled.
void updateHorizontalScrollHigh(byte scroll, EmuTime::param time) override
Informs the renderer of a horizontal scroll change: the higher scroll value has changed.
Represents a VDP display mode.
Definition: DisplayMode.hh:14
void reInit() override
Reinitialise Renderer state.
void updateColorBase(int addr, EmuTime::param time) override
Informs the renderer of a color table base address change.
void updateBlinkState(bool enabled, EmuTime::param time) override
Informs the renderer of a VDP blinking state change.
void updateHorizontalScrollLow(byte scroll, EmuTime::param time) override
Informs the renderer of a horizontal scroll change: the lower scroll value has changed.
void updateDisplayMode(DisplayMode mode, EmuTime::param time) override
Informs the renderer of a VDP display mode change.
Abstract base class for Renderers.
Definition: Renderer.hh:22
void updateVerticalScroll(int scroll, EmuTime::param time) override
Informs the renderer of a vertical scroll change.
void frameEnd(EmuTime::param time) override
Signals the end of a frame.
void updateMultiPage(bool multiPage, EmuTime::param time) override
Informs the renderer of a horizontal scroll change: the multi page setting has changed.
void updateDisplayEnabled(bool enabled, EmuTime::param time) override
Informs the renderer of a VDP display enabled change.
void updateTransparency(bool enabled, EmuTime::param time) override
Informs the renderer of a VDP transparency enable/disable change.
PixelRenderer(VDP &vdp, Display &display)
void updateNameBase(int addr, EmuTime::param time) override
Informs the renderer of a name table base address change.
void updateBlinkBackgroundColor(int color, EmuTime::param time) override
Informs the renderer of a VDP blink background color change.
std::array< std::array< uint8_t, 3 >, 16 > getMSX1Palette() const
Get the (fixed) palette for this MSX1 VDP.
Definition: VDP.cc:1482
void updatePatternBase(int addr, EmuTime::param time) override
Informs the renderer of a pattern table base address change.
Manages VRAM contents and synchronises the various users of the VRAM.
Definition: VDPVRAM.hh:384
void updateForegroundColor(int color, EmuTime::param time) override
Informs the renderer of a VDP foreground color change.
void updateBlinkForegroundColor(int color, EmuTime::param time) override
Informs the renderer of a VDP blink foreground color change.
void updateBackgroundColor(int color, EmuTime::param time) override
Informs the renderer of a VDP background color change.
void updateSpritesEnabled(bool enabled, EmuTime::param time) override
Informs the renderer of a VDP sprites enabled change.
void frameStart(EmuTime::param time) override
Signals the start of a new frame.
void updateWindow(bool enabled, EmuTime::param time) override
Informs the observer that the entire VRAM window will change.
void updateVRAM(unsigned offset, EmuTime::param time) override
Informs the observer of a change in VRAM contents.