2 * GPAC - Multimedia Framework C SDK
\r
4 * Copyright (c) Jean Le Feuvre 2000-2005
\r
5 * All rights reserved
\r
7 * This file is part of GPAC / Scene Graph sub-project
\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
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
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
27 #ifndef _GF_SCENEGRAPH_DEV_H_
\r
28 #define _GF_SCENEGRAPH_DEV_H_
\r
30 /*defined this macro to enable cyclic render*/
\r
31 #define GF_CYCLIC_TRAVERSE_ON
\r
33 /*defined this macro to enable scene replacement from inside (through conditional)*/
\r
34 //#define GF_SELF_REPLACE_ENABLE
\r
36 /*for vrml base types, ROUTEs and PROTOs*/
\r
37 #include <gpac/scenegraph_vrml.h>
\r
39 #include <gpac/scenegraph_svg.h>
\r
41 #ifdef GPAC_HAS_SPIDERMONKEY
\r
43 /*WIN32 and WinCE config (no configure script)*/
\r
44 #if defined(WIN32) || defined(_WIN32_WCE) || defined(__SYMBIAN32__)
\r
51 /*WINCE specific config*/
\r
52 #if defined(_WIN32_WCE)
\r
53 #include <windows.h>
\r
58 /*other platforms should be setup through configure*/
\r
63 void gf_node_setup(GF_Node *p, u32 tag);
\r
65 typedef struct _parent_list
\r
67 struct _parent_list *next;
\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
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
83 #define GF_NODE_INTERNAL_FLAGS 0xE0000000
\r
86 struct _node_interactive_ext
\r
88 /*routes on eventOut, ISed routes, ... for VRML-based scene graphs
\r
89 THIS IS DYNAMICALLY CREATED*/
\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
98 #ifndef GPAC_DISABLE_SVG
\r
99 /*event listeners - THIS IS DYNAMICALLY CREATED*/
\r
100 GF_DOMEventTarget *dom_evt;
\r
102 /* SVG animations are registered in the target node - THIS IS DYNAMICALLY CREATED*/
\r
103 GF_List *animations;
\r
108 typedef struct _nodepriv
\r
112 /*number of instances of this node in the graph*/
\r
116 /*scenegraph holding the node*/
\r
117 struct __tag_scene_graph *scenegraph;
\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
124 /*list of all parent nodes (needed to invalidate parent tree)*/
\r
125 GF_ParentList *parents;
\r
127 /*holder for all interactive stuff - THIS IS DYNAMICALLY CREATED*/
\r
128 struct _node_interactive_ext *interact;
\r
132 typedef struct __tag_node_id
\r
134 struct __tag_node_id *next;
\r
150 struct __tag_scene_graph
\r
152 /*used to discriminate between node and scenegraph*/
\r
153 u64 __reserved_null;
\r
155 /*all DEF nodes (explicit)*/
\r
156 NodeIDedItem *id_node, *id_node_last;
\r
158 /*all routes available*/
\r
161 /*all routes available*/
\r
162 GF_List *exported_nodes;
\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
169 /*all first-level protos of the graph (the only ones that can be instanciated in this graph)*/
\r
171 /*all first-level protos of the graph not currently registered - memory handling of graph only*/
\r
172 GF_List *unregistered_protos;
\r
174 /*pointer to the root node*/
\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
182 /*since events may trigger deletion of objects we use a 2 step delete*/
\r
183 GF_List *routes_to_destroy;
\r
185 u32 simulation_tick;
\r
187 /*user private data*/
\r
190 /*callback routines*/
\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
196 GF_SceneGraph *(*GetExternProtoLib)(void *userpriv, MFURL *lib_url);
\r
198 /*parent scene if any*/
\r
199 struct __tag_scene_graph *parent_scene;
\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
204 Bool usePixelMetrics;
\r
208 /*application interface for javascript*/
\r
209 gf_sg_script_action script_action;
\r
210 void *script_action_cbck;
\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
217 u32 max_defined_route_id;
\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
223 #ifdef GF_SELF_REPLACE_ENABLE
\r
224 /*to detect replace scene from within conditionals*/
\r
225 Bool graph_has_been_reset;
\r
227 /*global qp used in BIFS coding*/
\r
228 GF_Node *global_qp;
\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
233 /*temp storage for name conversions*/
\r
234 char szNameBuffer[100];
\r
236 #ifndef GPAC_DISABLE_SVG
\r
237 GF_DOMEventTarget dom_evt;
\r
244 u32 nb_evts_mutation;
\r
248 u32 dom_evt_filter;
\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
255 /*listeners to add*/
\r
256 GF_List *listeners_to_add;
\r
258 #ifdef GPAC_HAS_SPIDERMONKEY
\r
259 struct __tag_svg_script_ctx *svg_js;
\r
264 #ifdef GPAC_HAS_SPIDERMONKEY
\r
267 Note about reference counter
\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
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
278 u32 reference_count;
\r
282 struct JSObject *document;
\r
288 void gf_sg_parent_setup(GF_Node *pNode);
\r
289 void gf_sg_parent_reset(GF_Node *pNode);
\r
291 void *gf_node_get_name_address(GF_Node*node);
\r
293 void gf_node_changed_internal(GF_Node *node, GF_FieldInfo *field, Bool notify_scripts);
\r
298 /*set to true for proto IS fields*/
\r
305 GF_FieldInfo FromField;
\r
308 GF_FieldInfo ToField;
\r
310 /*scope of this route*/
\r
311 GF_SceneGraph *graph;
\r
312 u32 lastActivateTime;
\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
320 void gf_sg_destroy_routes(GF_SceneGraph *sg);
\r
322 void gf_sg_route_setup(GF_Route *r);
\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
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
344 Bool gf_x3d_get_node_type(u32 NDT_Tag, u32 NodeTag);
\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
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
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
375 #ifndef GPAC_DISABLE_SVG
\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
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
393 /*SMIL anim tools*/
\r
395 typedef struct __xlink_attrip_ptrs {
\r
397 SVG_ContentType *type;
\r
402 SVG_String *actuate;
\r
403 } XLinkAttributesPointers;
\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
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
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
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
438 SMIL_KeyPoints *keyPoints;
\r
439 SVG_String *origin;
\r
440 SVG_Rotate *rotate;
\r
441 SVG_PathData *path;
\r
442 } SMILAnimationAttributesPointers;
\r
448 /*shortcuts for xlink, anim, timing attributes*/
\r
449 XLinkAttributesPointers *xlinkp;
\r
450 SMILAnimationAttributesPointers *animp;
\r
451 SMILTimingAttributesPointers *timingp;
\r
452 } SVGTimedAnimBaseElement;
\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
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
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
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
471 /* SMIL Timing structures */
\r
472 /* status of an SMIL timed element */
\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
482 u32 activation_cycle;
\r
485 /* for the case where min > simple duration*/
\r
488 /* negative values mean indefinite */
\r
497 struct _smil_timing_rti
\r
499 GF_Node *timed_elt;
\r
500 SMILTimingAttributesPointers *timingp;
\r
503 Fixed normalized_simple_time;
\r
504 Bool force_reevaluation;
\r
506 /* SMIL element life-cycle status */
\r
509 SMIL_Interval *current_interval;
\r
510 SMIL_Interval *next_interval;
\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
517 void (*evaluate)(struct _smil_timing_rti *rti, Fixed normalized_simple_time, u32 state);
\r
518 u32 evaluate_status;
\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
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
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
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
533 /* simulated normalized simple time */
\r
537 Double media_duration;
\r
539 /* shortcut when this rti corresponds to an animation */
\r
540 struct _smil_anim_rti *rai;
\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
550 /* SMIL Animation Structures */
\r
551 /* This structure is used per animated attribute,
\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
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
567 GF_FieldInfo specified_value;
\r
568 GF_FieldInfo presentation_value;
\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
577 Bool dirty_parents;
\r
578 } SMIL_AttributeAnimations;
\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
586 Bool is_first_anim;
\r
588 /* animation element */
\r
590 SMILAnimationAttributesPointers *animp;
\r
591 SMILTimingAttributesPointers *timingp;
\r
592 XLinkAttributesPointers *xlinkp;
\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
598 /* result of the animation */
\r
599 GF_FieldInfo interpolated_value;
\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
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
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
615 u32 key_times_count;
\r
616 u32 key_points_count;
\r
617 u32 key_splines_count;
\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
633 GF_PathIterator *path_iterator;
\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
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
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
651 void gf_smil_timing_pause(GF_Node *node);
\r
652 void gf_smil_timing_resume(GF_Node *node);
\r
659 // WARNING: MF / SF Nodes CANNOT USE THESE FUNCTIONS
\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
666 /*BASE node (GF_Node) destructor*/
\r
667 void gf_node_free(GF_Node *node);
\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
672 /*creates an undefined GF_Node - for parsing only*/
\r
673 GF_Node *gf_sg_new_base_node();
\r
675 /*returns field type from its name*/
\r
676 u32 gf_sg_field_type_by_name(char *fieldType);
\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
691 /*if UseName, otherwise fieldN*/
\r
694 /*default field value*/
\r
697 GF_Node *def_sfnode_value;
\r
698 GF_ChildNodeItem *def_mfnode_value;
\r
701 u32 IN_index, OUT_index, DEF_index, ALL_index;
\r
704 u32 QP_Type, hasMinMax;
\r
705 void *qp_min_value, *qp_max_value;
\r
706 /*this is for QP=13 only*/
\r
713 void (*OnDelete)(void *ptr);
\r
716 GF_ProtoFieldInterface *gf_sg_proto_new_field_interface(u32 FieldType);
\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
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
727 u8 has_been_accessed;
\r
728 void *field_pointer;
\r
734 /*1 - Prototype interface*/
\r
737 GF_List *proto_fields;
\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
744 /*2 - proto implementation as declared in the bitstream*/
\r
745 GF_List *node_code;
\r
748 u32 NumIn, NumOut, NumDef, NumDyn;
\r
751 void (*OnDelete)(void *ptr);
\r
753 /*URL of extern proto lib (if none, URL is empty)*/
\r
756 /*list of instances*/
\r
757 GF_List *instances;
\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
765 typedef struct _proto_instance
\r
770 /*Prototype interface for coding and field addressing*/
\r
771 GF_Proto *proto_interface;
\r
773 /*proto implementation at run-time (aka the state of the nodes may differ accross
\r
774 different instances of the proto)*/
\r
777 /*a proto doesn't have one root SFnode but a collection of nodes for implementation*/
\r
778 GF_List *node_code;
\r
780 /*node for proto rendering, first of all declared nodes*/
\r
781 GF_Node *RenderingNode;
\r
783 /*in case the PROTO is destroyed*/
\r
786 /*scripts are loaded once all IS routes are activated and node code is loaded*/
\r
787 GF_List *scripts_to_load;
\r
790 } GF_ProtoInstance;
\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
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
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
810 s32 gf_sg_proto_get_field_index_by_name(GF_Proto *proto, GF_Node *node, char *name);
\r
812 GF_Node *gf_vrml_node_clone(GF_SceneGraph *inScene, GF_Node *orig, GF_Node *cloned_parent, char *inst_id_suffix);
\r
821 //extra script fields
\r
824 //BIFS coding stuff
\r
825 u32 numIn, numDef, numOut;
\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
835 struct JSObject *event;
\r
838 void (*JS_PreDestroy)(GF_Node *node);
\r
839 void (*JS_EventIn)(GF_Node *node, GF_FieldInfo *in_field);
\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
855 struct _scriptfield
\r
861 s32 IN_index, OUT_index, DEF_index;
\r
867 Double last_route_time;
\r
868 Bool activate_event_out;
\r
872 #ifdef GPAC_HAS_SPIDERMONKEY
\r
875 #include <gpac/download.h>
\r
876 #include <gpac/network.h>
\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
896 GF_DownloadSession *sess;
\r
899 struct JSContext *gf_sg_ecmascript_new(GF_SceneGraph *sg);
\r
900 void gf_sg_ecmascript_del(struct JSContext *);
\r
902 void gf_sg_script_init_sm_api(GF_ScriptPriv *sc, GF_Node *script);
\r
906 GF_FieldInfo field;
\r
908 struct JSObject *obj;
\r
910 /*JS list for MFFields or NULL*/
\r
911 struct JSObject *js_list;
\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
920 /*cpontext in which the field was created*/
\r
921 struct JSContext *js_ctx;
\r
924 #ifndef GPAC_DISABLE_SVG
\r
925 void JSScript_LoadSVG(GF_Node *node);
\r
927 typedef struct __tag_svg_script_ctx
\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
932 /*global script context for the scene*/
\r
933 struct JSContext *js_ctx;
\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
940 #endif /*GPAC_DISABLE_SVG*/
\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
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
955 struct JSObject *gf_dom_new_event(struct JSContext *c);
\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
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
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
985 int dom_throw_exception(struct JSContext *c, u32 code);
\r
987 void gf_sg_handle_dom_event_for_vrml(GF_Node *hdl, GF_DOM_Event *event, GF_Node *observer);
\r
989 void gf_sg_load_script_extensions(GF_SceneGraph *sg, struct JSContext *c, struct JSObject *obj, Bool unload);
\r
991 #endif /*GPAC_HAS_SPIDERMONKEY*/
\r
993 GF_Err gf_sg_reload_xml_doc(const char *src, GF_SceneGraph *scene);
\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
1001 SVGAttribute *gf_node_create_attribute_from_datatype(u32 data_type, u32 attribute_tag);
\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
1008 Bool gf_svg_is_property(GF_Node *node, GF_FieldInfo *target_attribute);
\r
1010 /*exported for LASeR paring*/
\r
1011 u32 svg_parse_point(SVG_Point *p, char *value_string);
\r
1013 /*activates node. This is used by LASeR:activate and whenever a node is inserted in the scene
\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
1018 GF_Err gf_node_deactivate(GF_Node *node);
\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
1028 void gf_node_delete_attributes(GF_Node *node);
\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
1039 GF_Node *gf_xml_node_clone(GF_SceneGraph *inScene, GF_Node *orig, GF_Node *cloned_parent, char *inst_id, Bool deep);
\r
1041 GF_Err gf_dom_listener_del(GF_Node *listener, GF_DOMEventTarget *target);
\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
1046 #endif /*_GF_SCENEGRAPH_DEV_H_*/
\r