2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2015-01-09 02:12:47 +03: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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GFX_SOFTWARE_VSYNC_SOURCE_H
|
|
|
|
#define GFX_SOFTWARE_VSYNC_SOURCE_H
|
|
|
|
|
2022-05-05 05:15:18 +03:00
|
|
|
#include "mozilla/DataMutex.h"
|
2015-01-09 02:12:47 +03:00
|
|
|
#include "mozilla/Monitor.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-01-09 02:12:47 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "base/thread.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "VsyncSource.h"
|
|
|
|
|
2022-05-05 05:15:18 +03:00
|
|
|
namespace mozilla::gfx {
|
|
|
|
|
2022-03-15 21:13:56 +03:00
|
|
|
// 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.
|
2022-05-05 05:15:18 +03:00
|
|
|
class SoftwareVsyncSource : public VsyncSource {
|
2015-01-09 02:12:47 +03:00
|
|
|
public:
|
2022-05-05 05:15:18 +03:00
|
|
|
explicit SoftwareVsyncSource(const TimeDuration& aInitialVsyncRate);
|
2022-03-15 21:13:56 +03:00
|
|
|
virtual ~SoftwareVsyncSource();
|
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void EnableVsync() override;
|
|
|
|
void DisableVsync() override;
|
|
|
|
bool IsVsyncEnabled() override;
|
2015-01-09 02:12:47 +03:00
|
|
|
bool IsInSoftwareVsyncThread();
|
2022-05-05 05:15:18 +03:00
|
|
|
void NotifyVsync(const TimeStamp& aVsyncTimestamp,
|
|
|
|
const TimeStamp& aOutputTimestamp) override;
|
|
|
|
TimeDuration GetVsyncRate() override;
|
|
|
|
void ScheduleNextVsync(TimeStamp aVsyncTimestamp);
|
2016-06-06 20:07:29 +03:00
|
|
|
void Shutdown() override;
|
2015-01-09 02:12:47 +03:00
|
|
|
|
2022-05-05 05:15:18 +03:00
|
|
|
// Can be called on any thread
|
|
|
|
void SetVsyncRate(const TimeDuration& aNewRate);
|
|
|
|
|
2021-10-23 14:19:10 +03:00
|
|
|
protected:
|
2015-01-09 02:12:47 +03:00
|
|
|
// Use a chromium thread because nsITimers* fire on the main thread
|
|
|
|
base::Thread* mVsyncThread;
|
2022-05-05 05:15:18 +03:00
|
|
|
RefPtr<CancelableRunnable> mCurrentVsyncTask; // only access on vsync thread
|
|
|
|
bool mVsyncEnabled; // Only access on main thread
|
2022-05-05 05:15:18 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
DataMutex<TimeDuration> mVsyncRate; // can be accessed on any thread
|
2015-01-09 02:12:47 +03:00
|
|
|
};
|
|
|
|
|
2022-05-05 05:15:18 +03:00
|
|
|
} // namespace mozilla::gfx
|
|
|
|
|
2015-01-09 02:12:47 +03:00
|
|
|
#endif /* GFX_SOFTWARE_VSYNC_SOURCE_H */
|