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>
15
+ #include < mutex>
14
16
#include < sstream>
15
17
#include < string>
16
18
@@ -154,7 +156,7 @@ double ExtractDoubleFromMap(const flutter::EncodableValue& arguments,
154
156
}
155
157
156
158
WebView::WebView (flutter::PluginRegistrar* registrar, int viewId,
157
- FlutterTextureRegistrar * texture_registrar, double width,
159
+ flutter::TextureRegistrar * texture_registrar, double width,
158
160
double height, flutter::EncodableMap& params)
159
161
: PlatformView(registrar, viewId),
160
162
texture_registrar_(texture_registrar),
@@ -166,7 +168,14 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
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 { this ->Destruction (); }));
178
+ SetTextureId (texture_registrar_->RegisterTexture (textureVariant_));
170
179
InitWebView ();
171
180
172
181
channel_ = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
@@ -375,7 +384,8 @@ std::string WebView::GetChannelName() {
375
384
}
376
385
377
386
void WebView::Dispose () {
378
- FlutterUnregisterExternalTexture (texture_registrar_, GetTextureId ());
387
+ // FlutterUnregisterExternalTexture(texture_registrar_, GetTextureId());
388
+ texture_registrar_->UnregisterTexture (GetTextureId ());
379
389
380
390
if (webview_instance_) {
381
391
webview_instance_->Destroy ();
@@ -754,19 +764,17 @@ void WebView::InitWebView() {
754
764
" Asia/Seoul" ,
755
765
[this ]() -> LWE::WebContainer::ExternalImageInfo {
756
766
LWE::WebContainer::ExternalImageInfo result;
757
- if (!tbm_surface_ ) {
758
- tbm_surface_ =
767
+ if (candidate_surfaces_. size () < 2 ) {
768
+ tbm_surface_h tbm_surface =
759
769
tbm_surface_create (width_, height_, TBM_FORMAT_ARGB8888);
770
+ candidate_surfaces_.push (tbm_surface);
760
771
}
761
- result.imageAddress = (void *)tbm_surface_ ;
772
+ result.imageAddress = (void *)candidate_surfaces_. top () ;
762
773
return result;
763
774
},
764
775
[this ](LWE::WebContainer* c, bool isRendered) {
765
776
if (isRendered) {
766
- FlutterMarkExternalTextureFrameAvailable (
767
- texture_registrar_, GetTextureId (), tbm_surface_);
768
- tbm_surface_destroy (tbm_surface_);
769
- tbm_surface_ = nullptr ;
777
+ texture_registrar_->MarkTextureFrameAvailable (GetTextureId ());
770
778
}
771
779
});
772
780
#ifndef TV_PROFILE
@@ -834,6 +842,7 @@ void WebView::HandleMethodCall(
834
842
});
835
843
} else {
836
844
result->Error (" Invalid Arguments" , " Invalid Arguments" );
845
+ // result->Success();
837
846
}
838
847
} else if (method_name.compare (" addJavascriptChannels" ) == 0 ) {
839
848
if (std::holds_alternative<flutter::EncodableList>(arguments)) {
@@ -900,3 +909,26 @@ void WebView::HandleCookieMethodCall(
900
909
result->NotImplemented ();
901
910
}
902
911
}
912
+
913
+ FlutterDesktopGpuBuffer* WebView::CopyGpuBuffer (size_t width, size_t height) {
914
+ if (candidate_surfaces_.size () == 0 ) {
915
+ return nullptr ;
916
+ }
917
+ std::lock_guard<std::mutex> lock (mutex_);
918
+ tbm_surface_ = candidate_surfaces_.top ();
919
+ candidate_surfaces_.pop ();
920
+
921
+ FlutterDesktopGpuBuffer* gpuBuffer = new FlutterDesktopGpuBuffer ();
922
+ gpuBuffer->buffer = tbm_surface_;
923
+ gpuBuffer->width = width;
924
+ gpuBuffer->height = height;
925
+ return gpuBuffer;
926
+ }
927
+
928
+ void WebView::Destruction () {
929
+ if (tbm_surface_) {
930
+ std::lock_guard<std::mutex> lock (mutex_);
931
+ tbm_surface_destroy (tbm_surface_);
932
+ tbm_surface_ = nullptr ;
933
+ }
934
+ }
0 commit comments