|
6 | 6 |
|
7 | 7 | #include <Ecore_IMF_Evas.h>
|
8 | 8 | #include <Ecore_Input_Evas.h>
|
| 9 | +#include <flutter/texture_registrar.h> |
9 | 10 | #include <flutter_platform_view.h>
|
10 |
| -#include <flutter_tizen_texture_registrar.h> |
| 11 | +#include <flutter_texture_registrar.h> |
11 | 12 |
|
12 | 13 | #include <map>
|
13 | 14 | #include <memory>
|
@@ -154,19 +155,27 @@ double ExtractDoubleFromMap(const flutter::EncodableValue& arguments,
|
154 | 155 | }
|
155 | 156 |
|
156 | 157 | WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
|
157 |
| - FlutterTextureRegistrar* texture_registrar, double width, |
| 158 | + flutter::TextureRegistrar* texture_registrar, double width, |
158 | 159 | double height, flutter::EncodableMap& params)
|
159 | 160 | : PlatformView(registrar, viewId),
|
160 | 161 | texture_registrar_(texture_registrar),
|
161 | 162 | webview_instance_(nullptr),
|
162 | 163 | width_(width),
|
163 | 164 | height_(height),
|
164 |
| - tbm_surface_(nullptr), |
| 165 | + candidate_surface_(nullptr), |
| 166 | + rendered_surface_(nullptr), |
165 | 167 | is_mouse_lbutton_down_(false),
|
166 | 168 | has_navigation_delegate_(false),
|
167 | 169 | has_progress_tracking_(false),
|
168 |
| - context_(nullptr) { |
169 |
| - SetTextureId(FlutterRegisterExternalTexture(texture_registrar_)); |
| 170 | + context_(nullptr), |
| 171 | + texture_variant_(nullptr), |
| 172 | + gpu_buffer_(nullptr) { |
| 173 | + texture_variant_ = new flutter::TextureVariant(flutter::GpuBufferTexture( |
| 174 | + [this](size_t width, size_t height) -> const FlutterDesktopGpuBuffer* { |
| 175 | + return this->ObtainGpuBuffer(width, height); |
| 176 | + }, |
| 177 | + [this](void* buffer) -> void { this->DestructBuffer(buffer); })); |
| 178 | + SetTextureId(texture_registrar_->RegisterTexture(texture_variant_)); |
170 | 179 | InitWebView();
|
171 | 180 |
|
172 | 181 | channel_ = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
|
@@ -375,12 +384,22 @@ std::string WebView::GetChannelName() {
|
375 | 384 | }
|
376 | 385 |
|
377 | 386 | void WebView::Dispose() {
|
378 |
| - FlutterUnregisterExternalTexture(texture_registrar_, GetTextureId()); |
| 387 | + texture_registrar_->UnregisterTexture(GetTextureId()); |
379 | 388 |
|
380 | 389 | if (webview_instance_) {
|
381 | 390 | webview_instance_->Destroy();
|
382 | 391 | webview_instance_ = nullptr;
|
383 | 392 | }
|
| 393 | + |
| 394 | + if (texture_variant_) { |
| 395 | + delete texture_variant_; |
| 396 | + texture_variant_ = nullptr; |
| 397 | + } |
| 398 | + |
| 399 | + if (gpu_buffer_) { |
| 400 | + delete gpu_buffer_; |
| 401 | + gpu_buffer_ = nullptr; |
| 402 | + } |
384 | 403 | }
|
385 | 404 |
|
386 | 405 | void WebView::Resize(double width, double height) {
|
@@ -747,26 +766,28 @@ void WebView::InitWebView() {
|
747 | 766 | webview_instance_->Destroy();
|
748 | 767 | webview_instance_ = nullptr;
|
749 | 768 | }
|
| 769 | + if (!gpu_buffer_) { |
| 770 | + gpu_buffer_ = new FlutterDesktopGpuBuffer(); |
| 771 | + } |
| 772 | + |
750 | 773 | float scale_factor = 1;
|
751 | 774 |
|
752 | 775 | webview_instance_ = (LWE::WebContainer*)createWebViewInstance(
|
753 | 776 | 0, 0, width_, height_, scale_factor, "SamsungOneUI", "ko-KR",
|
754 | 777 | "Asia/Seoul",
|
755 | 778 | [this]() -> LWE::WebContainer::ExternalImageInfo {
|
| 779 | + std::lock_guard<std::mutex> lock(mutex_); |
756 | 780 | LWE::WebContainer::ExternalImageInfo result;
|
757 |
| - if (!tbm_surface_) { |
758 |
| - tbm_surface_ = |
| 781 | + if (!candidate_surface_) { |
| 782 | + candidate_surface_ = |
759 | 783 | tbm_surface_create(width_, height_, TBM_FORMAT_ARGB8888);
|
760 | 784 | }
|
761 |
| - result.imageAddress = (void*)tbm_surface_; |
| 785 | + result.imageAddress = (void*)candidate_surface_; |
762 | 786 | return result;
|
763 | 787 | },
|
764 | 788 | [this](LWE::WebContainer* c, bool isRendered) {
|
765 | 789 | if (isRendered) {
|
766 |
| - FlutterMarkExternalTextureFrameAvailable( |
767 |
| - texture_registrar_, GetTextureId(), tbm_surface_); |
768 |
| - tbm_surface_destroy(tbm_surface_); |
769 |
| - tbm_surface_ = nullptr; |
| 790 | + texture_registrar_->MarkTextureFrameAvailable(GetTextureId()); |
770 | 791 | }
|
771 | 792 | });
|
772 | 793 | #ifndef TV_PROFILE
|
@@ -900,3 +921,35 @@ void WebView::HandleCookieMethodCall(
|
900 | 921 | result->NotImplemented();
|
901 | 922 | }
|
902 | 923 | }
|
| 924 | + |
| 925 | +FlutterDesktopGpuBuffer* WebView::ObtainGpuBuffer(size_t width, size_t height) { |
| 926 | + if (!candidate_surface_) { |
| 927 | + return nullptr; |
| 928 | + } |
| 929 | + |
| 930 | + std::lock_guard<std::mutex> lock(mutex_); |
| 931 | + if (rendered_surface_) { |
| 932 | + tbm_surface_destroy(rendered_surface_); |
| 933 | + rendered_surface_ = nullptr; |
| 934 | + } |
| 935 | + |
| 936 | + rendered_surface_ = candidate_surface_; |
| 937 | + candidate_surface_ = nullptr; |
| 938 | + |
| 939 | + if (gpu_buffer_) { |
| 940 | + gpu_buffer_->buffer = rendered_surface_; |
| 941 | + gpu_buffer_->width = width; |
| 942 | + gpu_buffer_->height = height; |
| 943 | + } |
| 944 | + return gpu_buffer_; |
| 945 | +} |
| 946 | + |
| 947 | +void WebView::DestructBuffer(void* buffer) { |
| 948 | + 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; |
| 953 | + } |
| 954 | + } |
| 955 | +} |
0 commit comments