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 static constexpr std::string_view SCREENSHOT_DIR = "screenshots";
35 static constexpr std::string_view SCREENSHOT_EXTENSION = ".png";
36
37public:
38 using Layers = std::vector<Layer*>;
39
40 explicit Display(Reactor& reactor);
41 ~Display();
42
43 void createVideoSystem();
44 [[nodiscard]] VideoSystem& getVideoSystem();
45
46 [[nodiscard]] CliComm& getCliComm() const;
47 [[nodiscard]] RenderSettings& getRenderSettings() { return renderSettings; }
48 [[nodiscard]] OSDGUI& getOSDGUI() { return osdGui; }
49
53 void repaint();
54 void repaintDelayed(uint64_t delta);
55 void repaintImpl();
56 void repaintImpl(OutputSurface& surface);
57
58 void addLayer(Layer& layer);
59 void removeLayer(Layer& layer);
60
61 void attach(VideoSystemChangeListener& listener);
62 void detach(VideoSystemChangeListener& listener);
63
64 [[nodiscard]] Layer* findActiveLayer() const;
65 [[nodiscard]] const Layers& getAllLayers() const { return layers; }
66
67 [[nodiscard]] OutputSurface* getOutputSurface();
68
69 [[nodiscard]] std::string getWindowTitle();
70
73 [[nodiscard]] gl::ivec2 getWindowPosition();
75 // should only be called from VisibleSurface
77 [[nodiscard]] gl::ivec2 retrieveWindowPosition();
78
79private:
80 void resetVideoSystem();
81
82 // EventListener interface
83 int signalEvent(const Event& event) override;
84
85 // RTSchedulable
86 void executeRT() override;
87
88 // Observer<Setting> interface
89 void update(const Setting& setting) noexcept override;
90
91 void checkRendererSwitch();
92 void doRendererSwitch();
93 void doRendererSwitch2();
94
97 [[nodiscard]] Layers::iterator baseLayer();
98
99 // LayerListener interface
100 void updateZ(Layer& layer) noexcept override;
101
102private:
103 Layers layers; // sorted on z
104 std::unique_ptr<VideoSystem> videoSystem;
105
106 std::vector<VideoSystemChangeListener*> listeners; // unordered
107
108 // fps related data
109 static constexpr unsigned NUM_FRAME_DURATIONS = 50;
111 uint64_t frameDurationSum;
112 uint64_t prevTimeStamp;
113
114 struct ScreenShotCmd final : Command {
115 explicit ScreenShotCmd(CommandController& commandController);
116 void execute(std::span<const TclObject> tokens, TclObject& result) override;
117 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
118 void tabCompletion(std::vector<std::string>& tokens) const override;
119 } screenShotCmd;
120
121 struct FpsInfoTopic final : InfoTopic {
122 explicit FpsInfoTopic(InfoCommand& openMSXInfoCommand);
123 void execute(std::span<const TclObject> tokens,
124 TclObject& result) const override;
125 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
126 } fpsInfo;
127
128 OSDGUI osdGui;
129
130 Reactor& reactor;
131 RenderSettings renderSettings;
132
133 // the current renderer
135
136 bool renderFrozen = false;
137 bool switchInProgress = false;
138};
139
140} // namespace openmsx
141
142#endif
BaseSetting * setting
Represents the output window/screen of openMSX.
Definition Display.hh:32
std::string getWindowTitle()
Definition Display.cc:205
void repaint()
Redraw the display.
Definition Display.cc:365
void repaintImpl()
Definition Display.cc:321
gl::ivec2 retrieveWindowPosition()
Definition Display.cc:241
void detach(VideoSystemChangeListener &listener)
Definition Display.cc:121
static constexpr std::string_view SCREENSHOT_EXTENSION
Definition Display.hh:35
OSDGUI & getOSDGUI()
Definition Display.hh:48
CliComm & getCliComm() const
Definition Display.cc:110
void storeWindowPosition(gl::ivec2 pos)
Definition Display.cc:236
std::vector< Layer * > Layers
Definition Display.hh:38
void removeLayer(Layer &layer)
Definition Display.cc:389
VideoSystem & getVideoSystem()
Definition Display.cc:91
RenderSettings & getRenderSettings()
Definition Display.hh:47
void attach(VideoSystemChangeListener &listener)
Definition Display.cc:115
void createVideoSystem()
Definition Display.cc:81
static constexpr std::string_view SCREENSHOT_DIR
Definition Display.hh:34
void repaintDelayed(uint64_t delta)
Definition Display.cc:372
void setWindowPosition(gl::ivec2 pos)
Definition Display.cc:230
Layer * findActiveLayer() const
Definition Display.cc:126
OutputSurface * getOutputSurface()
Definition Display.cc:97
const Layers & getAllLayers() const
Definition Display.hh:65
gl::ivec2 getWindowPosition()
Get/set x,y coordinates of top-left window corner.
Definition Display.cc:222
void addLayer(Layer &layer)
Definition Display.cc:381
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:74
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:11
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, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
Definition Event.hh:446