1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/apz/src/TaskThrottler.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */ 1.5 +/* vim: set sw=2 sts=2 ts=8 et tw=80 : */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "TaskThrottler.h" 1.11 + 1.12 +namespace mozilla { 1.13 +namespace layers { 1.14 + 1.15 +TaskThrottler::TaskThrottler(const TimeStamp& aTimeStamp) 1.16 + : mOutstanding(false) 1.17 + , mQueuedTask(nullptr) 1.18 + , mStartTime(aTimeStamp) 1.19 + , mMean(1) 1.20 +{ } 1.21 + 1.22 +void 1.23 +TaskThrottler::PostTask(const tracked_objects::Location& aLocation, 1.24 + CancelableTask* aTask, const TimeStamp& aTimeStamp) 1.25 +{ 1.26 + aTask->SetBirthPlace(aLocation); 1.27 + 1.28 + if (mOutstanding) { 1.29 + if (mQueuedTask) { 1.30 + mQueuedTask->Cancel(); 1.31 + } 1.32 + mQueuedTask = aTask; 1.33 + } else { 1.34 + mStartTime = aTimeStamp; 1.35 + aTask->Run(); 1.36 + delete aTask; 1.37 + mOutstanding = true; 1.38 + } 1.39 +} 1.40 + 1.41 +void 1.42 +TaskThrottler::TaskComplete(const TimeStamp& aTimeStamp) 1.43 +{ 1.44 + if (!mOutstanding) { 1.45 + return; 1.46 + } 1.47 + 1.48 + mMean.insert(aTimeStamp - mStartTime); 1.49 + 1.50 + if (mQueuedTask) { 1.51 + mStartTime = aTimeStamp; 1.52 + mQueuedTask->Run(); 1.53 + mQueuedTask = nullptr; 1.54 + } else { 1.55 + mOutstanding = false; 1.56 + } 1.57 +} 1.58 + 1.59 +TimeDuration 1.60 +TaskThrottler::TimeSinceLastRequest(const TimeStamp& aTimeStamp) 1.61 +{ 1.62 + return aTimeStamp - mStartTime; 1.63 +} 1.64 + 1.65 +} 1.66 +}