···11-// Copyright 2019, Collabora, Ltd.
11+// Copyright 2019-2022, Collabora, Ltd.
22// SPDX-License-Identifier: BSL-1.0
33/*!
44 * @file
···5353};
54545555/*!
5656- * Fetches the OpenGL context that is current on this thread and makes the OpenGL context given in the graphics binding
5757- * current instead. Only one thread at a time can operate on the sections between @ref client_gl_context_begin_func_t
5858- * and
5959- * @ref client_gl_context_end_func_t, therefore client_gl_context_end_func_t MUST be called to avoid blocking the next
6060- * thread calling @ref client_gl_context_begin_func_t.
5656+ * Fetches the OpenGL context that is current on this thread and makes the
5757+ * OpenGL context given in the graphics binding current instead. Only one thread
5858+ * at a time can operate on the sections between
5959+ * @ref client_gl_context_begin_locked_func_t and
6060+ * @ref client_gl_context_end_locked_func_t,
6161+ * therefore @ref client_gl_context_end_locked_func_t MUST be called to avoid
6262+ * blocking the next thread calling @ref client_gl_context_begin_locked_func_t.
6163 *
6262- * If the return value is not XRT_SUCCESS, @ref client_gl_context_end_func_t should not be called.
6464+ * This function must be called with the context_mutex locked held, that is
6565+ * handled by the helper function @ref client_gl_compositor_context_begin.
6666+ *
6767+ * If the return value is not XRT_SUCCESS,
6868+ * @ref client_gl_context_end_locked_func_t should not be called.
6369 */
6464-typedef xrt_result_t (*client_gl_context_begin_func_t)(struct xrt_compositor *xc);
7070+typedef xrt_result_t (*client_gl_context_begin_locked_func_t)(struct xrt_compositor *xc);
65716672/*!
6767- * Makes the OpenGL context current that was current before @ref client_gl_context_begin_func_t was called.
7373+ * Makes the OpenGL context current that was current before
7474+ * @ref client_gl_context_begin_locked_func_t was called.
7575+ *
7676+ * This function must be called with the context_mutex locked held, successful
7777+ * call to @ref client_gl_compositor_context_begin will ensure that. The lock is
7878+ * not released by this function, but @ref client_gl_compositor_context_end does
7979+ * release it.
6880 */
6969-typedef void (*client_gl_context_end_func_t)(struct xrt_compositor *xc);
8181+typedef void (*client_gl_context_end_locked_func_t)(struct xrt_compositor *xc);
70827183/*!
7284 * The type of a swapchain create constructor.
···113125 /*!
114126 * Function pointer for making the OpenGL context current.
115127 */
116116- client_gl_context_begin_func_t context_begin;
128128+ client_gl_context_begin_locked_func_t context_begin_locked;
117129118130 /*!
119131 * Function pointer for restoring prior OpenGL context.
120132 */
121121- client_gl_context_end_func_t context_end;
133133+ client_gl_context_end_locked_func_t context_end_locked;
122134123135 /*!
124136 * Function pointer for creating the client swapchain.
···172184bool
173185client_gl_compositor_init(struct client_gl_compositor *c,
174186 struct xrt_compositor_native *xcn,
175175- client_gl_context_begin_func_t context_begin,
176176- client_gl_context_end_func_t context_end,
187187+ client_gl_context_begin_locked_func_t context_begin,
188188+ client_gl_context_end_locked_func_t context_end,
177189 client_gl_swapchain_create_func_t create_swapchain,
178190 client_gl_insert_fence_func_t insert_fence);
179191···186198 */
187199void
188200client_gl_compositor_close(struct client_gl_compositor *c);
201201+202202+/*!
203203+ * @copydoc client_gl_context_begin_locked_func_t
204204+ *
205205+ * Helper for calling through the function pointer.
206206+ *
207207+ * @public @memberof client_gl_compositor
208208+ */
209209+static inline xrt_result_t
210210+client_gl_compositor_context_begin(struct xrt_compositor *xc)
211211+{
212212+ struct client_gl_compositor *cgc = client_gl_compositor(xc);
213213+214214+ os_mutex_lock(&cgc->context_mutex);
215215+216216+ xrt_result_t xret = cgc->context_begin_locked(xc);
217217+ if (xret != XRT_SUCCESS) {
218218+ os_mutex_unlock(&cgc->context_mutex);
219219+ }
220220+221221+ return xret;
222222+}
223223+224224+/*!
225225+ * @copydoc client_gl_context_end_locked_func_t
226226+ *
227227+ * Helper for calling through the function pointer.
228228+ *
229229+ * @public @memberof client_gl_compositor
230230+ */
231231+static inline void
232232+client_gl_compositor_context_end(struct xrt_compositor *xc)
233233+{
234234+ struct client_gl_compositor *cgc = client_gl_compositor(xc);
235235+236236+ cgc->context_end_locked(xc);
237237+238238+ os_mutex_unlock(&cgc->context_mutex);
239239+}
189240190241191242#ifdef __cplusplus