Skip to content

Commit 9905fa8

Browse files
authored
[webview_flutter] Update minor things (#118)
* [webview_flutter] Update minor things * Update lightweight web engine binary * Update version && change log * Enable resize function Signed-off-by: MuHong Byun <[email protected]> * [webview_flutter] Update minor things #2 * Update lightweightwebengine binary (aarch64/armel, tizen 5.5) * Introduce buffer pool Signed-off-by: MuHong Byun <[email protected]> * [webview_flutter] Apply review's commit Signed-off-by: MuHong Byun <[email protected]> * [webview_flutter] Apply review's commit #2 Signed-off-by: MuHong Byun <[email protected]>
1 parent 181a7a6 commit 9905fa8

10 files changed

+193
-22
lines changed

packages/webview_flutter/CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@
1010
* Update webivew_flutter to 2.0.4
1111

1212
## 0.2.1
13-
* Add lightweight web engine binary for arm64
13+
* Add lightweight web engine binary for arm64
14+
15+
## 0.2.2
16+
* Update lightweight web engine binary & header file (6263be6c888d5cb9dcca5466dfc3941a70b424eb)
17+
* Activate resizing function
18+
* Apply embedder's texture APIs change

packages/webview_flutter/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: webview_flutter_tizen
22
description: Tizen implementation of the webview plugin
33
homepage: https://github.com/flutter-tizen/plugins
4-
version: 0.2.1
4+
version: 0.2.2
55

66
environment:
77
sdk: ">=2.12.0 <3.0.0"

packages/webview_flutter/tizen/inc/lwe/LWEWebView.h

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class LWE_EXPORT Settings {
8383
void GetBaseForegroundColor(unsigned char& r, unsigned char& g,
8484
unsigned char& b, unsigned char& a) const;
8585
bool NeedsDownloadWebFontsEarly() const;
86+
bool UseHttp2() const;
8687
uint32_t NeedsDownScaleImageResourceLargerThan() const;
8788
void SetUserAgentString(const std::string& ua);
8889
void SetCacheMode(int mode);
@@ -97,6 +98,7 @@ class LWE_EXPORT Settings {
9798
void SetIdleModeJob(IdleModeJob j);
9899
void SetIdleModeCheckIntervalInMS(uint32_t intervalInMS);
99100
void SetNeedsDownloadWebFontsEarly(bool b);
101+
void SetUseHttp2(bool b);
100102
void SetNeedsDownScaleImageResourceLargerThan(
101103
uint32_t demention); // Experimental
102104

@@ -113,6 +115,7 @@ class LWE_EXPORT Settings {
113115
IdleModeJob m_idleModeJob; // default value is IdleModeJob::IdleModeFull
114116
uint32_t m_idleModeCheckIntervalInMS; // default value is 3000(ms)
115117
bool m_needsDownloadWebFontsEarly;
118+
bool m_useHttp2; // default value is false
116119
uint32_t m_needsDownScaleImageResourceLargerThan;
117120
};
118121

Binary file not shown.
Binary file not shown.

packages/webview_flutter/tizen/project_def.prop

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type = sharedLib
66
profile = common-5.5
77

88
# Source files
9-
USER_SRCS += src/webview_flutter_tizen_plugin.cc src/webview.cc src/webview_factory.cc
9+
USER_SRCS += src/*.cc
1010

1111
# User defines
1212
USER_DEFS =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "buffer_pool.h"
6+
7+
#include "log.h"
8+
9+
#define BUFFER_POOL_SIZE 5
10+
11+
BufferUnit::BufferUnit(int index, int width, int height)
12+
: isUsed_(false),
13+
index_(index),
14+
width_(0),
15+
height_(0),
16+
tbm_surface_(nullptr) {
17+
Reset(width, height);
18+
}
19+
20+
BufferUnit::~BufferUnit() {
21+
if (tbm_surface_) {
22+
tbm_surface_destroy(tbm_surface_);
23+
tbm_surface_ = nullptr;
24+
}
25+
}
26+
27+
bool BufferUnit::MarkInUse() {
28+
if (!isUsed_) {
29+
isUsed_ = true;
30+
return true;
31+
}
32+
return false;
33+
}
34+
35+
int BufferUnit::Index() { return index_; }
36+
37+
bool BufferUnit::IsUsed() { return isUsed_ && tbm_surface_; }
38+
39+
tbm_surface_h BufferUnit::Surface() {
40+
if (IsUsed()) {
41+
return tbm_surface_;
42+
}
43+
return nullptr;
44+
}
45+
46+
void BufferUnit::UnmarkInUse() { isUsed_ = false; }
47+
48+
void BufferUnit::Reset(int width, int height) {
49+
if (width_ == width && height_ == height) {
50+
return;
51+
}
52+
width_ = width;
53+
height_ = height;
54+
if (tbm_surface_) {
55+
tbm_surface_destroy(tbm_surface_);
56+
tbm_surface_ = nullptr;
57+
}
58+
tbm_surface_ = tbm_surface_create(width_, height_, TBM_FORMAT_ARGB8888);
59+
}
60+
61+
BufferPool::BufferPool(int width, int height) {
62+
for (int idx = 0; idx < BUFFER_POOL_SIZE; idx++) {
63+
pool_.emplace_back(new BufferUnit(idx, width, height));
64+
}
65+
Prepare(width, height);
66+
}
67+
68+
BufferPool::~BufferPool() {}
69+
70+
BufferUnit* BufferPool::Find(tbm_surface_h surface) {
71+
for (int idx = 0; idx < pool_.size(); idx++) {
72+
BufferUnit* buffer = pool_[idx].get();
73+
if (buffer->Surface() == surface) {
74+
return buffer;
75+
}
76+
}
77+
return nullptr;
78+
}
79+
80+
BufferUnit* BufferPool::GetAvailableBuffer() {
81+
std::lock_guard<std::mutex> lock(mutex_);
82+
for (int idx = 0; idx < pool_.size(); idx++) {
83+
BufferUnit* buffer = pool_[idx].get();
84+
if (buffer->MarkInUse()) {
85+
return buffer;
86+
}
87+
}
88+
return nullptr;
89+
}
90+
91+
void BufferPool::Release(BufferUnit* unit) {
92+
std::lock_guard<std::mutex> lock(mutex_);
93+
unit->UnmarkInUse();
94+
}
95+
96+
void BufferPool::Prepare(int width, int height) {
97+
std::lock_guard<std::mutex> lock(mutex_);
98+
for (int idx = 0; idx < pool_.size(); idx++) {
99+
BufferUnit* buffer = pool_[idx].get();
100+
buffer->Reset(width, height);
101+
}
102+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef FLUTTER_PLUGIN_WEBVIEW_FLUTTER_TIZEN_WEBVIEW_BUFFER_POOL_H_
6+
#define FLUTTER_PLUGIN_WEBVIEW_FLUTTER_TIZEN_WEBVIEW_BUFFER_POOL_H_
7+
8+
#include <tbm_surface.h>
9+
10+
#include <memory>
11+
#include <mutex>
12+
#include <string>
13+
#include <vector>
14+
15+
class BufferUnit {
16+
public:
17+
explicit BufferUnit(int index, int width, int height);
18+
~BufferUnit();
19+
void Reset(int width, int height);
20+
bool MarkInUse();
21+
void UnmarkInUse();
22+
int Index();
23+
bool IsUsed();
24+
tbm_surface_h Surface();
25+
26+
private:
27+
bool isUsed_;
28+
int index_;
29+
int width_;
30+
int height_;
31+
tbm_surface_h tbm_surface_;
32+
};
33+
34+
class BufferPool {
35+
public:
36+
explicit BufferPool(int width, int height);
37+
~BufferPool();
38+
39+
BufferUnit* GetAvailableBuffer();
40+
BufferUnit* Find(tbm_surface_h surface);
41+
void Release(BufferUnit* unit);
42+
void Prepare(int with, int height);
43+
44+
private:
45+
std::mutex mutex_;
46+
std::vector<std::unique_ptr<BufferUnit>> pool_;
47+
};
48+
49+
#endif

packages/webview_flutter/tizen/src/webview.cc

+26-17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <sstream>
1616
#include <string>
1717

18+
#include "buffer_pool.h"
1819
#include "log.h"
1920
#include "lwe/LWEWebView.h"
2021
#include "lwe/PlatformIntegrationData.h"
@@ -170,6 +171,7 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
170171
context_(nullptr),
171172
texture_variant_(nullptr),
172173
gpu_buffer_(nullptr) {
174+
tbm_pool_ = std::make_unique<BufferPool>(width, height);
173175
texture_variant_ = new flutter::TextureVariant(flutter::GpuBufferTexture(
174176
[this](size_t width, size_t height) -> const FlutterDesktopGpuBuffer* {
175177
return this->ObtainGpuBuffer(width, height);
@@ -404,7 +406,14 @@ void WebView::Dispose() {
404406

405407
void WebView::Resize(double width, double height) {
406408
LOG_DEBUG("WebView::Resize width: %f height: %f \n", width, height);
407-
// NOTE: Not supported by LWE on Tizen.
409+
width_ = width;
410+
height_ = height;
411+
412+
if (candidate_surface_) {
413+
candidate_surface_ = nullptr;
414+
}
415+
tbm_pool_->Prepare(width_, height_);
416+
webview_instance_->ResizeTo(width_, height_);
408417
}
409418

410419
void WebView::Touch(int type, int button, double x, double y, double dx,
@@ -779,10 +788,14 @@ void WebView::InitWebView() {
779788
std::lock_guard<std::mutex> lock(mutex_);
780789
LWE::WebContainer::ExternalImageInfo result;
781790
if (!candidate_surface_) {
782-
candidate_surface_ =
783-
tbm_surface_create(width_, height_, TBM_FORMAT_ARGB8888);
791+
candidate_surface_ = tbm_pool_->GetAvailableBuffer();
792+
}
793+
if (candidate_surface_) {
794+
result.imageAddress =
795+
static_cast<void*>(candidate_surface_->Surface());
796+
} else {
797+
result.imageAddress = nullptr;
784798
}
785-
result.imageAddress = (void*)candidate_surface_;
786799
return result;
787800
},
788801
[this](LWE::WebContainer* c, bool isRendered) {
@@ -924,20 +937,17 @@ void WebView::HandleCookieMethodCall(
924937

925938
FlutterDesktopGpuBuffer* WebView::ObtainGpuBuffer(size_t width, size_t height) {
926939
if (!candidate_surface_) {
927-
return nullptr;
940+
if (!rendered_surface_) {
941+
return nullptr;
942+
} else {
943+
return gpu_buffer_;
944+
}
928945
}
929-
930946
std::lock_guard<std::mutex> lock(mutex_);
931-
if (rendered_surface_) {
932-
tbm_surface_destroy(rendered_surface_);
933-
rendered_surface_ = nullptr;
934-
}
935-
936947
rendered_surface_ = candidate_surface_;
937948
candidate_surface_ = nullptr;
938-
939949
if (gpu_buffer_) {
940-
gpu_buffer_->buffer = rendered_surface_;
950+
gpu_buffer_->buffer = static_cast<void*>(rendered_surface_->Surface());
941951
gpu_buffer_->width = width;
942952
gpu_buffer_->height = height;
943953
}
@@ -946,10 +956,9 @@ FlutterDesktopGpuBuffer* WebView::ObtainGpuBuffer(size_t width, size_t height) {
946956

947957
void WebView::DestructBuffer(void* buffer) {
948958
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;
959+
BufferUnit* unit = tbm_pool_->Find((tbm_surface_h)buffer);
960+
if (unit) {
961+
tbm_pool_->Release(unit);
953962
}
954963
}
955964
}

packages/webview_flutter/tizen/src/webview.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class WebContainer;
2020
}
2121

2222
class TextInputChannel;
23+
class BufferPool;
24+
class BufferUnit;
2325

2426
class WebView : public PlatformView {
2527
public:
@@ -68,8 +70,8 @@ class WebView : public PlatformView {
6870
LWE::WebContainer* webview_instance_;
6971
double width_;
7072
double height_;
71-
tbm_surface_h candidate_surface_;
72-
tbm_surface_h rendered_surface_;
73+
BufferUnit* candidate_surface_;
74+
BufferUnit* rendered_surface_;
7375
bool is_mouse_lbutton_down_;
7476
bool has_navigation_delegate_;
7577
bool has_progress_tracking_;
@@ -78,6 +80,7 @@ class WebView : public PlatformView {
7880
flutter::TextureVariant* texture_variant_;
7981
FlutterDesktopGpuBuffer* gpu_buffer_;
8082
std::mutex mutex_;
83+
std::unique_ptr<BufferPool> tbm_pool_;
8184
};
8285

8386
#endif // FLUTTER_PLUGIN_WEBVIEW_FLUTTER_TIZEN_WEVIEW_H_

0 commit comments

Comments
 (0)