~ubuntu-branches/debian/experimental/gpac/experimental

« back to all changes in this revision

Viewing changes to src/scenegraph/vrml_smjs.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2014-02-22 18:15:00 UTC
  • mfrom: (1.2.2) (3.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140222181500-b4phupo05gjpmopa
Tags: 0.5.0+svn5104~dfsg1-1
* New  upstream version 0.5.0+svn5104~dfsg1:
  - src/utils/sha1.c is relicensed under LGPLv2.1, Closes: #730759
* Don't install modules in multi-arch directories, Closes: #730497
* Add libusb-1.0.0-dev headers because libfreenect requires this
* Fix install rule
* Follow upstream soname bump
  - Drop the symbols file for now until it has been revised thourougly
* Let binaries produce the correct svn revision
* Refresh patches
* Patch and build against libav10, Closes: #739321
* Bump standards version, no changes necessary

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
#if !defined(__GNUC__)
104
104
# if defined(_WIN32_WCE)
105
105
#  pragma comment(lib, "js32")
 
106
# elif defined (_WIN64)
 
107
#  pragma comment(lib, "js")
106
108
# elif defined (WIN32)
107
 
#  pragma comment(lib, "js32")
 
109
#  pragma comment(lib, "js")
108
110
# endif
109
111
#endif
110
112
 
111
113
/*define this macro to force Garbage Collection after each input to JS (script initialize/shutdown and all eventIn) 
112
114
on latest SM, GC will crash if called from a different thread than the thread creating the contex, no clue why
 
115
 
 
116
for iOS don't force GC (better performances according to Ivica)
113
117
*/
114
 
#if (JS_VERSION<180)
115
 
#define FORCE_GC
 
118
#if !defined(GPAC_IPHONE)
 
119
# if (JS_VERSION<180)
 
120
#  define FORCE_GC
 
121
# endif
116
122
#endif
117
123
 
118
124
 
880
886
        }
881
887
        /*route to object*/
882
888
        else {
883
 
                GF_RouteToFunction *r;
 
889
                u32 i = 0;
 
890
                const char *fun_name;
 
891
                GF_RouteToFunction *r = NULL;
884
892
                if (!JSVAL_IS_OBJECT(argv[3]) || !JS_ObjectIsFunction(c, JSVAL_TO_OBJECT(argv[3])) ) return JS_FALSE;
885
893
 
886
 
                GF_SAFEALLOC(r, GF_RouteToFunction)
887
 
                if (!r) return JS_FALSE;
888
 
                r->FromNode = n1;
889
 
                r->FromField.fieldIndex = f_id1;
890
 
                gf_node_get_field(r->FromNode, f_id1, &r->FromField);
891
 
 
892
 
                r->ToNode = (GF_Node*)JS_GetScript(c);
893
 
                r->ToField.fieldType = GF_SG_VRML_SCRIPT_FUNCTION;
894
 
                r->ToField.on_event_in = on_route_to_object;
895
 
                r->ToField.eventType = GF_SG_EVENT_IN;
896
 
                r->ToField.far_ptr = NULL;
897
 
                r->ToField.name = JS_GetFunctionName( JS_ValueToFunction(c, argv[3] ) );
898
 
 
899
 
                r->obj = JSVAL_TO_OBJECT( argv[2] ) ;
900
 
//              gf_js_add_root(c, & r->obj);
901
 
 
902
 
                r->fun = argv[3];
903
 
//              gf_js_add_root(c, &r->fun);
904
 
 
905
 
                r->is_setup = 1;
906
 
                r->graph = n1->sgprivate->scenegraph;
907
 
 
908
 
                if (!n1->sgprivate->interact) GF_SAFEALLOC(n1->sgprivate->interact, struct _node_interactive_ext);
909
 
                if (!n1->sgprivate->interact->routes) n1->sgprivate->interact->routes = gf_list_new();
910
 
                gf_list_add(n1->sgprivate->interact->routes, r);
911
 
                gf_list_add(n1->sgprivate->scenegraph->Routes, r);
 
894
                fun_name = JS_GetFunctionName( JS_ValueToFunction(c, argv[3] ) );
 
895
                if (fun_name && n1->sgprivate->interact && n1->sgprivate->interact->routes ) {
 
896
                        while ( (r = (GF_RouteToFunction*)gf_list_enum(n1->sgprivate->interact->routes, &i) )) {
 
897
                                if ( (r->FromNode == n1) 
 
898
                                && (r->FromField.fieldIndex == f_id1)
 
899
                                && (r->ToNode == (GF_Node*)JS_GetScript(c))
 
900
                                && !stricmp(r->ToField.name, fun_name)
 
901
                        )
 
902
                                        break;
 
903
                        }
 
904
                }
 
905
 
 
906
                if ( !r ) {
 
907
                        GF_SAFEALLOC(r, GF_RouteToFunction)
 
908
                        if (!r) return JS_FALSE;
 
909
                        r->FromNode = n1;
 
910
                        r->FromField.fieldIndex = f_id1;
 
911
                        gf_node_get_field(r->FromNode, f_id1, &r->FromField);
 
912
 
 
913
                        r->ToNode = (GF_Node*)JS_GetScript(c);
 
914
                        r->ToField.fieldType = GF_SG_VRML_SCRIPT_FUNCTION;
 
915
                        r->ToField.on_event_in = on_route_to_object;
 
916
                        r->ToField.eventType = GF_SG_EVENT_IN;
 
917
                        r->ToField.far_ptr = NULL;
 
918
                        r->ToField.name = fun_name;
 
919
 
 
920
                        r->obj = JSVAL_TO_OBJECT( argv[2] ) ;
 
921
        //              gf_js_add_root(c, & r->obj);
 
922
 
 
923
                        r->fun = argv[3];
 
924
        //              gf_js_add_root(c, &r->fun);
 
925
 
 
926
                        r->is_setup = 1;
 
927
                        r->graph = n1->sgprivate->scenegraph;
 
928
 
 
929
                        if (!n1->sgprivate->interact) GF_SAFEALLOC(n1->sgprivate->interact, struct _node_interactive_ext);
 
930
                        if (!n1->sgprivate->interact->routes) n1->sgprivate->interact->routes = gf_list_new();
 
931
                        gf_list_add(n1->sgprivate->interact->routes, r);
 
932
                        gf_list_add(n1->sgprivate->scenegraph->Routes, r);
 
933
                }
912
934
        }
