openMSX
Display.hh
Go to the documentation of this file.
1 #ifndef DISPLAY_HH
2 #define DISPLAY_HH
3 
4 #include "RenderSettings.hh"
5 #include "Command.hh"
6 #include "CommandConsole.hh"
7 #include "InfoTopic.hh"
8 #include "OSDGUI.hh"
9 #include "EventListener.hh"
10 #include "LayerListener.hh"
11 #include "RTSchedulable.hh"
12 #include "Observer.hh"
13 #include "CircularBuffer.hh"
14 #include <memory>
15 #include <vector>
16 #include <cstdint>
17 
18 namespace openmsx {
19 
20 class Layer;
21 class Reactor;
22 class VideoSystem;
23 class CliComm;
24 class VideoSystemChangeListener;
25 class Setting;
26 class OutputSurface;
27 
31 class Display final : public EventListener, private Observer<Setting>
32  , private LayerListener, private RTSchedulable
33 {
34 public:
35  using Layers = std::vector<Layer*>;
36 
37  explicit Display(Reactor& reactor);
38  ~Display();
39 
40  void createVideoSystem();
42 
43  CliComm& getCliComm() const;
44  RenderSettings& getRenderSettings() { return renderSettings; }
45  OSDGUI& getOSDGUI() { return osdGui; }
46  CommandConsole& getCommandConsole() { return commandConsole; }
47 
50  void repaint();
51  void repaint(OutputSurface& surface);
52  void repaintDelayed(uint64_t delta);
53 
54  void addLayer(Layer& layer);
55  void removeLayer(Layer& layer);
56 
57  void attach(VideoSystemChangeListener& listener);
58  void detach(VideoSystemChangeListener& listener);
59 
60  Layer* findActiveLayer() const;
61  const Layers& getAllLayers() const { return layers; }
62 
64 
65  std::string getWindowTitle();
66 
67 private:
68  void resetVideoSystem();
69 
70  // EventListener interface
71  int signalEvent(const std::shared_ptr<const Event>& event) override;
72 
73  // RTSchedulable
74  void executeRT() override;
75 
76  // Observer<Setting> interface
77  void update(const Setting& setting) override;
78 
79  void checkRendererSwitch();
80  void doRendererSwitch();
81  void doRendererSwitch2();
82 
85  Layers::iterator baseLayer();
86 
87  // LayerListener interface
88  void updateZ(Layer& layer) override;
89 
90  Layers layers; // sorted on z
91  std::unique_ptr<VideoSystem> videoSystem;
92 
93  std::vector<VideoSystemChangeListener*> listeners; // unordered
94 
95  // fps related data
96  static const unsigned NUM_FRAME_DURATIONS = 50;
98  uint64_t frameDurationSum;
99  uint64_t prevTimeStamp;
100 
101  struct ScreenShotCmd final : Command {
102  explicit ScreenShotCmd(CommandController& commandController);
103  void execute(span<const TclObject> tokens, TclObject& result) override;
104  std::string help(const std::vector<std::string>& tokens) const override;
105  void tabCompletion(std::vector<std::string>& tokens) const override;
106  } screenShotCmd;
107 
108  struct FpsInfoTopic final : InfoTopic {
109  explicit FpsInfoTopic(InfoCommand& openMSXInfoCommand);
110  void execute(span<const TclObject> tokens,
111  TclObject& result) const override;
112  std::string help(const std::vector<std::string>& tokens) const override;
113  } fpsInfo;
114 
115  OSDGUI osdGui;
116 
117  Reactor& reactor;
118  RenderSettings renderSettings;
119  CommandConsole commandConsole;
120 
121  // the current renderer
122  RenderSettings::RendererID currentRenderer;
123 
124  bool renderFrozen;
125  bool switchInProgress;
126 };
127 
128 } // namespace openmsx
129 
130 #endif
Contains the main loop of openMSX.
Definition: Reactor.hh:64
void createVideoSystem()
Definition: Display.cc:101
Represents the output window/screen of openMSX.
Definition: Display.hh:31
std::string getWindowTitle()
Definition: Display.cc:221
void addLayer(Layer &layer)
Definition: Display.cc:375
CommandConsole & getCommandConsole()
Definition: Display.hh:46
Definition: span.hh:34
Interface for display layers.
Definition: Layer.hh:11
Display(Reactor &reactor)
Definition: Display.cc:38
RenderSettings & getRenderSettings()
Definition: Display.hh:44
A frame buffer where pixels can be written to.
OSDGUI & getOSDGUI()
Definition: Display.hh:45
CliComm & getCliComm() const
Definition: Display.cc:130
VideoSystem & getVideoSystem()
Definition: Display.cc:111
RendererID
Enumeration of Renderers known to openMSX.
void repaint()
Redraw the display.
Definition: Display.cc:326
void removeLayer(Layer &layer)
Definition: Display.cc:383
void detach(VideoSystemChangeListener &listener)
Definition: Display.cc:141
Layer * findActiveLayer() const
Definition: Display.cc:146
Video back-end system.
Definition: VideoSystem.hh:20
void repaintDelayed(uint64_t delta)
Definition: Display.cc:366
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
const Layers & getAllLayers() const
Definition: Display.hh:61
void attach(VideoSystemChangeListener &listener)
Definition: Display.cc:135
Class containing all settings for renderers.
std::vector< Layer * > Layers
Definition: Display.hh:35
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:9
OutputSurface * getOutputSurface()
Definition: Display.cc:117