6
6
7
7
#include " log.h"
8
8
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) {
10
11
Reset (width, height);
11
12
}
12
13
@@ -38,7 +39,7 @@ tbm_surface_h BufferUnit::Surface() {
38
39
return nullptr ;
39
40
}
40
41
41
- void BufferUnit::Reset (int width, int height) {
42
+ void BufferUnit::Reset (int32_t width, int32_t height) {
42
43
if (width_ == width && height_ == height) {
43
44
return ;
44
45
}
@@ -66,9 +67,9 @@ void BufferUnit::Reset(int width, int height) {
66
67
gpu_buffer_->release_context = this ;
67
68
}
68
69
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));
72
73
}
73
74
Prepare (width, height);
74
75
}
@@ -77,8 +78,8 @@ BufferPool::~BufferPool() {}
77
78
78
79
BufferUnit* BufferPool::GetAvailableBuffer () {
79
80
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 ();
82
83
BufferUnit* buffer = pool_[current].get ();
83
84
if (buffer->MarkInUse ()) {
84
85
last_index_ = current;
@@ -93,15 +94,15 @@ void BufferPool::Release(BufferUnit* buffer) {
93
94
buffer->UnmarkInUse ();
94
95
}
95
96
96
- void BufferPool::Prepare (int width, int height) {
97
+ void BufferPool::Prepare (int32_t width, int32_t height) {
97
98
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 ();
100
101
buffer->Reset (width, height);
101
102
}
102
103
}
103
104
104
- SingleBufferPool::SingleBufferPool (int width, int height)
105
+ SingleBufferPool::SingleBufferPool (int32_t width, int32_t height)
105
106
: BufferPool(width, height, 1 ) {}
106
107
107
108
SingleBufferPool::~SingleBufferPool () {}
0 commit comments