LCOV - code coverage report
Current view: top level - xenolith/core - XLCoreFrameRequest.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 14 100.0 %
Date: 2024-05-12 00:16:13 Functions: 12 12 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #ifndef XENOLITH_CORE_XLCOREFRAMEREQUEST_H_
      24             : #define XENOLITH_CORE_XLCOREFRAMEREQUEST_H_
      25             : 
      26             : #include "XLCoreFrameEmitter.h"
      27             : 
      28             : namespace STAPPLER_VERSIONIZED stappler::xenolith::core {
      29             : 
      30             : struct FrameOutputBinding : public Ref {
      31             :         using CompleteCallback = Function<bool(FrameAttachmentData &data, bool success, Ref *)>;
      32             : 
      33             :         const AttachmentData *attachment = nullptr;
      34             :         CompleteCallback callback;
      35             :         Rc<Ref> handle;
      36             : 
      37             :         FrameOutputBinding(const AttachmentData *, CompleteCallback &&, Rc<Ref> && = nullptr);
      38             : 
      39             :         virtual ~FrameOutputBinding();
      40             : 
      41             :         bool handleReady(FrameAttachmentData &data, bool success);
      42             : };
      43             : 
      44             : class FrameRequest final : public Ref {
      45             : public:
      46             :         using CompleteCallback = FrameOutputBinding::CompleteCallback;
      47             : 
      48             :         virtual ~FrameRequest();
      49             : 
      50             :         bool init(const Rc<FrameEmitter> &, const FrameContraints &);
      51             :         bool init(const Rc<Queue> &q);
      52             :         bool init(const Rc<Queue> &q, const FrameContraints &);
      53             :         bool init(const Rc<Queue> &q, const Rc<FrameEmitter> &, const FrameContraints &);
      54             : 
      55             :         void addSignalDependency(Rc<DependencyEvent> &&);
      56             :         void addSignalDependencies(Vector<Rc<DependencyEvent>> &&);
      57             : 
      58             :         void addImageSpecialization(const ImageAttachment *, ImageInfoData &&);
      59             :         const ImageInfoData *getImageSpecialization(const ImageAttachment *image) const;
      60             : 
      61             :         bool addInput(const Attachment *a, Rc<AttachmentInputData> &&);
      62             :         bool addInput(const AttachmentData *, Rc<AttachmentInputData> &&);
      63             : 
      64             :         void setQueue(const Rc<Queue> &q);
      65             : 
      66             :         void setOutput(Rc<FrameOutputBinding> &&);
      67             :         void setOutput(const AttachmentData *, CompleteCallback &&, Rc<Ref> && = nullptr);
      68             :         void setOutput(const Attachment *a, CompleteCallback &&cb, Rc<Ref> && = nullptr);
      69             : 
      70             :         void setRenderTarget(const AttachmentData *, Rc<ImageStorage> &&);
      71             : 
      72             :         void attachFrame(FrameHandle *);
      73             :         void detachFrame();
      74             : 
      75             :         bool onOutputReady(Loop &, FrameAttachmentData &);
      76             :         void onOutputInvalidated(Loop &, FrameAttachmentData &);
      77             : 
      78             :         void finalize(Loop &, HashMap<const AttachmentData *, FrameAttachmentData *> &attachments, bool success);
      79             :         void signalDependencies(Loop &, Queue *, bool success);
      80             : 
      81             :         Rc<AttachmentInputData> getInputData(const AttachmentData *attachment);
      82             : 
      83       56297 :         const Rc<PoolRef> &getPool() const { return _pool; }
      84             :         Rc<ImageStorage> getRenderTarget(const AttachmentData *);
      85             : 
      86       79810 :         const Rc<FrameEmitter> &getEmitter() const { return _emitter; }
      87       58175 :         const Rc<Queue> &getQueue() const { return _queue; }
      88             : 
      89             :         Set<Rc<Queue>> getQueueList() const;
      90             : 
      91      746433 :         const FrameContraints & getFrameConstraints() const { return _constraints; }
      92             : 
      93        7338 :         void setReadyForSubmit(bool value) { _readyForSubmit = value; }
      94      138935 :         bool isReadyForSubmit() const { return _readyForSubmit; }
      95             : 
      96       72345 :         bool isPersistentMapping() const { return _persistentMappings; }
      97             : 
      98        9538 :         void setSceneId(uint64_t val) { _sceneId = val; }
      99        9538 :         uint64_t getSceneId() const { return _sceneId; }
     100             : 
     101         812 :         const Vector<Rc<DependencyEvent>> &getSignalDependencies() const { return _signalDependencies; }
     102             : 
     103       28435 :         FrameRequest() = default;
     104             : 
     105             :         void waitForInput(FrameQueue &, const Rc<AttachmentHandle> &a, Function<void(bool)> &&cb);
     106             : 
     107             :         const FrameOutputBinding *getOutputBinding(const AttachmentData *) const;
     108             : 
     109        4640 :         void autorelease(Ref *ref) {
     110        4640 :                 _autorelease.emplace_front(ref);
     111        4640 :         }
     112             : 
     113             : protected:
     114             :         FrameRequest(const FrameRequest &) = delete;
     115             :         FrameRequest &operator=(const FrameRequest &) = delete;
     116             : 
     117             :         Rc<PoolRef> _pool;
     118             :         Rc<FrameEmitter> _emitter;
     119             :         Rc<Queue> _queue;
     120             :         FrameContraints _constraints;
     121             :         Map<const AttachmentData *, Rc<AttachmentInputData>> _input;
     122             :         bool _readyForSubmit = true; // if true, do not wait synchronization with other active frames in emitter
     123             :         bool _persistentMappings = true; // true; // true; // try to map per-frame GPU memory persistently
     124             :         uint64_t _sceneId = 0;
     125             : 
     126             :         Map<const ImageAttachment *, ImageInfoData> _imageSpecialization;
     127             :         Map<const AttachmentData *, Rc<FrameOutputBinding>> _output;
     128             :         Map<const AttachmentData *, Rc<ImageStorage>> _renderTargets;
     129             : 
     130             :         Vector<Rc<DependencyEvent>> _signalDependencies;
     131             : 
     132             :         struct WaitInputData {
     133             :                 Rc<FrameQueue> queue;
     134             :                 AttachmentHandle *handle;
     135             :                 Function<void(bool)> callback;
     136             :         };
     137             : 
     138             :         Map<const AttachmentData *, WaitInputData> _waitForInputs;
     139             :         FrameHandle *_frame = nullptr;
     140             :         std::forward_list<Rc<Ref>> _autorelease;
     141             : };
     142             : 
     143             : }
     144             : 
     145             : #endif /* XENOLITH_CORE_XLCOREFRAMEREQUEST_H_ */

Generated by: LCOV version 1.14