Skip to content

Commit 2bf6ad7

Browse files
authored
Provide monitor information (#90)
1 parent 52b1409 commit 2bf6ad7

File tree

9 files changed

+158
-23
lines changed

9 files changed

+158
-23
lines changed

flutter/shell/platform/tizen/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ template("embedder") {
104104
"flutter_platform_node_delegate_tizen.cc",
105105
"flutter_project_bundle.cc",
106106
"flutter_tizen.cc",
107+
"flutter_tizen_display_monitor.cc",
107108
"flutter_tizen_elementary.cc",
108109
"flutter_tizen_engine.cc",
109110
"flutter_tizen_texture_registrar.cc",
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2025 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Copyright 2013 The Flutter Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
6+
#include <Ecore.h>
7+
#include <system_info.h>
8+
9+
#include "flutter/shell/platform/tizen/flutter_tizen_display_monitor.h"
10+
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
11+
#include "flutter/shell/platform/tizen/flutter_tizen_view.h"
12+
#include "flutter/shell/platform/tizen/system_utils.h"
13+
14+
namespace flutter {
15+
16+
FlutterTizenDisplayMonitor::FlutterTizenDisplayMonitor(
17+
FlutterTizenEngine* engine)
18+
: engine_(engine) {}
19+
20+
FlutterTizenDisplayMonitor::~FlutterTizenDisplayMonitor() {}
21+
22+
void FlutterTizenDisplayMonitor::UpdateDisplays() {
23+
// TODO: Currently Tizen only supports one display device.
24+
// So, if Tizen supports multiple displays in the future, please implement to
25+
// get information about multiple displays.
26+
27+
FlutterEngineDisplay display = {};
28+
display.struct_size = sizeof(FlutterEngineDisplay);
29+
display.display_id = 0;
30+
display.single_display = true;
31+
32+
double fps = ecore_animator_frametime_get();
33+
if (fps <= 0.0) {
34+
display.refresh_rate = 0.0;
35+
} else {
36+
display.refresh_rate = 1 / fps;
37+
}
38+
39+
int32_t width = 0, height = 0, dpi = 0;
40+
FlutterTizenView* view = engine_->view();
41+
if (view) {
42+
TizenGeometry geometry = view->tizen_view()->GetGeometry();
43+
width = geometry.width;
44+
height = geometry.height;
45+
dpi = view->tizen_view()->GetDpi();
46+
} else {
47+
system_info_get_platform_int("http://tizen.org/feature/screen.width",
48+
&width);
49+
system_info_get_platform_int("http://tizen.org/feature/screen.height",
50+
&height);
51+
system_info_get_platform_int("http://tizen.org/feature/screen.dpi", &dpi);
52+
}
53+
54+
display.width = width;
55+
display.height = height;
56+
display.device_pixel_ratio = ComputePixelRatio(dpi);
57+
58+
std::vector<FlutterEngineDisplay> displays = {display};
59+
engine_->UpdateDisplay(displays);
60+
}
61+
62+
} // namespace flutter
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2025 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Copyright 2013 The Flutter Authors. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
6+
#ifndef EMBEDDER_FLUTTER_TIZEN_DISPLAY_MONITOR_H_
7+
#define EMBEDDER_FLUTTER_TIZEN_DISPLAY_MONITOR_H_
8+
9+
namespace flutter {
10+
11+
class FlutterTizenEngine;
12+
class FlutterTizenDisplayMonitor {
13+
public:
14+
FlutterTizenDisplayMonitor(FlutterTizenEngine* engine);
15+
~FlutterTizenDisplayMonitor();
16+
17+
// Updates the display information and notifies the engine
18+
void UpdateDisplays();
19+
20+
private:
21+
FlutterTizenEngine* engine_;
22+
};
23+
} // namespace flutter
24+
25+
#endif // EMBEDDER_FLUTTER_TIZEN_DISPLAY_MONITOR_H_

flutter/shell/platform/tizen/flutter_tizen_engine.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "flutter/shell/platform/tizen/accessibility_bridge_tizen.h"
1313
#include "flutter/shell/platform/tizen/flutter_platform_node_delegate_tizen.h"
14+
#include "flutter/shell/platform/tizen/flutter_tizen_display_monitor.h"
1415
#include "flutter/shell/platform/tizen/flutter_tizen_view.h"
1516
#include "flutter/shell/platform/tizen/logger.h"
1617
#include "flutter/shell/platform/tizen/system_utils.h"
@@ -70,6 +71,8 @@ FlutterTizenEngine::FlutterTizenEngine(const FlutterProjectBundle& project)
7071

7172
plugin_registrar_ = std::make_unique<FlutterDesktopPluginRegistrar>();
7273
plugin_registrar_->engine = this;
74+
75+
display_monitor_ = std::make_unique<FlutterTizenDisplayMonitor>(this);
7376
}
7477

7578
FlutterTizenEngine::~FlutterTizenEngine() {
@@ -253,11 +256,22 @@ bool FlutterTizenEngine::RunEngine() {
253256

254257
accessibility_settings_ = std::make_unique<AccessibilitySettings>(this);
255258

259+
display_monitor_->UpdateDisplays();
260+
256261
SetupLocales();
257262

258263
return true;
259264
}
260265

266+
void FlutterTizenEngine::UpdateDisplay(
267+
const std::vector<FlutterEngineDisplay>& displays) {
268+
if (engine_) {
269+
embedder_api_.NotifyDisplayUpdate(engine_,
270+
kFlutterEngineDisplaysUpdateTypeStartup,
271+
displays.data(), displays.size());
272+
}
273+
}
274+
261275
bool FlutterTizenEngine::StopEngine() {
262276
if (engine_) {
263277
for (const auto& [callback, registrar] :

flutter/shell/platform/tizen/flutter_tizen_engine.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "flutter/shell/platform/tizen/channels/platform_view_channel.h"
2222
#include "flutter/shell/platform/tizen/channels/settings_channel.h"
2323
#include "flutter/shell/platform/tizen/flutter_project_bundle.h"
24+
#include "flutter/shell/platform/tizen/flutter_tizen_display_monitor.h"
2425
#include "flutter/shell/platform/tizen/flutter_tizen_texture_registrar.h"
2526
#include "flutter/shell/platform/tizen/public/flutter_tizen.h"
2627
#include "flutter/shell/platform/tizen/tizen_event_loop.h"
@@ -179,6 +180,9 @@ class FlutterTizenEngine {
179180
// Notifies the engine about enabled accessibility features.
180181
void UpdateAccessibilityFeatures(bool invert_colors, bool high_contrast);
181182

183+
// Notifies the engine about a display update.
184+
void UpdateDisplay(const std::vector<FlutterEngineDisplay>& displays);
185+
182186
private:
183187
friend class EngineModifier;
184188

@@ -269,6 +273,9 @@ class FlutterTizenEngine {
269273

270274
// The vsync waiter for the embedder.
271275
std::unique_ptr<TizenVsyncWaiter> vsync_waiter_;
276+
277+
// The display monitor.
278+
std::unique_ptr<FlutterTizenDisplayMonitor> display_monitor_;
272279
};
273280

274281
} // namespace flutter

flutter/shell/platform/tizen/flutter_tizen_engine_unittest.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) {
6969
return kSuccess;
7070
}));
7171

72+
bool notify_display_update_called = false;
73+
modifier.embedder_api().NotifyDisplayUpdate = MOCK_ENGINE_PROC(
74+
NotifyDisplayUpdate,
75+
([&notify_display_update_called](
76+
auto engine, FlutterEngineDisplaysUpdateType update_type,
77+
const FlutterEngineDisplay* displays, size_t display_count) {
78+
notify_display_update_called = true;
79+
EXPECT_GE(display_count, (size_t)1);
80+
EXPECT_EQ(update_type, kFlutterEngineDisplaysUpdateTypeStartup);
81+
EXPECT_NE(displays, nullptr);
82+
83+
return kSuccess;
84+
}));
85+
7286
// It should send locale info.
7387
bool update_locales_called = false;
7488
modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC(
@@ -97,6 +111,7 @@ TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) {
97111
engine_->RunEngine();
98112

99113
EXPECT_TRUE(run_called);
114+
EXPECT_TRUE(notify_display_update_called);
100115
EXPECT_TRUE(update_locales_called);
101116
EXPECT_TRUE(settings_message_sent);
102117
EXPECT_NE(engine_->plugin_registrar(), nullptr);
@@ -198,6 +213,12 @@ TEST_F(FlutterTizenEngineTest, AddPluginRegistrarDestructionCallback) {
198213
return kSuccess;
199214
}));
200215

216+
modifier.embedder_api().NotifyDisplayUpdate = MOCK_ENGINE_PROC(
217+
NotifyDisplayUpdate,
218+
([](auto engine, FlutterEngineDisplaysUpdateType update_type,
219+
const FlutterEngineDisplay* displays,
220+
size_t display_count) { return kSuccess; }));
221+
201222
// Stub out UpdateLocales and SendPlatformMessage as we don't have a fully
202223
// initialized engine instance.
203224
modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC(

flutter/shell/platform/tizen/flutter_tizen_view.cc

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "flutter_tizen_view.h"
77

88
#include "flutter/shell/platform/tizen/logger.h"
9+
#include "flutter/shell/platform/tizen/system_utils.h"
910
#include "flutter/shell/platform/tizen/tizen_view.h"
1011
#ifdef NUI_SUPPORT
1112
#include "flutter/shell/platform/tizen/tizen_view_nui.h"
@@ -15,14 +16,6 @@
1516

1617
namespace {
1718

18-
#if defined(MOBILE_PROFILE)
19-
constexpr double kProfileFactor = 0.7;
20-
#elif defined(TV_PROFILE)
21-
constexpr double kProfileFactor = 2.0;
22-
#else
23-
constexpr double kProfileFactor = 1.0;
24-
#endif
25-
2619
constexpr char kSysMenuKey[] = "XF86SysMenu";
2720
constexpr char kBackKey[] = "XF86Back";
2821
constexpr char kExitKey[] = "XF86Exit";
@@ -45,19 +38,6 @@ const std::vector<std::string> kBindableSystemKeys = {
4538
// (ui/events/x/events_x_utils.cc).
4639
constexpr int32_t kScrollOffsetMultiplier = 53;
4740

48-
double ComputePixelRatio(flutter::TizenViewBase* view) {
49-
// The scale factor is computed based on the display DPI and the current
50-
// profile. A fixed DPI value (72) is used on TVs. See:
51-
// https://docs.tizen.org/application/native/guides/ui/efl/multiple-screens
52-
#ifdef TV_PROFILE
53-
double dpi = 72.0;
54-
#else
55-
double dpi = static_cast<double>(view->GetDpi());
56-
#endif
57-
double scale_factor = dpi / 90.0 * kProfileFactor;
58-
return std::max(scale_factor, 1.0);
59-
}
60-
6141
} // namespace
6242

6343
namespace flutter {
@@ -103,7 +83,7 @@ void FlutterTizenView::SetEngine(std::unique_ptr<FlutterTizenEngine> engine) {
10383

10484
double pixel_ratio;
10585
if (user_pixel_ratio_ == 0.0) {
106-
pixel_ratio = ComputePixelRatio(tizen_view_.get());
86+
pixel_ratio = ComputePixelRatio(tizen_view_->GetDpi());
10787
} else {
10888
pixel_ratio = user_pixel_ratio_;
10989
}
@@ -407,7 +387,7 @@ void FlutterTizenView::SendWindowMetrics(int32_t left,
407387
double pixel_ratio) {
408388
if (pixel_ratio == 0.0) {
409389
if (user_pixel_ratio_ == 0.0) {
410-
pixel_ratio = ComputePixelRatio(tizen_view_.get());
390+
pixel_ratio = ComputePixelRatio(tizen_view_->GetDpi());
411391
} else {
412392
pixel_ratio = user_pixel_ratio_;
413393
}

flutter/shell/platform/tizen/system_utils.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,27 @@
1010

1111
namespace flutter {
1212

13+
#if defined(MOBILE_PROFILE)
14+
constexpr double kProfileFactor = 0.7;
15+
#elif defined(TV_PROFILE)
16+
constexpr double kProfileFactor = 2.0;
17+
#else
18+
constexpr double kProfileFactor = 1.0;
19+
#endif
20+
21+
double ComputePixelRatio(int32_t screen_dpi) {
22+
// The scale factor is computed based on the display DPI and the current
23+
// profile. A fixed DPI value (72) is used on TVs. See:
24+
// https://docs.tizen.org/application/native/guides/ui/efl/multiple-screens
25+
#ifdef TV_PROFILE
26+
double dpi = 72.0;
27+
#else
28+
double dpi = static_cast<double>(screen_dpi);
29+
#endif
30+
double scale_factor = dpi / 90.0 * kProfileFactor;
31+
return std::max(scale_factor, 1.0);
32+
}
33+
1334
std::vector<LanguageInfo> GetPreferredLanguageInfo() {
1435
std::vector<LanguageInfo> languages;
1536
const char* locale;

flutter/shell/platform/tizen/system_utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ struct LanguageInfo {
1818
std::string variant;
1919
};
2020

21+
// Returns the scale factor calculated based on the display DPI and the current
22+
// profile.
23+
double ComputePixelRatio(int32_t screen_dpi);
24+
2125
// Returns the list of user-preferred locales, in preference order,
2226
// parsed into LanguageInfo structures.
2327
std::vector<LanguageInfo> GetPreferredLanguageInfo();

0 commit comments

Comments
 (0)