| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | /* | ||
| 3 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 4 | * 2013-2022 by the Falcon Player Developers. | ||
| 5 | * | ||
| 6 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 7 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 8 | * file for descriptions of what files are covered by each license. | ||
| 9 | * | ||
| 10 | * This source file is covered under the LGPL v2.1 as described in the | ||
| 11 | * included LICENSE.LGPL file. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <atomic> | ||
| 15 | #include <memory> | ||
| 16 | #include <mutex> | ||
| 17 | #include <vector> | ||
| 18 | |||
| 19 | #include "PixelOverlayModel.h" | ||
| 20 | #include "fpp-json-fwd.h" | ||
| 21 | |||
| 22 | class PixelOverlayModelSub : public PixelOverlayModel { | ||
| 23 | public: | ||
| 24 | PixelOverlayModelSub(const Json::Value& config); | ||
| 25 | virtual ~PixelOverlayModelSub(); | ||
| 26 | |||
| 27 | virtual void doOverlay(uint8_t* channels) override; | ||
| 28 | virtual void setData(const uint8_t* data) override; | ||
| 29 | |||
| 30 | virtual void setState(const PixelOverlayState& st) override; | ||
| 31 | |||
| 32 | void resetParent(); | ||
| 33 | std::string getParentName() const; | ||
| 34 | // Looks the parent up now if it has not been yet (a grid submodel needs | ||
| 35 | // none). Not from the channel output thread, as foundParent(). | ||
| 36 |
4/4✓ Branch 0 taken 44 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 41 times.
✓ Branch 3 taken 3 times.
|
49 | bool resolveParent() { return gridMode || foundParent(); } |
| 37 | 4 | bool isGridMode() const { return gridMode; } | |
| 38 | // The parent is resolved and its chain ends at a framebuffer, the only | ||
| 39 | // kind of model a VirtualMatrix can draw from its own SendData(). | ||
| 40 | bool drawsToFramebuffer() const { return fbRoot; } | ||
| 41 | // For a VirtualMatrix or VirtualDisplay drawing this model from its | ||
| 42 | // SendData(): drawsToFramebuffer(), saying once why not when it is not. | ||
| 43 | bool readyForPassThrough(); | ||
| 44 | |||
| 45 | protected: | ||
| 46 | // Grid submodels and groups SCATTER: a buffer cell lands on an arbitrary | ||
| 47 | // parent/member channel rather than at a fixed offset from a start channel, | ||
| 48 | // so the base class's contiguous assumption does not hold. Both scatter | ||
| 49 | // tables are indexed by channelData slot, which is what this receives. | ||
| 50 | uint32_t outputChannelForData(uint32_t dataOffset) const override; | ||
| 51 | |||
| 52 | private: | ||
| 53 | bool foundParent(); | ||
| 54 | |||
| 55 | // `parent` is what doOverlay() draws through; `parentRef` owns a share | ||
| 56 | // of the same model, so setState() can call into it from any thread | ||
| 57 | // without modelsLock. Both are set and cleared together under | ||
| 58 | // parentLock (a leaf lock), always with modelsLock held as well. | ||
| 59 | PixelOverlayModel* parent = nullptr; | ||
| 60 | std::weak_ptr<PixelOverlayModel> parentRef; | ||
| 61 | std::mutex parentLock; | ||
| 62 | // Held across doOverlay()'s use of the parent, and taken by | ||
| 63 | // resetParent(): a VirtualMatrix in pass-through calls doOverlay() outside | ||
| 64 | // the active list, so disabling this model does not wait it out. An | ||
| 65 | // output reload closes outputs with the output thread held off anyway; | ||
| 66 | // this covers a parent removed any other way (a VirtualMatrix's Init() | ||
| 67 | // replacing its model while other outputs keep sending). | ||
| 68 | std::mutex useLock; | ||
| 69 | std::atomic<bool> fbRoot = false; | ||
| 70 | std::atomic<bool> passThroughWarned = false; | ||
| 71 | |||
| 72 | int xOffset = 0; | ||
| 73 | int yOffset = 0; | ||
| 74 | |||
| 75 | // Grid-mode (xLights submodel) support. When set, the submodel is a sparse | ||
| 76 | // subset of its parent's nodes defined by a grid of parent node numbers. | ||
| 77 | // The base class builds a dense width*height buffer + channelData; outputMap | ||
| 78 | // scatters each buffer cell's color to the parent's absolute output channel. | ||
| 79 | // See docs/PixelOverlaySubModels.md. | ||
| 80 | bool gridMode = false; | ||
| 81 | std::vector<uint32_t> outputMap; // one entry per buffer cell -> absolute output channel base (or FPPD_OFF_CHANNEL) | ||
| 82 | |||
| 83 | // Channel-grid mode (xLights model groups): a combined buffer whose cells | ||
| 84 | // each map to one OR MORE absolute output channels (member pixels binned by | ||
| 85 | // world position). See docs/PixelOverlaySubModels.md. | ||
| 86 | bool channelGridMode = false; | ||
| 87 | std::vector<std::vector<uint32_t>> outputCells; // per buffer cell -> list of absolute output channel bases | ||
| 88 | |||
| 89 | void buildGrid(); | ||
| 90 | void buildChannelGrid(); | ||
| 91 | void doGridOverlay(uint8_t* channels); | ||
| 92 | }; | ||
| 93 |