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