Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / common / frame-time.h
1 #ifndef __DALI_INTERNAL_FRAME_TIME_H__
2 #define __DALI_INTERNAL_FRAME_TIME_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include <stdint.h>
21
22 namespace Dali
23 {
24
25 namespace Integration
26 {
27 class PlatformAbstraction;
28 }
29
30 namespace Internal
31 {
32
33 /**
34  * FrameTime stores the time of the last VSync. It can then be used by the update thread to predict
35  * the current update will be rendered.
36  */
37 class FrameTime
38 {
39 public: // Core Methods
40
41   // Called from Event thread
42
43   /**
44    * Constructor
45    * @param[in]  platform  The platform used to retrieve the current time
46    */
47   FrameTime( Integration::PlatformAbstraction& platform );
48
49   /**
50    * Destructor, non virtual
51    */
52   ~FrameTime();
53
54   /**
55    * Sets the expected minimum frame time interval.
56    * @param[in]  interval  The interval in microseconds.
57    */
58   void SetMinimumFrameTimeInterval( unsigned int interval );
59
60   /**
61    * Suspends the FrameTime object.
62    * During the suspended state animations will be paused.
63    * @note Should only be called by the Core.
64    */
65   void Suspend();
66
67   /**
68    * Resumes the FrameTime object.
69    * Animations etc. will carry on from where they left off.
70    * @note Should only be called by the Core.
71    */
72   void Resume();
73
74   // Called from Update thread
75
76   /**
77    * Sets the FrameTime object to sleep.
78    * @note Should only be called by the Core, from the update thread.
79    */
80   void Sleep();
81
82   /**
83    * Wakes the FrameTime object from a sleep state.
84    * @note Should only be called by the Core, from the update thread.
85    */
86   void WakeUp();
87
88   /**
89    * Predicts when the next render time will occur.
90    *
91    * @param[out]  lastFrameDeltaSeconds      The delta, in seconds (with float precision), between the last two renders.
92    * @param[out]  lastVSyncTimeMilliseconds  The time, in milliseconds, of the last VSync.
93    * @param[out]  nextVSyncTimeMilliseconds  The estimated time, in milliseconds, at the next VSync.
94    *
95    * @note Should only be called once per tick, from the update thread.
96    */
97   void PredictNextVSyncTime( float& lastFrameDeltaSeconds, unsigned int& lastVSyncTimeMilliseconds, unsigned int& nextVSyncTimeMilliseconds );
98
99   // Called from VSync thread
100
101   /**
102    * Tells the FrameTime object that a VSync has occurred.
103    *
104    * @param[in]  frameNumber  The frame number of the current VSync.
105    *
106    * @note Should only be called by the Core (from the VSync thread).
107    */
108   void SetVSyncTime( unsigned int frameNumber );
109
110 private:
111
112   /**
113    * Sets the current time to be the last Vsync time.
114    */
115   inline void SetLastVSyncTime();
116
117 private:
118
119   Integration::PlatformAbstraction& mPlatform;    ///< The platform abstraction.
120
121   unsigned int mMinimumFrameTimeInterval;   ///< The minimum frame time interval, set by Adaptor.
122
123   uint64_t mLastVSyncTime;                  ///< The last VSync time (in microseconds).
124   uint64_t mLastVSyncTimeAtUpdate;          ///< The last VSync time at Update (in microseconds).
125
126   unsigned int mLastVSyncFrameNumber;       ///< The last VSync frame number
127   unsigned int mLastUpdateFrameNumber;      ///< The last VSync frame number handled in Update.
128
129   bool         mRunning:1;                  ///< The state of the FrameTime object.
130   bool         mFirstFrame:1;               ///< Whether the current update is the first frame (after initialisation, resume or wake up).
131
132   unsigned int mPreviousUpdateFrames[3];    ///< Array holding the number of frames Update took in the last three iterations.
133   unsigned int writePos;                    ///< The current write position in the array.
134
135   unsigned int mExtraUpdatesSinceVSync;     ///< The number of extra updates since the last VSync.
136 };
137
138 } // namespace Internal
139
140 } // namespace Dali
141
142 #endif // __DALI_INTERNAL_FRAME_TIME_H__