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