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