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
79 // Get the latest fps value
80 [[nodiscard]] float getFps() const;
81
82private:
83 void resetVideoSystem();
84
85 // EventListener interface
86 bool signalEvent(const Event& event) override;
87
88 // RTSchedulable
89 void executeRT() override;
90
91 // Observer<Setting> interface
92 void update(const Setting& setting) noexcept override;
93
94 void checkRendererSwitch();
95 void doRendererSwitch();
96 void doRendererSwitch2();
97
100 [[nodiscard]] Layers::iterator baseLayer();
101
102 // LayerListener interface
103 void updateZ(Layer& layer) noexcept override;
104
105private:
106 Layers layers; // sorted on z
107 std::unique_ptr<VideoSystem> videoSystem;
108
109 std::vector<VideoSystemChangeListener*> listeners; // unordered
110
111 // fps related data
112 static constexpr unsigned NUM_FRAME_DURATIONS = 50;
114 uint64_t frameDurationSum;
115 uint64_t prevTimeStamp;
116
117 struct ScreenShotCmd final : Command {
118 explicit ScreenShotCmd(CommandController& commandController);
119 void execute(std::span<const TclObject> tokens, TclObject& result) override;
120 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
121 void tabCompletion(std::vector<std::string>& tokens) const override;
122 } screenShotCmd;
123
124 struct FpsInfoTopic final : InfoTopic {
125 explicit FpsInfoTopic(InfoCommand& openMSXInfoCommand);
126 void execute(std::span<const TclObject> tokens,
127 TclObject& result) const override;
128 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
129 } fpsInfo;
130
131 OSDGUI osdGui;
132
133 Reactor& reactor;
134 RenderSettings renderSettings;
135
136 // the current renderer
138
139 bool renderFrozen = false;
140 bool switchInProgress = false;
141};
142
143} // namespace openmsx
144
145#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:367
void repaintImpl()
Definition Display.cc:323
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:391
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
float getFps() const
Definition Display.cc:246
void repaintDelayed(uint64_t delta)
Definition Display.cc:374
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:383
Interface for display layers.
Definition Layer.hh:14
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:75
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:445