Commit ef0a25d5 authored by Kevin Qin's avatar Kevin Qin Committed by Commit Bot

Use constexpr for OpenXR Test static Variables

Convert OpenXR test static variables to constexpr according to the code
style guide.

Bug: 1027794
Change-Id: Ic915a14d85df8f65baba3e363a9827b28f14bb46
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1957130Reviewed-by: default avatarAlexander Cooper <alcooper@chromium.org>
Commit-Queue: Zheng Qin <zheqi@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#723511}
parent 4d89104f
...@@ -152,12 +152,12 @@ XrResult xrCreateInstance(const XrInstanceCreateInfo* create_info, ...@@ -152,12 +152,12 @@ XrResult xrCreateInstance(const XrInstanceCreateInfo* create_info,
"XrInstanceCreateInfo ApiLayer is not supported by this version of test"); "XrInstanceCreateInfo ApiLayer is not supported by this version of test");
RETURN_IF(create_info->enabledExtensionCount != RETURN_IF(create_info->enabledExtensionCount !=
OpenXrTestHelper::NumExtensionsSupported(), OpenXrTestHelper::kNumExtensionsSupported,
XR_ERROR_VALIDATION_FAILURE, "enabledExtensionCount invalid"); XR_ERROR_VALIDATION_FAILURE, "enabledExtensionCount invalid");
for (uint32_t i = 0; i < create_info->enabledExtensionCount; i++) { for (uint32_t i = 0; i < create_info->enabledExtensionCount; i++) {
bool valid_extension = false; bool valid_extension = false;
for (size_t j = 0; j < OpenXrTestHelper::NumExtensionsSupported(); j++) { for (size_t j = 0; j < OpenXrTestHelper::kNumExtensionsSupported; j++) {
if (strcmp(create_info->enabledExtensionNames[i], if (strcmp(create_info->enabledExtensionNames[i],
OpenXrTestHelper::kExtensions[j]) == 0) { OpenXrTestHelper::kExtensions[j]) == 0) {
valid_extension = true; valid_extension = true;
...@@ -381,24 +381,24 @@ XrResult xrEnumerateInstanceExtensionProperties( ...@@ -381,24 +381,24 @@ XrResult xrEnumerateInstanceExtensionProperties(
DVLOG(2) << __FUNCTION__; DVLOG(2) << __FUNCTION__;
RETURN_IF( RETURN_IF(
property_capacity_input < OpenXrTestHelper::NumExtensionsSupported() && property_capacity_input < OpenXrTestHelper::kNumExtensionsSupported &&
property_capacity_input != 0, property_capacity_input != 0,
XR_ERROR_SIZE_INSUFFICIENT, "XrExtensionProperties array is too small"); XR_ERROR_SIZE_INSUFFICIENT, "XrExtensionProperties array is too small");
RETURN_IF(property_count_output == nullptr, XR_ERROR_VALIDATION_FAILURE, RETURN_IF(property_count_output == nullptr, XR_ERROR_VALIDATION_FAILURE,
"property_count_output is nullptr"); "property_count_output is nullptr");
*property_count_output = OpenXrTestHelper::NumExtensionsSupported(); *property_count_output = OpenXrTestHelper::kNumExtensionsSupported;
if (property_capacity_input == 0) { if (property_capacity_input == 0) {
return XR_SUCCESS; return XR_SUCCESS;
} }
RETURN_IF( RETURN_IF(
property_capacity_input != OpenXrTestHelper::NumExtensionsSupported(), property_capacity_input != OpenXrTestHelper::kNumExtensionsSupported,
XR_ERROR_VALIDATION_FAILURE, XR_ERROR_VALIDATION_FAILURE,
"property_capacity_input is neither 0 or NumExtensionsSupported()"); "property_capacity_input is neither 0 or kNumExtensionsSupported");
RETURN_IF(properties == nullptr, XR_ERROR_VALIDATION_FAILURE, RETURN_IF(properties == nullptr, XR_ERROR_VALIDATION_FAILURE,
"XrExtensionProperties is nullptr"); "XrExtensionProperties is nullptr");
for (uint32_t i = 0; i < OpenXrTestHelper::NumExtensionsSupported(); i++) { for (uint32_t i = 0; i < OpenXrTestHelper::kNumExtensionsSupported; i++) {
properties[i].type = XR_TYPE_EXTENSION_PROPERTIES; properties[i].type = XR_TYPE_EXTENSION_PROPERTIES;
errno_t error = strcpy_s(properties[i].extensionName, errno_t error = strcpy_s(properties[i].extensionName,
base::size(properties[i].extensionName), base::size(properties[i].extensionName),
...@@ -425,14 +425,14 @@ XrResult xrEnumerateViewConfigurationViews( ...@@ -425,14 +425,14 @@ XrResult xrEnumerateViewConfigurationViews(
"xrEnumerateViewConfigurationViews viewConfigurationType invalid"); "xrEnumerateViewConfigurationViews viewConfigurationType invalid");
RETURN_IF(view_count_output == nullptr, XR_ERROR_VALIDATION_FAILURE, RETURN_IF(view_count_output == nullptr, XR_ERROR_VALIDATION_FAILURE,
"view_count_output is nullptr"); "view_count_output is nullptr");
*view_count_output = OpenXrTestHelper::NumViews(); *view_count_output = OpenXrTestHelper::kNumViews;
if (view_capacity_input == 0) { if (view_capacity_input == 0) {
return XR_SUCCESS; return XR_SUCCESS;
} }
RETURN_IF(view_capacity_input != OpenXrTestHelper::NumViews(), RETURN_IF(view_capacity_input != OpenXrTestHelper::kNumViews,
XR_ERROR_VALIDATION_FAILURE, XR_ERROR_VALIDATION_FAILURE,
"view_capacity_input is neither 0 or NumViews()"); "view_capacity_input is neither 0 or kNumViews");
RETURN_IF(views == nullptr, XR_ERROR_VALIDATION_FAILURE, RETURN_IF(views == nullptr, XR_ERROR_VALIDATION_FAILURE,
"XrViewConfigurationView is nullptr"); "XrViewConfigurationView is nullptr");
views[0] = OpenXrTestHelper::kViewConfigurationViews[0]; views[0] = OpenXrTestHelper::kViewConfigurationViews[0];
......
...@@ -20,38 +20,6 @@ bool PathContainsString(const std::string& path, const std::string& s) { ...@@ -20,38 +20,6 @@ bool PathContainsString(const std::string& path, const std::string& s) {
} // namespace } // namespace
// Initialize static variables in OpenXrTestHelper.
const char* OpenXrTestHelper::kExtensions[] = {
XR_KHR_D3D11_ENABLE_EXTENSION_NAME};
const uint32_t OpenXrTestHelper::kDimension = 128;
const uint32_t OpenXrTestHelper::kSwapCount = 1;
const uint32_t OpenXrTestHelper::kMinSwapchainBuffering = 3;
const uint32_t OpenXrTestHelper::kViewCount = 2;
const XrViewConfigurationView OpenXrTestHelper::kViewConfigView = {
XR_TYPE_VIEW_CONFIGURATION_VIEW, nullptr,
OpenXrTestHelper::kDimension, OpenXrTestHelper::kDimension,
OpenXrTestHelper::kDimension, OpenXrTestHelper::kDimension,
OpenXrTestHelper::kSwapCount, OpenXrTestHelper::kSwapCount};
XrViewConfigurationView OpenXrTestHelper::kViewConfigurationViews[] = {
OpenXrTestHelper::kViewConfigView, OpenXrTestHelper::kViewConfigView};
const XrViewConfigurationType OpenXrTestHelper::kViewConfigurationType =
XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
const XrEnvironmentBlendMode OpenXrTestHelper::kEnvironmentBlendMode =
XR_ENVIRONMENT_BLEND_MODE_OPAQUE;
const char* OpenXrTestHelper::kLocalReferenceSpacePath =
"/reference_space/local";
const char* OpenXrTestHelper::kStageReferenceSpacePath =
"/reference_space/stage";
const char* OpenXrTestHelper::kViewReferenceSpacePath = "/reference_space/view";
uint32_t OpenXrTestHelper::NumExtensionsSupported() {
return sizeof(kExtensions) / sizeof(kExtensions[0]);
}
uint32_t OpenXrTestHelper::NumViews() {
return sizeof(kViewConfigurationViews) / sizeof(kViewConfigurationViews[0]);
}
OpenXrTestHelper::OpenXrTestHelper() OpenXrTestHelper::OpenXrTestHelper()
// since openxr_statics is created first, so the first instance returned // since openxr_statics is created first, so the first instance returned
// should be a fake one since openxr_statics does not need to use // should be a fake one since openxr_statics does not need to use
......
...@@ -15,9 +15,11 @@ ...@@ -15,9 +15,11 @@
#include <vector> #include <vector>
#include "base/optional.h" #include "base/optional.h"
#include "base/stl_util.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "device/vr/test/test_hook.h" #include "device/vr/test/test_hook.h"
#include "third_party/openxr/src/include/openxr/openxr.h" #include "third_party/openxr/src/include/openxr/openxr.h"
#include "third_party/openxr/src/include/openxr/openxr_platform.h"
namespace gfx { namespace gfx {
class Transform; class Transform;
...@@ -111,21 +113,36 @@ class OpenXrTestHelper : public device::ServiceTestHook { ...@@ -111,21 +113,36 @@ class OpenXrTestHelper : public device::ServiceTestHook {
XrResult ValidateViews(uint32_t view_capacity_input, XrView* views) const; XrResult ValidateViews(uint32_t view_capacity_input, XrView* views) const;
// Properties of the mock OpenXR runtime that does not change are created // Properties of the mock OpenXR runtime that does not change are created
// as static variables. static constexpr const char* const kExtensions[] = {
static uint32_t NumExtensionsSupported(); XR_KHR_D3D11_ENABLE_EXTENSION_NAME};
static uint32_t NumViews(); static constexpr uint32_t kDimension = 128;
static const char* kExtensions[]; static constexpr uint32_t kSwapCount = 1;
static const uint32_t kDimension; static constexpr uint32_t kMinSwapchainBuffering = 3;
static const uint32_t kSwapCount; static constexpr uint32_t kViewCount = 2;
static const uint32_t kMinSwapchainBuffering; static constexpr XrViewConfigurationView kViewConfigView = {
static const uint32_t kViewCount; XR_TYPE_VIEW_CONFIGURATION_VIEW,
static const XrViewConfigurationView kViewConfigView; nullptr,
static XrViewConfigurationView kViewConfigurationViews[]; kDimension,
static const XrViewConfigurationType kViewConfigurationType; kDimension,
static const XrEnvironmentBlendMode kEnvironmentBlendMode; kDimension,
static const char* kLocalReferenceSpacePath; kDimension,
static const char* kStageReferenceSpacePath; kSwapCount,
static const char* kViewReferenceSpacePath; kSwapCount};
static constexpr XrViewConfigurationView kViewConfigurationViews[] = {
kViewConfigView, kViewConfigView};
static constexpr XrViewConfigurationType kViewConfigurationType =
XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
static constexpr XrEnvironmentBlendMode kEnvironmentBlendMode =
XR_ENVIRONMENT_BLEND_MODE_OPAQUE;
static constexpr const char* kLocalReferenceSpacePath =
"/reference_space/local";
static constexpr const char* kStageReferenceSpacePath =
"/reference_space/stage";
static constexpr const char* kViewReferenceSpacePath =
"/reference_space/view";
static constexpr uint32_t kNumExtensionsSupported = base::size(kExtensions);
static constexpr uint32_t kNumViews = base::size(kViewConfigurationViews);
private: private:
struct ActionProperties { struct ActionProperties {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment