Merge branch 'devel/master' into tizen
[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
22 #include <dali/devel-api/scripting/scripting.h>
23 #include <dali/devel-api/events/hit-test-algorithm.h>
24 #include <dali/devel-api/rendering/geometry.h>
25 #include <dali/devel-api/rendering/shader.h>
26 #include <dali/devel-api/rendering/sampler.h>
27 #include <dali/devel-api/rendering/texture-set.h>
28 #include <dali/devel-api/rendering/renderer.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   Dali::Geometry geometry = Dali::Geometry::QUAD();
355   Dali::Renderer renderer = Dali::Renderer::New( geometry, shader );
356   Dali::TextureSet textureSet = Dali::TextureSet::New();
357   textureSet.SetImage( 0u, imageData );
358   renderer.SetTextures( textureSet );
359
360   image.AddRenderer( renderer );
361
362   return image;
363 }
364
365 } // anon namespace
366
367 /**
368  * Sets the callback to getting a glyph (from dali-wrapper.js/browser)
369  */
370 void SetCallbackGetGlyphImage(const emscripten::val& callback)
371 {
372   JSGetGlyphImage = callback;
373 }
374
375 /**
376  * Sets the callback to get an image (from dali-wrapper.js/browser)
377  */
378 void SetCallbackGetImage(const emscripten::val& callback)
379 {
380   JSGetImage = callback;
381 }
382
383 /**
384  * Sets the callback to get image meta data (from dali-wrapper.js/browser)
385  */
386 void SetCallbackGetImageMetadata(const emscripten::val& callback)
387 {
388   JSGetImageMetaData = callback;
389 }
390
391 /**
392  * Sets the callback to signal render finished to dali-wrapper.js/browser
393  */
394 void SetCallbackRenderFinished(const emscripten::val& callback)
395 {
396   JSRenderFinished = callback;
397 }
398
399 /**
400  * Generates control points for a Path
401  */
402 void GenerateControlPoints(Dali::Handle& handle, float curvature)
403 {
404   if( handle )
405   {
406     Dali::Path path = Dali::Path::DownCast(handle);
407     if(path)
408     {
409       path.GenerateControlPoints(curvature);
410     }
411     else
412     {
413       EM_ASM( throw "Handle is not a path object" );
414     }
415   }
416   else
417   {
418     EM_ASM( throw "Handle is empty" );
419   }
420
421 }
422
423 /**
424  * Creating property Value Objects
425  *   javascript can't select on type so we have renamed constructors
426  *
427  * Emscripten can convert some basic types and ones we've declared as value_array(s)
428  * (These are given member access offsets/functions and are for simple structs etc)
429  *
430  * The composite types need converting.
431  */
432 Dali::Property::Value PropertyValueBoolean(bool v)
433 {
434   return Dali::Property::Value(v);
435 }
436
437 Dali::Property::Value PropertyValueFloat(float v)
438 {
439   return Dali::Property::Value(v);
440 }
441
442 Dali::Property::Value PropertyValueInteger(int v)
443 {
444   return Dali::Property::Value(v);
445 }
446
447 Dali::Property::Value PropertyValueVector2( const Dali::Vector2& v )
448 {
449   return Dali::Property::Value(v);
450 }
451
452 Dali::Property::Value PropertyValueVector3( const Dali::Vector3& v )
453 {
454   return Dali::Property::Value(v);
455 }
456
457 Dali::Property::Value PropertyValueVector4( const Dali::Vector4& v )
458 {
459   return Dali::Property::Value(v);
460 }
461
462 Dali::Property::Value PropertyValueIntRect( int a, int b, int c, int d )
463 {
464   return Dali::Property::Value(Dali::Rect<int>( a, b, c, d));
465 }
466
467 Dali::Property::Value PropertyValueMatrix( const Dali::Matrix& v )
468 {
469   return Dali::Property::Value(v);
470 }
471
472 Dali::Property::Value PropertyValueMatrix3( const Dali::Matrix3& v )
473 {
474   return Dali::Property::Value(v);
475 }
476
477 Dali::Property::Value PropertyValueEuler( const Dali::Vector3& v )
478 {
479   return Dali::Property::Value( Dali::Quaternion(
480                                   Dali::Radian(Dali::Degree(v.x)),
481                                   Dali::Radian(Dali::Degree(v.y)),
482                                   Dali::Radian(Dali::Degree(v.z)) ) );
483 }
484
485 Dali::Property::Value PropertyValueAxisAngle( const Dali::Vector4& v )
486 {
487   return Dali::Quaternion( Dali::Radian(Dali::Degree(v[3])), Dali::Vector3(v) );
488 }
489
490 Dali::Property::Value PropertyValueString( const std::string& v )
491 {
492   return Dali::Property::Value(v);
493 }
494
495 Dali::Property::Value PropertyValueContainer( const emscripten::val& v )
496 {
497   Dali::Property::Value ret;
498   RecursiveSetProperty( ret, v );
499   return ret;
500 }
501
502 /**
503  * Property value accessors from Dali Property Value
504  */
505 bool PropertyGetBoolean(const Dali::Property::Value& v)
506 {
507   return v.Get<bool>();
508 }
509
510 float PropertyGetFloat(const Dali::Property::Value& v)
511 {
512   return v.Get<float>();
513 }
514
515 int PropertyGetInteger(const Dali::Property::Value& v)
516 {
517   return v.Get<int>();
518 }
519
520 Dali::Vector2 PropertyGetVector2(const Dali::Property::Value& v)
521 {
522   return v.Get<Dali::Vector2>();
523 }
524
525 Dali::Vector3 PropertyGetVector3(const Dali::Property::Value& v)
526 {
527   return v.Get<Dali::Vector3>();
528 }
529
530 Dali::Vector4 PropertyGetVector4(const Dali::Property::Value& v)
531 {
532   return v.Get<Dali::Vector4>();
533 }
534
535 emscripten::val PropertyGetIntRect(const Dali::Property::Value& v)
536 {
537   return JavascriptValue(v);
538 }
539
540 std::string PropertyGetString(const Dali::Property::Value& v)
541 {
542   return v.Get<std::string>();
543 }
544
545 emscripten::val PropertyGetMap(const Dali::Property::Value& v)
546 {
547   return JavascriptValue(v);
548 }
549
550 emscripten::val PropertyGetArray(const Dali::Property::Value& v)
551 {
552   return JavascriptValue(v);
553 }
554
555 emscripten::val PropertyGetMatrix(const Dali::Property::Value& v)
556 {
557   return JavascriptValue(v);
558 }
559
560 emscripten::val PropertyGetMatrix3(const Dali::Property::Value& v)
561 {
562   return JavascriptValue(v);
563 }
564
565 emscripten::val PropertyGetEuler(const Dali::Property::Value& v)
566 {
567   return JavascriptValue(v);
568 }
569
570 emscripten::val PropertyGetRotation(const Dali::Property::Value& v)
571 {
572   return JavascriptValue(v);
573 }
574
575 int PropertyGetType(Dali::Property::Value& v)
576 {
577   return (int)v.GetType();
578 }
579
580 std::string PropertyGetTypeName(Dali::Property::Value& v)
581 {
582   return Dali::PropertyTypes::GetName(v.GetType());
583 }
584
585 template <typename T>
586 float MatrixGetter(T &v, int n)
587 {
588   return *(v.AsFloat() + n);
589 }
590
591 template <typename T>
592 void MatrixSetter(T &v, float f, int n)
593 {
594   *(v.AsFloat() + n) = f;
595 }
596
597 float MatrixGetter0(const Dali::Matrix &v)        { return MatrixGetter(v, 0); }
598 float MatrixGetter1(const Dali::Matrix &v)        { return MatrixGetter(v, 1); }
599 float MatrixGetter2(const Dali::Matrix &v)        { return MatrixGetter(v, 2); }
600 float MatrixGetter3(const Dali::Matrix &v)        { return MatrixGetter(v, 3); }
601 float MatrixGetter4(const Dali::Matrix &v)        { return MatrixGetter(v, 4); }
602 float MatrixGetter5(const Dali::Matrix &v)        { return MatrixGetter(v, 5); }
603 float MatrixGetter6(const Dali::Matrix &v)        { return MatrixGetter(v, 6); }
604 float MatrixGetter7(const Dali::Matrix &v)        { return MatrixGetter(v, 7); }
605 float MatrixGetter8(const Dali::Matrix &v)        { return MatrixGetter(v, 8); }
606 float MatrixGetter9(const Dali::Matrix &v)        { return MatrixGetter(v, 9); }
607 float MatrixGetter10(const Dali::Matrix &v)        { return MatrixGetter(v,10); }
608 float MatrixGetter11(const Dali::Matrix &v)        { return MatrixGetter(v,11); }
609 float MatrixGetter12(const Dali::Matrix &v)        { return MatrixGetter(v,12); }
610 float MatrixGetter13(const Dali::Matrix &v)        { return MatrixGetter(v,13); }
611 float MatrixGetter14(const Dali::Matrix &v)        { return MatrixGetter(v,14); }
612 float MatrixGetter15(const Dali::Matrix &v)        { return MatrixGetter(v,15); }
613 float MatrixGetter16(const Dali::Matrix &v)        { return MatrixGetter(v,16); }
614
615 void MatrixSetter0(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 0); }
616 void MatrixSetter1(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 1); }
617 void MatrixSetter2(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 2); }
618 void MatrixSetter3(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 3); }
619 void MatrixSetter4(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 4); }
620 void MatrixSetter5(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 5); }
621 void MatrixSetter6(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 6); }
622 void MatrixSetter7(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 7); }
623 void MatrixSetter8(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 8); }
624 void MatrixSetter9(Dali::Matrix &v, float f)      { MatrixSetter(v, f, 9); }
625 void MatrixSetter10(Dali::Matrix &v, float f)      { MatrixSetter(v, f,10); }
626 void MatrixSetter11(Dali::Matrix &v, float f)      { MatrixSetter(v, f,11); }
627 void MatrixSetter12(Dali::Matrix &v, float f)      { MatrixSetter(v, f,12); }
628 void MatrixSetter13(Dali::Matrix &v, float f)      { MatrixSetter(v, f,13); }
629 void MatrixSetter14(Dali::Matrix &v, float f)      { MatrixSetter(v, f,14); }
630 void MatrixSetter15(Dali::Matrix &v, float f)      { MatrixSetter(v, f,15); }
631 void MatrixSetter16(Dali::Matrix &v, float f)      { MatrixSetter(v, f,16); }
632
633 float Matrix3Getter0(const Dali::Matrix3 &v)        { return MatrixGetter(v, 0); }
634 float Matrix3Getter1(const Dali::Matrix3 &v)        { return MatrixGetter(v, 1); }
635 float Matrix3Getter2(const Dali::Matrix3 &v)        { return MatrixGetter(v, 2); }
636 float Matrix3Getter3(const Dali::Matrix3 &v)        { return MatrixGetter(v, 3); }
637 float Matrix3Getter4(const Dali::Matrix3 &v)        { return MatrixGetter(v, 4); }
638 float Matrix3Getter5(const Dali::Matrix3 &v)        { return MatrixGetter(v, 5); }
639 float Matrix3Getter6(const Dali::Matrix3 &v)        { return MatrixGetter(v, 6); }
640 float Matrix3Getter7(const Dali::Matrix3 &v)        { return MatrixGetter(v, 7); }
641 float Matrix3Getter8(const Dali::Matrix3 &v)        { return MatrixGetter(v, 8); }
642
643 void Matrix3Setter0(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 0); }
644 void Matrix3Setter1(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 1); }
645 void Matrix3Setter2(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 2); }
646 void Matrix3Setter3(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 3); }
647 void Matrix3Setter4(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 4); }
648 void Matrix3Setter5(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 5); }
649 void Matrix3Setter6(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 6); }
650 void Matrix3Setter7(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 7); }
651 void Matrix3Setter8(Dali::Matrix3 &v, float f)      { MatrixSetter(v, f, 8); }
652
653 val JavascriptUpdateCallback( val::undefined() );
654 bool JavascriptUpdateCallbackSet = false;
655
656 void JavascriptUpdate(int dt)
657 {
658   if( JavascriptUpdateCallbackSet )
659   {
660     JavascriptUpdateCallback( val(dt) );
661   }
662 }
663
664 void SetUpdateFunction( const emscripten::val& function )
665 {
666   JavascriptUpdateCallback = function;
667   JavascriptUpdateCallbackSet = true;
668 }
669
670 const emscripten::val& GetUpdateFunction()
671 {
672   return JavascriptUpdateCallback;
673 }
674
675 /**
676  * Emscripten Bindings
677  *
678  * This uses Emscripten 'bind' (similar in design to Boost's python wrapper library).
679  * It provides a simplified way to wrap C++ classes and wraps Emscriptens type
680  * registration API.
681  *
682  * A convention below is that where there is a function or method name prepended
683  * with '__' there is a corresponding Javascript helper function to help with
684  * marshalling parameters and return values.
685  *
686  */
687 EMSCRIPTEN_BINDINGS(dali_wrapper)
688 {
689   // With a little help embind knows about vectors so we tell it which ones to instantiate
690   register_dali_vector<int>("DaliVectorInt");
691   register_vector<std::string>("VectorString");
692   register_vector<int>("VectorInt");
693   register_vector<float>("VectorFloat");
694   register_vector<Dali::Actor>("VectorActor");
695
696   //
697   // Creation functions.
698   //
699   emscripten::function("VersionString", &VersionString);
700   emscripten::function("__createActor", &CreateActor);
701   emscripten::function("__createHandle", &CreateHandle);
702   emscripten::function("__createSolidColorActor", &CreateSolidColorActor);
703
704   //
705   // Helper functions
706   //
707   emscripten::function("javascriptValue", &JavascriptValue);
708   emscripten::function("__hitTest", &HitTest);
709   emscripten::function("sendMouseEvent", &EmscriptenMouseEvent);
710   emscripten::function("__updateOnce", &EmscriptenUpdateOnce);
711   emscripten::function("__renderOnce", &EmscriptenRenderOnce);
712   emscripten::function("generateControlPoints", &GenerateControlPoints);
713
714   //
715   // Global callback functions
716   //
717   emscripten::function("setCallbackGetGlyphImage", &SetCallbackGetGlyphImage);
718   emscripten::function("setCallbackGetImage", &SetCallbackGetImage);
719   emscripten::function("setCallbackGetImageMetadata", &SetCallbackGetImageMetadata);
720   emscripten::function("setCallbackRenderFinished", &SetCallbackRenderFinished);
721   emscripten::function("setUpdateFunction", &SetUpdateFunction);
722   emscripten::function("getUpdateFunction", &GetUpdateFunction);
723
724   //
725   // Property value creation (Javascript can't select on type)
726   //
727   emscripten::function("PropertyValueBoolean", &PropertyValueBoolean);
728   emscripten::function("PropertyValueFloat", &PropertyValueFloat);
729   emscripten::function("PropertyValueInteger", &PropertyValueInteger);
730   emscripten::function("PropertyValueString", &PropertyValueString);
731   emscripten::function("PropertyValueVector2", &PropertyValueVector2);
732   emscripten::function("PropertyValueVector3", &PropertyValueVector3);
733   emscripten::function("PropertyValueVector4", &PropertyValueVector4);
734   emscripten::function("PropertyValueMatrix", &PropertyValueMatrix);
735   emscripten::function("PropertyValueMatrix3", &PropertyValueMatrix3);
736   emscripten::function("PropertyValueMap", &PropertyValueContainer);
737   emscripten::function("PropertyValueArray", &PropertyValueContainer);
738   emscripten::function("PropertyValueEuler", &PropertyValueEuler);
739   emscripten::function("PropertyValueAxisAngle", &PropertyValueAxisAngle);
740   emscripten::function("PropertyValueString", &PropertyValueString);
741   emscripten::function("PropertyValueIntRect", &PropertyValueIntRect);
742
743   //
744   // One unfortunate aspect of wrapping for the browser is that we get no notification
745   // of object deletion so all JS wrapper objects must be wrapper.delete() correctly.
746   //
747   // Embind has a mechanism around this for simple c style structs decared as value_arrays.
748   // These are immediately transformed to Javascript arrays and don't need explicit
749   // destruction, however the API needs a member offset.
750   //
751   value_array<Dali::Internal::Emscripten::Statistics>("Statistics")
752     .element(&Dali::Internal::Emscripten::Statistics::on)
753     .element(&Dali::Internal::Emscripten::Statistics::frameCount)
754     .element(&Dali::Internal::Emscripten::Statistics::lastFrameDeltaSeconds)
755     .element(&Dali::Internal::Emscripten::Statistics::lastSyncTimeMilliseconds)
756     .element(&Dali::Internal::Emscripten::Statistics::nextSyncTimeMilliseconds)
757     .element(&Dali::Internal::Emscripten::Statistics::keepUpdating)
758     .element(&Dali::Internal::Emscripten::Statistics::needsNotification)
759     .element(&Dali::Internal::Emscripten::Statistics::secondsFromLastFrame)
760 ;
761
762   value_array<Dali::Vector2>("Vector2")
763     .element(&Dali::Vector2::x)
764     .element(&Dali::Vector2::y)
765 ;
766
767   value_array<Dali::Vector3>("Vector3")
768     .element(&Dali::Vector3::x)
769     .element(&Dali::Vector3::y)
770     .element(&Dali::Vector3::z)
771 ;
772
773   value_array<Dali::Vector4>("Vector4")
774     .element(&Dali::Vector4::x)
775     .element(&Dali::Vector4::y)
776     .element(&Dali::Vector4::z)
777     .element(&Dali::Vector4::w)
778 ;
779
780   value_array<Dali::Matrix>("Matrix")
781     .element(&MatrixGetter0, &MatrixSetter0)
782     .element(&MatrixGetter1, &MatrixSetter1)
783     .element(&MatrixGetter2, &MatrixSetter2)
784     .element(&MatrixGetter3, &MatrixSetter3)
785     .element(&MatrixGetter4, &MatrixSetter4)
786     .element(&MatrixGetter5, &MatrixSetter5)
787     .element(&MatrixGetter6, &MatrixSetter6)
788     .element(&MatrixGetter7, &MatrixSetter7)
789     .element(&MatrixGetter8, &MatrixSetter8)
790     .element(&MatrixGetter9, &MatrixSetter9)
791     .element(&MatrixGetter10, &MatrixSetter10)
792     .element(&MatrixGetter11, &MatrixSetter11)
793     .element(&MatrixGetter12, &MatrixSetter12)
794     .element(&MatrixGetter13, &MatrixSetter13)
795     .element(&MatrixGetter14, &MatrixSetter14)
796     .element(&MatrixGetter15, &MatrixSetter15)
797 ;
798
799   value_array<Dali::Matrix3>("Matrix3")
800     .element(&Matrix3Getter0, &Matrix3Setter0)
801     .element(&Matrix3Getter1, &Matrix3Setter1)
802     .element(&Matrix3Getter2, &Matrix3Setter2)
803     .element(&Matrix3Getter3, &Matrix3Setter3)
804     .element(&Matrix3Getter4, &Matrix3Setter4)
805     .element(&Matrix3Getter5, &Matrix3Setter5)
806     .element(&Matrix3Getter6, &Matrix3Setter6)
807     .element(&Matrix3Getter7, &Matrix3Setter7)
808     .element(&Matrix3Getter8, &Matrix3Setter8)
809 ;
810
811   //
812   // enums
813   //
814   enum_<Dali::Property::Type>("PropertyType")
815     .value("NONE", Dali::Property::NONE)
816     .value("BOOLEAN", Dali::Property::BOOLEAN)
817     .value("FLOAT", Dali::Property::FLOAT)
818     .value("INTEGER", Dali::Property::INTEGER)
819     .value("VECTOR2", Dali::Property::VECTOR2)
820     .value("VECTOR3", Dali::Property::VECTOR3)
821     .value("VECTOR4", Dali::Property::VECTOR4)
822     .value("MATRIX3", Dali::Property::MATRIX3)
823     .value("MATRIX", Dali::Property::MATRIX)
824     .value("RECTANGLE", Dali::Property::RECTANGLE)
825     .value("ROTATION", Dali::Property::ROTATION)
826     .value("STRING", Dali::Property::STRING)
827     .value("ARRAY", Dali::Property::ARRAY)
828     .value("MAP", Dali::Property::MAP)
829 ;
830
831   enum_<Dali::ShaderEffect::GeometryHints>("GeometryHints")
832     .value("HINT_NONE", Dali::ShaderEffect::HINT_NONE)
833     .value("HINT_GRID_X", Dali::ShaderEffect::HINT_GRID_X)
834     .value("HINT_GRID_Y", Dali::ShaderEffect::HINT_GRID_Y)
835     .value("HINT_GRID", Dali::ShaderEffect::HINT_GRID)
836     .value("HINT_DEPTH_BUFFER", Dali::ShaderEffect::HINT_DEPTH_BUFFER)
837     .value("HINT_BLENDING", Dali::ShaderEffect::HINT_BLENDING)
838     .value("HINT_DOESNT_MODIFY_GEOMETRY", Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY)
839 ;
840
841   enum_<Dali::Shader::ShaderHints>("ShaderHints")
842     .value("HINT_NONE",                      Dali::Shader::HINT_NONE)
843     .value("HINT_OUTPUT_IS_TRANSPARENT",     Dali::Shader::HINT_OUTPUT_IS_TRANSPARENT)
844     .value("HINT_MODIFIES_GEOMETRY",         Dali::Shader::HINT_MODIFIES_GEOMETRY)
845 ;
846
847   enum_<Dali::Animation::EndAction>("EndAction")
848     .value("Bake",        Dali::Animation::Bake)
849     .value("Discard",     Dali::Animation::Discard)
850     .value("BakeFinal",   Dali::Animation::BakeFinal)
851 ;
852
853   enum_<Dali::Animation::Interpolation>("Interpolation")
854     .value("Linear", Dali::Animation::Interpolation::Linear)
855     .value("Cubic", Dali::Animation::Interpolation::Cubic)
856 ;
857
858   enum_<Dali::Geometry::GeometryType>("GeometryType")
859     .value("POINTS",          Dali::Geometry::POINTS)
860     .value("LINES",           Dali::Geometry::LINES)
861     .value("LINE_LOOP",       Dali::Geometry::LINE_LOOP)
862     .value("LINE_STRIP",      Dali::Geometry::LINE_STRIP)
863     .value("TRIANGLES",       Dali::Geometry::TRIANGLES)
864     .value("TRIANGLE_FAN",    Dali::Geometry::TRIANGLE_FAN)
865     .value("TRIANGLE_STRIP",  Dali::Geometry::TRIANGLE_STRIP)
866 ;
867
868   enum_<Dali::Image::ReleasePolicy>("ReleasePolicy")
869     .value("UNUSED",          Dali::Image::UNUSED)
870     .value("NEVER",           Dali::Image::NEVER)
871 ;
872
873   enum_<Dali::Pixel::Format>("PixelFormat")
874     .value("A8", Dali::Pixel::Format::A8)
875     .value("L8", Dali::Pixel::Format::L8)
876     .value("LA88", Dali::Pixel::Format::LA88)
877     .value("RGB565", Dali::Pixel::Format::RGB565)
878     .value("BGR565", Dali::Pixel::Format::BGR565)
879     .value("RGBA4444", Dali::Pixel::Format::RGBA4444)
880     .value("BGRA4444", Dali::Pixel::Format::BGRA4444)
881     .value("RGBA5551", Dali::Pixel::Format::RGBA5551)
882     .value("BGRA5551", Dali::Pixel::Format::BGRA5551)
883     .value("RGB888", Dali::Pixel::Format::RGB888)
884     .value("RGB8888", Dali::Pixel::Format::RGB8888)
885     .value("BGR8888", Dali::Pixel::Format::BGR8888)
886     .value("RGBA8888", Dali::Pixel::Format::RGBA8888)
887     .value("BGRA8888", Dali::Pixel::Format::BGRA8888)
888     // GLES 3 Standard compressed formats:
889     .value("COMPRESSED_R11_EAC", Dali::Pixel::Format::COMPRESSED_R11_EAC)
890     .value("COMPRESSED_SIGNED_R11_EAC", Dali::Pixel::Format::COMPRESSED_SIGNED_R11_EAC)
891     .value("COMPRESSED_RG11_EAC", Dali::Pixel::Format::COMPRESSED_RG11_EAC)
892     .value("COMPRESSED_SIGNED_RG11_EAC", Dali::Pixel::Format::COMPRESSED_SIGNED_RG11_EAC)
893     .value("COMPRESSED_RGB8_ETC2", Dali::Pixel::Format::COMPRESSED_RGB8_ETC2)
894     .value("COMPRESSED_SRGB8_ETC2", Dali::Pixel::Format::COMPRESSED_SRGB8_ETC2)
895     .value("COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", Dali::Pixel::Format::COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2)
896     .value("COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", Dali::Pixel::Format::COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2)
897     .value("COMPRESSED_RGBA8_ETC2_EAC", Dali::Pixel::Format::COMPRESSED_RGBA8_ETC2_EAC)
898     .value("COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", Dali::Pixel::Format::COMPRESSED_SRGB8_ALPHA8_ETC2_EAC)
899     // GLES 2 extension compressed formats:
900     .value("COMPRESSED_RGB8_ETC1", Dali::Pixel::Format::COMPRESSED_RGB8_ETC1)
901     .value("COMPRESSED_RGB_PVRTC_4BPPV1", Dali::Pixel::Format::COMPRESSED_RGB_PVRTC_4BPPV1)
902 ;
903
904   enum_<Dali::FaceCullingMode::Type>("FaceCullingMode")
905     .value("NONE", Dali::FaceCullingMode::NONE)
906     .value("FRONT", Dali::FaceCullingMode::FRONT)
907     .value("BACK", Dali::FaceCullingMode::BACK)
908     .value("FRONT_AND_BACK", Dali::FaceCullingMode::FRONT_AND_BACK)
909 ;
910
911   enum_<Dali::DepthWriteMode::Type>("DepthWriteMode")
912     .value("OFF", Dali::DepthWriteMode::OFF)
913     .value("AUTO", Dali::DepthWriteMode::AUTO)
914     .value("ON", Dali::DepthWriteMode::ON)
915 ;
916
917   enum_<Dali::BlendMode::Type>("BlendMode")
918     .value("OFF", Dali::BlendMode::OFF)
919     .value("AUTO", Dali::BlendMode::AUTO)
920     .value("ON", Dali::BlendMode::ON)
921 ;
922
923   enum_<Dali::AlphaFunction::BuiltinFunction>("AlphaFunction")
924     .value("DEFAULT", Dali::AlphaFunction::BuiltinFunction::DEFAULT)
925     .value("LINEAR", Dali::AlphaFunction::BuiltinFunction::LINEAR)
926     .value("REVERSE", Dali::AlphaFunction::BuiltinFunction::REVERSE)
927     .value("EASE_IN_SQUARE", Dali::AlphaFunction::BuiltinFunction::EASE_IN_SQUARE)
928     .value("EASE_OUT_SQUARE", Dali::AlphaFunction::BuiltinFunction::EASE_OUT_SQUARE)
929     .value("EASE_IN", Dali::AlphaFunction::BuiltinFunction::EASE_IN)
930     .value("EASE_OUT", Dali::AlphaFunction::BuiltinFunction::EASE_OUT)
931     .value("EASE_IN_OUT", Dali::AlphaFunction::BuiltinFunction::EASE_IN_OUT)
932     .value("EASE_IN_SINE", Dali::AlphaFunction::BuiltinFunction::EASE_IN_SINE)
933     .value("EASE_OUT_SINE", Dali::AlphaFunction::BuiltinFunction::EASE_OUT_SINE)
934     .value("EASE_IN_OUT_SINE", Dali::AlphaFunction::BuiltinFunction::EASE_IN_OUT_SINE)
935     .value("BOUNCE", Dali::AlphaFunction::BuiltinFunction::BOUNCE)
936     .value("SIN", Dali::AlphaFunction::BuiltinFunction::SIN)
937     .value("EASE_OUT_BACK", Dali::AlphaFunction::BuiltinFunction::EASE_OUT_BACK)
938 ;
939
940   //
941   // classes
942   //
943
944   // we need property map as an object rather than straight conversion to javascript 'object'
945   // because its ordered. And PropertyBuffer needs an order.
946   class_<Dali::Property::Map>("PropertyMap")
947     .constructor<>()
948     .function("count", &Dali::Property::Map::Count)
949     .function("empty", &Dali::Property::Map::Empty)
950     .function("__insert", select_overload< void(const std::string&, const Dali::Property::Value&) > (&Dali::Property::Map::Insert))
951     .function("__get", &PropertyMapGet)
952     .function("__getValue", &Dali::Property::Map::GetValue)
953     .function("getKey", &Dali::Property::Map::GetKey)
954     .function("clear", &Dali::Property::Map::Clear)
955     .function("merge", &Dali::Property::Map::Merge)
956 ;
957
958   class_<Dali::Property::Value>("PropertyValue")
959     .constructor<>()
960     .function("getType", &PropertyGetType)
961     .function("getTypeName", &PropertyGetTypeName)
962     .function("getBoolean", &PropertyGetBoolean)
963     .function("getFloat", &PropertyGetFloat)
964     .function("getInteger", &PropertyGetInteger)
965     .function("getVector2", &PropertyGetVector2)
966     .function("getVector3", &PropertyGetVector3)
967     .function("getVector4", &PropertyGetVector4)
968     .function("getString", &PropertyGetString)
969     .function("getMap", &PropertyGetMap)
970     .function("getArray", &PropertyGetArray)
971     .function("getMatrix", &PropertyGetMatrix)
972     .function("getMatrix3", &PropertyGetMatrix3)
973     .function("getEuler", &PropertyGetEuler)
974     .function("getRotation", &PropertyGetRotation)
975     .function("getIntRect", &PropertyGetIntRect)
976 ;
977
978   class_<Dali::BaseHandle>("BaseHandle")
979     .function("ok", &BaseHandleOk)
980     .function("getTypeName", &BaseHandle::GetTypeName)
981 ;
982
983   class_<Dali::TypeInfo, base<Dali::BaseHandle>>("TypeInfo")
984     .function("getName", &Dali::TypeInfo::GetName)
985     .function("getBaseName", &Dali::TypeInfo::GetBaseName)
986     .function("getProperties", &GetAllProperties)
987     .function("getActions", &GetActions)
988     .function("getSignals", &GetSignals)
989     .function("getPropertyIndices", &Dali::TypeInfo::GetPropertyIndices)
990 ;
991
992   class_<Dali::TypeRegistry>("TypeRegistry")
993     .constructor<>(&Dali::TypeRegistry::Get)
994     .function("getTypeNameCount", &Dali::TypeRegistry::GetTypeNameCount)
995     .function("getTypeName", &Dali::TypeRegistry::GetTypeName)
996     .function("getTypeInfo", select_overload< Dali::TypeInfo(const std::string&) > (&Dali::TypeRegistry::GetTypeInfo))
997 ;
998
999   class_<SignalHolder>("SignalHolder")
1000     .constructor<>()
1001 ;
1002
1003   class_<Dali::Handle, base<Dali::BaseHandle>>("Handle")
1004     .function("__registerProperty", &RegisterProperty)
1005     .function("__registerAnimatedProperty", &RegisterAnimatedProperty)
1006     .function("setSelf", &SetSelf)
1007     .function("setProperty", &SetProperty)
1008     .function("getProperty", &GetProperty)
1009     .function("getPropertyIndex", &GetPropertyIndex)
1010     .function("getProperties", &GetProperties)
1011     .function("getPropertyIndices", &Handle::GetPropertyIndices)
1012     .function("getPropertyTypeFromName", &GetPropertyTypeFromName)
1013     .function("getPropertyTypeName", &GetPropertyTypeName)
1014     .function("registerProperty", &RegisterProperty)
1015     .function("registerAnimatedProperty", &RegisterAnimatedProperty)
1016     .function("getTypeInfo", &GetTypeInfo)
1017     .function("isPropertyWritable", &Handle::IsPropertyWritable)
1018     .function("isPropertyAnimatable", &Handle::IsPropertyAnimatable)
1019     .function("isPropertyAConstraintInput", &Handle::IsPropertyAConstraintInput)
1020 ;
1021
1022   class_<Dali::Path, base<Dali::Handle>>("Path")
1023     .constructor<>(&Dali::Path::New)
1024     .function("addPoint", &Dali::Path::AddPoint)
1025     .function("addControlPoint", &Dali::Path::AddControlPoint)
1026     .function("generateControlPoints", &Dali::Path::GenerateControlPoints)
1027     .function("sample", &Dali::Path::Sample)
1028     .function("getPoint", &Dali::Path::GetPoint)
1029     .function("getControlPoint", &Dali::Path::GetControlPoint)
1030     .function("getPointCount", &Dali::Path::GetPointCount)
1031 ;
1032
1033   class_<Dali::KeyFrames>("KeyFrames")
1034     .constructor<>(&Dali::KeyFrames::New)
1035     .function("add", select_overload<void (float progress, Property::Value value)>(&Dali::KeyFrames::Add))
1036     .function("addWithAlpha", &KeyFramesAddWithAlpha)
1037 ;
1038
1039   class_<Dali::Animation>("Animation")
1040     .constructor<float>(&Dali::Animation::New)
1041     .function("__animateTo", &AnimateTo)
1042     .function("__animateBy", &AnimateBy)
1043     .function("__animateBetween", &AnimateBetween)
1044     .function("__animatePath", &AnimatePath)
1045     .function("setDuration", &Dali::Animation::SetDuration)
1046     .function("getDuration", &Dali::Animation::GetDuration)
1047     .function("setLooping", &Dali::Animation::SetLooping)
1048     .function("isLooping", &Dali::Animation::IsLooping)
1049     .function("setEndAction", &Dali::Animation::SetEndAction)
1050     .function("getEndAction", &Dali::Animation::GetEndAction)
1051     .function("setDisconnectAction", &Dali::Animation::SetDisconnectAction)
1052     .function("getDisconnectAction", &Dali::Animation::GetDisconnectAction)
1053     .function("setCurrentProgress", &Dali::Animation::SetCurrentProgress)
1054     .function("getCurrentProgress", &Dali::Animation::GetCurrentProgress)
1055     .function("setSpeedFactor", &Dali::Animation::SetSpeedFactor)
1056     .function("getSpeedFactor", &Dali::Animation::GetSpeedFactor)
1057     .function("setPlayRange", &Dali::Animation::SetPlayRange)
1058     .function("getPlayRange", &Dali::Animation::GetPlayRange)
1059     .function("play", &Dali::Animation::Play)
1060     .function("playFrom", &Dali::Animation::PlayFrom)
1061     .function("pause", &Dali::Animation::Pause)
1062     .function("stop", &Dali::Animation::Stop)
1063     .function("clear", &Dali::Animation::Clear)
1064 ;
1065
1066   class_<Dali::PropertyBuffer>("PropertyBuffer")
1067     .constructor<Dali::Property::Map&>(Dali::PropertyBuffer::New)
1068     .function("setData", &SetPropertyBufferDataRaw)
1069 ;
1070
1071   class_<Dali::Geometry>("Geometry")
1072     .constructor<>(&Dali::Geometry::New)
1073     .function("addVertexBuffer", &Dali::Geometry::AddVertexBuffer)
1074     .function("getNumberOfVertexBuffers", &Dali::Geometry::GetNumberOfVertexBuffers)
1075     .function("setIndexBuffer", &SetIndexBufferDataRaw)
1076     .function("setGeometryType", &Dali::Geometry::SetGeometryType)
1077     .function("getGeometryType", &Dali::Geometry::GetGeometryType)
1078 ;
1079
1080   class_<Dali::Image>("Image")
1081 ;
1082
1083   class_<Dali::BufferImage, base<Dali::Image> >("BufferImage")
1084     .constructor<const std::string&, unsigned int, unsigned int, Dali::Pixel::Format>(&BufferImageNew)
1085 ;
1086
1087   class_<Dali::EncodedBufferImage, base<Dali::Image> >("EncodedBufferImage")
1088     .constructor<const std::string&>(&EncodedBufferImageNew)
1089 ;
1090
1091   class_<Dali::Sampler>("Sampler")
1092     .constructor<>(&Dali::Sampler::New)
1093 ;
1094
1095   class_<Dali::Shader, base<Dali::Handle>>("Shader")
1096     .constructor<>(&Dali::Shader::New)
1097 ;
1098
1099   class_<Dali::TextureSet>("TextureSet")
1100     .constructor<>(&Dali::TextureSet::New)
1101     .function("setImage", &Dali::TextureSet::SetImage)
1102     .function("setSampler", &Dali::TextureSet::SetSampler)
1103     .function("getImage", &Dali::TextureSet::GetImage)
1104     .function("getSampler", &Dali::TextureSet::GetSampler)
1105     .function("getTextureCount", &Dali::TextureSet::GetTextureCount)
1106 ;
1107
1108   class_<Dali::Renderer, base<Dali::Handle>>("Renderer")
1109     .constructor<>(&Dali::Renderer::New)
1110     .function("setGeometry", &Dali::Renderer::SetGeometry)
1111     .function("getGeometry", &Dali::Renderer::GetGeometry)
1112     .function("SetTextures", &Dali::Renderer::SetTextures)
1113     .function("SetTextures", &Dali::Renderer::SetTextures)
1114 ;
1115
1116   class_<Dali::ShaderEffect, base<Dali::Handle>>("ShaderEffect")
1117     .constructor<const std::string&, const std::string&,
1118                  const std::string&, const std::string&,
1119                  int >(&CreateShaderEffect)
1120     .function("setEffectImage", &Dali::ShaderEffect::SetEffectImage)
1121     .function("__setUniform", &SetUniform)
1122 ;
1123
1124   class_<Dali::Actor, base<Dali::Handle>>("Actor")
1125     .constructor<>(&Dali::Actor::New)
1126     .function("add", &Dali::Actor::Add)
1127     .function("remove", &Dali::Actor::Remove)
1128     .function("getId", &Dali::Actor::GetId)
1129     .function("__getParent", &Dali::Actor::GetParent)
1130     .function("__findChildById", &Dali::Actor::FindChildById)
1131     .function("__findChildByName", &Dali::Actor::FindChildByName)
1132     .function("__getChildAt", &Dali::Actor::GetChildAt)
1133     .function("getChildCount", &Dali::Actor::GetChildCount)
1134     .function("__screenToLocal",
1135               select_overload<std::vector<float> (Dali::Actor, float, float)>(&ScreenToLocal))
1136     .function("addressOf", &AddressOf)
1137     .function("__connect", &ConnectSignal)
1138     .function("__setPropertyNotification", &SetPropertyNotification)
1139     .function("addRenderer", &Dali::Actor::AddRenderer)
1140     .function("getRendererCount", &Dali::Actor::GetRendererCount)
1141     .function("removeRenderer",
1142               select_overload<void(unsigned int)>(&Dali::Actor::RemoveRenderer))
1143     .function("__getRendererAt", &Dali::Actor::GetRendererAt)
1144 ;
1145
1146   class_<Dali::CameraActor, base<Dali::Actor>>("CameraActor")
1147     .constructor<>( select_overload<Dali::CameraActor()>(&Dali::CameraActor::New))
1148 ;
1149
1150   class_<Dali::Layer, base<Dali::Actor>>("Layer")
1151     .constructor<>(&Dali::Layer::New)
1152     .function("raise", &Dali::Layer::Raise)
1153     .function("lower", &Dali::Layer::Lower)
1154 ;
1155
1156   class_<Dali::Stage>("Stage")
1157     .constructor<>(&Dali::Stage::GetCurrent)
1158     .function("add", &Dali::Stage::Add)
1159     .function("remove", &Dali::Stage::Remove)
1160     .function("__getRootLayer", &Dali::Stage::GetRootLayer)
1161     .function("getLayer", &Dali::Stage::GetLayer)
1162     .function("getRenderTaskList", &Dali::Stage::GetRenderTaskList)
1163     .function("setBackgroundColor", &Dali::Stage::SetBackgroundColor)
1164 ;
1165
1166   class_<Dali::RenderTaskList>("RenderTaskList")
1167     .function("createTask", &Dali::RenderTaskList::CreateTask)
1168     .function("removeTask", &Dali::RenderTaskList::RemoveTask)
1169     .function("getTaskCount", &Dali::RenderTaskList::GetTaskCount)
1170     .function("getTask", &Dali::RenderTaskList::GetTask)
1171 ;
1172
1173   class_<Dali::RenderTask>("RenderTask")
1174     .function("__getCameraActor", &Dali::RenderTask::GetCameraActor)
1175     .function("setCameraActor", &Dali::RenderTask::SetCameraActor)
1176     .function("setSourceActor", &Dali::RenderTask::SetSourceActor)
1177     .function("setExclusive", &Dali::RenderTask::SetExclusive)
1178     .function("setInputEnabled", &Dali::RenderTask::SetInputEnabled)
1179     .function("setViewportPosition", &Dali::RenderTask::SetViewportPosition)
1180     .function("setViewportSize", &Dali::RenderTask::SetViewportSize)
1181     .function("getCurrentViewportPosition", &Dali::RenderTask::GetCurrentViewportPosition)
1182     .function("getCurrentViewportSize", &Dali::RenderTask::GetCurrentViewportSize)
1183     .function("setClearColor", &Dali::RenderTask::SetClearColor)
1184     .function("getClearColor", &Dali::RenderTask::GetClearColor)
1185     .function("setClearEnabled", &Dali::RenderTask::SetClearEnabled)
1186     .function("getClearEnabled", &Dali::RenderTask::GetClearEnabled)
1187     .function("screenToLocal",
1188               select_overload<Dali::Vector2(Dali::RenderTask, Dali::Actor, float, float)>(&ScreenToLocal))
1189     .function("worldToScreen", &WorldToScreen)
1190 ;
1191
1192 }
1193
1194 }; // namespace Emscripten
1195 }; // namespace Internal
1196 }; // namespace Dali