Merge "DALi Version 1.0.35" into tizen
[platform/core/uifw/dali-adaptor.git] / adaptors / common / adaptor.h
1 #ifndef __DALI_ADAPTOR_H__
2 #define __DALI_ADAPTOR_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/signals/callback.h>
23 #include <dali/public-api/signals/dali-signal.h>
24 #include <dali/public-api/math/rect.h>
25 #include <dali/public-api/events/touch-event.h>
26
27 // INTERNAL INCLUDES
28 #include "window.h"
29 #include "application-configuration.h"
30 #include "tts-player.h"
31
32 namespace Dali DALI_INTERNAL
33 {
34
35 struct DeviceLayout;
36 class RenderSurface;
37
38 namespace Internal DALI_INTERNAL
39 {
40 namespace Adaptor
41 {
42 class Adaptor;
43 }
44 }
45
46 /**
47  * @brief An Adaptor object is used to initialize and control how Dali runs.
48  *
49  * It provides a lifecycle interface that allows the application
50  * writer to provide their own main loop and other platform related
51  * features.
52  *
53  * The Adaptor class provides a means for initialising the resources required by the Dali::Core.
54  *
55  * When dealing with platform events, the application writer MUST ensure that Dali is called in a
56  * thread-safe manner.
57  *
58  * As soon as the Adaptor class is created and started, the application writer can initialise their
59  * Dali::Actor objects straight away or as required by the main loop they intend to use (there is no
60  * need to wait for an initialise signal as per the Dali::Application class).
61  *
62  * The Adaptor does emit a Resize signal which informs the user when the surface is resized.
63  * Tizen and Linux Adaptors should follow the example below:
64  *
65  * @code
66  * void CreateProgram(DaliAdaptor& adaptor)
67  * {
68  *   // Create Dali components...
69  *   // Can instantiate adaptor here instead, if required
70  * }
71  *
72  * int main ()
73  * {
74  *   // Initialise platform
75  *   MyPlatform.Init();
76  *
77  *   // Create an 800 by 1280 window positioned at (0,0).
78  *   Dali::PositionSize positionSize(0, 0, 800, 1280);
79  *   Dali::Window window = Dali::Window::New( positionSize, "My Application" );
80  *
81  *   // Create an adaptor which uses that window for rendering
82  *   Dali::Adaptor adaptor = Dali::Adaptor::New( window );
83  *   adaptor.Start();
84  *
85  *   CreateProgram(adaptor);
86  *   // Or use this as a callback function depending on the platform initialisation sequence.
87  *
88  *   // Start Main Loop of your platform
89  *   MyPlatform.StartMainLoop();
90  *
91  *   return 0;
92  * }
93  * @endcode
94  *
95  * If required, you can also connect class member functions to a signal:
96  *
97  * @code
98  * MyApplication application;
99  * adaptor.ResizedSignal().Connect(&application, &MyApplication::Resize);
100  * @endcode
101  *
102  * @see RenderSurface
103  */
104 class Adaptor
105 {
106 public:
107
108   typedef Signal< void (Adaptor&) > AdaptorSignalType; ///< Generic Type for adaptor signals
109
110 public:
111   /**
112    * @brief Create a new adaptor using the window.
113    *
114    * @param[in] window The window to draw onto
115    * @note The default base layout DeviceLayout::DEFAULT_BASE_LAYOUT will be used.
116    * @return a reference to the adaptor handle
117    */
118   static Adaptor& New( Window window );
119
120   /**
121    * @brief Create a new adaptor using the window.
122    *
123    * @param[in] window The window to draw onto
124    * @param[in] baseLayout  The base layout that the application has been written for
125    * @param[in] configuration The context loss configuration.
126    * @return a reference to the adaptor handle
127    */
128   static Adaptor& New( Window window, const DeviceLayout& baseLayout, Configuration::ContextLoss configuration );
129
130   /**
131    * @brief Virtual Destructor.
132    */
133   virtual ~Adaptor();
134
135 public:
136
137   /**
138    * @brief Starts the Adaptor.
139    */
140   void Start();
141
142   /**
143    * @brief Pauses the Adaptor.
144    */
145   void Pause();
146
147   /**
148    * @brief Resumes the Adaptor, if previously paused.
149    *
150    * @note If the adaptor is not paused, this does not do anything.
151    */
152   void Resume();
153
154   /**
155    * @brief Stops the Adaptor.
156    */
157   void Stop();
158
159   /**
160    * @brief Ensures that the function passed in is called from the main loop when it is idle.
161    *
162    * A callback of the following type may be used:
163    * @code
164    *   void MyFunction();
165    * @endcode
166    *
167    * @param[in]  callBack  The function to call.
168    * @return true if added successfully, false otherwise
169    *
170    * @note Ownership of the callback is passed onto this class.
171    */
172   bool AddIdle( CallbackBase* callback );
173
174   /**
175    * @brief Get the render surface the adaptor is using to render to.
176    *
177    * @return reference to current render surface
178    */
179   RenderSurface& GetSurface();
180
181   /**
182    * @brief Release any locks the surface may hold.
183    *
184    * For example, after compositing an offscreen surface, use this method to allow
185    * rendering to continue.
186    */
187   void ReleaseSurfaceLock();
188
189   /**
190    * @brief Set the number of frames per render.
191    *
192    * This enables an application to deliberately render with a reduced FPS.
193    * @param[in] numberOfVSyncsPerRender The number of vsyncs between successive renders.
194    * Suggest this is a power of two:
195    * 1 - render each vsync frame
196    * 2 - render every other vsync frame
197    * 4 - render every fourth vsync frame
198    * 8 - render every eighth vsync frame
199    */
200   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
201
202   /**
203    * @brief Set whether the frame count per render is managed using the hardware VSync or
204    * manually timed.
205    *
206    * @param[in] useHardware True if the hardware VSync should be used
207    */
208   void SetUseHardwareVSync(bool useHardware);
209
210   /**
211    * @brief Returns a reference to the instance of the adaptor used by the current thread.
212    *
213    * @return A reference to the adaptor.
214    * @pre The adaptor has been initialised.
215    * @note This is only valid in the main thread.
216    */
217   static Adaptor& Get();
218
219   /**
220    * @brief Checks whether the adaptor is available.
221    *
222    * @return true, if it is available, false otherwise.
223    */
224   static bool IsAvailable();
225
226   /**
227    * @brief Call this method to notify Dali when the system language changes.
228    *
229    * Use this only when NOT using Dali::Application, As Application created using
230    * Dali::Application will automatically receive notification of language change.
231    * When Dali::Application is not used, the application developer should
232    * use app-core to receive language change notifications and should update Dali
233    * by calling this method.
234    */
235   void NotifyLanguageChanged();
236
237   /**
238    * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
239    * trigger a pinch gesture
240    *
241    * @param[in] distance The minimum pinch distance in pixels
242    */
243   void SetMinimumPinchDistance(float distance);
244
245 public:  // Signals
246
247   /**
248    * @brief The user should connect to this signal if they need to perform any
249    * special activities when the surface Dali is being rendered on is resized.
250    *
251    * @return The signal to connect to
252    */
253   AdaptorSignalType& ResizedSignal();
254
255   /**
256    * @brief This signal is emitted when the language is changed on the device.
257    *
258    * @return The signal to connect to
259    */
260   AdaptorSignalType& LanguageChangedSignal();
261
262 private:
263
264   // Undefined
265   Adaptor(const Adaptor&);
266   Adaptor& operator=(Adaptor&);
267
268 private:
269
270   /**
271    * @brief Create an uninitialized Adaptor.
272    */
273   Adaptor();
274
275   Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
276   friend class Internal::Adaptor::Adaptor;
277 };
278
279 } // namespace Dali
280
281 #endif // __DALI_ADAPTOR_H__