Skip to content

Commit

Permalink
Fix errors caused by incorrect use of the OpenXR APIs
Browse files Browse the repository at this point in the history
Future OpenXR runtimes are more stringent on validating correct usage
of APIs. The structure type of XrView objects passed into xrLocateViews
are not currently set. The current version of the WMR OpenXR runtime
from the Windows store does not do this validation, but future versions
will.


Bug: 1015223
Change-Id: Ib4e3fca557cc6e192bd166e2ebb604a3884e7811
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1865042
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Commit-Queue: Patrick To <patrto@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#709617}
  • Loading branch information
patrto authored and Commit Bot committed Oct 25, 2019
1 parent 49acf1e commit f997836
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
4 changes: 3 additions & 1 deletion device/vr/openxr/openxr_api_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,9 @@ XrResult OpenXrApiWrapper::LocateViews(XrReferenceSpaceType type,
NOTREACHED();
}

std::vector<XrView> new_views(kNumViews);
// Initialize the XrView objects' type field to XR_TYPE_VIEW. xrLocateViews
// fails validation if this isn't set.
std::vector<XrView> new_views(kNumViews, {XR_TYPE_VIEW});
uint32_t view_count;
RETURN_IF_XR_FAILED(xrLocateViews(session_, &view_locate_info, &view_state,
new_views.size(), &view_count,
Expand Down
12 changes: 8 additions & 4 deletions device/vr/openxr/test/fake_openxr_impl_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ XrResult xrCreateReferenceSpace(XrSession session,
RETURN_IF(create_info->type != XR_TYPE_REFERENCE_SPACE_CREATE_INFO,
XR_ERROR_VALIDATION_FAILURE,
"XrReferenceSpaceCreateInfo type invalid");
RETURN_IF(create_info->referenceSpaceType != XR_REFERENCE_SPACE_TYPE_LOCAL &&
create_info->referenceSpaceType != XR_REFERENCE_SPACE_TYPE_VIEW,
XR_ERROR_VALIDATION_FAILURE,
"XrReferenceSpaceCreateInfo referenceSpaceType invalid");
RETURN_IF(
create_info->referenceSpaceType != XR_REFERENCE_SPACE_TYPE_LOCAL &&
create_info->referenceSpaceType != XR_REFERENCE_SPACE_TYPE_VIEW &&
create_info->referenceSpaceType != XR_REFERENCE_SPACE_TYPE_STAGE,
XR_ERROR_VALIDATION_FAILURE,
"XrReferenceSpaceCreateInfo referenceSpaceType invalid");
RETURN_IF_XR_FAILED(g_test_helper.ValidateXrPosefIsIdentity(
create_info->poseInReferenceSpace));

Expand Down Expand Up @@ -595,6 +597,8 @@ XrResult xrLocateViews(XrSession session,
"xrLocateViews view_locate_info type invalid");
RETURN_IF_XR_FAILED(g_test_helper.ValidateSpace(view_locate_info->space));
if (view_capacity_input != 0) {
RETURN_IF_XR_FAILED(
g_test_helper.ValidateViews(view_capacity_input, views));
RETURN_IF_FALSE(g_test_helper.UpdateViewFOV(views, view_capacity_input),
XR_ERROR_VALIDATION_FAILURE,
"xrLocateViews UpdateViewFOV failed");
Expand Down
17 changes: 15 additions & 2 deletions device/vr/openxr/test/openxr_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,11 @@ XrSpace OpenXrTestHelper::CreateReferenceSpace(XrReferenceSpaceType type) {
case XR_REFERENCE_SPACE_TYPE_LOCAL:
reference_spaces_[cur_space] = "/reference_space/local";
break;
case XR_REFERENCE_SPACE_TYPE_STAGE:
reference_spaces_[cur_space] = "/reference_space/stage";
break;
default:
NOTREACHED() << "Test currently only supports to create View space and "
"local space";
NOTREACHED() << "Unsupported XrReferenceSpaceType: " << type;
}
return cur_space;
}
Expand Down Expand Up @@ -753,3 +755,14 @@ XrResult OpenXrTestHelper::ValidateXrPosefIsIdentity(

return XR_SUCCESS;
}

XrResult OpenXrTestHelper::ValidateViews(uint32_t view_capacity_input,
XrView* views) const {
for (uint32_t i = 0; i < view_capacity_input; i++) {
XrView view = views[i];
RETURN_IF_FALSE(view.type == XR_TYPE_VIEW, XR_ERROR_VALIDATION_FAILURE,
"XrView type invalid");
}

return XR_SUCCESS;
}
1 change: 1 addition & 0 deletions device/vr/openxr/test/openxr_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class OpenXrTestHelper : public device::ServiceTestHook {
XrResult ValidatePath(XrPath path) const;
XrResult ValidatePredictedDisplayTime(XrTime time) const;
XrResult ValidateXrPosefIsIdentity(const XrPosef& pose) const;
XrResult ValidateViews(uint32_t view_capacity_input, XrView* views) const;

// Properties of the mock OpenXR runtime that does not change are created
// as static variables.
Expand Down

0 comments on commit f997836

Please sign in to comment.