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 #if defined(DEBUG_ENABLED)
42 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_VSYNC_MONITOR");
45 const int FD_NONE( -1 );
47 } // unnamed namespace
49 VSyncMonitor::VSyncMonitor()
50 : mFileDescriptor( FD_NONE ),
55 VSyncMonitor::~VSyncMonitor()
60 void VSyncMonitor::SetUseHardware( bool useHardware )
62 mUseHardware = useHardware;
65 void VSyncMonitor::Initialize()
67 DALI_ASSERT_DEBUG( mFileDescriptor == FD_NONE && "VSyncMonitor::Initialize() called twice" );
69 // setup vblank request - block and wait for next vblank
70 mVBlankInfo.request.type = DRM_VBLANK_NEXTONMISS;
71 mVBlankInfo.request.sequence = 0;
72 mVBlankInfo.request.signal = 0;
74 // setup vblank reply - block and wait for next vblank
75 mVBlankInfo.reply.type = DRM_VBLANK_NEXTONMISS;
76 mVBlankInfo.reply.sequence = 0;
77 mVBlankInfo.reply.tval_sec = 0;
78 mVBlankInfo.reply.tval_usec = 0;
81 void VSyncMonitor::Terminate()
83 if( mFileDescriptor != FD_NONE )
85 close( mFileDescriptor );
86 mFileDescriptor = FD_NONE;
90 bool VSyncMonitor::UseHardware()
92 return mUseHardware && (FD_NONE != mFileDescriptor );
96 bool VSyncMonitor::DoSync( unsigned int& frameNumber, unsigned int& seconds, unsigned int& microseconds )
98 DALI_ASSERT_DEBUG( mFileDescriptor != FD_NONE && "ECoreX::VSyncMonitor is not initialized" );
100 if( 0 == drmWaitVBlank( mFileDescriptor, &mVBlankInfo ) )
102 frameNumber = mVBlankInfo.reply.sequence;
103 seconds = mVBlankInfo.reply.tval_sec;
104 microseconds = mVBlankInfo.reply.tval_usec;
112 } // namespace Adaptor
114 } // namespace Internal