Edit

kc3-lang/angle/util/win32/Win32Timer.cpp

Branch :

  • Show log

    Commit

  • Author : Jamie Madill
    Date : 2014-08-21 10:04:04
    Hash : 1cfaaf8a
    Message : Add a util project to share between samples and tests. This code shares the Window and EGL logic between the two projects. BUG=angle:730 Change-Id: I8940371226a8f7b02579c332f51679c4a5d0e2a5 Reviewed-on: https://chromium-review.googlesource.com/212799 Tested-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Brandon Jones <bajones@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org>

  • util/win32/Win32Timer.cpp
  • //
    // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    #include "win32/Win32Timer.h"
    
    Win32Timer::Win32Timer()
        : mRunning(0),
          mStartTime(0),
          mStopTime(0)
    {
    }
    
    void Win32Timer::start()
    {
        LARGE_INTEGER frequency;
        QueryPerformanceFrequency(&frequency);
        mFrequency = frequency.QuadPart;
    
        LARGE_INTEGER curTime;
        QueryPerformanceCounter(&curTime);
        mStartTime = curTime.QuadPart;
    
        mRunning = true;
    }
    
    void Win32Timer::stop()
    {
        LARGE_INTEGER curTime;
        QueryPerformanceCounter(&curTime);
        mStopTime = curTime.QuadPart;
    
        mRunning = false;
    }
    
    double Win32Timer::getElapsedTime() const
    {
        LONGLONG endTime;
        if (mRunning)
        {
            LARGE_INTEGER curTime;
            QueryPerformanceCounter(&curTime);
            endTime = curTime.QuadPart;
        }
        else
        {
            endTime = mStopTime;
        }
    
        return static_cast<double>(endTime - mStartTime) / mFrequency;
    }
    
    Timer *CreateTimer()
    {
        return new Win32Timer();
    }