2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "vsync-monitor.h"
22 #include <sys/types.h>
27 #include <dali/integration-api/debug.h>
41 const int FD_NONE( -1 );
43 } // unnamed namespace
45 VSyncMonitor::VSyncMonitor()
46 : mFileDescriptor( FD_NONE ),
47 mUseHardwareVSync( false ),
48 mHardwareVSyncAvailable( false )
52 VSyncMonitor::~VSyncMonitor()
57 void VSyncMonitor::SetUseHardwareVSync( bool useHardware )
59 mUseHardwareVSync = useHardware;
62 void VSyncMonitor::SetHardwareVSyncAvailable( bool hardwareVSyncAvailable )
64 mHardwareVSyncAvailable = hardwareVSyncAvailable;
67 void VSyncMonitor::Initialize()
69 DALI_ASSERT_DEBUG( mFileDescriptor == FD_NONE && "VSyncMonitor::Initialize() called twice" );
71 // setup vblank request - block and wait for next vblank
72 mVBlankInfo.request.type = DRM_VBLANK_NEXTONMISS;
73 mVBlankInfo.request.sequence = 0;
74 mVBlankInfo.request.signal = 0;
76 // setup vblank reply - block and wait for next vblank
77 mVBlankInfo.reply.type = DRM_VBLANK_NEXTONMISS;
78 mVBlankInfo.reply.sequence = 0;
79 mVBlankInfo.reply.tval_sec = 0;
80 mVBlankInfo.reply.tval_usec = 0;
83 void VSyncMonitor::Terminate()
87 bool VSyncMonitor::UseHardware()
89 return mUseHardwareVSync && mHardwareVSyncAvailable && (FD_NONE != mFileDescriptor );
93 bool VSyncMonitor::DoSync( unsigned int& frameNumber, unsigned int& seconds, unsigned int& microseconds )
95 DALI_ASSERT_DEBUG( mFileDescriptor != FD_NONE && "ECoreX::VSyncMonitor is not initialized" );
97 if( 0 == drmWaitVBlank( mFileDescriptor, &mVBlankInfo ) )
99 frameNumber = mVBlankInfo.reply.sequence;
100 seconds = mVBlankInfo.reply.tval_sec;
101 microseconds = mVBlankInfo.reply.tval_usec;
109 } // namespace Adaptor
111 } // namespace Internal