Revert "[Tizen] Added 'make clean' on each profile build."
[platform/core/uifw/dali-adaptor.git] / adaptors / emscripten / main.cpp
1
2 #include "sdl-application.h"
3 #include <cassert>
4
5 #include <dali/public-api/dali-core.h>
6
7 #include <SDL/SDL.h>
8
9 // main loop function called by emscripten/browser
10 extern void emscripten_set_main_loop(void (*func)(), int fps, int simulate_infinite_loop);
11
12 namespace Dali
13 {
14 namespace Internal
15 {
16 namespace Emscripten
17 {
18 extern void RenderFinished();
19 };
20 };
21 };
22
23 Dali::SdlApplication *app = NULL;
24
25 void EmscriptenMouseEvent(double x, double y, int downUpMotion)
26 {
27   DALI_ASSERT_ALWAYS(app);
28
29   if(app)
30   {
31     app->SendTouchEvent(x,y, downUpMotion);
32   }
33 }
34
35 void ProcessEvents()
36 {
37   SDL_PumpEvents();
38
39   //
40   // This wasnt working prior to emscripten v1.25
41   //
42   // But it only gives event inside the gl window.
43   // When dragging (for rotation etc) we want the drag/rotate to continue outside the window
44   //
45   // So we'll disable this handling for now
46   //
47   SDL_Event event;
48   while (SDL_PollEvent(&event))
49   {
50   } // Poll(event)
51
52 } // ProcessEvents()
53
54
55 void EmscriptenUpdateOnce()
56 {
57   DALI_ASSERT_ALWAYS(app);
58   app->DoUpdate();
59 };
60
61 void EmscriptenRenderOnce()
62 {
63   DALI_ASSERT_ALWAYS(app);
64
65   static int w = 0;
66   static int h = 0;
67
68   // 'Module' here should be 'dali' with emcc switch -s EXPORT_NAME="dali"
69   // but on upgrading to emscripten 1.34.2 it's broken.
70   int _x = EM_ASM_INT_V({ return Module.canvas.width;  });
71   int _y = EM_ASM_INT_V({ return Module.canvas.height; });
72
73   bool resize = false;
74   if( _x != w )
75   {
76     w = _x;
77     resize = true;
78   }
79   if( _y != h )
80   {
81     h = _y;
82     resize = true;
83   }
84   if( resize )
85   {
86     app->SetSurfaceWidth(w, h);
87   }
88
89   ProcessEvents();
90
91   EmscriptenUpdateOnce();
92
93   app->DoRender();
94
95   Dali::Internal::Emscripten::RenderFinished();
96 }
97
98 int main(int argc, char *argv[])
99 {
100   using namespace Dali;
101
102   // need to reference everything as emscripten/llvm will cut it all out so put a Actor here
103   Dali::Actor actor;
104
105   app = new SdlApplication( 0, 0, SdlApplication::DEFAULT_HORIZONTAL_DPI,  SdlApplication::DEFAULT_VERTICAL_DPI );
106
107   emscripten_set_main_loop(EmscriptenRenderOnce, 0, 1);
108
109   return 1;
110 }