|
7 | 7 | #include <Ecore_IMF_Evas.h>
|
8 | 8 | #include <Ecore_Input_Evas.h>
|
9 | 9 | #include <flutter_platform_view.h>
|
10 |
| -#include <flutter_tizen_texture_registrar.h> |
| 10 | +#include <flutter_texture_registrar.h> |
| 11 | +#include <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 | 170 | context_(nullptr) {
|
169 |
| - SetTextureId(FlutterRegisterExternalTexture(texture_registrar_)); |
| 171 | + flutter::TextureVariant* textureVariant_ = |
| 172 | + new flutter::TextureVariant(flutter::GpuBufferTexture( |
| 173 | + [this](size_t width, |
| 174 | + size_t height) -> const FlutterDesktopGpuBuffer* { |
| 175 | + return this->CopyGpuBuffer(width, height); |
| 176 | + }, |
| 177 | + [this](void* buffer) -> void { this->Destruction(buffer); })); |
| 178 | + SetTextureId(texture_registrar_->RegisterTexture(textureVariant_)); |
170 | 179 | InitWebView();
|
171 | 180 |
|
172 | 181 | channel_ = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
|
@@ -375,7 +384,7 @@ 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();
|
@@ -753,20 +762,18 @@ void WebView::InitWebView() {
|
753 | 762 | 0, 0, width_, height_, scale_factor, "SamsungOneUI", "ko-KR",
|
754 | 763 | "Asia/Seoul",
|
755 | 764 | [this]() -> LWE::WebContainer::ExternalImageInfo {
|
| 765 | + std::lock_guard<std::mutex> lock(mutex_); |
756 | 766 | LWE::WebContainer::ExternalImageInfo result;
|
757 |
| - if (!tbm_surface_) { |
758 |
| - tbm_surface_ = |
| 767 | + if (!candidate_surface_) { |
| 768 | + candidate_surface_ = |
759 | 769 | tbm_surface_create(width_, height_, TBM_FORMAT_ARGB8888);
|
760 | 770 | }
|
761 |
| - result.imageAddress = (void*)tbm_surface_; |
| 771 | + result.imageAddress = (void*)candidate_surface_; |
762 | 772 | return result;
|
763 | 773 | },
|
764 | 774 | [this](LWE::WebContainer* c, bool isRendered) {
|
765 | 775 | if (isRendered) {
|
766 |
| - FlutterMarkExternalTextureFrameAvailable( |
767 |
| - texture_registrar_, GetTextureId(), tbm_surface_); |
768 |
| - tbm_surface_destroy(tbm_surface_); |
769 |
| - tbm_surface_ = nullptr; |
| 776 | + texture_registrar_->MarkTextureFrameAvailable(GetTextureId()); |
770 | 777 | }
|
771 | 778 | });
|
772 | 779 | #ifndef TV_PROFILE
|
@@ -900,3 +907,34 @@ void WebView::HandleCookieMethodCall(
|
900 | 907 | result->NotImplemented();
|
901 | 908 | }
|
902 | 909 | }
|
| 910 | + |
| 911 | +FlutterDesktopGpuBuffer* WebView::CopyGpuBuffer(size_t width, size_t height) { |
| 912 | + if (!candidate_surface_) { |
| 913 | + return nullptr; |
| 914 | + } |
| 915 | + |
| 916 | + std::lock_guard<std::mutex> lock(mutex_); |
| 917 | + if (rendered_surface_) { |
| 918 | + tbm_surface_destroy(rendered_surface_); |
| 919 | + rendered_surface_ = nullptr; |
| 920 | + } |
| 921 | + |
| 922 | + rendered_surface_ = candidate_surface_; |
| 923 | + candidate_surface_ = nullptr; |
| 924 | + |
| 925 | + FlutterDesktopGpuBuffer* gpuBuffer = new FlutterDesktopGpuBuffer(); |
| 926 | + gpuBuffer->buffer = rendered_surface_; |
| 927 | + gpuBuffer->width = width; |
| 928 | + gpuBuffer->height = height; |
| 929 | + return gpuBuffer; |
| 930 | +} |
| 931 | + |
| 932 | +void WebView::Destruction(void* buffer) { |
| 933 | + if(buffer){ |
| 934 | + std::lock_guard<std::mutex> lock(mutex_); |
| 935 | + tbm_surface_destroy((tbm_surface_h)buffer); |
| 936 | + if (rendered_surface_==buffer) { |
| 937 | + rendered_surface_ = nullptr; |
| 938 | + } |
| 939 | + } |
| 940 | +} |
0 commit comments