1 #ifndef __DALI_INTERNAL_ADAPTOR_FRAME_TIME_H__
2 #define __DALI_INTERNAL_ADAPTOR_FRAME_TIME_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
29 class PlatformAbstraction;
38 * FrameTime stores the time of the last VSync. It can then be used by the update thread to predict
39 * the current update will be rendered.
45 // Called from Event thread
49 * @param[in] platform The platform used to retrieve the current time
51 FrameTime( Integration::PlatformAbstraction& platform );
54 * Destructor, non virtual
59 * Sets the expected minimum frame time interval.
60 * @param[in] interval The interval in microseconds.
62 void SetMinimumFrameTimeInterval( unsigned int interval );
65 * Suspends the FrameTime object when the application state changes
70 * Resumes the FrameTime object when the application state changes
74 // Called from Update thread
77 * Sets the FrameTime object to sleep, i.e. when there are no more updates required.
82 * Wakes the FrameTime object from a sleep state.
87 * Predicts when the next render time will occur.
89 * @param[out] lastFrameDeltaSeconds The delta, in seconds (with float precision), between the last two renders.
90 * @param[out] lastSyncTimeMilliseconds The time, in milliseconds, of the last Sync.
91 * @param[out] nextSyncTimeMilliseconds The estimated time, in milliseconds, at the next Sync.
93 * @note Should only be called once per tick, from the update thread.
95 void PredictNextSyncTime( float& lastFrameDeltaSeconds, unsigned int& lastVSyncTimeMilliseconds, unsigned int& nextVSyncTimeMilliseconds );
97 // Called from VSync thread
100 * Tells the FrameTime object that a Sync has occurred.
102 * @param[in] frameNumber The frame number of the current Sync.
104 * @note Should only be called from the VSync thread.
106 void SetSyncTime( unsigned int frameNumber );
111 * Sets the current time to be the last Vsync time.
113 inline void SetLastSyncTime();
117 Integration::PlatformAbstraction& mPlatform; ///< The platform abstraction.
119 unsigned int mMinimumFrameTimeInterval; ///< The minimum frame time interval, set by Adaptor.
121 uint64_t mLastSyncTime; ///< The last Sync time (in microseconds).
122 uint64_t mLastSyncTimeAtUpdate; ///< The last Sync time at Update (in microseconds).
124 unsigned int mLastSyncFrameNumber; ///< The last Sync frame number
125 unsigned int mLastUpdateFrameNumber; ///< The last Sync frame number handled in Update.
127 // NOTE cannot use bitfields or booleans as these are used from multiple threads, must use variable with machine word size for atomic read/write
128 unsigned int mRunning; ///< The state of the FrameTime object.
129 unsigned int mFirstFrame; ///< Whether the current update is the first frame (after initialisation, resume or wake up).
131 unsigned int mPreviousUpdateFrames[3]; ///< Array holding the number of frames Update took in the last three iterations.
132 unsigned int writePos; ///< The current write position in the array.
134 unsigned int mExtraUpdatesSinceSync; ///< The number of extra updates since the last Sync.
137 } // namespace Adaptor
138 } // namespace Internal
141 #endif // __DALI_INTERNAL_ADAPTOR_FRAME_TIME_H__