openMSX
VideoLayer.cc
Go to the documentation of this file.
1 #include "VideoLayer.hh"
2 #include "RenderSettings.hh"
3 #include "Display.hh"
4 #include "Reactor.hh"
5 #include "GlobalSettings.hh"
6 #include "BooleanSetting.hh"
7 #include "VideoSourceSetting.hh"
8 #include "MSXEventDistributor.hh"
9 #include "MSXMotherBoard.hh"
10 #include "Event.hh"
11 #include "openmsx.hh"
12 #include "memory.hh"
13 #include <cassert>
14 
15 namespace openmsx {
16 
18  const std::string& videoSource_)
19  : motherBoard(motherBoard_)
20  , display(motherBoard.getReactor().getDisplay())
21  , renderSettings(display.getRenderSettings())
22  , videoSourceSetting(motherBoard.getVideoSource())
23  , videoSourceActivator(make_unique<VideoSourceActivator>(
24  videoSourceSetting, videoSource_))
25  , powerSetting(motherBoard.getReactor().getGlobalSettings().getPowerSetting())
26  , video9000Source(0)
27  , activeVideo9000(INACTIVE)
28 {
29  calcCoverage();
30  calcZ();
31  display.addLayer(*this);
32 
33  videoSourceSetting.attach(*this);
34  powerSetting.attach(*this);
35  motherBoard.getMSXEventDistributor().registerEventListener(*this);
36 }
37 
39 {
40  PRT_DEBUG("Destructing VideoLayer...");
42  powerSetting.detach(*this);
43  videoSourceSetting.detach(*this);
44 
45  display.removeLayer(*this);
46  PRT_DEBUG("Destructing VideoLayer... DONE!");
47 }
48 
50 {
51  return videoSourceActivator->getID();
52 }
53 
54 void VideoLayer::update(const Setting& setting)
55 {
56  if (&setting == &videoSourceSetting) {
57  calcZ();
58  } else if (&setting == &powerSetting) {
59  calcCoverage();
60  }
61 }
62 
63 void VideoLayer::calcZ()
64 {
65  setZ((videoSourceSetting.getValue() == getVideoSource())
66  ? Z_MSX_ACTIVE
67  : Z_MSX_PASSIVE);
68 }
69 
70 void VideoLayer::calcCoverage()
71 {
72  Coverage coverage;
73 
74  if (!powerSetting.getValue() || !motherBoard.isActive()) {
75  coverage = COVER_NONE;
76  } else {
77  coverage = COVER_FULL;
78  }
79 
80  setCoverage(coverage);
81 }
82 
83 void VideoLayer::signalEvent(const std::shared_ptr<const Event>& event,
84  EmuTime::param /*time*/)
85 {
86  if ((event->getType() == OPENMSX_MACHINE_ACTIVATED) ||
87  (event->getType() == OPENMSX_MACHINE_DEACTIVATED)) {
88  calcCoverage();
89  }
90 }
91 
93 {
94  // Either when this layer itself is selected or when the video9000
95  // layer is selected and this layer is needed to render a
96  // (superimposed) image.
97  int current = videoSourceSetting.getValue();
98  return (current == getVideoSource()) ||
99  ((current == video9000Source) && (activeVideo9000 != INACTIVE));
100 }
101 
103 {
104  // Either when this layer itself is selected or when the video9000
105  // layer is selected and this layer is the front layer of a
106  // (superimposed) image
107  int current = videoSourceSetting.getValue();
108  return (current == getVideoSource()) ||
109  ((current == video9000Source) && (activeVideo9000 == ACTIVE_FRONT));
110 }
111 
112 } // namespace openmsx