Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-adaptor.git] / adaptors / integration-api / adaptor.h
1 #ifndef __DALI_INTEGRATION_ADAPTOR_H__
2 #define __DALI_INTEGRATION_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
31 namespace Dali
32 {
33
34 struct DeviceLayout;
35 class RenderSurface;
36
37 namespace Internal
38 {
39 namespace Adaptor
40 {
41 class Adaptor;
42 }
43 }
44
45 /**
46  * @brief An Adaptor object is used to initialize and control how Dali runs.
47  *
48  * It provides a lifecycle interface that allows the application
49  * writer to provide their own main loop and other platform related
50  * features.
51  *
52  * The Adaptor class provides a means for initialising the resources required by the Dali::Core.
53  *
54  * When dealing with platform events, the application writer MUST ensure that Dali is called in a
55  * thread-safe manner.
56  *
57  * As soon as the Adaptor class is created and started, the application writer can initialise their
58  * Dali::Actor objects straight away or as required by the main loop they intend to use (there is no
59  * need to wait for an initialise signal as per the Dali::Application class).
60  *
61  * The Adaptor does emit a Resize signal which informs the user when the surface is resized.
62  * Tizen and Linux Adaptors should follow the example below:
63  *
64  * @code
65  * void CreateProgram(DaliAdaptor& adaptor)
66  * {
67  *   // Create Dali components...
68  *   // Can instantiate adaptor here instead, if required
69  * }
70  *
71  * int main ()
72  * {
73  *   // Initialise platform
74  *   MyPlatform.Init();
75  *
76  *   // Create an 800 by 1280 window positioned at (0,0).
77  *   Dali::PositionSize positionSize(0, 0, 800, 1280);
78  *   Dali::Window window = Dali::Window::New( positionSize, "My Application" );
79  *
80  *   // Create an adaptor which uses that window for rendering
81  *   Dali::Adaptor adaptor = Dali::Adaptor::New( window );
82  *   adaptor.Start();
83  *
84  *   CreateProgram(adaptor);
85  *   // Or use this as a callback function depending on the platform initialisation sequence.
86  *
87  *   // Start Main Loop of your platform
88  *   MyPlatform.StartMainLoop();
89  *
90  *   return 0;
91  * }
92  * @endcode
93  *
94  * If required, you can also connect class member functions to a signal:
95  *
96  * @code
97  * MyApplication application;
98  * adaptor.ResizedSignal().Connect(&application, &MyApplication::Resize);
99  * @endcode
100  *
101  * @see RenderSurface
102  */
103 class DALI_IMPORT_API Adaptor
104 {
105 public:
106
107   typedef Signal< void (Adaptor&) > AdaptorSignalType; ///< Generic Type for adaptor signals
108
109 public:
110   /**
111    * @brief Create a new adaptor using the window.
112    *
113    * @param[in] window The window to draw onto
114    * @note The default base layout DeviceLayout::DEFAULT_BASE_LAYOUT will be used.
115    * @return a reference to the adaptor handle
116    */
117   static Adaptor& New( Window window );
118
119   /**
120    * @brief Create a new adaptor using the window.
121    *
122    * @param[in] window The window to draw onto
123    * @param[in] baseLayout  The base layout that the application has been written for
124    * @param[in] configuration The context loss configuration.
125    * @return a reference to the adaptor handle
126    */
127   static Adaptor& New( Window window, const DeviceLayout& baseLayout, Configuration::ContextLoss configuration );
128
129   /**
130    * @brief Create a new adaptor using render surface.
131    *
132    * @param[in] nativeWindow native window handle
133    * @param[in] surface The surface to draw onto
134    * @note The default base layout DeviceLayout::DEFAULT_BASE_LAYOUT will be used.
135    * @return a reference to the adaptor handle
136    */
137   static Adaptor& New( Any nativeWindow, const Dali::RenderSurface& surface );
138
139   /**
140    * @brief Create a new adaptor using render surface.
141    *
142    * @param[in] nativeWindow native window handle
143    * @param[in] surface The surface to draw onto
144    * @param[in] baseLayout  The base layout that the application has been written for
145    * @param[in] configuration The context loss configuration.
146    * @return a reference to the adaptor handle
147    */
148   static Adaptor& New( Any nativeWindow, const Dali::RenderSurface& surface, const DeviceLayout& baseLayout, Configuration::ContextLoss configuration = Configuration::APPLICATION_DOES_NOT_HANDLE_CONTEXT_LOSS);
149
150   /**
151    * @brief Virtual Destructor.
152    */
153   virtual ~Adaptor();
154
155 public:
156
157   /**
158    * @brief Starts the Adaptor.
159    */
160   void Start();
161
162   /**
163    * @brief Pauses the Adaptor.
164    */
165   void Pause();
166
167   /**
168    * @brief Resumes the Adaptor, if previously paused.
169    *
170    * @note If the adaptor is not paused, this does not do anything.
171    */
172   void Resume();
173
174   /**
175    * @brief Stops the Adaptor.
176    */
177   void Stop();
178
179   /**
180    * @brief Ensures that the function passed in is called from the main loop when it is idle.
181    *
182    * A callback of the following type may be used:
183    * @code
184    *   void MyFunction();
185    * @endcode
186    *
187    * @param[in] callback The function to call.
188    * @return true if added successfully, false otherwise
189    *
190    * @note Ownership of the callback is passed onto this class.
191    */
192   bool AddIdle( CallbackBase* callback );
193
194   /**
195    * @brief Replaces the rendering surface
196    *
197    * @param[in] nativeWindow native window handle
198    * @param[in] surface to use
199    */
200   void ReplaceSurface( Any nativeWindow, Dali::RenderSurface& surface );
201
202   /**
203    * @brief Get the render surface the adaptor is using to render to.
204    *
205    * @return reference to current render surface
206    */
207   RenderSurface& GetSurface();
208
209   /**
210    * @brief Release any locks the surface may hold.
211    *
212    * For example, after compositing an offscreen surface, use this method to allow
213    * rendering to continue.
214    */
215   void ReleaseSurfaceLock();
216
217   /**
218    * @brief Set the number of frames per render.
219    *
220    * This enables an application to deliberately render with a reduced FPS.
221    * @param[in] numberOfVSyncsPerRender The number of vsyncs between successive renders.
222    * Suggest this is a power of two:
223    * 1 - render each vsync frame
224    * 2 - render every other vsync frame
225    * 4 - render every fourth vsync frame
226    * 8 - render every eighth vsync frame
227    */
228   void SetRenderRefreshRate( unsigned int numberOfVSyncsPerRender );
229
230   /**
231    * @brief Set whether the frame count per render is managed using the hardware VSync or
232    * manually timed.
233    *
234    * @param[in] useHardware True if the hardware VSync should be used
235    */
236   void SetUseHardwareVSync(bool useHardware);
237
238   /**
239    * @brief Returns a reference to the instance of the adaptor used by the current thread.
240    *
241    * @return A reference to the adaptor.
242    * @pre The adaptor has been initialised.
243    * @note This is only valid in the main thread.
244    */
245   static Adaptor& Get();
246
247   /**
248    * @brief Checks whether the adaptor is available.
249    *
250    * @return true, if it is available, false otherwise.
251    */
252   static bool IsAvailable();
253
254   /**
255    * @brief Call this method to notify Dali when the system language changes.
256    *
257    * Use this only when NOT using Dali::Application, As Application created using
258    * Dali::Application will automatically receive notification of language change.
259    * When Dali::Application is not used, the application developer should
260    * use app-core to receive language change notifications and should update Dali
261    * by calling this method.
262    */
263   void NotifyLanguageChanged();
264
265   /**
266    * @brief Sets minimum distance in pixels that the fingers must move towards/away from each other in order to
267    * trigger a pinch gesture
268    *
269    * @param[in] distance The minimum pinch distance in pixels
270    */
271   void SetMinimumPinchDistance(float distance);
272
273   /**
274    * @brief Feed a touch point to the adaptor.
275    *
276    * @param[in] point touch point
277    * @param[in] timeStamp time value of event
278    */
279   void FeedTouchPoint( TouchPoint& point, int timeStamp );
280
281   /**
282    * @brief Feed a mouse wheel event to the adaptor.
283    *
284    * @param[in]  wheelEvent mouse wheel event
285    */
286   void FeedWheelEvent( MouseWheelEvent& wheelEvent );
287
288   /**
289    * @brief Feed a key event to the adaptor.
290    *
291    * @param[in] keyEvent The key event holding the key information.
292    */
293   void FeedKeyEvent( KeyEvent& keyEvent );
294
295 public:  // Signals
296
297   /**
298    * @brief The user should connect to this signal if they need to perform any
299    * special activities when the surface Dali is being rendered on is resized.
300    *
301    * @return The signal to connect to
302    */
303   AdaptorSignalType& ResizedSignal();
304
305   /**
306    * @brief This signal is emitted when the language is changed on the device.
307    *
308    * @return The signal to connect to
309    */
310   AdaptorSignalType& LanguageChangedSignal();
311
312 private:
313
314   // Undefined
315   Adaptor(const Adaptor&);
316   Adaptor& operator=(Adaptor&);
317
318 private:
319
320   /**
321    * @brief Create an uninitialized Adaptor.
322    */
323   Adaptor();
324
325   Internal::Adaptor::Adaptor* mImpl; ///< Implementation object
326   friend class Internal::Adaptor::Adaptor;
327 };
328
329 } // namespace Dali
330
331 #endif // __DALI_INTEGRATION_ADAPTOR_H__