[libdazzle] animation: add frame source to public API
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] animation: add frame source to public API
- Date: Fri, 9 Nov 2018 18:37:45 +0000 (UTC)
commit 9e7eb59a1c1dba340553cba52695bae9792b92c9
Author: Christian Hergert <chergert redhat com>
Date: Fri Nov 9 10:37:13 2018 -0800
animation: add frame source to public API
This can be useful in a couple of scenarios, so we will just give access
to it as public API.
src/animation/dzl-frame-source.c | 55 +++++++++++++++++++++++++++++++++++-----
src/animation/dzl-frame-source.h | 15 ++++++++---
src/animation/meson.build | 3 ++-
src/dazzle.h | 1 +
4 files changed, 63 insertions(+), 11 deletions(-)
---
diff --git a/src/animation/dzl-frame-source.c b/src/animation/dzl-frame-source.c
index 7f4a87e..c41ca51 100644
--- a/src/animation/dzl-frame-source.c
+++ b/src/animation/dzl-frame-source.c
@@ -22,6 +22,21 @@
#include "dzl-frame-source.h"
+/**
+ * SECTION:dzl-frame-source
+ * @title: DzlFrameSource
+ * @short_description: a frame source for objects without frame clocks
+ *
+ * If you are working with something that is not a #GtkWidget, getting
+ * access to a frame-clock is sometimes not possible. This can be used
+ * as a suitable fallback that approximates a frame-rate.
+ *
+ * If you have access to a #GdkFrameClock, in most cases you'll want that
+ * instead of using this.
+ *
+ * Since: 3.32
+ */
+
typedef struct
{
GSource parent;
@@ -117,18 +132,44 @@ dzl_frame_source_add (guint frames_per_sec,
guint ret;
g_return_val_if_fail (frames_per_sec > 0, 0);
- g_return_val_if_fail (frames_per_sec <= 120, 0);
- source = g_source_new(&source_funcs, sizeof(DzlFrameSource));
+ source = g_source_new (&source_funcs, sizeof (DzlFrameSource));
+ fsource = (DzlFrameSource *)(gpointer)source;
+ fsource->fps = frames_per_sec;
+ fsource->frame_count = 0;
+ fsource->start_time = g_get_monotonic_time () / 1000L;
+ g_source_set_callback (source, callback, user_data, NULL);
+ g_source_set_name (source, "DzlFrameSource");
+
+ ret = g_source_attach (source, NULL);
+ g_source_unref (source);
+
+ return ret;
+}
+
+guint
+dzl_frame_source_add_full (gint priority,
+ guint frames_per_sec,
+ GSourceFunc callback,
+ gpointer user_data,
+ GDestroyNotify notify)
+{
+ DzlFrameSource *fsource;
+ GSource *source;
+ guint ret;
+
+ g_return_val_if_fail (frames_per_sec > 0, 0);
+
+ source = g_source_new (&source_funcs, sizeof (DzlFrameSource));
fsource = (DzlFrameSource *)(gpointer)source;
fsource->fps = frames_per_sec;
fsource->frame_count = 0;
- fsource->start_time = g_get_monotonic_time() / 1000;
- g_source_set_callback(source, callback, user_data, NULL);
- g_source_set_name(source, "DzlFrameSource");
+ fsource->start_time = g_get_monotonic_time () / 1000L;
+ g_source_set_callback (source, callback, user_data, notify);
+ g_source_set_name (source, "DzlFrameSource");
- ret = g_source_attach(source, NULL);
- g_source_unref(source);
+ ret = g_source_attach (source, NULL);
+ g_source_unref (source);
return ret;
}
diff --git a/src/animation/dzl-frame-source.h b/src/animation/dzl-frame-source.h
index 7dbc4e8..c2a4d89 100644
--- a/src/animation/dzl-frame-source.h
+++ b/src/animation/dzl-frame-source.h
@@ -21,11 +21,20 @@
#include <glib.h>
+#include "dzl-version-macros.h"
+
G_BEGIN_DECLS
-guint dzl_frame_source_add (guint frames_per_sec,
- GSourceFunc callback,
- gpointer user_data);
+DZL_AVAILABLE_IN_3_32
+guint dzl_frame_source_add (guint frames_per_sec,
+ GSourceFunc callback,
+ gpointer user_data);
+DZL_AVAILABLE_IN_3_32
+guint dzl_frame_source_add_full (gint priority,
+ guint frames_per_sec,
+ GSourceFunc callback,
+ gpointer user_data,
+ GDestroyNotify notify);
G_END_DECLS
diff --git a/src/animation/meson.build b/src/animation/meson.build
index 48f045f..aed0623 100644
--- a/src/animation/meson.build
+++ b/src/animation/meson.build
@@ -1,15 +1,16 @@
animation_headers = [
'dzl-animation.h',
'dzl-box-theatric.h',
+ 'dzl-frame-source.h',
]
animation_sources = [
'dzl-animation.c',
'dzl-box-theatric.c',
+ 'dzl-frame-source.c',
]
libdazzle_public_headers += files(animation_headers)
libdazzle_public_sources += files(animation_sources)
-libdazzle_private_sources += files('dzl-frame-source.c')
install_headers(animation_headers, subdir: join_paths(libdazzle_header_subdir, 'animation'))
diff --git a/src/dazzle.h b/src/dazzle.h
index a076507..d70ff8b 100644
--- a/src/dazzle.h
+++ b/src/dazzle.h
@@ -41,6 +41,7 @@ G_BEGIN_DECLS
#include "actions/dzl-widget-action-group.h"
#include "animation/dzl-animation.h"
#include "animation/dzl-box-theatric.h"
+#include "animation/dzl-frame-source.h"
#include "app/dzl-application.h"
#include "app/dzl-application-window.h"
#include "bindings/dzl-binding-group.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]