b92844f941e5ae4e0a6759798078048b79d2d22b
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / windows / vsync-monitor-win.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/graphics/common/vsync-monitor.h>
20
21 // EXTERNAL INCLUDES
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <unistd.h>
26
27 #include <dali/integration-api/debug.h>
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace Adaptor
36 {
37
38 namespace
39 {
40 // constants to keep code readability with unsigned int has to be used as boolean (due to multithreading)
41 const unsigned int TRUE = 1u;
42 const unsigned int FALSE = 0u;
43
44 const int FD_NONE( -1 );
45
46 } // unnamed namespace
47
48 VSyncMonitor::VSyncMonitor()
49 : mFileDescriptor( FD_NONE ),
50   mUseHardwareVSync( FALSE ),
51   mHardwareVSyncAvailable( FALSE )
52 {
53 }
54
55 VSyncMonitor::~VSyncMonitor()
56 {
57   Terminate();
58 }
59
60 void VSyncMonitor::SetUseHardwareVSync( bool useHardware )
61 {
62   mUseHardwareVSync = useHardware;
63 }
64
65 void VSyncMonitor::SetHardwareVSyncAvailable( bool hardwareVSyncAvailable )
66 {
67   mHardwareVSyncAvailable = hardwareVSyncAvailable;
68 }
69
70 void VSyncMonitor::Initialize()
71 {
72   DALI_ASSERT_DEBUG( mFileDescriptor == FD_NONE && "VSyncMonitor::Initialize() called twice" );
73
74   // setup vblank request - block and wait for next vblank
75   mVBlankInfo.request.type = DRM_VBLANK_NEXTONMISS;
76   mVBlankInfo.request.sequence = 0;
77   mVBlankInfo.request.signal = 0;
78
79   // setup vblank reply - block and wait for next vblank
80   mVBlankInfo.reply.type = DRM_VBLANK_NEXTONMISS;
81   mVBlankInfo.reply.sequence = 0;
82   mVBlankInfo.reply.tval_sec = 0;
83   mVBlankInfo.reply.tval_usec = 0;
84 }
85
86 void VSyncMonitor::Terminate()
87 {
88 }
89
90 bool VSyncMonitor::UseHardware()
91 {
92   return mUseHardwareVSync && mHardwareVSyncAvailable && (FD_NONE != mFileDescriptor );
93 }
94
95
96 bool VSyncMonitor::DoSync( unsigned int& frameNumber, unsigned int& seconds, unsigned int& microseconds )
97 {
98   DALI_ASSERT_DEBUG( mFileDescriptor != FD_NONE && "ECoreX::VSyncMonitor is not initialized" );
99   return false;
100 }
101
102 } // namespace Adaptor
103
104 } // namespace Internal
105
106 } // namespace Dali