1#include "double_buffer.hpp"
3#include "libxr_mem.hpp"
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);
41 buffer_[1] = EMPTY_STORAGE ? nullptr : (
static_cast<uint8_t*
>(raw_data.
addr_) +
size_);
59 ASSERT((block == 0) || (block == 1));
int active_
当前活动缓冲区编号 / Index of active buffer
size_t active_len_
当前活动缓冲区有效数据长度 / Length of active data
DoubleBuffer()=default
默认构造一个未初始化的双缓冲对象 Constructs one uninitialized double buffer object
void Reset()
重置 active/pending 状态,但保留已绑定的 backing storage Resets active/pending state while keeping bound backing ...
size_t size_
单个缓冲区大小 / Size of each buffer
bool pending_valid_
标记备用区是否准备好 / Whether pending buffer is ready
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
size_t pending_len_
备用缓冲区有效数据长度 / Length of pending data
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
uint8_t * buffer_[2]
双缓冲区指针 / Double buffer pointers
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