зеркало из 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 "nsThreadUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
namespace mozilla::gfx {
|
||||
|
||||
SoftwareVsyncSource::SoftwareVsyncSource() : mVsyncEnabled(false) {
|
||||
// Mimic 60 fps
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
const double rate = 1000.0 / (double)gfxPlatform::GetSoftwareVsyncRate();
|
||||
mVsyncRate = mozilla::TimeDuration::FromMilliseconds(rate);
|
||||
mVsyncRate = TimeDuration::FromMilliseconds(rate);
|
||||
mVsyncThread = new base::Thread("SoftwareVsyncThread");
|
||||
MOZ_RELEASE_ASSERT(mVsyncThread->Start(),
|
||||
"GFX: Could not start software vsync thread");
|
||||
|
@ -79,13 +79,12 @@ bool SoftwareVsyncSource::IsInSoftwareVsyncThread() {
|
|||
return mVsyncThread->thread_id() == PlatformThread::CurrentId();
|
||||
}
|
||||
|
||||
void SoftwareVsyncSource::NotifyVsync(
|
||||
const mozilla::TimeStamp& aVsyncTimestamp,
|
||||
const mozilla::TimeStamp& aOutputTimestamp) {
|
||||
void SoftwareVsyncSource::NotifyVsync(const TimeStamp& aVsyncTimestamp,
|
||||
const TimeStamp& aOutputTimestamp) {
|
||||
MOZ_ASSERT(IsInSoftwareVsyncThread());
|
||||
|
||||
mozilla::TimeStamp displayVsyncTime = aVsyncTimestamp;
|
||||
mozilla::TimeStamp now = mozilla::TimeStamp::Now();
|
||||
TimeStamp displayVsyncTime = aVsyncTimestamp;
|
||||
TimeStamp now = TimeStamp::Now();
|
||||
// Posted tasks can only have integer millisecond delays
|
||||
// whereas TimeDurations can have floating point delays.
|
||||
// Thus the vsync timestamp can be in the future, which large parts
|
||||
|
@ -102,24 +101,22 @@ void SoftwareVsyncSource::NotifyVsync(
|
|||
ScheduleNextVsync(aVsyncTimestamp);
|
||||
}
|
||||
|
||||
mozilla::TimeDuration SoftwareVsyncSource::GetVsyncRate() { return mVsyncRate; }
|
||||
TimeDuration SoftwareVsyncSource::GetVsyncRate() { return mVsyncRate; }
|
||||
|
||||
void SoftwareVsyncSource::ScheduleNextVsync(
|
||||
mozilla::TimeStamp aVsyncTimestamp) {
|
||||
void SoftwareVsyncSource::ScheduleNextVsync(TimeStamp aVsyncTimestamp) {
|
||||
MOZ_ASSERT(IsInSoftwareVsyncThread());
|
||||
mozilla::TimeStamp nextVsync = aVsyncTimestamp + mVsyncRate;
|
||||
mozilla::TimeDuration delay = nextVsync - mozilla::TimeStamp::Now();
|
||||
TimeStamp nextVsync = aVsyncTimestamp + mVsyncRate;
|
||||
TimeDuration delay = nextVsync - TimeStamp::Now();
|
||||
if (delay.ToMilliseconds() < 0) {
|
||||
delay = mozilla::TimeDuration::FromMilliseconds(0);
|
||||
nextVsync = mozilla::TimeStamp::Now();
|
||||
delay = TimeDuration::FromMilliseconds(0);
|
||||
nextVsync = TimeStamp::Now();
|
||||
}
|
||||
|
||||
TimeStamp outputTime = nextVsync + mVsyncRate;
|
||||
|
||||
mCurrentVsyncTask =
|
||||
NewCancelableRunnableMethod<mozilla::TimeStamp, mozilla::TimeStamp>(
|
||||
"SoftwareVsyncSource::NotifyVsync", this,
|
||||
&SoftwareVsyncSource::NotifyVsync, nextVsync, outputTime);
|
||||
mCurrentVsyncTask = NewCancelableRunnableMethod<TimeStamp, TimeStamp>(
|
||||
"SoftwareVsyncSource::NotifyVsync", this,
|
||||
&SoftwareVsyncSource::NotifyVsync, nextVsync, outputTime);
|
||||
|
||||
RefPtr<Runnable> addrefedTask = mCurrentVsyncTask;
|
||||
mVsyncThread->message_loop()->PostDelayedTask(addrefedTask.forget(),
|
||||
|
@ -133,3 +130,5 @@ void SoftwareVsyncSource::Shutdown() {
|
|||
delete mVsyncThread;
|
||||
mVsyncThread = nullptr;
|
||||
}
|
||||
|
||||
} // namespace mozilla::gfx
|
||||
|
|
|
@ -14,10 +14,12 @@
|
|||
#include "nsISupportsImpl.h"
|
||||
#include "VsyncSource.h"
|
||||
|
||||
namespace mozilla::gfx {
|
||||
|
||||
// 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
|
||||
// vsync thread.
|
||||
class SoftwareVsyncSource : public mozilla::gfx::VsyncSource {
|
||||
class SoftwareVsyncSource : public VsyncSource {
|
||||
public:
|
||||
explicit SoftwareVsyncSource();
|
||||
virtual ~SoftwareVsyncSource();
|
||||
|
@ -26,19 +28,20 @@ class SoftwareVsyncSource : public mozilla::gfx::VsyncSource {
|
|||
void DisableVsync() override;
|
||||
bool IsVsyncEnabled() override;
|
||||
bool IsInSoftwareVsyncThread();
|
||||
void NotifyVsync(const mozilla::TimeStamp& aVsyncTimestamp,
|
||||
const mozilla::TimeStamp& aOutputTimestamp) override;
|
||||
mozilla::TimeDuration GetVsyncRate() override;
|
||||
void ScheduleNextVsync(mozilla::TimeStamp aVsyncTimestamp);
|
||||
void NotifyVsync(const TimeStamp& aVsyncTimestamp,
|
||||
const TimeStamp& aOutputTimestamp) override;
|
||||
TimeDuration GetVsyncRate() override;
|
||||
void ScheduleNextVsync(TimeStamp aVsyncTimestamp);
|
||||
void Shutdown() override;
|
||||
|
||||
protected:
|
||||
mozilla::TimeDuration mVsyncRate;
|
||||
TimeDuration mVsyncRate;
|
||||
// Use a chromium thread because nsITimers* fire on the main thread
|
||||
base::Thread* mVsyncThread;
|
||||
RefPtr<mozilla::CancelableRunnable>
|
||||
mCurrentVsyncTask; // only access on vsync thread
|
||||
bool mVsyncEnabled; // Only access on main thread
|
||||
RefPtr<CancelableRunnable> mCurrentVsyncTask; // only access on vsync thread
|
||||
bool mVsyncEnabled; // Only access on main thread
|
||||
};
|
||||
|
||||
} // namespace mozilla::gfx
|
||||
|
||||
#endif /* GFX_SOFTWARE_VSYNC_SOURCE_H */
|
||||
|
|
|
@ -2998,7 +2998,8 @@ RefPtr<mozilla::VsyncDispatcher> gfxPlatform::GetGlobalVsyncDispatcher() {
|
|||
*/
|
||||
already_AddRefed<mozilla::gfx::VsyncSource>
|
||||
gfxPlatform::CreateSoftwareVsyncSource() {
|
||||
RefPtr<mozilla::gfx::VsyncSource> softwareVsync = new SoftwareVsyncSource();
|
||||
RefPtr<mozilla::gfx::VsyncSource> softwareVsync =
|
||||
new mozilla::gfx::SoftwareVsyncSource();
|
||||
return softwareVsync.forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -852,7 +852,8 @@ class GtkVsyncSource final : public VsyncSource {
|
|||
bool mVsyncEnabled;
|
||||
};
|
||||
|
||||
class XrandrSoftwareVsyncSource final : public SoftwareVsyncSource {
|
||||
class XrandrSoftwareVsyncSource final
|
||||
: public mozilla::gfx::SoftwareVsyncSource {
|
||||
public:
|
||||
XrandrSoftwareVsyncSource() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
|
Загрузка…
Ссылка в новой задаче