Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 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 "PotentialCheckerboardDurationTracker.h"
8
9
#include "mozilla/Telemetry.h" // for Telemetry
10
11
namespace mozilla {
12
namespace layers {
13
14
PotentialCheckerboardDurationTracker::PotentialCheckerboardDurationTracker()
15
: mInCheckerboard(false), mInTransform(false) {}
16
17
void PotentialCheckerboardDurationTracker::CheckerboardSeen() {
18
// This might get called while mInCheckerboard is already true
19
if (!Tracking()) {
20
mCurrentPeriodStart = TimeStamp::Now();
21
}
22
mInCheckerboard = true;
23
}
24
25
void PotentialCheckerboardDurationTracker::CheckerboardDone() {
26
MOZ_ASSERT(Tracking());
27
mInCheckerboard = false;
28
if (!Tracking()) {
29
mozilla::Telemetry::AccumulateTimeDelta(
30
mozilla::Telemetry::CHECKERBOARD_POTENTIAL_DURATION,
31
mCurrentPeriodStart);
32
}
33
}
34
35
void PotentialCheckerboardDurationTracker::InTransform(bool aInTransform) {
36
if (aInTransform == mInTransform) {
37
// no-op
38
return;
39
}
40
41
if (!Tracking()) {
42
// Because !Tracking(), mInTransform must be false, and so aInTransform
43
// must be true (or we would have early-exited this function already).
44
// Therefore, we are starting a potential checkerboard period.
45
mInTransform = aInTransform;
46
mCurrentPeriodStart = TimeStamp::Now();
47
return;
48
}
49
50
mInTransform = aInTransform;
51
52
if (!Tracking()) {
53
// Tracking() must have been true at the start of this function, or we
54
// would have taken the other !Tracking branch above. If it's false now,
55
// it means we just stopped tracking, so we are ending a potential
56
// checkerboard period.
57
mozilla::Telemetry::AccumulateTimeDelta(
58
mozilla::Telemetry::CHECKERBOARD_POTENTIAL_DURATION,
59
mCurrentPeriodStart);
60
}
61
}
62
63
bool PotentialCheckerboardDurationTracker::Tracking() const {
64
return mInTransform || mInCheckerboard;
65
}
66
67
} // namespace layers
68
} // namespace mozilla