PerformancePaintTiming.cpp (2160B)
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 "PerformancePaintTiming.h" 8 9 #include "MainThreadUtils.h" 10 #include "Performance.h" 11 #include "mozilla/dom/PerformanceMeasureBinding.h" 12 #include "nsGkAtoms.h" 13 #include "nsRFPService.h" 14 15 using namespace mozilla::dom; 16 17 NS_IMPL_CYCLE_COLLECTION_INHERITED(PerformancePaintTiming, PerformanceEntry, 18 mPerformance) 19 20 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformancePaintTiming) 21 NS_INTERFACE_MAP_END_INHERITING(PerformanceEntry) 22 23 NS_IMPL_ADDREF_INHERITED(PerformancePaintTiming, PerformanceEntry) 24 NS_IMPL_RELEASE_INHERITED(PerformancePaintTiming, PerformanceEntry) 25 26 PerformancePaintTiming::PerformancePaintTiming(Performance* aPerformance, 27 const nsAString& aName, 28 const TimeStamp& aStartTime) 29 : PerformanceEntry(aPerformance->GetParentObject(), aName, 30 nsGkAtoms::paint), 31 mPerformance(aPerformance), 32 mRawStartTime(aStartTime) {} 33 34 PerformancePaintTiming::~PerformancePaintTiming() = default; 35 36 JSObject* PerformancePaintTiming::WrapObject( 37 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 38 return PerformancePaintTiming_Binding::Wrap(aCx, this, aGivenProto); 39 } 40 41 DOMHighResTimeStamp PerformancePaintTiming::StartTime() const { 42 if (mCachedStartTime.isNothing()) { 43 DOMHighResTimeStamp rawValue = 44 mPerformance->GetDOMTiming()->TimeStampToDOMHighRes(mRawStartTime); 45 mCachedStartTime.emplace(nsRFPService::ReduceTimePrecisionAsMSecs( 46 rawValue, mPerformance->GetRandomTimelineSeed(), 47 mPerformance->GetRTPCallerType())); 48 } 49 return mCachedStartTime.value(); 50 } 51 52 size_t PerformancePaintTiming::SizeOfIncludingThis( 53 mozilla::MallocSizeOf aMallocSizeOf) const { 54 return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); 55 }