913
935
 
914
936
        return JS_TRUE;
1144
1166
        return JS_TRUE;
1145
1167
}
1146
1168
 
 
1169
void gf_node_event_out_proto(GF_Node *node, u32 FieldIndex);
 
1170
 
1147
1171
void Script_FieldChanged(JSContext *c, GF_Node *parent, GF_JSField *parent_owner, GF_FieldInfo *field)
1148
1172
{
1149
1173
        GF_ScriptPriv *priv;
1176
1200
                        return;
1177
1201
                }
1178
1202
                /*field has changed, set routes...*/
1179
 
                if (parent->sgprivate->tag == TAG_ProtoNode)
 
1203
                if (parent->sgprivate->tag == TAG_ProtoNode) {
1180
1204
                        gf_sg_proto_propagate_event(parent, field->fieldIndex, (GF_Node*)JS_GetScript(c));
1181
 
                else {
 
1205
                        /* Node exposedField can also be routed to another field */
 
1206
                        gf_node_event_out_proto(parent, field->fieldIndex);
 
1207
                }else{
1182
1208
                        gf_node_event_out(parent, field->fieldIndex);
1183
1209
                        gf_node_changed_internal(parent, field, 0);
1184
1210
                }
1273
1299
        case GF_SG_VRML_SFCOLOR:
1274
1300
        {
1275
1301
                SFColor val = * ((SFColor *) f_ptr);
1276
 
                sprintf(temp, "%f %f %f", val.red, val.green, val.blue);
 
1302
                sprintf(temp, "%f %f %f", FIX2FLT(val.red), FIX2FLT(val.green), FIX2FLT(val.blue));
1277
1303
                strcat(str, temp);
1278
1304
                break;
1279
1305
        }
1791
1817
                        pixels = (MFInt32 *) ((GF_JSField *) SMJS_GET_PRIVATE(c, JSVAL_TO_OBJECT(*vp)))->field.far_ptr;
1792
1818
                        if (sfi->pixels) gf_free(sfi->pixels);
1793
1819
                        len = sfi->width*sfi->height*sfi->numComponents;
1794
 
                        sfi->pixels = (char *) gf_malloc(sizeof(char)*len);
 
1820
                        sfi->pixels = (unsigned char *) gf_malloc(sizeof(char)*len);
1795
1821
                        len = MAX(len, pixels->count);
1796
1822
                        for (i=0; i<len; i++) sfi->pixels[i] = (u8) pixels->vals[i];
1797
1823
                        changed = 1;
4336
4362
        GF_FieldInfo t_info;
4337
4363
        GF_ScriptPriv *priv;
4338
4364
        u32 i;
 
4365
        uintN attr;
 
4366
        JSBool found;
4339
4367
        priv = node->sgprivate->UserPrivate;
4340
4368
 
4341
4369
        /*no support for change of static fields*/
4353
4381
        gf_sg_lock_javascript(priv->js_ctx, 1);
4354
4382
 
4355
4383
        //locate function
4356
 
        if (! JS_LookupProperty(priv->js_ctx, priv->js_obj, sf->name, &fval) || JSVAL_IS_VOID(fval)) {
 
4384
        if (!JS_LookupProperty(priv->js_ctx, priv->js_obj, sf->name, &fval) || JSVAL_IS_VOID(fval) ||
 
4385
                !JS_GetPropertyAttributes(priv->js_ctx, priv->js_obj, sf->name, &attr, &found) || found != JS_TRUE ){
4357
4386
                gf_sg_lock_javascript(priv->js_ctx, 0);
4358
4387
                return;
4359
4388
        }
4402
4431
        JSBool ret;
4403
4432
        jsval rval, fval;
4404
4433
        GF_ScriptPriv *priv = (GF_ScriptPriv *) script->sgprivate->UserPrivate;
 
4434
        uintN attr;
 
4435
        JSBool found;
4405
4436
 
4406
4437
        jsf = gf_f64_open(file, "rb");
4407
4438
        if (!jsf) return 0;
4414
4445
        fclose(jsf);
4415
4446
        jsscript[fsize] = 0;
4416
4447
 
4417
 
        ret = JS_EvaluateScript(priv->js_ctx, priv->js_obj, jsscript, sizeof(char)*(size_t)fsize, 0, 0, &rval);
 
4448
        ret = JS_EvaluateScript(priv->js_ctx, priv->js_obj, jsscript, (u32) (sizeof(char)*fsize), 0, 0, &rval);
4418
4449
        if (ret==JS_FALSE) success = 0;
4419
4450
 
4420
 
        if (success && primary_script && JS_LookupProperty(priv->js_ctx, priv->js_obj, "initialize", &fval)) {
4421
 
                if (! JSVAL_IS_VOID(fval)) {
 
4451
        if (success && primary_script
 
4452
                && JS_LookupProperty(priv->js_ctx, priv->js_obj, "initialize", &fval) && !JSVAL_IS_VOID(fval)
 
4453
                && JS_GetPropertyAttributes(priv->js_ctx, priv->js_obj, "initialize", &attr, &found) && found == JS_TRUE) {
 
4454
                
4422
4455
                        JS_CallFunctionValue(priv->js_ctx, priv->js_obj, fval, 0, NULL, &rval);
4423
4456
                        gf_js_vrml_flush_event_out((GF_Node *)script, priv);
4424
 
                }
4425
4457
        }
4426
4458
        gf_free(jsscript);
4427
4459
        return success;
4504
4536
        jsval rval, fval;
4505
4537
        M_Script *script = (M_Script *)node;
4506
4538
        GF_ScriptPriv *priv = (GF_ScriptPriv *) node->sgprivate->UserPrivate;
 
4539
        uintN attr;
 
4540
        JSBool found;
4507
4541
 
4508
4542
        if (!priv || priv->is_loaded) return;
4509
4543
        if (!script->url.count) return;
4566
4600
        GF_LOG(GF_LOG_DEBUG, GF_LOG_SCRIPT, ("[VRML JS] Evaluating script %s\n", str));
4567
4601
 
4568
4602
#if 1
4569
 
        ret = JS_EvaluateScript(priv->js_ctx, priv->js_obj, str, strlen(str), 0, 0, &rval);
 
4603
        ret = JS_EvaluateScript(priv->js_ctx, priv->js_obj, str, (u32) strlen(str), 0, 0, &rval);
4570
4604
        if (ret==JS_TRUE) {
4571
4605
                /*call initialize if present*/
4572
 
                if (JS_LookupProperty(priv->js_ctx, priv->js_obj, "initialize", &fval) && !JSVAL_IS_VOID(fval))
 
4606
                if (JS_LookupProperty(priv->js_ctx, priv->js_obj, "initialize", &fval) && !JSVAL_IS_VOID(fval)
 
4607
                        && JS_GetPropertyAttributes(priv->js_ctx, priv->js_obj, "initialize", &attr, &found) && found == JS_TRUE)
 
4608
                        
4573
4609
                        JS_CallFunctionValue(priv->js_ctx, priv->js_obj, fval, 0, NULL, &rval);
4574
 
 
4575
 
                gf_js_vrml_flush_event_out(node, priv);
 
4610
                        gf_js_vrml_flush_event_out(node, priv);
4576
4611
        }
4577
4612
#endif
4578
4613
 
4912
4947
        }
4913
4948
        return 0;
4914
4949
}
 
4950
 
4915
4951
#endif /* GPAC_HAS_SPIDERMONKEY */
 
4952
 
 
4953
GF_Err gf_scene_execute_script(GF_SceneGraph *sg, const char *com) 
 
4954
{
 
4955
#ifdef GPAC_HAS_SPIDERMONKEY
 
4956
        u32 tag;
 
4957
        GF_Err e;
 
4958
        GF_Node *root = gf_sg_get_root_node(sg);
 
4959
        if (root) {
 
4960
                tag = gf_node_get_tag(root);
 
4961
                if (tag >= GF_NODE_RANGE_FIRST_SVG) {
 
4962
                        GF_SVGJS *svg_js = sg->svg_js;
 
4963
                        Bool ret = svg_js->script_execute(sg, (char *)com, NULL);
 
4964
                        return (ret == GF_TRUE ? GF_OK : GF_BAD_PARAM);
 
4965
                } else {
 
4966
                        e = GF_NOT_SUPPORTED;
 
4967
                        return e;
 
4968
                }
 
4969
        }
 
4970
        return GF_BAD_PARAM;
 
4971
#else
 
4972
        return GF_NOT_SUPPORTED;
 
4973
#endif
 
4974
}