Skip to content

Commit 393c4e0

Browse files
wayland: fix "xdg_surface has never been configured" error (sony#336)
Fixed sony#330 Signed-off-by: Hidenori Matsubayashi <[email protected]>
1 parent 9b58e60 commit 393c4e0

File tree

2 files changed

+49
-43
lines changed

2 files changed

+49
-43
lines changed

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

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include <poll.h>
1010
#include <unistd.h>
1111
#include <xkbcommon/xkbcommon-keysyms.h>
12-
#include <algorithm>
1312

13+
#include <algorithm>
1414
#include <cassert>
1515
#include <cmath>
1616
#include <unordered_map>
@@ -68,6 +68,8 @@ const xdg_wm_base_listener ELinuxWindowWayland::kXdgWmBaseListener = {
6868
const xdg_surface_listener ELinuxWindowWayland::kXdgSurfaceListener = {
6969
.configure =
7070
[](void* data, xdg_surface* xdg_surface, uint32_t serial) {
71+
ELINUX_LOG(TRACE) << "xdg_surface_listener.configure";
72+
7173
auto self = reinterpret_cast<ELinuxWindowWayland*>(data);
7274
constexpr int32_t x = 0;
7375
int32_t y = 0;
@@ -81,6 +83,9 @@ const xdg_surface_listener ELinuxWindowWayland::kXdgSurfaceListener = {
8183
self->view_properties_.width,
8284
self->view_properties_.height);
8385
xdg_surface_ack_configure(xdg_surface, serial);
86+
if (self->wait_for_configure_) {
87+
self->wait_for_configure_ = false;
88+
}
8489
},
8590
};
8691

@@ -91,13 +96,17 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = {
9196
int32_t width,
9297
int32_t height,
9398
wl_array* states) {
99+
ELINUX_LOG(TRACE)
100+
<< "xdg_toplevel_listener.configure: " << width << ", " << height;
101+
94102
auto self = reinterpret_cast<ELinuxWindowWayland*>(data);
95103
if (self->current_rotation_ == 90 || self->current_rotation_ == 270) {
96104
std::swap(width, height);
97105
}
98106

99107
int32_t next_width = width;
100-
int32_t next_height = height;
108+
int32_t next_height =
109+
height - self->WindowDecorationsPhysicalHeight();
101110
if (self->restore_window_required_) {
102111
self->restore_window_required_ = false;
103112
next_width = self->restore_window_width_;
@@ -112,16 +121,7 @@ const xdg_toplevel_listener ELinuxWindowWayland::kXdgToplevelListener = {
112121

113122
self->view_properties_.width = next_width;
114123
self->view_properties_.height = next_height;
115-
if (self->window_decorations_) {
116-
self->window_decorations_->Resize(next_width, next_height,
117-
self->current_scale_);
118-
}
119-
if (self->binding_handler_delegate_) {
120-
self->binding_handler_delegate_->OnWindowSizeChanged(
121-
next_width * self->current_scale_,
122-
next_height * self->current_scale_ -
123-
self->WindowDecorationsPhysicalHeight());
124-
}
124+
self->request_redraw_ = true;
125125
},
126126
.close =
127127
[](void* data, xdg_toplevel* xdg_toplevel) {
@@ -582,17 +582,7 @@ const wl_output_listener ELinuxWindowWayland::kWlOutputListener = {
582582
FlutterDesktopViewMode::kFullscreen) {
583583
self->view_properties_.width = width;
584584
self->view_properties_.height = height;
585-
586-
if (self->window_decorations_) {
587-
int32_t width_dip = width / self->current_scale_;
588-
int32_t height_dip = height / self->current_scale_;
589-
self->window_decorations_->Resize(width_dip, height_dip,
590-
self->current_scale_);
591-
}
592-
593-
if (self->binding_handler_delegate_) {
594-
self->binding_handler_delegate_->OnWindowSizeChanged(width, height);
595-
}
585+
self->request_redraw_ = true;
596586
}
597587
}
598588
},
@@ -895,7 +885,6 @@ ELinuxWindowWayland::ELinuxWindowWayland(
895885
}
896886

897887
wl_registry_add_listener(wl_registry_, &kWlRegistryListener, this);
898-
wl_display_dispatch(wl_display_);
899888
wl_display_roundtrip(wl_display_);
900889

901890
if (wl_data_device_manager_ && wl_seat_) {
@@ -1085,6 +1074,20 @@ bool ELinuxWindowWayland::DispatchEvent() {
10851074
return false;
10861075
}
10871076

1077+
if (request_redraw_) {
1078+
request_redraw_ = false;
1079+
if (window_decorations_) {
1080+
window_decorations_->Resize(view_properties_.width,
1081+
view_properties_.height, current_scale_);
1082+
}
1083+
if (binding_handler_delegate_) {
1084+
binding_handler_delegate_->OnWindowSizeChanged(
1085+
view_properties_.width * current_scale_,
1086+
view_properties_.height * current_scale_ -
1087+
WindowDecorationsPhysicalHeight());
1088+
}
1089+
}
1090+
10881091
// Prepare to call wl_display_read_events.
10891092
while (wl_display_prepare_read(wl_display_) != 0) {
10901093
// If Wayland compositor terminates, -1 is returned.
@@ -1181,7 +1184,6 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px,
11811184
}
11821185
xdg_toplevel_add_listener(xdg_toplevel_, &kXdgToplevelListener, this);
11831186
wl_surface_set_buffer_scale(native_window_->Surface(), current_scale_);
1184-
wl_surface_commit(native_window_->Surface());
11851187

11861188
{
11871189
auto* callback = wl_surface_frame(native_window_->Surface());
@@ -1195,6 +1197,13 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px,
11951197
}
11961198
}
11971199

1200+
if (view_properties_.view_mode == FlutterDesktopViewMode::kFullscreen) {
1201+
xdg_toplevel_set_fullscreen(xdg_toplevel_, NULL);
1202+
}
1203+
1204+
wait_for_configure_ = true;
1205+
wl_surface_commit(native_window_->Surface());
1206+
11981207
render_surface_ = std::make_unique<SurfaceGl>(std::make_unique<ContextEgl>(
11991208
std::make_unique<EnvironmentEgl>(wl_display_)));
12001209
render_surface_->SetNativeWindow(native_window_.get());
@@ -1207,6 +1216,11 @@ bool ELinuxWindowWayland::CreateRenderSurface(int32_t width_px,
12071216
native_window_->Surface(), width_dip, height_dip, current_scale_);
12081217
}
12091218

1219+
// Wait for making sure that xdg_surface has been configured.
1220+
while (wait_for_configure_) {
1221+
wl_display_dispatch(wl_display_);
1222+
}
1223+
12101224
return true;
12111225
}
12121226

@@ -1575,7 +1589,7 @@ void ELinuxWindowWayland::DismissVirtualKeybaord() {
15751589
}
15761590

15771591
void ELinuxWindowWayland::UpdateWindowScale() {
1578-
if (this->view_properties_.force_scale_factor)
1592+
if (view_properties_.force_scale_factor)
15791593
return;
15801594

15811595
double scale_factor = 1.0;
@@ -1589,33 +1603,23 @@ void ELinuxWindowWayland::UpdateWindowScale() {
15891603
scale_factor = output_scale_factor;
15901604
}
15911605

1592-
if (this->current_scale_ == scale_factor)
1606+
if (current_scale_ == scale_factor) {
15931607
return;
1608+
}
15941609

15951610
ELINUX_LOG(TRACE) << "Window scale has changed: " << scale_factor;
1596-
this->current_scale_ = scale_factor;
1611+
current_scale_ = scale_factor;
15971612

15981613
wl_surface_set_buffer_scale(native_window_->Surface(), current_scale_);
1599-
1600-
if (this->window_decorations_) {
1601-
this->window_decorations_->Resize(this->view_properties_.width,
1602-
this->view_properties_.height,
1603-
this->current_scale_);
1604-
}
1605-
1606-
if (this->binding_handler_delegate_) {
1607-
this->binding_handler_delegate_->OnWindowSizeChanged(
1608-
this->view_properties_.width * this->current_scale_,
1609-
this->view_properties_.height * this->current_scale_ -
1610-
this->WindowDecorationsPhysicalHeight());
1611-
}
1614+
request_redraw_ = true;
16121615
}
16131616

16141617
uint32_t ELinuxWindowWayland::WindowDecorationsPhysicalHeight() const {
1615-
if (!this->window_decorations_)
1618+
if (!window_decorations_) {
16161619
return 0;
1620+
}
16171621

1618-
return this->window_decorations_->Height() * current_scale_;
1622+
return window_decorations_->Height() * current_scale_;
16191623
}
16201624

16211625
} // namespace flutter

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler {
145145

146146
bool display_valid_;
147147
bool running_;
148+
bool wait_for_configure_ = false;
149+
bool request_redraw_ = false;
148150
bool maximised_;
149151
uint32_t last_frame_time_;
150152

0 commit comments

Comments
 (0)