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 "InfoTopic.hh"
7#include "OSDGUI.hh"
8#include "EventListener.hh"
9#include "LayerListener.hh"
10#include "RTSchedulable.hh"
11#include "Observer.hh"
12#include "CircularBuffer.hh"
13#include <memory>
14#include <vector>
15#include <cstdint>
16
17namespace openmsx {
18
19class Layer;
20class Reactor;
21class VideoSystem;
22class CliComm;
23class VideoSystemChangeListener;
24class Setting;
25class OutputSurface;
26
30class Display final : public EventListener, private Observer<Setting>
31 , private LayerListener, private RTSchedulable
32{
33public:
34 using Layers = std::vector<Layer*>;
35
36 explicit Display(Reactor& reactor);
37 ~Display();
38
39 void createVideoSystem();
40 [[nodiscard]] VideoSystem& getVideoSystem();
41
42 [[nodiscard]] CliComm& getCliComm() const;
43 [[nodiscard]] RenderSettings& getRenderSettings() { return renderSettings; }
44 [[nodiscard]] OSDGUI& getOSDGUI() { return osdGui; }
45
49 void repaint();
50 void repaintDelayed(uint64_t delta);
51 void repaintImpl();
52 void repaintImpl(OutputSurface& surface);
53
54 void addLayer(Layer& layer);
55 void removeLayer(Layer& layer);
56
57 void attach(VideoSystemChangeListener& listener);
58 void detach(VideoSystemChangeListener& listener);
59
60 [[nodiscard]] Layer* findActiveLayer() const;
61 [[nodiscard]] const Layers& getAllLayers() const { return layers; }
62
63 [[nodiscard]] OutputSurface* getOutputSurface();
64
65 [[nodiscard]] std::string getWindowTitle();
66
69 [[nodiscard]] gl::ivec2 getWindowPosition();
71 // should only be called from VisibleSurface
73 [[nodiscard]] gl::ivec2 retrieveWindowPosition();
74
75private:
76 void resetVideoSystem();
77
78 // EventListener interface
79 int signalEvent(const Event& event) override;
80
81 // RTSchedulable
82 void executeRT() override;
83
84 // Observer<Setting> interface
85 void update(const Setting& setting) noexcept override;
86
87 void checkRendererSwitch();
88 void doRendererSwitch();
89 void doRendererSwitch2();
90
93 [[nodiscard]] Layers::iterator baseLayer();
94
95 // LayerListener interface
96 void updateZ(Layer& layer) noexcept override;
97
98private:
99 Layers layers; // sorted on z
100 std::unique_ptr<VideoSystem> videoSystem;
101
102 std::vector<VideoSystemChangeListener*> listeners; // unordered
103
104 // fps related data
105 static constexpr unsigned NUM_FRAME_DURATIONS = 50;
107 uint64_t frameDurationSum;
108 uint64_t prevTimeStamp;
109
110 struct ScreenShotCmd final : Command {
111 explicit ScreenShotCmd(CommandController& commandController);
112 void execute(std::span<const TclObject> tokens, TclObject& result) override;
113 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
114 void tabCompletion(std::vector<std::string>& tokens) const override;
115 } screenShotCmd;
116
117 struct FpsInfoTopic final : InfoTopic {
118 explicit FpsInfoTopic(InfoCommand& openMSXInfoCommand);
119 void execute(std::span<const TclObject> tokens,
120 TclObject& result) const override;
121 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
122 } fpsInfo;
123
124 OSDGUI osdGui;
125
126 Reactor& reactor;
127 RenderSettings renderSettings;
128
129 // the current renderer
131
132 bool renderFrozen = false;
133 bool switchInProgress = false;
134};
135
136} // namespace openmsx
137
138#endif
BaseSetting * setting
Represents the output window/screen of openMSX.
Definition Display.hh:32
std::string getWindowTitle()
Definition Display.cc:212
void repaint()
Redraw the display.
Definition Display.cc:372
void repaintImpl()
Definition Display.cc:328
gl::ivec2 retrieveWindowPosition()
Definition Display.cc:248
void detach(VideoSystemChangeListener &listener)
Definition Display.cc:128
OSDGUI & getOSDGUI()
Definition Display.hh:44
CliComm & getCliComm() const
Definition Display.cc:117
void storeWindowPosition(gl::ivec2 pos)
Definition Display.cc:243
std::vector< Layer * > Layers
Definition Display.hh:34
void removeLayer(Layer &layer)
Definition Display.cc:396
VideoSystem & getVideoSystem()
Definition Display.cc:98
RenderSettings & getRenderSettings()
Definition Display.hh:43
void attach(VideoSystemChangeListener &listener)
Definition Display.cc:122
void createVideoSystem()
Definition Display.cc:88
void repaintDelayed(uint64_t delta)
Definition Display.cc:379
void setWindowPosition(gl::ivec2 pos)
Definition Display.cc:237
Layer * findActiveLayer() const
Definition Display.cc:133
OutputSurface * getOutputSurface()
Definition Display.cc:104
const Layers & getAllLayers() const
Definition Display.hh:61
gl::ivec2 getWindowPosition()
Get/set x,y coordinates of top-left window corner.
Definition Display.cc:229
void addLayer(Layer &layer)
Definition Display.cc:388
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:72
Class containing all settings for renderers.
RendererID
Enumeration of Renderers known to openMSX.
Video back-end system.
This file implemented 3 utility functions:
Definition Autofire.cc:9
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
Definition Event.hh:452