Skip to content

Commit c08d8cf

Browse files
committed
stuff 3
1 parent a48dc5b commit c08d8cf

4 files changed

Lines changed: 63 additions & 33 deletions

File tree

src/ruisapp/glue/android/window.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void native_window::bind_rendering_context()
6262
if (!this->egl_dummy_surface.has_value()) {
6363
this->egl_dummy_surface.emplace(
6464
this->egl_display, //
65-
egl_config
65+
this->egl_config
6666
);
6767
}
6868
eglMakeCurrent(

src/ruisapp/glue/linux/wayland/window.hxx

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ class native_window : public ruis::render::native_window
4343
wayland_egl_window_wrapper wayland_egl_window;
4444

4545
egl_config_wrapper egl_config;
46-
egl_surface_wrapper egl_surface;
4746
egl_context_wrapper egl_context;
4847

48+
std::optional<egl_pbuffer_surface_wrapper> egl_dummy_surface;
49+
std::optional<egl_surface_wrapper> egl_surface;
50+
4951
wayland_surface_wrapper::scale_and_dpi scale_and_dpi;
5052

5153
public:
@@ -91,11 +93,6 @@ public:
9193
gl_version,
9294
window_params
9395
),
94-
egl_surface(
95-
this->display.get().egl_display, //
96-
this->egl_config,
97-
this->wayland_egl_window.window
98-
),
9996
egl_context(
10097
this->display.get().egl_display, //
10198
gl_version,
@@ -125,21 +122,59 @@ public:
125122
return this->wayland_surface.surface;
126123
}
127124

125+
void create_egl_surface()
126+
{
127+
this->egl_surface.emplace(
128+
this->display.get().egl_display, //
129+
this->egl_config,
130+
this->wayland_egl_window.window
131+
);
132+
}
133+
128134
void swap_frame_buffers() override
129135
{
130-
this->egl_surface.swap_frame_buffers();
136+
if (this->egl_surface.has_value()) {
137+
this->egl_surface.value().swap_frame_buffers();
138+
}
131139
}
132140

133141
void bind_rendering_context() override
134142
{
135-
if (eglMakeCurrent(
136-
this->display.get().egl_display.display,
137-
this->egl_surface.surface,
138-
this->egl_surface.surface,
139-
this->egl_context.context
140-
) == EGL_FALSE)
141-
{
142-
throw std::runtime_error("eglMakeCurrent() failed");
143+
auto& egl_display = this->display.get().egl_display;
144+
145+
if (this->egl_surface.has_value()) {
146+
if (eglMakeCurrent(
147+
egl_display.display,
148+
this->egl_surface.value().surface,
149+
this->egl_surface.value().surface,
150+
this->egl_context.context
151+
) == EGL_FALSE)
152+
{
153+
throw std::runtime_error("eglMakeCurrent() failed");
154+
}
155+
} else {
156+
if (egl_display.extensions.get(egl::extension::khr_surfaceless_context)) {
157+
eglMakeCurrent(
158+
egl_display.display, //
159+
EGL_NO_SURFACE,
160+
EGL_NO_SURFACE,
161+
this->egl_context.context
162+
);
163+
} else {
164+
// KHR_surfaceless_context EGL extension is not available, create a dummy pbuffer surface to make the context current
165+
if (!this->egl_dummy_surface.has_value()) {
166+
this->egl_dummy_surface.emplace(
167+
egl_display, //
168+
this->egl_config
169+
);
170+
}
171+
eglMakeCurrent(
172+
egl_display.display, //
173+
this->egl_dummy_surface.value().surface,
174+
this->egl_dummy_surface.value().surface,
175+
this->egl_context.context
176+
);
177+
}
143178
}
144179
}
145180

src/ruisapp/glue/linux/wayland/xdg_surface.cxx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,19 @@ void xdg_surface_wrapper::xdg_surface_configure(
4242
o << "xgd_surface: CONFIGURE for surface id = " << id << std::endl;
4343
});
4444

45-
// Wayland protocol requires to acknowledge the configure event
45+
// Wayland protocol requires to acknowledge the configure event
4646
xdg_surface_ack_configure(
4747
surface, //
4848
serial
4949
);
5050

51+
// The configure callback is invoked by Wayland after initial toplevel configure has been invoked.
52+
// Right after creating a Wayland surface, according to the Wayland protocol, it
53+
// should do the initial configure call, after which one is supposed to do the
54+
// initial surface commit. In case of EGL we have to call eglSwapBuffers(), which will do the
55+
// surface commit for us. This makes the surface to be mapped to the screen and become visible.
56+
// If this sequence is not honored the surface will not appear on the screen.
57+
5158
auto& glue = get_glue();
5259

5360
auto window = glue.get_window(self.wayland_surface.surface);
@@ -58,12 +65,14 @@ void xdg_surface_wrapper::xdg_surface_configure(
5865
}
5966

6067
auto& win = *window;
61-
auto& natwin = win.ruis_native_window.get();
68+
auto& natwin = win.ruis_native_window.get();
69+
70+
natwin.create_egl_surface();
6271

6372
// swap EGL frame buffers with the window's EGL context made current
6473
win.gui.context.get().ren().ctx().apply([&]() {
6574
natwin.swap_frame_buffers();
6675
});
6776

68-
self.wayland_surface.commit();
77+
// self.wayland_surface.commit();
6978
}

src/ruisapp/glue/linux/wayland/xdg_toplevel.cxx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,8 @@ void xdg_toplevel_wrapper::xdg_toplevel_configure(
157157
// if both width and height are zero, then it is a state change
158158
if (width == 0 && height == 0) {
159159
if (states_span.empty()) {
160-
// The configure callback is invoked with both dimensions 0
161-
// and no any state changes. This means that it is an initial configure call.
162-
// Right after creating a Wayland surface, according to the Wayland protocol, it
163-
// should do the initial configure call, after which one is supposed to do the
164-
// initial surface commit. In case of EGL we have to call eglSwapBuffers(), which will do the
165-
// surface commit for us. This makes the surface to be mapped to the screen and become visible.
166-
// If this sequence is not honored the surface will not appear on the screen.
167-
168160
utki::logcat_debug(" initial configure call", '\n');
169161

170-
// swap EGL frame buffers with the window's EGL context made current
171-
// win.gui.context.get().ren().ctx().apply([&]() {
172-
// natwin.swap_frame_buffers();
173-
// });
174-
175-
// self.wayland_surface.commit();
176162
return;
177163
}
178164

0 commit comments

Comments
 (0)