Skip to content

Commit 6fe3f64

Browse files
committed
[webview_flutter] Apply texture api change
Signed-off-by: MuHong Byun <[email protected]>
1 parent e5dceb5 commit 6fe3f64

File tree

5 files changed

+65
-20
lines changed

5 files changed

+65
-20
lines changed

packages/webview_flutter/tizen/src/webview.cc

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#include <Ecore_IMF_Evas.h>
88
#include <Ecore_Input_Evas.h>
99
#include <flutter_platform_view.h>
10-
#include <flutter_tizen_texture_registrar.h>
10+
#include <flutter_texture_registrar.h>
11+
#include <texture_registrar.h>
1112

1213
#include <map>
1314
#include <memory>
@@ -154,19 +155,27 @@ double ExtractDoubleFromMap(const flutter::EncodableValue& arguments,
154155
}
155156

156157
WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
157-
FlutterTextureRegistrar* texture_registrar, double width,
158+
flutter::TextureRegistrar* texture_registrar, double width,
158159
double height, flutter::EncodableMap& params)
159160
: PlatformView(registrar, viewId),
160161
texture_registrar_(texture_registrar),
161162
webview_instance_(nullptr),
162163
width_(width),
163164
height_(height),
164-
tbm_surface_(nullptr),
165+
candidate_surface_(nullptr),
166+
rendered_surface_(nullptr),
165167
is_mouse_lbutton_down_(false),
166168
has_navigation_delegate_(false),
167169
has_progress_tracking_(false),
168170
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_));
170179
InitWebView();
171180

172181
channel_ = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
@@ -375,7 +384,7 @@ std::string WebView::GetChannelName() {
375384
}
376385

377386
void WebView::Dispose() {
378-
FlutterUnregisterExternalTexture(texture_registrar_, GetTextureId());
387+
texture_registrar_->UnregisterTexture(GetTextureId());
379388

380389
if (webview_instance_) {
381390
webview_instance_->Destroy();
@@ -753,20 +762,18 @@ void WebView::InitWebView() {
753762
0, 0, width_, height_, scale_factor, "SamsungOneUI", "ko-KR",
754763
"Asia/Seoul",
755764
[this]() -> LWE::WebContainer::ExternalImageInfo {
765+
std::lock_guard<std::mutex> lock(mutex_);
756766
LWE::WebContainer::ExternalImageInfo result;
757-
if (!tbm_surface_) {
758-
tbm_surface_ =
767+
if (!candidate_surface_) {
768+
candidate_surface_ =
759769
tbm_surface_create(width_, height_, TBM_FORMAT_ARGB8888);
760770
}
761-
result.imageAddress = (void*)tbm_surface_;
771+
result.imageAddress = (void*)candidate_surface_;
762772
return result;
763773
},
764774
[this](LWE::WebContainer* c, bool isRendered) {
765775
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());
770777
}
771778
});
772779
#ifndef TV_PROFILE
@@ -900,3 +907,34 @@ void WebView::HandleCookieMethodCall(
900907
result->NotImplemented();
901908
}
902909
}
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+
}

packages/webview_flutter/tizen/src/webview.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
#include <flutter/standard_message_codec.h>
1111
#include <flutter/standard_method_codec.h>
1212
#include <flutter_platform_view.h>
13-
#include <flutter_tizen_texture_registrar.h>
1413
#include <tbm_surface.h>
1514

15+
#include <mutex>
16+
#include <stack>
17+
1618
namespace LWE {
1719
class WebContainer;
1820
}
@@ -22,7 +24,7 @@ class TextInputChannel;
2224
class WebView : public PlatformView {
2325
public:
2426
WebView(flutter::PluginRegistrar* registrar, int viewId,
25-
FlutterTextureRegistrar* textureRegistrar, double width,
27+
flutter::TextureRegistrar* textureRegistrar, double width,
2628
double height, flutter::EncodableMap& params);
2729
~WebView();
2830
virtual void Dispose() override;
@@ -46,6 +48,9 @@ class WebView : public PlatformView {
4648
void HidePanel();
4749
void ShowPanel();
4850

51+
FlutterDesktopGpuBuffer* CopyGpuBuffer(size_t width, size_t height);
52+
void Destruction(void* buffer);
53+
4954
private:
5055
void HandleMethodCall(
5156
const flutter::MethodCall<flutter::EncodableValue>& method_call,
@@ -59,16 +64,18 @@ class WebView : public PlatformView {
5964
void RegisterJavaScriptChannelName(const std::string& name);
6065
void ApplySettings(flutter::EncodableMap);
6166

62-
FlutterTextureRegistrar* texture_registrar_;
67+
flutter::TextureRegistrar* texture_registrar_;
6368
LWE::WebContainer* webview_instance_;
6469
double width_;
6570
double height_;
66-
tbm_surface_h tbm_surface_;
71+
tbm_surface_h candidate_surface_;
72+
tbm_surface_h rendered_surface_;
6773
bool is_mouse_lbutton_down_;
6874
bool has_navigation_delegate_;
6975
bool has_progress_tracking_;
7076
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;
7177
Ecore_IMF_Context* context_;
78+
std::mutex mutex_;
7279
};
7380

7481
#endif // FLUTTER_PLUGIN_WEBVIEW_FLUTTER_TIZEN_WEVIEW_H_

packages/webview_flutter/tizen/src/webview_factory.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "webview_flutter_tizen_plugin.h"
2323

2424
WebViewFactory::WebViewFactory(flutter::PluginRegistrar* registrar,
25-
FlutterTextureRegistrar* textureRegistrar)
25+
flutter::TextureRegistrar* textureRegistrar)
2626
: PlatformViewFactory(registrar), textureRegistrar_(textureRegistrar) {
2727
char* path = app_get_data_path();
2828
if (!path || strlen(path) == 0) {

packages/webview_flutter/tizen/src/webview_factory.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
class WebViewFactory : public PlatformViewFactory {
1010
public:
1111
WebViewFactory(flutter::PluginRegistrar* registrar,
12-
FlutterTextureRegistrar* textureRegistrar);
12+
flutter::TextureRegistrar* textureRegistrar);
1313
virtual void Dispose() override;
1414
virtual PlatformView* Create(
1515
int viewId, double width, double height,
1616
const std::vector<uint8_t>& createParams) override;
1717

1818
private:
19-
FlutterTextureRegistrar* textureRegistrar_;
19+
flutter::TextureRegistrar* textureRegistrar_;
2020
};
2121

2222
#endif // FLUTTER_PLUGIN_WEBVIEW_FLUTTER_TIZEN_WEVIEW_FACTORY_H_

packages/webview_flutter/tizen/src/webview_flutter_tizen_plugin.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void WebviewFlutterTizenPluginRegisterWithRegistrar(
3838
flutter::PluginRegistrarManager::GetInstance()
3939
->GetRegistrar<flutter::PluginRegistrar>(registrar);
4040
auto factory = std::make_unique<WebViewFactory>(
41-
core_registrar, FlutterPluginRegistrarGetTexture(registrar));
41+
core_registrar, core_registrar->texture_registrar());
4242
FlutterRegisterViewFactory(registrar, kViewType, std::move(factory));
4343
WebviewFlutterTizenPlugin::RegisterWithRegistrar(core_registrar);
4444
}

0 commit comments

Comments
 (0)