st/oxr: Fill XrViewConfigurationView with new two call helper

The previous two call helper macro copied the entire input struct to output struct.
In particular this did not keep the .type and .next fields intact.

Rather than trying to keep those intact, each struct type should have its own fill function,
only filling in the data we actually want to fill in.
This commit is contained in:
Christoph Haag 2020-03-04 15:50:48 +01:00
parent 622320904a
commit de7d9de5ae
2 changed files with 40 additions and 3 deletions

View file

@ -278,6 +278,20 @@ oxr_system_get_view_conf_properties(
return XR_SUCCESS;
}
static void
view_configuration_view_fill_in(XrViewConfigurationView *target_view,
XrViewConfigurationView *source_view)
{
// clang-format off
target_view->recommendedImageRectWidth = source_view->recommendedImageRectWidth;
target_view->maxImageRectWidth = source_view->maxImageRectWidth;
target_view->recommendedImageRectHeight = source_view->recommendedImageRectHeight;
target_view->maxImageRectHeight = source_view->maxImageRectHeight;
target_view->recommendedSwapchainSampleCount = source_view->recommendedSwapchainSampleCount;
target_view->maxSwapchainSampleCount = source_view->maxSwapchainSampleCount;
// clang-format on
}
XrResult
oxr_system_enumerate_view_conf_views(
struct oxr_logger *log,
@ -293,6 +307,7 @@ oxr_system_enumerate_view_conf_views(
"invalid view configuration type");
}
OXR_TWO_CALL_HELPER(log, viewCapacityInput, viewCountOutput, views, 2,
sys->views, XR_SUCCESS);
OXR_TWO_CALL_FILL_IN_HELPER(log, viewCapacityInput, viewCountOutput,
views, 2, view_configuration_view_fill_in,
sys->views, XR_SUCCESS);
}

View file

@ -37,7 +37,29 @@ extern "C" {
return sval; \
} while (false)
//! Calls fill_fn(&output_struct[i], &source_struct[i]) to fill output_structs
#define OXR_TWO_CALL_FILL_IN_HELPER(log, cnt_input, cnt_output, \
output_structs, count, fill_fn, \
source_structs, sval) \
do { \
if (cnt_output == NULL) { \
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, \
#cnt_output); \
} \
*cnt_output = count; \
\
if (cnt_input == 0) { \
return sval; \
} \
if (cnt_input < count) { \
return oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT, \
#cnt_input); \
} \
for (uint32_t i = 0; i < count; i++) { \
fill_fn(&output_structs[i], &source_structs[i]); \
} \
return sval; \
} while (false)
#ifdef __cplusplus
}