Files
palemoon27/widget/VsyncDispatcher.cpp
T
roytam1 081721a2da import changes from `dev' branch of rmottola/Arctic-Fox:
- reapply Bug 1574573 - Disambiguate a use of Handle in XPCShellEnvironment.cpp r=Ehsan (a674c4b006)
- Bug 1255707 - Part 2. Remove ScreenSizeChanged. r=snorp (3a93e4e768)
- Bug 1250418 - Remove the assertion check of mCanSend in CompositorCh ld::ActorDestroy, r=nical (14bb402a1d)
- Bug 1250718 - Improve layer logging for preserve-3d layers. r=thinker (f373a50040)
- Bug 1232042 - Addendum: Add comment for mLayerManager check. r=jrmuizel (2b69aa784a)
- Bug 1239861. Skip composite if vsync time is before force composite time. r=kats (5ee4038157)
- Bug 1241678 - Fix low-volume null-deref crash. r=BenWa (b28d944615)
- Rename PCompositor to PCompositorBridge. (bug 1258479 part 2, r=mattwoodrow) (dd535a9bdd)
- Bug 1220184 - Eliminate Gingerbread compatibility. r=froydnj, r=nalexander (dce9e4f9e8)
- Bug 1250917 - Remove NS_SUCCESS_I_DID_SOMETHING; r=bholley (9dd6fe351b)
- Bug 1155241: Check mInstanceOwner for nullptr in nsObjectLoadingContent::PluginDestroyed; r=smaug (ad60991e3e)
- Bug 1229220 - Update the scrollbar visibility prefs when initializing a TabChild; r=smaug (28997e0a6d)
- Bug 1252262 - Don't combine the client offset into the outer rect for the child process. r=jimm (f415c0418e)
- Bug 1249943 - Make test_basic_pan work on Fennec and Linux as well. r=botond (657c940be1)
- bit of bug 1245765 part 5 (82463f7eaa)
- Bug 1207512 - Remove the JS_IsRunning call in nsObjectLoadingContent::ScriptRequestPluginInstance; r=bholley (76047284a6)
- Bug 1239463 - Do not assert when notifying an inactive document about changed content from the plugin crash notification. r=bz (03bf38a683)
- Bug 1192450 - Remove PlayPreview registration from Shumway. r=jet (9b6e131876)
- Bug 1200602 - Use the alternate content for <applet>. r=kmachulis (843fccf0aa)
2024-03-15 00:30:42 +08:00

202 lines
5.4 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "MainThreadUtils.h"
#include "VsyncDispatcher.h"
#include "VsyncSource.h"
#include "gfxPlatform.h"
#include "mozilla/layers/Compositor.h"
#include "mozilla/layers/CompositorBridgeParent.h"
#ifdef MOZ_ENABLE_PROFILER_SPS
#include "GeckoProfiler.h"
#include "ProfilerMarkers.h"
#endif
namespace mozilla {
static bool sThreadAssertionsEnabled = true;
void CompositorVsyncDispatcher::SetThreadAssertionsEnabled(bool aEnable)
{
// Should only be used in test environments
MOZ_ASSERT(NS_IsMainThread());
sThreadAssertionsEnabled = aEnable;
}
CompositorVsyncDispatcher::CompositorVsyncDispatcher()
: mCompositorObserverLock("CompositorObserverLock")
, mDidShutdown(false)
{
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(NS_IsMainThread());
}
CompositorVsyncDispatcher::~CompositorVsyncDispatcher()
{
MOZ_ASSERT(XRE_IsParentProcess());
// We auto remove this vsync dispatcher from the vsync source in the nsBaseWidget
}
void
CompositorVsyncDispatcher::NotifyVsync(TimeStamp aVsyncTimestamp)
{
// In vsync thread
#ifdef MOZ_ENABLE_PROFILER_SPS
layers::CompositorBridgeParent::PostInsertVsyncProfilerMarker(aVsyncTimestamp);
#endif
MutexAutoLock lock(mCompositorObserverLock);
if (mCompositorVsyncObserver) {
mCompositorVsyncObserver->NotifyVsync(aVsyncTimestamp);
}
}
void
CompositorVsyncDispatcher::AssertOnCompositorThread()
{
if (!sThreadAssertionsEnabled) {
return;
}
Compositor::AssertOnCompositorThread();
}
void
CompositorVsyncDispatcher::ObserveVsync(bool aEnable)
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(XRE_IsParentProcess());
if (mDidShutdown) {
return;
}
if (aEnable) {
gfxPlatform::GetPlatform()->GetHardwareVsync()->AddCompositorVsyncDispatcher(this);
} else {
gfxPlatform::GetPlatform()->GetHardwareVsync()->RemoveCompositorVsyncDispatcher(this);
}
}
void
CompositorVsyncDispatcher::SetCompositorVsyncObserver(VsyncObserver* aVsyncObserver)
{
AssertOnCompositorThread();
{ // scope lock
MutexAutoLock lock(mCompositorObserverLock);
mCompositorVsyncObserver = aVsyncObserver;
}
bool observeVsync = aVsyncObserver != nullptr;
nsCOMPtr<nsIRunnable> vsyncControl = NS_NewRunnableMethodWithArg<bool>(this,
&CompositorVsyncDispatcher::ObserveVsync,
observeVsync);
NS_DispatchToMainThread(vsyncControl);
}
void
CompositorVsyncDispatcher::Shutdown()
{
// Need to explicitly remove CompositorVsyncDispatcher when the nsBaseWidget shuts down.
// Otherwise, we would get dead vsync notifications between when the nsBaseWidget
// shuts down and the CompositorBridgeParent shuts down.
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(NS_IsMainThread());
ObserveVsync(false);
mDidShutdown = true;
{ // scope lock
MutexAutoLock lock(mCompositorObserverLock);
mCompositorVsyncObserver = nullptr;
}
}
RefreshTimerVsyncDispatcher::RefreshTimerVsyncDispatcher()
: mRefreshTimersLock("RefreshTimers lock")
{
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(NS_IsMainThread());
}
RefreshTimerVsyncDispatcher::~RefreshTimerVsyncDispatcher()
{
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(NS_IsMainThread());
}
void
RefreshTimerVsyncDispatcher::NotifyVsync(TimeStamp aVsyncTimestamp)
{
MutexAutoLock lock(mRefreshTimersLock);
for (size_t i = 0; i < mChildRefreshTimers.Length(); i++) {
mChildRefreshTimers[i]->NotifyVsync(aVsyncTimestamp);
}
if (mParentRefreshTimer) {
mParentRefreshTimer->NotifyVsync(aVsyncTimestamp);
}
}
void
RefreshTimerVsyncDispatcher::SetParentRefreshTimer(VsyncObserver* aVsyncObserver)
{
MOZ_ASSERT(NS_IsMainThread());
{ // lock scope because UpdateVsyncStatus runs on main thread and will deadlock
MutexAutoLock lock(mRefreshTimersLock);
mParentRefreshTimer = aVsyncObserver;
}
UpdateVsyncStatus();
}
void
RefreshTimerVsyncDispatcher::AddChildRefreshTimer(VsyncObserver* aVsyncObserver)
{
{ // scope lock - called on pbackground thread
MutexAutoLock lock(mRefreshTimersLock);
MOZ_ASSERT(aVsyncObserver);
if (!mChildRefreshTimers.Contains(aVsyncObserver)) {
mChildRefreshTimers.AppendElement(aVsyncObserver);
}
}
UpdateVsyncStatus();
}
void
RefreshTimerVsyncDispatcher::RemoveChildRefreshTimer(VsyncObserver* aVsyncObserver)
{
{ // scope lock - called on pbackground thread
MutexAutoLock lock(mRefreshTimersLock);
MOZ_ASSERT(aVsyncObserver);
mChildRefreshTimers.RemoveElement(aVsyncObserver);
}
UpdateVsyncStatus();
}
void
RefreshTimerVsyncDispatcher::UpdateVsyncStatus()
{
if (!NS_IsMainThread()) {
nsCOMPtr<nsIRunnable> vsyncControl = NS_NewRunnableMethod(this,
&RefreshTimerVsyncDispatcher::UpdateVsyncStatus);
NS_DispatchToMainThread(vsyncControl);
return;
}
gfx::VsyncSource::Display& display = gfxPlatform::GetPlatform()->GetHardwareVsync()->GetGlobalDisplay();
display.NotifyRefreshTimerVsyncStatus(NeedsVsync());
}
bool
RefreshTimerVsyncDispatcher::NeedsVsync()
{
MOZ_ASSERT(NS_IsMainThread());
MutexAutoLock lock(mRefreshTimersLock);
return (mParentRefreshTimer != nullptr) || !mChildRefreshTimers.IsEmpty();
}
} // namespace mozilla