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