15
15
#include < sstream>
16
16
#include < string>
17
17
18
+ #include " buffer_pool.h"
18
19
#include " log.h"
19
20
#include " lwe/LWEWebView.h"
20
21
#include " lwe/PlatformIntegrationData.h"
@@ -170,6 +171,7 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
170
171
context_(nullptr ),
171
172
texture_variant_(nullptr ),
172
173
gpu_buffer_(nullptr ) {
174
+ tbm_pool_ = std::make_unique<BufferPool>(width, height);
173
175
texture_variant_ = new flutter::TextureVariant (flutter::GpuBufferTexture (
174
176
[this ](size_t width, size_t height) -> const FlutterDesktopGpuBuffer* {
175
177
return this ->ObtainGpuBuffer (width, height);
@@ -404,7 +406,14 @@ void WebView::Dispose() {
404
406
405
407
void WebView::Resize (double width, double height) {
406
408
LOG_DEBUG (" WebView::Resize width: %f height: %f \n " , width, height);
407
- // NOTE: Not supported by LWE on Tizen.
409
+ width_ = width;
410
+ height_ = height;
411
+
412
+ if (candidate_surface_) {
413
+ candidate_surface_ = nullptr ;
414
+ }
415
+ tbm_pool_->Prepare (width_, height_);
416
+ webview_instance_->ResizeTo (width_, height_);
408
417
}
409
418
410
419
void WebView::Touch (int type, int button, double x, double y, double dx,
@@ -779,10 +788,14 @@ void WebView::InitWebView() {
779
788
std::lock_guard<std::mutex> lock (mutex_);
780
789
LWE::WebContainer::ExternalImageInfo result;
781
790
if (!candidate_surface_) {
782
- candidate_surface_ =
783
- tbm_surface_create (width_, height_, TBM_FORMAT_ARGB8888);
791
+ candidate_surface_ = tbm_pool_->GetAvailableBuffer ();
792
+ }
793
+ if (candidate_surface_) {
794
+ result.imageAddress =
795
+ static_cast <void *>(candidate_surface_->Surface ());
796
+ } else {
797
+ result.imageAddress = nullptr ;
784
798
}
785
- result.imageAddress = (void *)candidate_surface_;
786
799
return result;
787
800
},
788
801
[this ](LWE::WebContainer* c, bool isRendered) {
@@ -924,20 +937,17 @@ void WebView::HandleCookieMethodCall(
924
937
925
938
FlutterDesktopGpuBuffer* WebView::ObtainGpuBuffer (size_t width, size_t height) {
926
939
if (!candidate_surface_) {
927
- return nullptr ;
940
+ if (!rendered_surface_) {
941
+ return nullptr ;
942
+ } else {
943
+ return gpu_buffer_;
944
+ }
928
945
}
929
-
930
946
std::lock_guard<std::mutex> lock (mutex_);
931
- if (rendered_surface_) {
932
- tbm_surface_destroy (rendered_surface_);
933
- rendered_surface_ = nullptr ;
934
- }
935
-
936
947
rendered_surface_ = candidate_surface_;
937
948
candidate_surface_ = nullptr ;
938
-
939
949
if (gpu_buffer_) {
940
- gpu_buffer_->buffer = rendered_surface_;
950
+ gpu_buffer_->buffer = static_cast < void *>( rendered_surface_-> Surface ()) ;
941
951
gpu_buffer_->width = width;
942
952
gpu_buffer_->height = height;
943
953
}
@@ -946,10 +956,9 @@ FlutterDesktopGpuBuffer* WebView::ObtainGpuBuffer(size_t width, size_t height) {
946
956
947
957
void WebView::DestructBuffer (void * buffer) {
948
958
if (buffer) {
949
- std::lock_guard<std::mutex> lock (mutex_);
950
- tbm_surface_destroy ((tbm_surface_h)buffer);
951
- if (rendered_surface_ == buffer) {
952
- rendered_surface_ = nullptr ;
959
+ BufferUnit* unit = tbm_pool_->Find ((tbm_surface_h)buffer);
960
+ if (unit) {
961
+ tbm_pool_->Release (unit);
953
962
}
954
963
}
955
964
}
0 commit comments