Display.hh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef DISPLAY_HH
  2. #define DISPLAY_HH
  3. #include "RenderSettings.hh"
  4. #include "Command.hh"
  5. #include "CommandConsole.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. namespace openmsx {
  17. class Layer;
  18. class Reactor;
  19. class VideoSystem;
  20. class CliComm;
  21. class VideoSystemChangeListener;
  22. class Setting;
  23. class OutputSurface;
  24. /** Represents the output window/screen of openMSX.
  25. * A display contains several layers.
  26. */
  27. class Display final : public EventListener, private Observer<Setting>
  28. , private LayerListener, private RTSchedulable
  29. {
  30. public:
  31. using Layers = std::vector<Layer*>;
  32. explicit Display(Reactor& reactor);
  33. ~Display();
  34. void createVideoSystem();
  35. VideoSystem& getVideoSystem();
  36. CliComm& getCliComm() const;
  37. RenderSettings& getRenderSettings() { return renderSettings; }
  38. OSDGUI& getOSDGUI() { return osdGui; }
  39. CommandConsole& getCommandConsole() { return commandConsole; }
  40. /** Redraw the display.
  41. * repaint() should only be called from the VideoSystem.
  42. */
  43. void repaint();
  44. void repaint(OutputSurface& surface);
  45. void repaintDelayed(uint64_t delta);
  46. void addLayer(Layer& layer);
  47. void removeLayer(Layer& layer);
  48. void attach(VideoSystemChangeListener& listener);
  49. void detach(VideoSystemChangeListener& listener);
  50. Layer* findActiveLayer() const;
  51. const Layers& getAllLayers() const { return layers; }
  52. OutputSurface* getOutputSurface();
  53. std::string getWindowTitle();
  54. private:
  55. void resetVideoSystem();
  56. // EventListener interface
  57. int signalEvent(const std::shared_ptr<const Event>& event) override;
  58. // RTSchedulable
  59. void executeRT() override;
  60. // Observer<Setting> interface
  61. void update(const Setting& setting) override;
  62. void checkRendererSwitch();
  63. void doRendererSwitch();
  64. void doRendererSwitch2();
  65. /** Find frontmost opaque layer.
  66. */
  67. Layers::iterator baseLayer();
  68. // LayerListener interface
  69. void updateZ(Layer& layer) override;
  70. Layers layers; // sorted on z
  71. std::unique_ptr<VideoSystem> videoSystem;
  72. std::vector<VideoSystemChangeListener*> listeners; // unordered
  73. // fps related data
  74. static constexpr unsigned NUM_FRAME_DURATIONS = 50;
  75. CircularBuffer<uint64_t, NUM_FRAME_DURATIONS> frameDurations;
  76. uint64_t frameDurationSum;
  77. uint64_t prevTimeStamp;
  78. struct ScreenShotCmd final : Command {
  79. explicit ScreenShotCmd(CommandController& commandController);
  80. void execute(span<const TclObject> tokens, TclObject& result) override;
  81. std::string help(const std::vector<std::string>& tokens) const override;
  82. void tabCompletion(std::vector<std::string>& tokens) const override;
  83. } screenShotCmd;
  84. struct FpsInfoTopic final : InfoTopic {
  85. explicit FpsInfoTopic(InfoCommand& openMSXInfoCommand);
  86. void execute(span<const TclObject> tokens,
  87. TclObject& result) const override;
  88. std::string help(const std::vector<std::string>& tokens) const override;
  89. } fpsInfo;
  90. OSDGUI osdGui;
  91. Reactor& reactor;
  92. RenderSettings renderSettings;
  93. CommandConsole commandConsole;
  94. // the current renderer
  95. RenderSettings::RendererID currentRenderer;
  96. bool renderFrozen;
  97. bool switchInProgress;
  98. };
  99. } // namespace openmsx
  100. #endif