Add cogl_xlib_renderer_set_threaded_swap_wait_enabled()

Because the threaded-swap-wait functionality requires XInitThreads(),
and because it isn't clear that it is a win for all applications,
add a API function to conditionally enable it.

Fix the cogl-crate example not to just have a hard-coded dependency
on libX11.

https://bugzilla.gnome.org/show_bug.cgi?id=779039
This commit is contained in:
Owen W. Taylor 2016-06-29 13:52:59 -04:00
parent 690b232258
commit d200868459
4 changed files with 43 additions and 0 deletions

View File

@ -69,6 +69,7 @@ struct _CoglRenderer
Display *foreign_xdpy;
CoglBool xlib_enable_event_retrieval;
CoglBool xlib_want_reset_on_video_memory_purge;
CoglBool xlib_enable_threaded_swap_wait;
#endif
CoglDriver driver;

View File

@ -285,6 +285,17 @@ cogl_xlib_renderer_request_reset_on_video_memory_purge (CoglRenderer *renderer,
renderer->xlib_want_reset_on_video_memory_purge = enable;
}
void
cogl_xlib_renderer_set_threaded_swap_wait_enabled (CoglRenderer *renderer,
CoglBool enable)
{
_COGL_RETURN_IF_FAIL (cogl_is_renderer (renderer));
/* NB: Renderers are considered immutable once connected */
_COGL_RETURN_IF_FAIL (!renderer->connected);
renderer->xlib_enable_threaded_swap_wait = enable;
}
#endif /* COGL_HAS_XLIB_SUPPORT */
CoglBool

View File

@ -167,6 +167,36 @@ void
cogl_xlib_renderer_set_event_retrieval_enabled (CoglRenderer *renderer,
CoglBool enable);
/**
* cogl_xlib_renderer_set_threaded_swap_wait_enabled:
* @renderer: a #CoglRenderer
* @enable: The new value
*
* Sets whether Cogl is allowed to use a separate threaded to wait for the
* completion of glXSwapBuffers() and call the frame callback for the
* corresponding #CoglOnscreen. This is a way of emulating the
* INTEL_swap_event extension, and will only ever be used if
* INTEL_swap_event is not present; it will also only be used for
* specific white-listed drivers that are known to work correctly with
* multiple contexts sharing state between threads.
*
* The advantage of enabling this is that it will allow your main loop
* to do other work while waiting for the system to be ready to draw
* the next frame, instead of blocking in glXSwapBuffers(). A disadvantage
* is that the driver will be prevented from buffering up multiple frames
* even if it thinks that it would be advantageous. In general, this
* will work best for something like a system compositor that is doing
* simple drawing but handling lots of other complex tasks.
*
* If you enable this, you must call XInitThreads() before any other
* X11 calls in your program. (See the documentation for XInitThreads())
*
* Stability: unstable
*/
void
cogl_xlib_renderer_set_threaded_swap_wait_enabled (CoglRenderer *renderer,
CoglBool enable);
/**
* cogl_xlib_renderer_get_display: (skip)
*/

View File

@ -901,6 +901,7 @@ update_winsys_features (CoglContext *context, CoglError **error)
{
CoglGpuInfo *info = &context->gpu;
if (glx_display->have_vblank_counter &&
context->display->renderer->xlib_enable_threaded_swap_wait &&
info->vendor == COGL_GPU_INFO_VENDOR_NVIDIA)
{
COGL_FLAGS_SET (context->winsys_features,