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