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 "RTSchedulable.hh"
10#include "Observer.hh"
11#include "CircularBuffer.hh"
12#include <memory>
13#include <vector>
14#include <cstdint>
15
16namespace openmsx {
17
18class Layer;
19class Reactor;
20class VideoSystem;
21class CliComm;
22class VideoSystemChangeListener;
23class Setting;
24class OutputSurface;
25
29class Display final : public EventListener, private Observer<Setting>
30 , private RTSchedulable
31{
32public:
33 static constexpr std::string_view SCREENSHOT_DIR = "screenshots";
34 static constexpr std::string_view SCREENSHOT_EXTENSION = ".png";
35
36public:
37 using Layers = std::vector<Layer*>;
38
39 explicit Display(Reactor& reactor);
40 ~Display();
41
42 void createVideoSystem();
43 [[nodiscard]] VideoSystem& getVideoSystem();
44
45 [[nodiscard]] CliComm& getCliComm() const;
46 [[nodiscard]] RenderSettings& getRenderSettings() { return renderSettings; }
47 [[nodiscard]] OSDGUI& getOSDGUI() { return osdGui; }
48
52 void repaint();
53 void repaintDelayed(uint64_t delta);
54 void repaintImpl();
55 void repaintImpl(OutputSurface& surface);
56
57 void addLayer(Layer& layer);
58 void removeLayer(Layer& layer);
59 void updateZ(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 [[nodiscard]] gl::ivec2 getWindowSize() const;
80
81 // Get the latest fps value
82 [[nodiscard]] float getFps() const;
83
84private:
85 void resetVideoSystem();
86
87 // EventListener interface
88 bool signalEvent(const Event& event) override;
89
90 // RTSchedulable
91 void executeRT() override;
92
93 // Observer<Setting> interface
94 void update(const Setting& setting) noexcept override;
95
96 void checkRendererSwitch();
97 void doRendererSwitch();
98 void doRendererSwitch2();
99
102 [[nodiscard]] Layers::iterator baseLayer();
103
104private:
105 Layers layers; // sorted on z
106 std::unique_ptr<VideoSystem> videoSystem;
107
108 std::vector<VideoSystemChangeListener*> listeners; // unordered
109
110 // fps related data
111 static constexpr unsigned NUM_FRAME_DURATIONS = 50;
113 uint64_t frameDurationSum;
114 uint64_t prevTimeStamp;
115
116 struct ScreenShotCmd final : Command {
117 explicit ScreenShotCmd(CommandController& commandController);
118 void execute(std::span<const TclObject> tokens, TclObject& result) override;
119 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
120 void tabCompletion(std::vector<std::string>& tokens) const override;
121 } screenShotCmd;
122
123 struct FpsInfoTopic final : InfoTopic {
124 explicit FpsInfoTopic(InfoCommand& openMSXInfoCommand);
125 void execute(std::span<const TclObject> tokens,
126 TclObject& result) const override;
127 [[nodiscard]] std::string help(std::span<const TclObject> tokens) const override;
128 } fpsInfo;
129
130 OSDGUI osdGui;
131
132 Reactor& reactor;
133 RenderSettings renderSettings;
134
135 // the current renderer
137
138 bool renderFrozen = false;
139 bool switchInProgress = false;
140};
141
142} // namespace openmsx
143
144#endif
BaseSetting * setting
Represents the output window/screen of openMSX.
Definition Display.hh:31
std::string getWindowTitle()
Definition Display.cc:205
void repaint()
Redraw the display.
Definition Display.cc:373
void repaintImpl()
Definition Display.cc:329
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:34
OSDGUI & getOSDGUI()
Definition Display.hh:47
CliComm & getCliComm() const
Definition Display.cc:110
void storeWindowPosition(gl::ivec2 pos)
Definition Display.cc:236
void updateZ(Layer &layer)
Definition Display.cc:402
std::vector< Layer * > Layers
Definition Display.hh:37
void removeLayer(Layer &layer)
Definition Display.cc:397
VideoSystem & getVideoSystem()
Definition Display.cc:91
RenderSettings & getRenderSettings()
Definition Display.hh:46
void attach(VideoSystemChangeListener &listener)
Definition Display.cc:115
void createVideoSystem()
Definition Display.cc:81
static constexpr std::string_view SCREENSHOT_DIR
Definition Display.hh:33
gl::ivec2 getWindowSize() const
Definition Display.cc:246
float getFps() const
Definition Display.cc:252
void repaintDelayed(uint64_t delta)
Definition Display.cc:380
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:389
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