KiCad PCB EDA Suite
Loading...
Searching...
No Matches
frame_mailbox.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef RHI_FRAME_MAILBOX_H
21#define RHI_FRAME_MAILBOX_H
22
23#include <rhi/frame_packet.h>
24
25#include <atomic>
26#include <memory>
27
28
29namespace KIGFX
30{
31
39{
40public:
41 FRAME_MAILBOX() = default;
42
44 {
45 delete m_pending.load( std::memory_order_acquire );
46 }
47
48 FRAME_MAILBOX( const FRAME_MAILBOX& ) = delete;
50
54 std::unique_ptr<FRAME_PACKET> Submit( std::unique_ptr<FRAME_PACKET> aPacket )
55 {
56 if( aPacket )
57 {
58 aPacket->bufferGeneration = std::min( aPacket->staticDrawDesc.bufferGeneration,
59 aPacket->dynamicDrawDesc.bufferGeneration );
60 }
61
62 if( aPacket )
63 m_pendingInputSerial.store( aPacket->inputSerial, std::memory_order_release );
64
65 FRAME_PACKET* old = m_pending.exchange( aPacket.release(), std::memory_order_acq_rel );
66 return std::unique_ptr<FRAME_PACKET>( old );
67 }
68
72 std::unique_ptr<FRAME_PACKET> Load()
73 {
74 std::unique_ptr<FRAME_PACKET> packet( m_pending.exchange( nullptr, std::memory_order_acq_rel ) );
75
77 if( packet )
78 m_consumedGeneration.store( packet->bufferGeneration, std::memory_order_release );
79
80 return packet;
81 }
82
87 uint64_t ConsumedBufferGeneration() const
88 {
89 return m_consumedGeneration.load( std::memory_order_acquire );
90 }
91
95 uint64_t PendingInputSerial() const
96 {
97 return m_pendingInputSerial.load( std::memory_order_acquire );
98 }
99
100private:
101 std::atomic<FRAME_PACKET*> m_pending{ nullptr };
102 std::atomic<uint64_t> m_consumedGeneration{ 0 };
103 std::atomic<uint64_t> m_pendingInputSerial{ 0 };
104};
105
106
107} // namespace KIGFX
108
109
110#endif // RHI_FRAME_MAILBOX_H
FRAME_MAILBOX & operator=(const FRAME_MAILBOX &)=delete
std::unique_ptr< FRAME_PACKET > Load()
std::atomic< uint64_t > m_consumedGeneration
std::atomic< uint64_t > m_pendingInputSerial
std::atomic< FRAME_PACKET * > m_pending
FRAME_MAILBOX(const FRAME_MAILBOX &)=delete
uint64_t PendingInputSerial() const
std::unique_ptr< FRAME_PACKET > Submit(std::unique_ptr< FRAME_PACKET > aPacket)
uint64_t ConsumedBufferGeneration() const
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
Everything the render thread needs to draw one frame of a window.