Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 50 additions & 12 deletions packages/webview_flutter/tizen/src/webview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include <Ecore_IMF_Evas.h>
#include <Ecore_Input_Evas.h>
#include <flutter_platform_view.h>
#include <flutter_tizen_texture_registrar.h>
#include <flutter_texture_registrar.h>
#include <texture_registrar.h>

#include <map>
#include <memory>
Expand Down Expand Up @@ -154,19 +155,27 @@ double ExtractDoubleFromMap(const flutter::EncodableValue& arguments,
}

WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
FlutterTextureRegistrar* texture_registrar, double width,
flutter::TextureRegistrar* texture_registrar, double width,
double height, flutter::EncodableMap& params)
: PlatformView(registrar, viewId),
texture_registrar_(texture_registrar),
webview_instance_(nullptr),
width_(width),
height_(height),
tbm_surface_(nullptr),
candidate_surface_(nullptr),
rendered_surface_(nullptr),
is_mouse_lbutton_down_(false),
has_navigation_delegate_(false),
has_progress_tracking_(false),
context_(nullptr) {
SetTextureId(FlutterRegisterExternalTexture(texture_registrar_));
flutter::TextureVariant* textureVariant_ =
new flutter::TextureVariant(flutter::GpuBufferTexture(
[this](size_t width,
size_t height) -> const FlutterDesktopGpuBuffer* {
return this->CopyGpuBuffer(width, height);
},
[this](void* buffer) -> void { this->Destruction(buffer); }));
SetTextureId(texture_registrar_->RegisterTexture(textureVariant_));
InitWebView();

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

void WebView::Dispose() {
FlutterUnregisterExternalTexture(texture_registrar_, GetTextureId());
texture_registrar_->UnregisterTexture(GetTextureId());

if (webview_instance_) {
webview_instance_->Destroy();
Expand Down Expand Up @@ -753,20 +762,18 @@ void WebView::InitWebView() {
0, 0, width_, height_, scale_factor, "SamsungOneUI", "ko-KR",
"Asia/Seoul",
[this]() -> LWE::WebContainer::ExternalImageInfo {
std::lock_guard<std::mutex> lock(mutex_);
LWE::WebContainer::ExternalImageInfo result;
if (!tbm_surface_) {
tbm_surface_ =
if (!candidate_surface_) {
candidate_surface_ =
tbm_surface_create(width_, height_, TBM_FORMAT_ARGB8888);
}
result.imageAddress = (void*)tbm_surface_;
result.imageAddress = (void*)candidate_surface_;
return result;
},
[this](LWE::WebContainer* c, bool isRendered) {
if (isRendered) {
FlutterMarkExternalTextureFrameAvailable(
texture_registrar_, GetTextureId(), tbm_surface_);
tbm_surface_destroy(tbm_surface_);
tbm_surface_ = nullptr;
texture_registrar_->MarkTextureFrameAvailable(GetTextureId());
}
});
#ifndef TV_PROFILE
Expand Down Expand Up @@ -900,3 +907,34 @@ void WebView::HandleCookieMethodCall(
result->NotImplemented();
}
}

FlutterDesktopGpuBuffer* WebView::CopyGpuBuffer(size_t width, size_t height) {
if (!candidate_surface_) {
return nullptr;
}

std::lock_guard<std::mutex> lock(mutex_);
if (rendered_surface_) {
tbm_surface_destroy(rendered_surface_);
rendered_surface_ = nullptr;
}

rendered_surface_ = candidate_surface_;
candidate_surface_ = nullptr;

FlutterDesktopGpuBuffer* gpuBuffer = new FlutterDesktopGpuBuffer();
gpuBuffer->buffer = rendered_surface_;
gpuBuffer->width = width;
gpuBuffer->height = height;
return gpuBuffer;
}

void WebView::Destruction(void* buffer) {
if (buffer) {
std::lock_guard<std::mutex> lock(mutex_);
tbm_surface_destroy((tbm_surface_h)buffer);
if (rendered_surface_ == buffer) {
rendered_surface_ = nullptr;
}
}
}
15 changes: 11 additions & 4 deletions packages/webview_flutter/tizen/src/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#include <flutter/standard_message_codec.h>
#include <flutter/standard_method_codec.h>
#include <flutter_platform_view.h>
#include <flutter_tizen_texture_registrar.h>
#include <tbm_surface.h>

#include <mutex>
#include <stack>

namespace LWE {
class WebContainer;
}
Expand All @@ -22,7 +24,7 @@ class TextInputChannel;
class WebView : public PlatformView {
public:
WebView(flutter::PluginRegistrar* registrar, int viewId,
FlutterTextureRegistrar* textureRegistrar, double width,
flutter::TextureRegistrar* textureRegistrar, double width,
double height, flutter::EncodableMap& params);
~WebView();
virtual void Dispose() override;
Expand All @@ -46,6 +48,9 @@ class WebView : public PlatformView {
void HidePanel();
void ShowPanel();

FlutterDesktopGpuBuffer* CopyGpuBuffer(size_t width, size_t height);
void Destruction(void* buffer);

private:
void HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue>& method_call,
Expand All @@ -59,16 +64,18 @@ class WebView : public PlatformView {
void RegisterJavaScriptChannelName(const std::string& name);
void ApplySettings(flutter::EncodableMap);

FlutterTextureRegistrar* texture_registrar_;
flutter::TextureRegistrar* texture_registrar_;
LWE::WebContainer* webview_instance_;
double width_;
double height_;
tbm_surface_h tbm_surface_;
tbm_surface_h candidate_surface_;
tbm_surface_h rendered_surface_;
bool is_mouse_lbutton_down_;
bool has_navigation_delegate_;
bool has_progress_tracking_;
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;
Ecore_IMF_Context* context_;
std::mutex mutex_;
};

#endif // FLUTTER_PLUGIN_WEBVIEW_FLUTTER_TIZEN_WEVIEW_H_
2 changes: 1 addition & 1 deletion packages/webview_flutter/tizen/src/webview_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "webview_flutter_tizen_plugin.h"

WebViewFactory::WebViewFactory(flutter::PluginRegistrar* registrar,
FlutterTextureRegistrar* textureRegistrar)
flutter::TextureRegistrar* textureRegistrar)
: PlatformViewFactory(registrar), textureRegistrar_(textureRegistrar) {
char* path = app_get_data_path();
if (!path || strlen(path) == 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/webview_flutter/tizen/src/webview_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
class WebViewFactory : public PlatformViewFactory {
public:
WebViewFactory(flutter::PluginRegistrar* registrar,
FlutterTextureRegistrar* textureRegistrar);
flutter::TextureRegistrar* textureRegistrar);
virtual void Dispose() override;
virtual PlatformView* Create(
int viewId, double width, double height,
const std::vector<uint8_t>& createParams) override;

private:
FlutterTextureRegistrar* textureRegistrar_;
flutter::TextureRegistrar* textureRegistrar_;
};

#endif // FLUTTER_PLUGIN_WEBVIEW_FLUTTER_TIZEN_WEVIEW_FACTORY_H_
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void WebviewFlutterTizenPluginRegisterWithRegistrar(
flutter::PluginRegistrarManager::GetInstance()
->GetRegistrar<flutter::PluginRegistrar>(registrar);
auto factory = std::make_unique<WebViewFactory>(
core_registrar, FlutterPluginRegistrarGetTexture(registrar));
core_registrar, core_registrar->texture_registrar());
FlutterRegisterViewFactory(registrar, kViewType, std::move(factory));
WebviewFlutterTizenPlugin::RegisterWithRegistrar(core_registrar);
}