Merge "Added PixelBuffer for image loading and operations." into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / emscripten / sdl-application.h
1 #ifndef __DALI_SDL_APPLICATION_H__
2 #define __DALI_SDL_APPLICATION_H__
3
4 /*
5 Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
6
7 This file is part of Dali
8
9 PROPRIETARY/CONFIDENTIAL
10
11 This software is the confidential and proprietary information of
12 SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
13 disclose such Confidential Information and shall use it only in
14 accordance with the terms of the license agreement you entered
15 into with SAMSUNG ELECTRONICS.
16
17 SAMSUNG make no representations or warranties about the suitability
18 of the software, either express or implied, including but not limited
19 to the implied warranties of merchantability, fitness for a particular
20 purpose, or non-infringement. SAMSUNG shall not be liable for any
21 damages suffered by licensee as a result of using, modifying or
22 distributing this software or its derivatives.
23 */
24
25 // INTERNAL INCLUDES
26 #include "platform-abstractions/emscripten/emscripten-platform-abstraction.h"
27 #include "sdl-gesture-manager.h"
28 #include "adaptors/common/gl/gl-implementation.h"
29 #include "sdl-gl-sync-abstraction.h"
30 #include "sdl-render-controller.h"
31 #include <dali/public-api/common/dali-common.h>
32 #include <dali/public-api/signals/connection-tracker.h>
33 #include <dali/integration-api/core.h>
34 #include <gl/egl-implementation.h>
35
36 namespace Dali
37 {
38
39 /**
40  *
41  * An SdlApplication object for Emscripten main()
42  *
43  * This provides libSDL calls for creating the application surface and running
44  * the update and rendering.
45  * The libSDL calls are stubbed by Emscripten into browser canvas construction
46  * calls. The update and rendering are exposed as we are in a single threaded
47  * environment and the browser needs to control the main loop.
48  * Emscripten provides emscripten_set_main_loop() for the 'loop' function which
49  * should render one frame and return
50  *
51  */
52 class DALI_IMPORT_API SdlApplication : public ConnectionTracker
53 {
54 public:
55
56   // Default values derived from H2 device.
57   static const unsigned int DEFAULT_SURFACE_WIDTH;
58   static const unsigned int DEFAULT_SURFACE_HEIGHT;
59
60 #ifdef _CPP11
61   static constexpr float DEFAULT_HORIZONTAL_DPI = 220.0f;
62   static constexpr float DEFAULT_VERTICAL_DPI   = 217.0f;
63 #else
64   static const float DEFAULT_HORIZONTAL_DPI = 220.0f;
65   static const float DEFAULT_VERTICAL_DPI   = 217.0f;
66 #endif
67
68   static const unsigned int DEFAULT_RENDER_INTERVAL = 1;
69
70   /**
71    * Constructor
72    *
73    * @param[in] surfaceWidth  Initial width of the browser canvas
74    * @param[in] surfaceHeight Initial height of the browser canvas
75    * @param[in] horizontalDpi Horizontal Dpi
76    * @param[in] verticalDpi Vertical Dpi
77    */
78   SdlApplication( size_t surfaceWidth  = DEFAULT_SURFACE_WIDTH,
79                   size_t surfaceHeight = DEFAULT_SURFACE_HEIGHT,
80                   float  horizontalDpi = DEFAULT_HORIZONTAL_DPI,
81                   float  verticalDpi   = DEFAULT_VERTICAL_DPI );
82
83   /**
84    * Destructor
85    */
86   virtual ~SdlApplication();
87
88   /**
89    * Run the update once.
90    * The browser is a single threaded environment and this is called on a browser callback.
91    */
92   void DoUpdate();
93
94   /**
95    * Render once. The browser is a single threaded environment.
96    * The browser is a single threaded environment and this is called on a browser callback.
97    */
98   void DoRender();
99
100   /**
101    * Send Touch event into Dali event loop.
102    * The allows the browser to supply touch events.
103    */
104   void SendTouchEvent(double x, double y, int downUpMotion);
105
106   /**
107    * Set surface width.
108    * The allows the browser to tell Dali that the rendering canvas has changed size.
109    *
110    * @param[in] width  The surface/canvas width
111    * @param[in] height The surface/canvas height
112    */
113   void SetSurfaceWidth( unsigned int width, unsigned height );
114
115 protected:
116   EmscriptenPlatformAbstraction        mPlatformAbstraction;
117   SdlGlSyncAbstraction                 mGlSyncAbstraction;
118   SdlRenderController                  mRenderController;
119   Internal::Adaptor::GlImplementation  mGlAbstraction;
120   SdlGestureManager                    mGestureManager;
121
122   Integration::UpdateStatus            mStatus;
123   Integration::RenderStatus            mRenderStatus;
124
125   Integration::Core*                   mCore;
126   Internal::Adaptor::EglImplementation mEglImplementation;
127
128   unsigned int mSurfaceWidth;
129   unsigned int mSurfaceHeight;
130   unsigned int mFrame;
131
132   unsigned int mSeconds;
133   unsigned int mMicroSeconds;
134
135   void SdlCreateWindow(size_t surfaceWidth,
136                        size_t surfaceHeight,
137                        const std::string &title);
138
139 };
140
141 } // Dali
142
143 #endif // header