29#include <vulkan/vulkan.h>
30#include <vulkan/vulkan_wayland.h>
35#include <wayland-client.h>
36#include "xdg-shell-client-protocol.h"
37#include "xdg-decoration-client-protocol.h"
38#include "viewporter-client-protocol.h"
39#include "cursor-shape-client-protocol.h"
40#include <xkbcommon/xkbcommon.h>
52int32_t GPUDisplayFrontendWayland::GetKey(uint32_t
key, uint32_t state)
59 xkb_keysym_t sym = xkb_state_key_get_one_sym(mXKBstate,
key + 8);
60 if (sym == XKB_KEY_KP_Subtract) {
62 }
else if (sym == XKB_KEY_KP_Add) {
64 }
else if (sym == XKB_KEY_Shift_L || sym == XKB_KEY_Shift_R) {
66 }
else if (sym == XKB_KEY_Alt_L) {
68 }
else if (sym == XKB_KEY_ISO_Level3_Shift || sym == XKB_KEY_Alt_R) {
70 }
else if (sym == XKB_KEY_Control_L) {
72 }
else if (sym == XKB_KEY_Control_R) {
74 }
else if (sym == XKB_KEY_Up) {
76 }
else if (sym == XKB_KEY_Down) {
78 }
else if (sym == XKB_KEY_Left) {
80 }
else if (sym == XKB_KEY_Right) {
82 }
else if (sym == XKB_KEY_Page_Up) {
84 }
else if (sym == XKB_KEY_Page_Down) {
85 return (KEY_PAGEDOWN);
86 }
else if (sym == XKB_KEY_Escape) {
88 }
else if (sym == XKB_KEY_Return) {
90 }
else if (sym == XKB_KEY_End) {
92 }
else if (sym == XKB_KEY_Home) {
94 }
else if (sym == XKB_KEY_Insert) {
96 }
else if (sym == XKB_KEY_BackSpace) {
97 return (KEY_BACKSPACE);
98 }
else if (sym == XKB_KEY_Delete) {
100 }
else if (sym == XKB_KEY_F1) {
102 }
else if (sym == XKB_KEY_F2) {
104 }
else if (sym == XKB_KEY_F3) {
106 }
else if (sym == XKB_KEY_F4) {
108 }
else if (sym == XKB_KEY_F5) {
110 }
else if (sym == XKB_KEY_F6) {
112 }
else if (sym == XKB_KEY_F7) {
114 }
else if (sym == XKB_KEY_F8) {
116 }
else if (sym == XKB_KEY_F9) {
118 }
else if (sym == XKB_KEY_F10) {
120 }
else if (sym == XKB_KEY_F11) {
122 }
else if (sym == XKB_KEY_F12) {
124 }
else if (sym == 32) {
126 }
else if (sym > 255) {
129 retVal = xkb_keysym_to_utf32(sym);
138int32_t GPUDisplayFrontendWayland::FrontendMain()
141 fprintf(stderr,
"Only Vulkan backend supported\n");
145 mXKBcontext = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
146 if (mXKBcontext ==
nullptr) {
147 throw std::runtime_error(
"Error initializing xkb context");
150 mWayland = wl_display_connect(
nullptr);
151 if (mWayland ==
nullptr) {
152 throw std::runtime_error(
"Could not connect to wayland display");
154 mRegistry = wl_display_get_registry(mWayland);
155 if (mRegistry ==
nullptr) {
156 throw std::runtime_error(
"Could not create wayland registry");
159 auto pointer_enter = [](
void*
data, wl_pointer* wl_pointer,
uint32_t serial, wl_surface*
surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
161 if (!
me->mCursorShapeDevice &&
me->mCursorShapeManager) {
162 me->mCursorShapeDevice = wp_cursor_shape_manager_v1_get_pointer(
me->mCursorShapeManager, wl_pointer);
164 if (
me->mCursorShapeDevice) {
165 wp_cursor_shape_device_v1_set_shape(
me->mCursorShapeDevice, serial, WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT);
168 auto pointer_leave = [](
void*
data, wl_pointer* wl_pointer,
uint32_t serial, wl_surface* wl_surface) {
170 me->mMouseDn =
me->mMouseDnR =
me->mMouseDnM =
false;
172 auto pointer_motion = [](
void*
data, wl_pointer* wl_pointer,
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) {
174 me->mMouseMvX = wl_fixed_to_double(surface_x) *
me->mScale;
175 me->mMouseMvY = wl_fixed_to_double(surface_y) *
me->mScale;
179 if (state == WL_POINTER_BUTTON_STATE_PRESSED || state == WL_POINTER_BUTTON_STATE_RELEASED) {
180 me->handlePointerButton(button, state == WL_POINTER_BUTTON_STATE_PRESSED);
186 if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
187 me->mAxisValue += wl_fixed_to_double(
value);
188 if (
me->mSeatVersion < WL_POINTER_FRAME_SINCE_VERSION) {
193 auto pointer_axis_source = [](
void*
data, wl_pointer* wl_pointer,
uint32_t axis_source) {};
195 auto pointer_axis_discrete = [](
void*
data, wl_pointer* wl_pointer,
uint32_t axis,
int32_t discrete) {};
196#ifdef WL_POINTER_AXIS_VALUE120_SINCE_VERSION
197 auto pointer_axis_value120 = [](
void*
data, wl_pointer* wl_pointer,
uint32_t axis,
int32_t value120) {
199 if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
200 me->mAxisValue120 += value120;
201 me->mHasAxisValue120 =
true;
205#pragma GCC diagnostic push
206#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
207 mPointerListener = wl_pointer_listener{.enter = pointer_enter, .leave = pointer_leave, .motion = pointer_motion, .button = pointer_button, .axis = pointer_axis, .frame = pointer_frame, .axis_source = pointer_axis_source, .axis_stop = pointer_axis_stop, .axis_discrete = pointer_axis_discrete,
208#ifdef WL_POINTER_AXIS_VALUE120_SINCE_VERSION
209 .axis_value120 = pointer_axis_value120
212#pragma GCC diagnostic pop
215 char* keymap_string =
format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1 ? (
char*)mmap(
nullptr,
size, PROT_READ, MAP_PRIVATE, fd, 0) : (
char*)MAP_FAILED;
217 if (keymap_string == MAP_FAILED) {
218 GPUError(
"Cannot read Wayland keymap");
221 xkb_keymap* keymap = xkb_keymap_new_from_string(
me->mXKBcontext, keymap_string, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS);
222 munmap(keymap_string,
size);
223 xkb_state*
state = keymap ? xkb_state_new(keymap) : nullptr;
225 GPUError(
"Cannot compile Wayland keymap");
226 xkb_keymap_unref(keymap);
229 if (
me->mXKBkeymap) {
230 xkb_state_unref(
me->mXKBstate);
231 xkb_keymap_unref(
me->mXKBkeymap);
233 me->mXKBkeymap = keymap;
236 auto keyboard_enter = [](
void*
data, wl_keyboard* wl_keyboard,
uint32_t serial, wl_surface*
surface, wl_array*
keys) {};
237 auto keyboard_leave = [](
void*
data, wl_keyboard* wl_keyboard,
uint32_t serial, wl_surface*
surface) {
240 me->mRepeatKeyCode = -1;
245 int32_t keyPress = (symbol >=
'a' && symbol <=
'z') ? symbol +
'A' -
'a' : symbol;
246 if (state == WL_KEYBOARD_KEY_STATE_PRESSED) {
247 me->mKeys[keyPress] = keyPress == KEY_SHIFT || !
me->consoleShown();
248 me->HandleKey(symbol);
249 if (symbol &&
me->mRepeatRate > 0 &&
me->mXKBkeymap && xkb_keymap_key_repeats(
me->mXKBkeymap,
key + 8)) {
250 me->mRepeatKeyCode =
key;
251 me->mRepeatSymbol = symbol;
252 me->mRepeatNext = std::chrono::steady_clock::now() + std::chrono::milliseconds(
me->mRepeatDelay);
255 me->mKeys[keyPress] =
false;
257 me->mRepeatKeyCode = -1;
263 xkb_state_update_mask(
me->mXKBstate, mods_depressed, mods_latched, mods_locked, 0, 0,
group);
268 me->mRepeatDelay = delay;
270 me->mRepeatKeyCode = -1;
273 mKeyboardListener = wl_keyboard_listener{.keymap = keyboard_keymap, .enter = keyboard_enter, .leave = keyboard_leave, .key = keyboard_key, .modifiers = keyboard_modifiers, .repeat_info = keyboard_repeat};
275 auto xdg_wm_base_ping = [](
void*
data,
struct xdg_wm_base* xdg_wm_base,
uint32_t serial) {
276 xdg_wm_base_pong(xdg_wm_base, serial);
278 mXdgWmBaseListener = xdg_wm_base_listener{
279 .ping = xdg_wm_base_ping,
282 auto seat_capabilities = [](
void*
data,
struct wl_seat* seat,
uint32_t capabilities) {
284 if ((capabilities & WL_SEAT_CAPABILITY_POINTER) && !
me->mPointer) {
285 me->mPointer = wl_seat_get_pointer(seat);
286 wl_pointer_add_listener(
me->mPointer, &
me->mPointerListener, me);
288 if ((capabilities & WL_SEAT_CAPABILITY_KEYBOARD) && !
me->mKeyboard) {
289 me->mKeyboard = wl_seat_get_keyboard(seat);
290 wl_keyboard_add_listener(
me->mKeyboard, &
me->mKeyboardListener, me);
293 auto seat_name = [](
void*
data,
struct wl_seat* seat,
const char*
name) {
295 GPUInfo(
"Wayland seat: %s",
name);
298 mSeatListener = wl_seat_listener{
299 .capabilities = seat_capabilities,
306 if (
auto* o =
me->findOutput(
output); o && (
flags & WL_OUTPUT_MODE_CURRENT)) {
307 o->refresh = refresh;
310 auto output_done = [](
void*
data, wl_output*
output) {};
313 if (
auto* o =
me->findOutput(
output)) {
318#ifdef WL_OUTPUT_NAME_SINCE_VERSION
319 auto output_name = [](
void*
data, wl_output*
output,
const char*
name) {
321 if (
auto* o =
me->findOutput(
output)) {
324 if (
me->mDisplay->GetProcessingSettings().debugLevel >= 2) {
325 GPUInfo(
"Wayland output: %s",
name);
330 mOutputListener = wl_output_listener{
331 .geometry = output_geometry,
334 .scale = output_scale,
335#ifdef WL_OUTPUT_NAME_SINCE_VERSION
337 .description = output_description,
343 if (
me->mDisplay->GetProcessingSettings().debugLevel >= 3) {
344 GPUInfo(
"Available interface %s (version %u)", interface,
version);
346 auto bindVersion = [
version](
const wl_interface& iface,
uint32_t maxVersion) {
return std::min<uint32_t>({
version, (
uint32_t)iface.version, maxVersion}); };
347 if (strcmp(interface, wl_output_interface.name) == 0) {
348 uint32_t v = bindVersion(wl_output_interface, 4);
349 wl_output*
output = (wl_output*)wl_registry_bind(registry,
name, &wl_output_interface,
v);
350 me->mOutputs.emplace_back(OutputInfo{
output,
name,
v, 1,
""});
351 wl_output_add_listener(
output, &
me->mOutputListener, me);
352 }
else if (strcmp(interface, wl_compositor_interface.name) == 0) {
353 me->mCompositor = (wl_compositor*)wl_registry_bind(registry,
name, &wl_compositor_interface, bindVersion(wl_compositor_interface, 6));
354 }
else if (strcmp(interface, xdg_wm_base_interface.name) == 0) {
355 me->mXdgBase = (xdg_wm_base*)wl_registry_bind(registry,
name, &xdg_wm_base_interface, bindVersion(xdg_wm_base_interface, 6));
356 xdg_wm_base_add_listener(
me->mXdgBase, &
me->mXdgWmBaseListener, me);
357 }
else if (strcmp(interface, wl_seat_interface.name) == 0 && !
me->mSeat) {
358 me->mSeatVersion = bindVersion(wl_seat_interface, 8);
359 me->mSeat = (wl_seat*)wl_registry_bind(registry,
name, &wl_seat_interface,
me->mSeatVersion);
360 wl_seat_add_listener(
me->mSeat, &
me->mSeatListener, me);
361 }
else if (strcmp(interface, zxdg_decoration_manager_v1_interface.name) == 0) {
362 me->mDecManager = (zxdg_decoration_manager_v1*)wl_registry_bind(registry,
name, &zxdg_decoration_manager_v1_interface, 1);
363 }
else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0) {
364 me->mCursorShapeManager = (wp_cursor_shape_manager_v1*)wl_registry_bind(registry,
name, &wp_cursor_shape_manager_v1_interface, 1);
365 }
else if (strcmp(interface, wp_viewporter_interface.name) == 0) {
366 me->mViewporter = (wp_viewporter*)wl_registry_bind(registry,
name, &wp_viewporter_interface, 1);
367 }
else if (strcmp(interface, wp_fractional_scale_manager_v1_interface.name) == 0) {
368 me->mFractionalScaleManager = (wp_fractional_scale_manager_v1*)wl_registry_bind(registry,
name, &wp_fractional_scale_manager_v1_interface, 1);
371 auto registry_global_remove = [](
void*
data, wl_registry* registry,
uint32_t name) {
373 for (
auto it =
me->mOutputs.begin(); it !=
me->mOutputs.end(); it++) {
374 if (it->globalName ==
name) {
375 std::erase(
me->mSurfaceOutputs, it->output);
376 if (it->version >= WL_OUTPUT_RELEASE_SINCE_VERSION) {
377 wl_output_release(it->output);
379 wl_output_destroy(it->output);
381 me->mOutputs.erase(it);
387 mRegistryListener = wl_registry_listener{.global = registry_global, .global_remove = registry_global_remove};
389 wl_registry_add_listener(mRegistry, &mRegistryListener,
this);
390 if (wl_display_roundtrip(mWayland) == -1) {
391 reportError(
"initial roundtrip");
392 throw std::runtime_error(
"Wayland initialization failed");
395 if (mCompositor ==
nullptr || mXdgBase ==
nullptr || mSeat ==
nullptr) {
396 throw std::runtime_error(
"Error getting wayland objects");
399 mSurface = wl_compositor_create_surface(mCompositor);
400 if (mSurface ==
nullptr) {
401 throw std::runtime_error(
"Error creating wayland surface");
406 me->mSurfaceOutputs.emplace_back(
output);
411 std::erase(
me->mSurfaceOutputs,
output);
414#ifdef WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION
420 auto surface_preferred_buffer_transform = [](
void*
data, wl_surface*
surface,
uint32_t transform) {};
422 mSurfaceListener = wl_surface_listener{
423 .enter = surface_enter,
424 .leave = surface_leave,
425#ifdef WL_SURFACE_PREFERRED_BUFFER_SCALE_SINCE_VERSION
426 .preferred_buffer_scale = surface_preferred_buffer_scale,
427 .preferred_buffer_transform = surface_preferred_buffer_transform,
430 wl_surface_add_listener(mSurface, &mSurfaceListener,
this);
432 if (mViewporter && mFractionalScaleManager) {
433 auto fractional_scale_preferred_scale = [](
void*
data, wp_fractional_scale_v1* fractional_scale,
uint32_t scale) {
435 me->mFractionalScale120 = scale;
438 mFractionalScaleListener = wp_fractional_scale_v1_listener{.preferred_scale = fractional_scale_preferred_scale};
439 mViewport = wp_viewporter_get_viewport(mViewporter, mSurface);
440 mFractionalScale = wp_fractional_scale_manager_v1_get_fractional_scale(mFractionalScaleManager, mSurface);
441 wp_fractional_scale_v1_add_listener(mFractionalScale, &mFractionalScaleListener,
this);
444 mXdgSurface = xdg_wm_base_get_xdg_surface(mXdgBase, mSurface);
445 if (mXdgSurface ==
nullptr) {
446 throw std::runtime_error(
"Error creating wayland xdg surface");
448 mXdgToplevel = xdg_surface_get_toplevel(mXdgSurface);
452 if (
me->mDisplay->GetProcessingSettings().debugLevel >= 3) {
453 GPUInfo(
"Wayland surface resized to %d %d",
width,
height);
457 bool fullScreen =
false, maximized =
false;
458 me->mSuspended =
false;
461 if (
state[
i] == XDG_TOPLEVEL_STATE_FULLSCREEN) {
463 }
else if (
state[
i] == XDG_TOPLEVEL_STATE_MAXIMIZED) {
465#ifdef XDG_TOPLEVEL_STATE_SUSPENDED_SINCE_VERSION
466 }
else if (
state[
i] == XDG_TOPLEVEL_STATE_SUSPENDED) {
467 me->mSuspended =
true;
471 me->setWindowState(fullScreen, maximized);
472 me->mStateFullScreenOrMaximized = fullScreen || maximized;
475 auto xdg_surface_handle_configure = [](
void*
data, xdg_surface*
surface,
uint32_t serial) {
477 xdg_surface_ack_configure(
me->mXdgSurface, serial);
478 if (
me->mWidthRequested &&
me->mHeightRequested) {
479 me->mWidthLogical =
me->mWidthRequested;
480 me->mHeightLogical =
me->mHeightRequested;
481 if (!
me->mStateFullScreenOrMaximized) {
482 me->mWidthWindowed =
me->mWidthRequested;
483 me->mHeightWindowed =
me->mHeightRequested;
485 }
else if (!
me->mStateFullScreenOrMaximized) {
486 me->mWidthLogical =
me->mWidthWindowed;
487 me->mHeightLogical =
me->mHeightWindowed;
488 if (
me->mBoundsWidth &&
me->mBoundsHeight) {
489 me->mWidthLogical = std::min(
me->mWidthLogical,
me->mBoundsWidth);
490 me->mHeightLogical = std::min(
me->mHeightLogical,
me->mBoundsHeight);
494 me->mWidthRequested =
me->mHeightRequested = 0;
497 auto xdg_toplevel_handle_close = [](
void*
data, xdg_toplevel* toplevel) {
500#ifdef XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION
507#ifdef XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION
508 auto xdg_toplevel_handle_wm_capabilities = [](
void*
data, xdg_toplevel* toplevel, wl_array* capabilities) {
510 me->mCanFullscreen =
me->mCanMaximize =
false;
512 for (
size_t i = 0;
i < capabilities->size /
sizeof(
uint32_t);
i++) {
513 me->mCanFullscreen |= cap[
i] == XDG_TOPLEVEL_WM_CAPABILITIES_FULLSCREEN;
514 me->mCanMaximize |= cap[
i] == XDG_TOPLEVEL_WM_CAPABILITIES_MAXIMIZE;
519 mXdgSurfaceListener = xdg_surface_listener{
520 .configure = xdg_surface_handle_configure,
523 mXdgToplevelListener = xdg_toplevel_listener{
524 .configure = xdg_toplevel_handle_configure,
525 .close = xdg_toplevel_handle_close,
526#ifdef XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION
527 .configure_bounds = xdg_toplevel_handle_configure_bounds,
529#ifdef XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION
530 .wm_capabilities = xdg_toplevel_handle_wm_capabilities,
534 xdg_surface_add_listener(mXdgSurface, &mXdgSurfaceListener,
this);
535 xdg_toplevel_add_listener(mXdgToplevel, &mXdgToplevelListener,
this);
539 xdg_toplevel_set_app_id(mXdgToplevel,
"o2-gpu-event-display");
542 mXdgDecoration = zxdg_decoration_manager_v1_get_toplevel_decoration(mDecManager, mXdgToplevel);
543 zxdg_toplevel_decoration_v1_set_mode(mXdgDecoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
545 GPUInfo(
"Wayland compositor does not support server-side decorations");
549 wl_surface_commit(mSurface);
550 if (wl_display_roundtrip(mWayland) == -1) {
551 reportError(
"initial roundtrip");
552 throw std::runtime_error(
"Wayland initialization failed");
554 if (initialFullScreen || initialMaximized) {
555 if (initialFullScreen) {
560 if (wl_display_roundtrip(mWayland) == -1) {
561 reportError(
"initial window state roundtrip");
562 throw std::runtime_error(
"Wayland initialization failed");
572 while (!
error && wl_display_prepare_read(mWayland) != 0) {
573 error = wl_display_dispatch_pending(mWayland) == -1;
576 reportError(
"dispatching events");
579 wl_display_flush(mWayland);
580 pollfd pfd = {wl_display_get_fd(mWayland), POLLIN, 0};
581 if (poll(&pfd, 1, mSuspended ? 100 : 0) > 0) {
582 if (wl_display_read_events(mWayland) == -1) {
583 reportError(
"reading events");
587 wl_display_cancel_read(mWayland);
589 if (wl_display_dispatch_pending(mWayland) == -1) {
590 reportError(
"dispatching events");
604 xkb_state_unref(mXKBstate);
605 xkb_keymap_unref(mXKBkeymap);
606 mXKBkeymap =
nullptr;
608 xkb_context_unref(mXKBcontext);
616 if (mCursorShapeDevice) {
617 wp_cursor_shape_device_v1_destroy(mCursorShapeDevice);
618 mCursorShapeDevice =
nullptr;
620 if (mCursorShapeManager) {
621 wp_cursor_shape_manager_v1_destroy(mCursorShapeManager);
622 mCursorShapeManager =
nullptr;
625 mSeatVersion >= WL_POINTER_RELEASE_SINCE_VERSION ? wl_pointer_release(mPointer) : wl_pointer_destroy(mPointer);
629 mSeatVersion >= WL_KEYBOARD_RELEASE_SINCE_VERSION ? wl_keyboard_release(mKeyboard) : wl_keyboard_destroy(mKeyboard);
632 if (mXdgDecoration) {
633 zxdg_toplevel_decoration_v1_destroy(mXdgDecoration);
634 mXdgDecoration =
nullptr;
636 if (mFractionalScale) {
637 wp_fractional_scale_v1_destroy(mFractionalScale);
638 mFractionalScale =
nullptr;
641 wp_viewport_destroy(mViewport);
644 xdg_toplevel_destroy(mXdgToplevel);
645 xdg_surface_destroy(mXdgSurface);
646 wl_surface_destroy(mSurface);
647 if (mFractionalScaleManager) {
648 wp_fractional_scale_manager_v1_destroy(mFractionalScaleManager);
649 mFractionalScaleManager =
nullptr;
652 wp_viewporter_destroy(mViewporter);
653 mViewporter =
nullptr;
656 zxdg_decoration_manager_v1_destroy(mDecManager);
657 mDecManager =
nullptr;
659 for (
auto& o : mOutputs) {
660 if (o.version >= WL_OUTPUT_RELEASE_SINCE_VERSION) {
661 wl_output_release(o.output);
663 wl_output_destroy(o.output);
667 mSurfaceOutputs.clear();
669 if (mSeatVersion >= WL_SEAT_RELEASE_SINCE_VERSION) {
670 wl_seat_release(mSeat);
672 wl_seat_destroy(mSeat);
676 xdg_wm_base_destroy(mXdgBase);
677 wl_compositor_destroy(mCompositor);
678 wl_registry_destroy(mRegistry);
679 wl_display_disconnect(mWayland);
686 if (!mCanFullscreen) {
687 GPUWarning(
"Wayland compositor does not support fullscreen");
689 xdg_toplevel_set_fullscreen(mXdgToplevel, mSurfaceOutputs.size() ? mSurfaceOutputs.back() :
nullptr);
691 xdg_toplevel_unset_fullscreen(mXdgToplevel);
698 GPUWarning(
"Wayland compositor does not support maximizing windows");
700 xdg_toplevel_set_maximized(mXdgToplevel);
702 xdg_toplevel_unset_maximized(mXdgToplevel);
708 auto* o = mSurfaceOutputs.size() ? findOutput(mSurfaceOutputs.back()) :
nullptr;
709 return o ? o->refresh / 1000.f : 0.f;
712GPUDisplayFrontendWayland::OutputInfo* GPUDisplayFrontendWayland::findOutput(wl_output*
output)
714 auto it = std::find_if(mOutputs.begin(), mOutputs.end(), [
output](
const auto& o) { return o.output == output; });
715 return it == mOutputs.end() ? nullptr : &*it;
718void GPUDisplayFrontendWayland::updateScale()
721 if (mFractionalScale) {
722 scale = mFractionalScale120 ? mFractionalScale120 / 120. : 1.;
724 int32_t intScale = mPreferredScale;
727 for (
auto*
output : mSurfaceOutputs) {
728 if (
auto* o = findOutput(
output)) {
729 intScale = std::max(intScale, o->scale);
735 if (scale != mScale && mSurface) {
737 if (!mFractionalScale) {
738 wl_surface_set_buffer_scale(mSurface, (
int32_t)mScale);
744void GPUDisplayFrontendWayland::updateSize()
747 wp_viewport_set_destination(mViewport, mWidthLogical, mHeightLogical);
761void GPUDisplayFrontendWayland::reportError(
const char* where)
763 const int32_t err = wl_display_get_error(mWayland);
765 const wl_interface* iface =
nullptr;
767 const uint32_t code = wl_display_get_protocol_error(mWayland, &iface, &
id);
768 GPUError(
"Wayland protocol error %u on %s@%u while %s", code, iface ? iface->name :
"unknown interface",
id, where);
770 GPUError(
"Wayland error while %s: %s", where, strerror(err));
774void GPUDisplayFrontendWayland::handleKeyRepeat()
776 if (mRepeatKeyCode < 0) {
779 const auto now = std::chrono::steady_clock::now();
780 const auto period = std::chrono::microseconds(1000000 / mRepeatRate);
781 if (now >= mRepeatNext + period) {
784 while (now >= mRepeatNext && mRepeatKeyCode >= 0) {
786 mRepeatNext += period;
790void GPUDisplayFrontendWayland::applyScroll()
792 mMouseWheel += mHasAxisValue120 ? (mAxisValue120 * -100 / 120) : (
int32_t)(mAxisValue * (-100. / 15.));
795 mHasAxisValue120 =
false;
810 VkWaylandSurfaceCreateInfoKHR info{};
811 info.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
813 info.display = mWayland;
814 info.surface = mSurface;
815 return vkCreateWaylandSurfaceKHR(*(VkInstance*)instance, &info,
nullptr, (VkSurfaceKHR*)
surface) != VK_SUCCESS;
820 static const char* exts[] = {
"VK_KHR_surface",
"VK_KHR_wayland_surface"};
header::DataDescription description
std::vector< std::string > keys
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by factor
char error[CURL_ERROR_SIZE]
const Acts::Surface * surface
void ToggleMaximized(bool set) override
void SwitchFullscreen(bool set) override
int32_t getVulkanSurface(void *instance, void *surface) override
void getSize(int32_t &width, int32_t &height) override
float getRefreshRate() override
GPUDisplayFrontendWayland()
uint32_t getReqVulkanExtensions(const char **&p) override
void SetVSync(bool enable) override
const char * mFrontendName
void HandleKey(uint8_t key)
void requestMaximized(bool set)
std::mutex mExitStateMutex
int32_t HandleUpdatesAndDrawGLScene(bool suspended=false)
void ResizeScene(int32_t width, int32_t height)
std::condition_variable mDisplayStoppedCV
static constexpr const char * DISPLAY_WINDOW_NAME
frontendTypes mFrontendType
int32_t InitDisplay(bool initFailure=false)
GPUDisplayBackend * backend()
static constexpr int32_t MIN_WIDTH
void requestFullScreen(bool set)
static constexpr int32_t MIN_HEIGHT
std::atomic< bool > mDisplayRunning
const GPUSettingsDisplayRenderer & cfgR() const
const GPUSettingsProcessing & GetProcessingSettings() const
GLuint const GLchar * name
GLint GLsizei GLsizei height
GLsizei const GLfloat * value
GLint GLint GLsizei GLint GLenum format
GPUDisplayFrontend * createGPUDisplayFrontendWayland()
constexpr auto make(F f) -> std::array< int, N >
Polygon< T > close(Polygon< T > polygon)