[3.0] Remove experimental features
[platform/core/uifw/dali-adaptor.git] / adaptors / emscripten / wrappers / dali-wrapper.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18
19 // EXTERNAL INCLUDES
20 #include <sstream>
21 #include <dali/public-api/rendering/geometry.h>
22 #include <dali/public-api/rendering/sampler.h>
23 #include <dali/public-api/rendering/shader.h>
24 #include <dali/public-api/rendering/texture-set.h>
25 #include <dali/public-api/rendering/renderer.h>
26 #include <dali/devel-api/scripting/scripting.h>
27 #include <dali/devel-api/events/hit-test-algorithm.h>
28 #include <dali/devel-api/images/texture-set-image.h>
29 #include "emscripten/emscripten.h"
30 #include "emscripten/bind.h"
31 #include "emscripten/val.h"
32
33 // INTERNAL INCLUDES
34 #include "platform-abstractions/emscripten/emscripten-callbacks.h"
35 #include "platform-abstractions/emscripten/emscripten-platform-abstraction.h"
36 #include "sdl-application.h"
37 #include "actor-wrapper.h"
38 #include "animation-wrapper.h"
39 #include "emscripten-utils.h"
40 #include "geometry-wrapper.h"
41 #include "handle-wrapper.h"
42 #include "image-wrapper.h"
43 #include "property-buffer-wrapper.h"
44 #include "property-value-wrapper.h"
45 #include "render-task-wrapper.h"
46 #include "shader-effect-wrapper.h"
47 #include "signal-holder.h"
48 #include "type-info-wrapper.h"
49
50 ////////////////////////////////////////////////////////////////////////////////
51 //
52 // The browser javascript wrapper consists of this cpp file and a counterpart
53 // javascript file.
54 //
55 // They work in tandem to help make the interface natural and convenient
56 // for a Javascript programmer.
57 //
58 // Unfortunately there is no finalize/destruction in javascript so any cpp
59 // objects created must be explicitly deleted. Sometimes this wrapper can
60 // hide the details and simple types can be immediately marshalled to and
61 // from javascript values. More often objects created must have
62 // object.delete() called at the correct time.
63 //
64 ////////////////////////////////////////////////////////////////////////////////
65
66 extern void EmscriptenMouseEvent(double x, double y, int mouseIsDown);
67 extern void EmscriptenUpdateOnce();
68 extern void EmscriptenRenderOnce();
69
70 namespace Dali
71 {
72 namespace Internal
73 {
74 namespace Emscripten
75 {
76
77 // Javascript callbacks. These are set in the Javascript wrapper source and called
78 // from the c++ wrapper source
79 extern emscripten::val JSGetGlyphImage;
80 extern emscripten::val JSGetImage;
81 extern emscripten::val JSGetImageMetaData;
82 extern emscripten::val JSRenderFinished;
83
84 using namespace emscripten;
85
86 /**
87  * Dali Vector access for Emscripten wrapping of Dali::Vector
88  */
89 template<typename DaliVectorType>
90 struct DaliVectorAccess
91 {
92   static emscripten::val Get( const DaliVectorType& v, typename DaliVectorType::SizeType index )
93   {
94     if (index < v.Size())
95     {
96       return emscripten::val(v[index]);
97     }
98     else
99     {
100       return emscripten::val::undefined();
101     }
102   }
103
104   static bool Set( DaliVectorType& v, typename DaliVectorType::SizeType index, const typename DaliVectorType::ItemType& value)
105   {
106     v[index] = value;
107     return true;
108   }
109
110   static size_t Size( DaliVectorType& v)
111   {
112     return v.Size();
113   }
114 };
115
116 /**
117  * Registering a Dali Vector with Emscripten to wrap for JavaScript
118  */
119 template<typename T>
120 class_<Dali::Vector<T>> register_dali_vector(const char* name)
121 {
122   typedef Dali::Vector<T> DaliVecType;
123
124   void (DaliVecType::*PushBack)(const T&) = &DaliVecType::PushBack;
125   void (DaliVecType::*Resize)(const size_t, const T&) = &DaliVecType::Resize;
126   return class_<DaliVecType>(name)
127     .template constructor<>()
128     .function("push_back", PushBack)
129     .function("resize", Resize)
130     .function("size", &DaliVectorAccess<DaliVecType>::Size)
131     .function("get", &DaliVectorAccess<DaliVecType>::Get)
132     .function("set", &DaliVectorAccess<DaliVecType>::Set)
133 ;
134 };
135
136
137 namespace
138 {
139
140 std::string VersionString()
141 {
142   std::stringstream versionString;
143   versionString <<  "DALi Core:      " << Dali::CORE_MAJOR_VERSION << "." << Dali::CORE_MINOR_VERSION << "." << Dali::CORE_MICRO_VERSION << " (" << Dali::CORE_BUILD_DATE << ")" << std::endl;
144   return versionString.str();
145 }
146
147 /**
148  * Creates an Actor previously registered with the TypeRegistry by name
149  * Actors are currently differentiated in the dali-wrapper.js and have accessor functions
150  * to support 'property.name=' access in the Javascript side object
151  */
152 Dali::Actor CreateActor(const std::string& name)
153 {
154   Dali::Actor ret;
155
156   Dali::TypeRegistry registry = Dali::TypeRegistry::Get();
157
158   Dali::TypeInfo typeInfo = registry.GetTypeInfo( name );
159
160   if(!typeInfo)
161   {
162     EM_ASM( throw "Invalid type name" );
163   }
164   else
165   {
166     Dali::BaseHandle handle = typeInfo.CreateInstance();
167
168     if(!handle)
169     {
170       EM_ASM( throw "Invalid handle. Cannot downcast (not an actor)" );
171     }
172
173     if( Dali::Actor actor = Dali::Actor::DownCast(handle) )
174     {
175       ret = actor;
176     }
177   }
178
179   return ret;
180 }
181
182 /**
183  * Creates any Handle from the TypeRegistry by name
184  */
185 Dali::Handle CreateHandle(const std::string& name)
186 {
187   Dali::Handle ret;
188
189   Dali::TypeRegistry registry = Dali::TypeRegistry::Get();
190
191   Dali::TypeInfo typeInfo = registry.GetTypeInfo( name );
192
193   if(!typeInfo)
194   {
195     EM_ASM( throw "Invalid type name" );
196   }
197   else
198   {
199     Dali::BaseHandle base = typeInfo.CreateInstance();
200     if(!base)
201     {
202       EM_ASM( throw "Cannot create instance (not a handle)" );
203     }
204     Dali::Handle handle = Dali::Handle::DownCast(base);
205
206     if(!handle)
207     {
208       EM_ASM( throw "Invalid handle. Cannot downcast" );
209     }
210
211     ret = handle;
212   }
213
214   return ret;
215 }
216
217 /**
218  * The functor to be used in the hit-test algorithm to check whether the actor is hittable.
219  */
220 bool IsActorHittableFunction(Dali::Actor actor, Dali::HitTestAlgorithm::TraverseType type)
221 {
222   const std::string& name = actor.GetName();
223   // by convention if not visible, or with a * starting the name or if the root layer
224   return actor.IsVisible() && (name.size() ? name[0] != '*' : true);
225 };
226
227 /*
228  * Hit Test wrapper
229  *
230  */
231 Dali::Actor HitTest(float x, float y)
232 {
233   Dali::HitTestAlgorithm::Results results;
234   Dali::HitTestAlgorithm::HitTest( Dali::Stage::GetCurrent(), Dali::Vector2(x,y), results, IsActorHittableFunction );
235   return results.actor;
236 }
237
238 /**
239  * Creates a solid colour actor
240  */
241 Dali::Actor CreateSolidColorActor( const Dali::Vector4& color, bool border, const Dali::Vector4& borderColor, const unsigned int borderSize )
242 {
243   static const unsigned int MAX_BORDER_SIZE( 9 );
244
245   Dali::Actor image;
246   if( borderSize > MAX_BORDER_SIZE )
247   {
248     return image;
249   }
250
251   const unsigned int bitmapWidth = borderSize * 2 + 2;
252
253   // Using a (2 + border) x (2 + border) image gives a better blend with the GL implementation
254   // than a (1 + border) x (1 + border) image
255   const unsigned int bitmapSize = bitmapWidth * bitmapWidth;
256   const unsigned int topLeft = bitmapWidth * borderSize + borderSize;
257   const unsigned int topRight = topLeft + 1;
258   const unsigned int bottomLeft = bitmapWidth * (borderSize + 1) + borderSize;
259   const unsigned int bottomRight = bottomLeft + 1;
260
261   Dali::BufferImage imageData;
262   if(color.a != 1.0 || borderColor.a != 1.0)
263   {
264     imageData = Dali::BufferImage::New( bitmapWidth, bitmapWidth, Dali::Pixel::RGBA8888 );
265
266     // Create the image
267     Dali::PixelBuffer* pixbuf = imageData.GetBuffer();
268     Dali::Vector4 outerColor = color;
269     if ( border )
270     {
271       outerColor = borderColor;
272     }
273
274     for( size_t i = 0; i < bitmapSize; ++i )
275     {
276       if( i == topLeft ||
277           i == topRight ||
278           i == bottomLeft ||
279           i == bottomRight )
280       {
281         pixbuf[i*4+0] = 0xFF * color.r;
282         pixbuf[i*4+1] = 0xFF * color.g;
283         pixbuf[i*4+2] = 0xFF * color.b;
284         pixbuf[i*4+3] = 0xFF * color.a;
285       }
286       else
287       {
288         pixbuf[i*4+0] = 0xFF * outerColor.r;
289         pixbuf[i*4+1] = 0xFF * outerColor.g;
290         pixbuf[i*4+2] = 0xFF * outerColor.b;
291         pixbuf[i*4+3] = 0xFF * outerColor.a;
292       }
293     }
294   }
295   else
296   {
297     imageData = Dali::BufferImage::New( bitmapWidth, bitmapWidth, Dali::Pixel::RGB888 );
298
299     // Create the image
300     Dali::PixelBuffer* pixbuf = imageData.GetBuffer();
301     Dali::Vector4 outerColor = color;
302     if ( border )
303     {
304       outerColor = borderColor;
305     }
306
307     for( size_t i = 0; i < bitmapSize; ++i )
308     {
309       if( i == topLeft ||
310           i == topRight ||
311           i == bottomLeft ||
312           i == bottomRight )
313       {
314         pixbuf[i*3+0] = 0xFF * color.r;
315         pixbuf[i*3+1] = 0xFF * color.g;
316         pixbuf[i*3+2] = 0xFF * color.b;
317       }
318       else
319       {
320         pixbuf[i*3+0] = 0xFF * outerColor.r;
321         pixbuf[i*3+1] = 0xFF * outerColor.g;
322         pixbuf[i*3+2] = 0xFF * outerColor.b;
323       }
324     }
325   }
326
327   imageData.Update();
328   image = Dali::Actor::New();
329   image.SetAnchorPoint( Dali::AnchorPoint::CENTER );
330   image.SetParentOrigin( Dali::ParentOrigin::CENTER );
331
332   std::string vertexShader(
333     "attribute mediump vec2 aPosition;\n"
334     "varying mediump vec2 vTexCoord;\n"
335     "uniform mediump mat4 uMvpMatrix;\n"
336     "uniform mediump vec3 uSize;\n"
337     "uniform mediump vec4 sTextureRect;\n"
338     "void main()\n"
339     "{\n"
340     "  gl_Position = uMvpMatrix * vec4(aPosition * uSize.xy, 0.0, 1.0);\n"
341     "  vTexCoord = aPosition + vec2(0.5);\n"
342     "}\n");
343
344   std::string fragmentShader(
345     "varying mediump vec2 vTexCoord;\n"
346     "uniform sampler2D sTexture;\n"
347     "uniform lowp vec4 uColor;\n"
348     "void main()\n"
349     "{\n"
350     "  gl_FragColor = texture2D( sTexture, vTexCoord )*uColor;\n"
351     "}\n");
352
353   Dali::Shader shader = Dali::Shader::New( vertexShader, fragmentShader );
354
355   // Create Quad geometry
356   Dali::Property::Map quadVertexFormat;
357   quadVertexFormat["aPosition"] = Dali::Property::VECTOR2;
358   Dali::PropertyBuffer vertexData = Dali::PropertyBuffer::New( quadVertexFormat );
359   const float halfQuadSize = .5f;
360   struct QuadVertex { Dali::Vector2 position; };
361   QuadVertex quadVertexData[4] = {
362       { Dali::Vector2(-halfQuadSize, -halfQuadSize) },
363       { Dali::Vector2(-halfQuadSize, halfQuadSize) },
364       { Dali::Vector2( halfQuadSize, -halfQuadSize) },
365       { Dali::Vector2( halfQuadSize, halfQuadSize) } };
366   vertexData.SetData(quadVertexData, 4);
367
368   Dali::Geometry quad = Dali::Geometry::New();
369   quad.AddVertexBuffer( vertexData );
370   quad.SetType( Dali::Geometry::TRIANGLE_STRIP );
371
372   Dali::Renderer renderer = Dali::Renderer::New( quad, shader );
373   Dali::TextureSet textureSet = Dali::TextureSet::New();
374   TextureSetImage( textureSet, 0u, imageData );
375   renderer.SetTextures( textureSet );
376
377   image.AddRenderer( renderer );
378
379   return image;
380 }
381
382 } // anon namespace
383
384 /**
385  * Sets the callback to getting a glyph (from dali-wrapper.js/browser)
386  */
387 void SetCallbackGetGlyphImage(const emscripten::val& callback)
388 {
389   JSGetGlyphImage = callback;
390 }
391
392 /**
393  * Sets the callback to get an image (from dali-wrapper.js/browser)
394  */
395 void SetCallbackGetImage(const emscripten::val& callback)
396 {
397   JSGetImage = callback;
398 }
399
400 /**
401  * Sets the callback to get image meta data (from dali-wrapper.js/browser)
402  */
403 void SetCallbackGetImageMetadata(const emscripten::val& callback)
404 {
405   JSGetImageMetaData = callback;
406 }
407
408 /**
409  * Sets the callback to signal render finished to dali-wrapper.js/browser
410  */
411 void SetCallbackRenderFinished(const emscripten::val& callback)
412 {
413   JSRenderFinished = callback;
414 }
415
416 /**
417  * Generates control points for a Path
418  */
419 void GenerateControlPoints(Dali::Handle& handle, float curvature)
420 {
421   if( handle )
422   {
423     Dali::Path path = Dali::Path::DownCast(handle);
424     if(path)
425     {
426       path.GenerateControlPoints(curvature);
427     }
428     else
429     {
430       EM_ASM( throw "Handle is not a path object" );
431     }
432   }
433   else
434   {
435     EM_ASM( throw "Handle is empty" );
436   }
437
438 }
439
440 /**
441  * Creating property Value Objects
442  *   javascript can't select on type so we have renamed constructors
443  *
444  * Emscripten can convert some basic types and ones we've declared as value_array(s)
445  * (These are given member access offsets/functions and are for simple structs etc)
446  *
447  * The composite types need converting.
448  */
449 Dali::Property::Value PropertyValueBoolean(bool v)
450 {
451   return Dali::Property::Value(v);
452 }
453
454 Dali::Property::Value PropertyValueFloat(float v)
455 {
456   return Dali::Property::Value(v);
457 }
458
459 Dali::Property::Value PropertyValueInteger(int v)
460 {
461   return Dali::Property::Value(v);
462 }
463
464 Dali::Property::Value PropertyValueVector2( const Dali::Vector2& v )
465 {
466   return Dali::Property::Value(v);
467 }
468
469 Dali::Property::Value PropertyValueVector3( const Dali::Vector3& v )
470 {
471   return Dali::Property::Value(v);
472 }
473
474 Dali::Property::Value PropertyValueVector4( const Dali::Vector4& v )
475 {
476   return Dali::Property::Value(v);
477 }
478
479 Dali::Property::Value PropertyValueIntRect( int a, int b, int c, int d )
480 {
481   return Dali::Property::Value(Dali::Rect<int>( a, b, c, d));
482 }
483
484 Dali::Property::Value PropertyValueMatrix( const Dali::Matrix& v )
485 {
486   return Dali::Property::Value(v);
487 }
488
489 Dali::Property::Value PropertyValueMatrix3( const Dali::Matrix3& v )
490 {
491   return Dali::Property::Value(v);
492 }
493
494 Dali::Property::Value PropertyValueEuler( const Dali::Vector3& v )
495 {
496   return Dali::Property::Value( Dali::Quaternion(
497                                   Dali::Radian(Dali::Degree(v.x)),
498                                   Dali::Radian(Dali::Degree(v.y)),
499                                   Dali::Radian(Dali::Degree(v.z)) ) );
500 }
501
502 Dali::Property::Value PropertyValueAxisAngle( const Dali::Vector4& v )
503 {
504   return Dali::Quaternion( Dali::Radian(Dali::Degree(v[3])), Dali::Vector3(v) );
505 }
506
507 Dali::Property::Value PropertyValueString( const std::string& v )
508 {
509   return Dali::Property::Value(v);
510 }
511
512 Dali::Property::Value PropertyValueContainer( const emscripten::val& v )
513 {
514   Dali::Property::Value ret;
515   RecursiveSetProperty( ret, v );
516   return ret;
517 }
518
519 /**
520  * Property value accessors from Dali Property Value
521  */
522 bool PropertyGetBoolean(const Dali::Property::Value& v)
523 {
524   return v.Get<bool>();
525 }
526
527 float PropertyGetFloat(const Dali::Property::Value& v)
528 {
529   return v.Get<float>();
530 }
531
532 int PropertyGetInteger(const Dali::Property::Value& v)
533 {
534   return v.Get<int>();
535 }
536
537 Dali::Vector2 PropertyGetVector2(const Dali::Property::Value& v)
538 {
539   return v.Get<Dali::Vector2>();
540 }
541
542 Dali::Vector3 PropertyGetVector3(const Dali::Property::Value& v)
543 {
544   return v.Get<Dali::Vector3>();
545 }
546
547 Dali::Vector4 PropertyGetVector4(const Dali::Property::Value& v)
548 {
549   return v.Get<Dali::Vector4>();
550 }
551
552 emscripten::val PropertyGetIntRect(const Dali::Property::Value& v)
553 {
554   return JavascriptValue(v);
555 }
556
557 std::string PropertyGetString(const Dali::Property::Value& v)
558 {
559   return v.Get<std::string>();
560 }
561
562 emscripten::val PropertyGetMap(const Dali::Property::Value& v)
563 {
564   return JavascriptValue(v);
565 }
566
567 emscripten::val PropertyGetArray(const Dali::Property::Value& v)
568 {
569   return JavascriptValue(v);
570 }
571
572 emscripten::val PropertyGetMatrix(const Dali::Property::Value& v)
573 {
574   return JavascriptValue(v);
575 }
576
577 emscripten::val PropertyGetMatrix3(const Dali::Property::Value& v)
578 {
579   return JavascriptValue(v);
580 }
581
582 emscripten::val PropertyGetEuler(const Dali::Property::Value& v)
583 {
584   return JavascriptValue(v);
585 }
586
587 emscripten::val PropertyGetRotation(const Dali::Property::Value& v)
588 {
589   return JavascriptValue(v);
590 }
591
592 int PropertyGetType(Dali::Property::Value& v)
593 {
594   return (int)v.GetType();
595 }
596
597 std::string PropertyGetTypeName(Dali::Property::Value& v)
598 {
599   return Dali::PropertyTypes::GetName(v.GetType());
600 }
601
602 template <typename T>
603 float MatrixGetter(T &v, int n)
604 {
605   return *(v.AsFloat() + n);
606 }
607
608 template <typename T>
609 void MatrixSetter(T &v, float f, int n)
610 {
611   *(v.AsFloat() + n) = f;
612 }
613
614 float MatrixGetter0(const Dali::Matrix &v)        { return MatrixGetter(v, 0); }
615 float MatrixGetter1(const Dali::Matrix &v)        { return MatrixGetter(v, 1); }
616 float MatrixGetter2(const Dali::Matrix &v)        { return MatrixGetter(v, 2); }
617 float MatrixGetter3(const Dali::Matrix &v)        { return MatrixGetter(v, 3); }
618 float MatrixGetter4(const Dali::Matrix &v)        { return MatrixGetter(v, 4); }
619 float MatrixGetter5(const Dali::Matrix &v)        { return MatrixGetter(v, 5); }
620 float MatrixGetter6(const Dali::Matrix &v)        { return MatrixGetter(v, 6); }
621 float MatrixGetter7(const Dali::Matrix &v)        { return MatrixGetter(v, 7); }
622 float MatrixGetter8(const Dali::Matrix &v)        { return MatrixGetter(v, 8); }
623 float MatrixGetter9(const Dali::Matrix &v)        { return MatrixGetter(v, 9); }
624 float MatrixGetter10(const Dali::Matrix &v)        { return MatrixGetter(v,10); }
625 float MatrixGetter11(const Dali::Matrix &v)        { return MatrixGetter(v,11); }
626 float MatrixGetter12(const Dali::Matrix &v)        { return MatrixGetter(v,12); }
627 float MatrixGetter13(const Dali::Matrix &v)        { return MatrixGetter(v,13); }
628 float MatrixGetter14(const Dali::Matrix &v)        { return MatrixGetter(v,14); }
629 float MatrixGetter15(const Dali::Matrix &v)        { return MatrixGetter(v,15); }
630 float MatrixGetter16(const Dali::Matrix &v)        { return MatrixGetter(v,16); }
631
632 void MatrixSetter0(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 0); }
633 void MatrixSetter1(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 1); }
634 void MatrixSetter2(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 2); }
635 void MatrixSetter3(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 3); }
636 void MatrixSetter4(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 4); }
637 void MatrixSetter5(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 5); }
638 void MatrixSetter6(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 6); }
639 void MatrixSetter7(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 7); }
640 void MatrixSetter8(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 8); }
641 void MatrixSetter9(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 9); }
642 void MatrixSetter10(Dali::Matrix &v, float f)      { MatrixSetter(v, f,10); }
643 void MatrixSetter11(Dali::Matrix &v, float f)      { MatrixSetter(v, f,11); }
644 void MatrixSetter12(Dali::Matrix &v, float f)      { MatrixSetter(v, f,12); }
645 void MatrixSetter13(Dali::Matrix &v, float f)      { MatrixSetter(v, f,13); }
646 void MatrixSetter14(Dali::Matrix &v, float f)      { MatrixSetter(v, f,14); }
647 void MatrixSetter15(Dali::Matrix &v, float f)      { MatrixSetter(v, f,15); }
648 void MatrixSetter16(Dali::Matrix &v, float f)      { MatrixSetter(v, f,16); }
649
650 float Matrix3Getter0(const Dali::Matrix3 &v)        { return MatrixGetter(v, 0); }
651 float Matrix3Getter1(const Dali::Matrix3 &v)        { return MatrixGetter(v, 1); }
652 float Matrix3Getter2(const Dali::Matrix3 &v)        { return MatrixGetter(v, 2); }
653 float Matrix3Getter3(const Dali::Matrix3 &v)        { return MatrixGetter(v, 3); }
654 float Matrix3Getter4(const Dali::Matrix3 &v)        { return MatrixGetter(v, 4); }
655 float Matrix3Getter5(const Dali::Matrix3 &v)        { return MatrixGetter(v, 5); }
656 float Matrix3Getter6(const Dali::Matrix3 &v)        { return MatrixGetter(v, 6); }
657 float Matrix3Getter7(const Dali::Matrix3 &v)        { return MatrixGetter(v, 7); }
658 float Matrix3Getter8(const Dali::Matrix3 &v)        { return MatrixGetter(v, 8); }
659
660 void Matrix3Setter0(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 0); }
661 void Matrix3Setter1(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 1); }
662 void Matrix3Setter2(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 2); }
663 void Matrix3Setter3(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 3); }
664 void Matrix3Setter4(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 4); }
665 void Matrix3Setter5(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 5); }
666 void Matrix3Setter6(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 6); }
667 void Matrix3Setter7(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 7); }
668 void Matrix3Setter8(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 8); }
669
670 val JavascriptUpdateCallback( val::undefined() );
671 bool JavascriptUpdateCallbackSet = false;
672
673 void JavascriptUpdate(int dt)
674 {
675   if( JavascriptUpdateCallbackSet )
676   {
677     JavascriptUpdateCallback( val(dt) );
678   }
679 }
680
681 void SetUpdateFunction( const emscripten::val& function )
682 {
683   JavascriptUpdateCallback = function;
684   JavascriptUpdateCallbackSet = true;
685 }
686
687 const emscripten::val& GetUpdateFunction()
688 {
689   return JavascriptUpdateCallback;
690 }
691
692 /**
693  * Emscripten Bindings
694  *
695  * This uses Emscripten 'bind' (similar in design to Boost's python wrapper library).
696  * It provides a simplified way to wrap C++ classes and wraps Emscriptens type
697  * registration API.
698  *
699  * A convention below is that where there is a function or method name prepended
700  * with '__' there is a corresponding Javascript helper function to help with
701  * marshalling parameters and return values.
702  *
703  */
704 EMSCRIPTEN_BINDINGS(dali_wrapper)
705 {
706   // With a little help embind knows about vectors so we tell it which ones to instantiate
707   register_dali_vector<int>("DaliVectorInt");
708   register_vector<std::string>("VectorString");
709   register_vector<int>("VectorInt");
710   register_vector<float>("VectorFloat");
711   register_vector<Dali::Actor>("VectorActor");
712
713   //
714   // Creation functions.
715   //
716   emscripten::function("VersionString", &VersionString);
717   emscripten::function("__createActor", &CreateActor);
718   emscripten::function("__createHandle", &CreateHandle);
719   emscripten::function("__createSolidColorActor", &CreateSolidColorActor);
720
721   //
722   // Helper functions
723   //
724   emscripten::function("javascriptValue", &JavascriptValue);
725   emscripten::function("__hitTest", &HitTest);
726   emscripten::function("sendMouseEvent", &EmscriptenMouseEvent);
727   emscripten::function("__updateOnce", &EmscriptenUpdateOnce);
728   emscripten::function("__renderOnce", &EmscriptenRenderOnce);
729   emscripten::function("generateControlPoints", &GenerateControlPoints);
730
731   //
732   // Global callback functions
733   //
734   emscripten::function("setCallbackGetGlyphImage", &SetCallbackGetGlyphImage);
735   emscripten::function("setCallbackGetImage", &SetCallbackGetImage);
736   emscripten::function("setCallbackGetImageMetadata", &SetCallbackGetImageMetadata);
737   emscripten::function("setCallbackRenderFinished", &SetCallbackRenderFinished);
738   emscripten::function("setUpdateFunction", &SetUpdateFunction);
739   emscripten::function("getUpdateFunction", &GetUpdateFunction);
740
741   //
742   // Property value creation (Javascript can't select on type)
743   //
744   emscripten::function("PropertyValueBoolean", &PropertyValueBoolean);
745   emscripten::function("PropertyValueFloat", &PropertyValueFloat);
746   emscripten::function("PropertyValueInteger", &PropertyValueInteger);
747   emscripten::function("PropertyValueString", &PropertyValueString);
748   emscripten::function("PropertyValueVector2", &PropertyValueVector2);
749   emscripten::function("PropertyValueVector3", &PropertyValueVector3);
750   emscripten::function("PropertyValueVector4", &PropertyValueVector4);
751   emscripten::function("PropertyValueMatrix", &PropertyValueMatrix);
752   emscripten::function("PropertyValueMatrix3", &PropertyValueMatrix3);
753   emscripten::function("PropertyValueMap", &PropertyValueContainer);
754   emscripten::function("PropertyValueArray", &PropertyValueContainer);
755   emscripten::function("PropertyValueEuler", &PropertyValueEuler);
756   emscripten::function("PropertyValueAxisAngle", &PropertyValueAxisAngle);
757   emscripten::function("PropertyValueString", &PropertyValueString);
758   emscripten::function("PropertyValueIntRect", &PropertyValueIntRect);
759
760   //
761   // One unfortunate aspect of wrapping for the browser is that we get no notification
762   // of object deletion so all JS wrapper objects must be wrapper.delete() correctly.
763   //
764   // Embind has a mechanism around this for simple c style structs decared as value_arrays.
765   // These are immediately transformed to Javascript arrays and don't need explicit
766   // destruction, however the API needs a member offset.
767   //
768   value_array<Dali::Internal::Emscripten::Statistics>("Statistics")
769     .element(&Dali::Internal::Emscripten::Statistics::on)
770     .element(&Dali::Internal::Emscripten::Statistics::frameCount)
771     .element(&Dali::Internal::Emscripten::Statistics::lastFrameDeltaSeconds)
772     .element(&Dali::Internal::Emscripten::Statistics::lastSyncTimeMilliseconds)
773     .element(&Dali::Internal::Emscripten::Statistics::nextSyncTimeMilliseconds)
774     .element(&Dali::Internal::Emscripten::Statistics::keepUpdating)
775     .element(&Dali::Internal::Emscripten::Statistics::needsNotification)
776     .element(&Dali::Internal::Emscripten::Statistics::secondsFromLastFrame)
777 ;
778
779   value_array<Dali::Vector2>("Vector2")
780     .element(&Dali::Vector2::x)
781     .element(&Dali::Vector2::y)
782 ;
783
784   value_array<Dali::Vector3>("Vector3")
785     .element(&Dali::Vector3::x)
786     .element(&Dali::Vector3::y)
787     .element(&Dali::Vector3::z)
788 ;
789
790   value_array<Dali::Vector4>("Vector4")
791     .element(&Dali::Vector4::x)
792     .element(&Dali::Vector4::y)
793     .element(&Dali::Vector4::z)
794     .element(&Dali::Vector4::w)
795 ;
796
797   value_array<Dali::Matrix>("Matrix")
798     .element(&MatrixGetter0, &MatrixSetter0)
799     .element(&MatrixGetter1, &MatrixSetter1)
800     .element(&MatrixGetter2, &MatrixSetter2)
801     .element(&MatrixGetter3, &MatrixSetter3)
802     .element(&MatrixGetter4, &MatrixSetter4)
803     .element(&MatrixGetter5, &MatrixSetter5)
804     .element(&MatrixGetter6, &MatrixSetter6)
805     .element(&MatrixGetter7, &MatrixSetter7)
806     .element(&MatrixGetter8, &MatrixSetter8)
807     .element(&MatrixGetter9, &MatrixSetter9)
808     .element(&MatrixGetter10, &MatrixSetter10)
809     .element(&MatrixGetter11, &MatrixSetter11)
810     .element(&MatrixGetter12, &MatrixSetter12)
811     .element(&MatrixGetter13, &MatrixSetter13)
812     .element(&MatrixGetter14, &MatrixSetter14)
813     .element(&MatrixGetter15, &MatrixSetter15)
814 ;
815
816   value_array<Dali::Matrix3>("Matrix3")
817     .element(&Matrix3Getter0, &Matrix3Setter0)
818     .element(&Matrix3Getter1, &Matrix3Setter1)
819     .element(&Matrix3Getter2, &Matrix3Setter2)
820     .element(&Matrix3Getter3, &Matrix3Setter3)
821     .element(&Matrix3Getter4, &Matrix3Setter4)
822     .element(&Matrix3Getter5, &Matrix3Setter5)
823     .element(&Matrix3Getter6, &Matrix3Setter6)
824     .element(&Matrix3Getter7, &Matrix3Setter7)
825     .element(&Matrix3Getter8, &Matrix3Setter8)
826 ;
827
828   //
829   // enums
830   //
831   enum_<Dali::Property::Type>("PropertyType")
832     .value("NONE", Dali::Property::NONE)
833     .value("BOOLEAN", Dali::Property::BOOLEAN)
834     .value("FLOAT", Dali::Property::FLOAT)
835     .value("INTEGER", Dali::Property::INTEGER)
836     .value("VECTOR2", Dali::Property::VECTOR2)
837     .value("VECTOR3", Dali::Property::VECTOR3)
838     .value("VECTOR4", Dali::Property::VECTOR4)
839     .value("MATRIX3", Dali::Property::MATRIX3)
840     .value("MATRIX", Dali::Property::MATRIX)
841     .value("RECTANGLE", Dali::Property::RECTANGLE)
842     .value("ROTATION", Dali::Property::ROTATION)
843     .value("STRING", Dali::Property::STRING)
844     .value("ARRAY", Dali::Property::ARRAY)
845     .value("MAP", Dali::Property::MAP)
846 ;
847
848   enum_<Dali::ShaderEffect::GeometryHints>("GeometryHints")
849     .value("HINT_NONE", Dali::ShaderEffect::HINT_NONE)
850     .value("HINT_GRID_X", Dali::ShaderEffect::HINT_GRID_X)
851     .value("HINT_GRID_Y", Dali::ShaderEffect::HINT_GRID_Y)
852     .value("HINT_GRID", Dali::ShaderEffect::HINT_GRID)
853     .value("HINT_DEPTH_BUFFER", Dali::ShaderEffect::HINT_DEPTH_BUFFER)
854     .value("HINT_BLENDING", Dali::ShaderEffect::HINT_BLENDING)
855     .value("HINT_DOESNT_MODIFY_GEOMETRY", Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY)
856 ;
857
858   enum_<Dali::Shader::Hint::Value>("ShaderHints")
859     .value("NONE",                      Dali::Shader::Hint::NONE)
860     .value("OUTPUT_IS_TRANSPARENT",     Dali::Shader::Hint::OUTPUT_IS_TRANSPARENT)
861     .value("MODIFIES_GEOMETRY",         Dali::Shader::Hint::MODIFIES_GEOMETRY)
862 ;
863
864   enum_<Dali::Animation::EndAction>("EndAction")
865     .value("Bake",        Dali::Animation::Bake)
866     .value("Discard",     Dali::Animation::Discard)
867     .value("BakeFinal",   Dali::Animation::BakeFinal)
868 ;
869
870   enum_<Dali::Animation::Interpolation>("Interpolation")
871     .value("Linear", Dali::Animation::Interpolation::Linear)
872     .value("Cubic", Dali::Animation::Interpolation::Cubic)
873 ;
874
875   enum_<Dali::Geometry::Type>("Type")
876     .value("POINTS",          Dali::Geometry::POINTS)
877     .value("LINES",           Dali::Geometry::LINES)
878     .value("LINE_LOOP",       Dali::Geometry::LINE_LOOP)
879     .value("LINE_STRIP",      Dali::Geometry::LINE_STRIP)
880     .value("TRIANGLES",       Dali::Geometry::TRIANGLES)
881     .value("TRIANGLE_FAN",    Dali::Geometry::TRIANGLE_FAN)
882     .value("TRIANGLE_STRIP",  Dali::Geometry::TRIANGLE_STRIP)
883 ;
884
885   enum_<Dali::Pixel::Format>("PixelFormat")
886     .value("A8", Dali::Pixel::Format::A8)
887     .value("L8", Dali::Pixel::Format::L8)
888     .value("LA88", Dali::Pixel::Format::LA88)
889     .value("RGB565", Dali::Pixel::Format::RGB565)
890     .value("BGR565", Dali::Pixel::Format::BGR565)
891     .value("RGBA4444", Dali::Pixel::Format::RGBA4444)
892     .value("BGRA4444", Dali::Pixel::Format::BGRA4444)
893     .value("RGBA5551", Dali::Pixel::Format::RGBA5551)
894     .value("BGRA5551", Dali::Pixel::Format::BGRA5551)
895     .value("RGB888", Dali::Pixel::Format::RGB888)
896     .value("RGB8888", Dali::Pixel::Format::RGB8888)
897     .value("BGR8888", Dali::Pixel::Format::BGR8888)
898     .value("RGBA8888", Dali::Pixel::Format::RGBA8888)
899     .value("BGRA8888", Dali::Pixel::Format::BGRA8888)
900     // GLES 3 Standard compressed formats:
901     .value("COMPRESSED_R11_EAC", Dali::Pixel::Format::COMPRESSED_R11_EAC)
902     .value("COMPRESSED_SIGNED_R11_EAC", Dali::Pixel::Format::COMPRESSED_SIGNED_R11_EAC)
903     .value("COMPRESSED_RG11_EAC", Dali::Pixel::Format::COMPRESSED_RG11_EAC)
904     .value("COMPRESSED_SIGNED_RG11_EAC", Dali::Pixel::Format::COMPRESSED_SIGNED_RG11_EAC)
905     .value("COMPRESSED_RGB8_ETC2", Dali::Pixel::Format::COMPRESSED_RGB8_ETC2)
906     .value("COMPRESSED_SRGB8_ETC2", Dali::Pixel::Format::COMPRESSED_SRGB8_ETC2)
907     .value("COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", Dali::Pixel::Format::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2)
908     .value("COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", Dali::Pixel::Format::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2)
909     .value("COMPRESSED_RGBA8_ETC2_EAC", Dali::Pixel::Format::COMPRESSED_RGBA8_ETC2_EAC)
910     .value("COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", Dali::Pixel::Format::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC)
911     // GLES 2 extension compressed formats:
912     .value("COMPRESSED_RGB8_ETC1", Dali::Pixel::Format::COMPRESSED_RGB8_ETC1)
913     .value("COMPRESSED_RGB_PVRTC_4BPPV1", Dali::Pixel::Format::COMPRESSED_RGB_PVRTC_4BPPV1)
914 ;
915
916   enum_<Dali::FaceCullingMode::Type>("FaceCullingMode")
917     .value("NONE", Dali::FaceCullingMode::NONE)
918     .value("FRONT", Dali::FaceCullingMode::FRONT)
919     .value("BACK", Dali::FaceCullingMode::BACK)
920     .value("FRONT_AND_BACK", Dali::FaceCullingMode::FRONT_AND_BACK)
921 ;
922
923   enum_<Dali::DepthWriteMode::Type>("DepthWriteMode")
924     .value("OFF", Dali::DepthWriteMode::OFF)
925     .value("AUTO", Dali::DepthWriteMode::AUTO)
926     .value("ON", Dali::DepthWriteMode::ON)
927 ;
928
929   enum_<Dali::BlendMode::Type>("BlendMode")
930     .value("OFF", Dali::BlendMode::OFF)
931     .value("AUTO", Dali::BlendMode::AUTO)
932     .value("ON", Dali::BlendMode::ON)
933 ;
934
935   enum_<Dali::AlphaFunction::BuiltinFunction>("AlphaFunction")
936     .value("DEFAULT", Dali::AlphaFunction::BuiltinFunction::DEFAULT)
937     .value("LINEAR", Dali::AlphaFunction::BuiltinFunction::LINEAR)
938     .value("REVERSE", Dali::AlphaFunction::BuiltinFunction::REVERSE)
939     .value("EASE_IN_SQUARE", Dali::AlphaFunction::BuiltinFunction::EASE_IN_SQUARE)
940     .value("EASE_OUT_SQUARE", Dali::AlphaFunction::BuiltinFunction::EASE_OUT_SQUARE)
941     .value("EASE_IN", Dali::AlphaFunction::BuiltinFunction::EASE_IN)
942     .value("EASE_OUT", Dali::AlphaFunction::BuiltinFunction::EASE_OUT)
943     .value("EASE_IN_OUT", Dali::AlphaFunction::BuiltinFunction::EASE_IN_OUT)
944     .value("EASE_IN_SINE", Dali::AlphaFunction::BuiltinFunction::EASE_IN_SINE)
945     .value("EASE_OUT_SINE", Dali::AlphaFunction::BuiltinFunction::EASE_OUT_SINE)
946     .value("EASE_IN_OUT_SINE", Dali::AlphaFunction::BuiltinFunction::EASE_IN_OUT_SINE)
947     .value("BOUNCE", Dali::AlphaFunction::BuiltinFunction::BOUNCE)
948     .value("SIN", Dali::AlphaFunction::BuiltinFunction::SIN)
949     .value("EASE_OUT_BACK", Dali::AlphaFunction::BuiltinFunction::EASE_OUT_BACK)
950 ;
951
952   //
953   // classes
954   //
955
956   // we need property map as an object rather than straight conversion to javascript 'object'
957   // because its ordered. And PropertyBuffer needs an order.
958   class_<Dali::Property::Map>("PropertyMap")
959     .constructor<>()
960     .function("count", &Dali::Property::Map::Count)
961     .function("empty", &Dali::Property::Map::Empty)
962     .function("__insert", select_overload< void(const std::string&, const Dali::Property::Value&) > (&Dali::Property::Map::Insert))
963     .function("__get", &PropertyMapGet)
964     .function("__getValue", &Dali::Property::Map::GetValue)
965     .function("getKey", &Dali::Property::Map::GetKey)
966     .function("clear", &Dali::Property::Map::Clear)
967     .function("merge", &Dali::Property::Map::Merge)
968 ;
969
970   class_<Dali::Property::Value>("PropertyValue")
971     .constructor<>()
972     .function("getType", &PropertyGetType)
973     .function("getTypeName", &PropertyGetTypeName)
974     .function("getBoolean", &PropertyGetBoolean)
975     .function("getFloat", &PropertyGetFloat)
976     .function("getInteger", &PropertyGetInteger)
977     .function("getVector2", &PropertyGetVector2)
978     .function("getVector3", &PropertyGetVector3)
979     .function("getVector4", &PropertyGetVector4)
980     .function("getString", &PropertyGetString)
981     .function("getMap", &PropertyGetMap)
982     .function("getArray", &PropertyGetArray)
983     .function("getMatrix", &PropertyGetMatrix)
984     .function("getMatrix3", &PropertyGetMatrix3)
985     .function("getEuler", &PropertyGetEuler)
986     .function("getRotation", &PropertyGetRotation)
987     .function("getIntRect", &PropertyGetIntRect)
988 ;
989
990   class_<Dali::BaseHandle>("BaseHandle")
991     .function("ok", &BaseHandleOk)
992     .function("getTypeName", &BaseHandle::GetTypeName)
993 ;
994
995   class_<Dali::TypeInfo, base<Dali::BaseHandle>>("TypeInfo")
996     .function("getName", &Dali::TypeInfo::GetName)
997     .function("getBaseName", &Dali::TypeInfo::GetBaseName)
998     .function("getProperties", &GetAllProperties)
999     .function("getActions", &GetActions)
1000     .function("getSignals", &GetSignals)
1001     .function("getPropertyIndices", &Dali::TypeInfo::GetPropertyIndices)
1002 ;
1003
1004   class_<Dali::TypeRegistry>("TypeRegistry")
1005     .constructor<>(&Dali::TypeRegistry::Get)
1006     .function("getTypeNameCount", &Dali::TypeRegistry::GetTypeNameCount)
1007     .function("getTypeName", &Dali::TypeRegistry::GetTypeName)
1008     .function("getTypeInfo", select_overload< Dali::TypeInfo(const std::string&) > (&Dali::TypeRegistry::GetTypeInfo))
1009 ;
1010
1011   class_<SignalHolder>("SignalHolder")
1012     .constructor<>()
1013 ;
1014
1015   class_<Dali::Handle, base<Dali::BaseHandle>>("Handle")
1016     .function("__registerProperty", &RegisterProperty)
1017     .function("__registerAnimatedProperty", &RegisterAnimatedProperty)
1018     .function("setSelf", &SetSelf)
1019     .function("setProperty", &SetProperty)
1020     .function("getProperty", &GetProperty)
1021     .function("getPropertyIndex", &GetPropertyIndex)
1022     .function("getProperties", &GetProperties)
1023     .function("getPropertyIndices", &Handle::GetPropertyIndices)
1024     .function("getPropertyTypeFromName", &GetPropertyTypeFromName)
1025     .function("getPropertyTypeName", &GetPropertyTypeName)
1026     .function("registerProperty", &RegisterProperty)
1027     .function("registerAnimatedProperty", &RegisterAnimatedProperty)
1028     .function("getTypeInfo", &GetTypeInfo)
1029     .function("isPropertyWritable", &Handle::IsPropertyWritable)
1030     .function("isPropertyAnimatable", &Handle::IsPropertyAnimatable)
1031     .function("isPropertyAConstraintInput", &Handle::IsPropertyAConstraintInput)
1032 ;
1033
1034   class_<Dali::Path, base<Dali::Handle>>("Path")
1035     .constructor<>(&Dali::Path::New)
1036     .function("addPoint", &Dali::Path::AddPoint)
1037     .function("addControlPoint", &Dali::Path::AddControlPoint)
1038     .function("generateControlPoints", &Dali::Path::GenerateControlPoints)
1039     .function("sample", &Dali::Path::Sample)
1040     .function("getPoint", &Dali::Path::GetPoint)
1041     .function("getControlPoint", &Dali::Path::GetControlPoint)
1042     .function("getPointCount", &Dali::Path::GetPointCount)
1043 ;
1044
1045   class_<Dali::KeyFrames>("KeyFrames")
1046     .constructor<>(&Dali::KeyFrames::New)
1047     .function("add", select_overload<void (float progress, Property::Value value)>(&Dali::KeyFrames::Add))
1048     .function("addWithAlpha", &KeyFramesAddWithAlpha)
1049 ;
1050
1051   class_<Dali::Animation>("Animation")
1052     .constructor<float>(&Dali::Animation::New)
1053     .function("__animateTo", &AnimateTo)
1054     .function("__animateBy", &AnimateBy)
1055     .function("__animateBetween", &AnimateBetween)
1056     .function("__animatePath", &AnimatePath)
1057     .function("setDuration", &Dali::Animation::SetDuration)
1058     .function("getDuration", &Dali::Animation::GetDuration)
1059     .function("setLooping", &Dali::Animation::SetLooping)
1060     .function("isLooping", &Dali::Animation::IsLooping)
1061     .function("setEndAction", &Dali::Animation::SetEndAction)
1062     .function("getEndAction", &Dali::Animation::GetEndAction)
1063     .function("setDisconnectAction", &Dali::Animation::SetDisconnectAction)
1064     .function("getDisconnectAction", &Dali::Animation::GetDisconnectAction)
1065     .function("setCurrentProgress", &Dali::Animation::SetCurrentProgress)
1066     .function("getCurrentProgress", &Dali::Animation::GetCurrentProgress)
1067     .function("setSpeedFactor", &Dali::Animation::SetSpeedFactor)
1068     .function("getSpeedFactor", &Dali::Animation::GetSpeedFactor)
1069     .function("setPlayRange", &Dali::Animation::SetPlayRange)
1070     .function("getPlayRange", &Dali::Animation::GetPlayRange)
1071     .function("play", &Dali::Animation::Play)
1072     .function("playFrom", &Dali::Animation::PlayFrom)
1073     .function("pause", &Dali::Animation::Pause)
1074     .function("stop", &Dali::Animation::Stop)
1075     .function("clear", &Dali::Animation::Clear)
1076 ;
1077
1078   class_<Dali::PropertyBuffer>("PropertyBuffer")
1079     .constructor<Dali::Property::Map&>(Dali::PropertyBuffer::New)
1080     .function("setData", &SetPropertyBufferDataRaw)
1081 ;
1082
1083   class_<Dali::Geometry>("Geometry")
1084     .constructor<>(&Dali::Geometry::New)
1085     .function("addVertexBuffer", &Dali::Geometry::AddVertexBuffer)
1086     .function("getNumberOfVertexBuffers", &Dali::Geometry::GetNumberOfVertexBuffers)
1087     .function("setIndexBuffer", &SetIndexBufferDataRaw)
1088     .function("setType", &Dali::Geometry::SetType)
1089     .function("getType", &Dali::Geometry::GetType)
1090 ;
1091
1092   class_<Dali::Image>("Image")
1093 ;
1094
1095   class_<Dali::BufferImage, base<Dali::Image> >("BufferImage")
1096     .constructor<const std::string&, unsigned int, unsigned int, Dali::Pixel::Format>(&BufferImageNew)
1097 ;
1098
1099   class_<Dali::EncodedBufferImage, base<Dali::Image> >("EncodedBufferImage")
1100     .constructor<const std::string&>(&EncodedBufferImageNew)
1101 ;
1102
1103   class_<Dali::Sampler>("Sampler")
1104     .constructor<>(&Dali::Sampler::New)
1105 ;
1106
1107   class_<Dali::Shader, base<Dali::Handle>>("Shader")
1108     .constructor<>(&Dali::Shader::New)
1109 ;
1110
1111   class_<Dali::TextureSet>("TextureSet")
1112     .constructor<>(&Dali::TextureSet::New)
1113     .function("setTexture", &Dali::TextureSet::SetTexture)
1114     .function("setSampler", &Dali::TextureSet::SetSampler)
1115     .function("getTexture", &Dali::TextureSet::GetTexture)
1116     .function("getSampler", &Dali::TextureSet::GetSampler)
1117     .function("getTextureCount", &Dali::TextureSet::GetTextureCount)
1118 ;
1119
1120   class_<Dali::Renderer, base<Dali::Handle>>("Renderer")
1121     .constructor<>(&Dali::Renderer::New)
1122     .function("setGeometry", &Dali::Renderer::SetGeometry)
1123     .function("getGeometry", &Dali::Renderer::GetGeometry)
1124     .function("SetTextures", &Dali::Renderer::SetTextures)
1125     .function("SetTextures", &Dali::Renderer::SetTextures)
1126 ;
1127
1128   class_<Dali::ShaderEffect, base<Dali::Handle>>("ShaderEffect")
1129     .constructor<const std::string&, const std::string&,
1130                  const std::string&, const std::string&,
1131                  int >(&CreateShaderEffect)
1132     .function("setEffectImage", &Dali::ShaderEffect::SetEffectImage)
1133     .function("__setUniform", &SetUniform)
1134 ;
1135
1136   class_<Dali::Actor, base<Dali::Handle>>("Actor")
1137     .constructor<>(&Dali::Actor::New)
1138     .function("add", &Dali::Actor::Add)
1139     .function("remove", &Dali::Actor::Remove)
1140     .function("getId", &Dali::Actor::GetId)
1141     .function("__getParent", &Dali::Actor::GetParent)
1142     .function("__findChildById", &Dali::Actor::FindChildById)
1143     .function("__findChildByName", &Dali::Actor::FindChildByName)
1144     .function("__getChildAt", &Dali::Actor::GetChildAt)
1145     .function("getChildCount", &Dali::Actor::GetChildCount)
1146     .function("__screenToLocal",
1147               select_overload<std::vector<float> (Dali::Actor, float, float)>(&ScreenToLocal))
1148     .function("addressOf", &AddressOf)
1149     .function("__connect", &ConnectSignal)
1150     .function("__setPropertyNotification", &SetPropertyNotification)
1151     .function("addRenderer", &Dali::Actor::AddRenderer)
1152     .function("getRendererCount", &Dali::Actor::GetRendererCount)
1153     .function("removeRenderer",
1154               select_overload<void(unsigned int)>(&Dali::Actor::RemoveRenderer))
1155     .function("__getRendererAt", &Dali::Actor::GetRendererAt)
1156 ;
1157
1158   class_<Dali::CameraActor, base<Dali::Actor>>("CameraActor")
1159     .constructor<>( select_overload<Dali::CameraActor()>(&Dali::CameraActor::New))
1160 ;
1161
1162   class_<Dali::Layer, base<Dali::Actor>>("Layer")
1163     .constructor<>(&Dali::Layer::New)
1164     .function("raise", &Dali::Layer::Raise)
1165     .function("lower", &Dali::Layer::Lower)
1166 ;
1167
1168   class_<Dali::Stage>("Stage")
1169     .constructor<>(&Dali::Stage::GetCurrent)
1170     .function("add", &Dali::Stage::Add)
1171     .function("remove", &Dali::Stage::Remove)
1172     .function("__getRootLayer", &Dali::Stage::GetRootLayer)
1173     .function("getLayer", &Dali::Stage::GetLayer)
1174     .function("getRenderTaskList", &Dali::Stage::GetRenderTaskList)
1175     .function("setBackgroundColor", &Dali::Stage::SetBackgroundColor)
1176 ;
1177
1178   class_<Dali::RenderTaskList>("RenderTaskList")
1179     .function("createTask", &Dali::RenderTaskList::CreateTask)
1180     .function("removeTask", &Dali::RenderTaskList::RemoveTask)
1181     .function("getTaskCount", &Dali::RenderTaskList::GetTaskCount)
1182     .function("getTask", &Dali::RenderTaskList::GetTask)
1183 ;
1184
1185   class_<Dali::RenderTask>("RenderTask")
1186     .function("__getCameraActor", &Dali::RenderTask::GetCameraActor)
1187     .function("setCameraActor", &Dali::RenderTask::SetCameraActor)
1188     .function("setSourceActor", &Dali::RenderTask::SetSourceActor)
1189     .function("setExclusive", &Dali::RenderTask::SetExclusive)
1190     .function("setInputEnabled", &Dali::RenderTask::SetInputEnabled)
1191     .function("setViewportPosition", &Dali::RenderTask::SetViewportPosition)
1192     .function("setViewportSize", &Dali::RenderTask::SetViewportSize)
1193     .function("getCurrentViewportPosition", &Dali::RenderTask::GetCurrentViewportPosition)
1194     .function("getCurrentViewportSize", &Dali::RenderTask::GetCurrentViewportSize)
1195     .function("setClearColor", &Dali::RenderTask::SetClearColor)
1196     .function("getClearColor", &Dali::RenderTask::GetClearColor)
1197     .function("setClearEnabled", &Dali::RenderTask::SetClearEnabled)
1198     .function("getClearEnabled", &Dali::RenderTask::GetClearEnabled)
1199     .function("screenToLocal",
1200               select_overload<Dali::Vector2(Dali::RenderTask, Dali::Actor, float, float)>(&ScreenToLocal))
1201     .function("worldToScreen", &WorldToScreen)
1202 ;
1203
1204 }
1205
1206 }; // namespace Emscripten
1207 }; // namespace Internal
1208 }; // namespace Dali