Skip to content

Commit 549415f

Browse files
wayland: add notification of display changes to embedder (sony#374)
This change adds notification of display changes to embedder support in Wayland backend. Signed-off-by: Hidenori Matsubayashi <[email protected]>
1 parent 7f83ccb commit 549415f

File tree

10 files changed

+66
-14
lines changed

10 files changed

+66
-14
lines changed

src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,12 @@ void FlutterELinuxEngine::UpdateAccessibilityFeatures(
440440
embedder_api_.UpdateAccessibilityFeatures(engine_, flags);
441441
}
442442

443+
void FlutterELinuxEngine::UpdateDisplayInfo(
444+
FlutterEngineDisplaysUpdateType update_type,
445+
const FlutterEngineDisplay* displays,
446+
size_t display_count) {
447+
embedder_api_.NotifyDisplayUpdate(engine_, update_type, displays,
448+
display_count);
449+
}
450+
443451
} // namespace flutter

src/flutter/shell/platform/linux_embedded/flutter_elinux_engine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ class FlutterELinuxEngine {
133133
// Updates accessibility, e.g. switch to high contrast mode
134134
void UpdateAccessibilityFeatures(FlutterAccessibilityFeature flags);
135135

136+
// Update display information.
137+
void UpdateDisplayInfo(FlutterEngineDisplaysUpdateType update_type,
138+
const FlutterEngineDisplay* displays,
139+
size_t display_count);
140+
136141
private:
137142
// Allows swapping out embedder_api_ calls in tests.
138143
friend class EngineEmbedderApiModifier;

src/flutter/shell/platform/linux_embedded/flutter_elinux_view.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,4 +560,23 @@ void FlutterELinuxView::UpdateTextScaleFactor(float factor) {
560560
settings_handler_->UpdateTextScaleFactor(factor);
561561
}
562562

563+
void FlutterELinuxView::UpdateDisplayInfo(double refresh_rate,
564+
size_t width_px,
565+
size_t height_px,
566+
double pixel_ratio) {
567+
const FlutterEngineDisplaysUpdateType update_type =
568+
kFlutterEngineDisplaysUpdateTypeStartup;
569+
const FlutterEngineDisplay displays = {
570+
.struct_size = sizeof(FlutterEngineDisplay),
571+
.display_id = 0,
572+
.single_display = true,
573+
.refresh_rate = refresh_rate,
574+
.width = width_px,
575+
.height = height_px,
576+
.device_pixel_ratio = pixel_ratio,
577+
};
578+
const size_t display_count = 1;
579+
engine_.get()->UpdateDisplayInfo(update_type, &displays, display_count);
580+
}
581+
563582
} // namespace flutter

