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 0000000..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*
         (*connect)(struct wcore_platform *platform,
@@ -134,6 +142,7 @@ struct wcore_platform_vtbl {
         union waffle_native_window*
         (*get_native)(struct wcore_window *window);
     } window;
+
 };
 
 struct wcore_platform {
diff --git a/src/waffle/waffle.def.in b/src/waffle/waffle.def.in
index db8464f..0b3de66 100644
--- a/src/waffle/waffle.def.in
+++ b/src/waffle/waffle.def.in
@@ -30,4 +30,5 @@ EXPORTS
     waffle_attrib_list_length
     waffle_attrib_list_get
     waffle_attrib_list_get_with_default
-    waffle_attrib_list_update
\ No newline at end of file
+    waffle_attrib_list_update
+    waffle_register_swap_callback
-- 
2.1.0

_______________________________________________
waffle mailing list
waffle@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/waffle

Reply via email to