Skip to content

Commit 1fdf6cd

Browse files
committed
westeros backend : ensure paired execution of prepare and check callbacks
Change-Id: Ie533bba38945a7562ea7ce07eaabc58bd3c99003
1 parent 183aaad commit 1fdf6cd

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/westeros/renderer-backend.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class EventSource {
117117
GSource source;
118118
GPollFD pfd;
119119
struct wl_display* display;
120+
bool prepared;
120121
};
121122

122123
GSourceFuncs EventSource::sourceFuncs = {
@@ -126,6 +127,9 @@ GSourceFuncs EventSource::sourceFuncs = {
126127
auto* source = reinterpret_cast<EventSource*>(base);
127128
struct wl_display* display = source->display;
128129

130+
if (source->prepared)
131+
return FALSE;
132+
129133
*timeout = -1;
130134

131135
while (wl_display_prepare_read(display) != 0) {
@@ -136,6 +140,7 @@ GSourceFuncs EventSource::sourceFuncs = {
136140
}
137141
wl_display_flush(display);
138142

143+
source->prepared = true;
139144
return FALSE;
140145
},
141146
// check
@@ -144,14 +149,19 @@ GSourceFuncs EventSource::sourceFuncs = {
144149
auto* source = reinterpret_cast<EventSource*>(base);
145150
struct wl_display* display = source->display;
146151

152+
if (!source->prepared)
153+
return FALSE;
154+
147155
if (source->pfd.revents & G_IO_IN) {
148156
if (wl_display_read_events(display) < 0) {
149157
DEBUG_PRINT("Wayland::Display: error in wayland read\n");
150158
return FALSE;
151159
}
160+
source->prepared = false;
152161
return TRUE;
153162
} else {
154163
wl_display_cancel_read(display);
164+
source->prepared = false;
155165
return FALSE;
156166
}
157167
},
@@ -213,8 +223,7 @@ Backend::Backend()
213223

214224
Backend::~Backend()
215225
{
216-
if (m_eventSource)
217-
g_source_destroy(m_eventSource);
226+
invalidate();
218227

219228
if (m_compositor)
220229
wl_compositor_destroy(m_compositor);
@@ -227,6 +236,8 @@ Backend::~Backend()
227236
void Backend::invalidate()
228237
{
229238
if (m_eventSource) {
239+
if (m_eventSource->prepared && m_display)
240+
wl_display_cancel_read(m_display);
230241
g_source_destroy(m_eventSource);
231242
m_eventSource = nullptr;
232243
}
@@ -240,6 +251,7 @@ void Backend::initialize()
240251
m_eventSource = g_source_new(&EventSource::sourceFuncs, sizeof(EventSource));
241252
auto& source = *reinterpret_cast<EventSource*>(m_eventSource);
242253
source.display = m_display;
254+
source.prepared = false;
243255

244256
source.pfd.fd = wl_display_get_fd(m_display);
245257
source.pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP;

0 commit comments

Comments
 (0)