1 // 2 // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 #include "win32/Win32Timer.h" 8 9 Win32Timer::Win32Timer() 10 : mRunning(0), 11 mStartTime(0), 12 mStopTime(0) 13 { 14 } 15 16 void Win32Timer::start() 17 { 18 LARGE_INTEGER frequency; 19 QueryPerformanceFrequency(&frequency); 20 mFrequency = frequency.QuadPart; 21 22 LARGE_INTEGER curTime; 23 QueryPerformanceCounter(&curTime); 24 mStartTime = curTime.QuadPart; 25 26 mRunning = true; 27 } 28 29 void Win32Timer::stop() 30 { 31 LARGE_INTEGER curTime; 32 QueryPerformanceCounter(&curTime); 33 mStopTime = curTime.QuadPart; 34 35 mRunning = false; 36 } 37 38 double Win32Timer::getElapsedTime() const 39 { 40 LONGLONG endTime; 41 if (mRunning) 42 { 43 LARGE_INTEGER curTime; 44 QueryPerformanceCounter(&curTime); 45 endTime = curTime.QuadPart; 46 } 47 else 48 { 49 endTime = mStopTime; 50 } 51 52 return static_cast<double>(endTime - mStartTime) / mFrequency; 53 } 54 55 Timer *CreateTimer() 56 { 57 return new Win32Timer(); 58 } 59