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
18namespace openmsx {
19
20class Layer;
21class Reactor;
22class VideoSystem;
23class CliComm;
24class VideoSystemChangeListener;
25class Setting;
26class OutputSurface;
27
31class Display final : public EventListener, private Observer<Setting>
32 , private LayerListener, private RTSchedulable
33{
34public:
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
69private:
70 void resetVideoSystem();
71
72 // EventListener interface
73 int signalEvent(const Event& event) 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
92private:
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(std::span<const TclObject> tokens, TclObject& result) override;
107 [[nodiscard]] std::string help(std::span<const TclObject> 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(std::span<const TclObject> tokens,
114 TclObject& result) const override;
115 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
116 } fpsInfo;
117
118 OSDGUI osdGui;
119
120 Reactor& reactor;
121 RenderSettings renderSettings;
122 CommandConsole commandConsole;
123
124 // the current renderer
126
127 bool renderFrozen = false;
128 bool switchInProgress = false;
129};
130
131} // namespace openmsx
132
133#endif
BaseSetting * setting
Definition: Interpreter.cc:28
Represents the output window/screen of openMSX.
Definition: Display.hh:33
std::string getWindowTitle()
Definition: Display.cc:220
void repaint()
Redraw the display.
Definition: Display.cc:364
void repaintImpl()
Definition: Display.cc:324
void detach(VideoSystemChangeListener &listener)
Definition: Display.cc:137
OSDGUI & getOSDGUI()
Definition: Display.hh:45
CliComm & getCliComm() const
Definition: Display.cc:126
std::vector< Layer * > Layers
Definition: Display.hh:35
void removeLayer(Layer &layer)
Definition: Display.cc:388
VideoSystem & getVideoSystem()
Definition: Display.cc:107
Display(Reactor &reactor)
Definition: Display.cc:37
RenderSettings & getRenderSettings()
Definition: Display.hh:44
void attach(VideoSystemChangeListener &listener)
Definition: Display.cc:131
void createVideoSystem()
Definition: Display.cc:97
void repaintDelayed(uint64_t delta)
Definition: Display.cc:371
Layer * findActiveLayer() const
Definition: Display.cc:142
CommandConsole & getCommandConsole()
Definition: Display.hh:46
OutputSurface * getOutputSurface()
Definition: Display.cc:113
const Layers & getAllLayers() const
Definition: Display.hh:63
void addLayer(Layer &layer)
Definition: Display.cc:380
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:68
Class containing all settings for renderers.
RendererID
Enumeration of Renderers known to openMSX.
Video back-end system.
Definition: VideoSystem.hh:23
This file implemented 3 utility functions:
Definition: Autofire.cc:9