gfx/layers/apz/src/TaskThrottler.cpp

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:912fa6454306
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */
2 /* vim: set sw=2 sts=2 ts=8 et tw=80 : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #include "TaskThrottler.h"
8
9 namespace mozilla {
10 namespace layers {
11
12 TaskThrottler::TaskThrottler(const TimeStamp& aTimeStamp)
13 : mOutstanding(false)
14 , mQueuedTask(nullptr)
15 , mStartTime(aTimeStamp)
16 , mMean(1)
17 { }
18
19 void
20 TaskThrottler::PostTask(const tracked_objects::Location& aLocation,
21 CancelableTask* aTask, const TimeStamp& aTimeStamp)
22 {
23 aTask->SetBirthPlace(aLocation);
24
25 if (mOutstanding) {
26 if (mQueuedTask) {
27 mQueuedTask->Cancel();
28 }
29 mQueuedTask = aTask;
30 } else {
31 mStartTime = aTimeStamp;
32 aTask->Run();
33 delete aTask;
34 mOutstanding = true;
35 }
36 }
37
38 void
39 TaskThrottler::TaskComplete(const TimeStamp& aTimeStamp)
40 {
41 if (!mOutstanding) {
42 return;
43 }
44
45 mMean.insert(aTimeStamp - mStartTime);
46
47 if (mQueuedTask) {
48 mStartTime = aTimeStamp;
49 mQueuedTask->Run();
50 mQueuedTask = nullptr;
51 } else {
52 mOutstanding = false;
53 }
54 }
55
56 TimeDuration
57 TaskThrottler::TimeSinceLastRequest(const TimeStamp& aTimeStamp)
58 {
59 return aTimeStamp - mStartTime;
60 }
61
62 }
63 }

mercurial