Extract out FPS Tracker & Update Status Logger from UpdateThread class
[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 // INTERNAL INCLUDES
25 #include <base/fps-tracker.h>
26 #include <base/update-status-logger.h>
27
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33 class Core;
34 }
35
36 namespace Internal
37 {
38
39 namespace Adaptor
40 {
41
42 class ThreadSynchronization;
43 class AdaptorInternalServices;
44 class EnvironmentOptions;
45
46 /**
47  * The update-thread is responsible for calling Core::Update(), and
48  * for triggering the render-thread after each update.
49  */
50 class UpdateThread
51 {
52 public:
53
54   /**
55    * Create the update-thread; this will not do anything until Start() is called.
56    * @param[in] sync An object used to synchronize update & render threads.
57    * @param[in] adaptorInterfaces base adaptor interface
58    * @param[in] environmentOptions environment options
59    */
60   UpdateThread(ThreadSynchronization& sync,
61                AdaptorInternalServices& adaptorInterfaces,
62                const EnvironmentOptions& environmentOptions );
63
64   /**
65    * Non-virtual destructor; UpdateThread is not suitable as a base class.
66    */
67   ~UpdateThread();
68
69   /**
70    * Starts the update-thread
71    */
72   void Start();
73
74   /**
75    * Stops the update-thread
76    */
77   void Stop();
78
79 private:
80
81   /**
82    * This method is used by the update-thread for calling Core::Update().
83    * @return true, if the thread finishes properly.
84    */
85   bool Run();
86
87   /**
88    * Helper for the thread calling the entry function
89    * @param[in] This A pointer to the current UpdateThread object
90    */
91   static inline void* InternalThreadEntryFunc( void* This )
92   {
93     ( static_cast<UpdateThread*>( This ) )->Run();
94     return NULL;
95   }
96
97 private: // Data
98
99   ThreadSynchronization&              mThreadSynchronization; ///< Used to synchronize all the threads
100
101   Dali::Integration::Core&            mCore;                ///< Dali core reference
102
103   FpsTracker                          mFpsTracker;          ///< Object that tracks the FPS
104   UpdateStatusLogger                  mUpdateStatusLogger;  ///< Object that logs the update-status as required.
105
106   pthread_t*                          mThread;              ///< The actual update-thread.
107   const EnvironmentOptions&           mEnvironmentOptions;  ///< environment options
108 }; // class UpdateThread
109
110 } // namespace Adaptor
111
112 } // namespace Internal
113
114 } // namespace Dali
115
116 #endif // __DALI_INTERNAL_UPDATE_THREAD_H__