| 1 |
#include "VideoLayer.hh" |
| 2 |
|
| 3 |
#include "Display.hh" |
| 4 |
|
| 5 |
#include "BooleanSetting.hh" |
| 6 |
#include "Event.hh" |
| 7 |
#include "GlobalSettings.hh" |
| 8 |
#include "MSXEventDistributor.hh" |
| 9 |
#include "MSXMotherBoard.hh" |
| 10 |
#include "Reactor.hh" |
| 11 |
|
| 12 |
#include "one_of.hh" |
| 13 |
|
| 14 |
namespace openmsx { |
| 15 |
|
| 16 |
VideoLayer::VideoLayer(MSXMotherBoard& motherBoard_, |
| 17 |
const std::string& videoSource_) |
| 18 |
: Layer(Layer::Coverage::NONE, Layer::ZIndex::BACKGROUND) |
| 19 |
, motherBoard(motherBoard_) |
| 20 |
, display(motherBoard.getReactor().getDisplay()) |
| 21 |
, videoSourceSetting(motherBoard.getVideoSource()) |
| 22 |
, videoSourceActivator(videoSourceSetting, videoSource_) |
| 23 |
, powerSetting(motherBoard.getReactor().getGlobalSettings().getPowerSetting()) |
| 24 |
{ |
| 25 |
calcCoverage(); |
| 26 |
calcZ(); |
| 27 |
display.addLayer(*this); |
| 28 |
|
| 29 |
videoSourceSetting.attach(*this); |
| 30 |
powerSetting.attach(*this); |
| 31 |
motherBoard.getMSXEventDistributor().registerEventListener(*this); |
| 32 |
} |
| 33 |
|
| 34 |
VideoLayer::~VideoLayer() |
| 35 |
{ |
| 36 |
motherBoard.getMSXEventDistributor().unregisterEventListener(*this); |
| 37 |
powerSetting.detach(*this); |
| 38 |
videoSourceSetting.detach(*this); |
| 39 |
|
| 40 |
display.removeLayer(*this); |
| 41 |
} |
| 42 |
|
| 43 |
int VideoLayer::getVideoSource() const |
| 44 |
{ |
| 45 |
return videoSourceActivator.getID(); |
| 46 |
} |
| 47 |
int VideoLayer::getVideoSourceSetting() const |
| 48 |
{ |
| 49 |
return videoSourceSetting.getSource(); |
| 50 |
} |
| 51 |
|
| 52 |
void VideoLayer::update(const Setting& setting) noexcept |
| 53 |
{ |
| 54 |
if (&setting == &videoSourceSetting) { |
| 55 |
calcZ(); |
| 56 |
} else if (&setting == &powerSetting) { |
| 57 |
calcCoverage(); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
void VideoLayer::calcZ() |
| 62 |
{ |
| 63 |
setZ((videoSourceSetting.getSource() == getVideoSource()) |
| 64 |
? ZIndex::MSX_ACTIVE |
| 65 |
: ZIndex::MSX_PASSIVE); |
| 66 |
} |
| 67 |
|
| 68 |
void VideoLayer::calcCoverage() |
| 69 |
{ |
| 70 |
auto cov = (!powerSetting.getBoolean() || !motherBoard.isActive()) |
| 71 |
? Coverage::NONE |
| 72 |
: Coverage::FULL; |
| 73 |
setCoverage(cov); |
| 74 |
} |
| 75 |
|
| 76 |
void VideoLayer::signalMSXEvent(const Event& event, |
| 77 |
EmuTime ) noexcept |
| 78 |
{ |
| 79 |
if (getType(event) == one_of(EventType::MACHINE_ACTIVATED, |
| 80 |
EventType::MACHINE_DEACTIVATED)) { |
| 81 |
calcCoverage(); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
bool VideoLayer::needRender() const |
| 86 |
{ |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
int current = videoSourceSetting.getSource(); |
| 91 |
return (current == getVideoSource()) || |
| 92 |
((current == video9000Source) && (activeVideo9000 != Video9000Active::NO)); |
| 93 |
} |
| 94 |
|
| 95 |
bool VideoLayer::needRecord() const |
| 96 |
{ |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
int current = videoSourceSetting.getSource(); |
| 101 |
return (current == getVideoSource()) || |
| 102 |
((current == video9000Source) && (activeVideo9000 == Video9000Active::FRONT)); |
| 103 |
} |
| 104 |
|
| 105 |
} |