Skip to content

Commit

Permalink
Rename FFI structs
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Jan 26, 2023
1 parent c3cf129 commit c311845
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 361 deletions.
13 changes: 4 additions & 9 deletions alvr/client_core/cpp/bindings.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

struct EyeInput {
struct FfiViewInput {
float orientation[4]; // x, y, z, w
float position[3];
float fovLeft;
Expand All @@ -10,12 +10,7 @@ struct EyeInput {
unsigned int swapchainIndex;
};

struct OnCreateResult {
int streamSurfaceHandle;
int loadingSurfaceHandle;
};

struct StreamConfigInput {
struct FfiStreamConfig {
unsigned int viewWidth;
unsigned int viewHeight;
const unsigned int *swapchainTextures[2];
Expand Down Expand Up @@ -43,8 +38,8 @@ extern "C" void prepareLobbyRoom(int viewWidth,
const unsigned int *swapchainTextures[2],
int swapchainLength);
extern "C" void destroyRenderers();
extern "C" void streamStartNative(StreamConfigInput config);
extern "C" void streamStartNative(FfiStreamConfig config);
extern "C" void updateLobbyHudTexture(const unsigned char *data);
extern "C" void renderLobbyNative(const EyeInput eyeInputs[2]);
extern "C" void renderLobbyNative(const FfiViewInput eyeInputs[2]);
extern "C" void renderStreamNative(void *streamHardwareBuffer,
const unsigned int swapchainIndices[2]);
8 changes: 4 additions & 4 deletions alvr/client_core/cpp/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ void renderEye(
GL(glUseProgram(0));
}

void ovrRenderer_RenderFrame(ovrRenderer *renderer, const EyeInput input[2], bool isLobby) {
void ovrRenderer_RenderFrame(ovrRenderer *renderer, const FfiViewInput input[2], bool isLobby) {
if (renderer->enableFFR) {
renderer->ffr->Render();
}
Expand Down Expand Up @@ -760,7 +760,7 @@ void destroyRenderers() {
}
}

void streamStartNative(StreamConfigInput config) {
void streamStartNative(FfiStreamConfig config) {
if (g_ctx.streamRenderer) {
ovrRenderer_Destroy(g_ctx.streamRenderer.get());
g_ctx.streamRenderer.release();
Expand Down Expand Up @@ -800,7 +800,7 @@ void updateLobbyHudTexture(const unsigned char *data) {
memcpy(&g_ctx.hudTextureBitmap[0], data, HUD_TEXTURE_WIDTH * HUD_TEXTURE_HEIGHT * 4);
}

void renderLobbyNative(const EyeInput eyeInputs[2]) {
void renderLobbyNative(const FfiViewInput eyeInputs[2]) {
// update text image
{
std::lock_guard<std::mutex> lock(g_ctx.hudTextureMutex);
Expand Down Expand Up @@ -832,7 +832,7 @@ void renderStreamNative(void *streamHardwareBuffer, const unsigned int swapchain
GL(glBindTexture(GL_TEXTURE_EXTERNAL_OES, g_ctx.streamTexture->GetGLTexture()));
GL(glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, (GLeglImageOES)image));

EyeInput eyeInputs[2] = {};
FfiViewInput eyeInputs[2] = {};
eyeInputs[0].swapchainIndex = swapchainIndices[0];
eyeInputs[1].swapchainIndex = swapchainIndices[1];
ovrRenderer_RenderFrame(g_ctx.streamRenderer.get(), eyeInputs, false);
Expand Down
6 changes: 3 additions & 3 deletions alvr/client_core/src/opengl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn start_stream(
) {
#[cfg(target_os = "android")]
unsafe {
let config = StreamConfigInput {
let config = FfiStreamConfig {
viewWidth: view_resolution.x,
viewHeight: view_resolution.y,
swapchainTextures: [
Expand Down Expand Up @@ -165,7 +165,7 @@ pub fn render_lobby(view_inputs: [RenderViewInput; 2]) {
#[cfg(target_os = "android")]
unsafe {
let eye_inputs = [
EyeInput {
FfiViewInput {
position: view_inputs[0].position.to_array(),
orientation: view_inputs[0].orientation.to_array(),
fovLeft: view_inputs[0].fov.left,
Expand All @@ -174,7 +174,7 @@ pub fn render_lobby(view_inputs: [RenderViewInput; 2]) {
fovDown: view_inputs[0].fov.down,
swapchainIndex: view_inputs[0].swapchain_index as _,
},
EyeInput {
FfiViewInput {
position: view_inputs[1].position.to_array(),
orientation: view_inputs[1].orientation.to_array(),
fovLeft: view_inputs[1].fov.left,
Expand Down
413 changes: 191 additions & 222 deletions alvr/server/cpp/alvr_server/OvrController.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions alvr/server/cpp/alvr_server/OvrController.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class OvrController : public TrackedDevice, public vr::ITrackedDeviceServerDrive

vr::VRInputComponentHandle_t getHapticComponent();

void SetButton(uint64_t id, AlvrButtonValue value);
void SetButton(uint64_t id, FfiButtonValue value);

bool onPoseUpdate(float predictionS, AlvrDeviceMotion motion, const OculusHand &hand);
bool onPoseUpdate(float predictionS, FfiDeviceMotion motion, const FfiHandSkeleton &hand);
std::string GetSerialNumber();

void GetBoneTransform(bool withController,
Expand Down
10 changes: 5 additions & 5 deletions alvr/server/cpp/alvr_server/OvrHMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
const vr::HmdMatrix34_t MATRIX_IDENTITY = {
{{1.0, 0.0, 0.0, 0.0}, {0.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}}};

vr::HmdRect2_t fov_to_projection(EyeFov fov) {
vr::HmdRect2_t fov_to_projection(FfiFov fov) {
auto proj_bounds = vr::HmdRect2_t{};
proj_bounds.vTopLeft.v[0] = tanf(fov.left);
proj_bounds.vBottomRight.v[0] = tanf(fov.right);
Expand Down Expand Up @@ -50,9 +50,9 @@ inline vr::ETrackedDeviceClass getControllerDeviceClass() {
OvrHmd::OvrHmd()
: TrackedDevice(HEAD_ID), m_baseComponentsInitialized(false),
m_streamComponentsInitialized(false) {
auto dummy_fov = EyeFov{-1.0, 1.0, 1.0, -1.0};
auto dummy_fov = FfiFov{-1.0, 1.0, 1.0, -1.0};

this->views_config = ViewsConfigData{};
this->views_config = FfiViewsConfig{};
this->views_config.ipd_m = 0.063;
this->views_config.fov[0] = dummy_fov;
this->views_config.fov[1] = dummy_fov;
Expand Down Expand Up @@ -309,7 +309,7 @@ void *OvrHmd::GetComponent(const char *component_name_and_version) {

vr::DriverPose_t OvrHmd::GetPose() { return m_pose; }

void OvrHmd::OnPoseUpdated(uint64_t targetTimestampNs, AlvrDeviceMotion motion) {
void OvrHmd::OnPoseUpdated(uint64_t targetTimestampNs, FfiDeviceMotion motion) {
if (this->object_id != vr::k_unTrackedDeviceIndexInvalid) {
auto pose = vr::DriverPose_t{};
pose.poseIsValid = true;
Expand Down Expand Up @@ -393,7 +393,7 @@ void OvrHmd::StopStreaming() {
vr::VRDriverInput()->UpdateBooleanComponent(m_proximity, false, 0.0);
}

void OvrHmd::SetViewsConfig(ViewsConfigData config) {
void OvrHmd::SetViewsConfig(FfiViewsConfig config) {
this->views_config = config;

auto left_transform = MATRIX_IDENTITY;
Expand Down
6 changes: 3 additions & 3 deletions alvr/server/cpp/alvr_server/OvrHMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ class OvrHmd : public TrackedDevice,
virtual void DebugRequest(const char *, char *, uint32_t) {}
virtual vr::DriverPose_t GetPose();

void OnPoseUpdated(uint64_t targetTimestampNs, AlvrDeviceMotion motion);
void OnPoseUpdated(uint64_t targetTimestampNs, FfiDeviceMotion motion);

void StartStreaming();

void StopStreaming();

void SetViewsConfig(ViewsConfigData config);
void SetViewsConfig(FfiViewsConfig config);

bool IsTrackingRef() const { return m_deviceClass == vr::TrackedDeviceClass_TrackingReference; }
bool IsHMD() const { return m_deviceClass == vr::TrackedDeviceClass_HMD; }
Expand Down Expand Up @@ -71,7 +71,7 @@ class OvrHmd : public TrackedDevice,
std::shared_ptr<PoseHistory> m_poseHistory;

private:
ViewsConfigData views_config;
FfiViewsConfig views_config;

bool m_baseComponentsInitialized;
bool m_streamComponentsInitialized;
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/cpp/alvr_server/PoseHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <mutex>
#include <optional>

void PoseHistory::OnPoseUpdated(uint64_t targetTimestampNs, AlvrDeviceMotion motion) {
void PoseHistory::OnPoseUpdated(uint64_t targetTimestampNs, FfiDeviceMotion motion) {
// Put pose history buffer
TrackingHistoryFrame history;
history.targetTimestampNs = targetTimestampNs;
Expand Down
4 changes: 2 additions & 2 deletions alvr/server/cpp/alvr_server/PoseHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class PoseHistory
public:
struct TrackingHistoryFrame {
uint64_t targetTimestampNs;
AlvrDeviceMotion motion;
FfiDeviceMotion motion;
vr::HmdMatrix34_t rotationMatrix;
};

void OnPoseUpdated(uint64_t targetTimestampNs, AlvrDeviceMotion motion);
void OnPoseUpdated(uint64_t targetTimestampNs, FfiDeviceMotion motion);

std::optional<TrackingHistoryFrame> GetBestPoseMatch(const vr::HmdMatrix34_t &pose) const;
// Return the most recent pose known at the given timestamp
Expand Down
16 changes: 8 additions & 8 deletions alvr/server/cpp/alvr_server/TrackedDevice.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#include "TrackedDevice.h"
#include "Logger.h"

void TrackedDevice::set_prop(OpenvrProperty prop) {
void TrackedDevice::set_prop(FfiOpenvrProperty prop) {
auto key = (vr::ETrackedDeviceProperty)prop.key;

auto vr_properties = vr::VRProperties();

vr::ETrackedPropertyError result;

if (prop.type == OpenvrPropertyType::Bool) {
if (prop.type == FfiOpenvrPropertyType::Bool) {
result = vr_properties->SetBoolProperty(this->prop_container, key, prop.value.bool_);
} else if (prop.type == OpenvrPropertyType::Float) {
} else if (prop.type == FfiOpenvrPropertyType::Float) {
result = vr_properties->SetFloatProperty(this->prop_container, key, prop.value.float_);
} else if (prop.type == OpenvrPropertyType::Int32) {
} else if (prop.type == FfiOpenvrPropertyType::Int32) {
result = vr_properties->SetInt32Property(this->prop_container, key, prop.value.int32);
} else if (prop.type == OpenvrPropertyType::Uint64) {
} else if (prop.type == FfiOpenvrPropertyType::Uint64) {
result =
vr_properties->SetUint64Property(this->prop_container, key, prop.value.uint64);
} else if (prop.type == OpenvrPropertyType::Vector3) {
} else if (prop.type == FfiOpenvrPropertyType::Vector3) {
auto vec3 = vr::HmdVector3_t{};
vec3.v[0] = prop.value.vector3[0];
vec3.v[1] = prop.value.vector3[1];
vec3.v[2] = prop.value.vector3[2];
result = vr_properties->SetVec3Property(this->prop_container, key, vec3);
} else if (prop.type == OpenvrPropertyType::Double) {
} else if (prop.type == FfiOpenvrPropertyType::Double) {
result =
vr_properties->SetDoubleProperty(this->prop_container, key, prop.value.double_);
} else if (prop.type == OpenvrPropertyType::String) {
} else if (prop.type == FfiOpenvrPropertyType::String) {
result =
vr_properties->SetStringProperty(this->prop_container, key, prop.value.string);
} else {
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/cpp/alvr_server/TrackedDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TrackedDevice {
vr::TrackedDeviceIndex_t object_id = vr::k_unTrackedDeviceIndexInvalid;
vr::PropertyContainerHandle_t prop_container = vr::k_ulInvalidPropertyContainer;

void set_prop(OpenvrProperty prop);
void set_prop(FfiOpenvrProperty prop);

TrackedDevice(uint64_t device_id) : device_id(device_id) {}
};
12 changes: 6 additions & 6 deletions alvr/server/cpp/alvr_server/alvr_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ void RequestIDR() {

void SetTracking(unsigned long long targetTimestampNs,
float controllerPoseTimeOffsetS,
const AlvrDeviceMotion *deviceMotions,
const FfiDeviceMotion *deviceMotions,
int motionsCount,
OculusHand leftHand,
OculusHand rightHand) {
FfiHandSkeleton leftHand,
FfiHandSkeleton rightHand) {
for (int i = 0; i < motionsCount; i++) {
if (deviceMotions[i].deviceID == HEAD_ID && g_driver_provider.hmd) {
g_driver_provider.hmd->OnPoseUpdated(targetTimestampNs, deviceMotions[i]);
Expand Down Expand Up @@ -281,15 +281,15 @@ void ShutdownSteamvr() {
}
}

void SetOpenvrProperty(unsigned long long top_level_path, OpenvrProperty prop) {
void SetOpenvrProperty(unsigned long long top_level_path, FfiOpenvrProperty prop) {
auto device_it = g_driver_provider.tracked_devices.find(top_level_path);

if (device_it != g_driver_provider.tracked_devices.end()) {
device_it->second->set_prop(prop);
}
}

void SetViewsConfig(ViewsConfigData config) {
void SetViewsConfig(FfiViewsConfig config) {
if (g_driver_provider.hmd) {
g_driver_provider.hmd->SetViewsConfig(config);
}
Expand All @@ -306,7 +306,7 @@ void SetBattery(unsigned long long top_level_path, float gauge_value, bool is_pl
}
}

void SetButton(unsigned long long path, AlvrButtonValue value) {
void SetButton(unsigned long long path, FfiButtonValue value) {
if (std::find(LEFT_CONTROLLER_BUTTON_IDS.begin(), LEFT_CONTROLLER_BUTTON_IDS.end(), path) !=
LEFT_CONTROLLER_BUTTON_IDS.end()) {
g_driver_provider.left_controller->SetButton(path, value);
Expand Down
44 changes: 22 additions & 22 deletions alvr/server/cpp/alvr_server/bindings.h
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#pragma once

struct EyeFov {
struct FfiFov {
float left;
float right;
float up;
float down;
};

struct AlvrQuat {
struct FfiQuat {
float x;
float y;
float z;
float w;
};

struct OculusHand {
struct FfiHandSkeleton {
bool enabled;
AlvrQuat boneRotations[19];
FfiQuat boneRotations[19];
};

struct AlvrDeviceMotion {
struct FfiDeviceMotion {
unsigned long long deviceID;
AlvrQuat orientation;
FfiQuat orientation;
float position[3];
float linearVelocity[3];
float angularVelocity[3];
};

enum OpenvrPropertyType {
enum FfiOpenvrPropertyType {
Bool,
Float,
Int32,
Expand All @@ -37,7 +37,7 @@ enum OpenvrPropertyType {
String,
};

union OpenvrPropertyValue {
union FfiOpenvrPropertyValue {
bool bool_;
float float_;
int int32;
Expand All @@ -47,24 +47,24 @@ union OpenvrPropertyValue {
char string[64];
};

struct OpenvrProperty {
struct FfiOpenvrProperty {
unsigned int key;
OpenvrPropertyType type;
OpenvrPropertyValue value;
FfiOpenvrPropertyType type;
FfiOpenvrPropertyValue value;
};

struct ViewsConfigData {
EyeFov fov[2];
struct FfiViewsConfig {
FfiFov fov[2];
float ipd_m;
};

enum AlvrButtonType {
enum FfiButtonType {
BUTTON_TYPE_BINARY,
BUTTON_TYPE_SCALAR,
};

struct AlvrButtonValue {
AlvrButtonType type;
struct FfiButtonValue {
FfiButtonType type;
union {
bool binary;
float scalar;
Expand Down Expand Up @@ -121,19 +121,19 @@ extern "C" void SendVSync(float frameIntervalS);
extern "C" void RequestIDR();
extern "C" void SetTracking(unsigned long long targetTimestampNs,
float controllerPoseTimeOffsetS,
const AlvrDeviceMotion *deviceMotions,
const FfiDeviceMotion *deviceMotions,
int motionsCount,
OculusHand leftHand,
OculusHand rightHand);
FfiHandSkeleton leftHand,
FfiHandSkeleton rightHand);
extern "C" void ReportNetworkLatency(unsigned long long latencyUs);
extern "C" void VideoErrorReportReceive();
extern "C" void ShutdownSteamvr();

extern "C" void SetOpenvrProperty(unsigned long long topLevelPath, OpenvrProperty prop);
extern "C" void SetOpenvrProperty(unsigned long long topLevelPath, FfiOpenvrProperty prop);
extern "C" void SetChaperone(float areaWidth, float areaHeight);
extern "C" void SetViewsConfig(ViewsConfigData config);
extern "C" void SetViewsConfig(FfiViewsConfig config);
extern "C" void SetBattery(unsigned long long topLevelPath, float gauge_value, bool is_plugged);
extern "C" void SetButton(unsigned long long path, AlvrButtonValue value);
extern "C" void SetButton(unsigned long long path, FfiButtonValue value);

extern "C" void SetBitrateParameters(unsigned long long bitrate_mbs,
bool adaptive_bitrate_enabled,
Expand Down
Loading

0 comments on commit c311845

Please sign in to comment.