src/flutter/shell/platform/linux_embedded/flutter_elinux_view.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ class FlutterELinuxView : public WindowBindingHandlerDelegate {
151151
// |WindowBindingHandlerDelegate|
152152
void UpdateTextScaleFactor(float factor) override;
153153

154+
// |WindowBindingHandlerDelegate|
155+
void UpdateDisplayInfo(double refresh_rate,
156+
size_t width_px,
157+
size_t height_px,
158+
double pixel_ratio) override;
159+
154160
private:
155161
// Struct holding the mouse state. The engine doesn't keep track of which
156162
// mouse buttons have been pressed, so it's the embedding's responsibility.

src/flutter/shell/platform/linux_embedded/window/elinux_window.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#ifndef FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_ELINUX_WINDOW_H_
66
#define FLUTTER_SHELL_PLATFORM_LINUX_EMBEDDED_WINDOW_ELINUX_WINDOW_H_
77

8+
#include <cmath>
9+
810
#include "flutter/shell/platform/linux_embedded/public/flutter_elinux.h"
11+
#include "flutter/shell/platform/linux_embedded/window_binding_handler.h"
912

1013
namespace flutter {
1114

@@ -39,9 +42,23 @@ class ELinuxWindow {
3942
}
4043
}
4144

45+
void NotifyDisplayInfoUpdates() const {
46+
if (binding_handler_delegate_) {
47+
binding_handler_delegate_->UpdateDisplayInfo(
48+
std::trunc(1000000.0 / frame_rate_), GetCurrentWidth(),
49+
GetCurrentHeight(), current_scale_);
50+
}
51+
}
52+
4253
FlutterDesktopViewProperties view_properties_;
54+
55+
// A pointer to a FlutterWindowsView that can be used to update engine
56+
// windowing and input state.
57+
WindowBindingHandlerDelegate* binding_handler_delegate_ = nullptr;
58+
4359
int32_t display_max_width_ = -1;
4460
int32_t display_max_height_ = -1;
61+
int32_t frame_rate_ = 60000;
4562
double current_scale_ = 1.0;
4663
uint16_t current_rotation_ = 0;
4764
// The x coordinate of the pointer in physical pixels.

src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,6 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler {
708708
bool is_pointer_device;
709709
};
710710

711-
// A pointer to a FlutterWindowsView that can be used to update engine
712-
// windowing and input state.
713-
WindowBindingHandlerDelegate* binding_handler_delegate_ = nullptr;
714-
715711
std::unique_ptr<T> native_window_;
716712
std::unique_ptr<SurfaceGl> render_surface_;
717713

src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,6 @@ ELinuxWindowWayland::ELinuxWindowWayland(
10411041
zwp_text_input_v3_(nullptr),
10421042
wp_presentation_(nullptr),
10431043
wp_presentation_clk_id_(UINT32_MAX),
1044-
frame_rate_(60000),
10451044
window_decorations_(nullptr) {
10461045
view_properties_ = view_properties;
10471046
current_scale_ =
@@ -1281,6 +1280,7 @@ bool ELinuxWindowWayland::DispatchEvent() {
12811280
view_properties_.height * current_scale_ -
12821281
WindowDecorationsPhysicalHeight());
12831282
}
1283+
NotifyDisplayInfoUpdates();
12841284
}
12851285

12861286
// Prepare to call wl_display_read_events.

src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler {
135135
kZxdgToplevelDecorationV1Listener;
136136
static constexpr size_t kDefaultPointerSize = 24;
137137

138-
// A pointer to a FlutterWindowsView that can be used to update engine
139-
// windowing and input state.
140-
WindowBindingHandlerDelegate* binding_handler_delegate_ = nullptr;
141-
142138
std::unique_ptr<NativeWindowWayland> native_window_;
143139
std::unique_ptr<SurfaceGl> render_surface_;
144140

@@ -189,7 +185,6 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler {
189185
wp_presentation* wp_presentation_;
190186
uint32_t wp_presentation_clk_id_;
191187
uint64_t last_frame_time_nanos_;
192-
int32_t frame_rate_;
193188

194189
CursorInfo cursor_info_;
195190
size_t cursor_size_;

src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ class ELinuxWindowX11 : public ELinuxWindow, public WindowBindingHandler {
7070
int16_t x,
7171
int16_t y);
7272

73-
// A pointer to a FlutterWindowsView that can be used to update engine
74-
// windowing and input state.
75-
WindowBindingHandlerDelegate* binding_handler_delegate_ = nullptr;
76-
7773
Display* display_ = nullptr;
7874
std::unique_ptr<NativeWindowX11> native_window_;
7975
std::unique_ptr<SurfaceGl> render_surface_;

src/flutter/shell/platform/linux_embedded/window_binding_handler_delegate.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ class WindowBindingHandlerDelegate {
110110

111111
// Update the status of the text scaling factor feature
112112
virtual void UpdateTextScaleFactor(float factor) = 0;
113+
114+
// Update the status of the corresponding to display changes.
115+
// @param[in] refresh_rate Refresh rate of the display.
116+
// @param[in] width_px Physical width of the display.
117+
// @param[in] height_px Physical height of the display.
118+
// @param[in] pixel_ratio Pixel ratio of the display.
119+
virtual void UpdateDisplayInfo(double refresh_rate,
120+
size_t width_px,
121+
size_t height_px,
122+
double pixel_ratio) = 0;
113123
};
114124

115125
} // namespace flutter

0 commit comments

Comments
 (0)