make frametime state flags properly atomic read/write
[platform/core/uifw/dali-adaptor.git] / adaptors / base / update-thread.h
1 #ifndef __DALI_INTERNAL_UPDATE_THREAD_H__
2 #define __DALI_INTERNAL_UPDATE_THREAD_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 // INTERNAL INCLUDES
22 #include <dali/public-api/common/vector-wrapper.h>
23
24 namespace boost
25 {
26
27 class thread;
28
29 } // namespace boost
30
31 namespace Dali
32 {
33
34 namespace Integration
35 {
36 class Core;
37 }
38
39 namespace Internal
40 {
41
42 namespace Adaptor
43 {
44
45 class UpdateRenderSynchronization;
46 class AdaptorInternalServices;
47 class TriggerEventInterface;
48 class EnvironmentOptions;
49
50 /**
51  * The update-thread is responsible for calling Core::Update(), and
52  * for triggering the render-thread after each update.
53  */
54 class UpdateThread
55 {
56 public:
57
58   /**
59    * Create the update-thread; this will not do anything until Start() is called.
60    * @param[in] sync An object used to synchronize update & render threads.
61    * @param[in] adaptorInterfaces base adaptor interface
62    * @param[in] environmentOptions environment options
63    */
64   UpdateThread(UpdateRenderSynchronization& sync,
65                AdaptorInternalServices& adaptorInterfaces,
66                const EnvironmentOptions& environmentOptions );
67
68   /**
69    * Non-virtual destructor; UpdateThread is not suitable as a base class.
70    */
71   ~UpdateThread();
72
73   /**
74    * Starts the update-thread
75    */
76   void Start();
77
78   /**
79    * Stops the update-thread
80    */
81   void Stop();
82
83 private:
84
85   /**
86    * This method is used by the update-thread for calling Core::Update().
87    * @return true, if the thread finishes properly.
88    */
89   bool Run();
90
91   /**
92    * When DALI_FPS_TRACKING is enabled, this method calculates the frame rates for the specified time period
93    */
94   void FPSTracking(float secondsFromLastFrame);
95
96   /**
97    * Output the FPS information
98    * when the FSP tracking is enabled,
99    * it is called when the specified tracking period is elapsed or in the destructor when the process finished beforehand
100    */
101   void OutputFPSRecord();
102
103   /**
104    * Optionally output the update thread status.
105    * @param[in] keepUpdatingStatus Whether the update-thread requested further updates.
106    * @param[in] renderNeedsUpdate Whether the render-thread requested another update.
107    */
108   void UpdateStatusLogging( unsigned int keepUpdatingStatus, bool renderNeedsUpdate );
109
110 private: // Data
111
112   UpdateRenderSynchronization&        mUpdateRenderSync;    ///< Used to synchronize the update & render threads
113
114   Dali::Integration::Core&            mCore;                ///< Dali core reference
115
116   unsigned int                        mFpsTrackingSeconds;  ///< fps tracking time length in seconds
117   std::vector<float>                  mFpsRecord;           ///< Record of frame rate
118   float                               mElapsedTime;         ///< time elapsed within current second
119   unsigned int                        mElapsedSeconds;      ///< seconds elapsed since the fps tracking started
120
121   unsigned int                        mStatusLogInterval;   ///< Interval in frames between status debug prints
122   unsigned int                        mStatusLogCount;      ///< Used to count frames between status debug prints
123
124   TriggerEventInterface&              mNotificationTrigger; ///< Reference to notification event trigger
125
126   boost::thread*                      mThread;              ///< The actual update-thread.
127   const EnvironmentOptions&           mEnvironmentOptions;  ///< environment options
128 }; // class UpdateThread
129
130 } // namespace Adaptor
131
132 } // namespace Internal
133
134 } // namespace Dali
135
136 #endif // __DALI_INTERNAL_UPDATE_THREAD_H__