зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1765399 - Move SoftwareVsyncSource into the mozilla::gfx namespace. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D144376
This commit is contained in:
Родитель
2d423f22c5
Коммит
d53e3d4836
|
@ -9,13 +9,13 @@
|
||||||
#include "gfxPlatform.h"
|
#include "gfxPlatform.h"
|
||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
namespace mozilla::gfx {
|
||||||
|
|
||||||
SoftwareVsyncSource::SoftwareVsyncSource() : mVsyncEnabled(false) {
|
SoftwareVsyncSource::SoftwareVsyncSource() : mVsyncEnabled(false) {
|
||||||
// Mimic 60 fps
|
// Mimic 60 fps
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
const double rate = 1000.0 / (double)gfxPlatform::GetSoftwareVsyncRate();
|
const double rate = 1000.0 / (double)gfxPlatform::GetSoftwareVsyncRate();
|
||||||
mVsyncRate = mozilla::TimeDuration::FromMilliseconds(rate);
|
mVsyncRate = TimeDuration::FromMilliseconds(rate);
|
||||||
mVsyncThread = new base::Thread("SoftwareVsyncThread");
|
mVsyncThread = new base::Thread("SoftwareVsyncThread");
|
||||||
MOZ_RELEASE_ASSERT(mVsyncThread->Start(),
|
MOZ_RELEASE_ASSERT(mVsyncThread->Start(),
|
||||||
"GFX: Could not start software vsync thread");
|
"GFX: Could not start software vsync thread");
|
||||||
|
@ -79,13 +79,12 @@ bool SoftwareVsyncSource::IsInSoftwareVsyncThread() {
|
||||||
return mVsyncThread->thread_id() == PlatformThread::CurrentId();
|
return mVsyncThread->thread_id() == PlatformThread::CurrentId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoftwareVsyncSource::NotifyVsync(
|
void SoftwareVsyncSource::NotifyVsync(const TimeStamp& aVsyncTimestamp,
|
||||||
const mozilla::TimeStamp& aVsyncTimestamp,
|
const TimeStamp& aOutputTimestamp) {
|
||||||
const mozilla::TimeStamp& aOutputTimestamp) {
|
|
||||||
MOZ_ASSERT(IsInSoftwareVsyncThread());
|
MOZ_ASSERT(IsInSoftwareVsyncThread());
|
||||||
|
|
||||||
mozilla::TimeStamp displayVsyncTime = aVsyncTimestamp;
|
TimeStamp displayVsyncTime = aVsyncTimestamp;
|
||||||
mozilla::TimeStamp now = mozilla::TimeStamp::Now();
|
TimeStamp now = TimeStamp::Now();
|
||||||
// Posted tasks can only have integer millisecond delays
|
// Posted tasks can only have integer millisecond delays
|
||||||
// whereas TimeDurations can have floating point delays.
|
// whereas TimeDurations can have floating point delays.
|
||||||
// Thus the vsync timestamp can be in the future, which large parts
|
// Thus the vsync timestamp can be in the future, which large parts
|
||||||
|
@ -102,22 +101,20 @@ void SoftwareVsyncSource::NotifyVsync(
|
||||||
ScheduleNextVsync(aVsyncTimestamp);
|
ScheduleNextVsync(aVsyncTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
mozilla::TimeDuration SoftwareVsyncSource::GetVsyncRate() { return mVsyncRate; }
|
TimeDuration SoftwareVsyncSource::GetVsyncRate() { return mVsyncRate; }
|
||||||
|
|
||||||
void SoftwareVsyncSource::ScheduleNextVsync(
|
void SoftwareVsyncSource::ScheduleNextVsync(TimeStamp aVsyncTimestamp) {
|
||||||
mozilla::TimeStamp aVsyncTimestamp) {
|
|
||||||
MOZ_ASSERT(IsInSoftwareVsyncThread());
|
MOZ_ASSERT(IsInSoftwareVsyncThread());
|
||||||
mozilla::TimeStamp nextVsync = aVsyncTimestamp + mVsyncRate;
|
TimeStamp nextVsync = aVsyncTimestamp + mVsyncRate;
|
||||||
mozilla::TimeDuration delay = nextVsync - mozilla::TimeStamp::Now();
|
TimeDuration delay = nextVsync - TimeStamp::Now();
|
||||||
if (delay.ToMilliseconds() < 0) {
|
if (delay.ToMilliseconds() < 0) {
|
||||||
delay = mozilla::TimeDuration::FromMilliseconds(0);
|
delay = TimeDuration::FromMilliseconds(0);
|
||||||
nextVsync = mozilla::TimeStamp::Now();
|
nextVsync = TimeStamp::Now();
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeStamp outputTime = nextVsync + mVsyncRate;
|
TimeStamp outputTime = nextVsync + mVsyncRate;
|
||||||
|
|
||||||
mCurrentVsyncTask =
|
mCurrentVsyncTask = NewCancelableRunnableMethod<TimeStamp, TimeStamp>(
|
||||||
NewCancelableRunnableMethod<mozilla::TimeStamp, mozilla::TimeStamp>(
|
|
||||||
"SoftwareVsyncSource::NotifyVsync", this,
|
"SoftwareVsyncSource::NotifyVsync", this,
|
||||||
&SoftwareVsyncSource::NotifyVsync, nextVsync, outputTime);
|
&SoftwareVsyncSource::NotifyVsync, nextVsync, outputTime);
|
||||||
|
|
||||||
|
@ -133,3 +130,5 @@ void SoftwareVsyncSource::Shutdown() {
|
||||||
delete mVsyncThread;
|
delete mVsyncThread;
|
||||||
mVsyncThread = nullptr;
|
mVsyncThread = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace mozilla::gfx
|
||||||
|
|
|
@ -14,10 +14,12 @@
|
||||||
#include "nsISupportsImpl.h"
|
#include "nsISupportsImpl.h"
|
||||||
#include "VsyncSource.h"
|
#include "VsyncSource.h"
|
||||||
|
|
||||||
|
namespace mozilla::gfx {
|
||||||
|
|
||||||
// Fallback option to use a software timer to mimic vsync. Useful for gtests
|
// Fallback option to use a software timer to mimic vsync. Useful for gtests
|
||||||
// To mimic a hardware vsync thread, we create a dedicated software timer
|
// To mimic a hardware vsync thread, we create a dedicated software timer
|
||||||
// vsync thread.
|
// vsync thread.
|
||||||
class SoftwareVsyncSource : public mozilla::gfx::VsyncSource {
|
class SoftwareVsyncSource : public VsyncSource {
|
||||||
public:
|
public:
|
||||||
explicit SoftwareVsyncSource();
|
explicit SoftwareVsyncSource();
|
||||||
virtual ~SoftwareVsyncSource();
|
virtual ~SoftwareVsyncSource();
|
||||||
|
@ -26,19 +28,20 @@ class SoftwareVsyncSource : public mozilla::gfx::VsyncSource {
|
||||||
void DisableVsync() override;
|
void DisableVsync() override;
|
||||||
bool IsVsyncEnabled() override;
|
bool IsVsyncEnabled() override;
|
||||||
bool IsInSoftwareVsyncThread();
|
bool IsInSoftwareVsyncThread();
|
||||||
void NotifyVsync(const mozilla::TimeStamp& aVsyncTimestamp,
|
void NotifyVsync(const TimeStamp& aVsyncTimestamp,
|
||||||
const mozilla::TimeStamp& aOutputTimestamp) override;
|
const TimeStamp& aOutputTimestamp) override;
|
||||||
mozilla::TimeDuration GetVsyncRate() override;
|
TimeDuration GetVsyncRate() override;
|
||||||
void ScheduleNextVsync(mozilla::TimeStamp aVsyncTimestamp);
|
void ScheduleNextVsync(TimeStamp aVsyncTimestamp);
|
||||||
void Shutdown() override;
|
void Shutdown() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
mozilla::TimeDuration mVsyncRate;
|
TimeDuration mVsyncRate;
|
||||||
// Use a chromium thread because nsITimers* fire on the main thread
|
// Use a chromium thread because nsITimers* fire on the main thread
|
||||||
base::Thread* mVsyncThread;
|
base::Thread* mVsyncThread;
|
||||||
RefPtr<mozilla::CancelableRunnable>
|
RefPtr<CancelableRunnable> mCurrentVsyncTask; // only access on vsync thread
|
||||||
mCurrentVsyncTask; // only access on vsync thread
|
|
||||||
bool mVsyncEnabled; // Only access on main thread
|
bool mVsyncEnabled; // Only access on main thread
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace mozilla::gfx
|
||||||
|
|
||||||
#endif /* GFX_SOFTWARE_VSYNC_SOURCE_H */
|
#endif /* GFX_SOFTWARE_VSYNC_SOURCE_H */
|
||||||
|
|
|
@ -2998,7 +2998,8 @@ RefPtr<mozilla::VsyncDispatcher> gfxPlatform::GetGlobalVsyncDispatcher() {
|
||||||
*/
|
*/
|
||||||
already_AddRefed<mozilla::gfx::VsyncSource>
|
already_AddRefed<mozilla::gfx::VsyncSource>
|
||||||
gfxPlatform::CreateSoftwareVsyncSource() {
|
gfxPlatform::CreateSoftwareVsyncSource() {
|
||||||
RefPtr<mozilla::gfx::VsyncSource> softwareVsync = new SoftwareVsyncSource();
|
RefPtr<mozilla::gfx::VsyncSource> softwareVsync =
|
||||||
|
new mozilla::gfx::SoftwareVsyncSource();
|
||||||
return softwareVsync.forget();
|
return softwareVsync.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -852,7 +852,8 @@ class GtkVsyncSource final : public VsyncSource {
|
||||||
bool mVsyncEnabled;
|
bool mVsyncEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
class XrandrSoftwareVsyncSource final : public SoftwareVsyncSource {
|
class XrandrSoftwareVsyncSource final
|
||||||
|
: public mozilla::gfx::SoftwareVsyncSource {
|
||||||
public:
|
public:
|
||||||
XrandrSoftwareVsyncSource() {
|
XrandrSoftwareVsyncSource() {
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
|
|
Загрузка…
Ссылка в новой задаче