[3.0] Support screen rotation
[platform/core/uifw/dali-adaptor.git] / adaptors / base / single-threaded / single-thread-controller.h
1 #ifndef __DALI_INTERNAL_SINGLE_THREAD_CONTROLLER_H__
2 #define __DALI_INTERNAL_SINGLE_THREAD_CONTROLLER_H__
3
4 /*
5  * Copyright (c) 2015 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 <stdint.h>
23 #include <dali/public-api/signals/connection-tracker.h>
24 #include <dali/integration-api/core.h>
25
26 // INTERNAL INCLUDES
27 #include <timer.h>
28 #include <base/interfaces/performance-interface.h>
29 #include <base/fps-tracker.h>
30 #include <base/render-helper.h>
31 #include <base/thread-controller-interface.h>
32 #include <base/update-status-logger.h>
33
34 namespace Dali
35 {
36
37 class RenderSurface;
38
39 namespace Internal
40 {
41
42 namespace Adaptor
43 {
44
45 class AdaptorInternalServices;
46 class EnvironmentOptions;
47
48 /**
49  * Single Thread Controller, where events, updates & renders ALL occur on the same thread.
50  */
51 class SingleThreadController : public ConnectionTracker,
52                                public ThreadControllerInterface
53 {
54 public:
55
56   /**
57    * Constructor
58    */
59   SingleThreadController( AdaptorInternalServices& adaptorInterfaces, const EnvironmentOptions& environmentOptions );
60
61   /**
62    * Non virtual destructor. Not intended as base class.
63    */
64   ~SingleThreadController();
65
66   /**
67    * @copydoc ThreadControllerInterface::Initialize()
68    */
69   void Initialize();
70
71   /**
72    * @copydoc ThreadControllerInterface::Start()
73    */
74   void Start();
75
76   /**
77    * @copydoc ThreadControllerInterface::Pause()
78    */
79   void Pause();
80
81   /**
82    * @copydoc ThreadControllerInterface::Resume()
83    */
84   void Resume();
85
86   /**
87    * @copydoc ThreadControllerInterface::Stop()
88    */
89   void Stop();
90
91   /**
92    * @copydoc ThreadControllerInterface::RequestUpdate()
93    */
94   void RequestUpdate();
95
96   /**
97    * @copydoc ThreadControllerInterface::RequestUpdateOnce()
98    */
99   void RequestUpdateOnce();
100
101   /**
102    * @copydoc ThreadControllerInterface::ReplaceSurface()
103    */
104   void ReplaceSurface( RenderSurface* surface );
105
106   /**
107    * @copydoc ThreadControllerInterface::ResizeSurface()
108    */
109   virtual void ResizeSurface();
110
111   /**
112    * @copydoc ThreadControllerInterface::SetRenderRefreshRate()
113    */
114   void SetRenderRefreshRate( unsigned int refreshRate );
115
116 private:
117
118   /**
119    * State Machine
120    */
121   struct State
122   {
123     enum Type
124     {
125       STOPPED,
126       RUNNING,
127       PAUSED,
128       SLEEPING
129     };
130   };
131
132   // Undefined copy constructor.
133   SingleThreadController( const SingleThreadController& );
134
135   // Undefined assignment operator.
136   SingleThreadController& operator=( const SingleThreadController& );
137
138   /**
139    * Ticks whenever the timer expires
140    */
141   bool OnTimerTick();
142
143   /**
144    * Runs the update and render
145    *
146    * @param[in] incrementTime If true, then the animation times are incremented.
147    */
148   void UpdateRender( bool incrementTime );
149
150   /**
151    * Updates mCurrentTime and gets the time elapsed (in seconds) since last time this function was called.
152    *
153    * @return time elapsed (in seconds) since last call.
154    */
155   float UpdateTimeSinceLastRender();
156
157   /**
158    * Helper to add a performance marker to the performance server (if it's active)
159    * @param type performance marker type
160    */
161   void AddPerformanceMarker( PerformanceInterface::MarkerType type );
162
163   /**
164    * Changes the state and performs any other state-change related functionality.
165    * @param[in] state The new state
166    */
167   void ChangeState( State::Type state );
168
169   /**
170    * Performs operations to stop rendering, e.g. informing Core of context being destroyed & shutting down EGL.
171    */
172   void StopRendering();
173
174 private:
175
176   Dali::Timer                       mTimer;                           ///< Ensures an update & render is run every frame.
177   FpsTracker                        mFpsTracker;                      ///< Object that tracks the FPS
178   UpdateStatusLogger                mUpdateStatusLogger;              ///< Object that logs the update-status as required.
179
180   RenderHelper                      mRenderHelper;                    ///< Helper class for EGL, pre & post rendering
181
182   Integration::Core&                mCore;                            ///< DALi core reference
183   PerformanceInterface*             mPerformanceInterface;            ///< The performance logging interface
184
185   uint64_t                          mLastUpdateRenderTime;            ///< Last time we did an update and render
186   uint64_t                          mSystemTime;                      ///< The current system time for FPS calculations
187   unsigned int                      mRefreshRate;                     ///< Frame skipping count
188   State::Type                       mState;                           ///< The state
189   bool                              mUpdatingAndRendering:1;          ///< Set to true when we are updating and rendering.
190   bool                              mStopRequestedWhileRendering:1;   ///< Set to true if we were told to stop while we were in the middle of a render
191 };
192
193 } // namespace Adaptor
194
195 } // namespace Internal
196
197 } // namespace Dali
198
199 #endif // __DALI_INTERNAL_SINGLE_THREAD_CONTROLLER_H__