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 
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  Layer* findActiveLayer() const;
62  const Layers& getAllLayers() const { return layers; }
63 
65 
66  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  Layers::iterator baseLayer();
87 
88  // LayerListener interface
89  void updateZ(Layer& layer) override;
90 
91  Layers layers; // sorted on z
92  std::unique_ptr<VideoSystem> videoSystem;
93 
94  std::vector<VideoSystemChangeListener*> listeners; // unordered
95 
96  // fps related data
97  static constexpr unsigned NUM_FRAME_DURATIONS = 50;
99  uint64_t frameDurationSum;
100  uint64_t prevTimeStamp;
101 
102  struct ScreenShotCmd final : Command {
103  explicit ScreenShotCmd(CommandController& commandController);
104  void execute(span<const TclObject> tokens, TclObject& result) override;
105  std::string help(const std::vector<std::string>& tokens) const override;
106  void tabCompletion(std::vector<std::string>& tokens) const override;
107  } screenShotCmd;
108 
109  struct FpsInfoTopic final : InfoTopic {
110  explicit FpsInfoTopic(InfoCommand& openMSXInfoCommand);
111  void execute(span<const TclObject> tokens,
112  TclObject& result) const override;
113  std::string help(const std::vector<std::string>& tokens) const override;
114  } fpsInfo;
115 
116  OSDGUI osdGui;
117 
118  Reactor& reactor;
119  RenderSettings renderSettings;
120  CommandConsole commandConsole;
121 
122  // the current renderer
123  RenderSettings::RendererID currentRenderer;
124 
125  bool renderFrozen;
126  bool switchInProgress;
127 };
128 
129 } // namespace openmsx
130 
131 #endif
openmsx::CircularBuffer< uint64_t, NUM_FRAME_DURATIONS >
openmsx::LayerListener
Definition: LayerListener.hh:8
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:10
openmsx::CommandController
Definition: CommandController.hh:17
openmsx::RenderSettings
Class containing all settings for renderers.
Definition: RenderSettings.hh:21
openmsx::Display::~Display
~Display()
Definition: Display.cc:77
OSDGUI.hh
openmsx::Display::attach
void attach(VideoSystemChangeListener &listener)
Definition: Display.cc:136
EventListener.hh
RTSchedulable.hh
CommandConsole.hh
openmsx::VideoSystem
Video back-end system.
Definition: VideoSystem.hh:20
openmsx::Display::getOutputSurface
OutputSurface * getOutputSurface()
Definition: Display.cc:118
openmsx::Setting
Definition: Setting.hh:119
openmsx::Display::repaintDelayed
void repaintDelayed(uint64_t delta)
Definition: Display.cc:367
span
Definition: span.hh:34
openmsx::Reactor
Contains the main loop of openMSX.
Definition: Reactor.hh:66
openmsx::OSDGUI
Definition: OSDGUI.hh:13
openmsx::RenderSettings::RendererID
RendererID
Enumeration of Renderers known to openMSX.
Definition: RenderSettings.hh:27
Observer.hh
openmsx::Display::getVideoSystem
VideoSystem & getVideoSystem()
Definition: Display.cc:112
openmsx::Display::getWindowTitle
std::string getWindowTitle()
Definition: Display.cc:222
openmsx::Layer
Interface for display layers.
Definition: Layer.hh:11
openmsx::Display::createVideoSystem
void createVideoSystem()
Definition: Display.cc:102
RenderSettings.hh
openmsx::EventListener
Definition: EventListener.hh:10
openmsx::Display::findActiveLayer
Layer * findActiveLayer() const
Definition: Display.cc:147
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:31
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:19
InfoTopic.hh
openmsx::Command
Definition: Command.hh:40
openmsx::CliComm
Definition: CliComm.hh:10
openmsx::Display::getCommandConsole
CommandConsole & getCommandConsole()
Definition: Display.hh:46
openmsx::Display::repaint
void repaint()
Redraw the display.
Definition: Display.cc:327
openmsx::TclObject
Definition: TclObject.hh:21
openmsx::Display::Display
Display(Reactor &reactor)
Definition: Display.cc:39
openmsx::Display::addLayer
void addLayer(Layer &layer)
Definition: Display.cc:376
openmsx::Display::getCliComm
CliComm & getCliComm() const
Definition: Display.cc:131
openmsx::VideoSystemChangeListener
Definition: VideoSystemChangeListener.hh:6
LayerListener.hh
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::Observer
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:9
openmsx::Display::removeLayer
void removeLayer(Layer &layer)
Definition: Display.cc:384
openmsx::CommandConsole
Definition: CommandConsole.hh:64
openmsx::Display::detach
void detach(VideoSystemChangeListener &listener)
Definition: Display.cc:142