VideoLayer.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "VideoLayer.hh"
  2. #include "Display.hh"
  3. #include "Reactor.hh"
  4. #include "GlobalSettings.hh"
  5. #include "BooleanSetting.hh"
  6. #include "MSXEventDistributor.hh"
  7. #include "MSXMotherBoard.hh"
  8. #include "Event.hh"
  9. #include "one_of.hh"
  10. namespace openmsx {
  11. VideoLayer::VideoLayer(MSXMotherBoard& motherBoard_,
  12. const std::string& videoSource_)
  13. : motherBoard(motherBoard_)
  14. , display(motherBoard.getReactor().getDisplay())
  15. , videoSourceSetting(motherBoard.getVideoSource())
  16. , videoSourceActivator(videoSourceSetting, videoSource_)
  17. , powerSetting(motherBoard.getReactor().getGlobalSettings().getPowerSetting())
  18. , video9000Source(0)
  19. , activeVideo9000(INACTIVE)
  20. {
  21. calcCoverage();
  22. calcZ();
  23. display.addLayer(*this);
  24. videoSourceSetting.attach(*this);
  25. powerSetting.attach(*this);
  26. motherBoard.getMSXEventDistributor().registerEventListener(*this);
  27. }
  28. VideoLayer::~VideoLayer()
  29. {
  30. motherBoard.getMSXEventDistributor().unregisterEventListener(*this);
  31. powerSetting.detach(*this);
  32. videoSourceSetting.detach(*this);
  33. display.removeLayer(*this);
  34. }
  35. int VideoLayer::getVideoSource() const
  36. {
  37. return videoSourceActivator.getID();
  38. }
  39. int VideoLayer::getVideoSourceSetting() const
  40. {
  41. return videoSourceSetting.getSource();
  42. }
  43. void VideoLayer::update(const Setting& setting)
  44. {
  45. if (&setting == &videoSourceSetting) {
  46. calcZ();
  47. } else if (&setting == &powerSetting) {
  48. calcCoverage();
  49. }
  50. }
  51. void VideoLayer::calcZ()
  52. {
  53. setZ((videoSourceSetting.getSource() == getVideoSource())
  54. ? Z_MSX_ACTIVE
  55. : Z_MSX_PASSIVE);
  56. }
  57. void VideoLayer::calcCoverage()
  58. {
  59. Coverage cov;
  60. if (!powerSetting.getBoolean() || !motherBoard.isActive()) {
  61. cov = COVER_NONE;
  62. } else {
  63. cov = COVER_FULL;
  64. }
  65. setCoverage(cov);
  66. }
  67. void VideoLayer::signalMSXEvent(const std::shared_ptr<const Event>& event,
  68. EmuTime::param /*time*/)
  69. {
  70. if (event->getType() == one_of(OPENMSX_MACHINE_ACTIVATED,
  71. OPENMSX_MACHINE_DEACTIVATED)) {
  72. calcCoverage();
  73. }
  74. }
  75. bool VideoLayer::needRender() const
  76. {
  77. // Either when this layer itself is selected or when the video9000
  78. // layer is selected and this layer is needed to render a
  79. // (superimposed) image.
  80. int current = videoSourceSetting.getSource();
  81. return (current == getVideoSource()) ||
  82. ((current == video9000Source) && (activeVideo9000 != INACTIVE));
  83. }
  84. bool VideoLayer::needRecord() const
  85. {
  86. // Either when this layer itself is selected or when the video9000
  87. // layer is selected and this layer is the front layer of a
  88. // (superimposed) image
  89. int current = videoSourceSetting.getSource();
  90. return (current == getVideoSource()) ||
  91. ((current == video9000Source) && (activeVideo9000 == ACTIVE_FRONT));
  92. }
  93. } // namespace openmsx