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();
41  [[nodiscard]] VideoSystem& getVideoSystem();
42 
43  [[nodiscard]] CliComm& getCliComm() const;
44  [[nodiscard]] RenderSettings& getRenderSettings() { return renderSettings; }
45  [[nodiscard]] OSDGUI& getOSDGUI() { return osdGui; }
46  [[nodiscard]] CommandConsole& getCommandConsole() { return commandConsole; }
47 
51  void repaint();
52  void repaintDelayed(uint64_t delta);
53  void repaintImpl();
54  void repaintImpl(OutputSurface& surface);
55 
56  void addLayer(Layer& layer);
57  void removeLayer(Layer& layer);
58 
59  void attach(VideoSystemChangeListener& listener);
60  void detach(VideoSystemChangeListener& listener);
61 
62  [[nodiscard]] Layer* findActiveLayer() const;
63  [[nodiscard]] const Layers& getAllLayers() const { return layers; }
64 
65  [[nodiscard]] OutputSurface* getOutputSurface();
66 
67  [[nodiscard]] std::string getWindowTitle();
68 
69 private:
70  void resetVideoSystem();
71 
72  // EventListener interface
73  int signalEvent(const std::shared_ptr<const Event>& event) noexcept override;
74 
75  // RTSchedulable
76  void executeRT() override;
77 
78  // Observer<Setting> interface
79  void update(const Setting& setting) noexcept override;
80 
81  void checkRendererSwitch();
82  void doRendererSwitch();
83  void doRendererSwitch2();
84 
87  [[nodiscard]] Layers::iterator baseLayer();
88 
89  // LayerListener interface
90  void updateZ(Layer& layer) noexcept override;
91 
92 private:
93  Layers layers; // sorted on z
94  std::unique_ptr<VideoSystem> videoSystem;
95 
96  std::vector<VideoSystemChangeListener*> listeners; // unordered
97 
98  // fps related data
99  static constexpr unsigned NUM_FRAME_DURATIONS = 50;
101  uint64_t frameDurationSum;
102  uint64_t prevTimeStamp;
103 
104  struct ScreenShotCmd final : Command {
105  explicit ScreenShotCmd(CommandController& commandController);
106  void execute(span<const TclObject> tokens, TclObject& result) override;
107  [[nodiscard]] std::string help(const std::vector<std::string>& tokens) const override;
108  void tabCompletion(std::vector<std::string>& tokens) const override;
109  } screenShotCmd;
110 
111  struct FpsInfoTopic final : InfoTopic {
112  explicit FpsInfoTopic(InfoCommand& openMSXInfoCommand);
113  void execute(span<const TclObject> tokens,
114  TclObject& result) const override;
115  [[nodiscard]] std::string help(const std::vector<std::string>& tokens) const override;
116  } fpsInfo;
117 
118  OSDGUI osdGui;
119 
120  Reactor& reactor;
121  RenderSettings renderSettings;
122  CommandConsole commandConsole;
123 
124  // the current renderer
125  RenderSettings::RendererID currentRenderer;
126 
127  bool renderFrozen;
128  bool switchInProgress;
129 };
130 
131 } // namespace openmsx
132 
133 #endif
Represents the output window/screen of openMSX.
Definition: Display.hh:33
std::string getWindowTitle()
Definition: Display.cc:223
void repaint()
Redraw the display.
Definition: Display.cc:368
void repaintImpl()
Definition: Display.cc:328
void detach(VideoSystemChangeListener &listener)
Definition: Display.cc:143
const Layers & getAllLayers() const
Definition: Display.hh:63
CliComm & getCliComm() const
Definition: Display.cc:132
std::vector< Layer * > Layers
Definition: Display.hh:35
void removeLayer(Layer &layer)
Definition: Display.cc:392
VideoSystem & getVideoSystem()
Definition: Display.cc:113
Display(Reactor &reactor)
Definition: Display.cc:40
void attach(VideoSystemChangeListener &listener)
Definition: Display.cc:137
void createVideoSystem()
Definition: Display.cc:103
RenderSettings & getRenderSettings()
Definition: Display.hh:44
void repaintDelayed(uint64_t delta)
Definition: Display.cc:375
Layer * findActiveLayer() const
Definition: Display.cc:148
OutputSurface * getOutputSurface()
Definition: Display.cc:119
OSDGUI & getOSDGUI()
Definition: Display.hh:45
CommandConsole & getCommandConsole()
Definition: Display.hh:46
void addLayer(Layer &layer)
Definition: Display.cc:384
Interface for display layers.
Definition: Layer.hh:12
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:10
A frame buffer where pixels can be written to.
Contains the main loop of openMSX.
Definition: Reactor.hh:67
Class containing all settings for renderers.
RendererID
Enumeration of Renderers known to openMSX.
Video back-end system.
Definition: VideoSystem.hh:23
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:9