From cc9b415a8fda3a371133f3b5c75f5d50d3778121 Mon Sep 17 00:00:00 2001 From: Christoph Haag Date: Thu, 4 Jun 2020 14:31:01 +0200 Subject: [PATCH] xrt: Add xrt_result_t return type to many functions Many functions returned void and were assumed to always succeed, and some functions returned only a bool to indicate vague success/failure. Now that these functions get piped over IPC all of them have to be able to indicate an IPC failure like for example an unreachable service. With the xrt_result_t return type they now have the opportunity to report various types of failures. --- src/xrt/compositor/client/comp_gl_client.c | 48 ++++----- src/xrt/compositor/client/comp_vk_client.c | 48 ++++----- src/xrt/compositor/main/comp_compositor.c | 30 ++++-- src/xrt/compositor/main/comp_swapchain.c | 24 +++-- src/xrt/include/xrt/xrt_compositor.h | 114 +++++++++++---------- src/xrt/include/xrt/xrt_defines.h | 2 + src/xrt/include/xrt/xrt_results.h | 1 + src/xrt/ipc/ipc_client_compositor.c | 88 ++++++++++------ src/xrt/state_trackers/oxr/oxr_swapchain.c | 6 +- 9 files changed, 205 insertions(+), 156 deletions(-) diff --git a/src/xrt/compositor/client/comp_gl_client.c b/src/xrt/compositor/client/comp_gl_client.c index d9b7d3a04..ec971fbc6 100644 --- a/src/xrt/compositor/client/comp_gl_client.c +++ b/src/xrt/compositor/client/comp_gl_client.c @@ -55,7 +55,7 @@ client_gl_swapchain_destroy(struct xrt_swapchain *xsc) free(sc); } -static bool +static xrt_result_t client_gl_swapchain_acquire_image(struct xrt_swapchain *xsc, uint32_t *index) { struct client_gl_swapchain *sc = client_gl_swapchain(xsc); @@ -64,7 +64,7 @@ client_gl_swapchain_acquire_image(struct xrt_swapchain *xsc, uint32_t *index) return xrt_swapchain_acquire_image(&sc->xscfd->base, index); } -static bool +static xrt_result_t client_gl_swapchain_wait_image(struct xrt_swapchain *xsc, uint64_t timeout, uint32_t index) @@ -75,7 +75,7 @@ client_gl_swapchain_wait_image(struct xrt_swapchain *xsc, return xrt_swapchain_wait_image(&sc->xscfd->base, timeout, index); } -static bool +static xrt_result_t client_gl_swapchain_release_image(struct xrt_swapchain *xsc, uint32_t index) { struct client_gl_swapchain *sc = client_gl_swapchain(xsc); @@ -91,60 +91,60 @@ client_gl_swapchain_release_image(struct xrt_swapchain *xsc, uint32_t index) * */ -static void +static xrt_result_t client_gl_compositor_begin_session(struct xrt_compositor *xc, enum xrt_view_type type) { struct client_gl_compositor *c = client_gl_compositor(xc); // Pipe down call into fd compositor. - xrt_comp_begin_session(&c->xcfd->base, type); + return xrt_comp_begin_session(&c->xcfd->base, type); } -static void +static xrt_result_t client_gl_compositor_end_session(struct xrt_compositor *xc) { struct client_gl_compositor *c = client_gl_compositor(xc); // Pipe down call into fd compositor. - xrt_comp_end_session(&c->xcfd->base); + return xrt_comp_end_session(&c->xcfd->base); } -static void +static xrt_result_t client_gl_compositor_wait_frame(struct xrt_compositor *xc, uint64_t *predicted_display_time, uint64_t *predicted_display_period) { struct client_gl_compositor *c = client_gl_compositor(xc); // Pipe down call into fd compositor. - xrt_comp_wait_frame(&c->xcfd->base, predicted_display_time, - predicted_display_period); + return xrt_comp_wait_frame(&c->xcfd->base, predicted_display_time, + predicted_display_period); } -static void +static xrt_result_t client_gl_compositor_begin_frame(struct xrt_compositor *xc) { struct client_gl_compositor *c = client_gl_compositor(xc); // Pipe down call into fd compositor. - xrt_comp_begin_frame(&c->xcfd->base); + return xrt_comp_begin_frame(&c->xcfd->base); } -static void +static xrt_result_t client_gl_compositor_discard_frame(struct xrt_compositor *xc) { struct client_gl_compositor *c = client_gl_compositor(xc); // Pipe down call into fd compositor. - xrt_comp_discard_frame(&c->xcfd->base); + return xrt_comp_discard_frame(&c->xcfd->base); } -static void +static xrt_result_t client_gl_compositor_layer_begin(struct xrt_compositor *xc, enum xrt_blend_mode env_blend_mode) { struct client_gl_compositor *c = client_gl_compositor(xc); - xrt_comp_layer_begin(&c->xcfd->base, env_blend_mode); + return xrt_comp_layer_begin(&c->xcfd->base, env_blend_mode); } -static void +static xrt_result_t client_gl_compositor_layer_stereo_projection( struct xrt_compositor *xc, uint64_t timestamp, @@ -171,13 +171,13 @@ client_gl_compositor_layer_stereo_projection( l_xscfd = &client_gl_swapchain(l_sc)->xscfd->base; r_xscfd = &client_gl_swapchain(r_sc)->xscfd->base; - xrt_comp_layer_stereo_projection( + return xrt_comp_layer_stereo_projection( &c->xcfd->base, timestamp, xdev, name, layer_flags, l_xscfd, l_image_index, l_rect, l_array_index, l_fov, l_pose, r_xscfd, r_image_index, r_rect, r_array_index, r_fov, r_pose, true); } -static void +static xrt_result_t client_gl_compositor_layer_quad(struct xrt_compositor *xc, uint64_t timestamp, struct xrt_device *xdev, @@ -197,17 +197,17 @@ client_gl_compositor_layer_quad(struct xrt_compositor *xc, xscfb = &client_gl_swapchain(sc)->xscfd->base; - xrt_comp_layer_quad(&c->xcfd->base, timestamp, xdev, name, layer_flags, - visibility, xscfb, image_index, rect, array_index, - pose, size, true); + return xrt_comp_layer_quad(&c->xcfd->base, timestamp, xdev, name, + layer_flags, visibility, xscfb, image_index, + rect, array_index, pose, size, true); } -static void +static xrt_result_t client_gl_compositor_layer_commit(struct xrt_compositor *xc) { struct client_gl_compositor *c = client_gl_compositor(xc); - xrt_comp_layer_commit(&c->xcfd->base); + return xrt_comp_layer_commit(&c->xcfd->base); } static int64_t diff --git a/src/xrt/compositor/client/comp_vk_client.c b/src/xrt/compositor/client/comp_vk_client.c index c39b809ea..77ef8d301 100644 --- a/src/xrt/compositor/client/comp_vk_client.c +++ b/src/xrt/compositor/client/comp_vk_client.c @@ -69,7 +69,7 @@ client_vk_swapchain_destroy(struct xrt_swapchain *xsc) free(sc); } -static bool +static xrt_result_t client_vk_swapchain_acquire_image(struct xrt_swapchain *xsc, uint32_t *index) { struct client_vk_swapchain *sc = client_vk_swapchain(xsc); @@ -78,7 +78,7 @@ client_vk_swapchain_acquire_image(struct xrt_swapchain *xsc, uint32_t *index) return xrt_swapchain_acquire_image(&sc->xscfd->base, index); } -static bool +static xrt_result_t client_vk_swapchain_wait_image(struct xrt_swapchain *xsc, uint64_t timeout, uint32_t index) @@ -89,7 +89,7 @@ client_vk_swapchain_wait_image(struct xrt_swapchain *xsc, return xrt_swapchain_wait_image(&sc->xscfd->base, timeout, index); } -static bool +static xrt_result_t client_vk_swapchain_release_image(struct xrt_swapchain *xsc, uint32_t index) { struct client_vk_swapchain *sc = client_vk_swapchain(xsc); @@ -120,60 +120,60 @@ client_vk_compositor_destroy(struct xrt_compositor *xc) free(c); } -static void +static xrt_result_t client_vk_compositor_begin_session(struct xrt_compositor *xc, enum xrt_view_type type) { struct client_vk_compositor *c = client_vk_compositor(xc); // Pipe down call into fd compositor. - xrt_comp_begin_session(&c->xcfd->base, type); + return xrt_comp_begin_session(&c->xcfd->base, type); } -static void +static xrt_result_t client_vk_compositor_end_session(struct xrt_compositor *xc) { struct client_vk_compositor *c = client_vk_compositor(xc); // Pipe down call into fd compositor. - xrt_comp_end_session(&c->xcfd->base); + return xrt_comp_end_session(&c->xcfd->base); } -static void +static xrt_result_t client_vk_compositor_wait_frame(struct xrt_compositor *xc, uint64_t *predicted_display_time, uint64_t *predicted_display_period) { struct client_vk_compositor *c = client_vk_compositor(xc); // Pipe down call into fd compositor. - xrt_comp_wait_frame(&c->xcfd->base, predicted_display_time, - predicted_display_period); + return xrt_comp_wait_frame(&c->xcfd->base, predicted_display_time, + predicted_display_period); } -static void +static xrt_result_t client_vk_compositor_begin_frame(struct xrt_compositor *xc) { struct client_vk_compositor *c = client_vk_compositor(xc); // Pipe down call into fd compositor. - xrt_comp_begin_frame(&c->xcfd->base); + return xrt_comp_begin_frame(&c->xcfd->base); } -static void +static xrt_result_t client_vk_compositor_discard_frame(struct xrt_compositor *xc) { struct client_vk_compositor *c = client_vk_compositor(xc); // Pipe down call into fd compositor. - xrt_comp_discard_frame(&c->xcfd->base); + return xrt_comp_discard_frame(&c->xcfd->base); } -static void +static xrt_result_t client_vk_compositor_layer_begin(struct xrt_compositor *xc, enum xrt_blend_mode env_blend_mode) { struct client_vk_compositor *c = client_vk_compositor(xc); - xrt_comp_layer_begin(&c->xcfd->base, env_blend_mode); + return xrt_comp_layer_begin(&c->xcfd->base, env_blend_mode); } -static void +static xrt_result_t client_vk_compositor_layer_stereo_projection( struct xrt_compositor *xc, uint64_t timestamp, @@ -200,13 +200,13 @@ client_vk_compositor_layer_stereo_projection( l_xscfd = &client_vk_swapchain(l_sc)->xscfd->base; r_xscfd = &client_vk_swapchain(r_sc)->xscfd->base; - xrt_comp_layer_stereo_projection( + return xrt_comp_layer_stereo_projection( &c->xcfd->base, timestamp, xdev, name, layer_flags, l_xscfd, l_image_index, l_rect, l_array_index, l_fov, l_pose, r_xscfd, r_image_index, r_rect, r_array_index, r_fov, r_pose, false); } -static void +static xrt_result_t client_vk_compositor_layer_quad(struct xrt_compositor *xc, uint64_t timestamp, struct xrt_device *xdev, @@ -226,17 +226,17 @@ client_vk_compositor_layer_quad(struct xrt_compositor *xc, xscfb = &client_vk_swapchain(sc)->xscfd->base; - xrt_comp_layer_quad(&c->xcfd->base, timestamp, xdev, name, layer_flags, - visibility, xscfb, image_index, rect, array_index, - pose, size, false); + return xrt_comp_layer_quad(&c->xcfd->base, timestamp, xdev, name, + layer_flags, visibility, xscfb, image_index, + rect, array_index, pose, size, false); } -static void +static xrt_result_t client_vk_compositor_layer_commit(struct xrt_compositor *xc) { struct client_vk_compositor *c = client_vk_compositor(xc); - xrt_comp_layer_commit(&c->xcfd->base); + return xrt_comp_layer_commit(&c->xcfd->base); } static struct xrt_swapchain * diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index 5bcf18033..6ca0a045d 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -109,18 +109,20 @@ compositor_destroy(struct xrt_compositor *xc) free(c); } -static void +static xrt_result_t compositor_begin_session(struct xrt_compositor *xc, enum xrt_view_type type) { struct comp_compositor *c = comp_compositor(xc); COMP_DEBUG(c, "BEGIN_SESSION"); + return XRT_SUCCESS; } -static void +static xrt_result_t compositor_end_session(struct xrt_compositor *xc) { struct comp_compositor *c = comp_compositor(xc); COMP_DEBUG(c, "END_SESSION"); + return XRT_SUCCESS; } /*! @@ -168,7 +170,7 @@ compositor_wait_vsync_or_time(struct comp_compositor *c, int64_t wake_up_time) return ret; } -static void +static xrt_result_t compositor_wait_frame(struct xrt_compositor *xc, uint64_t *predicted_display_time, uint64_t *predicted_display_period) @@ -186,7 +188,7 @@ compositor_wait_frame(struct xrt_compositor *xc, *predicted_display_period = interval_ns; c->last_next_display_time = now_ns + interval_ns; *predicted_display_time = c->last_next_display_time; - return; + return XRT_SUCCESS; } // First estimate of next display time. @@ -217,24 +219,26 @@ compositor_wait_frame(struct xrt_compositor *xc, *predicted_display_time = next_display_time; c->last_next_display_time = next_display_time; - return; + return XRT_SUCCESS; } } } -static void +static xrt_result_t compositor_begin_frame(struct xrt_compositor *xc) { struct comp_compositor *c = comp_compositor(xc); COMP_SPEW(c, "BEGIN_FRAME"); c->app_profiling.last_begin = os_monotonic_get_ns(); + return XRT_SUCCESS; } -static void +static xrt_result_t compositor_discard_frame(struct xrt_compositor *xc) { struct comp_compositor *c = comp_compositor(xc); COMP_SPEW(c, "DISCARD_FRAME"); + return XRT_SUCCESS; } static void @@ -274,7 +278,7 @@ compositor_add_frame_timing(struct comp_compositor *c) (float)diff * 1. / 1000. * 1. / 1000.; } -static void +static xrt_result_t compositor_layer_begin(struct xrt_compositor *xc, enum xrt_blend_mode env_blend_mode) { @@ -285,9 +289,10 @@ compositor_layer_begin(struct xrt_compositor *xc, c->slots[slot_id].env_blend_mode = env_blend_mode; c->slots[slot_id].num_layers = 0; + return XRT_SUCCESS; } -static void +static xrt_result_t compositor_layer_stereo_projection(struct xrt_compositor *xc, uint64_t timestamp, struct xrt_device *xdev, @@ -326,9 +331,10 @@ compositor_layer_stereo_projection(struct xrt_compositor *xc, layer->type = COMP_LAYER_STEREO_PROJECTION; c->slots[slot_id].num_layers++; + return XRT_SUCCESS; } -static void +static xrt_result_t compositor_layer_quad(struct xrt_compositor *xc, uint64_t timestamp, struct xrt_device *xdev, @@ -363,9 +369,10 @@ compositor_layer_quad(struct xrt_compositor *xc, layer->type = COMP_LAYER_QUAD; c->slots[slot_id].num_layers++; + return XRT_SUCCESS; } -static void +static xrt_result_t compositor_layer_commit(struct xrt_compositor *xc) { struct comp_compositor *c = comp_compositor(xc); @@ -418,6 +425,7 @@ compositor_layer_commit(struct xrt_compositor *xc) // Now is a good point to garbage collect. comp_compositor_garbage_collect(c); + return XRT_SUCCESS; } diff --git a/src/xrt/compositor/main/comp_swapchain.c b/src/xrt/compositor/main/comp_swapchain.c index b2d06bbe6..ef7f5ca7e 100644 --- a/src/xrt/compositor/main/comp_swapchain.c +++ b/src/xrt/compositor/main/comp_swapchain.c @@ -26,7 +26,7 @@ swapchain_destroy(struct xrt_swapchain *xsc) u_threading_stack_push(&sc->c->threading.destroy_swapchains, sc); } -static bool +static xrt_result_t swapchain_acquire_image(struct xrt_swapchain *xsc, uint32_t *index) { struct comp_swapchain *sc = comp_swapchain(xsc); @@ -34,10 +34,15 @@ swapchain_acquire_image(struct xrt_swapchain *xsc, uint32_t *index) COMP_SPEW(sc->c, "ACQUIRE_IMAGE"); // Returns negative on empty fifo. - return u_index_fifo_pop(&sc->fifo, index) >= 0; + int res = u_index_fifo_pop(&sc->fifo, index); + if (res >= 0) { + return XRT_SUCCESS; + } else { + return XRT_ERROR_NO_IMAGE_AVAILABLE; + } } -static bool +static xrt_result_t swapchain_wait_image(struct xrt_swapchain *xsc, uint64_t timeout, uint32_t index) @@ -45,19 +50,24 @@ swapchain_wait_image(struct xrt_swapchain *xsc, struct comp_swapchain *sc = comp_swapchain(xsc); COMP_SPEW(sc->c, "WAIT_IMAGE"); - return true; + return XRT_SUCCESS; } -static bool +static xrt_result_t swapchain_release_image(struct xrt_swapchain *xsc, uint32_t index) { struct comp_swapchain *sc = comp_swapchain(xsc); COMP_SPEW(sc->c, "RELEASE_IMAGE"); - u_index_fifo_push(&sc->fifo, index); + int res = u_index_fifo_push(&sc->fifo, index); - return true; + if (res >= 0) { + return XRT_SUCCESS; + } else { + // FIFO full + return XRT_ERROR_NO_IMAGE_AVAILABLE; + } } static VkResult diff --git a/src/xrt/include/xrt/xrt_compositor.h b/src/xrt/include/xrt/xrt_compositor.h index 239b8ffef..fc2454b9b 100644 --- a/src/xrt/include/xrt/xrt_compositor.h +++ b/src/xrt/include/xrt/xrt_compositor.h @@ -91,19 +91,21 @@ struct xrt_swapchain * See xrWaitSwapchainImage, must make sure that no image is acquired * before calling acquire_image. */ - bool (*acquire_image)(struct xrt_swapchain *xsc, uint32_t *index); + xrt_result_t (*acquire_image)(struct xrt_swapchain *xsc, + uint32_t *index); /*! * See xrWaitSwapchainImage, state tracker needs to track index. */ - bool (*wait_image)(struct xrt_swapchain *xsc, - uint64_t timeout, - uint32_t index); + xrt_result_t (*wait_image)(struct xrt_swapchain *xsc, + uint64_t timeout, + uint32_t index); /*! * See xrReleaseSwapchainImage, state tracker needs to track index. */ - bool (*release_image)(struct xrt_swapchain *xsc, uint32_t index); + xrt_result_t (*release_image)(struct xrt_swapchain *xsc, + uint32_t index); }; /*! @@ -113,7 +115,7 @@ struct xrt_swapchain * * @public @memberof xrt_swapchain */ -static inline bool +static inline xrt_result_t xrt_swapchain_acquire_image(struct xrt_swapchain *xsc, uint32_t *index) { return xsc->acquire_image(xsc, index); @@ -126,7 +128,7 @@ xrt_swapchain_acquire_image(struct xrt_swapchain *xsc, uint32_t *index) * * @public @memberof xrt_swapchain */ -static inline bool +static inline xrt_result_t xrt_swapchain_wait_image(struct xrt_swapchain *xsc, uint64_t timeout, uint32_t index) @@ -141,7 +143,7 @@ xrt_swapchain_wait_image(struct xrt_swapchain *xsc, * * @public @memberof xrt_swapchain */ -static inline bool +static inline xrt_result_t xrt_swapchain_release_image(struct xrt_swapchain *xsc, uint32_t index) { return xsc->release_image(xsc, index); @@ -216,27 +218,27 @@ struct xrt_compositor /*! * See xrBeginSession. */ - void (*begin_session)(struct xrt_compositor *xc, - enum xrt_view_type view_type); + xrt_result_t (*begin_session)(struct xrt_compositor *xc, + enum xrt_view_type view_type); /*! * See xrEndSession, unlike the OpenXR one the state tracker is * responsible to call discard frame before calling this function. See * discard_frame. */ - void (*end_session)(struct xrt_compositor *xc); + xrt_result_t (*end_session)(struct xrt_compositor *xc); /*! * See xrWaitFrame. */ - void (*wait_frame)(struct xrt_compositor *xc, - uint64_t *predicted_display_time, - uint64_t *predicted_display_period); + xrt_result_t (*wait_frame)(struct xrt_compositor *xc, + uint64_t *predicted_display_time, + uint64_t *predicted_display_period); /*! * See xrBeginFrame. */ - void (*begin_frame)(struct xrt_compositor *xc); + xrt_result_t (*begin_frame)(struct xrt_compositor *xc); /*! * This isn't in the OpenXR API but is explicit in the XRT interfaces. @@ -249,7 +251,7 @@ struct xrt_compositor * xc->begin_frame(xc) * ``` */ - void (*discard_frame)(struct xrt_compositor *xc); + xrt_result_t (*discard_frame)(struct xrt_compositor *xc); /*! * Begins layer submission, this and the other layer_* calls are @@ -257,8 +259,8 @@ struct xrt_compositor * @p layer_commit that layers will be displayed. From the point of view * of the swapchain the image is used as soon as it's given in a call. */ - void (*layer_begin)(struct xrt_compositor *xc, - enum xrt_blend_mode env_blend_mode); + xrt_result_t (*layer_begin)(struct xrt_compositor *xc, + enum xrt_blend_mode env_blend_mode); /*! * Adds a stereo projection layer for submissions. @@ -282,7 +284,7 @@ struct xrt_compositor * @param r_pose Right pose the left projection rendered with. * @param flip_y Flip Y texture coordinates. */ - void (*layer_stereo_projection)( + xrt_result_t (*layer_stereo_projection)( struct xrt_compositor *xc, uint64_t timestamp, struct xrt_device *xdev, @@ -320,25 +322,25 @@ struct xrt_compositor * @param size Size of the quad in meters. * @param flip_y Flip Y texture coordinates. */ - void (*layer_quad)(struct xrt_compositor *xc, - uint64_t timestamp, - struct xrt_device *xdev, - enum xrt_input_name name, - enum xrt_layer_composition_flags layer_flags, - enum xrt_layer_eye_visibility visibility, - struct xrt_swapchain *sc, - uint32_t image_index, - struct xrt_rect *rect, - uint32_t array_index, - struct xrt_pose *pose, - struct xrt_vec2 *size, - bool flip_y); + xrt_result_t (*layer_quad)(struct xrt_compositor *xc, + uint64_t timestamp, + struct xrt_device *xdev, + enum xrt_input_name name, + enum xrt_layer_composition_flags layer_flags, + enum xrt_layer_eye_visibility visibility, + struct xrt_swapchain *sc, + uint32_t image_index, + struct xrt_rect *rect, + uint32_t array_index, + struct xrt_pose *pose, + struct xrt_vec2 *size, + bool flip_y); /*! * Commits all of the submitted layers, it's from this on that the * compositor will use the layers. */ - void (*layer_commit)(struct xrt_compositor *xc); + xrt_result_t (*layer_commit)(struct xrt_compositor *xc); /*! * Teardown the compositor. @@ -406,10 +408,10 @@ xrt_comp_prepare_session(struct xrt_compositor *xc) * * @public @memberof xrt_compositor */ -static inline void +static inline xrt_result_t xrt_comp_begin_session(struct xrt_compositor *xc, enum xrt_view_type view_type) { - xc->begin_session(xc, view_type); + return xc->begin_session(xc, view_type); } /*! @@ -419,10 +421,10 @@ xrt_comp_begin_session(struct xrt_compositor *xc, enum xrt_view_type view_type) * * @public @memberof xrt_compositor */ -static inline void +static inline xrt_result_t xrt_comp_end_session(struct xrt_compositor *xc) { - xc->end_session(xc); + return xc->end_session(xc); } /*! @@ -432,12 +434,13 @@ xrt_comp_end_session(struct xrt_compositor *xc) * * @public @memberof xrt_compositor */ -static inline void +static inline xrt_result_t xrt_comp_wait_frame(struct xrt_compositor *xc, uint64_t *predicted_display_time, uint64_t *predicted_display_period) { - xc->wait_frame(xc, predicted_display_time, predicted_display_period); + return xc->wait_frame(xc, predicted_display_time, + predicted_display_period); } /*! @@ -447,10 +450,10 @@ xrt_comp_wait_frame(struct xrt_compositor *xc, * * @public @memberof xrt_compositor */ -static inline void +static inline xrt_result_t xrt_comp_begin_frame(struct xrt_compositor *xc) { - xc->begin_frame(xc); + return xc->begin_frame(xc); } /*! @@ -460,10 +463,10 @@ xrt_comp_begin_frame(struct xrt_compositor *xc) * * @public @memberof xrt_compositor */ -static inline void +static inline xrt_result_t xrt_comp_discard_frame(struct xrt_compositor *xc) { - xc->discard_frame(xc); + return xc->discard_frame(xc); } /*! @@ -473,11 +476,11 @@ xrt_comp_discard_frame(struct xrt_compositor *xc) * * @public @memberof xrt_compositor */ -static inline void +static inline xrt_result_t xrt_comp_layer_begin(struct xrt_compositor *xc, enum xrt_blend_mode env_blend_mode) { - xc->layer_begin(xc, env_blend_mode); + return xc->layer_begin(xc, env_blend_mode); } /*! @@ -487,7 +490,7 @@ xrt_comp_layer_begin(struct xrt_compositor *xc, * * @public @memberof xrt_compositor */ -static inline void +static inline xrt_result_t xrt_comp_layer_stereo_projection(struct xrt_compositor *xc, uint64_t timestamp, struct xrt_device *xdev, @@ -507,10 +510,10 @@ xrt_comp_layer_stereo_projection(struct xrt_compositor *xc, struct xrt_pose *r_pose, bool flip_y) { - xc->layer_stereo_projection(xc, timestamp, xdev, name, layer_flags, - l_sc, l_image_index, l_rect, l_array_index, - l_fov, l_pose, r_sc, r_image_index, r_rect, - r_array_index, r_fov, r_pose, flip_y); + return xc->layer_stereo_projection( + xc, timestamp, xdev, name, layer_flags, l_sc, l_image_index, l_rect, + l_array_index, l_fov, l_pose, r_sc, r_image_index, r_rect, + r_array_index, r_fov, r_pose, flip_y); } /*! @@ -520,7 +523,7 @@ xrt_comp_layer_stereo_projection(struct xrt_compositor *xc, * * @public @memberof xrt_compositor */ -static inline void +static inline xrt_result_t xrt_comp_layer_quad(struct xrt_compositor *xc, uint64_t timestamp, struct xrt_device *xdev, @@ -535,8 +538,9 @@ xrt_comp_layer_quad(struct xrt_compositor *xc, struct xrt_vec2 *size, bool flip_y) { - xc->layer_quad(xc, timestamp, xdev, name, layer_flags, visibility, sc, - image_index, rect, array_index, pose, size, flip_y); + return xc->layer_quad(xc, timestamp, xdev, name, layer_flags, + visibility, sc, image_index, rect, array_index, + pose, size, flip_y); } /*! @@ -546,10 +550,10 @@ xrt_comp_layer_quad(struct xrt_compositor *xc, * * @public @memberof xrt_compositor */ -static inline void +static inline xrt_result_t xrt_comp_layer_commit(struct xrt_compositor *xc) { - xc->layer_commit(xc); + return xc->layer_commit(xc); } /*! diff --git a/src/xrt/include/xrt/xrt_defines.h b/src/xrt/include/xrt/xrt_defines.h index b9e2208d7..7da1d9aeb 100644 --- a/src/xrt/include/xrt/xrt_defines.h +++ b/src/xrt/include/xrt/xrt_defines.h @@ -12,6 +12,8 @@ #include "xrt/xrt_compiler.h" #include "util/u_time.h" +#include "xrt/xrt_results.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/src/xrt/include/xrt/xrt_results.h b/src/xrt/include/xrt/xrt_results.h index 222e23908..f9fc6d17b 100644 --- a/src/xrt/include/xrt/xrt_results.h +++ b/src/xrt/include/xrt/xrt_results.h @@ -13,4 +13,5 @@ typedef enum xrt_result { XRT_SUCCESS = 0, XRT_ERROR_IPC_FAILURE = -1, + XRT_ERROR_NO_IMAGE_AVAILABLE = -2 } xrt_result_t; diff --git a/src/xrt/ipc/ipc_client_compositor.c b/src/xrt/ipc/ipc_client_compositor.c index 81b6753f4..2148737d1 100644 --- a/src/xrt/ipc/ipc_client_compositor.c +++ b/src/xrt/ipc/ipc_client_compositor.c @@ -96,8 +96,9 @@ compositor_disconnect(ipc_connection_t *ipc_c) ipc_c->socket_fd = -1; } -#define CALL_CHK(call) \ - if ((call) != XRT_SUCCESS) { \ +#define IPC_CALL_CHK(call) \ + xrt_result_t res = (call); \ + if (res == XRT_ERROR_IPC_FAILURE) { \ IPC_ERROR(icc->ipc_c, "IPC: %s call error!", __func__); \ } @@ -114,12 +115,12 @@ ipc_compositor_swapchain_destroy(struct xrt_swapchain *xsc) struct ipc_client_swapchain *ics = ipc_client_swapchain(xsc); struct ipc_client_compositor *icc = ics->icc; - CALL_CHK(ipc_call_swapchain_destroy(icc->ipc_c, ics->id)); + IPC_CALL_CHK(ipc_call_swapchain_destroy(icc->ipc_c, ics->id)); free(xsc); } -static bool +static xrt_result_t ipc_compositor_swapchain_wait_image(struct xrt_swapchain *xsc, uint64_t timeout, uint32_t index) @@ -127,35 +128,36 @@ ipc_compositor_swapchain_wait_image(struct xrt_swapchain *xsc, struct ipc_client_swapchain *ics = ipc_client_swapchain(xsc); struct ipc_client_compositor *icc = ics->icc; - CALL_CHK( + IPC_CALL_CHK( ipc_call_swapchain_wait_image(icc->ipc_c, ics->id, timeout, index)); - return true; + return res; } -static bool +static xrt_result_t ipc_compositor_swapchain_acquire_image(struct xrt_swapchain *xsc, uint32_t *out_index) { struct ipc_client_swapchain *ics = ipc_client_swapchain(xsc); struct ipc_client_compositor *icc = ics->icc; - CALL_CHK( + IPC_CALL_CHK( ipc_call_swapchain_acquire_image(icc->ipc_c, ics->id, out_index)); - return true; + return res; } -static bool +static xrt_result_t ipc_compositor_swapchain_release_image(struct xrt_swapchain *xsc, uint32_t index) { struct ipc_client_swapchain *ics = ipc_client_swapchain(xsc); struct ipc_client_compositor *icc = ics->icc; - CALL_CHK(ipc_call_swapchain_release_image(icc->ipc_c, ics->id, index)); + IPC_CALL_CHK( + ipc_call_swapchain_release_image(icc->ipc_c, ics->id, index)); - return true; + return res; } @@ -222,7 +224,7 @@ ipc_compositor_swapchain_create(struct xrt_compositor *xc, return &ics->base.base; } -static void +static xrt_result_t ipc_compositor_begin_session(struct xrt_compositor *xc, enum xrt_view_type view_type) { @@ -230,20 +232,24 @@ ipc_compositor_begin_session(struct xrt_compositor *xc, IPC_SPEW(icc->ipc_c, "IPC: compositor begin session"); - CALL_CHK(ipc_call_session_begin(icc->ipc_c)); + IPC_CALL_CHK(ipc_call_session_begin(icc->ipc_c)); + + return res; } -static void +static xrt_result_t ipc_compositor_end_session(struct xrt_compositor *xc) { struct ipc_client_compositor *icc = ipc_client_compositor(xc); IPC_SPEW(icc->ipc_c, "IPC: compositor end session"); - CALL_CHK(ipc_call_session_end(icc->ipc_c)); + IPC_CALL_CHK(ipc_call_session_end(icc->ipc_c)); + + return res; } -static void +static xrt_result_t ipc_compositor_get_formats(struct xrt_compositor *xc, uint32_t *num_formats, int64_t *formats) @@ -253,19 +259,21 @@ ipc_compositor_get_formats(struct xrt_compositor *xc, IPC_SPEW(icc->ipc_c, "IPC: compositor get_formats"); struct ipc_formats_info info; - CALL_CHK(ipc_call_compositor_get_formats(icc->ipc_c, &info)); + IPC_CALL_CHK(ipc_call_compositor_get_formats(icc->ipc_c, &info)); *num_formats = info.num_formats; memcpy(formats, info.formats, sizeof(int64_t) * (*num_formats)); + + return res; } -static void +static bool wait_semaphore(struct ipc_client_compositor *icc, struct ipc_shared_memory *ism) { struct timespec ts; if (clock_gettime(CLOCK_REALTIME, &ts) == -1) { IPC_ERROR(icc->ipc_c, "Error getting CLOCK_REALTIME\n"); - return; + return false; } int s; @@ -284,18 +292,20 @@ wait_semaphore(struct ipc_client_compositor *icc, struct ipc_shared_memory *ism) } else { IPC_ERROR(icc->ipc_c, "Error sem_timedwait() error '%i'\n", errno); + return false; } } + return true; } -static void +static xrt_result_t ipc_compositor_wait_frame(struct xrt_compositor *xc, uint64_t *out_predicted_display_time, uint64_t *out_predicted_display_period) { struct ipc_client_compositor *icc = ipc_client_compositor(xc); - CALL_CHK(ipc_call_compositor_wait_frame(icc->ipc_c)); + IPC_CALL_CHK(ipc_call_compositor_wait_frame(icc->ipc_c)); wait_semaphore(icc, icc->ipc_c->ism); @@ -303,26 +313,32 @@ ipc_compositor_wait_frame(struct xrt_compositor *xc, icc->ipc_c->ism->wait_frame.predicted_display_time; *out_predicted_display_period = icc->ipc_c->ism->wait_frame.predicted_display_period; + + return res; } -static void +static xrt_result_t ipc_compositor_begin_frame(struct xrt_compositor *xc) { struct ipc_client_compositor *icc = ipc_client_compositor(xc); - CALL_CHK(ipc_call_compositor_begin_frame(icc->ipc_c)); + IPC_CALL_CHK(ipc_call_compositor_begin_frame(icc->ipc_c)); + + return res; } -static void +static xrt_result_t ipc_compositor_layer_begin(struct xrt_compositor *xc, enum xrt_blend_mode env_blend_mode) { struct ipc_client_compositor *icc = ipc_client_compositor(xc); icc->layers.env_blend_mode = env_blend_mode; + + return XRT_SUCCESS; } -static void +static xrt_result_t ipc_compositor_layer_stereo_projection( struct xrt_compositor *xc, uint64_t timestamp, @@ -375,9 +391,11 @@ ipc_compositor_layer_stereo_projection( // Increment the number of layers. icc->layers.num_layers++; + + return XRT_SUCCESS; } -static void +static xrt_result_t ipc_compositor_layer_quad(struct xrt_compositor *xc, uint64_t timestamp, struct xrt_device *xdev, @@ -416,9 +434,11 @@ ipc_compositor_layer_quad(struct xrt_compositor *xc, // Increment the number of layers. icc->layers.num_layers++; + + return XRT_SUCCESS; } -static void +static xrt_result_t ipc_compositor_layer_commit(struct xrt_compositor *xc) { struct ipc_client_compositor *icc = ipc_client_compositor(xc); @@ -429,19 +449,23 @@ ipc_compositor_layer_commit(struct xrt_compositor *xc) // Last bit of data to put in the shared memory area. slot->num_layers = icc->layers.num_layers; - CALL_CHK(ipc_call_compositor_layer_sync(icc->ipc_c, icc->layers.slot_id, - &icc->layers.slot_id)); + IPC_CALL_CHK(ipc_call_compositor_layer_sync( + icc->ipc_c, icc->layers.slot_id, &icc->layers.slot_id)); // Reset. icc->layers.num_layers = 0; + + return res; } -static void +static xrt_result_t ipc_compositor_discard_frame(struct xrt_compositor *xc) { struct ipc_client_compositor *icc = ipc_client_compositor(xc); - CALL_CHK(ipc_call_compositor_discard_frame(icc->ipc_c)); + IPC_CALL_CHK(ipc_call_compositor_discard_frame(icc->ipc_c)); + + return res; } static void diff --git a/src/xrt/state_trackers/oxr/oxr_swapchain.c b/src/xrt/state_trackers/oxr/oxr_swapchain.c index 42d509080..4bbdf0e1a 100644 --- a/src/xrt/state_trackers/oxr/oxr_swapchain.c +++ b/src/xrt/state_trackers/oxr/oxr_swapchain.c @@ -37,7 +37,7 @@ oxr_swapchain_acquire_image(struct oxr_logger *log, } struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; - if (!xsc->acquire_image(xsc, &index)) { + if (xsc->acquire_image(xsc, &index) != XRT_SUCCESS) { return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Call to xsc->acquire_image failed"); } @@ -84,7 +84,7 @@ oxr_swapchain_wait_image(struct oxr_logger *log, u_index_fifo_pop(&sc->acquired.fifo, &index); struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; - if (!xsc->wait_image(xsc, waitInfo->timeout, index)) { + if (xsc->wait_image(xsc, waitInfo->timeout, index) != XRT_SUCCESS) { return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Call to xsc->wait_image failed"); } @@ -111,7 +111,7 @@ oxr_swapchain_release_image(struct oxr_logger *log, uint32_t index = sc->waited.index; struct xrt_swapchain *xsc = (struct xrt_swapchain *)sc->swapchain; - if (!xsc->release_image(xsc, index)) { + if (xsc->release_image(xsc, index) != XRT_SUCCESS) { return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Call to xsc->release_image failed"); }