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 // WindowsTimer.cpp: Implementation of a high precision timer class on Windows 8 9 #include "windows/WindowsTimer.h" 10 WindowsTimer()11WindowsTimer::WindowsTimer() : mRunning(false), mStartTime(0), mStopTime(0) 12 { 13 } 14 start()15void WindowsTimer::start() 16 { 17 LARGE_INTEGER frequency; 18 QueryPerformanceFrequency(&frequency); 19 mFrequency = frequency.QuadPart; 20 21 LARGE_INTEGER curTime; 22 QueryPerformanceCounter(&curTime); 23 mStartTime = curTime.QuadPart; 24 25 mRunning = true; 26 } 27 stop()28void WindowsTimer::stop() 29 { 30 LARGE_INTEGER curTime; 31 QueryPerformanceCounter(&curTime); 32 mStopTime = curTime.QuadPart; 33 34 mRunning = false; 35 } 36 getElapsedTime() const37double WindowsTimer::getElapsedTime() const 38 { 39 LONGLONG endTime; 40 if (mRunning) 41 { 42 LARGE_INTEGER curTime; 43 QueryPerformanceCounter(&curTime); 44 endTime = curTime.QuadPart; 45 } 46 else 47 { 48 endTime = mStopTime; 49 } 50 51 return static_cast<double>(endTime - mStartTime) / mFrequency; 52 } 53 CreateTimer()54Timer *CreateTimer() 55 { 56 return new WindowsTimer(); 57 } 58