openMSX
SDLRasterizer.hh
Go to the documentation of this file.
1 #ifndef SDLRASTERIZER_HH
2 #define SDLRASTERIZER_HH
3 
4 #include "Rasterizer.hh"
5 #include "BitmapConverter.hh"
6 #include "CharacterConverter.hh"
7 #include "SpriteConverter.hh"
8 #include "Observer.hh"
9 #include "openmsx.hh"
10 #include <memory>
11 
12 namespace openmsx {
13 
14 class Display;
15 class VDP;
16 class VDPVRAM;
17 class OutputSurface;
18 class VisibleSurface;
19 class RawFrame;
20 class RenderSettings;
21 class Setting;
22 class PostProcessor;
23 
27 template <class Pixel>
28 class SDLRasterizer final : public Rasterizer
29  , private Observer<Setting>
30 {
31 public:
32  SDLRasterizer(const SDLRasterizer&) = delete;
33  SDLRasterizer& operator=(const SDLRasterizer&) = delete;
34 
36  VDP& vdp, Display& display, VisibleSurface& screen,
37  std::unique_ptr<PostProcessor> postProcessor);
38  ~SDLRasterizer() override;
39 
40  // Rasterizer interface:
41  PostProcessor* getPostProcessor() const override;
42  bool isActive() override;
43  void reset() override;
44  void frameStart(EmuTime::param time) override;
45  void frameEnd() override;
46  void setDisplayMode(DisplayMode mode) override;
47  void setPalette(int index, int grb) override;
48  void setBackgroundColor(int index) override;
49  void setHorizontalAdjust(int adjust) override;
50  void setHorizontalScrollLow(byte scroll) override;
51  void setBorderMask(bool masked) override;
52  void setTransparency(bool enabled) override;
53  void setSuperimposeVideoFrame(const RawFrame* videoSource) override;
54  void drawBorder(int fromX, int fromY, int limitX, int limitY) override;
55  void drawDisplay(
56  int fromX, int fromY,
57  int displayX, int displayY,
58  int displayWidth, int displayHeight) override;
59  void drawSprites(
60  int fromX, int fromY,
61  int displayX, int displayY,
62  int displayWidth, int displayHeight) override;
63  bool isRecording() const override;
64 
65 private:
66  inline void renderBitmapLine(Pixel* buf, unsigned vramLine);
67 
70  void resetPalette();
71 
76  void precalcPalette();
77 
82  void precalcColorIndex0(DisplayMode mode, bool transparency,
83  const RawFrame* superimposing, byte bgcolorIndex);
84 
85  // Some of the border-related settings changed.
86  void borderSettingChanged();
87 
88  // Get the border color(s). These are 16bpp or 32bpp host pixels.
89  void getBorderColors(Pixel& border0, Pixel& border1);
90 
91  // Observer<Setting>
92  void update(const Setting& setting) override;
93 
96  VDP& vdp;
97 
100  VDPVRAM& vram;
101 
104  OutputSurface& screen;
105 
109  const std::unique_ptr<PostProcessor> postProcessor;
110 
113  std::unique_ptr<RawFrame> workFrame;
114 
117  RenderSettings& renderSettings;
118 
121  CharacterConverter<Pixel> characterConverter;
122 
125  BitmapConverter<Pixel> bitmapConverter;
126 
129  SpriteConverter<Pixel> spriteConverter;
130 
134  int lineRenderTop;
135 
143  Pixel palFg[16 * 2], palBg[16];
144 
147  Pixel palGraphic7Sprites[16];
148 
152  Pixel V9938_COLORS[8][8][8];
153 
157  Pixel PALETTE256[256];
158 
161  Pixel V9958_COLORS[32768];
162 
163  // True iff left/right border optimization can (still) be applied
164  // this frame.
165  bool canSkipLeftRightBorders;
166 
167  // True iff some of the left/right border related settings changed
168  // during this frame (meaning the border pixels of this frame cannot
169  // be reused for future frames).
170  bool mixedLeftRightBorders;
171 };
172 
173 } // namespace openmsx
174 
175 #endif
Utility class for converting VRAM contents to host pixels.
void setPalette(int index, int grb) override
Change an entry in the palette.
Represents the output window/screen of openMSX.
Definition: Display.hh:31
Utility class for converting VRAM contents to host pixels.
void setBackgroundColor(int index) override
Changes the background color.
void reset() override
Resynchronize with VDP: all cached states are flushed.
Rasterizer using a frame buffer approach: it writes pixels to a single rectangular pixel buffer...
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
void drawSprites(int fromX, int fromY, int displayX, int displayY, int displayWidth, int displayHeight) override
Render a rectangle of sprite pixels on the host screen.
Represents a VDP display mode.
Definition: DisplayMode.hh:14
A frame buffer where pixels can be written to.
uint32_t Pixel
bool isActive() override
Will the output of this Rasterizer be displayed? There is no point in producing a frame that will not...
SDLRasterizer & operator=(const SDLRasterizer &)=delete
void drawDisplay(int fromX, int fromY, int displayX, int displayY, int displayWidth, int displayHeight) override
Render a rectangle of display pixels on the host screen.
A video frame as output by the VDP scanline conversion unit, before any postprocessing filters are ap...
Definition: RawFrame.hh:25
bool isRecording() const override
Is video recording active?
void drawBorder(int fromX, int fromY, int limitX, int limitY) override
Render a rectangle of border pixels on the host screen.
void setHorizontalScrollLow(byte scroll) override
An OutputSurface which is visible to the user, such as a window or a full screen display.
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void setTransparency(bool enabled) override
void setHorizontalAdjust(int adjust) override
SDLRasterizer(const SDLRasterizer &)=delete
void setDisplayMode(DisplayMode mode) override
Precalc several values that depend on the display mode.
Unified implementation of MSX Video Display Processors (VDPs).
Definition: VDP.hh:61
Abstract base class for post processors.
Class containing all settings for renderers.
Manages VRAM contents and synchronises the various users of the VRAM.
Definition: VDPVRAM.hh:384
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:9
void setBorderMask(bool masked) override
void frameStart(EmuTime::param time) override
Indicates the start of a new frame.
Utility class for converting VRAM contents to host pixels.
void frameEnd() override
Indicates the end of the current frame.
void setSuperimposeVideoFrame(const RawFrame *videoSource) override
PostProcessor * getPostProcessor() const override
See VDP::getPostProcessor().