86cdc24f6d4d48f660c7043362d0022062d3a5a0
[platform/core/uifw/dali-adaptor.git] / adaptors / base / separate-update-render / vsync-notifier.h
1 #ifndef __DALI_INTERNAL_VSYNC_NOTIFIER_H__
2 #define __DALI_INTERNAL_VSYNC_NOTIFIER_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
30 class Core;
31 class PlatformAbstraction;
32
33 } // namespace Integration
34
35 namespace Internal
36 {
37
38 namespace Adaptor
39 {
40
41 class VSyncMonitorInterface;
42 class ThreadSynchronization;
43 class EnvironmentOptions;
44 class AdaptorInternalServices;
45
46 /**
47  * Implements a simple class that either monitors vertical blanks from libdrm, or manages
48  * a software timer to handle syncing.
49  */
50 class VSyncNotifier
51 {
52 public:
53
54   /**
55    * Create the vsync notification thread; this will not start to monitor vsync and
56    * send notifications until Start() is called.
57    * @param[in] sync         An object used to synchronize update, render and vsync threads.
58    * @param[in] adaptorInterfaces base adaptor interface
59    * @param[in] environmentOptions environment options
60    */
61   VSyncNotifier( ThreadSynchronization& sync,
62                  AdaptorInternalServices& adaptorInterfaces,
63                  const EnvironmentOptions& environmentOptions);
64
65   /**
66    * Non-virtual destructor; VSyncNotifier is not suitable as a base class.
67    */
68   ~VSyncNotifier();
69
70   /**
71    * Starts the thread
72    */
73   void Start();
74
75   /**
76    * Stops the thread
77    */
78   void Stop();
79
80 private:
81
82   /**
83    * The main thread loop. The system thread will be destroyed on
84    * exit from this function.
85    */
86   void Run();
87
88   /**
89    * Helper for the thread calling the entry function
90    * @param[in] This A pointer to the current VSyncNotifier object
91    */
92   static inline void* InternalThreadEntryFunc( void* This )
93   {
94     ( static_cast<VSyncNotifier*>( This ) )->Run();
95     return NULL;
96   }
97
98 private:
99
100   ThreadSynchronization&              mThreadSynchronization;   ///< Used to synchronize all the threads
101   Dali::Integration::Core&            mCore;                    ///< Dali core reference
102   VSyncMonitorInterface*              mVSyncMonitor;            ///< VSyncMonitor interface
103   pthread_t*                          mThread;                  ///< The actual thread.
104   const EnvironmentOptions&           mEnvironmentOptions;      ///< Environment options
105   unsigned int                        mNumberOfVSyncsPerRender; ///< How many frames for each update/render cycle.
106
107 }; // class VSyncNotifier
108
109 } // namespace Adaptor
110
111 } // namespace Internal
112
113 } // namespace Dali
114
115 #endif // __DALI_INTERNAL_VSYNC_NOTIFIER_H__