gfx/layers/apz/src/TaskThrottler.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     7 #include "TaskThrottler.h"
     9 namespace mozilla {
    10 namespace layers {
    12 TaskThrottler::TaskThrottler(const TimeStamp& aTimeStamp)
    13   : mOutstanding(false)
    14   , mQueuedTask(nullptr)
    15   , mStartTime(aTimeStamp)
    16   , mMean(1)
    17 { }
    19 void
    20 TaskThrottler::PostTask(const tracked_objects::Location& aLocation,
    21                         CancelableTask* aTask, const TimeStamp& aTimeStamp)
    22 {
    23   aTask->SetBirthPlace(aLocation);
    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 }
    38 void
    39 TaskThrottler::TaskComplete(const TimeStamp& aTimeStamp)
    40 {
    41   if (!mOutstanding) {
    42     return;
    43   }
    45   mMean.insert(aTimeStamp - mStartTime);
    47   if (mQueuedTask) {
    48     mStartTime = aTimeStamp;
    49     mQueuedTask->Run();
    50     mQueuedTask = nullptr;
    51   } else {
    52     mOutstanding = false;
    53   }
    54 }
    56 TimeDuration
    57 TaskThrottler::TimeSinceLastRequest(const TimeStamp& aTimeStamp)
    58 {
    59   return aTimeStamp - mStartTime;
    60 }
    62 }
    63 }

mercurial