Release Clutter 1.11.4 (snapshot)
[profile/ivi/clutter.git] / clutter / clutter-private.h
1 /*
2  * Clutter.
3  *
4  * An OpenGL based 'interactive canvas' library.
5  *
6  * Authored By Matthew Allum  <mallum@openedhand.com>
7  *
8  * Copyright (C) 2006 OpenedHand
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
22  *
23  *
24  */
25
26 #ifndef __CLUTTER_PRIVATE_H__
27 #define __CLUTTER_PRIVATE_H__
28
29 #include <glib.h>
30
31 #include <glib/gi18n-lib.h>
32
33 #include <cogl-pango/cogl-pango.h>
34
35 #include "clutter-backend.h"
36 #include "clutter-effect.h"
37 #include "clutter-event.h"
38 #include "clutter-feature.h"
39 #include "clutter-id-pool.h"
40 #include "clutter-layout-manager.h"
41 #include "clutter-master-clock.h"
42 #include "clutter-settings.h"
43 #include "clutter-stage-manager.h"
44 #include "clutter-stage.h"
45
46 G_BEGIN_DECLS
47
48 typedef struct _ClutterMainContext      ClutterMainContext;
49
50 #define CLUTTER_REGISTER_VALUE_TRANSFORM_TO(TYPE_TO,func)             { \
51   g_value_register_transform_func (g_define_type_id, TYPE_TO, func);    \
52 }
53
54 #define CLUTTER_REGISTER_VALUE_TRANSFORM_FROM(TYPE_FROM,func)         { \
55   g_value_register_transform_func (TYPE_FROM, g_define_type_id, func);  \
56 }
57
58 #define CLUTTER_REGISTER_INTERVAL_PROGRESS(func)                      { \
59   clutter_interval_register_progress_func (g_define_type_id, func);     \
60 }
61
62 #define CLUTTER_PRIVATE_FLAGS(a)         (((ClutterActor *) (a))->private_flags)
63 #define CLUTTER_SET_PRIVATE_FLAGS(a,f)   (CLUTTER_PRIVATE_FLAGS (a) |= (f))
64 #define CLUTTER_UNSET_PRIVATE_FLAGS(a,f) (CLUTTER_PRIVATE_FLAGS (a) &= ~(f))
65
66 #define CLUTTER_ACTOR_IS_TOPLEVEL(a)            ((CLUTTER_PRIVATE_FLAGS (a) & CLUTTER_IS_TOPLEVEL) != FALSE)
67 #define CLUTTER_ACTOR_IS_INTERNAL_CHILD(a)      ((CLUTTER_PRIVATE_FLAGS (a) & CLUTTER_INTERNAL_CHILD) != FALSE)
68 #define CLUTTER_ACTOR_IN_DESTRUCTION(a)         ((CLUTTER_PRIVATE_FLAGS (a) & CLUTTER_IN_DESTRUCTION) != FALSE)
69 #define CLUTTER_ACTOR_IN_REPARENT(a)            ((CLUTTER_PRIVATE_FLAGS (a) & CLUTTER_IN_REPARENT) != FALSE)
70 #define CLUTTER_ACTOR_IN_PAINT(a)               ((CLUTTER_PRIVATE_FLAGS (a) & CLUTTER_IN_PAINT) != FALSE)
71 #define CLUTTER_ACTOR_IN_RELAYOUT(a)            ((CLUTTER_PRIVATE_FLAGS (a) & CLUTTER_IN_RELAYOUT) != FALSE)
72 #define CLUTTER_STAGE_IN_RESIZE(a)              ((CLUTTER_PRIVATE_FLAGS (a) & CLUTTER_IN_RESIZE) != FALSE)
73
74 #define CLUTTER_PARAM_READABLE  (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)
75 #define CLUTTER_PARAM_WRITABLE  (G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS)
76 #define CLUTTER_PARAM_READWRITE (G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS)
77
78 #define CLUTTER_PARAM_ANIMATABLE        (1 << G_PARAM_USER_SHIFT)
79
80 /* automagic interning of a static string */
81 #define I_(str)  (g_intern_static_string ((str)))
82
83 /* mark all properties under the "Property" context */
84 #ifdef ENABLE_NLS
85 #define P_(String) (_clutter_gettext ((String)))
86 #else
87 #define P_(String) (String)
88 #endif
89
90 /* This is a replacement for the nearbyint function which always rounds to the
91  * nearest integer. nearbyint is apparently a C99 function so it might not
92  * always be available but also it seems in glibc it is defined as a function
93  * call so this macro could end up faster anyway. We can't just add 0.5f
94  * because it will break for negative numbers. */
95 #define CLUTTER_NEARBYINT(x) ((int) ((x) < 0.0f ? (x) - 0.5f : (x) + 0.5f))
96
97 typedef enum {
98   CLUTTER_ACTOR_UNUSED_FLAG = 0,
99
100   CLUTTER_IN_DESTRUCTION = 1 << 0,
101   CLUTTER_IS_TOPLEVEL    = 1 << 1,
102   CLUTTER_IN_REPARENT    = 1 << 2,
103
104   /* Used to avoid recursion */
105   CLUTTER_IN_PAINT       = 1 << 3,
106
107   /* Used to avoid recursion */
108   CLUTTER_IN_RELAYOUT    = 1 << 4,
109
110   /* Used by the stage if resizing is an asynchronous operation (like on
111    * X11) to delay queueing relayouts until we got a notification from the
112    * event handling
113    */
114   CLUTTER_IN_RESIZE      = 1 << 5,
115
116   /* a flag for internal children of Containers */
117   CLUTTER_INTERNAL_CHILD = 1 << 6
118 } ClutterPrivateFlags;
119
120 /*
121  * ClutterMainContext:
122  *
123  * The shared state of Clutter
124  */
125 struct _ClutterMainContext
126 {
127   /* the main windowing system backend */
128   ClutterBackend *backend;
129
130   /* the object holding all the stage instances */
131   ClutterStageManager *stage_manager;
132
133   /* the clock driving all the frame operations */
134   ClutterMasterClock *master_clock;
135
136   /* the main event queue */
137   GQueue *events_queue;
138
139   ClutterPickMode  pick_mode;
140
141   /* mapping between reused integer ids and actors */
142   ClutterIDPool *id_pool;
143
144   /* default FPS; this is only used if we cannot sync to vblank */
145   guint frame_rate;
146
147   /* actors with a grab on all devices */
148   ClutterActor *pointer_grab_actor;
149   ClutterActor *keyboard_grab_actor;
150
151   /* stack of actors with shaders during paint */
152   GSList *shaders;
153
154   /* fb bit masks for col<->id mapping in picking */
155   gint fb_r_mask;
156   gint fb_g_mask;
157   gint fb_b_mask;
158   gint fb_r_mask_used;
159   gint fb_g_mask_used;
160   gint fb_b_mask_used;
161
162   PangoContext *pango_context;  /* Global Pango context */
163   CoglPangoFontMap *font_map;   /* Global font map */
164
165   ClutterEvent *current_event;
166   guint32 last_event_time;
167
168   /* list of repaint functions installed through
169    * clutter_threads_add_repaint_func()
170    */
171   GList *repaint_funcs;
172   guint last_repaint_id;
173
174   /* main settings singleton */
175   ClutterSettings *settings;
176
177   /* boolean flags */
178   guint is_initialized          : 1;
179   guint motion_events_per_actor : 1;
180   guint defer_display_setup     : 1;
181   guint options_parsed          : 1;
182   guint show_fps                : 1;
183 };
184
185 /* shared between clutter-main.c and clutter-frame-source.c */
186 typedef struct
187 {
188   GSourceFunc func;
189   gpointer data;
190   GDestroyNotify notify;
191 } ClutterThreadsDispatch;
192
193 gboolean _clutter_threads_dispatch      (gpointer data);
194 void     _clutter_threads_dispatch_free (gpointer data);
195
196 ClutterMainContext *    _clutter_context_get_default                    (void);
197 void                    _clutter_context_lock                           (void);
198 void                    _clutter_context_unlock                         (void);
199 gboolean                _clutter_context_is_initialized                 (void);
200 PangoContext *          _clutter_context_create_pango_context           (void);
201 PangoContext *          _clutter_context_get_pango_context              (void);
202 ClutterPickMode         _clutter_context_get_pick_mode                  (void);
203 void                    _clutter_context_push_shader_stack              (ClutterActor *actor);
204 ClutterActor *          _clutter_context_pop_shader_stack               (ClutterActor *actor);
205 ClutterActor *          _clutter_context_peek_shader_stack              (void);
206 guint32                 _clutter_context_acquire_id                     (gpointer      key);
207 void                    _clutter_context_release_id                     (guint32       id_);
208 gboolean                _clutter_context_get_motion_events_enabled      (void);
209 gboolean                _clutter_context_get_show_fps                   (void);
210
211 const gchar *_clutter_gettext (const gchar *str);
212
213 gboolean      _clutter_feature_init (GError **error);
214
215 /* Diagnostic mode */
216 gboolean        _clutter_diagnostic_enabled     (void);
217 void            _clutter_diagnostic_message     (const char *fmt, ...);
218
219 /* Picking code */
220 guint           _clutter_pixel_to_id            (guchar        pixel[4]);
221 void            _clutter_id_to_color            (guint         id,
222                                                  ClutterColor *col);
223 ClutterActor *  _clutter_get_actor_by_id        (ClutterStage *stage,
224                                                  guint32       actor_id);
225
226 gboolean        _clutter_get_sync_to_vblank     (void);
227
228 /* use this function as the accumulator if you have a signal with
229  * a G_TYPE_BOOLEAN return value; this will stop the emission as
230  * soon as one handler returns TRUE
231  */
232 gboolean _clutter_boolean_handled_accumulator (GSignalInvocationHint *ihint,
233                                                GValue                *return_accu,
234                                                const GValue          *handler_return,
235                                                gpointer               dummy);
236
237 void _clutter_run_repaint_functions (ClutterRepaintFlags flags);
238
239 void _clutter_constraint_update_allocation (ClutterConstraint *constraint,
240                                             ClutterActor      *actor,
241                                             ClutterActorBox   *allocation);
242
243 GType _clutter_layout_manager_get_child_meta_type (ClutterLayoutManager *manager);
244
245 void  _clutter_util_fully_transform_vertices (const CoglMatrix    *modelview,
246                                               const CoglMatrix    *projection,
247                                               const float         *viewport,
248                                               const ClutterVertex *vertices_in,
249                                               ClutterVertex       *vertices_out,
250                                               int                  n_vertices);
251
252 void _clutter_util_rectangle_union (const cairo_rectangle_int_t *src1,
253                                     const cairo_rectangle_int_t *src2,
254                                     cairo_rectangle_int_t       *dest);
255
256 typedef struct _ClutterPlane
257 {
258   float v0[3];
259   float n[3];
260 } ClutterPlane;
261
262 typedef enum _ClutterCullResult
263 {
264   CLUTTER_CULL_RESULT_UNKNOWN,
265   CLUTTER_CULL_RESULT_IN,
266   CLUTTER_CULL_RESULT_OUT,
267   CLUTTER_CULL_RESULT_PARTIAL
268 } ClutterCullResult;
269
270 gboolean        _clutter_has_progress_function  (GType gtype);
271 gboolean        _clutter_run_progress_function  (GType gtype,
272                                                  const GValue *initial,
273                                                  const GValue *final,
274                                                  gdouble progress,
275                                                  GValue *retval);
276
277 G_END_DECLS
278
279 #endif /* __CLUTTER_PRIVATE_H__ */