66
77#include " log.h"
88
9- BufferUnit::BufferUnit (int index, int width, int height) : index_(index) {
9+ BufferUnit::BufferUnit (size_t index, int32_t width, int32_t height)
10+ : index_(index) {
1011 Reset (width, height);
1112}
1213
@@ -38,7 +39,7 @@ tbm_surface_h BufferUnit::Surface() {
3839 return nullptr ;
3940}
4041
41- void BufferUnit::Reset (int width, int height) {
42+ void BufferUnit::Reset (int32_t width, int32_t height) {
4243 if (width_ == width && height_ == height) {
4344 return ;
4445 }
@@ -66,9 +67,9 @@ void BufferUnit::Reset(int width, int height) {
6667 gpu_buffer_->release_context = this ;
6768}
6869
69- BufferPool::BufferPool (int width, int height, int pool_size) : last_index_( 0 ) {
70- for (int idx = 0 ; idx < pool_size; idx ++) {
71- pool_.emplace_back (new BufferUnit (idx , width, height));
70+ BufferPool::BufferPool (int32_t width, int32_t height, size_t pool_size) {
71+ for (size_t index = 0 ; index < pool_size; index ++) {
72+ pool_.emplace_back (std::make_unique< BufferUnit>(index , width, height));
7273 }
7374 Prepare (width, height);
7475}
@@ -77,8 +78,8 @@ BufferPool::~BufferPool() {}
7778
7879BufferUnit* BufferPool::GetAvailableBuffer () {
7980 std::lock_guard<std::mutex> lock (mutex_);
80- for (int idx = 0 ; idx < pool_.size (); idx ++) {
81- int current = (idx + last_index_) % pool_.size ();
81+ for (size_t index = 0 ; index < pool_.size (); index ++) {
82+ size_t current = (index + last_index_) % pool_.size ();
8283 BufferUnit* buffer = pool_[current].get ();
8384 if (buffer->MarkInUse ()) {
8485 last_index_ = current;
@@ -93,15 +94,15 @@ void BufferPool::Release(BufferUnit* buffer) {
9394 buffer->UnmarkInUse ();
9495}
9596
96- void BufferPool::Prepare (int width, int height) {
97+ void BufferPool::Prepare (int32_t width, int32_t height) {
9798 std::lock_guard<std::mutex> lock (mutex_);
98- for (int idx = 0 ; idx < pool_.size (); idx ++) {
99- BufferUnit* buffer = pool_[idx ].get ();
99+ for (size_t index = 0 ; index < pool_.size (); index ++) {
100+ BufferUnit* buffer = pool_[index ].get ();
100101 buffer->Reset (width, height);
101102 }
102103}
103104
104- SingleBufferPool::SingleBufferPool (int width, int height)
105+ SingleBufferPool::SingleBufferPool (int32_t width, int32_t height)
105106 : BufferPool(width, height, 1 ) {}
106107
107108SingleBufferPool::~SingleBufferPool () {}
0 commit comments