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