2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-08 07:22:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Code to notify things that animate before a refresh, at an appropriate
|
|
|
|
* refresh rate. (Perhaps temporary, until replaced by compositor.)
|
2012-12-12 02:15:32 +04:00
|
|
|
*
|
|
|
|
* Chrome and each tab have their own RefreshDriver, which in turn
|
|
|
|
* hooks into one of a few global timer based on RefreshDriverTimer,
|
|
|
|
* defined below. There are two main global timers -- one for active
|
|
|
|
* animations, and one for inactive ones. These are implemented as
|
|
|
|
* subclasses of RefreshDriverTimer; see below for a description of
|
|
|
|
* their implementations. In the future, additional timer types may
|
|
|
|
* implement things like blocking on vsync.
|
2009-10-08 07:22:42 +04:00
|
|
|
*/
|
|
|
|
|
2018-03-07 02:59:36 +03:00
|
|
|
#include "nsRefreshDriver.h"
|
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
# include <windows.h>
|
|
|
|
// mmsystem isn't part of WIN32_LEAN_AND_MEAN, so we have
|
|
|
|
// to manually include it
|
|
|
|
# include <mmsystem.h>
|
2013-08-15 08:25:58 +04:00
|
|
|
# include "WinUtils.h"
|
2012-12-12 02:15:32 +04:00
|
|
|
#endif
|
|
|
|
|
2018-01-27 15:17:27 +03:00
|
|
|
#include "mozilla/AnimationEventDispatcher.h"
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2019-02-25 09:02:12 +03:00
|
|
|
#include "mozilla/Assertions.h"
|
2013-09-04 15:47:21 +04:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2019-12-05 07:44:32 +03:00
|
|
|
#include "mozilla/BasePrincipal.h"
|
2018-09-18 21:05:48 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2015-07-02 12:12:31 +03:00
|
|
|
#include "mozilla/IntegerRange.h"
|
2019-04-03 15:40:26 +03:00
|
|
|
#include "mozilla/PresShell.h"
|
2018-06-02 16:51:42 +03:00
|
|
|
#include "mozilla/dom/FontTableURIProtocolHandler.h"
|
2012-12-12 02:15:32 +04:00
|
|
|
#include "nsITimer.h"
|
2013-05-14 03:47:02 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2009-10-08 07:22:42 +04:00
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2019-05-20 08:48:29 +03:00
|
|
|
#include "mozilla/dom/DocumentInlines.h"
|
2017-04-12 12:53:48 +03:00
|
|
|
#include "nsIXULRuntime.h"
|
2010-08-12 01:05:28 +04:00
|
|
|
#include "jsapi.h"
|
2010-08-23 13:30:08 +04:00
|
|
|
#include "nsContentUtils.h"
|
2015-04-21 04:22:09 +03:00
|
|
|
#include "mozilla/PendingAnimationTracker.h"
|
2018-09-08 01:53:33 +03:00
|
|
|
#include "mozilla/PendingFullscreenEvent.h"
|
2011-05-25 10:32:00 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2019-07-26 04:10:23 +03:00
|
|
|
#include "mozilla/StaticPrefs_apz.h"
|
|
|
|
#include "mozilla/StaticPrefs_gfx.h"
|
|
|
|
#include "mozilla/StaticPrefs_layout.h"
|
2019-08-02 11:52:42 +03:00
|
|
|
#include "mozilla/StaticPrefs_page_load.h"
|
2013-01-05 07:12:24 +04:00
|
|
|
#include "nsViewManager.h"
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2012-12-07 03:58:14 +04:00
|
|
|
#include "nsNPAPIPluginInstance.h"
|
2019-06-17 07:36:29 +03:00
|
|
|
#include "mozilla/dom/CallbackDebuggerNotification.h"
|
2018-04-05 20:42:41 +03:00
|
|
|
#include "mozilla/dom/Event.h"
|
2016-06-09 20:04:42 +03:00
|
|
|
#include "mozilla/dom/Performance.h"
|
2017-06-25 00:38:42 +03:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2013-04-25 19:13:21 +04:00
|
|
|
#include "mozilla/dom/WindowBinding.h"
|
2017-02-13 06:21:33 +03:00
|
|
|
#include "mozilla/RestyleManager.h"
|
2013-08-14 15:33:03 +04:00
|
|
|
#include "Layers.h"
|
2013-10-02 01:00:38 +04:00
|
|
|
#include "imgIContainer.h"
|
2013-12-12 05:51:58 +04:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2014-09-09 22:54:08 +04:00
|
|
|
#include "nsDocShell.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
2014-11-27 14:47:51 +03:00
|
|
|
#include "nsJSEnvironment.h"
|
2014-11-18 15:47:32 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2019-05-26 17:31:53 +03:00
|
|
|
|
2015-01-14 02:38:00 +03:00
|
|
|
#include "BackgroundChild.h"
|
|
|
|
#include "mozilla/ipc/PBackgroundChild.h"
|
|
|
|
#include "mozilla/layout/VsyncChild.h"
|
|
|
|
#include "VsyncSource.h"
|
|
|
|
#include "mozilla/VsyncDispatcher.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-07-18 16:35:59 +03:00
|
|
|
#include "mozilla/TimelineConsumers.h"
|
2015-07-29 04:57:39 +03:00
|
|
|
#include "nsAnimationManager.h"
|
2016-10-12 10:58:04 +03:00
|
|
|
#include "nsDisplayList.h"
|
2018-02-01 07:04:04 +03:00
|
|
|
#include "nsTransitionManager.h"
|
2014-11-18 15:47:32 +03:00
|
|
|
|
2019-04-12 07:42:28 +03:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2019-10-24 22:58:15 +03:00
|
|
|
# include "VRManagerChild.h"
|
2019-04-12 07:42:28 +03:00
|
|
|
#endif // defined(MOZ_WIDGET_ANDROID)
|
|
|
|
|
2017-02-16 16:53:59 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
# include "nsXULPopupManager.h"
|
|
|
|
#endif
|
|
|
|
|
2019-07-25 04:31:41 +03:00
|
|
|
#include <numeric>
|
|
|
|
|
2011-05-25 10:32:00 +04:00
|
|
|
using namespace mozilla;
|
2013-08-15 08:25:58 +04:00
|
|
|
using namespace mozilla::widget;
|
2015-01-14 02:38:00 +03:00
|
|
|
using namespace mozilla::ipc;
|
2019-01-02 16:05:23 +03:00
|
|
|
using namespace mozilla::dom;
|
2015-01-14 02:38:00 +03:00
|
|
|
using namespace mozilla::layout;
|
2011-05-25 10:32:00 +04:00
|
|
|
|
2015-11-06 01:35:03 +03:00
|
|
|
static mozilla::LazyLogModule sRefreshDriverLog("nsRefreshDriver");
|
|
|
|
#define LOG(...) \
|
|
|
|
MOZ_LOG(sRefreshDriverLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
|
2012-12-12 02:15:32 +04:00
|
|
|
|
2010-08-27 08:26:23 +04:00
|
|
|
#define DEFAULT_THROTTLED_FRAME_RATE 1
|
2015-05-30 09:50:51 +03:00
|
|
|
#define DEFAULT_RECOMPUTE_VISIBILITY_INTERVAL_MS 1000
|
2016-10-28 17:24:00 +03:00
|
|
|
#define DEFAULT_NOTIFY_INTERSECTION_OBSERVERS_INTERVAL_MS 100
|
2012-12-12 02:15:32 +04:00
|
|
|
// after 10 minutes, stop firing off inactive timers
|
|
|
|
#define DEFAULT_INACTIVE_TIMER_DISABLE_SECONDS 600
|
|
|
|
|
2016-09-15 23:48:48 +03:00
|
|
|
// The number of seconds spent skipping frames because we are waiting for the
|
|
|
|
// compositor before logging.
|
2016-10-06 14:27:33 +03:00
|
|
|
#if defined(MOZ_ASAN)
|
|
|
|
# define REFRESH_WAIT_WARNING 5
|
|
|
|
#elif defined(DEBUG) && !defined(MOZ_VALGRIND)
|
|
|
|
# define REFRESH_WAIT_WARNING 5
|
|
|
|
#elif defined(DEBUG) && defined(MOZ_VALGRIND)
|
|
|
|
# define REFRESH_WAIT_WARNING (RUNNING_ON_VALGRIND ? 20 : 5)
|
|
|
|
#elif defined(MOZ_VALGRIND)
|
|
|
|
# define REFRESH_WAIT_WARNING (RUNNING_ON_VALGRIND ? 10 : 1)
|
2016-09-15 23:48:48 +03:00
|
|
|
#else
|
2016-10-06 14:27:33 +03:00
|
|
|
# define REFRESH_WAIT_WARNING 1
|
2016-09-15 23:48:48 +03:00
|
|
|
#endif
|
|
|
|
|
2015-10-30 16:35:46 +03:00
|
|
|
namespace {
|
|
|
|
// `true` if we are currently in jank-critical mode.
|
|
|
|
//
|
|
|
|
// In jank-critical mode, any iteration of the event loop that takes
|
|
|
|
// more than 16ms to compute will cause an ongoing animation to miss
|
|
|
|
// frames.
|
|
|
|
//
|
|
|
|
// For simplicity, the current implementation assumes that we are in
|
|
|
|
// jank-critical mode if and only if at least one vsync driver has
|
|
|
|
// at least one observer.
|
|
|
|
static uint64_t sActiveVsyncTimers = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-01-14 17:07:18 +03:00
|
|
|
// The latest value of process-wide jank levels.
|
|
|
|
//
|
|
|
|
// For each i, sJankLevels[i] counts the number of times delivery of
|
|
|
|
// vsync to the main thread has been delayed by at least 2^i ms. Use
|
|
|
|
// GetJankLevels to grab a copy of this array.
|
|
|
|
uint64_t sJankLevels[12];
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-06-06 16:51:15 +03:00
|
|
|
// The number outstanding nsRefreshDrivers (that have been created but not
|
|
|
|
// disconnected). When this reaches zero we will call
|
|
|
|
// nsRefreshDriver::Shutdown.
|
|
|
|
static uint32_t sRefreshDriverCount = 0;
|
2019-07-25 04:31:41 +03:00
|
|
|
|
|
|
|
// RAII-helper for recording elapsed duration for refresh tick phases.
|
|
|
|
class AutoRecordPhase {
|
|
|
|
public:
|
|
|
|
explicit AutoRecordPhase(double* aResultMs)
|
|
|
|
: mTotalMs(aResultMs), mStartTime(TimeStamp::Now()) {
|
|
|
|
MOZ_ASSERT(mTotalMs);
|
|
|
|
}
|
|
|
|
~AutoRecordPhase() {
|
|
|
|
*mTotalMs = (TimeStamp::Now() - mStartTime).ToMilliseconds();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
double* mTotalMs;
|
|
|
|
mozilla::TimeStamp mStartTime;
|
|
|
|
};
|
|
|
|
|
2015-10-30 16:35:46 +03:00
|
|
|
} // namespace
|
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The base class for all global refresh driver timers. It takes care
|
|
|
|
* of managing the list of refresh drivers attached to them and
|
|
|
|
* provides interfaces for querying/setting the rate and actually
|
|
|
|
* running a timer 'Tick'. Subclasses must implement StartTimer(),
|
|
|
|
* StopTimer(), and ScheduleNextTick() -- the first two just
|
|
|
|
* start/stop whatever timer mechanism is in use, and ScheduleNextTick
|
|
|
|
* is called at the start of the Tick() implementation to set a time
|
|
|
|
* for the next tick.
|
|
|
|
*/
|
|
|
|
class RefreshDriverTimer {
|
|
|
|
public:
|
2015-01-06 20:28:18 +03:00
|
|
|
RefreshDriverTimer() {}
|
2012-12-12 02:15:32 +04:00
|
|
|
|
2018-06-30 02:08:54 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(RefreshDriverTimer)
|
2012-12-12 02:15:32 +04:00
|
|
|
|
|
|
|
virtual void AddRefreshDriver(nsRefreshDriver* aDriver) {
|
|
|
|
LOG("[%p] AddRefreshDriver %p", this, aDriver);
|
|
|
|
|
2015-11-16 19:12:38 +03:00
|
|
|
bool startTimer =
|
|
|
|
mContentRefreshDrivers.IsEmpty() && mRootRefreshDrivers.IsEmpty();
|
|
|
|
if (IsRootRefreshDriver(aDriver)) {
|
|
|
|
NS_ASSERTION(!mRootRefreshDrivers.Contains(aDriver),
|
|
|
|
"Adding a duplicate root refresh driver!");
|
|
|
|
mRootRefreshDrivers.AppendElement(aDriver);
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(!mContentRefreshDrivers.Contains(aDriver),
|
|
|
|
"Adding a duplicate content refresh driver!");
|
|
|
|
mContentRefreshDrivers.AppendElement(aDriver);
|
|
|
|
}
|
2012-12-12 02:15:32 +04:00
|
|
|
|
2015-11-16 19:12:38 +03:00
|
|
|
if (startTimer) {
|
2012-12-12 02:15:32 +04:00
|
|
|
StartTimer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-06 04:23:49 +03:00
|
|
|
void RemoveRefreshDriver(nsRefreshDriver* aDriver) {
|
2012-12-12 02:15:32 +04:00
|
|
|
LOG("[%p] RemoveRefreshDriver %p", this, aDriver);
|
|
|
|
|
2015-11-16 19:12:38 +03:00
|
|
|
if (IsRootRefreshDriver(aDriver)) {
|
|
|
|
NS_ASSERTION(mRootRefreshDrivers.Contains(aDriver),
|
|
|
|
"RemoveRefreshDriver for a refresh driver that's not in the "
|
|
|
|
"root refresh list!");
|
|
|
|
mRootRefreshDrivers.RemoveElement(aDriver);
|
|
|
|
} else {
|
2016-10-12 14:27:38 +03:00
|
|
|
nsPresContext* pc = aDriver->GetPresContext();
|
|
|
|
nsPresContext* rootContext = pc ? pc->GetRootPresContext() : nullptr;
|
2015-11-16 19:12:38 +03:00
|
|
|
// During PresContext shutdown, we can't accurately detect
|
|
|
|
// if a root refresh driver exists or not. Therefore, we have to
|
|
|
|
// search and find out which list this driver exists in.
|
2016-01-22 04:09:04 +03:00
|
|
|
if (!rootContext) {
|
2015-11-16 19:12:38 +03:00
|
|
|
if (mRootRefreshDrivers.Contains(aDriver)) {
|
|
|
|
mRootRefreshDrivers.RemoveElement(aDriver);
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(mContentRefreshDrivers.Contains(aDriver),
|
|
|
|
"RemoveRefreshDriver without a display root for a "
|
|
|
|
"driver that is not in the content refresh list");
|
|
|
|
mContentRefreshDrivers.RemoveElement(aDriver);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(mContentRefreshDrivers.Contains(aDriver),
|
|
|
|
"RemoveRefreshDriver for a driver that is not in the "
|
|
|
|
"content refresh list");
|
|
|
|
mContentRefreshDrivers.RemoveElement(aDriver);
|
|
|
|
}
|
|
|
|
}
|
2012-12-12 02:15:32 +04:00
|
|
|
|
2015-11-16 19:12:38 +03:00
|
|
|
bool stopTimer =
|
|
|
|
mContentRefreshDrivers.IsEmpty() && mRootRefreshDrivers.IsEmpty();
|
|
|
|
if (stopTimer) {
|
2012-12-12 02:15:32 +04:00
|
|
|
StopTimer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeStamp MostRecentRefresh() const { return mLastFireTime; }
|
|
|
|
|
2015-01-14 02:38:00 +03:00
|
|
|
void SwapRefreshDrivers(RefreshDriverTimer* aNewTimer) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-11-16 19:12:38 +03:00
|
|
|
for (nsRefreshDriver* driver : mContentRefreshDrivers) {
|
|
|
|
aNewTimer->AddRefreshDriver(driver);
|
|
|
|
driver->mActiveTimer = aNewTimer;
|
|
|
|
}
|
|
|
|
mContentRefreshDrivers.Clear();
|
|
|
|
|
|
|
|
for (nsRefreshDriver* driver : mRootRefreshDrivers) {
|
2015-06-18 00:36:40 +03:00
|
|
|
aNewTimer->AddRefreshDriver(driver);
|
|
|
|
driver->mActiveTimer = aNewTimer;
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
2015-11-16 19:12:38 +03:00
|
|
|
mRootRefreshDrivers.Clear();
|
2015-01-14 02:38:00 +03:00
|
|
|
|
|
|
|
aNewTimer->mLastFireTime = mLastFireTime;
|
2017-07-29 01:01:27 +03:00
|
|
|
|
|
|
|
StopTimer();
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
2016-08-22 15:52:45 +03:00
|
|
|
virtual TimeDuration GetTimerRate() = 0;
|
|
|
|
|
2017-05-25 04:11:12 +03:00
|
|
|
TimeStamp GetIdleDeadlineHint(TimeStamp aDefault) {
|
2016-08-22 15:52:45 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
TimeStamp mostRecentRefresh = MostRecentRefresh();
|
|
|
|
TimeDuration refreshRate = GetTimerRate();
|
|
|
|
TimeStamp idleEnd = mostRecentRefresh + refreshRate;
|
|
|
|
|
|
|
|
if (idleEnd +
|
2019-08-14 22:36:46 +03:00
|
|
|
refreshRate *
|
|
|
|
StaticPrefs::layout_idle_period_required_quiescent_frames() <
|
2016-08-22 15:52:45 +03:00
|
|
|
TimeStamp::Now()) {
|
2017-05-25 04:11:12 +03:00
|
|
|
return aDefault;
|
2016-08-22 15:52:45 +03:00
|
|
|
}
|
|
|
|
|
2017-05-25 04:11:12 +03:00
|
|
|
idleEnd = idleEnd - TimeDuration::FromMilliseconds(
|
2019-08-14 22:36:46 +03:00
|
|
|
StaticPrefs::layout_idle_period_time_limit());
|
2017-05-25 04:11:12 +03:00
|
|
|
return idleEnd < aDefault ? idleEnd : aDefault;
|
2016-08-22 15:52:45 +03:00
|
|
|
}
|
|
|
|
|
2017-03-21 10:44:12 +03:00
|
|
|
Maybe<TimeStamp> GetNextTickHint() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
TimeStamp nextTick = MostRecentRefresh() + GetTimerRate();
|
|
|
|
return nextTick < TimeStamp::Now() ? Nothing() : Some(nextTick);
|
|
|
|
}
|
|
|
|
|
2019-01-30 00:54:38 +03:00
|
|
|
// Returns null if the RefreshDriverTimer is attached to several
|
|
|
|
// RefreshDrivers. That may happen for example when there are
|
|
|
|
// several windows open.
|
|
|
|
nsPresContext* GetPresContextForOnlyRefreshDriver() {
|
|
|
|
if (mRootRefreshDrivers.Length() == 1 && mContentRefreshDrivers.IsEmpty()) {
|
|
|
|
return mRootRefreshDrivers[0]->GetPresContext();
|
|
|
|
}
|
|
|
|
if (mContentRefreshDrivers.Length() == 1 && mRootRefreshDrivers.IsEmpty()) {
|
|
|
|
return mContentRefreshDrivers[0]->GetPresContext();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
protected:
|
2018-06-30 02:08:54 +03:00
|
|
|
virtual ~RefreshDriverTimer() {
|
|
|
|
MOZ_ASSERT(
|
|
|
|
mContentRefreshDrivers.Length() == 0,
|
|
|
|
"Should have removed all content refresh drivers from here by now!");
|
|
|
|
MOZ_ASSERT(
|
|
|
|
mRootRefreshDrivers.Length() == 0,
|
|
|
|
"Should have removed all root refresh drivers from here by now!");
|
|
|
|
}
|
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
virtual void StartTimer() = 0;
|
|
|
|
virtual void StopTimer() = 0;
|
|
|
|
virtual void ScheduleNextTick(TimeStamp aNowTime) = 0;
|
|
|
|
|
2015-11-16 19:12:38 +03:00
|
|
|
bool IsRootRefreshDriver(nsRefreshDriver* aDriver) {
|
2016-10-12 14:27:38 +03:00
|
|
|
nsPresContext* pc = aDriver->GetPresContext();
|
|
|
|
nsPresContext* rootContext = pc ? pc->GetRootPresContext() : nullptr;
|
2016-01-22 04:09:04 +03:00
|
|
|
if (!rootContext) {
|
2015-11-16 19:12:38 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-22 04:09:04 +03:00
|
|
|
return aDriver == rootContext->RefreshDriver();
|
2015-11-16 19:12:38 +03:00
|
|
|
}
|
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
/*
|
|
|
|
* Actually runs a tick, poking all the attached RefreshDrivers.
|
2018-07-11 00:15:00 +03:00
|
|
|
* Grabs the "now" time via TimeStamp::Now().
|
2012-12-12 02:15:32 +04:00
|
|
|
*/
|
|
|
|
void Tick() {
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
2018-12-08 02:28:03 +03:00
|
|
|
Tick(VsyncId(), now);
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
2012-12-12 02:15:32 +04:00
|
|
|
|
2018-12-08 02:28:03 +03:00
|
|
|
void TickRefreshDrivers(VsyncId aId, TimeStamp aNow,
|
2018-07-11 00:15:00 +03:00
|
|
|
nsTArray<RefPtr<nsRefreshDriver>>& aDrivers) {
|
2015-11-16 19:12:38 +03:00
|
|
|
if (aDrivers.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-05 01:15:53 +03:00
|
|
|
nsTArray<RefPtr<nsRefreshDriver>> drivers(aDrivers);
|
2015-11-16 19:12:38 +03:00
|
|
|
for (nsRefreshDriver* driver : drivers) {
|
|
|
|
// don't poke this driver if it's in test mode
|
|
|
|
if (driver->IsTestControllingRefreshesEnabled()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-12-08 02:28:03 +03:00
|
|
|
TickDriver(driver, aId, aNow);
|
2015-11-16 19:12:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-14 02:38:00 +03:00
|
|
|
/*
|
|
|
|
* Tick the refresh drivers based on the given timestamp.
|
|
|
|
*/
|
2018-12-08 02:28:03 +03:00
|
|
|
void Tick(VsyncId aId, TimeStamp now) {
|
2012-12-12 02:15:32 +04:00
|
|
|
ScheduleNextTick(now);
|
|
|
|
|
|
|
|
mLastFireTime = now;
|
|
|
|
|
|
|
|
LOG("[%p] ticking drivers...", this);
|
2014-04-22 22:13:00 +04:00
|
|
|
// RD is short for RefreshDriver
|
2019-01-18 18:40:15 +03:00
|
|
|
AUTO_PROFILER_TRACING("Paint", "RefreshDriverTick", GRAPHICS);
|
2012-12-12 02:15:32 +04:00
|
|
|
|
2018-12-08 02:28:03 +03:00
|
|
|
TickRefreshDrivers(aId, now, mContentRefreshDrivers);
|
|
|
|
TickRefreshDrivers(aId, now, mRootRefreshDrivers);
|
2015-11-16 19:12:38 +03:00
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
LOG("[%p] done.", this);
|
|
|
|
}
|
|
|
|
|
2018-12-08 02:28:03 +03:00
|
|
|
static void TickDriver(nsRefreshDriver* driver, VsyncId aId, TimeStamp now) {
|
|
|
|
driver->Tick(aId, now);
|
2012-12-12 02:15:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TimeStamp mLastFireTime;
|
|
|
|
TimeStamp mTargetTime;
|
|
|
|
|
2018-02-05 01:15:53 +03:00
|
|
|
nsTArray<RefPtr<nsRefreshDriver>> mContentRefreshDrivers;
|
|
|
|
nsTArray<RefPtr<nsRefreshDriver>> mRootRefreshDrivers;
|
2012-12-12 02:15:32 +04:00
|
|
|
|
|
|
|
// useful callback for nsITimer-based derived classes, here
|
2018-06-30 02:08:54 +03:00
|
|
|
// because of c++ protected shenanigans
|
2012-12-12 02:15:32 +04:00
|
|
|
static void TimerTick(nsITimer* aTimer, void* aClosure) {
|
2018-06-30 02:08:54 +03:00
|
|
|
RefPtr<RefreshDriverTimer> timer =
|
|
|
|
static_cast<RefreshDriverTimer*>(aClosure);
|
2012-12-12 02:15:32 +04:00
|
|
|
timer->Tick();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A RefreshDriverTimer that uses a nsITimer as the underlying timer. Note that
|
|
|
|
* this is a ONE_SHOT timer, not a repeating one! Subclasses are expected to
|
|
|
|
* implement ScheduleNextTick and intelligently calculate the next time to tick,
|
|
|
|
* and to reset mTimer. Using a repeating nsITimer gets us into a lot of pain
|
|
|
|
* with its attempt at intelligent slack removal and such, so we don't do it.
|
|
|
|
*/
|
|
|
|
class SimpleTimerBasedRefreshDriverTimer : public RefreshDriverTimer {
|
|
|
|
public:
|
2015-01-06 20:28:18 +03:00
|
|
|
/*
|
|
|
|
* aRate -- the delay, in milliseconds, requested between timer firings
|
|
|
|
*/
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit SimpleTimerBasedRefreshDriverTimer(double aRate) {
|
2015-01-06 20:28:18 +03:00
|
|
|
SetRate(aRate);
|
2017-10-16 09:13:31 +03:00
|
|
|
mTimer = NS_NewTimer();
|
2012-12-12 02:15:32 +04:00
|
|
|
}
|
|
|
|
|
2017-07-29 01:01:27 +03:00
|
|
|
virtual ~SimpleTimerBasedRefreshDriverTimer() override { StopTimer(); }
|
2012-12-12 02:15:32 +04:00
|
|
|
|
2015-01-06 20:28:18 +03:00
|
|
|
// will take effect at next timer tick
|
|
|
|
virtual void SetRate(double aNewRate) {
|
|
|
|
mRateMilliseconds = aNewRate;
|
|
|
|
mRateDuration = TimeDuration::FromMilliseconds(mRateMilliseconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
double GetRate() const { return mRateMilliseconds; }
|
2016-08-22 15:52:45 +03:00
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
TimeDuration GetTimerRate() override { return mRateDuration; }
|
|
|
|
|
|
|
|
protected:
|
2016-11-09 16:37:59 +03:00
|
|
|
void StartTimer() override {
|
2012-12-24 04:29:23 +04:00
|
|
|
// pretend we just fired, and we schedule the next tick normally
|
2012-12-12 02:15:32 +04:00
|
|
|
mLastFireTime = TimeStamp::Now();
|
|
|
|
|
2012-12-24 04:29:23 +04:00
|
|
|
mTargetTime = mLastFireTime + mRateDuration;
|
|
|
|
|
|
|
|
uint32_t delay = static_cast<uint32_t>(mRateMilliseconds);
|
2017-06-12 22:34:10 +03:00
|
|
|
mTimer->InitWithNamedFuncCallback(
|
|
|
|
TimerTick, this, delay, nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"SimpleTimerBasedRefreshDriverTimer::StartTimer");
|
2012-12-12 02:15:32 +04:00
|
|
|
}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
void StopTimer() override { mTimer->Cancel(); }
|
2012-12-12 02:15:32 +04:00
|
|
|
|
2015-01-06 20:28:18 +03:00
|
|
|
double mRateMilliseconds;
|
|
|
|
TimeDuration mRateDuration;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsITimer> mTimer;
|
2012-12-12 02:15:32 +04:00
|
|
|
};
|
|
|
|
|
2015-01-14 02:38:00 +03:00
|
|
|
/*
|
|
|
|
* A refresh driver that listens to vsync events and ticks the refresh driver
|
|
|
|
* on vsync intervals. We throttle the refresh driver if we get too many
|
|
|
|
* vsync events and wait to catch up again.
|
|
|
|
*/
|
|
|
|
class VsyncRefreshDriverTimer : public RefreshDriverTimer {
|
|
|
|
public:
|
|
|
|
VsyncRefreshDriverTimer() : mVsyncChild(nullptr) {
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mVsyncObserver = new RefreshDriverVsyncObserver(this);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::gfx::VsyncSource> vsyncSource =
|
|
|
|
gfxPlatform::GetPlatform()->GetHardwareVsync();
|
2015-01-14 02:38:00 +03:00
|
|
|
MOZ_ALWAYS_TRUE(mVsyncDispatcher =
|
|
|
|
vsyncSource->GetRefreshTimerVsyncDispatcher());
|
2019-11-27 03:21:33 +03:00
|
|
|
mVsyncDispatcher->AddChildRefreshTimer(mVsyncObserver);
|
2016-08-22 15:52:45 +03:00
|
|
|
mVsyncRate = vsyncSource->GetGlobalDisplay().GetVsyncRate();
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
explicit VsyncRefreshDriverTimer(VsyncChild* aVsyncChild)
|
|
|
|
: mVsyncChild(aVsyncChild) {
|
|
|
|
MOZ_ASSERT(!XRE_IsParentProcess());
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mVsyncChild);
|
|
|
|
mVsyncObserver = new RefreshDriverVsyncObserver(this);
|
|
|
|
mVsyncChild->SetVsyncObserver(mVsyncObserver);
|
2016-08-22 15:52:45 +03:00
|
|
|
mVsyncRate = mVsyncChild->GetVsyncRate();
|
|
|
|
}
|
|
|
|
|
2019-11-27 03:21:33 +03:00
|
|
|
explicit VsyncRefreshDriverTimer(const RefPtr<gfx::VsyncSource>& aVsyncSource)
|
|
|
|
: mVsyncChild(nullptr) {
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mVsyncSource = aVsyncSource;
|
|
|
|
mVsyncObserver = new RefreshDriverVsyncObserver(this);
|
|
|
|
MOZ_ALWAYS_TRUE(mVsyncDispatcher =
|
|
|
|
aVsyncSource->GetRefreshTimerVsyncDispatcher());
|
|
|
|
mVsyncDispatcher->AddChildRefreshTimer(mVsyncObserver);
|
|
|
|
mVsyncRate = aVsyncSource->GetGlobalDisplay().GetVsyncRate();
|
|
|
|
}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
TimeDuration GetTimerRate() override {
|
2016-08-22 15:52:45 +03:00
|
|
|
if (mVsyncRate != TimeDuration::Forever()) {
|
|
|
|
return mVsyncRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mVsyncChild) {
|
2016-11-10 12:01:51 +03:00
|
|
|
// VsyncChild::VsyncRate() is a simple getter for the cached
|
|
|
|
// hardware vsync rate. We depend on that
|
|
|
|
// VsyncChild::GetVsyncRate() being called in the constructor
|
|
|
|
// will result in a response with the actual vsync rate sooner
|
|
|
|
// or later. Until that happens VsyncChild::VsyncRate() returns
|
|
|
|
// TimeDuration::Forever() and we have to guess below.
|
|
|
|
mVsyncRate = mVsyncChild->VsyncRate();
|
2016-08-22 15:52:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// If hardware queries fail / are unsupported, we have to just guess.
|
|
|
|
return mVsyncRate != TimeDuration::Forever()
|
|
|
|
? mVsyncRate
|
|
|
|
: TimeDuration::FromMilliseconds(1000.0 / 60.0);
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Since VsyncObservers are refCounted, but the RefreshDriverTimer are
|
|
|
|
// explicitly shutdown. We create an inner class that has the VsyncObserver
|
2018-06-30 02:08:54 +03:00
|
|
|
// and is shutdown when the RefreshDriverTimer is deleted.
|
2015-03-21 19:28:04 +03:00
|
|
|
class RefreshDriverVsyncObserver final : public VsyncObserver {
|
2015-01-14 02:38:00 +03:00
|
|
|
public:
|
|
|
|
explicit RefreshDriverVsyncObserver(
|
|
|
|
VsyncRefreshDriverTimer* aVsyncRefreshDriverTimer)
|
|
|
|
: mVsyncRefreshDriverTimer(aVsyncRefreshDriverTimer),
|
2015-01-30 04:41:03 +03:00
|
|
|
mRefreshTickLock("RefreshTickLock"),
|
2015-11-06 19:20:58 +03:00
|
|
|
mRecentVsync(TimeStamp::Now()),
|
|
|
|
mLastChildTick(TimeStamp::Now()),
|
|
|
|
mVsyncRate(TimeDuration::Forever()),
|
2015-01-30 04:41:03 +03:00
|
|
|
mProcessedVsync(true) {
|
2015-01-14 02:38:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
2017-04-12 12:53:48 +03:00
|
|
|
class ParentProcessVsyncNotifier final : public Runnable,
|
|
|
|
public nsIRunnablePriority {
|
|
|
|
public:
|
|
|
|
ParentProcessVsyncNotifier(RefreshDriverVsyncObserver* aObserver,
|
2018-12-08 02:28:03 +03:00
|
|
|
VsyncId aId, TimeStamp aVsyncTimestamp)
|
2017-06-12 22:34:10 +03:00
|
|
|
: Runnable(
|
|
|
|
"VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::"
|
|
|
|
"ParentProcessVsyncNotifier"),
|
|
|
|
mObserver(aObserver),
|
2018-12-08 02:28:03 +03:00
|
|
|
mId(aId),
|
2017-06-12 22:34:10 +03:00
|
|
|
mVsyncTimestamp(aVsyncTimestamp) {}
|
2017-04-12 12:53:48 +03:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
NS_IMETHOD Run() override {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2019-08-22 00:54:58 +03:00
|
|
|
sHighPriorityEnabled = mozilla::BrowserTabsRemoteAutostart();
|
2017-04-12 12:53:48 +03:00
|
|
|
|
2018-12-08 02:28:03 +03:00
|
|
|
mObserver->TickRefreshDriver(mId, mVsyncTimestamp);
|
2017-04-12 12:53:48 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD GetPriority(uint32_t* aPriority) override {
|
|
|
|
*aPriority = sHighPriorityEnabled
|
|
|
|
? nsIRunnablePriority::PRIORITY_HIGH
|
|
|
|
: nsIRunnablePriority::PRIORITY_NORMAL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~ParentProcessVsyncNotifier() {}
|
|
|
|
RefPtr<RefreshDriverVsyncObserver> mObserver;
|
2018-12-08 02:28:03 +03:00
|
|
|
VsyncId mId;
|
2017-04-12 12:53:48 +03:00
|
|
|
TimeStamp mVsyncTimestamp;
|
|
|
|
static mozilla::Atomic<bool> sHighPriorityEnabled;
|
|
|
|
};
|
|
|
|
|
2018-12-08 02:27:28 +03:00
|
|
|
bool NotifyVsync(const VsyncEvent& aVsync) override {
|
2018-06-30 02:08:54 +03:00
|
|
|
// IMPORTANT: All paths through this method MUST hold a strong ref on
|
|
|
|
// |this| for the duration of the TickRefreshDriver callback.
|
|
|
|
|
2015-01-14 02:38:00 +03:00
|
|
|
if (!NS_IsMainThread()) {
|
2015-01-30 04:41:03 +03:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
// Compress vsync notifications such that only 1 may run at a time
|
|
|
|
// This is so that we don't flood the refresh driver with vsync messages
|
|
|
|
// if the main thread is blocked for long periods of time
|
|
|
|
{ // scope lock
|
|
|
|
MonitorAutoLock lock(mRefreshTickLock);
|
2018-12-08 02:27:28 +03:00
|
|
|
mRecentVsync = aVsync.mTime;
|
2018-12-08 02:28:03 +03:00
|
|
|
mRecentVsyncId = aVsync.mId;
|
2015-01-30 04:41:03 +03:00
|
|
|
if (!mProcessedVsync) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
mProcessedVsync = false;
|
|
|
|
}
|
|
|
|
|
2015-01-14 02:38:00 +03:00
|
|
|
nsCOMPtr<nsIRunnable> vsyncEvent =
|
2018-12-08 02:28:03 +03:00
|
|
|
new ParentProcessVsyncNotifier(this, aVsync.mId, aVsync.mTime);
|
2015-01-14 02:38:00 +03:00
|
|
|
NS_DispatchToMainThread(vsyncEvent);
|
|
|
|
} else {
|
2018-12-08 02:27:28 +03:00
|
|
|
mRecentVsync = aVsync.mTime;
|
2018-12-08 02:28:03 +03:00
|
|
|
mRecentVsyncId = aVsync.mId;
|
2018-12-08 02:27:28 +03:00
|
|
|
if (!mBlockUntil.IsNull() && mBlockUntil > aVsync.mTime) {
|
2017-02-16 19:50:44 +03:00
|
|
|
if (mProcessedVsync) {
|
|
|
|
// Re-post vsync update as a normal priority runnable. This way
|
|
|
|
// runnables already in normal priority queue get processed.
|
|
|
|
mProcessedVsync = false;
|
|
|
|
nsCOMPtr<nsIRunnable> vsyncEvent = NewRunnableMethod<>(
|
2017-05-10 02:19:37 +03:00
|
|
|
"RefreshDriverVsyncObserver::NormalPriorityNotify", this,
|
2017-02-16 19:50:44 +03:00
|
|
|
&RefreshDriverVsyncObserver::NormalPriorityNotify);
|
|
|
|
NS_DispatchToMainThread(vsyncEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-30 00:54:38 +03:00
|
|
|
if (StaticPrefs::layout_lower_priority_refresh_driver_during_load()) {
|
|
|
|
nsPresContext* pctx =
|
|
|
|
mVsyncRefreshDriverTimer->GetPresContextForOnlyRefreshDriver();
|
|
|
|
if (pctx && pctx->HadContentfulPaint() && pctx->Document() &&
|
|
|
|
pctx->Document()->GetReadyStateEnum() <
|
|
|
|
Document::READYSTATE_COMPLETE) {
|
|
|
|
nsPIDOMWindowInner* win = pctx->Document()->GetInnerWindow();
|
2019-03-26 23:47:50 +03:00
|
|
|
uint32_t frameRateMultiplier = pctx->GetNextFrameRateMultiplier();
|
|
|
|
if (!frameRateMultiplier) {
|
|
|
|
pctx->DidUseFrameRateMultiplier();
|
|
|
|
}
|
|
|
|
if (win && frameRateMultiplier) {
|
2019-01-30 00:54:38 +03:00
|
|
|
dom::Performance* perf = win->GetPerformance();
|
|
|
|
// Limit slower refresh rate to 5 seconds between the
|
|
|
|
// first contentful paint and page load.
|
2019-08-02 11:52:42 +03:00
|
|
|
if (perf &&
|
|
|
|
perf->Now() <
|
|
|
|
StaticPrefs::page_load_deprioritization_period()) {
|
2019-01-30 00:54:38 +03:00
|
|
|
if (mProcessedVsync) {
|
|
|
|
mProcessedVsync = false;
|
|
|
|
// Handle this case similarly to the code above, but just
|
|
|
|
// use idle queue.
|
|
|
|
TimeDuration rate = mVsyncRefreshDriverTimer->GetTimerRate();
|
2019-03-26 23:47:50 +03:00
|
|
|
uint32_t slowRate = static_cast<uint32_t>(
|
|
|
|
rate.ToMilliseconds() * frameRateMultiplier);
|
|
|
|
pctx->DidUseFrameRateMultiplier();
|
2019-01-30 00:54:38 +03:00
|
|
|
nsCOMPtr<nsIRunnable> vsyncEvent = NewRunnableMethod<>(
|
|
|
|
"RefreshDriverVsyncObserver::NormalPriorityNotify[IDLE]",
|
|
|
|
this, &RefreshDriverVsyncObserver::NormalPriorityNotify);
|
|
|
|
NS_DispatchToCurrentThreadQueue(vsyncEvent.forget(), slowRate,
|
|
|
|
EventQueuePriority::Idle);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-30 02:08:54 +03:00
|
|
|
RefPtr<RefreshDriverVsyncObserver> kungFuDeathGrip(this);
|
2018-12-08 02:28:03 +03:00
|
|
|
TickRefreshDriver(aVsync.mId, aVsync.mTime);
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
mVsyncRefreshDriverTimer = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-11-06 19:20:58 +03:00
|
|
|
void OnTimerStart() {
|
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
mLastChildTick = TimeStamp::Now();
|
|
|
|
}
|
|
|
|
}
|
2017-02-16 19:50:44 +03:00
|
|
|
|
|
|
|
void NormalPriorityNotify() {
|
|
|
|
if (mLastProcessedTickInChildProcess.IsNull() ||
|
|
|
|
mRecentVsync > mLastProcessedTickInChildProcess) {
|
|
|
|
// mBlockUntil is for high priority vsync notifications only.
|
|
|
|
mBlockUntil = TimeStamp();
|
2018-12-08 02:28:03 +03:00
|
|
|
TickRefreshDriver(mRecentVsyncId, mRecentVsync);
|
2017-02-16 19:50:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mProcessedVsync = true;
|
|
|
|
}
|
|
|
|
|
2015-01-14 02:38:00 +03:00
|
|
|
private:
|
2016-11-09 16:35:40 +03:00
|
|
|
~RefreshDriverVsyncObserver() = default;
|
2015-01-14 02:38:00 +03:00
|
|
|
|
2015-11-06 19:20:58 +03:00
|
|
|
void RecordTelemetryProbes(TimeStamp aVsyncTimestamp) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
#ifndef ANDROID /* bug 1142079 */
|
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
TimeDuration vsyncLatency = TimeStamp::Now() - aVsyncTimestamp;
|
2015-12-16 21:06:40 +03:00
|
|
|
uint32_t sample = (uint32_t)vsyncLatency.ToMilliseconds();
|
2015-11-06 19:20:58 +03:00
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::FX_REFRESH_DRIVER_CHROME_FRAME_DELAY_MS, sample);
|
2015-12-16 21:06:40 +03:00
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::FX_REFRESH_DRIVER_SYNC_SCROLL_FRAME_DELAY_MS, sample);
|
2016-01-14 17:07:18 +03:00
|
|
|
RecordJank(sample);
|
2015-11-06 19:20:58 +03:00
|
|
|
} else if (mVsyncRate != TimeDuration::Forever()) {
|
|
|
|
TimeDuration contentDelay =
|
|
|
|
(TimeStamp::Now() - mLastChildTick) - mVsyncRate;
|
2015-11-17 03:21:04 +03:00
|
|
|
if (contentDelay.ToMilliseconds() < 0) {
|
|
|
|
// Vsyncs are noisy and some can come at a rate quicker than
|
|
|
|
// the reported hardware rate. In those cases, consider that we have 0
|
|
|
|
// delay.
|
|
|
|
contentDelay = TimeDuration::FromMilliseconds(0);
|
|
|
|
}
|
2015-12-16 21:06:40 +03:00
|
|
|
uint32_t sample = (uint32_t)contentDelay.ToMilliseconds();
|
2015-11-06 19:20:58 +03:00
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::FX_REFRESH_DRIVER_CONTENT_FRAME_DELAY_MS, sample);
|
2015-12-16 21:06:40 +03:00
|
|
|
Telemetry::Accumulate(
|
|
|
|
Telemetry::FX_REFRESH_DRIVER_SYNC_SCROLL_FRAME_DELAY_MS, sample);
|
2016-01-14 17:07:18 +03:00
|
|
|
RecordJank(sample);
|
2015-11-06 19:20:58 +03:00
|
|
|
} else {
|
|
|
|
// Request the vsync rate from the parent process. Might be a few vsyncs
|
|
|
|
// until the parent responds.
|
2017-02-20 11:24:46 +03:00
|
|
|
if (mVsyncRefreshDriverTimer) {
|
|
|
|
mVsyncRate = mVsyncRefreshDriverTimer->mVsyncChild->GetVsyncRate();
|
|
|
|
}
|
2015-11-06 19:20:58 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-01-14 17:07:18 +03:00
|
|
|
void RecordJank(uint32_t aJankMS) {
|
|
|
|
uint32_t duration = 1 /* ms */;
|
|
|
|
for (size_t i = 0;
|
|
|
|
i < mozilla::ArrayLength(sJankLevels) && duration < aJankMS;
|
|
|
|
++i, duration *= 2) {
|
|
|
|
sJankLevels[i]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-08 02:28:03 +03:00
|
|
|
void TickRefreshDriver(VsyncId aId, TimeStamp aVsyncTimestamp) {
|
2015-01-14 02:38:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-11-06 19:20:58 +03:00
|
|
|
RecordTelemetryProbes(aVsyncTimestamp);
|
2015-01-30 04:41:03 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
MonitorAutoLock lock(mRefreshTickLock);
|
|
|
|
aVsyncTimestamp = mRecentVsync;
|
2015-11-14 00:47:34 +03:00
|
|
|
mProcessedVsync = true;
|
2015-11-06 19:20:58 +03:00
|
|
|
} else {
|
|
|
|
mLastChildTick = TimeStamp::Now();
|
2017-02-16 19:50:44 +03:00
|
|
|
mLastProcessedTickInChildProcess = aVsyncTimestamp;
|
2015-01-30 04:41:03 +03:00
|
|
|
}
|
2018-09-18 21:05:48 +03:00
|
|
|
|
2019-03-07 17:24:23 +03:00
|
|
|
// On 32-bit Windows we sometimes get times where TimeStamp::Now() is not
|
|
|
|
// monotonic because the underlying system apis produce non-monontonic
|
|
|
|
// results. (bug 1306896)
|
|
|
|
#if !defined(_WIN32)
|
2018-09-18 21:05:48 +03:00
|
|
|
// Do not compare timestamps unless they are both canonical or fuzzy
|
|
|
|
DebugOnly<TimeStamp> rightnow = TimeStamp::Now();
|
|
|
|
MOZ_ASSERT_IF(
|
|
|
|
(*&rightnow).UsedCanonicalNow() == aVsyncTimestamp.UsedCanonicalNow(),
|
|
|
|
aVsyncTimestamp <= *&rightnow);
|
2019-03-07 17:24:23 +03:00
|
|
|
#endif
|
2015-01-30 04:41:03 +03:00
|
|
|
|
2015-01-14 02:38:00 +03:00
|
|
|
// We might have a problem that we call ~VsyncRefreshDriverTimer() before
|
|
|
|
// the scheduled TickRefreshDriver() runs. Check mVsyncRefreshDriverTimer
|
|
|
|
// before use.
|
|
|
|
if (mVsyncRefreshDriverTimer) {
|
2018-06-30 02:08:54 +03:00
|
|
|
RefPtr<VsyncRefreshDriverTimer> timer = mVsyncRefreshDriverTimer;
|
2018-12-08 02:28:03 +03:00
|
|
|
timer->RunRefreshDrivers(aId, aVsyncTimestamp);
|
2018-06-30 02:08:54 +03:00
|
|
|
// Note: mVsyncRefreshDriverTimer might be null now.
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
2017-02-11 17:42:20 +03:00
|
|
|
|
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
TimeDuration tickDuration = TimeStamp::Now() - mLastChildTick;
|
|
|
|
mBlockUntil = aVsyncTimestamp + tickDuration;
|
|
|
|
}
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// VsyncRefreshDriverTimer holds this RefreshDriverVsyncObserver and it will
|
|
|
|
// be always available before Shutdown(). We can just use the raw pointer
|
|
|
|
// here.
|
|
|
|
VsyncRefreshDriverTimer* mVsyncRefreshDriverTimer;
|
2015-01-30 04:41:03 +03:00
|
|
|
Monitor mRefreshTickLock;
|
|
|
|
TimeStamp mRecentVsync;
|
2018-12-08 02:28:03 +03:00
|
|
|
VsyncId mRecentVsyncId;
|
2015-11-06 19:20:58 +03:00
|
|
|
TimeStamp mLastChildTick;
|
2017-02-16 19:50:44 +03:00
|
|
|
TimeStamp mLastProcessedTickInChildProcess;
|
2017-02-11 17:42:20 +03:00
|
|
|
TimeStamp mBlockUntil;
|
2015-11-06 19:20:58 +03:00
|
|
|
TimeDuration mVsyncRate;
|
2015-01-30 04:41:03 +03:00
|
|
|
bool mProcessedVsync;
|
2015-01-14 02:38:00 +03:00
|
|
|
}; // RefreshDriverVsyncObserver
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
~VsyncRefreshDriverTimer() override {
|
2015-01-14 02:38:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2019-11-27 03:21:33 +03:00
|
|
|
mVsyncDispatcher->RemoveChildRefreshTimer(mVsyncObserver);
|
2015-01-14 02:38:00 +03:00
|
|
|
mVsyncDispatcher = nullptr;
|
|
|
|
} else {
|
|
|
|
// Since the PVsyncChild actors live through the life of the process, just
|
|
|
|
// send the unobserveVsync message to disable vsync event. We don't need
|
|
|
|
// to handle the cleanup stuff of this actor. PVsyncChild::ActorDestroy()
|
|
|
|
// will be called and clean up this actor.
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mVsyncChild->SendUnobserve();
|
2015-01-14 02:38:00 +03:00
|
|
|
mVsyncChild->SetVsyncObserver(nullptr);
|
|
|
|
mVsyncChild = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Detach current vsync timer from this VsyncObserver. The observer will no
|
|
|
|
// longer tick this timer.
|
|
|
|
mVsyncObserver->Shutdown();
|
|
|
|
mVsyncObserver = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
void StartTimer() override {
|
2015-10-30 16:35:46 +03:00
|
|
|
// Protect updates to `sActiveVsyncTimers`.
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-01-14 02:38:00 +03:00
|
|
|
mLastFireTime = TimeStamp::Now();
|
|
|
|
|
|
|
|
if (XRE_IsParentProcess()) {
|
2019-11-27 03:21:33 +03:00
|
|
|
mVsyncDispatcher->AddChildRefreshTimer(mVsyncObserver);
|
2015-01-14 02:38:00 +03:00
|
|
|
} else {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mVsyncChild->SendObserve();
|
2015-11-06 19:20:58 +03:00
|
|
|
mVsyncObserver->OnTimerStart();
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
2015-10-30 16:35:46 +03:00
|
|
|
|
|
|
|
++sActiveVsyncTimers;
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
void StopTimer() override {
|
2015-10-30 16:35:46 +03:00
|
|
|
// Protect updates to `sActiveVsyncTimers`.
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-01-14 02:38:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2019-11-27 03:21:33 +03:00
|
|
|
mVsyncDispatcher->RemoveChildRefreshTimer(mVsyncObserver);
|
2015-01-14 02:38:00 +03:00
|
|
|
} else {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mVsyncChild->SendUnobserve();
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
2015-10-30 16:35:46 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(sActiveVsyncTimers > 0);
|
|
|
|
--sActiveVsyncTimers;
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
void ScheduleNextTick(TimeStamp aNowTime) override {
|
2015-01-14 02:38:00 +03:00
|
|
|
// Do nothing since we just wait for the next vsync from
|
|
|
|
// RefreshDriverVsyncObserver.
|
|
|
|
}
|
|
|
|
|
2018-12-08 02:28:03 +03:00
|
|
|
void RunRefreshDrivers(VsyncId aId, TimeStamp aTimeStamp) {
|
|
|
|
Tick(aId, aTimeStamp);
|
|
|
|
}
|
2015-01-14 02:38:00 +03:00
|
|
|
|
2019-11-27 03:21:33 +03:00
|
|
|
// Used to hold external vsync sources alive. Must be destroyed *after*
|
|
|
|
// mVsyncDispatcher.
|
|
|
|
RefPtr<gfx::VsyncSource> mVsyncSource;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<RefreshDriverVsyncObserver> mVsyncObserver;
|
2015-01-30 00:19:00 +03:00
|
|
|
// Used for parent process.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<RefreshTimerVsyncDispatcher> mVsyncDispatcher;
|
2015-01-30 00:19:00 +03:00
|
|
|
// Used for child process.
|
|
|
|
// The mVsyncChild will be always available before VsncChild::ActorDestroy().
|
|
|
|
// After ActorDestroy(), StartTimer() and StopTimer() calls will be non-op.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<VsyncChild> mVsyncChild;
|
2016-08-22 15:52:45 +03:00
|
|
|
TimeDuration mVsyncRate;
|
2015-01-14 02:38:00 +03:00
|
|
|
}; // VsyncRefreshDriverTimer
|
|
|
|
|
2017-04-12 12:53:48 +03:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(
|
|
|
|
VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::
|
|
|
|
ParentProcessVsyncNotifier,
|
|
|
|
Runnable, nsIRunnablePriority)
|
|
|
|
|
|
|
|
mozilla::Atomic<bool> VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::
|
|
|
|
ParentProcessVsyncNotifier::sHighPriorityEnabled(false);
|
|
|
|
|
2015-08-26 16:45:54 +03:00
|
|
|
/**
|
|
|
|
* Since the content process takes some time to setup
|
|
|
|
* the vsync IPC connection, this timer is used
|
|
|
|
* during the intial startup process.
|
|
|
|
* During initial startup, the refresh drivers
|
|
|
|
* are ticked off this timer, and are swapped out once content
|
|
|
|
* vsync IPC connection is established.
|
2012-12-12 02:15:32 +04:00
|
|
|
*/
|
|
|
|
class StartupRefreshDriverTimer : public SimpleTimerBasedRefreshDriverTimer {
|
|
|
|
public:
|
2015-08-26 16:45:54 +03:00
|
|
|
explicit StartupRefreshDriverTimer(double aRate)
|
2012-12-12 02:15:32 +04:00
|
|
|
: SimpleTimerBasedRefreshDriverTimer(aRate) {}
|
|
|
|
|
|
|
|
protected:
|
2016-11-09 16:37:59 +03:00
|
|
|
void ScheduleNextTick(TimeStamp aNowTime) override {
|
2015-08-26 16:45:54 +03:00
|
|
|
// Since this is only used for startup, it isn't super critical
|
|
|
|
// that we tick at consistent intervals.
|
|
|
|
TimeStamp newTarget = aNowTime + mRateDuration;
|
2012-12-12 02:15:32 +04:00
|
|
|
uint32_t delay =
|
|
|
|
static_cast<uint32_t>((newTarget - aNowTime).ToMilliseconds());
|
2017-06-12 22:34:10 +03:00
|
|
|
mTimer->InitWithNamedFuncCallback(
|
|
|
|
TimerTick, this, delay, nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"StartupRefreshDriverTimer::ScheduleNextTick");
|
2012-12-12 02:15:32 +04:00
|
|
|
mTargetTime = newTarget;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A RefreshDriverTimer for inactive documents. When a new refresh driver is
|
|
|
|
* added, the rate is reset to the base (normally 1s/1fps). Every time
|
|
|
|
* it ticks, a single refresh driver is poked. Once they have all been poked,
|
|
|
|
* the duration between ticks doubles, up to mDisableAfterMilliseconds. At that
|
|
|
|
* point, the timer is quiet and doesn't tick (until something is added to it
|
|
|
|
* again).
|
|
|
|
*
|
|
|
|
* When a timer is removed, there is a possibility of another timer
|
|
|
|
* being skipped for one cycle. We could avoid this by adjusting
|
|
|
|
* mNextDriverIndex in RemoveRefreshDriver, but there's little need to
|
|
|
|
* add that complexity. All we want is for inactive drivers to tick
|
|
|
|
* at some point, but we don't care too much about how often.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class InactiveRefreshDriverTimer final
|
2015-01-06 20:28:18 +03:00
|
|
|
: public SimpleTimerBasedRefreshDriverTimer {
|
2012-12-12 02:15:32 +04:00
|
|
|
public:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit InactiveRefreshDriverTimer(double aRate)
|
2015-01-06 20:28:18 +03:00
|
|
|
: SimpleTimerBasedRefreshDriverTimer(aRate),
|
2012-12-12 02:15:32 +04:00
|
|
|
mNextTickDuration(aRate),
|
|
|
|
mDisableAfterMilliseconds(-1.0),
|
|
|
|
mNextDriverIndex(0) {}
|
|
|
|
|
|
|
|
InactiveRefreshDriverTimer(double aRate, double aDisableAfterMilliseconds)
|
2015-01-06 20:28:18 +03:00
|
|
|
: SimpleTimerBasedRefreshDriverTimer(aRate),
|
2012-12-12 02:15:32 +04:00
|
|
|
mNextTickDuration(aRate),
|
|
|
|
mDisableAfterMilliseconds(aDisableAfterMilliseconds),
|
|
|
|
mNextDriverIndex(0) {}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
void AddRefreshDriver(nsRefreshDriver* aDriver) override {
|
2012-12-12 02:15:32 +04:00
|
|
|
RefreshDriverTimer::AddRefreshDriver(aDriver);
|
|
|
|
|
|
|
|
LOG("[%p] inactive timer got new refresh driver %p, resetting rate", this,
|
|
|
|
aDriver);
|
|
|
|
|
|
|
|
// reset the timer, and start with the newly added one next time.
|
|
|
|
mNextTickDuration = mRateMilliseconds;
|
|
|
|
|
|
|
|
// we don't really have to start with the newly added one, but we may as
|
|
|
|
// well not tick the old ones at the fastest rate any more than we need to.
|
2015-11-16 19:12:38 +03:00
|
|
|
mNextDriverIndex = GetRefreshDriverCount() - 1;
|
2012-12-12 02:15:32 +04:00
|
|
|
|
|
|
|
StopTimer();
|
|
|
|
StartTimer();
|
|
|
|
}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
TimeDuration GetTimerRate() override {
|
2016-08-22 15:52:45 +03:00
|
|
|
return TimeDuration::FromMilliseconds(mNextTickDuration);
|
|
|
|
}
|
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
protected:
|
2015-11-16 19:12:38 +03:00
|
|
|
uint32_t GetRefreshDriverCount() {
|
|
|
|
return mContentRefreshDrivers.Length() + mRootRefreshDrivers.Length();
|
|
|
|
}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
void StartTimer() override {
|
2012-12-12 02:15:32 +04:00
|
|
|
mLastFireTime = TimeStamp::Now();
|
|
|
|
|
2012-12-24 04:29:23 +04:00
|
|
|
mTargetTime = mLastFireTime + mRateDuration;
|
|
|
|
|
|
|
|
uint32_t delay = static_cast<uint32_t>(mRateMilliseconds);
|
2017-06-12 22:34:10 +03:00
|
|
|
mTimer->InitWithNamedFuncCallback(TimerTickOne, this, delay,
|
|
|
|
nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"InactiveRefreshDriverTimer::StartTimer");
|
2012-12-12 02:15:32 +04:00
|
|
|
}
|
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
void StopTimer() override { mTimer->Cancel(); }
|
2012-12-12 02:15:32 +04:00
|
|
|
|
2016-11-09 16:37:59 +03:00
|
|
|
void ScheduleNextTick(TimeStamp aNowTime) override {
|
2012-12-12 02:15:32 +04:00
|
|
|
if (mDisableAfterMilliseconds > 0.0 &&
|
|
|
|
mNextTickDuration > mDisableAfterMilliseconds) {
|
|
|
|
// We hit the time after which we should disable
|
|
|
|
// inactive window refreshes; don't schedule anything
|
|
|
|
// until we get kicked by an AddRefreshDriver call.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// double the next tick time if we've already gone through all of them once
|
2015-11-16 19:12:38 +03:00
|
|
|
if (mNextDriverIndex >= GetRefreshDriverCount()) {
|
2012-12-12 02:15:32 +04:00
|
|
|
mNextTickDuration *= 2.0;
|
|
|
|
mNextDriverIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this doesn't need to be precise; do a simple schedule
|
|
|
|
uint32_t delay = static_cast<uint32_t>(mNextTickDuration);
|
2017-06-12 22:34:10 +03:00
|
|
|
mTimer->InitWithNamedFuncCallback(
|
|
|
|
TimerTickOne, this, delay, nsITimer::TYPE_ONE_SHOT,
|
|
|
|
"InactiveRefreshDriverTimer::ScheduleNextTick");
|
2012-12-12 02:15:32 +04:00
|
|
|
|
|
|
|
LOG("[%p] inactive timer next tick in %f ms [index %d/%d]", this,
|
2015-11-16 19:12:38 +03:00
|
|
|
mNextTickDuration, mNextDriverIndex, GetRefreshDriverCount());
|
2012-12-12 02:15:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Runs just one driver's tick. */
|
|
|
|
void TickOne() {
|
|
|
|
TimeStamp now = TimeStamp::Now();
|
|
|
|
|
|
|
|
ScheduleNextTick(now);
|
|
|
|
|
|
|
|
mLastFireTime = now;
|
|
|
|
|
2018-02-05 01:15:53 +03:00
|
|
|
nsTArray<RefPtr<nsRefreshDriver>> drivers(mContentRefreshDrivers);
|
2015-11-16 19:12:38 +03:00
|
|
|
drivers.AppendElements(mRootRefreshDrivers);
|
2016-08-22 15:52:45 +03:00
|
|
|
size_t index = mNextDriverIndex;
|
2015-11-16 19:12:38 +03:00
|
|
|
|
2016-08-22 15:52:45 +03:00
|
|
|
if (index < drivers.Length() &&
|
|
|
|
!drivers[index]->IsTestControllingRefreshesEnabled()) {
|
2018-12-08 02:28:03 +03:00
|
|
|
TickDriver(drivers[index], VsyncId(), now);
|
2012-12-12 02:15:32 +04:00
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
mNextDriverIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TimerTickOne(nsITimer* aTimer, void* aClosure) {
|
2018-06-30 02:08:54 +03:00
|
|
|
RefPtr<InactiveRefreshDriverTimer> timer =
|
|
|
|
static_cast<InactiveRefreshDriverTimer*>(aClosure);
|
2012-12-12 02:15:32 +04:00
|
|
|
timer->TickOne();
|
|
|
|
}
|
|
|
|
|
|
|
|
double mNextTickDuration;
|
|
|
|
double mDisableAfterMilliseconds;
|
|
|
|
uint32_t mNextDriverIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-06-30 02:08:54 +03:00
|
|
|
static StaticRefPtr<RefreshDriverTimer> sRegularRateTimer;
|
|
|
|
static StaticRefPtr<InactiveRefreshDriverTimer> sThrottledRateTimer;
|
2015-01-14 02:38:00 +03:00
|
|
|
|
2015-01-19 04:28:00 +03:00
|
|
|
static void CreateContentVsyncRefreshTimer(void*) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!XRE_IsParentProcess());
|
2015-01-14 02:38:00 +03:00
|
|
|
|
2015-01-19 04:28:00 +03:00
|
|
|
// Create the PVsync actor child for vsync-base refresh timer.
|
2017-10-24 13:02:41 +03:00
|
|
|
// PBackgroundChild is created synchronously. We will still use software
|
|
|
|
// timer before PVsync ready, and change to use hw timer when the connection
|
|
|
|
// is done. Please check nsRefreshDriver::PVsyncActorCreated().
|
|
|
|
|
|
|
|
PBackgroundChild* actorChild = BackgroundChild::GetOrCreateForCurrentThread();
|
|
|
|
if (NS_WARN_IF(!actorChild)) {
|
2017-10-25 09:45:53 +03:00
|
|
|
return;
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
2017-10-24 13:02:41 +03:00
|
|
|
|
|
|
|
layout::PVsyncChild* actor = actorChild->SendPVsyncConstructor();
|
|
|
|
if (NS_WARN_IF(!actor)) {
|
2017-10-25 09:45:53 +03:00
|
|
|
return;
|
2017-10-24 13:02:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
layout::VsyncChild* child = static_cast<layout::VsyncChild*>(actor);
|
|
|
|
nsRefreshDriver::PVsyncActorCreated(child);
|
2015-01-19 04:28:00 +03:00
|
|
|
}
|
|
|
|
|
2019-11-27 03:21:33 +03:00
|
|
|
void nsRefreshDriver::CreateVsyncRefreshTimer() {
|
2015-01-19 04:28:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-01-14 17:07:18 +03:00
|
|
|
PodArrayZero(sJankLevels);
|
2015-01-19 04:28:00 +03:00
|
|
|
|
2015-08-25 16:01:40 +03:00
|
|
|
if (gfxPlatform::IsInLayoutAsapMode()) {
|
2015-01-19 04:28:00 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-27 03:21:33 +03:00
|
|
|
// If available, we fetch the widget-specific vsync source.
|
|
|
|
nsIWidget* widget = GetPresContext()->GetRootWidget();
|
|
|
|
if (widget) {
|
|
|
|
RefPtr<gfx::VsyncSource> localVsyncSource = widget->GetVsyncSource();
|
|
|
|
if (localVsyncSource) {
|
|
|
|
mOwnTimer = new VsyncRefreshDriverTimer(localVsyncSource);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-19 04:28:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
// Make sure all vsync systems are ready.
|
|
|
|
gfxPlatform::GetPlatform();
|
|
|
|
// In parent process, we don't need to use ipc. We can create the
|
|
|
|
// VsyncRefreshDriverTimer directly.
|
|
|
|
sRegularRateTimer = new VsyncRefreshDriverTimer();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this process is not created by NUWA, just create the vsync timer here.
|
|
|
|
CreateContentVsyncRefreshTimer(nullptr);
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
2013-05-18 00:57:26 +04:00
|
|
|
static uint32_t GetFirstFrameDelay(imgIRequest* req) {
|
|
|
|
nsCOMPtr<imgIContainer> container;
|
|
|
|
if (NS_FAILED(req->GetImage(getter_AddRefs(container))) || !container) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this image isn't animated, there isn't a first frame delay.
|
|
|
|
int32_t delay = container->GetFirstFrameDelay();
|
|
|
|
if (delay < 0) return 0;
|
|
|
|
|
|
|
|
return static_cast<uint32_t>(delay);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
void nsRefreshDriver::Shutdown() {
|
2012-12-12 02:15:32 +04:00
|
|
|
// clean up our timers
|
|
|
|
sRegularRateTimer = nullptr;
|
|
|
|
sThrottledRateTimer = nullptr;
|
2011-03-07 19:58:48 +03:00
|
|
|
}
|
2011-12-24 07:52:26 +04:00
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
int32_t nsRefreshDriver::DefaultInterval() {
|
2015-09-15 18:13:57 +03:00
|
|
|
return NSToIntRound(1000.0 / gfxPlatform::GetDefaultFrameRate());
|
2011-12-24 07:52:26 +04:00
|
|
|
}
|
|
|
|
|
2013-05-29 14:31:16 +04:00
|
|
|
// Compute the interval to use for the refresh driver timer, in milliseconds.
|
|
|
|
// outIsDefault indicates that rate was not explicitly set by the user
|
|
|
|
// so we might choose other, more appropriate rates (e.g. vsync, etc)
|
2013-08-03 00:29:57 +04:00
|
|
|
// layout.frame_rate=0 indicates "ASAP mode".
|
|
|
|
// In ASAP mode rendering is iterated as fast as possible (typically for stress
|
|
|
|
// testing). A target rate of 10k is used internally instead of special-handling
|
|
|
|
// 0. Backends which block on swap/present/etc should try to not block when
|
|
|
|
// layout.frame_rate=0 - to comply with "ASAP" as much as possible.
|
2018-05-16 15:32:18 +03:00
|
|
|
double nsRefreshDriver::GetRegularTimerInterval() const {
|
2012-12-12 02:15:32 +04:00
|
|
|
int32_t rate = Preferences::GetInt("layout.frame_rate", -1);
|
2013-08-03 00:29:57 +04:00
|
|
|
if (rate < 0) {
|
2015-09-15 18:13:57 +03:00
|
|
|
rate = gfxPlatform::GetDefaultFrameRate();
|
2018-05-16 15:32:18 +03:00
|
|
|
} else if (rate == 0) {
|
2013-08-03 00:29:57 +04:00
|
|
|
rate = 10000;
|
|
|
|
}
|
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
return 1000.0 / rate;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
double nsRefreshDriver::GetThrottledTimerInterval() {
|
2012-12-12 02:15:32 +04:00
|
|
|
int32_t rate = Preferences::GetInt("layout.throttled_frame_rate", -1);
|
|
|
|
if (rate <= 0) {
|
|
|
|
rate = DEFAULT_THROTTLED_FRAME_RATE;
|
2011-03-04 18:27:02 +03:00
|
|
|
}
|
2012-12-12 02:15:32 +04:00
|
|
|
return 1000.0 / rate;
|
|
|
|
}
|
|
|
|
|
2015-05-30 09:50:51 +03:00
|
|
|
/* static */ mozilla::TimeDuration
|
|
|
|
nsRefreshDriver::GetMinRecomputeVisibilityInterval() {
|
|
|
|
int32_t interval =
|
|
|
|
Preferences::GetInt("layout.visibility.min-recompute-interval-ms", -1);
|
|
|
|
if (interval <= 0) {
|
|
|
|
interval = DEFAULT_RECOMPUTE_VISIBILITY_INTERVAL_MS;
|
|
|
|
}
|
|
|
|
return TimeDuration::FromMilliseconds(interval);
|
|
|
|
}
|
|
|
|
|
2019-11-27 03:21:33 +03:00
|
|
|
RefreshDriverTimer* nsRefreshDriver::ChooseTimer() {
|
2011-03-04 18:27:02 +03:00
|
|
|
if (mThrottled) {
|
2015-07-18 16:35:59 +03:00
|
|
|
if (!sThrottledRateTimer)
|
2012-12-12 02:15:32 +04:00
|
|
|
sThrottledRateTimer = new InactiveRefreshDriverTimer(
|
|
|
|
GetThrottledTimerInterval(),
|
|
|
|
DEFAULT_INACTIVE_TIMER_DISABLE_SECONDS * 1000.0);
|
|
|
|
return sThrottledRateTimer;
|
2012-10-02 20:38:49 +04:00
|
|
|
}
|
2012-12-12 02:15:32 +04:00
|
|
|
|
2019-11-27 03:21:33 +03:00
|
|
|
if (!sRegularRateTimer && !mOwnTimer) {
|
2018-05-16 15:32:18 +03:00
|
|
|
double rate = GetRegularTimerInterval();
|
2015-01-14 02:38:00 +03:00
|
|
|
|
2015-01-19 04:28:00 +03:00
|
|
|
// Try to use vsync-base refresh timer first for sRegularRateTimer.
|
|
|
|
CreateVsyncRefreshTimer();
|
2015-01-14 02:38:00 +03:00
|
|
|
|
2019-11-27 03:21:33 +03:00
|
|
|
if (mOwnTimer) {
|
|
|
|
return mOwnTimer.get();
|
|
|
|
}
|
|
|
|
|
2013-05-29 14:31:16 +04:00
|
|
|
if (!sRegularRateTimer) {
|
2015-08-26 16:45:54 +03:00
|
|
|
sRegularRateTimer = new StartupRefreshDriverTimer(rate);
|
2013-05-29 14:31:16 +04:00
|
|
|
}
|
|
|
|
}
|
2019-11-27 03:21:33 +03:00
|
|
|
|
|
|
|
if (mOwnTimer) {
|
|
|
|
return mOwnTimer.get();
|
|
|
|
}
|
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
return sRegularRateTimer;
|
2010-08-23 13:30:08 +04:00
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
nsRefreshDriver::nsRefreshDriver(nsPresContext* aPresContext)
|
|
|
|
: mActiveTimer(nullptr),
|
2019-11-27 03:21:33 +03:00
|
|
|
mOwnTimer(nullptr),
|
2012-12-12 02:15:32 +04:00
|
|
|
mPresContext(aPresContext),
|
2014-05-29 01:43:41 +04:00
|
|
|
mRootRefresh(nullptr),
|
2018-09-06 05:21:39 +03:00
|
|
|
mNextTransactionId{0},
|
|
|
|
mOutstandingTransactionId{0},
|
2018-04-20 22:13:06 +03:00
|
|
|
mCompletedTransaction{0},
|
2013-12-20 01:38:35 +04:00
|
|
|
mFreezeCount(0),
|
2015-04-21 19:44:40 +03:00
|
|
|
mThrottledFrameRequestInterval(
|
|
|
|
TimeDuration::FromMilliseconds(GetThrottledTimerInterval())),
|
2015-05-30 09:50:51 +03:00
|
|
|
mMinRecomputeVisibilityInterval(GetMinRecomputeVisibilityInterval()),
|
2011-03-07 19:58:48 +03:00
|
|
|
mThrottled(false),
|
2015-05-30 09:50:51 +03:00
|
|
|
mNeedToRecomputeVisibility(false),
|
2011-04-12 10:18:43 +04:00
|
|
|
mTestControllingRefreshes(false),
|
2011-12-24 07:52:22 +04:00
|
|
|
mViewManagerFlushIsPending(false),
|
2017-10-03 11:00:38 +03:00
|
|
|
mHasScheduleFlush(false),
|
2014-05-29 01:42:17 +04:00
|
|
|
mInRefresh(false),
|
|
|
|
mWaitingForTransaction(false),
|
2016-05-03 10:58:57 +03:00
|
|
|
mSkippedPaints(false),
|
2016-09-09 13:06:29 +03:00
|
|
|
mResizeSuppressed(false),
|
2018-04-27 01:36:52 +03:00
|
|
|
mNotifyDOMContentFlushed(false),
|
2016-09-15 23:48:48 +03:00
|
|
|
mWarningThreshold(REFRESH_WAIT_WARNING) {
|
2016-06-06 16:51:15 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mPresContext,
|
|
|
|
"Need a pres context to tell us to call Disconnect() later "
|
|
|
|
"and decrement sRefreshDriverCount.");
|
2012-12-12 02:15:32 +04:00
|
|
|
mMostRecentRefresh = TimeStamp::Now();
|
2018-07-15 14:19:29 +03:00
|
|
|
mNextThrottledFrameRequestTick = mMostRecentRefresh;
|
|
|
|
mNextRecomputeVisibilityTick = mMostRecentRefresh;
|
2016-06-06 16:51:15 +03:00
|
|
|
|
2016-06-06 16:53:41 +03:00
|
|
|
++sRefreshDriverCount;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefreshDriver::~nsRefreshDriver() {
|
2016-06-06 16:51:15 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-06-29 14:46:11 +03:00
|
|
|
MOZ_ASSERT(ObserverCount() == mEarlyRunners.Length(),
|
2017-06-25 00:38:42 +03:00
|
|
|
"observers, except pending selection scrolls, "
|
|
|
|
"should have been unregistered");
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mActiveTimer, "timer should be gone");
|
2016-06-06 16:51:15 +03:00
|
|
|
MOZ_ASSERT(!mPresContext,
|
|
|
|
"Should have called Disconnect() and decremented "
|
|
|
|
"sRefreshDriverCount!");
|
2015-07-18 16:35:59 +03:00
|
|
|
|
2014-05-29 01:43:41 +04:00
|
|
|
if (mRootRefresh) {
|
2017-01-05 10:31:56 +03:00
|
|
|
mRootRefresh->RemoveRefreshObserver(this, FlushType::Style);
|
2014-05-29 01:43:41 +04:00
|
|
|
mRootRefresh = nullptr;
|
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
// Method for testing. See nsIDOMWindowUtils.advanceTimeAndRefresh
|
|
|
|
// for description.
|
2012-08-22 19:56:38 +04:00
|
|
|
void nsRefreshDriver::AdvanceTimeAndRefresh(int64_t aMilliseconds) {
|
2012-12-12 02:15:32 +04:00
|
|
|
// ensure that we're removed from our driver
|
|
|
|
StopTimer();
|
|
|
|
|
|
|
|
if (!mTestControllingRefreshes) {
|
|
|
|
mMostRecentRefresh = TimeStamp::Now();
|
|
|
|
|
|
|
|
mTestControllingRefreshes = true;
|
2014-05-29 01:42:17 +04:00
|
|
|
if (mWaitingForTransaction) {
|
|
|
|
// Disable any refresh driver throttling when entering test mode
|
|
|
|
mWaitingForTransaction = false;
|
2014-08-15 06:24:50 +04:00
|
|
|
mSkippedPaints = false;
|
2016-09-15 23:48:48 +03:00
|
|
|
mWarningThreshold = REFRESH_WAIT_WARNING;
|
2014-05-29 01:42:17 +04:00
|
|
|
}
|
2012-12-12 02:15:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mMostRecentRefresh += TimeDuration::FromMilliseconds((double)aMilliseconds);
|
|
|
|
|
2014-04-15 07:27:00 +04:00
|
|
|
mozilla::dom::AutoNoJSAPI nojsapi;
|
2013-02-26 23:04:11 +04:00
|
|
|
DoTick();
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsRefreshDriver::RestoreNormalRefresh() {
|
|
|
|
mTestControllingRefreshes = false;
|
2015-01-06 04:56:02 +03:00
|
|
|
EnsureTimerStarted(eAllowTimeToGoBackwards);
|
2018-09-06 05:21:39 +03:00
|
|
|
mCompletedTransaction = mOutstandingTransactionId = mNextTransactionId;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
TimeStamp nsRefreshDriver::MostRecentRefresh() const {
|
2017-02-20 08:37:13 +03:00
|
|
|
// In case of stylo traversal, we have already activated the refresh driver in
|
2018-04-05 22:12:37 +03:00
|
|
|
// RestyleManager::ProcessPendingRestyles().
|
2017-02-20 08:37:13 +03:00
|
|
|
if (!ServoStyleSet::IsInServoTraversal()) {
|
|
|
|
const_cast<nsRefreshDriver*>(this)->EnsureTimerStarted();
|
|
|
|
}
|
2012-12-24 04:29:23 +04:00
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
return mMostRecentRefresh;
|
|
|
|
}
|
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
void nsRefreshDriver::AddRefreshObserver(nsARefreshObserver* aObserver,
|
2017-01-05 10:31:56 +03:00
|
|
|
FlushType aFlushType) {
|
2009-10-08 07:22:42 +04:00
|
|
|
ObserverArray& array = ArrayFor(aFlushType);
|
2018-10-14 19:12:22 +03:00
|
|
|
array.AppendElement(aObserver);
|
2015-01-06 04:56:02 +03:00
|
|
|
EnsureTimerStarted();
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
bool nsRefreshDriver::RemoveRefreshObserver(nsARefreshObserver* aObserver,
|
2017-01-05 10:31:56 +03:00
|
|
|
FlushType aFlushType) {
|
2009-10-08 07:22:42 +04:00
|
|
|
ObserverArray& array = ArrayFor(aFlushType);
|
2009-12-31 22:07:57 +03:00
|
|
|
return array.RemoveElement(aObserver);
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
2018-07-03 04:57:12 +03:00
|
|
|
void nsRefreshDriver::AddTimerAdjustmentObserver(
|
2018-10-14 19:12:23 +03:00
|
|
|
nsATimerAdjustmentObserver* aObserver) {
|
2018-07-03 04:57:12 +03:00
|
|
|
MOZ_ASSERT(!mTimerAdjustmentObservers.Contains(aObserver));
|
2018-10-14 19:12:23 +03:00
|
|
|
mTimerAdjustmentObservers.AppendElement(aObserver);
|
2018-07-03 04:57:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsRefreshDriver::RemoveTimerAdjustmentObserver(
|
2018-10-14 19:12:23 +03:00
|
|
|
nsATimerAdjustmentObserver* aObserver) {
|
2018-07-03 04:57:12 +03:00
|
|
|
MOZ_ASSERT(mTimerAdjustmentObservers.Contains(aObserver));
|
2018-10-14 19:12:23 +03:00
|
|
|
mTimerAdjustmentObservers.RemoveElement(aObserver);
|
2018-07-03 04:57:12 +03:00
|
|
|
}
|
|
|
|
|
2018-12-21 00:35:26 +03:00
|
|
|
void nsRefreshDriver::PostVisualViewportResizeEvent(
|
|
|
|
VVPResizeEvent* aResizeEvent) {
|
|
|
|
mVisualViewportResizeEvents.AppendElement(aResizeEvent);
|
|
|
|
EnsureTimerStarted();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsRefreshDriver::DispatchVisualViewportResizeEvents() {
|
|
|
|
// We're taking a hint from scroll events and only dispatch the current set
|
|
|
|
// of queued resize events. If additional events are posted in response to
|
|
|
|
// the current events being dispatched, we'll dispatch them on the next tick.
|
|
|
|
VisualViewportResizeEventArray events;
|
|
|
|
events.SwapElements(mVisualViewportResizeEvents);
|
|
|
|
for (auto& event : events) {
|
|
|
|
event->Run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-19 04:38:45 +03:00
|
|
|
void nsRefreshDriver::PostScrollEvent(mozilla::Runnable* aScrollEvent,
|
|
|
|
bool aDelayed) {
|
|
|
|
if (aDelayed) {
|
|
|
|
mDelayedScrollEvents.AppendElement(aScrollEvent);
|
|
|
|
} else {
|
|
|
|
mScrollEvents.AppendElement(aScrollEvent);
|
|
|
|
EnsureTimerStarted();
|
|
|
|
}
|
2017-08-10 04:08:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsRefreshDriver::DispatchScrollEvents() {
|
|
|
|
// Scroll events are one-shot, so after running them we can drop them.
|
|
|
|
// However, dispatching a scroll event can potentially cause more scroll
|
|
|
|
// events to be posted, so we move the initial set into a temporary array
|
|
|
|
// first. (Newly posted scroll events will be dispatched on the next tick.)
|
|
|
|
ScrollEventArray events;
|
|
|
|
events.SwapElements(mScrollEvents);
|
|
|
|
for (auto& event : events) {
|
|
|
|
event->Run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-21 00:35:26 +03:00
|
|
|
void nsRefreshDriver::PostVisualViewportScrollEvent(
|
|
|
|
VVPScrollEvent* aScrollEvent) {
|
|
|
|
mVisualViewportScrollEvents.AppendElement(aScrollEvent);
|
|
|
|
EnsureTimerStarted();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsRefreshDriver::DispatchVisualViewportScrollEvents() {
|
|
|
|
// Scroll events are one-shot, so after running them we can drop them.
|
|
|
|
// However, dispatching a scroll event can potentially cause more scroll
|
|
|
|
// events to be posted, so we move the initial set into a temporary array
|
|
|
|
// first. (Newly posted scroll events will be dispatched on the next tick.)
|
|
|
|
VisualViewportScrollEventArray events;
|
|
|
|
events.SwapElements(mVisualViewportScrollEvents);
|
|
|
|
for (auto& event : events) {
|
|
|
|
event->Run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-19 17:08:44 +04:00
|
|
|
void nsRefreshDriver::AddPostRefreshObserver(
|
|
|
|
nsAPostRefreshObserver* aObserver) {
|
|
|
|
mPostRefreshObservers.AppendElement(aObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsRefreshDriver::RemovePostRefreshObserver(
|
|
|
|
nsAPostRefreshObserver* aObserver) {
|
|
|
|
mPostRefreshObservers.RemoveElement(aObserver);
|
|
|
|
}
|
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
bool nsRefreshDriver::AddImageRequest(imgIRequest* aRequest) {
|
2013-05-18 00:57:26 +04:00
|
|
|
uint32_t delay = GetFirstFrameDelay(aRequest);
|
|
|
|
if (delay == 0) {
|
2017-06-29 21:53:46 +03:00
|
|
|
mRequests.PutEntry(aRequest);
|
2013-05-18 00:57:26 +04:00
|
|
|
} else {
|
2017-06-29 21:53:46 +03:00
|
|
|
ImageStartData* start = mStartTable.LookupForAdd(delay).OrInsert(
|
|
|
|
[]() { return new ImageStartData(); });
|
2013-05-18 00:57:26 +04:00
|
|
|
start->mEntries.PutEntry(aRequest);
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
|
|
|
|
2015-01-06 04:56:02 +03:00
|
|
|
EnsureTimerStarted();
|
2011-11-10 01:39:16 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsRefreshDriver::RemoveImageRequest(imgIRequest* aRequest) {
|
2013-05-18 00:57:26 +04:00
|
|
|
// Try to remove from both places, just in case, because we can't tell
|
|
|
|
// whether RemoveEntry() succeeds.
|
2011-11-10 01:39:16 +04:00
|
|
|
mRequests.RemoveEntry(aRequest);
|
2013-05-18 00:57:26 +04:00
|
|
|
uint32_t delay = GetFirstFrameDelay(aRequest);
|
|
|
|
if (delay != 0) {
|
|
|
|
ImageStartData* start = mStartTable.Get(delay);
|
|
|
|
if (start) {
|
|
|
|
start->mEntries.RemoveEntry(aRequest);
|
|
|
|
}
|
|
|
|
}
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
|
|
|
|
2018-04-27 01:36:52 +03:00
|
|
|
void nsRefreshDriver::NotifyDOMContentLoaded() {
|
|
|
|
// If the refresh driver is going to tick, we mark the timestamp after
|
|
|
|
// everything is flushed in the next tick. If it isn't, mark ourselves as
|
|
|
|
// flushed now.
|
|
|
|
if (!HasObservers()) {
|
|
|
|
GetPresContext()->NotifyDOMContentFlushed();
|
|
|
|
} else {
|
|
|
|
mNotifyDOMContentFlushed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-19 04:38:45 +03:00
|
|
|
void nsRefreshDriver::RunDelayedEventsSoon() {
|
|
|
|
// Place entries for delayed events into their corresponding normal list,
|
|
|
|
// and schedule a refresh. When these delayed events run, if their document
|
|
|
|
// still has events suppressed then they will be readded to the delayed
|
|
|
|
// events list.
|
|
|
|
|
|
|
|
mScrollEvents.AppendElements(mDelayedScrollEvents);
|
|
|
|
mDelayedScrollEvents.Clear();
|
|
|
|
|
|
|
|
mResizeEventFlushObservers.AppendElements(mDelayedResizeEventFlushObservers);
|
|
|
|
mDelayedResizeEventFlushObservers.Clear();
|
|
|
|
|
|
|
|
EnsureTimerStarted();
|
|
|
|
}
|
|
|
|
|
2015-01-06 04:56:02 +03:00
|
|
|
void nsRefreshDriver::EnsureTimerStarted(EnsureTimerStartedFlags aFlags) {
|
2017-03-10 05:53:17 +03:00
|
|
|
// FIXME: Bug 1346065: We should also assert the case where we have
|
|
|
|
// STYLO_THREADS=1.
|
|
|
|
MOZ_ASSERT(!ServoStyleSet::IsInServoTraversal() || NS_IsMainThread(),
|
2017-02-20 08:37:13 +03:00
|
|
|
"EnsureTimerStarted should be called only when we are not "
|
2017-03-10 05:53:17 +03:00
|
|
|
"in servo traversal or on the main-thread");
|
2017-02-20 08:37:13 +03:00
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
if (mTestControllingRefreshes) return;
|
2012-10-02 18:54:46 +04:00
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
// will it already fire, and no other changes needed?
|
2016-01-05 06:50:59 +03:00
|
|
|
if (mActiveTimer && !(aFlags & eForceAdjustTimer)) return;
|
2012-10-02 18:54:46 +04:00
|
|
|
|
2013-12-20 01:38:35 +04:00
|
|
|
if (IsFrozen() || !mPresContext) {
|
2012-12-12 02:15:32 +04:00
|
|
|
// If we don't want to start it now, or we've been disconnected.
|
|
|
|
StopTimer();
|
2009-10-08 07:22:42 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-01 20:31:54 +04:00
|
|
|
if (mPresContext->Document()->IsBeingUsedAsImage()) {
|
|
|
|
// Image documents receive ticks from clients' refresh drivers.
|
2014-12-04 23:13:37 +03:00
|
|
|
// XXXdholbert Exclude SVG-in-opentype fonts from this optimization, until
|
|
|
|
// they receive refresh-driver ticks from their client docs (bug 1107252).
|
|
|
|
nsIURI* uri = mPresContext->Document()->GetDocumentURI();
|
2018-06-02 16:51:42 +03:00
|
|
|
if (!uri || !mozilla::dom::IsFontTableURI(uri)) {
|
2014-12-04 23:13:37 +03:00
|
|
|
MOZ_ASSERT(!mActiveTimer,
|
|
|
|
"image doc refresh driver should never have its own timer");
|
|
|
|
return;
|
|
|
|
}
|
2014-05-01 20:31:54 +04:00
|
|
|
}
|
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
// We got here because we're either adjusting the time *or* we're
|
|
|
|
// starting it for the first time. Add to the right timer,
|
|
|
|
// prehaps removing it from a previously-set one.
|
|
|
|
RefreshDriverTimer* newTimer = ChooseTimer();
|
|
|
|
if (newTimer != mActiveTimer) {
|
|
|
|
if (mActiveTimer) mActiveTimer->RemoveRefreshDriver(this);
|
|
|
|
mActiveTimer = newTimer;
|
|
|
|
mActiveTimer->AddRefreshDriver(this);
|
2012-10-08 13:57:12 +04:00
|
|
|
}
|
2012-12-24 04:29:23 +04:00
|
|
|
|
2016-01-05 06:50:59 +03:00
|
|
|
// When switching from an inactive timer to an active timer, the root
|
|
|
|
// refresh driver is skipped due to being set to the content refresh
|
|
|
|
// driver's timestamp. In case of EnsureTimerStarted is called from
|
|
|
|
// ScheduleViewManagerFlush, we should avoid this behavior to flush
|
|
|
|
// a paint in the same tick on the root refresh driver.
|
|
|
|
if (aFlags & eNeverAdjustTimer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-26 04:17:50 +04:00
|
|
|
// Since the different timers are sampled at different rates, when switching
|
|
|
|
// timers, the most recent refresh of the new timer may be *before* the
|
|
|
|
// most recent refresh of the old timer. However, the refresh driver time
|
|
|
|
// should not go backwards so we clamp the most recent refresh time.
|
2015-01-06 04:56:02 +03:00
|
|
|
//
|
|
|
|
// The one exception to this is when we are restoring the refresh driver
|
|
|
|
// from test control in which case the time is expected to go backwards
|
|
|
|
// (see bug 1043078).
|
2018-07-03 04:57:12 +03:00
|
|
|
TimeStamp newMostRecentRefresh =
|
2015-01-06 04:56:02 +03:00
|
|
|
aFlags & eAllowTimeToGoBackwards
|
|
|
|
? mActiveTimer->MostRecentRefresh()
|
|
|
|
: std::max(mActiveTimer->MostRecentRefresh(), mMostRecentRefresh);
|
2018-07-03 04:57:12 +03:00
|
|
|
|
|
|
|
if (mMostRecentRefresh != newMostRecentRefresh) {
|
|
|
|
mMostRecentRefresh = newMostRecentRefresh;
|
|
|
|
|
|
|
|
nsTObserverArray<nsATimerAdjustmentObserver*>::EndLimitedIterator iter(
|
|
|
|
mTimerAdjustmentObservers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
nsATimerAdjustmentObserver* obs = iter.GetNext();
|
|
|
|
obs->NotifyTimerAdjusted(mMostRecentRefresh);
|
|
|
|
}
|
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsRefreshDriver::StopTimer() {
|
2012-12-12 02:15:32 +04:00
|
|
|
if (!mActiveTimer) return;
|
|
|
|
|
|
|
|
mActiveTimer->RemoveRefreshDriver(this);
|
|
|
|
mActiveTimer = nullptr;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t nsRefreshDriver::ObserverCount() const {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t sum = 0;
|
2018-02-05 01:15:53 +03:00
|
|
|
for (const ObserverArray& array : mObservers) {
|
|
|
|
sum += array.Length();
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
2011-11-10 01:39:16 +04:00
|
|
|
|
2010-08-27 08:26:23 +04:00
|
|
|
// Even while throttled, we need to process layout and style changes. Style
|
|
|
|
// changes can trigger transitions which fire events when they complete, and
|
|
|
|
// layout changes can affect media queries on child documents, triggering
|
|
|
|
// style changes, etc.
|
2018-01-27 15:17:27 +03:00
|
|
|
sum += mAnimationEventFlushObservers.Length();
|
2015-05-05 17:56:01 +03:00
|
|
|
sum += mResizeEventFlushObservers.Length();
|
2010-08-12 01:05:27 +04:00
|
|
|
sum += mStyleFlushObservers.Length();
|
|
|
|
sum += mLayoutFlushObservers.Length();
|
2018-09-08 01:53:33 +03:00
|
|
|
sum += mPendingFullscreenEvents.Length();
|
2011-11-28 16:48:30 +04:00
|
|
|
sum += mFrameRequestCallbackDocs.Length();
|
2015-04-21 19:44:40 +03:00
|
|
|
sum += mThrottledFrameRequestCallbackDocs.Length();
|
2011-12-24 07:52:22 +04:00
|
|
|
sum += mViewManagerFlushIsPending;
|
2017-06-29 14:46:11 +03:00
|
|
|
sum += mEarlyRunners.Length();
|
2018-07-03 04:57:12 +03:00
|
|
|
sum += mTimerAdjustmentObservers.Length();
|
2009-10-08 07:22:42 +04:00
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2018-01-27 15:17:26 +03:00
|
|
|
bool nsRefreshDriver::HasObservers() const {
|
2018-02-05 01:15:53 +03:00
|
|
|
for (const ObserverArray& array : mObservers) {
|
|
|
|
if (!array.IsEmpty()) {
|
2018-01-27 15:17:26 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-03 04:57:12 +03:00
|
|
|
// We should NOT count mTimerAdjustmentObservers here since this method is
|
|
|
|
// used to determine whether or not to stop the timer or re-start it and timer
|
|
|
|
// adjustment observers should not influence timer starting or stopping.
|
2018-01-27 15:17:26 +03:00
|
|
|
return mViewManagerFlushIsPending || !mStyleFlushObservers.IsEmpty() ||
|
|
|
|
!mLayoutFlushObservers.IsEmpty() ||
|
2018-01-27 15:17:27 +03:00
|
|
|
!mAnimationEventFlushObservers.IsEmpty() ||
|
2018-01-27 15:17:26 +03:00
|
|
|
!mResizeEventFlushObservers.IsEmpty() ||
|
2018-09-08 01:53:33 +03:00
|
|
|
!mPendingFullscreenEvents.IsEmpty() ||
|
2018-01-27 15:17:26 +03:00
|
|
|
!mFrameRequestCallbackDocs.IsEmpty() ||
|
|
|
|
!mThrottledFrameRequestCallbackDocs.IsEmpty() ||
|
|
|
|
!mEarlyRunners.IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsRefreshDriver::HasImageRequests() const {
|
2015-10-23 07:16:45 +03:00
|
|
|
for (auto iter = mStartTable.ConstIter(); !iter.Done(); iter.Next()) {
|
2018-01-27 15:17:26 +03:00
|
|
|
if (!iter.UserData()->mEntries.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-23 07:16:45 +03:00
|
|
|
}
|
2018-01-27 15:17:26 +03:00
|
|
|
|
|
|
|
return !mRequests.IsEmpty();
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
nsRefreshDriver::ObserverArray& nsRefreshDriver::ArrayFor(
|
2017-01-05 10:31:56 +03:00
|
|
|
FlushType aFlushType) {
|
2009-10-08 07:22:42 +04:00
|
|
|
switch (aFlushType) {
|
2017-08-11 09:58:08 +03:00
|
|
|
case FlushType::Event:
|
2009-10-08 07:22:42 +04:00
|
|
|
return mObservers[0];
|
2017-08-11 09:58:08 +03:00
|
|
|
case FlushType::Style:
|
2019-08-07 06:51:20 +03:00
|
|
|
case FlushType::Frames:
|
2009-10-08 07:22:42 +04:00
|
|
|
return mObservers[1];
|
2017-08-11 09:58:08 +03:00
|
|
|
case FlushType::Layout:
|
2009-10-08 07:22:42 +04:00
|
|
|
return mObservers[2];
|
2017-08-11 09:58:08 +03:00
|
|
|
case FlushType::Display:
|
|
|
|
return mObservers[3];
|
2009-10-08 07:22:42 +04:00
|
|
|
default:
|
2016-12-18 01:25:37 +03:00
|
|
|
MOZ_CRASH("We don't track refresh observers for this flush type");
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nsITimerCallback implementation
|
|
|
|
*/
|
|
|
|
|
2012-12-12 02:15:32 +04:00
|
|
|
void nsRefreshDriver::DoTick() {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(!IsFrozen(), "Why are we notified while frozen?");
|
|
|
|
MOZ_ASSERT(mPresContext, "Why are we notified after disconnection?");
|
|
|
|
MOZ_ASSERT(!nsContentUtils::GetCurrentJSContext(),
|
|
|
|
"Shouldn't have a JSContext on the stack");
|
2012-12-12 02:15:32 +04:00
|
|
|
|
|
|
|
if (mTestControllingRefreshes) {
|
2018-12-08 02:28:03 +03:00
|
|
|
Tick(VsyncId(), mMostRecentRefresh);
|
2012-12-12 02:15:32 +04:00
|
|
|
} else {
|
2018-12-08 02:28:03 +03:00
|
|
|
Tick(VsyncId(), TimeStamp::Now());
|
2012-12-12 02:15:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-25 19:13:21 +04:00
|
|
|
struct DocumentFrameCallbacks {
|
2019-01-02 16:05:23 +03:00
|
|
|
explicit DocumentFrameCallbacks(Document* aDocument) : mDocument(aDocument) {}
|
2013-04-25 19:13:21 +04:00
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
RefPtr<Document> mDocument;
|
2019-02-25 09:02:12 +03:00
|
|
|
nsTArray<Document::FrameRequest> mCallbacks;
|
2013-04-25 19:13:21 +04:00
|
|
|
};
|
|
|
|
|
2014-09-09 22:54:08 +04:00
|
|
|
static nsDocShell* GetDocShell(nsPresContext* aPresContext) {
|
|
|
|
return static_cast<nsDocShell*>(aPresContext->GetDocShell());
|
|
|
|
}
|
|
|
|
|
2019-04-16 10:25:10 +03:00
|
|
|
static bool HasPendingAnimations(PresShell* aPresShell) {
|
|
|
|
Document* doc = aPresShell->GetDocument();
|
2014-12-22 03:35:41 +03:00
|
|
|
if (!doc) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:22:09 +03:00
|
|
|
PendingAnimationTracker* tracker = doc->GetPendingAnimationTracker();
|
|
|
|
return tracker && tracker->HasPendingAnimations();
|
2014-12-22 03:35:41 +03:00
|
|
|
}
|
|
|
|
|
2014-09-09 22:54:08 +04:00
|
|
|
/**
|
|
|
|
* Return a list of all the child docShells in a given root docShell that are
|
|
|
|
* visible and are recording markers for the profilingTimeline
|
|
|
|
*/
|
|
|
|
static void GetProfileTimelineSubDocShells(nsDocShell* aRootDocShell,
|
|
|
|
nsTArray<nsDocShell*>& aShells) {
|
2015-10-22 00:10:05 +03:00
|
|
|
if (!aRootDocShell) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
|
|
|
|
if (!timelines || timelines->IsEmpty()) {
|
2014-09-09 22:54:08 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-18 23:11:58 +03:00
|
|
|
nsTArray<RefPtr<nsIDocShell>> docShells;
|
|
|
|
nsresult rv = aRootDocShell->GetAllDocShellsInSubtree(
|
2015-10-22 00:10:05 +03:00
|
|
|
nsIDocShellTreeItem::typeAll, nsIDocShell::ENUMERATE_BACKWARDS,
|
2019-11-18 23:11:58 +03:00
|
|
|
docShells);
|
2014-09-09 22:54:08 +04:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-18 23:11:58 +03:00
|
|
|
for (const auto& curItem : docShells) {
|
|
|
|
if (!curItem->GetRecordProfileTimelineMarkers()) {
|
2014-09-09 22:54:08 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDocShell* shell = static_cast<nsDocShell*>(curItem.get());
|
|
|
|
bool isVisible = false;
|
|
|
|
shell->GetVisibility(&isVisible);
|
|
|
|
if (!isVisible) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
aShells.AppendElement(shell);
|
2016-01-22 18:58:49 +03:00
|
|
|
}
|
2014-09-09 22:54:08 +04:00
|
|
|
}
|
|
|
|
|
2015-04-21 19:44:40 +03:00
|
|
|
static void TakeFrameRequestCallbacksFrom(
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* aDocument, nsTArray<DocumentFrameCallbacks>& aTarget) {
|
2015-04-21 19:44:40 +03:00
|
|
|
aTarget.AppendElement(aDocument);
|
|
|
|
aDocument->TakeFrameRequestCallbacks(aTarget.LastElement().mCallbacks);
|
|
|
|
}
|
|
|
|
|
2018-09-08 01:53:33 +03:00
|
|
|
// https://fullscreen.spec.whatwg.org/#run-the-fullscreen-steps
|
|
|
|
void nsRefreshDriver::RunFullscreenSteps() {
|
2015-07-02 12:12:31 +03:00
|
|
|
// Swap out the current pending events
|
2018-09-08 01:53:33 +03:00
|
|
|
nsTArray<UniquePtr<PendingFullscreenEvent>> pendings(
|
|
|
|
std::move(mPendingFullscreenEvents));
|
|
|
|
for (UniquePtr<PendingFullscreenEvent>& event : pendings) {
|
|
|
|
event->Dispatch();
|
2015-07-02 12:12:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-26 14:11:17 +03:00
|
|
|
void nsRefreshDriver::UpdateIntersectionObservations() {
|
2019-01-02 16:05:23 +03:00
|
|
|
AutoTArray<RefPtr<Document>, 32> documents;
|
2018-01-26 14:11:17 +03:00
|
|
|
|
|
|
|
if (mPresContext->Document()->HasIntersectionObservers()) {
|
|
|
|
documents.AppendElement(mPresContext->Document());
|
|
|
|
}
|
|
|
|
|
|
|
|
mPresContext->Document()->CollectDescendantDocuments(
|
2019-01-02 16:05:23 +03:00
|
|
|
documents, [](const Document* document) -> bool {
|
2018-01-26 14:11:17 +03:00
|
|
|
return document->HasIntersectionObservers();
|
|
|
|
});
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < documents.Length(); ++i) {
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = documents[i];
|
2018-01-26 14:11:17 +03:00
|
|
|
doc->UpdateIntersectionObservations();
|
|
|
|
doc->ScheduleIntersectionObserverNotification();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-29 04:57:39 +03:00
|
|
|
void nsRefreshDriver::DispatchAnimationEvents() {
|
|
|
|
if (!mPresContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-27 15:17:27 +03:00
|
|
|
// Hold all AnimationEventDispatcher in mAnimationEventFlushObservers as
|
|
|
|
// a RefPtr<> array since each AnimationEventDispatcher might be destroyed
|
|
|
|
// during processing the previous dispatcher.
|
|
|
|
AutoTArray<RefPtr<AnimationEventDispatcher>, 16> dispatchers;
|
2018-02-05 01:15:53 +03:00
|
|
|
dispatchers.AppendElements(mAnimationEventFlushObservers);
|
2018-01-27 15:17:27 +03:00
|
|
|
mAnimationEventFlushObservers.Clear();
|
2018-01-27 13:47:29 +03:00
|
|
|
|
2018-01-27 15:17:27 +03:00
|
|
|
for (auto& dispatcher : dispatchers) {
|
|
|
|
dispatcher->DispatchEvents();
|
2016-02-10 16:21:26 +03:00
|
|
|
}
|
2015-07-29 04:57:39 +03:00
|
|
|
}
|
|
|
|
|
2015-07-27 02:06:00 +03:00
|
|
|
void nsRefreshDriver::RunFrameRequestCallbacks(TimeStamp aNowTime) {
|
2015-04-21 19:44:40 +03:00
|
|
|
// Grab all of our frame request callbacks up front.
|
|
|
|
nsTArray<DocumentFrameCallbacks> frameRequestCallbacks(
|
|
|
|
mFrameRequestCallbackDocs.Length() +
|
|
|
|
mThrottledFrameRequestCallbackDocs.Length());
|
|
|
|
|
|
|
|
// First, grab throttled frame request callbacks.
|
|
|
|
{
|
2019-01-02 16:05:23 +03:00
|
|
|
nsTArray<Document*> docsToRemove;
|
2015-04-21 19:44:40 +03:00
|
|
|
|
|
|
|
// We always tick throttled frame requests if the entire refresh driver is
|
|
|
|
// throttled, because in that situation throttled frame requests tick at the
|
|
|
|
// same frequency as non-throttled frame requests.
|
|
|
|
bool tickThrottledFrameRequests = mThrottled;
|
|
|
|
|
|
|
|
if (!tickThrottledFrameRequests &&
|
|
|
|
aNowTime >= mNextThrottledFrameRequestTick) {
|
|
|
|
mNextThrottledFrameRequestTick =
|
|
|
|
aNowTime + mThrottledFrameRequestInterval;
|
|
|
|
tickThrottledFrameRequests = true;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
for (Document* doc : mThrottledFrameRequestCallbackDocs) {
|
2015-04-21 19:44:40 +03:00
|
|
|
if (tickThrottledFrameRequests) {
|
|
|
|
// We're ticking throttled documents, so grab this document's requests.
|
|
|
|
// We don't bother appending to docsToRemove because we're going to
|
|
|
|
// clear mThrottledFrameRequestCallbackDocs anyway.
|
|
|
|
TakeFrameRequestCallbacksFrom(doc, frameRequestCallbacks);
|
|
|
|
} else if (!doc->ShouldThrottleFrameRequests()) {
|
|
|
|
// This document is no longer throttled, so grab its requests even
|
|
|
|
// though we're not ticking throttled frame requests right now. If
|
|
|
|
// this is the first unthrottled document with frame requests, we'll
|
|
|
|
// enter high precision mode the next time the callback is scheduled.
|
|
|
|
TakeFrameRequestCallbacksFrom(doc, frameRequestCallbacks);
|
|
|
|
docsToRemove.AppendElement(doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove all the documents we're ticking from
|
|
|
|
// mThrottledFrameRequestCallbackDocs so they can be readded as needed.
|
|
|
|
if (tickThrottledFrameRequests) {
|
|
|
|
mThrottledFrameRequestCallbackDocs.Clear();
|
|
|
|
} else {
|
|
|
|
// XXX(seth): We're using this approach to avoid concurrent modification
|
|
|
|
// of mThrottledFrameRequestCallbackDocs. docsToRemove usually has either
|
|
|
|
// zero elements or a very small number, so this should be OK in practice.
|
2019-01-02 16:05:23 +03:00
|
|
|
for (Document* doc : docsToRemove) {
|
2015-04-21 19:44:40 +03:00
|
|
|
mThrottledFrameRequestCallbackDocs.RemoveElement(doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now grab unthrottled frame request callbacks.
|
2019-01-02 16:05:23 +03:00
|
|
|
for (Document* doc : mFrameRequestCallbackDocs) {
|
2015-04-21 19:44:40 +03:00
|
|
|
TakeFrameRequestCallbacksFrom(doc, frameRequestCallbacks);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset mFrameRequestCallbackDocs so they can be readded as needed.
|
|
|
|
mFrameRequestCallbackDocs.Clear();
|
|
|
|
|
2015-06-16 22:56:10 +03:00
|
|
|
if (!frameRequestCallbacks.IsEmpty()) {
|
2019-01-18 18:40:15 +03:00
|
|
|
AUTO_PROFILER_TRACING_DOCSHELL("Paint", "Scripts", GRAPHICS,
|
2018-11-07 00:45:50 +03:00
|
|
|
GetDocShell(mPresContext));
|
2015-06-18 00:36:40 +03:00
|
|
|
for (const DocumentFrameCallbacks& docCallbacks : frameRequestCallbacks) {
|
2015-06-16 22:56:10 +03:00
|
|
|
// XXXbz Bug 863140: GetInnerWindow can return the outer
|
|
|
|
// window in some cases.
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* innerWindow =
|
|
|
|
docCallbacks.mDocument->GetInnerWindow();
|
2015-06-16 22:56:10 +03:00
|
|
|
DOMHighResTimeStamp timeStamp = 0;
|
2017-11-22 02:07:45 +03:00
|
|
|
if (innerWindow) {
|
2016-06-09 20:04:42 +03:00
|
|
|
mozilla::dom::Performance* perf = innerWindow->GetPerformance();
|
2015-06-16 22:56:10 +03:00
|
|
|
if (perf) {
|
|
|
|
timeStamp = perf->GetDOMTiming()->TimeStampToDOMHighRes(aNowTime);
|
2019-10-04 01:53:28 +03:00
|
|
|
// 0 is an inappropriate mixin for this this area; however CSS
|
|
|
|
// Animations needs to have it's Time Reduction Logic refactored, so
|
|
|
|
// it's currently only clamping for RFP mode. RFP mode gives a much
|
|
|
|
// lower time precision, so we accept the security leak here for now
|
|
|
|
if (!perf->IsSystemPrincipal()) {
|
|
|
|
timeStamp = nsRFPService::ReduceTimePrecisionAsMSecs(
|
|
|
|
timeStamp, 0, TimerPrecisionType::RFPOnly);
|
|
|
|
}
|
2015-06-16 22:56:10 +03:00
|
|
|
}
|
|
|
|
// else window is partially torn down already
|
2015-04-21 19:44:40 +03:00
|
|
|
}
|
2015-07-20 17:14:24 +03:00
|
|
|
for (auto& callback : docCallbacks.mCallbacks) {
|
2019-02-25 09:15:56 +03:00
|
|
|
if (docCallbacks.mDocument->IsCanceledFrameRequestCallback(
|
|
|
|
callback.mHandle)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-06-17 07:36:29 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIGlobalObject> global(innerWindow ? innerWindow->AsGlobal()
|
|
|
|
: nullptr);
|
|
|
|
CallbackDebuggerNotificationGuard guard(
|
|
|
|
global, DebuggerNotificationType::RequestAnimationFrameCallback);
|
|
|
|
|
2019-02-25 09:02:12 +03:00
|
|
|
// MOZ_KnownLive is OK, because the stack array frameRequestCallbacks
|
|
|
|
// keeps callback alive and the mCallback strong reference can't be
|
|
|
|
// mutated by the call.
|
|
|
|
MOZ_KnownLive(callback.mCallback)->Call(timeStamp);
|
2015-04-21 19:44:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-10 02:38:50 +03:00
|
|
|
struct RunnableWithDelay {
|
|
|
|
nsCOMPtr<nsIRunnable> mRunnable;
|
|
|
|
uint32_t mDelay;
|
|
|
|
};
|
|
|
|
|
|
|
|
static AutoTArray<RunnableWithDelay, 8>* sPendingIdleRunnables = nullptr;
|
|
|
|
|
2019-04-15 18:41:15 +03:00
|
|
|
void nsRefreshDriver::DispatchIdleRunnableAfterTickUnlessExists(
|
|
|
|
nsIRunnable* aRunnable, uint32_t aDelay) {
|
2017-06-10 02:38:50 +03:00
|
|
|
if (!sPendingIdleRunnables) {
|
|
|
|
sPendingIdleRunnables = new AutoTArray<RunnableWithDelay, 8>();
|
2019-04-15 18:41:15 +03:00
|
|
|
} else {
|
|
|
|
for (uint32_t i = 0; i < sPendingIdleRunnables->Length(); ++i) {
|
|
|
|
if ((*sPendingIdleRunnables)[i].mRunnable == aRunnable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2017-06-10 02:38:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RunnableWithDelay rwd = {aRunnable, aDelay};
|
|
|
|
sPendingIdleRunnables->AppendElement(rwd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsRefreshDriver::CancelIdleRunnable(nsIRunnable* aRunnable) {
|
|
|
|
if (!sPendingIdleRunnables) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < sPendingIdleRunnables->Length(); ++i) {
|
|
|
|
if ((*sPendingIdleRunnables)[i].mRunnable == aRunnable) {
|
|
|
|
sPendingIdleRunnables->RemoveElementAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sPendingIdleRunnables->IsEmpty()) {
|
|
|
|
delete sPendingIdleRunnables;
|
|
|
|
sPendingIdleRunnables = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-19 10:58:45 +03:00
|
|
|
static CallState ReduceAnimations(Document& aDocument, void* aData) {
|
2019-12-14 08:08:39 +03:00
|
|
|
if (aDocument.GetPresContext() &&
|
|
|
|
aDocument.GetPresContext()->EffectCompositor()->NeedsReducing()) {
|
|
|
|
aDocument.GetPresContext()->EffectCompositor()->ReduceAnimations();
|
2019-05-20 08:48:29 +03:00
|
|
|
}
|
2019-12-14 08:08:39 +03:00
|
|
|
aDocument.EnumerateSubDocuments(ReduceAnimations, nullptr);
|
2019-12-19 10:58:45 +03:00
|
|
|
return CallState::Continue;
|
2019-05-20 08:48:29 +03:00
|
|
|
}
|
|
|
|
|
2018-12-08 02:28:03 +03:00
|
|
|
void nsRefreshDriver::Tick(VsyncId aId, TimeStamp aNowTime) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(!nsContentUtils::GetCurrentJSContext(),
|
|
|
|
"Shouldn't have a JSContext on the stack");
|
2012-12-12 02:15:32 +04:00
|
|
|
|
2013-02-27 15:50:27 +04:00
|
|
|
if (nsNPAPIPluginInstance::InPluginCallUnsafeForReentry()) {
|
2012-12-07 03:58:14 +04:00
|
|
|
NS_ERROR("Refresh driver should not run during plugin call!");
|
|
|
|
// Try to survive this by just ignoring the refresh tick.
|
2012-12-12 02:15:32 +04:00
|
|
|
return;
|
2012-12-07 03:58:14 +04:00
|
|
|
}
|
2010-02-04 00:17:55 +03:00
|
|
|
|
2018-05-19 00:46:59 +03:00
|
|
|
AUTO_PROFILER_LABEL("nsRefreshDriver::Tick", LAYOUT);
|
2012-12-12 02:15:32 +04:00
|
|
|
|
|
|
|
// We're either frozen or we were disconnected (likely in the middle
|
|
|
|
// of a tick iteration). Just do nothing here, since our
|
|
|
|
// prescontext went away.
|
2013-12-20 01:38:35 +04:00
|
|
|
if (IsFrozen() || !mPresContext) {
|
2012-12-12 02:15:32 +04:00
|
|
|
return;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
2015-03-25 00:28:34 +03:00
|
|
|
// We can have a race condition where the vsync timestamp
|
|
|
|
// is before the most recent refresh due to a forced refresh.
|
|
|
|
// The underlying assumption is that the refresh driver tick can only
|
|
|
|
// go forward in time, not backwards. To prevent the refresh
|
|
|
|
// driver from going back in time, just skip this tick and
|
|
|
|
// wait until the next tick.
|
|
|
|
if ((aNowTime <= mMostRecentRefresh) && !mTestControllingRefreshes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-24 22:58:15 +03:00
|
|
|
bool isPresentingInVR = false;
|
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
|
|
|
isPresentingInVR = gfx::VRManagerChild::IsPresenting();
|
2019-11-26 17:35:02 +03:00
|
|
|
#endif // defined(MOZ_WIDGET_ANDROID)
|
2019-10-24 22:58:15 +03:00
|
|
|
|
|
|
|
if (!isPresentingInVR && IsWaitingForPaint(aNowTime)) {
|
|
|
|
// In immersive VR mode, we do not get notifications when frames are
|
|
|
|
// presented, so we do not wait for the compositor in that mode.
|
|
|
|
|
2014-05-29 01:42:17 +04:00
|
|
|
// We're currently suspended waiting for earlier Tick's to
|
|
|
|
// be completed (on the Compositor). Mark that we missed the paint
|
|
|
|
// and keep waiting.
|
2019-02-12 19:52:43 +03:00
|
|
|
PROFILER_ADD_MARKER("nsRefreshDriver::Tick waiting for paint", LAYOUT);
|
2014-05-29 01:42:17 +04:00
|
|
|
return;
|
|
|
|
}
|
2018-07-15 14:19:29 +03:00
|
|
|
|
|
|
|
TimeStamp previousRefresh = mMostRecentRefresh;
|
|
|
|
mMostRecentRefresh = aNowTime;
|
|
|
|
|
2014-05-29 01:43:41 +04:00
|
|
|
if (mRootRefresh) {
|
2017-01-05 10:31:56 +03:00
|
|
|
mRootRefresh->RemoveRefreshObserver(this, FlushType::Style);
|
2014-05-29 01:43:41 +04:00
|
|
|
mRootRefresh = nullptr;
|
|
|
|
}
|
2014-08-15 06:24:50 +04:00
|
|
|
mSkippedPaints = false;
|
2016-09-09 13:06:29 +03:00
|
|
|
mWarningThreshold = 1;
|
2014-05-29 01:42:17 +04:00
|
|
|
|
2019-04-03 15:40:26 +03:00
|
|
|
RefPtr<PresShell> presShell = mPresContext->GetPresShell();
|
2018-01-27 15:17:26 +03:00
|
|
|
if (!presShell ||
|
2019-01-03 16:16:20 +03:00
|
|
|
(!HasObservers() && !HasImageRequests() &&
|
|
|
|
mVisualViewportResizeEvents.IsEmpty() && mScrollEvents.IsEmpty() &&
|
|
|
|
mVisualViewportScrollEvents.IsEmpty())) {
|
2009-12-31 22:07:57 +03:00
|
|
|
// Things are being destroyed, or we no longer have any observers.
|
|
|
|
// We don't want to stop the timer when observers are initially
|
|
|
|
// removed, because sometimes observers can be added and removed
|
|
|
|
// often depending on what other things are going on and in that
|
|
|
|
// situation we don't want to thrash our timer. So instead we
|
|
|
|
// wait until we get a Notify() call when we have no observers
|
|
|
|
// before stopping the timer.
|
2019-01-30 00:57:26 +03:00
|
|
|
// On top level content pages keep the timer running initially so that we
|
|
|
|
// paint the page soon enough.
|
2019-04-22 18:40:46 +03:00
|
|
|
if (presShell && !mThrottled && !mTestControllingRefreshes &&
|
|
|
|
XRE_IsContentProcess() &&
|
|
|
|
mPresContext->Document()->IsTopLevelContentDocument() &&
|
|
|
|
!gfxPlatform::IsInLayoutAsapMode() &&
|
|
|
|
!mPresContext->HadContentfulPaint() &&
|
|
|
|
mPresContext->Document()->GetReadyStateEnum() <
|
|
|
|
Document::READYSTATE_COMPLETE) {
|
2019-01-30 00:57:26 +03:00
|
|
|
if (mInitialTimerRunningLimit.IsNull()) {
|
|
|
|
mInitialTimerRunningLimit =
|
|
|
|
TimeStamp::Now() + TimeDuration::FromSeconds(4.0f);
|
|
|
|
// Don't let the timer to run forever, so limit to 4s for now.
|
|
|
|
} else if (mInitialTimerRunningLimit < TimeStamp::Now()) {
|
|
|
|
StopTimer();
|
|
|
|
}
|
2019-04-22 18:40:46 +03:00
|
|
|
} else {
|
|
|
|
StopTimer();
|
2019-01-30 00:57:26 +03:00
|
|
|
}
|
2012-12-12 02:15:32 +04:00
|
|
|
return;
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
2016-05-03 10:58:57 +03:00
|
|
|
mResizeSuppressed = false;
|
|
|
|
|
2013-09-04 15:47:21 +04:00
|
|
|
AutoRestore<bool> restoreInRefresh(mInRefresh);
|
|
|
|
mInRefresh = true;
|
|
|
|
|
2014-08-28 23:24:26 +04:00
|
|
|
AutoRestore<TimeStamp> restoreTickStart(mTickStart);
|
|
|
|
mTickStart = TimeStamp::Now();
|
2018-12-08 02:28:03 +03:00
|
|
|
mTickVsyncId = aId;
|
2019-01-03 22:43:04 +03:00
|
|
|
mTickVsyncTime = aNowTime;
|
2014-08-28 23:24:26 +04:00
|
|
|
|
2016-02-29 09:53:15 +03:00
|
|
|
gfxPlatform::GetPlatform()->SchedulePaintIfDeviceReset();
|
2015-12-17 22:20:08 +03:00
|
|
|
|
2016-03-14 18:50:55 +03:00
|
|
|
// We want to process any pending APZ metrics ahead of their positions
|
|
|
|
// in the queue. This will prevent us from spending precious time
|
|
|
|
// painting a stale displayport.
|
2019-06-24 06:57:06 +03:00
|
|
|
if (StaticPrefs::apz_peek_messages_enabled()) {
|
2016-03-14 18:50:55 +03:00
|
|
|
nsLayoutUtils::UpdateDisplayPortMarginsFromPendingMessages();
|
|
|
|
}
|
|
|
|
|
2017-06-29 14:46:11 +03:00
|
|
|
AutoTArray<nsCOMPtr<nsIRunnable>, 16> earlyRunners;
|
|
|
|
earlyRunners.SwapElements(mEarlyRunners);
|
2018-02-05 01:15:53 +03:00
|
|
|
for (auto& runner : earlyRunners) {
|
|
|
|
runner->Run();
|
2017-06-25 00:38:42 +03:00
|
|
|
}
|
|
|
|
|
2015-05-05 17:56:01 +03:00
|
|
|
// Resize events should be fired before layout flushes or
|
|
|
|
// calling animation frame callbacks.
|
2019-12-11 15:17:17 +03:00
|
|
|
AutoTArray<RefPtr<PresShell>, 16> observers;
|
2015-05-05 17:56:01 +03:00
|
|
|
observers.AppendElements(mResizeEventFlushObservers);
|
2019-12-11 15:17:17 +03:00
|
|
|
for (RefPtr<PresShell>& presShell : Reversed(observers)) {
|
2015-05-05 17:56:01 +03:00
|
|
|
if (!mPresContext || !mPresContext->GetPresShell()) {
|
2018-02-05 00:24:16 +03:00
|
|
|
StopTimer();
|
|
|
|
return;
|
2015-05-05 17:56:01 +03:00
|
|
|
}
|
|
|
|
// Make sure to not process observers which might have been removed
|
|
|
|
// during previous iterations.
|
2019-12-11 15:17:17 +03:00
|
|
|
if (!mResizeEventFlushObservers.RemoveElement(presShell)) {
|
2015-05-05 17:56:01 +03:00
|
|
|
continue;
|
|
|
|
}
|
2019-12-11 15:17:17 +03:00
|
|
|
presShell->FireResizeEvent();
|
2015-05-05 17:56:01 +03:00
|
|
|
}
|
2018-12-21 00:35:26 +03:00
|
|
|
DispatchVisualViewportResizeEvents();
|
2015-05-05 17:56:01 +03:00
|
|
|
|
2019-07-25 04:31:41 +03:00
|
|
|
double phaseMetrics[MOZ_ARRAY_LENGTH(mObservers)] = {
|
|
|
|
0.0,
|
|
|
|
};
|
|
|
|
|
2009-12-22 00:46:25 +03:00
|
|
|
/*
|
|
|
|
* The timer holds a reference to |this| while calling |Notify|.
|
|
|
|
* However, implementations of |WillRefresh| are permitted to destroy
|
|
|
|
* the pres context, which will cause our |mPresContext| to become
|
|
|
|
* null. If this happens, we must stop notifying observers.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < ArrayLength(mObservers); ++i) {
|
2019-07-25 04:31:41 +03:00
|
|
|
AutoRecordPhase phaseRecord(&phaseMetrics[i]);
|
|
|
|
|
2009-10-08 07:22:42 +04:00
|
|
|
ObserverArray::EndLimitedIterator etor(mObservers[i]);
|
|
|
|
while (etor.HasMore()) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsARefreshObserver> obs = etor.GetNext();
|
2012-12-12 02:15:32 +04:00
|
|
|
obs->WillRefresh(aNowTime);
|
2014-12-08 23:43:16 +03:00
|
|
|
|
2009-12-22 00:46:25 +03:00
|
|
|
if (!mPresContext || !mPresContext->GetPresShell()) {
|
|
|
|
StopTimer();
|
2012-12-12 02:15:32 +04:00
|
|
|
return;
|
2009-12-22 00:46:25 +03:00
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
2011-11-10 01:39:16 +04:00
|
|
|
|
2019-05-20 08:22:03 +03:00
|
|
|
// Any animation timelines updated above may cause animations to queue
|
|
|
|
// Promise resolution microtasks. We shouldn't run these, however, until we
|
|
|
|
// have fully updated the animation state.
|
|
|
|
//
|
2019-05-20 08:48:29 +03:00
|
|
|
// As per the "update animations and send events" procedure[1], we should
|
|
|
|
// remove replaced animations and then run these microtasks before
|
|
|
|
// dispatching the corresponding animation events.
|
2019-05-20 08:22:03 +03:00
|
|
|
//
|
|
|
|
// [1]
|
|
|
|
// https://drafts.csswg.org/web-animations-1/#update-animations-and-send-events
|
|
|
|
if (i == 1) {
|
|
|
|
nsAutoMicroTask mt;
|
2019-12-14 08:08:39 +03:00
|
|
|
ReduceAnimations(*mPresContext->Document(), nullptr);
|
2019-05-20 08:22:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if running the microtask checkpoint caused the pres context to
|
|
|
|
// be destroyed.
|
|
|
|
if (i == 1 && (!mPresContext || !mPresContext->GetPresShell())) {
|
|
|
|
StopTimer();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-11 09:58:08 +03:00
|
|
|
if (i == 1) {
|
2017-01-05 10:31:56 +03:00
|
|
|
// This is the FlushType::Style case.
|
2014-05-29 01:42:16 +04:00
|
|
|
|
2018-01-30 02:22:47 +03:00
|
|
|
DispatchScrollEvents();
|
2018-12-21 00:35:26 +03:00
|
|
|
DispatchVisualViewportScrollEvents();
|
2015-07-29 04:57:39 +03:00
|
|
|
DispatchAnimationEvents();
|
2018-09-08 01:53:33 +03:00
|
|
|
RunFullscreenSteps();
|
2015-07-27 02:06:00 +03:00
|
|
|
RunFrameRequestCallbacks(aNowTime);
|
2010-09-09 09:38:04 +04:00
|
|
|
|
2011-01-14 23:03:06 +03:00
|
|
|
if (mPresContext && mPresContext->GetPresShell()) {
|
2019-04-16 10:25:10 +03:00
|
|
|
AutoTArray<PresShell*, 16> observers;
|
2011-01-14 23:03:06 +03:00
|
|
|
observers.AppendElements(mStyleFlushObservers);
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t j = observers.Length();
|
2011-01-14 23:03:06 +03:00
|
|
|
j && mPresContext && mPresContext->GetPresShell(); --j) {
|
|
|
|
// Make sure to not process observers which might have been removed
|
|
|
|
// during previous iterations.
|
2019-04-16 10:25:10 +03:00
|
|
|
PresShell* rawPresShell = observers[j - 1];
|
2019-04-13 15:43:57 +03:00
|
|
|
if (!mStyleFlushObservers.RemoveElement(rawPresShell)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-16 10:25:10 +03:00
|
|
|
RefPtr<PresShell> presShell = rawPresShell;
|
2019-04-13 15:43:57 +03:00
|
|
|
presShell->mObservingStyleFlushes = false;
|
|
|
|
presShell->FlushPendingNotifications(
|
2017-01-05 10:31:56 +03:00
|
|
|
ChangesToFlush(FlushType::Style, false));
|
2014-10-02 06:32:09 +04:00
|
|
|
// Inform the FontFaceSet that we ticked, so that it can resolve its
|
|
|
|
// ready promise if it needs to (though it might still be waiting on
|
|
|
|
// a layout flush).
|
2019-04-13 15:43:57 +03:00
|
|
|
presShell->NotifyFontFaceSetOnRefresh();
|
2015-10-21 17:12:00 +03:00
|
|
|
mNeedToRecomputeVisibility = true;
|
2019-08-21 04:43:30 +03:00
|
|
|
|
2019-11-01 07:33:48 +03:00
|
|
|
// Record the telemetry for events that occurred between ticks.
|
|
|
|
presShell->PingPerTickTelemetry(FlushType::Style);
|
2011-01-14 23:03:06 +03:00
|
|
|
}
|
2014-05-29 01:42:16 +04:00
|
|
|
}
|
2017-08-11 09:58:08 +03:00
|
|
|
} else if (i == 2) {
|
2017-01-05 10:31:56 +03:00
|
|
|
// This is the FlushType::Layout case.
|
2019-04-16 10:25:10 +03:00
|
|
|
AutoTArray<PresShell*, 16> observers;
|
2015-07-13 02:32:04 +03:00
|
|
|
observers.AppendElements(mLayoutFlushObservers);
|
|
|
|
for (uint32_t j = observers.Length();
|
|
|
|
j && mPresContext && mPresContext->GetPresShell(); --j) {
|
|
|
|
// Make sure to not process observers which might have been removed
|
|
|
|
// during previous iterations.
|
2019-04-16 10:25:10 +03:00
|
|
|
PresShell* rawPresShell = observers[j - 1];
|
2019-04-13 15:43:57 +03:00
|
|
|
if (!mLayoutFlushObservers.RemoveElement(rawPresShell)) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-16 10:25:10 +03:00
|
|
|
RefPtr<PresShell> presShell = rawPresShell;
|
2019-04-13 15:43:57 +03:00
|
|
|
presShell->mObservingLayoutFlushes = false;
|
|
|
|
presShell->mWasLastReflowInterrupted = false;
|
|
|
|
FlushType flushType = HasPendingAnimations(presShell)
|
2017-01-05 10:31:56 +03:00
|
|
|
? FlushType::Layout
|
|
|
|
: FlushType::InterruptibleLayout;
|
2019-04-13 15:43:57 +03:00
|
|
|
presShell->FlushPendingNotifications(ChangesToFlush(flushType, false));
|
2015-07-13 02:32:04 +03:00
|
|
|
// Inform the FontFaceSet that we ticked, so that it can resolve its
|
|
|
|
// ready promise if it needs to.
|
2019-04-13 15:43:57 +03:00
|
|
|
presShell->NotifyFontFaceSetOnRefresh();
|
2015-10-21 17:12:00 +03:00
|
|
|
mNeedToRecomputeVisibility = true;
|
2019-08-21 04:43:30 +03:00
|
|
|
|
2019-11-01 07:33:48 +03:00
|
|
|
// Record the telemetry for events that occurred between ticks.
|
|
|
|
presShell->PingPerTickTelemetry(FlushType::Layout);
|
2015-10-21 17:12:00 +03:00
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
2015-07-13 02:32:04 +03:00
|
|
|
|
|
|
|
// The pres context may be destroyed during we do the flushing.
|
|
|
|
if (!mPresContext || !mPresContext->GetPresShell()) {
|
|
|
|
StopTimer();
|
|
|
|
return;
|
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
|
|
|
|
2016-03-26 00:49:43 +03:00
|
|
|
// Recompute approximate frame visibility if it's necessary and enough time
|
|
|
|
// has passed since the last time we did it.
|
2015-05-30 09:50:51 +03:00
|
|
|
if (mNeedToRecomputeVisibility && !mThrottled &&
|
|
|
|
aNowTime >= mNextRecomputeVisibilityTick &&
|
|
|
|
!presShell->IsPaintingSuppressed()) {
|
|
|
|
mNextRecomputeVisibilityTick = aNowTime + mMinRecomputeVisibilityInterval;
|
|
|
|
mNeedToRecomputeVisibility = false;
|
|
|
|
|
2016-03-26 00:49:43 +03:00
|
|
|
presShell->ScheduleApproximateFrameVisibilityUpdateNow();
|
2015-05-30 09:50:51 +03:00
|
|
|
}
|
|
|
|
|
2017-02-16 16:53:59 +03:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
// Update any popups that may need to be moved or hidden due to their
|
|
|
|
// anchor changing.
|
2018-02-05 01:15:53 +03:00
|
|
|
if (nsXULPopupManager* pm = nsXULPopupManager::GetInstance()) {
|
2017-02-16 16:53:59 +03:00
|
|
|
pm->UpdatePopupPositions(this);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-26 14:11:17 +03:00
|
|
|
UpdateIntersectionObservations();
|
2016-10-28 17:24:00 +03:00
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
/*
|
|
|
|
* Perform notification to imgIRequests subscribed to listen
|
|
|
|
* for refresh events.
|
|
|
|
*/
|
|
|
|
|
2015-10-23 07:16:45 +03:00
|
|
|
for (auto iter = mStartTable.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
const uint32_t& delay = iter.Key();
|
|
|
|
ImageStartData* data = iter.UserData();
|
|
|
|
|
|
|
|
if (data->mStartTime) {
|
|
|
|
TimeStamp& start = *data->mStartTime;
|
|
|
|
TimeDuration prev = previousRefresh - start;
|
|
|
|
TimeDuration curr = aNowTime - start;
|
|
|
|
uint32_t prevMultiple = uint32_t(prev.ToMilliseconds()) / delay;
|
|
|
|
|
|
|
|
// We want to trigger images' refresh if we've just crossed over a
|
|
|
|
// multiple of the first image's start time. If so, set the animation
|
|
|
|
// start time to the nearest multiple of the delay and move all the
|
|
|
|
// images in this table to the main requests table.
|
|
|
|
if (prevMultiple != uint32_t(curr.ToMilliseconds()) / delay) {
|
|
|
|
mozilla::TimeStamp desired =
|
|
|
|
start + TimeDuration::FromMilliseconds(prevMultiple * delay);
|
|
|
|
BeginRefreshingImages(data->mEntries, desired);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This is the very first time we've drawn images with this time delay.
|
|
|
|
// Set the animation start time to "now" and move all the images in this
|
|
|
|
// table to the main requests table.
|
|
|
|
mozilla::TimeStamp desired = aNowTime;
|
|
|
|
BeginRefreshingImages(data->mEntries, desired);
|
|
|
|
data->mStartTime.emplace(aNowTime);
|
|
|
|
}
|
|
|
|
}
|
2013-05-18 00:57:26 +04:00
|
|
|
|
2011-11-10 01:39:16 +04:00
|
|
|
if (mRequests.Count()) {
|
2013-09-06 12:48:26 +04:00
|
|
|
// RequestRefresh may run scripts, so it's not safe to directly call it
|
|
|
|
// while using a hashtable enumerator to enumerate mRequests in case
|
|
|
|
// script modifies the hashtable. Instead, we build a (local) array of
|
|
|
|
// images to refresh, and then we refresh each image in that array.
|
|
|
|
nsCOMArray<imgIContainer> imagesToRefresh(mRequests.Count());
|
2015-07-15 12:05:06 +03:00
|
|
|
|
|
|
|
for (auto iter = mRequests.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsISupportsHashKey* entry = iter.Get();
|
|
|
|
auto req = static_cast<imgIRequest*>(entry->GetKey());
|
|
|
|
MOZ_ASSERT(req, "Unable to retrieve the image request");
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
if (NS_SUCCEEDED(req->GetImage(getter_AddRefs(image)))) {
|
2016-06-21 01:38:10 +03:00
|
|
|
imagesToRefresh.AppendElement(image.forget());
|
2015-07-15 12:05:06 +03:00
|
|
|
}
|
|
|
|
}
|
2013-09-06 12:48:26 +04:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < imagesToRefresh.Length(); i++) {
|
|
|
|
imagesToRefresh[i]->RequestRefresh(aNowTime);
|
|
|
|
}
|
2011-11-10 01:39:16 +04:00
|
|
|
}
|
2013-05-18 00:57:26 +04:00
|
|
|
|
2019-07-25 04:31:41 +03:00
|
|
|
double phasePaint = 0.0;
|
2017-06-10 02:38:50 +03:00
|
|
|
bool dispatchRunnablesAfterTick = false;
|
2011-12-24 07:52:22 +04:00
|
|
|
if (mViewManagerFlushIsPending) {
|
2019-07-25 04:31:41 +03:00
|
|
|
AutoRecordPhase paintRecord(&phasePaint);
|
2015-10-22 00:10:05 +03:00
|
|
|
RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get();
|
|
|
|
|
2014-09-09 22:54:08 +04:00
|
|
|
nsTArray<nsDocShell*> profilingDocShells;
|
|
|
|
GetProfileTimelineSubDocShells(GetDocShell(mPresContext),
|
|
|
|
profilingDocShells);
|
2015-06-18 00:36:40 +03:00
|
|
|
for (nsDocShell* docShell : profilingDocShells) {
|
2014-09-09 22:54:08 +04:00
|
|
|
// For the sake of the profile timeline's simplicity, this is flagged as
|
|
|
|
// paint even if it includes creating display lists
|
2015-10-22 00:10:05 +03:00
|
|
|
MOZ_ASSERT(timelines);
|
|
|
|
MOZ_ASSERT(timelines->HasConsumer(docShell));
|
|
|
|
timelines->AddMarkerForDocShell(docShell, "Paint",
|
|
|
|
MarkerTracingType::START);
|
2014-09-09 22:54:08 +04:00
|
|
|
}
|
2015-10-22 00:10:05 +03:00
|
|
|
|
2013-05-14 03:47:02 +04:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
if (nsLayoutUtils::InvalidationDebuggingIsEnabled()) {
|
2013-11-24 02:44:18 +04:00
|
|
|
printf_stderr("Starting ProcessPendingUpdates\n");
|
2013-05-14 03:47:02 +04:00
|
|
|
}
|
2012-08-13 14:10:10 +04:00
|
|
|
#endif
|
2013-01-04 06:53:15 +04:00
|
|
|
|
2011-12-24 07:52:22 +04:00
|
|
|
mViewManagerFlushIsPending = false;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsViewManager> vm = mPresContext->GetPresShell()->GetViewManager();
|
2019-10-24 22:58:15 +03:00
|
|
|
const bool skipPaint = isPresentingInVR;
|
|
|
|
// Skip the paint in immersive VR mode because whatever we paint here will
|
|
|
|
// not end up on the screen. The screen is displaying WebGL content from a
|
|
|
|
// single canvas in that mode.
|
2019-08-22 01:41:56 +03:00
|
|
|
if (!skipPaint) {
|
2016-10-12 10:58:04 +03:00
|
|
|
PaintTelemetry::AutoRecordPaint record;
|
|
|
|
vm->ProcessPendingUpdates();
|
|
|
|
}
|
2015-10-22 00:10:05 +03:00
|
|
|
|
2013-05-14 03:47:02 +04:00
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
if (nsLayoutUtils::InvalidationDebuggingIsEnabled()) {
|
2013-11-24 02:44:18 +04:00
|
|
|
printf_stderr("Ending ProcessPendingUpdates\n");
|
2013-05-14 03:47:02 +04:00
|
|
|
}
|
2012-08-13 14:10:10 +04:00
|
|
|
#endif
|
2015-10-22 00:10:05 +03:00
|
|
|
|
2015-06-18 00:36:40 +03:00
|
|
|
for (nsDocShell* docShell : profilingDocShells) {
|
2015-10-22 00:10:05 +03:00
|
|
|
MOZ_ASSERT(timelines);
|
|
|
|
MOZ_ASSERT(timelines->HasConsumer(docShell));
|
|
|
|
timelines->AddMarkerForDocShell(docShell, "Paint",
|
|
|
|
MarkerTracingType::END);
|
2014-09-09 22:54:08 +04:00
|
|
|
}
|
2014-10-22 05:26:17 +04:00
|
|
|
|
2017-06-10 02:38:50 +03:00
|
|
|
dispatchRunnablesAfterTick = true;
|
2017-10-03 11:00:38 +03:00
|
|
|
mHasScheduleFlush = false;
|
2011-12-24 07:52:22 +04:00
|
|
|
}
|
2013-08-19 17:08:44 +04:00
|
|
|
|
2019-07-25 04:31:41 +03:00
|
|
|
double totalMs = (TimeStamp::Now() - mTickStart).ToMilliseconds();
|
|
|
|
|
2015-03-18 09:59:01 +03:00
|
|
|
#ifndef ANDROID /* bug 1142079 */
|
2019-07-25 04:31:41 +03:00
|
|
|
mozilla::Telemetry::Accumulate(mozilla::Telemetry::REFRESH_DRIVER_TICK,
|
|
|
|
static_cast<uint32_t>(totalMs));
|
2015-03-18 09:59:01 +03:00
|
|
|
#endif
|
2014-12-08 23:43:16 +03:00
|
|
|
|
2019-07-25 04:31:41 +03:00
|
|
|
// Bug 1568107: If the totalMs is greater than 1/60th second (ie. 1000/60 ms)
|
|
|
|
// then record, via telemetry, the percentage of time spent in each
|
|
|
|
// sub-system.
|
|
|
|
if (totalMs > 1000.0 / 60.0) {
|
|
|
|
auto record = [=](const nsCString& aKey, double aDurationMs) -> void {
|
|
|
|
MOZ_ASSERT(aDurationMs <= totalMs);
|
|
|
|
auto phasePercent = static_cast<uint32_t>(aDurationMs * 100.0 / totalMs);
|
|
|
|
Telemetry::Accumulate(Telemetry::REFRESH_DRIVER_TICK_PHASE_WEIGHT, aKey,
|
|
|
|
phasePercent);
|
|
|
|
};
|
|
|
|
|
|
|
|
record(NS_LITERAL_CSTRING("Event"), phaseMetrics[0]);
|
|
|
|
record(NS_LITERAL_CSTRING("Style"), phaseMetrics[1]);
|
|
|
|
record(NS_LITERAL_CSTRING("Reflow"), phaseMetrics[2]);
|
|
|
|
record(NS_LITERAL_CSTRING("Display"), phaseMetrics[3]);
|
|
|
|
record(NS_LITERAL_CSTRING("Paint"), phasePaint);
|
|
|
|
|
|
|
|
// Explicitly record the time unaccounted for.
|
|
|
|
double other = totalMs -
|
|
|
|
std::accumulate(phaseMetrics, ArrayEnd(phaseMetrics), 0.0) -
|
|
|
|
phasePaint;
|
|
|
|
record(NS_LITERAL_CSTRING("Other"), other);
|
|
|
|
}
|
|
|
|
|
2018-04-27 01:36:52 +03:00
|
|
|
if (mNotifyDOMContentFlushed) {
|
|
|
|
mNotifyDOMContentFlushed = false;
|
|
|
|
mPresContext->NotifyDOMContentFlushed();
|
|
|
|
}
|
|
|
|
|
2015-06-26 23:20:10 +03:00
|
|
|
nsTObserverArray<nsAPostRefreshObserver*>::ForwardIterator iter(
|
|
|
|
mPostRefreshObservers);
|
|
|
|
while (iter.HasMore()) {
|
|
|
|
nsAPostRefreshObserver* observer = iter.GetNext();
|
|
|
|
observer->DidRefresh();
|
2013-08-19 17:08:44 +04:00
|
|
|
}
|
2013-09-04 15:47:21 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(mInRefresh, "Still in refresh");
|
2016-08-16 18:46:13 +03:00
|
|
|
|
|
|
|
if (mPresContext->IsRoot() && XRE_IsContentProcess() &&
|
2019-06-26 03:38:09 +03:00
|
|
|
StaticPrefs::gfx_content_always_paint()) {
|
2016-08-16 18:46:13 +03:00
|
|
|
ScheduleViewManagerFlush();
|
|
|
|
}
|
2016-09-13 00:00:15 +03:00
|
|
|
|
2017-06-10 02:38:50 +03:00
|
|
|
if (dispatchRunnablesAfterTick && sPendingIdleRunnables) {
|
|
|
|
AutoTArray<RunnableWithDelay, 8>* runnables = sPendingIdleRunnables;
|
|
|
|
sPendingIdleRunnables = nullptr;
|
2018-02-05 01:15:53 +03:00
|
|
|
for (RunnableWithDelay& runnableWithDelay : *runnables) {
|
2019-01-26 20:18:05 +03:00
|
|
|
NS_DispatchToCurrentThreadQueue(runnableWithDelay.mRunnable.forget(),
|
|
|
|
runnableWithDelay.mDelay,
|
|
|
|
EventQueuePriority::Idle);
|
2017-06-10 02:38:50 +03:00
|
|
|
}
|
|
|
|
delete runnables;
|
2016-09-13 00:00:15 +03:00
|
|
|
}
|
2009-10-08 07:22:42 +04:00
|
|
|
}
|
2010-02-04 00:17:55 +03:00
|
|
|
|
2015-07-15 12:05:06 +03:00
|
|
|
void nsRefreshDriver::BeginRefreshingImages(RequestTable& aEntries,
|
2015-10-23 07:16:45 +03:00
|
|
|
mozilla::TimeStamp aDesired) {
|
2015-07-15 12:05:06 +03:00
|
|
|
for (auto iter = aEntries.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
auto req = static_cast<imgIRequest*>(iter.Get()->GetKey());
|
|
|
|
MOZ_ASSERT(req, "Unable to retrieve the image request");
|
2013-05-18 00:57:26 +04:00
|
|
|
|
2015-10-23 07:16:45 +03:00
|
|
|
mRequests.PutEntry(req);
|
2013-05-18 00:57:26 +04:00
|
|
|
|
2015-07-15 12:05:06 +03:00
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
if (NS_SUCCEEDED(req->GetImage(getter_AddRefs(image)))) {
|
2015-10-23 07:16:45 +03:00
|
|
|
image->SetAnimationStartTime(aDesired);
|
2015-07-15 12:05:06 +03:00
|
|
|
}
|
2013-05-18 00:57:26 +04:00
|
|
|
}
|
2015-07-15 12:05:06 +03:00
|
|
|
aEntries.Clear();
|
2013-05-18 00:57:26 +04:00
|
|
|
}
|
|
|
|
|
2010-02-04 00:17:55 +03:00
|
|
|
void nsRefreshDriver::Freeze() {
|
|
|
|
StopTimer();
|
2013-12-20 01:38:35 +04:00
|
|
|
mFreezeCount++;
|
2010-02-04 00:17:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsRefreshDriver::Thaw() {
|
2013-12-20 01:38:35 +04:00
|
|
|
NS_ASSERTION(mFreezeCount > 0, "Thaw() called on an unfrozen refresh driver");
|
|
|
|
|
|
|
|
if (mFreezeCount > 0) {
|
|
|
|
mFreezeCount--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mFreezeCount == 0) {
|
2018-01-27 15:17:26 +03:00
|
|
|
if (HasObservers() || HasImageRequests()) {
|
2013-12-20 01:38:35 +04:00
|
|
|
// FIXME: This isn't quite right, since our EnsureTimerStarted call
|
|
|
|
// updates our mMostRecentRefresh, but the DoRefresh call won't run
|
|
|
|
// and notify our observers until we get back to the event loop.
|
|
|
|
// Thus MostRecentRefresh() will lie between now and the DoRefresh.
|
2017-06-12 22:34:10 +03:00
|
|
|
RefPtr<nsRunnableMethod<nsRefreshDriver>> event = NewRunnableMethod(
|
|
|
|
"nsRefreshDriver::DoRefresh", this, &nsRefreshDriver::DoRefresh);
|
2017-03-15 07:15:24 +03:00
|
|
|
nsPresContext* pc = GetPresContext();
|
|
|
|
if (pc) {
|
2017-07-26 11:13:35 +03:00
|
|
|
pc->Document()->Dispatch(TaskCategory::Other, event.forget());
|
2017-03-15 07:15:24 +03:00
|
|
|
EnsureTimerStarted();
|
|
|
|
} else {
|
|
|
|
NS_ERROR("Thawing while document is being destroyed");
|
|
|
|
}
|
2013-12-20 01:38:35 +04:00
|
|
|
}
|
2010-02-04 00:17:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-29 01:42:17 +04:00
|
|
|
void nsRefreshDriver::FinishedWaitingForTransaction() {
|
|
|
|
mWaitingForTransaction = false;
|
2014-08-15 06:24:50 +04:00
|
|
|
mSkippedPaints = false;
|
2016-09-09 13:06:29 +03:00
|
|
|
mWarningThreshold = 1;
|
2014-05-29 01:42:17 +04:00
|
|
|
}
|
|
|
|
|
2017-07-12 16:10:25 +03:00
|
|
|
mozilla::layers::TransactionId nsRefreshDriver::GetTransactionId(
|
|
|
|
bool aThrottle) {
|
2018-09-06 05:21:39 +03:00
|
|
|
mOutstandingTransactionId = mOutstandingTransactionId.Next();
|
|
|
|
mNextTransactionId = mNextTransactionId.Next();
|
2014-05-29 01:42:17 +04:00
|
|
|
|
2018-09-06 05:21:39 +03:00
|
|
|
if (aThrottle && mOutstandingTransactionId - mCompletedTransaction >= 2 &&
|
2014-05-29 01:42:17 +04:00
|
|
|
!mWaitingForTransaction && !mTestControllingRefreshes) {
|
|
|
|
mWaitingForTransaction = true;
|
2014-08-15 06:24:50 +04:00
|
|
|
mSkippedPaints = false;
|
2016-09-09 13:06:29 +03:00
|
|
|
mWarningThreshold = 1;
|
2014-05-29 01:42:17 +04:00
|
|
|
}
|
|
|
|
|
2018-09-06 05:21:39 +03:00
|
|
|
return mNextTransactionId;
|
2014-05-29 01:42:17 +04:00
|
|
|
}
|
|
|
|
|
2016-04-13 23:59:15 +03:00
|
|
|
mozilla::layers::TransactionId nsRefreshDriver::LastTransactionId() const {
|
2018-09-06 05:21:39 +03:00
|
|
|
return mNextTransactionId;
|
2016-04-13 23:59:15 +03:00
|
|
|
}
|
|
|
|
|
2018-04-20 22:13:06 +03:00
|
|
|
void nsRefreshDriver::RevokeTransactionId(
|
|
|
|
mozilla::layers::TransactionId aTransactionId) {
|
2018-09-06 05:21:39 +03:00
|
|
|
MOZ_ASSERT(aTransactionId == mNextTransactionId);
|
|
|
|
if (mOutstandingTransactionId - mCompletedTransaction == 2 &&
|
2014-05-29 01:42:17 +04:00
|
|
|
mWaitingForTransaction) {
|
2014-05-29 01:45:06 +04:00
|
|
|
MOZ_ASSERT(!mSkippedPaints,
|
|
|
|
"How did we skip a paint when we're in the middle of one?");
|
2014-05-29 01:42:17 +04:00
|
|
|
FinishedWaitingForTransaction();
|
|
|
|
}
|
2018-09-06 05:21:39 +03:00
|
|
|
|
|
|
|
// Notify the pres context so that it can deliver MozAfterPaint for this
|
|
|
|
// id if any caller was expecting it.
|
|
|
|
nsPresContext* pc = GetPresContext();
|
|
|
|
if (pc) {
|
|
|
|
pc->NotifyRevokingDidPaint(aTransactionId);
|
|
|
|
}
|
|
|
|
// Revert the outstanding transaction since we're no longer waiting on it to
|
|
|
|
// be completed, but don't revert mNextTransactionId since we can't use the id
|
|
|
|
// again.
|
|
|
|
mOutstandingTransactionId = mOutstandingTransactionId.Prev();
|
2014-05-29 01:42:17 +04:00
|
|
|
}
|
|
|
|
|
2017-03-09 13:35:50 +03:00
|
|
|
void nsRefreshDriver::ClearPendingTransactions() {
|
2018-09-06 05:21:39 +03:00
|
|
|
mCompletedTransaction = mOutstandingTransactionId = mNextTransactionId;
|
2017-03-09 13:35:50 +03:00
|
|
|
mWaitingForTransaction = false;
|
|
|
|
}
|
|
|
|
|
2018-04-20 22:13:06 +03:00
|
|
|
void nsRefreshDriver::ResetInitialTransactionId(
|
|
|
|
mozilla::layers::TransactionId aTransactionId) {
|
2018-09-06 05:21:39 +03:00
|
|
|
mCompletedTransaction = mOutstandingTransactionId = mNextTransactionId =
|
|
|
|
aTransactionId;
|
2017-03-09 13:35:50 +03:00
|
|
|
}
|
|
|
|
|
2014-08-28 23:24:26 +04:00
|
|
|
mozilla::TimeStamp nsRefreshDriver::GetTransactionStart() { return mTickStart; }
|
|
|
|
|
2018-12-08 02:28:03 +03:00
|
|
|
VsyncId nsRefreshDriver::GetVsyncId() { return mTickVsyncId; }
|
|
|
|
|
2019-01-03 22:43:04 +03:00
|
|
|
mozilla::TimeStamp nsRefreshDriver::GetVsyncStart() { return mTickVsyncTime; }
|
|
|
|
|
2018-04-20 22:13:06 +03:00
|
|
|
void nsRefreshDriver::NotifyTransactionCompleted(
|
|
|
|
mozilla::layers::TransactionId aTransactionId) {
|
2014-05-29 01:42:17 +04:00
|
|
|
if (aTransactionId > mCompletedTransaction) {
|
2018-09-06 05:21:39 +03:00
|
|
|
if (mOutstandingTransactionId - mCompletedTransaction > 1 &&
|
2014-05-29 01:42:17 +04:00
|
|
|
mWaitingForTransaction) {
|
|
|
|
mCompletedTransaction = aTransactionId;
|
|
|
|
FinishedWaitingForTransaction();
|
|
|
|
} else {
|
|
|
|
mCompletedTransaction = aTransactionId;
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 05:21:39 +03:00
|
|
|
|
|
|
|
// If completed transaction id get ahead of outstanding id, reset to distance
|
|
|
|
// id.
|
|
|
|
if (mCompletedTransaction > mOutstandingTransactionId) {
|
|
|
|
mOutstandingTransactionId = mCompletedTransaction;
|
|
|
|
}
|
2014-05-29 01:42:17 +04:00
|
|
|
}
|
|
|
|
|
2014-05-29 01:43:41 +04:00
|
|
|
void nsRefreshDriver::WillRefresh(mozilla::TimeStamp aTime) {
|
2017-01-05 10:31:56 +03:00
|
|
|
mRootRefresh->RemoveRefreshObserver(this, FlushType::Style);
|
2014-05-29 01:43:41 +04:00
|
|
|
mRootRefresh = nullptr;
|
2014-05-29 01:45:06 +04:00
|
|
|
if (mSkippedPaints) {
|
2014-05-29 01:43:41 +04:00
|
|
|
DoRefresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-15 06:24:50 +04:00
|
|
|
bool nsRefreshDriver::IsWaitingForPaint(mozilla::TimeStamp aTime) {
|
2014-05-29 01:43:41 +04:00
|
|
|
if (mTestControllingRefreshes) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-09-09 13:06:29 +03:00
|
|
|
|
2014-05-29 01:43:41 +04:00
|
|
|
if (mWaitingForTransaction) {
|
2018-07-15 14:19:29 +03:00
|
|
|
if (mSkippedPaints &&
|
|
|
|
aTime > (mMostRecentRefresh +
|
|
|
|
TimeDuration::FromMilliseconds(mWarningThreshold * 1000))) {
|
2016-09-20 17:25:52 +03:00
|
|
|
// XXX - Bug 1303369 - too many false positives.
|
|
|
|
// gfxCriticalNote << "Refresh driver waiting for the compositor for "
|
2018-07-15 14:19:29 +03:00
|
|
|
// << (aTime - mMostRecentRefresh).ToSeconds()
|
2016-09-20 17:25:52 +03:00
|
|
|
// << " seconds.";
|
2016-09-15 23:48:39 +03:00
|
|
|
mWarningThreshold *= 2;
|
|
|
|
}
|
|
|
|
|
2014-08-15 06:24:50 +04:00
|
|
|
mSkippedPaints = true;
|
2014-05-29 01:43:41 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try find the 'root' refresh driver for the current window and check
|
|
|
|
// if that is waiting for a paint.
|
2016-10-12 14:27:38 +03:00
|
|
|
nsPresContext* pc = GetPresContext();
|
|
|
|
nsPresContext* rootContext = pc ? pc->GetRootPresContext() : nullptr;
|
2016-01-22 04:09:04 +03:00
|
|
|
if (rootContext) {
|
|
|
|
nsRefreshDriver* rootRefresh = rootContext->RefreshDriver();
|
2014-05-29 01:43:41 +04:00
|
|
|
if (rootRefresh && rootRefresh != this) {
|
2014-08-15 06:24:50 +04:00
|
|
|
if (rootRefresh->IsWaitingForPaint(aTime)) {
|
2014-05-29 01:43:41 +04:00
|
|
|
if (mRootRefresh != rootRefresh) {
|
|
|
|
if (mRootRefresh) {
|
2017-01-05 10:31:56 +03:00
|
|
|
mRootRefresh->RemoveRefreshObserver(this, FlushType::Style);
|
2014-05-29 01:43:41 +04:00
|
|
|
}
|
2017-01-05 10:31:56 +03:00
|
|
|
rootRefresh->AddRefreshObserver(this, FlushType::Style);
|
2014-05-29 01:43:41 +04:00
|
|
|
mRootRefresh = rootRefresh;
|
|
|
|
}
|
2014-08-15 06:24:50 +04:00
|
|
|
mSkippedPaints = true;
|
2014-05-29 01:43:41 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-27 08:26:23 +04:00
|
|
|
void nsRefreshDriver::SetThrottled(bool aThrottled) {
|
|
|
|
if (aThrottled != mThrottled) {
|
|
|
|
mThrottled = aThrottled;
|
2012-12-12 02:15:32 +04:00
|
|
|
if (mActiveTimer) {
|
2011-03-04 18:27:02 +03:00
|
|
|
// We want to switch our timer type here, so just stop and
|
|
|
|
// restart the timer.
|
2016-01-05 06:50:59 +03:00
|
|
|
EnsureTimerStarted(eForceAdjustTimer);
|
2010-08-27 08:26:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/*static*/
|
|
|
|
void nsRefreshDriver::PVsyncActorCreated(VsyncChild* aVsyncChild) {
|
2015-01-14 02:38:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!XRE_IsParentProcess());
|
2018-06-30 02:08:54 +03:00
|
|
|
RefPtr<RefreshDriverTimer> vsyncRefreshDriverTimer =
|
|
|
|
new VsyncRefreshDriverTimer(aVsyncChild);
|
2015-01-14 02:38:00 +03:00
|
|
|
|
|
|
|
// If we are using software timer, swap current timer to
|
|
|
|
// VsyncRefreshDriverTimer.
|
|
|
|
if (sRegularRateTimer) {
|
|
|
|
sRegularRateTimer->SwapRefreshDrivers(vsyncRefreshDriverTimer);
|
|
|
|
}
|
2018-06-30 02:08:54 +03:00
|
|
|
sRegularRateTimer = vsyncRefreshDriverTimer.forget();
|
2015-01-14 02:38:00 +03:00
|
|
|
}
|
|
|
|
|
2010-02-04 00:17:55 +03:00
|
|
|
void nsRefreshDriver::DoRefresh() {
|
|
|
|
// Don't do a refresh unless we're in a state where we should be refreshing.
|
2013-12-20 01:38:35 +04:00
|
|
|
if (!IsFrozen() && mPresContext && mActiveTimer) {
|
2012-12-12 02:15:32 +04:00
|
|
|
DoTick();
|
2010-02-04 00:17:55 +03:00
|
|
|
}
|
|
|
|
}
|
2010-02-19 20:11:40 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-12-12 02:15:32 +04:00
|
|
|
bool nsRefreshDriver::IsRefreshObserver(nsARefreshObserver* aObserver,
|
2017-01-05 10:31:56 +03:00
|
|
|
FlushType aFlushType) {
|
2010-02-19 20:11:40 +03:00
|
|
|
ObserverArray& array = ArrayFor(aFlushType);
|
|
|
|
return array.Contains(aObserver);
|
|
|
|
}
|
|
|
|
#endif
|
2010-08-12 01:05:28 +04:00
|
|
|
|
2012-09-17 09:06:12 +04:00
|
|
|
void nsRefreshDriver::ScheduleViewManagerFlush() {
|
|
|
|
NS_ASSERTION(mPresContext->IsRoot(),
|
|
|
|
"Should only schedule view manager flush on root prescontexts");
|
|
|
|
mViewManagerFlushIsPending = true;
|
2017-10-03 11:00:38 +03:00
|
|
|
mHasScheduleFlush = true;
|
2016-01-05 06:50:59 +03:00
|
|
|
EnsureTimerStarted(eNeverAdjustTimer);
|
2012-09-17 09:06:12 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void nsRefreshDriver::ScheduleFrameRequestCallbacks(Document* aDocument) {
|
2011-11-28 16:48:30 +04:00
|
|
|
NS_ASSERTION(mFrameRequestCallbackDocs.IndexOf(aDocument) ==
|
2015-04-21 19:44:40 +03:00
|
|
|
mFrameRequestCallbackDocs.NoIndex &&
|
|
|
|
mThrottledFrameRequestCallbackDocs.IndexOf(aDocument) ==
|
|
|
|
mThrottledFrameRequestCallbackDocs.NoIndex,
|
2010-09-09 09:38:04 +04:00
|
|
|
"Don't schedule the same document multiple times");
|
2015-04-21 19:44:40 +03:00
|
|
|
if (aDocument->ShouldThrottleFrameRequests()) {
|
|
|
|
mThrottledFrameRequestCallbackDocs.AppendElement(aDocument);
|
|
|
|
} else {
|
|
|
|
mFrameRequestCallbackDocs.AppendElement(aDocument);
|
|
|
|
}
|
2012-12-12 02:15:32 +04:00
|
|
|
|
|
|
|
// make sure that the timer is running
|
2015-01-06 04:56:02 +03:00
|
|
|
EnsureTimerStarted();
|
2010-09-09 09:38:04 +04:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void nsRefreshDriver::RevokeFrameRequestCallbacks(Document* aDocument) {
|
2011-11-28 16:48:30 +04:00
|
|
|
mFrameRequestCallbackDocs.RemoveElement(aDocument);
|
2015-04-21 19:44:40 +03:00
|
|
|
mThrottledFrameRequestCallbackDocs.RemoveElement(aDocument);
|
2011-03-07 19:58:48 +03:00
|
|
|
// No need to worry about restarting our timer in slack mode if it's already
|
|
|
|
// running; that will happen automatically when it fires.
|
2010-09-09 09:38:04 +04:00
|
|
|
}
|
2013-11-15 06:43:56 +04:00
|
|
|
|
2018-09-08 01:53:33 +03:00
|
|
|
void nsRefreshDriver::ScheduleFullscreenEvent(
|
|
|
|
UniquePtr<PendingFullscreenEvent> aEvent) {
|
|
|
|
mPendingFullscreenEvents.AppendElement(std::move(aEvent));
|
2015-07-02 12:12:31 +03:00
|
|
|
// make sure that the timer is running
|
|
|
|
EnsureTimerStarted();
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
void nsRefreshDriver::CancelPendingFullscreenEvents(Document* aDocument) {
|
2018-09-08 01:53:33 +03:00
|
|
|
for (auto i : Reversed(IntegerRange(mPendingFullscreenEvents.Length()))) {
|
|
|
|
if (mPendingFullscreenEvents[i]->Document() == aDocument) {
|
|
|
|
mPendingFullscreenEvents.RemoveElementAt(i);
|
2015-07-02 12:12:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 15:17:27 +03:00
|
|
|
void nsRefreshDriver::CancelPendingAnimationEvents(
|
|
|
|
AnimationEventDispatcher* aDispatcher) {
|
|
|
|
MOZ_ASSERT(aDispatcher);
|
|
|
|
aDispatcher->ClearEventQueue();
|
|
|
|
mAnimationEventFlushObservers.RemoveElement(aDispatcher);
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
TimeStamp nsRefreshDriver::GetIdleDeadlineHint(TimeStamp aDefault) {
|
2016-08-22 15:52:45 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-05-25 04:11:12 +03:00
|
|
|
MOZ_ASSERT(!aDefault.IsNull());
|
2016-08-22 15:52:45 +03:00
|
|
|
|
|
|
|
if (!sRegularRateTimer) {
|
2017-05-25 04:11:12 +03:00
|
|
|
return aDefault;
|
2016-08-22 15:52:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// For computing idleness of refresh drivers we only care about
|
|
|
|
// sRegularRateTimer, since we consider refresh drivers attached to
|
|
|
|
// sThrottledRateTimer to be inactive. This implies that tasks
|
|
|
|
// resulting from a tick on the sRegularRateTimer counts as being
|
|
|
|
// busy but tasks resulting from a tick on sThrottledRateTimer
|
|
|
|
// counts as being idle.
|
2017-05-25 04:11:12 +03:00
|
|
|
return sRegularRateTimer->GetIdleDeadlineHint(aDefault);
|
2016-08-22 15:52:45 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
Maybe<TimeStamp> nsRefreshDriver::GetNextTickHint() {
|
2017-03-21 10:44:12 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!sRegularRateTimer) {
|
|
|
|
return Nothing();
|
|
|
|
}
|
|
|
|
return sRegularRateTimer->GetNextTickHint();
|
|
|
|
}
|
|
|
|
|
2016-06-06 16:51:15 +03:00
|
|
|
void nsRefreshDriver::Disconnect() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
StopTimer();
|
|
|
|
|
|
|
|
if (mPresContext) {
|
|
|
|
mPresContext = nullptr;
|
|
|
|
if (--sRefreshDriverCount == 0) {
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
bool nsRefreshDriver::IsJankCritical() {
|
2015-10-30 16:35:46 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
return sActiveVsyncTimers > 0;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
bool nsRefreshDriver::GetJankLevels(Vector<uint64_t>& aJank) {
|
2016-01-14 17:07:18 +03:00
|
|
|
aJank.clear();
|
|
|
|
return aJank.append(sJankLevels, ArrayLength(sJankLevels));
|
|
|
|
}
|
|
|
|
|
2013-11-15 06:43:56 +04:00
|
|
|
#undef LOG
|