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