1#include "double_buffer.hpp"
3#include "libxr_mem.hpp"
17 pending_valid_ =
false;
27 constexpr size_t ALIGN =
alignof(size_t);
28 const bool EMPTY_STORAGE = (raw_data.
addr_ ==
nullptr) && (raw_data.
size_ == 0U);
30 ASSERT(EMPTY_STORAGE || (raw_data.
addr_ !=
nullptr));
34 ASSERT(raw_data.
size_ > 0U);
35 ASSERT((
reinterpret_cast<uintptr_t
>(raw_data.
addr_) % ALIGN) == 0U);
36 ASSERT((raw_data.
size_ % (2U * ALIGN)) == 0U);
39 size_ = raw_data.
size_ / 2U;
40 buffer_[0] =
static_cast<uint8_t*
>(raw_data.
addr_);
41 buffer_[1] = EMPTY_STORAGE ? nullptr : (
static_cast<uint8_t*
>(raw_data.
addr_) + size_);
59 ASSERT((block == 0) || (block == 1));
60 return buffer_[block];
75 pending_valid_ =
false;
88 if (pending_valid_ || len > size_)
95 pending_valid_ =
true;
122 return pending_valid_ ? pending_len_ : 0;
DoubleBuffer()=default
默认构造一个未初始化的双缓冲对象 Constructs one uninitialized double buffer object
void Reset()
重置 active/pending 状态,但保留已绑定的 backing storage Resets active/pending state while keeping bound backing ...
void EnablePending()
手动启用 pending 状态 Manually sets the pending state to true
bool HasPending() const
判断是否有待切换的缓冲区 Checks whether a pending buffer is ready
size_t Size() const
获取每个缓冲区的大小(单位:字节) Gets the size of each buffer in bytes
uint8_t * Buffer(int block) const
获取指定编号缓冲区的指针 Returns the pointer of the specified block
bool FillActive(const uint8_t *data, size_t len)
向当前使用的缓冲区直接写入数据 Fills the active buffer directly
uint8_t * ActiveBuffer() const
获取当前正在使用的缓冲区指针 Returns the currently active buffer
void Init(const LibXR::RawData &raw_data)
绑定连续 backing storage 并重置双缓冲状态 Binds continuous backing storage and resets double-buffer state
uint8_t * PendingBuffer() const
获取备用缓冲区的指针 Returns the pending (inactive) buffer
void Switch()
切换到备用缓冲区(若其有效) Switches to the pending buffer if it's valid
size_t GetPendingLength() const
获取 pending 缓冲区中准备好的数据长度 Gets the size of valid data in pending buffer
bool FillPending(const uint8_t *data, size_t len)
向备用缓冲区写入数据(不可重入) Fills the pending buffer with data (non-reentrant)
static void FastCopy(void *dst, const void *src, size_t size)
快速内存拷贝 / Fast memory copy
可写原始数据视图 / Mutable raw data view
size_t size_
数据字节数 / Data size in bytes
void * addr_
数据起始地址 / Data start address
LibXR 命名空间 / LibXR namespace.