PotentialCheckerboardDurationTracker.cpp (2364B)
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/glean/GfxMetrics.h" // for Glean 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 bool aRecordTelemetry) { 27 MOZ_ASSERT(Tracking()); 28 mInCheckerboard = false; 29 if (!Tracking()) { 30 if (aRecordTelemetry) { 31 mozilla::glean::gfx_checkerboard::potential_duration 32 .AccumulateRawDuration(TimeStamp::Now() - mCurrentPeriodStart); 33 } 34 } 35 } 36 37 void PotentialCheckerboardDurationTracker::InTransform(bool aInTransform, 38 bool aRecordTelemetry) { 39 if (aInTransform == mInTransform) { 40 // no-op 41 return; 42 } 43 44 if (!Tracking()) { 45 // Because !Tracking(), mInTransform must be false, and so aInTransform 46 // must be true (or we would have early-exited this function already). 47 // Therefore, we are starting a potential checkerboard period. 48 mInTransform = aInTransform; 49 mCurrentPeriodStart = TimeStamp::Now(); 50 return; 51 } 52 53 mInTransform = aInTransform; 54 55 if (!Tracking()) { 56 // Tracking() must have been true at the start of this function, or we 57 // would have taken the other !Tracking branch above. If it's false now, 58 // it means we just stopped tracking, so we are ending a potential 59 // checkerboard period. 60 if (aRecordTelemetry) { 61 mozilla::glean::gfx_checkerboard::potential_duration 62 .AccumulateRawDuration(TimeStamp::Now() - mCurrentPeriodStart); 63 } 64 } 65 } 66 67 bool PotentialCheckerboardDurationTracker::Tracking() const { 68 return mInTransform || mInCheckerboard; 69 } 70 71 } // namespace layers 72 } // namespace mozilla