Don't fake user presence, use focused instead
This commit is contained in:
@@ -79,6 +79,7 @@ if (WIVRN_BUILD_SERVER)
|
||||
main.cpp
|
||||
sleep_inhibitor.cpp
|
||||
start_application.cpp
|
||||
ipc_server_cb.cpp
|
||||
target_instance_wivrn.cpp
|
||||
wivrn_ipc.cpp
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ wivrn_hmd::wivrn_hmd(wivrn::wivrn_session * cnx,
|
||||
.supported = {
|
||||
.orientation_tracking = true,
|
||||
.position_tracking = true,
|
||||
.presence = true,
|
||||
.presence = info.user_presence,
|
||||
.battery_status = true,
|
||||
},
|
||||
.update_inputs = [](xrt_device *) { return XRT_SUCCESS; },
|
||||
@@ -231,28 +231,13 @@ void wivrn_hmd::update_visibility_mask(const from_headset::visibility_mask_chang
|
||||
m->at(mask.view_index) = mask.data;
|
||||
}
|
||||
|
||||
bool wivrn_hmd::update_presence(bool new_presence, bool real)
|
||||
bool wivrn_hmd::update_presence(bool new_presence)
|
||||
{
|
||||
// if this presence change comes from headset, always honor it,
|
||||
// otherwise try to keep it in sync with the real presence,
|
||||
// while still changing presence to false when session is not
|
||||
// visible
|
||||
if (real || new_presence == this->real_presence || !new_presence)
|
||||
if (this->presence.exchange(new_presence) != new_presence)
|
||||
{
|
||||
if (real && this->real_presence != new_presence)
|
||||
{
|
||||
U_LOG_I("Updating real user presence: %s -> %s", real_presence ? "true" : "false", new_presence ? "true" : "false");
|
||||
this->real_presence = new_presence;
|
||||
}
|
||||
|
||||
if (this->presence == new_presence)
|
||||
return false;
|
||||
|
||||
U_LOG_I("Updating user presence: %s -> %s", this->presence ? "true" : "false", new_presence ? "true" : "false");
|
||||
this->presence = new_presence;
|
||||
U_LOG_I("user presence changed to %s", new_presence ? "true" : "false");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -54,10 +54,6 @@ class wivrn_hmd : public xrt_device
|
||||
from_headset::battery battery{};
|
||||
|
||||
std::atomic<bool> presence{true};
|
||||
// last XR_EVENT_DATA_USER_PRESENCE_CHANGED_EXT from headset
|
||||
// we must keep track of this to not go out of sync with headset when
|
||||
// a session state change also triggers presence change
|
||||
std::atomic<bool> real_presence{true};
|
||||
thread_safe<std::array<std::optional<from_headset::visibility_mask_changed::masks>, 2>> visibility_mask;
|
||||
|
||||
wivrn::wivrn_session * cnx;
|
||||
@@ -86,7 +82,6 @@ public:
|
||||
void update_battery(const from_headset::battery &);
|
||||
void update_tracking(const from_headset::tracking &, const clock_offset &);
|
||||
void update_visibility_mask(const from_headset::visibility_mask_changed &);
|
||||
// real if this update comes from a presence changed event
|
||||
bool update_presence(bool new_presence, bool real);
|
||||
bool update_presence(bool);
|
||||
};
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "main/comp_compositor.h"
|
||||
#include "main/comp_main_interface.h"
|
||||
#include "main/comp_target.h"
|
||||
#include "server/ipc_server.h"
|
||||
#include "target_instance_wivrn.h"
|
||||
#include "util/u_builders.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "util/u_system.h"
|
||||
@@ -139,7 +141,7 @@ bool wivrn::tracking_control_t::set_enabled(to_headset::tracking_control::id id,
|
||||
return changed;
|
||||
}
|
||||
|
||||
wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection, u_system & system) :
|
||||
wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection, instance & inst, u_system & system) :
|
||||
xrt_system_devices{
|
||||
.get_roles = [](xrt_system_devices * self, xrt_system_roles * out_roles) { return ((wivrn_session *)self)->get_roles(out_roles); },
|
||||
.feature_inc = [](xrt_system_devices * self, xrt_device_feature_type f) { return ((wivrn_session *)self)->feature_inc(f); },
|
||||
@@ -147,6 +149,7 @@ wivrn::wivrn_session::wivrn_session(std::unique_ptr<wivrn_connection> connection
|
||||
.destroy = [](xrt_system_devices * self) { delete ((wivrn_session *)self); },
|
||||
},
|
||||
connection(std::move(connection)),
|
||||
inst(inst),
|
||||
xrt_system(system),
|
||||
hmd(this, get_info()),
|
||||
left_controller(0, &hmd, this),
|
||||
@@ -305,6 +308,7 @@ wivrn_session::~wivrn_session()
|
||||
}
|
||||
|
||||
xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connection> connection,
|
||||
instance & inst,
|
||||
u_system & system,
|
||||
xrt_system_devices ** out_xsysd,
|
||||
xrt_space_overseer ** out_xspovrs,
|
||||
@@ -313,7 +317,7 @@ xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connecti
|
||||
std::unique_ptr<wivrn_session> self;
|
||||
try
|
||||
{
|
||||
self.reset(new wivrn_session(std::move(connection), system));
|
||||
self.reset(new wivrn_session(std::move(connection), inst, system));
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
@@ -330,6 +334,7 @@ xrt_result_t wivrn::wivrn_session::create_session(std::unique_ptr<wivrn_connecti
|
||||
U_LOG_E("Failed to create system compositor");
|
||||
return xret;
|
||||
}
|
||||
self->system_compositor = *out_xsysc;
|
||||
|
||||
u_builder_create_space_overseer_legacy(
|
||||
&self->xrt_system.broadcast,
|
||||
@@ -668,49 +673,34 @@ void wivrn_session::operator()(from_headset::session_state_changed && event)
|
||||
{
|
||||
U_LOG_I("Session state changed: %s", xr::to_string(event.state));
|
||||
bool visible, focused;
|
||||
bool changed = false;
|
||||
switch (event.state)
|
||||
{
|
||||
case XR_SESSION_STATE_SYNCHRONIZED:
|
||||
visible = false;
|
||||
focused = false;
|
||||
changed = hmd.update_presence(false, false);
|
||||
break;
|
||||
case XR_SESSION_STATE_VISIBLE:
|
||||
visible = true;
|
||||
focused = false;
|
||||
changed = hmd.update_presence(true, false);
|
||||
break;
|
||||
case XR_SESSION_STATE_FOCUSED:
|
||||
visible = true;
|
||||
focused = true;
|
||||
changed = hmd.update_presence(true, false);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
visible = false;
|
||||
focused = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (changed)
|
||||
scoped_lock lock(inst.server->global_state.lock);
|
||||
for (auto & t: inst.server->threads)
|
||||
{
|
||||
xrt_session_event_user_presence_change event = {
|
||||
.type = XRT_SESSION_EVENT_USER_PRESENCE_CHANGE,
|
||||
};
|
||||
hmd.get_presence(&event.is_user_present);
|
||||
push_event({.presence_change = event});
|
||||
if (t.ics.server_thread_index < 0 or t.ics.xc == nullptr)
|
||||
continue;
|
||||
bool current = t.ics.client_state.session_overlay or
|
||||
inst.server->global_state.active_client_index == t.ics.server_thread_index;
|
||||
xrt_syscomp_set_state(system_compositor, t.ics.xc, visible and current, focused and current);
|
||||
}
|
||||
|
||||
push_event(
|
||||
{
|
||||
.state = {
|
||||
.type = XRT_SESSION_EVENT_STATE_CHANGE,
|
||||
.visible = visible,
|
||||
.focused = focused,
|
||||
},
|
||||
});
|
||||
}
|
||||
void wivrn_session::operator()(from_headset::user_presence_changed && event)
|
||||
{
|
||||
if (hmd.update_presence(event.present, true))
|
||||
if (hmd.update_presence(event.present))
|
||||
push_event(
|
||||
{
|
||||
.presence_change = {
|
||||
|
||||
@@ -43,6 +43,7 @@ union xrt_session_event;
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class instance;
|
||||
class wivrn_eye_tracker;
|
||||
class wivrn_fb_face2_tracker;
|
||||
class wivrn_htc_face_tracker;
|
||||
@@ -92,10 +93,12 @@ class wivrn_session : public xrt_system_devices
|
||||
{
|
||||
friend wivrn_comp_target_factory;
|
||||
std::unique_ptr<wivrn_connection> connection;
|
||||
instance & inst;
|
||||
pacing_app_factory app_pacers;
|
||||
|
||||
u_system & xrt_system;
|
||||
xrt_space_overseer * space_overseer;
|
||||
xrt_system_compositor * system_compositor;
|
||||
|
||||
std::mutex roles_mutex;
|
||||
xrt_system_roles roles{
|
||||
@@ -133,12 +136,13 @@ class wivrn_session : public xrt_system_devices
|
||||
|
||||
std::jthread thread;
|
||||
|
||||
wivrn_session(std::unique_ptr<wivrn_connection> connection, u_system &);
|
||||
wivrn_session(std::unique_ptr<wivrn_connection> connection, instance &, u_system &);
|
||||
|
||||
public:
|
||||
~wivrn_session();
|
||||
|
||||
static xrt_result_t create_session(std::unique_ptr<wivrn_connection> connection,
|
||||
instance & instance,
|
||||
u_system & system,
|
||||
xrt_system_devices ** out_xsysd,
|
||||
xrt_space_overseer ** out_xspovrs,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ipc_server_cb.h"
|
||||
#include "target_instance_wivrn.h"
|
||||
#include "utils/method.h"
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
void ipc_server_cb::init_failed(xrt_result res)
|
||||
{
|
||||
}
|
||||
|
||||
void ipc_server_cb::mainloop_entering(ipc_server * server, xrt_instance * xrt_inst)
|
||||
{
|
||||
auto inst = static_cast<wivrn::instance *>(xrt_inst);
|
||||
inst->server = server;
|
||||
}
|
||||
|
||||
void ipc_server_cb::mainloop_leaving(ipc_server * server, xrt_instance * xrt_inst)
|
||||
{
|
||||
auto inst = static_cast<wivrn::instance *>(xrt_inst);
|
||||
inst->server = nullptr;
|
||||
}
|
||||
|
||||
ipc_server_cb::ipc_server_cb() :
|
||||
ipc_server_callbacks{
|
||||
.init_failed = method_pointer2<&ipc_server_cb::init_failed>,
|
||||
.mainloop_entering = method_pointer2<&ipc_server_cb::mainloop_entering>,
|
||||
.mainloop_leaving = method_pointer2<&ipc_server_cb::mainloop_leaving>,
|
||||
}
|
||||
{}
|
||||
} // namespace wivrn
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "server/ipc_server_interface.h"
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class ipc_server_cb : public ipc_server_callbacks
|
||||
{
|
||||
void init_failed(xrt_result);
|
||||
void mainloop_entering(ipc_server *, xrt_instance *);
|
||||
void mainloop_leaving(ipc_server *, xrt_instance *);
|
||||
|
||||
public:
|
||||
using base = void;
|
||||
ipc_server_cb();
|
||||
};
|
||||
} // namespace wivrn
|
||||
+4
-3
@@ -16,6 +16,7 @@
|
||||
#include "driver/wivrn_connection.h"
|
||||
#include "exit_codes.h"
|
||||
#include "hostname.h"
|
||||
#include "ipc_server_cb.h"
|
||||
#include "protocol_version.h"
|
||||
#include "start_application.h"
|
||||
#include "utils/overloaded.h"
|
||||
@@ -48,7 +49,6 @@
|
||||
#include <glib.h>
|
||||
#include <libnotify/notify.h>
|
||||
|
||||
#include <server/ipc_server_interface.h>
|
||||
#include <shared/ipc_protocol.h>
|
||||
#include <util/u_file.h>
|
||||
|
||||
@@ -249,11 +249,12 @@ void start_server(configuration config)
|
||||
// foveation code does not allow oversampling
|
||||
setenv("XRT_COMPOSITOR_SCALE_PERCENTAGE", "100", true);
|
||||
|
||||
// FIXME: synchronization fails on gfx pipeline
|
||||
setenv("XRT_COMPOSITOR_COMPUTE", "1", true);
|
||||
|
||||
setenv("AMD_DEBUG", "lowlatencyenc", false);
|
||||
|
||||
wivrn::ipc_server_cb server_cb;
|
||||
|
||||
ipc_server_main_info server_info{
|
||||
.udgci = {
|
||||
.window_title = "WiVRn",
|
||||
@@ -267,7 +268,7 @@ void start_server(configuration config)
|
||||
|
||||
try
|
||||
{
|
||||
exit(ipc_server_main(0, 0, &server_info /*argc, argv, ismi*/));
|
||||
exit(ipc_server_main_common(&server_info, &server_cb, nullptr));
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
// Copyright 2020-2022, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
* @brief Shared default implementation of the instance with compositor.
|
||||
* @author Jakob Bornecrantz <jakob@collabora.com>
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "target_instance_wivrn.h"
|
||||
|
||||
#include "utils/method.h"
|
||||
|
||||
#include "xrt/xrt_instance.h"
|
||||
#include "xrt/xrt_system.h"
|
||||
|
||||
#include "os/os_time.h"
|
||||
|
||||
#include "util/u_system.h"
|
||||
#include "util/u_trace_marker.h"
|
||||
|
||||
@@ -19,18 +31,13 @@
|
||||
#include "driver/wivrn_session.h"
|
||||
#include "wivrn_ipc.h"
|
||||
|
||||
/*
|
||||
*
|
||||
* Internal functions.
|
||||
*
|
||||
*/
|
||||
|
||||
static xrt_result_t
|
||||
wivrn_instance_create_system(struct xrt_instance * xinst,
|
||||
struct xrt_system ** out_xsys,
|
||||
struct xrt_system_devices ** out_xsysd,
|
||||
struct xrt_space_overseer ** out_xspovrs,
|
||||
struct xrt_system_compositor ** out_xsysc)
|
||||
namespace wivrn
|
||||
{
|
||||
xrt_result_t instance::create_system(
|
||||
struct xrt_system ** out_xsys,
|
||||
struct xrt_system_devices ** out_xsysd,
|
||||
struct xrt_space_overseer ** out_xspovrs,
|
||||
struct xrt_system_compositor ** out_xsysc)
|
||||
{
|
||||
assert(out_xsysd != NULL);
|
||||
assert(*out_xsysd == NULL);
|
||||
@@ -41,6 +48,7 @@ wivrn_instance_create_system(struct xrt_instance * xinst,
|
||||
struct xrt_system_compositor * xsysc = NULL;
|
||||
auto res = wivrn::wivrn_session::create_session(
|
||||
std::move(connection),
|
||||
*this,
|
||||
*u_sys,
|
||||
out_xsysd,
|
||||
out_xspovrs,
|
||||
@@ -49,36 +57,29 @@ wivrn_instance_create_system(struct xrt_instance * xinst,
|
||||
return res;
|
||||
}
|
||||
|
||||
static void
|
||||
wivrn_instance_destroy(struct xrt_instance * xinst)
|
||||
{
|
||||
delete xinst;
|
||||
}
|
||||
|
||||
static xrt_result_t
|
||||
wivrn_instance_get_prober(struct xrt_instance * xinst, struct xrt_prober ** out_xp)
|
||||
xrt_result_t instance::get_prober(struct xrt_prober ** out_xp)
|
||||
{
|
||||
*out_xp = nullptr;
|
||||
return XRT_ERROR_PROBER_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Exported function(s).
|
||||
*
|
||||
*/
|
||||
instance::instance() :
|
||||
xrt_instance{
|
||||
.create_system = method_pointer<&instance::create_system>,
|
||||
.get_prober = method_pointer<&instance::get_prober>,
|
||||
.destroy = [](xrt_instance * ptr) { delete (instance *)ptr; },
|
||||
.startup_timestamp = os_monotonic_get_ns(),
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace wivrn
|
||||
xrt_result_t
|
||||
xrt_instance_create(struct xrt_instance_info * ii, struct xrt_instance ** out_xinst)
|
||||
{
|
||||
u_trace_marker_init();
|
||||
|
||||
*out_xinst = new xrt_instance{
|
||||
.create_system = wivrn_instance_create_system,
|
||||
.get_prober = wivrn_instance_get_prober,
|
||||
.destroy = wivrn_instance_destroy,
|
||||
.startup_timestamp = os_monotonic_get_ns(),
|
||||
};
|
||||
*out_xinst = new wivrn::instance();
|
||||
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "server/ipc_server.h"
|
||||
#include "xrt/xrt_instance.h"
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class instance : public xrt_instance
|
||||
{
|
||||
xrt_result_t create_system(
|
||||
xrt_system **,
|
||||
xrt_system_devices **,
|
||||
xrt_space_overseer **,
|
||||
xrt_system_compositor **);
|
||||
|
||||
xrt_result_t get_prober(xrt_prober **);
|
||||
|
||||
public:
|
||||
ipc_server * server = nullptr;
|
||||
using base = xrt_instance;
|
||||
instance();
|
||||
};
|
||||
} // namespace wivrn
|
||||
@@ -32,6 +32,10 @@ struct method_trait<Method, Result (Class::*)(Args...)>
|
||||
{
|
||||
return std::invoke(Method, static_cast<Class *>(arg), args...);
|
||||
}
|
||||
static Result magic2(Args... args, Class::base * arg)
|
||||
{
|
||||
return std::invoke(Method, static_cast<Class *>(arg), args...);
|
||||
}
|
||||
};
|
||||
} // namespace details
|
||||
|
||||
@@ -54,4 +58,8 @@ namespace wivrn
|
||||
// }
|
||||
template <auto Method>
|
||||
auto method_pointer = ::details::method_trait<Method>::magic;
|
||||
|
||||
// same, but "this" argument is last
|
||||
template <auto Method>
|
||||
auto method_pointer2 = ::details::method_trait<Method>::magic2;
|
||||
} // namespace wivrn
|
||||
|
||||
Reference in New Issue
Block a user