Re: [waffle] [RFC] waffle: support for swap completion callback
On 4 February 2015 at 06:20, Tapani Pälli tapani.pa...@intel.com wrote: On 02/03/2015 07:32 PM, Emil Velikov wrote: On 2 February 2015 at 13:08, Tapani Pälli tapani.pa...@intel.com wrote: Patch introduces a new API that enables application to register a callback to be called when swapbuffers has finished. This can be used to throttle rendering loop. [...] @@ -173,6 +174,9 @@ bool waffle_is_extension_in_string(const char *extension_string, const char *extension_name); +bool +waffle_register_swap_callback(waffle_swapbuffers_cb func); + Perhaps inlining the typedef in there, and wrapping it in WAFFLE_API_VERSION (alongside the function prototype) ? I put it in separate header so that wcore_platform.h would not need to include whole waffle.h but if that feels ok then typedef can be moved here. Hmm good point. I would leave the final decision to Chad, but imho things will be better if we're compacted. Fwiw changing the func prototype to something like the following will be more consistent, and less likely to abuse. bool waffle_window_register_swap_callback(struct waffle_window *window, waffle_swapbuffers_cb func); This means that callback would be window specific. I think this is ok, although then user needs to register callback for each window separately and window argument could be removed from the actual callback. True, and I don't think it can be seen as a problem. On the topic of the OML triple (ust, msc, sbc), I cannot really comment as I've never had the pleasure. diff --git a/src/waffle/api/waffle_gl_misc.c b/src/waffle/api/waffle_gl_misc.c index 138974d..ac155c0 100644 --- a/src/waffle/api/waffle_gl_misc.c +++ b/src/waffle/api/waffle_gl_misc.c @@ -108,3 +108,20 @@ waffle_get_proc_address(const char *name) return api_platform-vtbl-get_proc_address(api_platform, name); } + +WAFFLE_API bool +waffle_register_swap_callback(waffle_swapbuffers_cb func) +{ +const struct api_object *obj_list[] = { +(void*) func, +}; + +if (!api_check_entry(obj_list, 1)) +return false; + With the struct waffle_window * in you can use it so that one does not abuse the API too much :) I'm now sure what would be the abuse case? Maybe misuse is a better word - iirc api_check_entry confirms that all the objects in obj_list are linked/attached to each other. Although as you brought it up I'm not sure how it works when there is only a single object. -Emil ___ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle
Re: [waffle] [RFC] waffle: support for swap completion callback
On 02/03/2015 07:32 PM, Emil Velikov wrote: On 2 February 2015 at 13:08, Tapani Pälli tapani.pa...@intel.com wrote: Patch introduces a new API that enables application to register a callback to be called when swapbuffers has finished. This can be used to throttle rendering loop. [...] @@ -173,6 +174,9 @@ bool waffle_is_extension_in_string(const char *extension_string, const char *extension_name); +bool +waffle_register_swap_callback(waffle_swapbuffers_cb func); + Perhaps inlining the typedef in there, and wrapping it in WAFFLE_API_VERSION (alongside the function prototype) ? I put it in separate header so that wcore_platform.h would not need to include whole waffle.h but if that feels ok then typedef can be moved here. Fwiw changing the func prototype to something like the following will be more consistent, and less likely to abuse. bool waffle_window_register_swap_callback(struct waffle_window *window, waffle_swapbuffers_cb func); This means that callback would be window specific. I think this is ok, although then user needs to register callback for each window separately and window argument could be removed from the actual callback. On the topic of the OML triple (ust, msc, sbc), I cannot really comment as I've never had the pleasure. diff --git a/src/waffle/api/waffle_gl_misc.c b/src/waffle/api/waffle_gl_misc.c index 138974d..ac155c0 100644 --- a/src/waffle/api/waffle_gl_misc.c +++ b/src/waffle/api/waffle_gl_misc.c @@ -108,3 +108,20 @@ waffle_get_proc_address(const char *name) return api_platform-vtbl-get_proc_address(api_platform, name); } + +WAFFLE_API bool +waffle_register_swap_callback(waffle_swapbuffers_cb func) +{ +const struct api_object *obj_list[] = { +(void*) func, +}; + +if (!api_check_entry(obj_list, 1)) +return false; + With the struct waffle_window * in you can use it so that one does not abuse the API too much :) I'm now sure what would be the abuse case? +if (api_platform-vtbl-register_swap_callback) +return api_platform-vtbl-register_swap_callback(api_platform, func); + +wcore_error(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM); I'm not sure if we should error in here, considering that one of all platforms is likely to have a callback func. Cheers, Emil ___ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle ___ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle
Re: [waffle] [RFC] waffle: support for swap completion callback
On 2 February 2015 at 13:08, Tapani Pälli tapani.pa...@intel.com wrote: Patch introduces a new API that enables application to register a callback to be called when swapbuffers has finished. This can be used to throttle rendering loop. [...] @@ -173,6 +174,9 @@ bool waffle_is_extension_in_string(const char *extension_string, const char *extension_name); +bool +waffle_register_swap_callback(waffle_swapbuffers_cb func); + Perhaps inlining the typedef in there, and wrapping it in WAFFLE_API_VERSION (alongside the function prototype) ? Fwiw changing the func prototype to something like the following will be more consistent, and less likely to abuse. bool waffle_window_register_swap_callback(struct waffle_window *window, waffle_swapbuffers_cb func); On the topic of the OML triple (ust, msc, sbc), I cannot really comment as I've never had the pleasure. diff --git a/src/waffle/api/waffle_gl_misc.c b/src/waffle/api/waffle_gl_misc.c index 138974d..ac155c0 100644 --- a/src/waffle/api/waffle_gl_misc.c +++ b/src/waffle/api/waffle_gl_misc.c @@ -108,3 +108,20 @@ waffle_get_proc_address(const char *name) return api_platform-vtbl-get_proc_address(api_platform, name); } + +WAFFLE_API bool +waffle_register_swap_callback(waffle_swapbuffers_cb func) +{ +const struct api_object *obj_list[] = { +(void*) func, +}; + +if (!api_check_entry(obj_list, 1)) +return false; + With the struct waffle_window * in you can use it so that one does not abuse the API too much :) +if (api_platform-vtbl-register_swap_callback) +return api_platform-vtbl-register_swap_callback(api_platform, func); + +wcore_error(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM); I'm not sure if we should error in here, considering that one of all platforms is likely to have a callback func. Cheers, Emil ___ waffle mailing list waffle@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/waffle
[waffle] [RFC] waffle: support for swap completion callback
Patch introduces a new API that enables application to register a callback to be called when swapbuffers has finished. This can be used to throttle rendering loop. Signed-off-by: Tapani Pälli tapani.pa...@intel.com --- (This is a API proposal for swap event callback.) include/CMakeLists.txt | 1 + include/waffle/waffle.h | 4 include/waffle/waffle_typedefs.h | 38 ++ src/waffle/api/waffle_gl_misc.c | 17 + src/waffle/core/wcore_platform.h | 9 + src/waffle/waffle.def.in | 3 ++- 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 include/waffle/waffle_typedefs.h diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index e190a76..ba84e95 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -7,6 +7,7 @@ install( waffle/waffle.h waffle/waffle_gbm.h waffle/waffle_glx.h +waffle/waffle_typedefs.h waffle/waffle_version.h waffle/waffle_wayland.h waffle/waffle_x11_egl.h diff --git a/include/waffle/waffle.h b/include/waffle/waffle.h index 77885a4..e421375 100644 --- a/include/waffle/waffle.h +++ b/include/waffle/waffle.h @@ -31,6 +31,7 @@ #include stdlib.h #include waffle_version.h +#include waffle_typedefs.h #ifdef __cplusplus extern C { @@ -173,6 +174,9 @@ bool waffle_is_extension_in_string(const char *extension_string, const char *extension_name); +bool +waffle_register_swap_callback(waffle_swapbuffers_cb func); + // --- // waffle_display // --- diff --git a/include/waffle/waffle_typedefs.h b/include/waffle/waffle_typedefs.h new file mode 100644 index 000..6532de4 --- /dev/null +++ b/include/waffle/waffle_typedefs.h @@ -0,0 +1,38 @@ +// Copyright 2015 Intel Corporation +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// - Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#pragma once + +#ifdef __cplusplus +extern C { +#endif + +struct waffle_window; + +typedef void (*waffle_swapbuffers_cb) (const struct waffle_window *window); + +#ifdef __cplusplus +} // end extern C +#endif diff --git a/src/waffle/api/waffle_gl_misc.c b/src/waffle/api/waffle_gl_misc.c index 138974d..ac155c0 100644 --- a/src/waffle/api/waffle_gl_misc.c +++ b/src/waffle/api/waffle_gl_misc.c @@ -108,3 +108,20 @@ waffle_get_proc_address(const char *name) return api_platform-vtbl-get_proc_address(api_platform, name); } + +WAFFLE_API bool +waffle_register_swap_callback(waffle_swapbuffers_cb func) +{ +const struct api_object *obj_list[] = { +(void*) func, +}; + +if (!api_check_entry(obj_list, 1)) +return false; + +if (api_platform-vtbl-register_swap_callback) +return api_platform-vtbl-register_swap_callback(api_platform, func); + +wcore_error(WAFFLE_ERROR_UNSUPPORTED_ON_PLATFORM); +return NULL; +} diff --git a/src/waffle/core/wcore_platform.h b/src/waffle/core/wcore_platform.h index 77943e4..5f53ab8 100644 --- a/src/waffle/core/wcore_platform.h +++ b/src/waffle/core/wcore_platform.h @@ -30,6 +30,8 @@ #include stdint.h #include c99_compat.h +#include waffle_typedefs.h + struct wcore_config; struct wcore_config_attrs; struct wcore_context; @@ -64,6 +66,12 @@ struct wcore_platform_vtbl { int32_t waffle_dl, const char *symbol); +/// May be null. +bool +(*register_swap_callback)( +struct wcore_platform *self, +waffle_swapbuffers_cb callback); + struct wcore_display_vtbl { struct wcore_display*