OSDN Git Service

stop using trunk directory in rectool
[rec10/rec10-git.git] / tstools / DtsEdit / src / gpac / internal / scenegraph_dev.h
1 /*\r
2  *                      GPAC - Multimedia Framework C SDK\r
3  *\r
4  *                      Copyright (c) Jean Le Feuvre 2000-2005\r
5  *                                      All rights reserved\r
6  *\r
7  *  This file is part of GPAC / Scene Graph sub-project\r
8  *\r
9  *  GPAC is free software; you can redistribute it and/or modify\r
10  *  it under the terms of the GNU Lesser General Public License as published by\r
11  *  the Free Software Foundation; either version 2, or (at your option)\r
12  *  any later version.\r
13  *   \r
14  *  GPAC is distributed in the hope that it will be useful,\r
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  *  GNU Lesser General Public License for more details.\r
18  *   \r
19  *  You should have received a copy of the GNU Lesser General Public\r
20  *  License along with this library; see the file COPYING.  If not, write to\r
21  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. \r
22  *\r
23  */\r
24 \r
25 \r
26 \r
27 #ifndef _GF_SCENEGRAPH_DEV_H_\r
28 #define _GF_SCENEGRAPH_DEV_H_\r
29 \r
30 /*defined this macro to enable cyclic render*/\r
31 #define GF_CYCLIC_TRAVERSE_ON\r
32 \r
33 /*defined this macro to enable scene replacement from inside (through conditional)*/\r
34 //#define GF_SELF_REPLACE_ENABLE\r
35 \r
36 /*for vrml base types, ROUTEs and PROTOs*/\r
37 #include <gpac/scenegraph_vrml.h>\r
38 \r
39 #include <gpac/scenegraph_svg.h>\r
40 \r
41 #ifdef GPAC_HAS_SPIDERMONKEY\r
42 \r
43 /*WIN32 and WinCE config (no configure script)*/\r
44 #if defined(WIN32) || defined(_WIN32_WCE) || defined(__SYMBIAN32__)\r
45 #ifndef XP_PC\r
46 #define XP_PC\r
47 #endif\r
48 #ifndef XP_WIN\r
49 #define XP_WIN\r
50 #endif\r
51 /*WINCE specific config*/\r
52 #if defined(_WIN32_WCE)\r
53 #include <windows.h>\r
54 #define XP_WINCE\r
55 #endif\r
56 #endif\r
57 \r
58 /*other platforms should be setup through configure*/\r
59 \r
60 #endif\r
61 \r
62 \r
63 void gf_node_setup(GF_Node *p, u32 tag);\r
64 \r
65 typedef struct _parent_list\r
66 {\r
67         struct _parent_list *next;\r
68         GF_Node *node;\r
69 } GF_ParentList;\r
70 \r
71 \r
72 /*internal flag reserved for NodeID*/\r
73 #define GF_NODE_IS_DEF                  0x80000000      // 1<<31\r
74 /*internal flag reserved for activate/deactivate*/\r
75 #define GF_NODE_IS_DEACTIVATED  0x40000000      // 1<<30\r
76 /*internal flag reserved for node with scripting bindings*/\r
77 #define GF_NODE_HAS_BINDING             0x20000000      // 1<<29\r
78 \r
79 #ifdef GF_CYCLIC_TRAVERSE_ON\r
80 #define GF_NODE_IN_TRAVERSE             0x10000000      //      1<<28\r
81 #define GF_NODE_INTERNAL_FLAGS  0xF0000000\r
82 #else\r
83 #define GF_NODE_INTERNAL_FLAGS  0xE0000000\r
84 #endif\r
85 \r
86 struct _node_interactive_ext\r
87 {\r
88         /*routes on eventOut, ISed routes, ... for VRML-based scene graphs\r
89         THIS IS DYNAMICALLY CREATED*/\r
90         GF_List *routes;\r
91 \r
92 #ifdef GPAC_HAS_SPIDERMONKEY\r
93         /*JS bindings if any - THIS IS DYNAMICALLY CREATED\r
94         This speeds up field modif notification (script bindings are listed here)*/\r
95         GF_List *bindings;\r
96 #endif\r
97 \r
98 #ifndef GPAC_DISABLE_SVG\r
99         /*event listeners - THIS IS DYNAMICALLY CREATED*/\r
100         GF_DOMEventTarget *dom_evt;\r
101 \r
102         /* SVG animations are registered in the target node  - THIS IS DYNAMICALLY CREATED*/\r
103         GF_List *animations;\r
104 #endif\r
105 \r
106 };\r
107 \r
108 typedef struct _nodepriv\r
109 {\r
110         /*node type*/\r
111         u16 tag;\r
112         /*number of instances of this node in the graph*/\r
113         u16 num_instances;\r
114         /*node flags*/\r
115         u32 flags;\r
116         /*scenegraph holding the node*/\r
117         struct __tag_scene_graph *scenegraph;\r
118 \r
119         /*user defined callback function */\r
120         void (*UserCallback)(struct _base_node *node, void *render_stack, Bool node_destroy);\r
121         /*user defined stack*/\r
122         void *UserPrivate;\r
123 \r
124         /*list of all parent nodes (needed to invalidate parent tree)*/\r
125         GF_ParentList *parents;\r
126         \r
127         /*holder for all interactive stuff - THIS IS DYNAMICALLY CREATED*/\r
128         struct _node_interactive_ext *interact;\r
129 } NodePriv;\r
130 \r
131 \r
132 typedef struct __tag_node_id\r
133 {\r
134         struct __tag_node_id *next;\r
135         GF_Node *node;\r
136 \r
137         /*node ID*/\r
138         u32 NodeID;\r
139         /*node def name*/\r
140         char *NodeName;\r
141 } NodeIDedItem;\r
142 \r
143 typedef struct\r
144 {\r
145         char *name;\r
146         char *qname;\r
147         u32 xmlns_id;\r
148 } GF_XMLNS;\r
149 \r
150 struct __tag_scene_graph \r
151 {\r
152         /*used to discriminate between node and scenegraph*/\r
153         u64 __reserved_null;\r
154 \r
155         /*all DEF nodes (explicit)*/\r
156         NodeIDedItem *id_node, *id_node_last;\r
157 \r
158         /*all routes available*/\r
159         GF_List *Routes;\r
160 \r
161         /*all routes available*/\r
162         GF_List *exported_nodes;\r
163 \r
164         /*when a proto is instanciated it creates its own scene graph. BIFS/VRML specify that the namespace is the same \r
165         (eg cannot reuse a NodeID or route name/ID), but this could be done differently by some other stds\r
166         if NULL this is the main scenegraph*/\r
167         struct _proto_instance *pOwningProto;\r
168 \r
169         /*all first-level protos of the graph (the only ones that can be instanciated in this graph)*/\r
170         GF_List *protos;\r
171         /*all first-level protos of the graph not currently registered - memory handling of graph only*/\r
172         GF_List *unregistered_protos;\r
173 \r
174         /*pointer to the root node*/\r
175         GF_Node *RootNode;\r
176 \r
177         /*routes to be activated (cascade model). This is used at the top-level graph only (eg\r
178         proto routes use that too, ecept ISed fields). It is the app responsability to \r
179         correctly connect or browse scene graphs connected through Inline*/\r
180         GF_List *routes_to_activate;\r
181 \r
182         /*since events may trigger deletion of objects we use a 2 step delete*/\r
183         GF_List *routes_to_destroy;\r
184 \r
185         u32 simulation_tick;\r
186 \r
187         /*user private data*/\r
188         void *userpriv;\r
189 \r
190         /*callback routines*/\r
191         /*node callback*/\r
192         void (*NodeCallback)(void *user_priv, u32 type, GF_Node *node, void *ctxdata);\r
193         /*real scene time callback*/\r
194         Double (*GetSceneTime)(void *userpriv);\r
195 \r
196         GF_SceneGraph *(*GetExternProtoLib)(void *userpriv, MFURL *lib_url);\r
197 \r
198         /*parent scene if any*/\r
199         struct __tag_scene_graph *parent_scene;\r
200 \r
201         /*size info and pixel metrics - this is not used internally, however it helps when rendering\r
202         and decoding modules don't know each-other (as in MPEG4)*/\r
203         u32 width, height;\r
204         Bool usePixelMetrics;\r
205 \r
206         Bool modified;\r
207 \r
208         /*application interface for javascript*/\r
209         gf_sg_script_action script_action;\r
210         void *script_action_cbck;\r
211 \r
212         /*script loader*/\r
213         void (*script_load)(GF_Node *node);\r
214         /*callback to JS upon node modif*/\r
215         void (*on_node_modified)(struct __tag_scene_graph *sg, GF_Node *node, GF_FieldInfo *info, GF_Node *script);\r
216 \r
217         u32 max_defined_route_id;\r
218 \r
219         /*namespaces list. This list is used while parsing/dumping the tree to store the hierarchy of xmlns attributes in subtrees.\r
220         It is a stack of GF_XMLNS structures pushed/popped at each element*/\r
221         GF_List *ns;\r
222 \r
223 #ifdef GF_SELF_REPLACE_ENABLE\r
224         /*to detect replace scene from within conditionals*/\r
225         Bool graph_has_been_reset;\r
226 #endif\r
227         /*global qp used in BIFS coding*/\r
228         GF_Node *global_qp;\r
229 \r
230         /*use stack as used in the dom_fire_event - this is only valid during an event fire, and may be NULL*/\r
231         GF_List *use_stack;\r
232 \r
233         /*temp storage for name conversions*/\r
234         char szNameBuffer[100];\r
235 \r
236 #ifndef GPAC_DISABLE_SVG\r
237         GF_DOMEventTarget dom_evt;\r
238         u32 nb_evts_focus;\r
239         u32 nb_evts_mouse;\r
240         u32 nb_evts_key;\r
241         u32 nb_evts_ui;\r
242         u32 nb_evts_text;\r
243         u32 nb_evts_smil;\r
244         u32 nb_evts_mutation;\r
245         u32 nb_evts_laser;\r
246         u32 nb_evts_mae;\r
247         u32 nb_evts_svg;\r
248         u32 dom_evt_filter;\r
249 \r
250         GF_List *xlink_hrefs;\r
251         GF_List *smil_timed_elements;\r
252         GF_List *modified_smil_timed_elements;\r
253         Bool update_smil_timing;\r
254 \r
255         /*listeners to add*/\r
256         GF_List *listeners_to_add;\r
257 \r
258 #ifdef GPAC_HAS_SPIDERMONKEY\r
259         struct __tag_svg_script_ctx *svg_js;\r
260 #endif\r
261 \r
262 #endif\r
263 \r
264 #ifdef GPAC_HAS_SPIDERMONKEY\r
265         GF_List *scripts;\r
266         /*\r
267                         Note about reference counter\r
268 \r
269           A DOM document (<=> scenegraph) may be created through javascript, and the JS object having created the \r
270           document may be destroyed while the document is still in use. Moreover with XMLHttpRequest, the\r
271           "associated" doc is re-created at each request, but the script may still refer to the original document.\r
272           Since the document doesn't have a fixed owner, a reference counter is use and the scenegraph is kept alive \r
273           until the last object using it is destroyed.\r
274 \r
275         If this counter is set to 0 when creating DOM Elements/..., this means the scenegraph is hold by an external\r
276         entity (typically the player), and cannot be destroyed from the scripting engine\r
277         */\r
278         u32 reference_count;\r
279         /*DOM nodes*/\r
280         GF_List *objects;\r
281         /*DOM document*/\r
282         struct JSObject *document;\r
283 \r
284         Bool dcci_doc;\r
285 #endif\r
286 };\r
287 \r
288 void gf_sg_parent_setup(GF_Node *pNode);\r
289 void gf_sg_parent_reset(GF_Node *pNode);\r
290 \r
291 void *gf_node_get_name_address(GF_Node*node);\r
292 \r
293 void gf_node_changed_internal(GF_Node *node, GF_FieldInfo *field, Bool notify_scripts);\r
294 \r
295 struct _route\r
296 {\r
297         u8 is_setup;\r
298         /*set to true for proto IS fields*/\r
299         u8 IS_route;\r
300 \r
301         u32 ID;\r
302         char *name;\r
303 \r
304         GF_Node *FromNode;\r
305         GF_FieldInfo FromField;\r
306 \r
307         GF_Node *ToNode;\r
308         GF_FieldInfo ToField;\r
309 \r
310         /*scope of this route*/\r
311         GF_SceneGraph *graph;\r
312         u32 lastActivateTime;\r
313 };\r
314 \r
315 void gf_sg_route_unqueue(GF_SceneGraph *sg, GF_Route *r);\r
316 /*returns TRUE if route modified destination node*/\r
317 Bool gf_sg_route_activate(GF_Route *r);\r
318 void gf_sg_route_queue(GF_SceneGraph *pSG, GF_Route *r);\r
319 \r
320 void gf_sg_destroy_routes(GF_SceneGraph *sg);\r
321 \r
322 void gf_sg_route_setup(GF_Route *r);\r
323 \r
324 \r
325 /*MPEG4 def*/\r
326 GF_Node *gf_sg_mpeg4_node_new(u32 NodeTag);\r
327 u32 gf_sg_mpeg4_node_get_child_ndt(GF_Node *node);\r
328 GF_Err gf_sg_mpeg4_node_get_field_index(GF_Node *node, u32 inField, u8 code_mode, u32 *fieldIndex);\r
329 GF_Err gf_sg_mpeg4_node_get_field(GF_Node *node, GF_FieldInfo *field);\r
330 u32 gf_sg_mpeg4_node_get_field_count(GF_Node *node, u8 code_mode);\r
331 void gf_sg_mpeg4_node_del(GF_Node *node);\r
332 const char *gf_sg_mpeg4_node_get_class_name(u32 NodeTag);\r
333 Bool gf_sg_mpeg4_node_get_aq_info(GF_Node *node, u32 FieldIndex, u8 *QType, u8 *AType, Fixed *b_min, Fixed *b_max, u32 *QT13_bits);\r
334 s32 gf_sg_mpeg4_node_get_field_index_by_name(GF_Node *node, char *name);\r
335 \r
336 /*X3D def*/\r
337 GF_Node *gf_sg_x3d_node_new(u32 NodeTag);\r
338 GF_Err gf_sg_x3d_node_get_field(GF_Node *node, GF_FieldInfo *field);\r
339 u32 gf_sg_x3d_node_get_field_count(GF_Node *node);\r
340 void gf_sg_x3d_node_del(GF_Node *node);\r
341 const char *gf_sg_x3d_node_get_class_name(u32 NodeTag);\r
342 s32 gf_sg_x3d_node_get_field_index_by_name(GF_Node *node, char *name);\r
343 \r
344 Bool gf_x3d_get_node_type(u32 NDT_Tag, u32 NodeTag);\r
345 \r
346 void gf_sg_mfint32_del(MFInt32 par);\r
347 void gf_sg_mffloat_del(MFFloat par);\r
348 void gf_sg_mfdouble_del(MFDouble par);\r
349 void gf_sg_mfbool_del(MFBool par);\r
350 void gf_sg_mfcolor_del(MFColor par);\r
351 void gf_sg_mfcolor_rgba_del(MFColorRGBA par);\r
352 void gf_sg_mfrotation_del(MFRotation par);\r
353 void gf_sg_mfstring_del(MFString par);\r
354 void gf_sg_mftime_del(MFTime par);\r
355 void gf_sg_mfvec2f_del(MFVec2f par);\r
356 void gf_sg_mfvec3f_del(MFVec3f par);\r
357 void gf_sg_mfvec4f_del(MFVec4f par);\r
358 void gf_sg_mfvec2d_del(MFVec2d par);\r
359 void gf_sg_mfvec3d_del(MFVec3d par);\r
360 void gf_sg_sfimage_del(SFImage im);\r
361 void gf_sg_sfstring_del(SFString par);\r
362 void gf_sg_mfscript_del(MFScript sc);\r
363 void gf_sg_sfcommand_del(SFCommandBuffer cb);\r
364 void gf_sg_sfurl_del(SFURL url);\r
365 \r
366 Bool gf_sg_vrml_node_init(GF_Node *node);\r
367 Bool gf_sg_vrml_node_changed(GF_Node *node, GF_FieldInfo *field);\r
368 \r
369 \r
370 /*specialized node unregister for Memory Commands - checks if the node(s) used in the command have been destroyed\r
371 during the reset. If so don't attempt to unregister the node*/\r
372 GF_Err gf_node_try_destroy(GF_SceneGraph *sg, GF_Node *pNode, GF_Node *parentNode);\r
373 \r
374 \r
375 #ifndef GPAC_DISABLE_SVG\r
376 \r
377 \r
378 /* reset functions for SVG types */\r
379 void gf_svg_reset_path(SVG_PathData path);\r
380 void gf_svg_reset_iri(GF_SceneGraph *sg, XMLRI*iri);\r
381 /* delete functions for SVG types */\r
382 void gf_svg_delete_paint                (GF_SceneGraph *sg, SVG_Paint *paint);\r
383 void gf_smil_delete_times               (GF_List *l);\r
384 void gf_svg_delete_points               (GF_List *l);\r
385 void gf_svg_delete_coordinates  (GF_List *l);\r
386 /*for keyTimes, keyPoints and keySplines*/\r
387 void gf_smil_delete_key_types   (GF_List *l);\r
388 \r
389 u32 gf_node_get_attribute_count(GF_Node *node);\r
390 GF_Err gf_node_get_attribute_info(GF_Node *node, GF_FieldInfo *info) ;\r
391 \r
392 \r
393 /*SMIL anim tools*/\r
394 \r
395 typedef struct __xlink_attrip_ptrs {\r
396         XMLRI *href;\r
397         SVG_ContentType *type;\r
398         SVG_String *title;\r
399         XMLRI *arcrole; \r
400         XMLRI *role;\r
401         SVG_String *show;\r
402         SVG_String *actuate;\r
403 } XLinkAttributesPointers;\r
404 \r
405 typedef struct __smil_time_attrip_ptrs {\r
406         SMIL_Times *begin, *end;\r
407         SVG_Clock *clipBegin, *clipEnd;\r
408         SMIL_Duration *dur;\r
409         SMIL_RepeatCount *repeatCount;\r
410         SMIL_Duration *repeatDur;\r
411         SMIL_Restart *restart;\r
412         SMIL_Fill *fill;\r
413         SMIL_Duration *max;\r
414         SMIL_Duration *min;\r
415         struct _smil_timing_rti *runtime; /* contains values for runtime handling of the SMIL timing */\r
416 } SMILTimingAttributesPointers;\r
417 \r
418 typedef struct __smil_sync_attrip_ptrs {\r
419         SMIL_SyncBehavior *syncBehavior, *syncBehaviorDefault;\r
420         SMIL_SyncTolerance *syncTolerance, *syncToleranceDefault;\r
421         SVG_Boolean *syncMaster;\r
422         XMLRI *syncReference;\r
423 } SMILSyncAttributesPointers;\r
424 \r
425 typedef struct __smil_anim_attrip_ptrs {\r
426         SMIL_AttributeName *attributeName; \r
427         SMIL_AttributeType *attributeType;\r
428         SMIL_AnimateValue *to, *by, *from;\r
429         SMIL_AnimateValues *values;\r
430         SMIL_CalcMode *calcMode;\r
431         SMIL_Accumulate *accumulate;\r
432         SMIL_Additive *additive;\r
433         SMIL_KeySplines *keySplines;\r
434         SMIL_KeyTimes *keyTimes;\r
435         SVG_TransformType *type;\r
436         SVG_Boolean *lsr_enabled;\r
437 \r
438         SMIL_KeyPoints *keyPoints;\r
439         SVG_String *origin;\r
440         SVG_Rotate *rotate;\r
441         SVG_PathData *path;\r
442 } SMILAnimationAttributesPointers;\r
443 \r
444 \r
445 typedef struct {\r
446         GF_DOM_BASE_NODE\r
447 \r
448         /*shortcuts for xlink, anim, timing attributes*/\r
449         XLinkAttributesPointers *xlinkp;\r
450         SMILAnimationAttributesPointers *animp;\r
451         SMILTimingAttributesPointers *timingp;\r
452 } SVGTimedAnimBaseElement;\r
453 \r
454 GF_Err gf_node_animation_add(GF_Node *node, void *animation);\r
455 GF_Err gf_node_animation_del(GF_Node *node);\r
456 u32 gf_node_animation_count(GF_Node *node);\r
457 void *gf_node_animation_get(GF_Node *node, u32 i);\r
458 Bool gf_svg_is_inherit(GF_FieldInfo *a);\r
459 Bool gf_svg_is_current_color(GF_FieldInfo *a);\r
460 \r
461 void gf_svg_reset_animate_values(SMIL_AnimateValues anim_values, GF_SceneGraph *sg);\r
462 void gf_svg_reset_animate_value(SMIL_AnimateValue anim_value, GF_SceneGraph *sg);\r
463 \r
464 Bool gf_svg_is_timing_tag(u32 tag);\r
465 Bool gf_svg_is_animation_tag(u32 tag);\r
466 u32 gf_svg_get_modification_flags(SVG_Element *n, GF_FieldInfo *info);\r
467 \r
468 Bool gf_svg_resolve_smil_times(GF_Node *anim, void *event_base_element, GF_List *smil_times, Bool is_end, const char *node_name);\r
469 \r
470 \r
471 /* SMIL Timing structures */\r
472 /* status of an SMIL timed element */ \r
473 enum {\r
474         SMIL_STATUS_WAITING_TO_BEGIN = 0,\r
475         SMIL_STATUS_ACTIVE,\r
476         SMIL_STATUS_POST_ACTIVE,\r
477         SMIL_STATUS_FROZEN,\r
478         SMIL_STATUS_DONE\r
479 };\r
480 \r
481 typedef struct {\r
482         u32 activation_cycle;\r
483         u32 nb_iterations;\r
484 \r
485         /* for the case where min > simple duration*/\r
486         Bool min_active;\r
487 \r
488         /* negative values mean indefinite */\r
489         Double begin, \r
490                    end,\r
491                    simple_duration, \r
492                    active_duration,\r
493                    repeat_duration;\r
494 \r
495 } SMIL_Interval;\r
496 \r
497 struct _smil_timing_rti\r
498 {\r
499         GF_Node *timed_elt;\r
500         SMILTimingAttributesPointers *timingp;\r
501 \r
502         Double scene_time;\r
503         Fixed normalized_simple_time;\r
504         Bool force_reevaluation;\r
505 \r
506         /* SMIL element life-cycle status */\r
507         u8 status;\r
508 \r
509         SMIL_Interval *current_interval;\r
510         SMIL_Interval *next_interval;\r
511 \r
512         /* Evaluation of animations is postponed untill tree traversal, so that inherit values can be computed\r
513         Other timed elements (audio, video, animation) are evaluated directly and do not require\r
514         scene tree traversal.*/\r
515         Bool postpone;\r
516 \r
517         void (*evaluate)(struct _smil_timing_rti *rti, Fixed normalized_simple_time, u32 state);\r
518         u32 evaluate_status;\r
519 \r
520 #if 0\r
521         /* is called only when the timed element is active */\r
522         void (*activation)(struct _smil_timing_rti *rti, Fixed normalized_simple_time);\r
523 \r
524         /* is called (possibly many times) when the timed element is frozen */\r
525         void (*freeze)(struct _smil_timing_rti *rti, Fixed normalized_simple_time);\r
526 \r
527         /* is called (only once) when the timed element is restored */\r
528         void (*restore)(struct _smil_timing_rti *rti, Fixed normalized_simple_time);\r
529 \r
530         /* is called only when the timed element is inactive and receives a fraction event, the second parameter is ignored */\r
531         void (*fraction_activation)(struct _smil_timing_rti *rti, Fixed normalized_simple_time);\r
532 #endif\r
533         /* simulated normalized simple time */\r
534         Fixed fraction;\r
535 \r
536         Bool paused;\r
537         Double media_duration;\r
538 \r
539         /* shortcut when this rti corresponds to an animation */\r
540         struct _smil_anim_rti *rai;\r
541 };\r
542 \r
543 void gf_smil_timing_init_runtime_info(GF_Node *timed_elt);\r
544 void gf_smil_timing_delete_runtime_info(GF_Node *timed_elt, SMIL_Timing_RTI *rti);\r
545 Fixed gf_smil_timing_get_normalized_simple_time(SMIL_Timing_RTI *rti, Double scene_time, Bool *force_end);\r
546 /*returns 1 if an animation changed a value in the rendering tree */\r
547 s32 gf_smil_timing_notify_time(SMIL_Timing_RTI *rti, Double scene_time);\r
548 \r
549 \r
550 /* SMIL Animation Structures */\r
551 /* This structure is used per animated attribute,\r
552    it contains:\r
553     - all the animations applying to the same attribute,\r
554     - the specified value before any inheritance has been applied nor any animation started \r
555             (as specified in the SVG document),\r
556     - the presentation value passed from one animation to the next one, at the same level in the tree\r
557         - a boolean indicating if the animated attribute is in fact a property\r
558    \r
559    and if the attribute is a property:\r
560         - a pointer to presentation value passed from the previous level in the tree\r
561         - a pointer to the value of the color property (for handling of 'currentColor'), from previous level in the tree\r
562         - the location of the attribute in the elt structure when it was created \r
563           (used for fast comparison of SVG properties when animating from/to/by/values/... inherited values)\r
564 */\r
565 typedef struct {\r
566         GF_List *anims;\r
567         GF_FieldInfo specified_value;\r
568         GF_FieldInfo presentation_value;\r
569         Bool is_property;\r
570         GF_FieldInfo parent_presentation_value;\r
571         GF_FieldInfo current_color_value;\r
572         void *orig_dom_ptr;\r
573         /* flag set by any animation to inform other animations that there base value has changed */\r
574         Bool presentation_value_changed;\r
575         /* flag used for rendering */\r
576         u32 dirty_flags;\r
577         Bool dirty_parents;\r
578 } SMIL_AttributeAnimations;\r
579 \r
580 /* This structure is per animation element, \r
581    it holds the result of the animation and \r
582    some info to make animation computation faster */\r
583 typedef struct _smil_anim_rti {\r
584         SMIL_AttributeAnimations *owner;\r
585 \r
586         Bool is_first_anim;\r
587 \r
588         /* animation element */\r
589         GF_Node *anim_elt;\r
590         SMILAnimationAttributesPointers *animp;\r
591         SMILTimingAttributesPointers *timingp;\r
592         XLinkAttributesPointers *xlinkp;\r
593 \r
594         /* in case of animateTransform without from or to, the underlying value is the identity transform */\r
595         GF_Matrix2D identity;\r
596         GF_FieldInfo default_transform_value;\r
597 \r
598         /* result of the animation */\r
599         GF_FieldInfo interpolated_value;\r
600 \r
601         /* last value of the animation, used in accumulation phase */\r
602         /* normally the far pointer in the last specified value is a pointer to a real attribute value,\r
603            and there's no need to allocate a new value. Except if the last specified value is the last \r
604            point in a path (animateMotion) in which case we allocate a matrix as last spec value,\r
605            which we need to delete (see animate-elem-202-t.svg). This is signaled if rai->path is not NULL*/\r
606         GF_FieldInfo last_specified_value;\r
607 \r
608         /* temporary value needed when the type of \r
609            the key values is different from the target attribute type */\r
610         GF_FieldInfo tmp_value;\r
611 \r
612         /* the number of values in animations should be constant (unless updated with LASeR commands) \r
613            we can store them to avoid computing them at each cycle */\r
614         u32 values_count;\r
615         u32 key_times_count;\r
616         u32 key_points_count;\r
617         u32 key_splines_count;\r
618 \r
619 \r
620         /* In change detection mode, we test previous animation parameters to determine \r
621            if a new evaluation of the animation will produce a different result. \r
622            The result of these test is stored in interpolated_value_changed */\r
623         Bool    change_detection_mode;\r
624         Bool    interpolated_value_changed;\r
625         s32             previous_key_index;\r
626         u32             previous_keytime_index;\r
627         Fixed   previous_coef;\r
628         s32             previous_iteration;\r
629         Bool    anim_done;\r
630 \r
631         GF_Path *path;\r
632         u8 rotate;\r
633         GF_PathIterator *path_iterator;\r
634         Fixed length;\r
635 \r
636 } SMIL_Anim_RTI;\r
637 \r
638 void gf_smil_anim_init_node(GF_Node *node);\r
639 void gf_smil_anim_init_discard(GF_Node *node);\r
640 void gf_smil_anim_init_runtime_info(GF_Node *node);\r
641 void gf_smil_anim_delete_runtime_info(SMIL_Anim_RTI *rai);\r
642 void gf_smil_anim_delete_animations(GF_Node *e);\r
643 void gf_smil_anim_remove_from_target(GF_Node *anim, GF_Node *target);\r
644 \r
645 void gf_sg_handle_dom_event(GF_Node *hdl, GF_DOM_Event *event, GF_Node *observer);\r
646 void gf_smil_setup_events(GF_Node *node);\r
647 \r
648 void gf_smil_anim_reset_variables(SMIL_Anim_RTI *rai);\r
649 void gf_smil_anim_set_anim_runtime_in_timing(GF_Node *n);\r
650 \r
651 void gf_smil_timing_pause(GF_Node *node);\r
652 void gf_smil_timing_resume(GF_Node *node);\r
653 \r
654 #endif\r
655 \r
656 \r
657 //\r
658 //              MF Fields tools\r
659 //      WARNING: MF / SF Nodes CANNOT USE THESE FUNCTIONS\r
660 //\r
661 \r
662 //return the size (in bytes) of fixed fields (buffers are handled as a char ptr , 1 byte)\r
663 u32 gf_sg_vrml_get_sf_size(u32 FieldType);\r
664 \r
665 \r
666 /*BASE node (GF_Node) destructor*/\r
667 void gf_node_free(GF_Node *node);\r
668 \r
669 /*node destructor dispatcher: redirects destruction for each graph type: VRML/MPEG4, X3D, SVG...)*/\r
670 void gf_node_del(GF_Node *node);\r
671 \r
672 /*creates an undefined GF_Node - for parsing only*/\r
673 GF_Node *gf_sg_new_base_node();\r
674 \r
675 /*returns field type from its name*/\r
676 u32 gf_sg_field_type_by_name(char *fieldType);\r
677 \r
678 \r
679 \r
680 /*\r
681                         Proto node\r
682 \r
683 */\r
684 \r
685 /*field interface to codec. This is used to do the node decoding, index translation\r
686 and all QP/BIFS Anim parsing. */\r
687 struct _protofield\r
688 {\r
689         u8 EventType;\r
690         u8 FieldType;\r
691         /*if UseName, otherwise fieldN*/\r
692         char *FieldName;\r
693 \r
694         /*default field value*/\r
695         void *def_value;\r
696         \r
697         GF_Node *def_sfnode_value;\r
698         GF_ChildNodeItem *def_mfnode_value;\r
699 \r
700         /*coding indexes*/\r
701         u32 IN_index, OUT_index, DEF_index, ALL_index;\r
702 \r
703         /*Quantization*/\r
704         u32 QP_Type, hasMinMax;\r
705         void *qp_min_value, *qp_max_value;\r
706         /*this is for QP=13 only*/\r
707         u32 NumBits;\r
708 \r
709         /*Animation*/\r
710         u32 Anim_Type;\r
711 \r
712         void *userpriv;\r
713         void (*OnDelete)(void *ptr);\r
714 };\r
715 \r
716 GF_ProtoFieldInterface *gf_sg_proto_new_field_interface(u32 FieldType);\r
717 \r
718 /*set QP and anim info for a proto field (BIFS allows for that in proto coding)*/\r
719 GF_Err gf_bifs_proto_field_set_aq_info(GF_ProtoFieldInterface *field, u32 QP_Type, u32 hasMinMax, u32 QPSFType, void *qp_min_value, void *qp_max_value, u32 QP13_NumBits);\r
720 \r
721 /*proto field instance. since it is useless to duplicate all coding info, names and the like\r
722 we seperate proto declaration and proto instanciation*/\r
723 typedef struct \r
724 {\r
725         u8 EventType;\r
726         u8 FieldType;\r
727         u8 has_been_accessed;\r
728         void *field_pointer;\r
729 } GF_ProtoField;\r
730 \r
731 \r
732 struct _proto\r
733 {\r
734         /*1 - Prototype interface*/\r
735         u32 ID;\r
736         char *Name;\r
737         GF_List *proto_fields;\r
738 \r
739         /*pointer to parent scene graph*/\r
740         struct __tag_scene_graph *parent_graph;\r
741         /*pointer to proto scene graph*/\r
742         struct __tag_scene_graph *sub_graph;\r
743 \r
744         /*2 - proto implementation as declared in the bitstream*/\r
745         GF_List *node_code;\r
746 \r
747         /*num fields*/\r
748         u32 NumIn, NumOut, NumDef, NumDyn;\r
749 \r
750         void *userpriv;\r
751         void (*OnDelete)(void *ptr);\r
752 \r
753         /*URL of extern proto lib (if none, URL is empty)*/\r
754         MFURL ExternProto;\r
755 \r
756         /*list of instances*/\r
757         GF_List *instances;\r
758 };\r
759 \r
760 /*proto field API*/\r
761 u32 gf_sg_proto_get_num_fields(GF_Node *node, u8 code_mode);\r
762 GF_Err gf_sg_proto_get_field(GF_Proto *proto, GF_Node *node, GF_FieldInfo *field);\r
763 \r
764 \r
765 typedef struct _proto_instance\r
766 {\r
767         /*this is a node*/\r
768         BASE_NODE\r
769 \r
770         /*Prototype interface for coding and field addressing*/\r
771         GF_Proto *proto_interface;\r
772 \r
773         /*proto implementation at run-time (aka the state of the nodes may differ accross\r
774         different instances of the proto)*/\r
775         GF_List *fields;\r
776 \r
777         /*a proto doesn't have one root SFnode but a collection of nodes for implementation*/\r
778         GF_List *node_code;\r
779 \r
780         /*node for proto rendering, first of all declared nodes*/\r
781         GF_Node *RenderingNode;\r
782 \r
783         /*in case the PROTO is destroyed*/\r
784         char *proto_name;\r
785 \r
786         /*scripts are loaded once all IS routes are activated and node code is loaded*/\r
787         GF_List *scripts_to_load;\r
788 \r
789         Bool is_loaded;\r
790 } GF_ProtoInstance;\r
791 \r
792 /*destroy proto*/\r
793 void gf_sg_proto_del_instance(GF_ProtoInstance *inst);\r
794 GF_Err gf_sg_proto_get_field_index(GF_ProtoInstance *proto, u32 index, u32 code_mode, u32 *all_index);\r
795 Bool gf_sg_proto_get_aq_info(GF_Node *Node, u32 FieldIndex, u8 *QType, u8 *AType, Fixed *b_min, Fixed *b_max, u32 *QT13_bits);\r
796 GF_Err gf_sg_proto_get_field_ind_static(GF_Node *Node, u32 inField, u8 IndexMode, u32 *allField);\r
797 GF_Node *gf_sg_proto_create_node(GF_SceneGraph *scene, GF_Proto *proto, GF_ProtoInstance *from_inst);\r
798 void gf_sg_proto_instanciate(GF_ProtoInstance *proto_node);\r
799 \r
800 /*get tag of first node in proto code - used for validation only*/\r
801 u32 gf_sg_proto_get_root_tag(GF_Proto *proto);\r
802 \r
803 \r
804 /*to call when a proto field has been modified (at creation or through commands, modifications through events \r
805 are handled internally).\r
806 node can be the proto instance or a node from the proto code\r
807 this will call NodeChanged if needed, forward to proto/node or trigger any route if needed*/\r
808 void gf_sg_proto_propagate_event(GF_Node *node, u32 fieldIndex, GF_Node *from_node);\r
809 \r
810 s32 gf_sg_proto_get_field_index_by_name(GF_Proto *proto, GF_Node *node, char *name);\r
811 \r
812 GF_Node *gf_vrml_node_clone(GF_SceneGraph *inScene, GF_Node *orig, GF_Node *cloned_parent, char *inst_id_suffix);\r
813 \r
814 \r
815 /*\r
816                 Script node\r
817 */\r
818 \r
819 typedef struct \r
820 {\r
821         //extra script fields\r
822         GF_List *fields;\r
823 \r
824         //BIFS coding stuff\r
825         u32 numIn, numDef, numOut;\r
826 \r
827 #ifdef GPAC_HAS_SPIDERMONKEY\r
828         struct JSContext *js_ctx;\r
829         struct JSObject *js_obj;\r
830         struct JSObject *js_browser;\r
831         /*all attached objects (eg, not created by the script) are stored here so that we don't\r
832         allocate them again and again when getting properties. Garbage collection is performed (if needed)\r
833         on these objects after each eventIn execution*/\r
834         GF_List *js_cache;\r
835         struct JSObject *event;\r
836 #endif\r
837 \r
838         void (*JS_PreDestroy)(GF_Node *node);\r
839         void (*JS_EventIn)(GF_Node *node, GF_FieldInfo *in_field);\r
840 \r
841         Bool is_loaded;\r
842 } GF_ScriptPriv;\r
843 \r
844 /*setup script stack*/\r
845 void gf_sg_script_init(GF_Node *node);\r
846 /*get script field*/\r
847 GF_Err gf_sg_script_get_field(GF_Node *node, GF_FieldInfo *info);\r
848 /*get effective field count per event mode*/\r
849 u32 gf_sg_script_get_num_fields(GF_Node *node, u8 IndexMode);\r
850 /*translate field index from inMode to ALL mode*/\r
851 GF_Err gf_sg_script_get_field_index(GF_Node *Node, u32 inField, u8 IndexMode, u32 *allField);\r
852 /*create dynamic fields in the clone*/\r
853 GF_Err gf_sg_script_prepare_clone(GF_Node *dest, GF_Node *orig);\r
854 \r
855 struct _scriptfield\r
856 {\r
857         u32 eventType;\r
858         u32 fieldType;\r
859         char *name;\r
860 \r
861         s32 IN_index, OUT_index, DEF_index;\r
862         u32 ALL_index;\r
863 \r
864         //real field\r
865         void *pField;\r
866 \r
867         Double last_route_time;\r
868         Bool activate_event_out;\r
869 };\r
870 \r
871 \r
872 #ifdef GPAC_HAS_SPIDERMONKEY\r
873 \r
874 \r
875 #include <gpac/download.h>\r
876 #include <gpac/network.h>\r
877 \r
878 \r
879 #define JS_SETUP_CLASS(the_class, cname, flag, getp, setp, fin) \\r
880         memset(&the_class, 0, sizeof(the_class));       \\r
881         the_class.name = cname; \\r
882         the_class.flags = flag; \\r
883         the_class.addProperty = JS_PropertyStub;        \\r
884         the_class.delProperty = JS_PropertyStub;        \\r
885         the_class.getProperty = getp;   \\r
886         the_class.setProperty = setp;   \\r
887         the_class.enumerate = JS_EnumerateStub; \\r
888         the_class.resolve = JS_ResolveStub;             \\r
889         the_class.convert = JS_ConvertStub;             \\r
890         the_class.finalize = fin;       \\r
891         the_class.hasInstance = js_has_instance;\r
892 \r
893 typedef struct\r
894 {\r
895         GF_Node *node;\r
896         GF_DownloadSession *sess;\r
897 } JSFileDownload;\r
898 \r
899 struct JSContext *gf_sg_ecmascript_new(GF_SceneGraph *sg);\r
900 void gf_sg_ecmascript_del(struct JSContext *);\r
901 \r
902 void gf_sg_script_init_sm_api(GF_ScriptPriv *sc, GF_Node *script);\r
903 \r
904 typedef struct \r
905 {\r
906         GF_FieldInfo field;\r
907         GF_Node *owner;\r
908         struct JSObject *obj;\r
909 \r
910         /*JS list for MFFields or NULL*/\r
911         struct JSObject *js_list;\r
912 \r
913         /*when creating SFnode from inside the script, the node is stored here untill attached to an object*/\r
914         GF_Node *temp_node;\r
915         /*when creating MFnode from inside the script, the node list is stored here untill attached to an object*/\r
916         GF_ChildNodeItem *temp_list;\r
917         /*when not owned by a node*/\r
918         void *field_ptr;\r
919         \r
920         /*cpontext in which the field was created*/\r
921         struct JSContext *js_ctx;\r
922 } GF_JSField;\r
923 \r
924 #ifndef GPAC_DISABLE_SVG\r
925 void JSScript_LoadSVG(GF_Node *node);\r
926 \r
927 typedef struct __tag_svg_script_ctx \r
928 {\r
929         Bool (*script_execute)(struct __tag_scene_graph *sg, char *utf8_script, GF_DOM_Event *event);\r
930         Bool (*handler_execute)(GF_Node *n, GF_DOM_Event *event, GF_Node *observer);\r
931         u32 nb_scripts;\r
932         /*global script context for the scene*/\r
933         struct JSContext *js_ctx;\r
934         /*global object*/\r
935         struct JSObject *global;\r
936         /*global event object - used to update the associated DOMEvent (JS private stack) when dispatching events*/\r
937         struct JSObject *event;\r
938 } GF_SVGJS;\r
939 \r
940 #endif  /*GPAC_DISABLE_SVG*/\r
941 \r
942 /*initialize DOM Core (subset) + xmlHTTPRequest API. The global object MUST have private data storage\r
943 and its private data MUST be a scenegraph. This scenegraph is only used to create new documents\r
944 and setup the callback pointers*/\r
945 void dom_js_load(GF_SceneGraph *scene, struct JSContext *c, struct JSObject *global);\r
946 /*unloads the DOM core support (to be called upon destruction only, once the JSContext has been destroyed\r
947 to releases all resources used by DOM JS)*/\r
948 void dom_js_unload();\r
949 \r
950 /*defines a new global object "document" of type Document*/\r
951 void dom_js_define_document(struct JSContext *c, struct JSObject *global, GF_SceneGraph *doc);\r
952 /*defines a new global object "evt" of type Event*/\r
953 struct JSObject *dom_js_define_event(struct JSContext *c, struct JSObject *global);\r
954 \r
955 struct JSObject *gf_dom_new_event(struct JSContext *c);\r
956 \r
957 struct JSObject *dom_js_get_node_proto(struct JSContext *c);\r
958 struct JSObject *dom_js_get_element_proto(struct JSContext *c);\r
959 struct JSObject *dom_js_get_document_proto(struct JSContext *c);\r
960 struct JSObject *dom_js_get_event_proto(struct JSContext *c);\r
961 \r
962 void dom_set_class_selector(struct JSContext *c, /*struct JSClass*/void *(*get_element_class)(GF_Node *n), /*struct JSClass*/void *(*get_document_class)(GF_SceneGraph *n) );\r
963 \r
964 enum\r
965 {\r
966         GF_DOM_EXC_INDEX_SIZE_ERR = 1,\r
967         GF_DOM_EXC_DOMSTRING_SIZE_ERR = 2,\r
968         GF_DOM_EXC_HIERARCHY_REQUEST_ERR = 3,\r
969         GF_DOM_EXC_WRONG_DOCUMENT_ERR = 4,\r
970         GF_DOM_EXC_INVALID_CHARACTER_ERR = 5,\r
971         GF_DOM_EXC_NO_DATA_ALLOWED_ERR = 6,\r
972         GF_DOM_EXC_NO_MODIFICATION_ALLOWED_ERR = 7,\r
973         GF_DOM_EXC_NOT_FOUND_ERR = 8,\r
974         GF_DOM_EXC_NOT_SUPPORTED_ERR = 9,\r
975         GF_DOM_EXC_INUSE_ATTRIBUTE_ERR = 10,\r
976         GF_DOM_EXC_INVALID_STATE_ERR = 11,\r
977         GF_DOM_EXC_SYNTAX_ERR = 12,\r
978         GF_DOM_EXC_INVALID_MODIFICATION_ERR = 13,\r
979         GF_DOM_EXC_NAMESPACE_ERR = 14,\r
980         GF_DOM_EXC_INVALID_ACCESS_ERR = 15,\r
981         GF_DOM_EXC_VALIDATION_ERR = 16,\r
982         GF_DOM_EXC_TYPE_MISMATCH_ERR = 17,\r
983 };\r
984 \r
985 int dom_throw_exception(struct JSContext *c, u32 code);\r
986 \r
987 void gf_sg_handle_dom_event_for_vrml(GF_Node *hdl, GF_DOM_Event *event, GF_Node *observer);\r
988 \r
989 void gf_sg_load_script_extensions(GF_SceneGraph *sg, struct JSContext *c, struct JSObject *obj, Bool unload);\r
990 \r
991 #endif  /*GPAC_HAS_SPIDERMONKEY*/\r
992 \r
993 GF_Err gf_sg_reload_xml_doc(const char *src, GF_SceneGraph *scene);\r
994 \r
995 SVG_Element *gf_svg_create_node(u32 tag);\r
996 Bool gf_svg_node_init(GF_Node *node);\r
997 void gf_svg_node_del(GF_Node *node);\r
998 Bool gf_svg_node_changed(GF_Node *node, GF_FieldInfo *field);\r
999 const char *gf_xml_get_element_name(GF_Node *node);\r
1000 \r
1001 SVGAttribute *gf_node_create_attribute_from_datatype(u32 data_type, u32 attribute_tag);\r
1002 \r
1003 GF_Err gf_node_get_attribute_by_name(GF_Node *node, char *name, u32 xmlns_code, Bool create_if_not_found, Bool set_default, GF_FieldInfo *field);\r
1004 void *gf_svg_get_property_pointer_from_tag(SVGPropertiesPointers *output_property_context, u32 prop_tag);\r
1005 void *gf_svg_get_property_pointer(SVG_Element *elt, void *input_attribute,\r
1006                                                                    SVGPropertiesPointers *output_property_context);\r
1007 \r
1008 Bool gf_svg_is_property(GF_Node *node, GF_FieldInfo *target_attribute);\r
1009 \r
1010 /*exported for LASeR paring*/\r
1011 u32 svg_parse_point(SVG_Point *p, char *value_string);\r
1012 \r
1013 /*activates node. This is used by LASeR:activate and whenever a node is inserted in the scene\r
1014 through DOM*/\r
1015 GF_Err gf_node_activate(GF_Node *node);\r
1016 /*deactivates node. This is used by LASeR:deactivate and whenever a node is removed from the scene\r
1017 through DOM*/\r
1018 GF_Err gf_node_deactivate(GF_Node *node);\r
1019 \r
1020 /*post a listener to be added - this is only used by LASeR:activate and DOM.addEventListener. This \r
1021 is to ensure that when a node is processing an event creating a new listener on this node, this listener\r
1022 will not be triggered*/\r
1023 void gf_dom_listener_post_add(GF_Node *obs, GF_Node *listener);\r
1024 /*process all pending add_listener request*/\r
1025 void gf_dom_listener_process_add(GF_SceneGraph *sg);\r
1026 \r
1027 \r
1028 void gf_node_delete_attributes(GF_Node *node);\r
1029 \r
1030 \r
1031 typedef GF_DOMNode XBL_Element;\r
1032 const char *gf_xbl_get_element_name(u32 tag);\r
1033 u32 gf_xbl_get_element_tag(const char *element_name);\r
1034 XBL_Element *gf_xbl_create_node(u32 ElementTag);\r
1035 u32 gf_xbl_get_attribute_tag(u32 element_tag, const char *attribute_name);\r
1036 GF_DOMAttribute *gf_xbl_create_attribute(GF_DOMNode *elt, u32 tag);\r
1037 \r
1038 \r
1039 GF_Node *gf_xml_node_clone(GF_SceneGraph *inScene, GF_Node *orig, GF_Node *cloned_parent, char *inst_id, Bool deep);\r
1040 \r
1041 GF_Err gf_dom_listener_del(GF_Node *listener, GF_DOMEventTarget *target);\r
1042 \r
1043 GF_DOMHandler *gf_dom_listener_build_ex(GF_Node *node, u32 event_type, u32 event_parameter, GF_Node *handler, GF_Node **out_listener);\r
1044 \r
1045 \r
1046 #endif  /*_GF_SCENEGRAPH_DEV_H_*/\r
1047 \r