66
77#include " log.h"
88
9- BufferUnit::BufferUnit (int index, int width, int height)
10- : isUsed_(false ),
11- index_(index),
12- width_(0 ),
13- height_(0 ),
14- tbm_surface_(nullptr ),
15- gpu_buffer_(nullptr ) {
9+ BufferUnit::BufferUnit (int index, int width, int height) : index_(index) {
1610 Reset (width, height);
1711}
1812
@@ -28,18 +22,14 @@ BufferUnit::~BufferUnit() {
2822}
2923
3024bool BufferUnit::MarkInUse () {
31- if (!isUsed_ ) {
32- isUsed_ = true ;
25+ if (!is_used_ ) {
26+ is_used_ = true ;
3327 return true ;
3428 }
3529 return false ;
3630}
3731
38- FlutterDesktopGpuBuffer* BufferUnit::GpuBuffer () { return gpu_buffer_; }
39-
40- int BufferUnit::Index () { return index_; }
41-
42- bool BufferUnit::IsUsed () { return isUsed_ && tbm_surface_; }
32+ void BufferUnit::UnmarkInUse () { is_used_ = false ; }
4333
4434tbm_surface_h BufferUnit::Surface () {
4535 if (IsUsed ()) {
@@ -48,14 +38,13 @@ tbm_surface_h BufferUnit::Surface() {
4838 return nullptr ;
4939}
5040
51- void BufferUnit::UnmarkInUse () { isUsed_ = false ; }
52-
5341void BufferUnit::Reset (int width, int height) {
5442 if (width_ == width && height_ == height) {
5543 return ;
5644 }
5745 width_ = width;
5846 height_ = height;
47+
5948 if (tbm_surface_) {
6049 tbm_surface_destroy (tbm_surface_);
6150 tbm_surface_ = nullptr ;
@@ -64,14 +53,15 @@ void BufferUnit::Reset(int width, int height) {
6453 delete gpu_buffer_;
6554 gpu_buffer_ = nullptr ;
6655 }
56+
6757 tbm_surface_ = tbm_surface_create (width_, height_, TBM_FORMAT_ARGB8888);
6858 gpu_buffer_ = new FlutterDesktopGpuBuffer ();
6959 gpu_buffer_->width = width_;
7060 gpu_buffer_->height = height_;
7161 gpu_buffer_->buffer = tbm_surface_;
7262 gpu_buffer_->release_callback = [](void * release_context) {
73- BufferUnit* bu = ( BufferUnit*) release_context;
74- bu ->UnmarkInUse ();
63+ BufferUnit* buffer = reinterpret_cast < BufferUnit*>( release_context) ;
64+ buffer ->UnmarkInUse ();
7565 };
7666 gpu_buffer_->release_context = this ;
7767}
@@ -98,9 +88,9 @@ BufferUnit* BufferPool::GetAvailableBuffer() {
9888 return nullptr ;
9989}
10090
101- void BufferPool::Release (BufferUnit* unit ) {
91+ void BufferPool::Release (BufferUnit* buffer ) {
10292 std::lock_guard<std::mutex> lock (mutex_);
103- unit ->UnmarkInUse ();
93+ buffer ->UnmarkInUse ();
10494}
10595
10696void BufferPool::Prepare (int width, int height) {
@@ -117,27 +107,28 @@ SingleBufferPool::SingleBufferPool(int width, int height)
117107SingleBufferPool::~SingleBufferPool () {}
118108
119109BufferUnit* SingleBufferPool::GetAvailableBuffer () {
120- pool_[0 ].get ()->MarkInUse ();
121- return pool_[0 ].get ();
110+ BufferUnit* buffer = pool_[0 ].get ();
111+ buffer->MarkInUse ();
112+ return buffer;
122113}
123114
124- void SingleBufferPool::Release (BufferUnit* unit ) {}
115+ void SingleBufferPool::Release (BufferUnit* buffer ) {}
125116
126117#ifndef NDEBUG
127118#include < cairo.h>
128119void BufferUnit::DumpToPng (int file_name) {
129- char filePath [256 ];
130- sprintf (filePath , " /tmp/dump%d.png" , file_name);
131- tbm_surface_info_s surfaceInfo;
132- tbm_surface_map (tbm_surface_, TBM_SURF_OPTION_WRITE, &surfaceInfo) ;
133- void * buffer = surfaceInfo. planes [ 0 ]. ptr ;
134-
135- cairo_surface_t * png_buffer ;
136- png_buffer = cairo_image_surface_create_for_data (
137- ( unsigned char *) buffer, CAIRO_FORMAT_ARGB32, width_, height_,
138- surfaceInfo .planes [0 ].stride );
139-
140- cairo_surface_write_to_png (png_buffer, filePath );
120+ char file_path [256 ];
121+ sprintf (file_path , " /tmp/dump%d.png" , file_name);
122+
123+ tbm_surface_info_s surface_info ;
124+ tbm_surface_map (tbm_surface_, TBM_SURF_OPTION_WRITE, &surface_info) ;
125+
126+ unsigned char * buffer = surface_info. planes [ 0 ]. ptr ;
127+ cairo_surface_t * png_buffer = cairo_image_surface_create_for_data (
128+ buffer, CAIRO_FORMAT_ARGB32, width_, height_,
129+ surface_info .planes [0 ].stride );
130+
131+ cairo_surface_write_to_png (png_buffer, file_path );
141132
142133 tbm_surface_unmap (tbm_surface_);
143134 cairo_surface_destroy (png_buffer);
0 commit comments