LCOV - code coverage report
Current view: top level - xenolith/core - XLCoreQueuePass.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 58 101 57.4 %
Date: 2024-05-12 00:16:13 Functions: 21 31 67.7 %

          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             : #include "XLCoreQueuePass.h"
      24             : #include "XLCoreQueue.h"
      25             : #include "XLCoreFrameQueue.h"
      26             : 
      27             : namespace STAPPLER_VERSIONIZED stappler::xenolith::core {
      28             : 
      29         368 : QueuePass::~QueuePass() { }
      30             : 
      31         320 : bool QueuePass::init(QueuePassBuilder &builder) {
      32         320 :         _data = builder.getData();
      33         320 :         return true;
      34             : }
      35             : 
      36          48 : void QueuePass::invalidate() {
      37             : 
      38          48 : }
      39             : 
      40        1440 : StringView QueuePass::getName() const {
      41        1440 :         return _data->key;
      42             : }
      43             : 
      44           0 : RenderOrdering QueuePass::getOrdering() const {
      45           0 :         return _data->ordering;
      46             : }
      47             : 
      48           0 : size_t QueuePass::getSubpassCount() const {
      49           0 :         return _data->subpasses.size();
      50             : }
      51             : 
      52        8361 : PassType QueuePass::getType() const {
      53        8361 :         return _data->type;
      54             : }
      55             : 
      56      115200 : Rc<QueuePassHandle> QueuePass::makeFrameHandle(const FrameQueue &handle) {
      57      115200 :         if (_frameHandleCallback) {
      58      115200 :                 return _frameHandleCallback(*this, handle);
      59             :         }
      60           0 :         return Rc<QueuePassHandle>::create(*this, handle);
      61             : }
      62             : 
      63           0 : void QueuePass::setFrameHandleCallback(FrameHandleCallback &&cb) {
      64           0 :         _frameHandleCallback = move(cb);
      65           0 : }
      66             : 
      67      131597 : bool QueuePass::acquireForFrame(FrameQueue &frame, Function<void(bool)> &&onAcquired) {
      68      131597 :         if (_owner) {
      69           0 :                 if (_next.queue) {
      70           0 :                         _next.acquired(false);
      71             :                 }
      72           0 :                 _next = FrameQueueWaiter{
      73           0 :                         &frame,
      74           0 :                         move(onAcquired)
      75           0 :                 };
      76           0 :                 return false;
      77             :         } else {
      78      131597 :                 _owner = &frame;
      79      131597 :                 return true;
      80             :         }
      81             : }
      82             : 
      83      263482 : bool QueuePass::releaseForFrame(FrameQueue &frame) {
      84      263482 :         if (_owner == &frame) {
      85      131597 :                 if (_next.queue) {
      86           0 :                         _owner = move(_next.queue);
      87           0 :                         _next.acquired(true);
      88           0 :                         _next.queue = nullptr;
      89           0 :                         _next.acquired = nullptr;
      90             :                 } else {
      91      131597 :                         _owner = nullptr;
      92             :                 }
      93      131597 :                 return true;
      94      131885 :         } else if (_next.queue == &frame) {
      95           0 :                 auto tmp = move(_next.acquired);
      96           0 :                 _next.queue = nullptr;
      97           0 :                 _next.acquired = nullptr;
      98           0 :                 tmp(false);
      99           0 :                 return true;
     100           0 :         }
     101      131885 :         return false;
     102             : }
     103             : 
     104         272 : void QueuePass::prepare(Device &device) {
     105             : 
     106         272 : }
     107             : 
     108      131773 : QueuePassHandle::~QueuePassHandle() { }
     109             : 
     110      131773 : bool QueuePassHandle::init(QueuePass &pass, const FrameQueue &queue) {
     111      131773 :         _queuePass = &pass;
     112      131773 :         _data = pass.getData();
     113      131773 :         return true;
     114             : }
     115             : 
     116      131773 : void QueuePassHandle::setQueueData(FramePassData &data) {
     117      131773 :         _queueData = &data;
     118      131773 : }
     119             : 
     120       38412 : const FramePassData *QueuePassHandle::getQueueData() const {
     121       38412 :         return _queueData;
     122             : }
     123             : 
     124      131629 : StringView QueuePassHandle::getName() const {
     125      131629 :         return _data->key;
     126             : }
     127             : 
     128       21966 : const Rc<Framebuffer> &QueuePassHandle::getFramebuffer() const {
     129       21966 :         return _queueData->framebuffer;
     130             : }
     131             : 
     132      131773 : bool QueuePassHandle::isAvailable(const FrameQueue &handle) const {
     133      131773 :         return true;
     134             : }
     135             : 
     136           0 : bool QueuePassHandle::isSubmitted() const {
     137           0 :         return toInt(_queueData->state) >= toInt(FrameRenderPassState::Submitted);
     138             : }
     139             : 
     140           0 : bool QueuePassHandle::isCompleted() const {
     141           0 :         return toInt(_queueData->state) >= toInt(FrameRenderPassState::Complete);
     142             : }
     143             : 
     144        7322 : bool QueuePassHandle::isFramebufferRequired() const {
     145        7322 :         return _queuePass->getType() == PassType::Graphics;
     146             : }
     147             : 
     148           0 : bool QueuePassHandle::prepare(FrameQueue &q, Function<void(bool)> &&cb) {
     149           0 :         prepareSubpasses(q);
     150           0 :         return true;
     151             : }
     152             : 
     153           0 : void QueuePassHandle::submit(FrameQueue &, Rc<FrameSync> &&, Function<void(bool)> &&onSubmited, Function<void(bool)> &&onComplete) {
     154             : 
     155           0 : }
     156             : 
     157           0 : void QueuePassHandle::finalize(FrameQueue &, bool successful) {
     158             : 
     159           0 : }
     160             : 
     161      253238 : AttachmentHandle *QueuePassHandle::getAttachmentHandle(const AttachmentData *a) const {
     162      253238 :         auto it = _queueData->attachmentMap.find(a);
     163      253060 :         if (it != _queueData->attachmentMap.end()) {
     164      253031 :                 return it->second->handle.get();
     165             :         }
     166           0 :         return nullptr;
     167             : }
     168             : 
     169     2722429 : void QueuePassHandle::autorelease(Ref *ref) const {
     170     2722429 :         if (!ref) {
     171           0 :                 return;
     172             :         }
     173             : 
     174     2722429 :         std::unique_lock lock(_autoreleaseMutex);
     175     2722717 :         _autorelease.emplace_back(ref);
     176     2722740 : }
     177             : 
     178           0 : const AttachmentPassData *QueuePassHandle::getAttachemntData(const AttachmentData *a) const {
     179           0 :         for (auto &it : a->passes) {
     180           0 :                 if (it->pass == _data) {
     181           0 :                         return it;
     182             :                 }
     183             :         }
     184           0 :         return nullptr;
     185             : }
     186             : 
     187      131597 : void QueuePassHandle::prepareSubpasses(FrameQueue &q) {
     188      326379 :         for (auto &subpass : _queuePass->getData()->subpasses) {
     189      194782 :                 if (subpass->prepareCallback) {
     190      134400 :                         subpass->prepareCallback(*subpass, q);
     191             :                 }
     192             :         }
     193      131597 : }
     194             : 
     195             : }

Generated by: LCOV version 1.14