зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1119742 - Add RefreshTimerDispatcher into VsyncSource::Display. r=kats
1) Create RefreshTimerDispatcher in VsyncSource::Display. 2) Use mutex for all VsyncSource::Display's member access.
This commit is contained in:
Родитель
c2cc6f07fd
Коммит
81083d3e3b
|
@ -4,64 +4,94 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "VsyncSource.h"
|
#include "VsyncSource.h"
|
||||||
#include "gfxPlatform.h"
|
#include "nsThreadUtils.h"
|
||||||
#include "mozilla/TimeStamp.h"
|
#include "nsXULAppAPI.h"
|
||||||
#include "mozilla/VsyncDispatcher.h"
|
#include "mozilla/VsyncDispatcher.h"
|
||||||
#include "MainThreadUtils.h"
|
#include "MainThreadUtils.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
namespace mozilla {
|
||||||
using namespace mozilla::gfx;
|
namespace gfx {
|
||||||
|
|
||||||
void
|
void
|
||||||
VsyncSource::AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
VsyncSource::AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
||||||
{
|
{
|
||||||
|
MOZ_ASSERT(XRE_IsParentProcess());
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
// Just use the global display until we have enough information to get the
|
||||||
|
// corresponding display for compositor.
|
||||||
GetGlobalDisplay().AddCompositorVsyncDispatcher(aCompositorVsyncDispatcher);
|
GetGlobalDisplay().AddCompositorVsyncDispatcher(aCompositorVsyncDispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
VsyncSource::RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
VsyncSource::RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
||||||
{
|
{
|
||||||
|
MOZ_ASSERT(XRE_IsParentProcess());
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
// See also AddCompositorVsyncDispatcher().
|
||||||
GetGlobalDisplay().RemoveCompositorVsyncDispatcher(aCompositorVsyncDispatcher);
|
GetGlobalDisplay().RemoveCompositorVsyncDispatcher(aCompositorVsyncDispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
VsyncSource::Display&
|
nsRefPtr<RefreshTimerVsyncDispatcher>
|
||||||
VsyncSource::FindDisplay(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
VsyncSource::GetRefreshTimerVsyncDispatcher()
|
||||||
{
|
{
|
||||||
return GetGlobalDisplay();
|
MOZ_ASSERT(XRE_IsParentProcess());
|
||||||
|
// See also AddCompositorVsyncDispatcher().
|
||||||
|
return GetGlobalDisplay().GetRefreshTimerVsyncDispatcher();
|
||||||
|
}
|
||||||
|
|
||||||
|
VsyncSource::Display::Display()
|
||||||
|
: mDispatcherLock("display dispatcher lock")
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
mRefreshTimerVsyncDispatcher = new RefreshTimerVsyncDispatcher();
|
||||||
|
}
|
||||||
|
|
||||||
|
VsyncSource::Display::~Display()
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
MutexAutoLock lock(mDispatcherLock);
|
||||||
|
mRefreshTimerVsyncDispatcher = nullptr;
|
||||||
|
mCompositorVsyncDispatchers.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
VsyncSource::Display::NotifyVsync(TimeStamp aVsyncTimestamp)
|
VsyncSource::Display::NotifyVsync(TimeStamp aVsyncTimestamp)
|
||||||
{
|
{
|
||||||
// Called on the vsync thread
|
// Called on the vsync thread
|
||||||
|
MutexAutoLock lock(mDispatcherLock);
|
||||||
|
|
||||||
for (size_t i = 0; i < mCompositorVsyncDispatchers.Length(); i++) {
|
for (size_t i = 0; i < mCompositorVsyncDispatchers.Length(); i++) {
|
||||||
mCompositorVsyncDispatchers[i]->NotifyVsync(aVsyncTimestamp);
|
mCompositorVsyncDispatchers[i]->NotifyVsync(aVsyncTimestamp);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
VsyncSource::Display::Display()
|
mRefreshTimerVsyncDispatcher->NotifyVsync(aVsyncTimestamp);
|
||||||
{
|
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
|
||||||
}
|
|
||||||
|
|
||||||
VsyncSource::Display::~Display()
|
|
||||||
{
|
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
|
||||||
mCompositorVsyncDispatchers.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
VsyncSource::Display::AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
VsyncSource::Display::AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
mCompositorVsyncDispatchers.AppendElement(aCompositorVsyncDispatcher);
|
MOZ_ASSERT(aCompositorVsyncDispatcher);
|
||||||
|
MutexAutoLock lock(mDispatcherLock);
|
||||||
|
if (!mCompositorVsyncDispatchers.Contains(aCompositorVsyncDispatcher)) {
|
||||||
|
mCompositorVsyncDispatchers.AppendElement(aCompositorVsyncDispatcher);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
VsyncSource::Display::RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
VsyncSource::Display::RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
MOZ_ASSERT(aCompositorVsyncDispatcher);
|
||||||
|
MutexAutoLock lock(mDispatcherLock);
|
||||||
mCompositorVsyncDispatchers.RemoveElement(aCompositorVsyncDispatcher);
|
mCompositorVsyncDispatchers.RemoveElement(aCompositorVsyncDispatcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsRefPtr<RefreshTimerVsyncDispatcher>
|
||||||
|
VsyncSource::Display::GetRefreshTimerVsyncDispatcher()
|
||||||
|
{
|
||||||
|
return mRefreshTimerVsyncDispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
} //namespace gfx
|
||||||
|
} //namespace mozilla
|
||||||
|
|
|
@ -6,12 +6,14 @@
|
||||||
#ifndef GFX_VSYNCSOURCE_H
|
#ifndef GFX_VSYNCSOURCE_H
|
||||||
#define GFX_VSYNCSOURCE_H
|
#define GFX_VSYNCSOURCE_H
|
||||||
|
|
||||||
#include "mozilla/RefPtr.h"
|
#include "nsTArray.h"
|
||||||
|
#include "nsRefPtr.h"
|
||||||
|
#include "mozilla/Mutex.h"
|
||||||
#include "mozilla/TimeStamp.h"
|
#include "mozilla/TimeStamp.h"
|
||||||
#include "nsISupportsImpl.h"
|
#include "nsISupportsImpl.h"
|
||||||
#include "nsTArray.h"
|
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
class RefreshTimerVsyncDispatcher;
|
||||||
class CompositorVsyncDispatcher;
|
class CompositorVsyncDispatcher;
|
||||||
|
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
|
@ -21,14 +23,17 @@ namespace gfx {
|
||||||
class VsyncSource
|
class VsyncSource
|
||||||
{
|
{
|
||||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncSource)
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncSource)
|
||||||
|
|
||||||
|
typedef mozilla::RefreshTimerVsyncDispatcher RefreshTimerVsyncDispatcher;
|
||||||
|
typedef mozilla::CompositorVsyncDispatcher CompositorVsyncDispatcher;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Controls vsync unique to each display and unique on each platform
|
// Controls vsync unique to each display and unique on each platform
|
||||||
class Display {
|
class Display {
|
||||||
public:
|
public:
|
||||||
Display();
|
Display();
|
||||||
virtual ~Display();
|
virtual ~Display();
|
||||||
void AddCompositorVsyncDispatcher(mozilla::CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
|
|
||||||
void RemoveCompositorVsyncDispatcher(mozilla::CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
|
|
||||||
// Notified when this display's vsync occurs, on the vsync thread
|
// Notified when this display's vsync occurs, on the vsync thread
|
||||||
// The aVsyncTimestamp should normalize to the Vsync time that just occured
|
// The aVsyncTimestamp should normalize to the Vsync time that just occured
|
||||||
// However, different platforms give different vsync notification times.
|
// However, different platforms give different vsync notification times.
|
||||||
|
@ -38,7 +43,12 @@ public:
|
||||||
// Android: TODO
|
// Android: TODO
|
||||||
// All platforms should normalize to the vsync that just occured.
|
// All platforms should normalize to the vsync that just occured.
|
||||||
// Large parts of Gecko assume TimeStamps should not be in the future such as animations
|
// Large parts of Gecko assume TimeStamps should not be in the future such as animations
|
||||||
virtual void NotifyVsync(mozilla::TimeStamp aVsyncTimestamp);
|
virtual void NotifyVsync(TimeStamp aVsyncTimestamp);
|
||||||
|
|
||||||
|
nsRefPtr<RefreshTimerVsyncDispatcher> GetRefreshTimerVsyncDispatcher();
|
||||||
|
|
||||||
|
void AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
|
||||||
|
void RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
|
||||||
|
|
||||||
// These should all only be called on the main thread
|
// These should all only be called on the main thread
|
||||||
virtual void EnableVsync() = 0;
|
virtual void EnableVsync() = 0;
|
||||||
|
@ -46,18 +56,23 @@ public:
|
||||||
virtual bool IsVsyncEnabled() = 0;
|
virtual bool IsVsyncEnabled() = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nsTArray<nsRefPtr<mozilla::CompositorVsyncDispatcher>> mCompositorVsyncDispatchers;
|
Mutex mDispatcherLock;
|
||||||
}; // end Display
|
nsTArray<nsRefPtr<CompositorVsyncDispatcher>> mCompositorVsyncDispatchers;
|
||||||
|
nsRefPtr<RefreshTimerVsyncDispatcher> mRefreshTimerVsyncDispatcher;
|
||||||
|
};
|
||||||
|
|
||||||
void AddCompositorVsyncDispatcher(mozilla::CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
|
void AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
|
||||||
void RemoveCompositorVsyncDispatcher(mozilla::CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
|
void RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
|
||||||
|
|
||||||
|
nsRefPtr<RefreshTimerVsyncDispatcher> GetRefreshTimerVsyncDispatcher();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual Display& GetGlobalDisplay() = 0; // Works across all displays
|
virtual Display& GetGlobalDisplay() = 0; // Works across all displays
|
||||||
virtual Display& FindDisplay(mozilla::CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
|
|
||||||
virtual ~VsyncSource() {}
|
virtual ~VsyncSource() {}
|
||||||
}; // VsyncSource
|
};
|
||||||
} // gfx
|
|
||||||
} // mozilla
|
} // namespace gfx
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
#endif /* GFX_VSYNCSOURCE_H */
|
#endif /* GFX_VSYNCSOURCE_H */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче