1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 #ifndef GFX_SOFTWARE_VSYNC_SOURCE_H
8 #define GFX_SOFTWARE_VSYNC_SOURCE_H
10 #include "mozilla/DataMutex.h"
11 #include "mozilla/Monitor.h"
12 #include "mozilla/RefPtr.h"
13 #include "mozilla/TimeStamp.h"
14 #include "base/thread.h"
15 #include "nsISupportsImpl.h"
16 #include "VsyncSource.h"
18 namespace mozilla::gfx
{
20 // Fallback option to use a software timer to mimic vsync. Useful for gtests
21 // To mimic a hardware vsync thread, we create a dedicated software timer
23 class SoftwareVsyncSource
: public VsyncSource
{
25 explicit SoftwareVsyncSource(const TimeDuration
& aInitialVsyncRate
);
26 virtual ~SoftwareVsyncSource();
28 void EnableVsync() override
;
29 void DisableVsync() override
;
30 bool IsVsyncEnabled() override
;
31 bool IsInSoftwareVsyncThread();
32 void NotifyVsync(const TimeStamp
& aVsyncTimestamp
,
33 const TimeStamp
& aOutputTimestamp
) override
;
34 TimeDuration
GetVsyncRate() override
;
35 void ScheduleNextVsync(TimeStamp aVsyncTimestamp
);
36 void Shutdown() override
;
38 // Can be called on any thread
39 void SetVsyncRate(const TimeDuration
& aNewRate
);
42 // Use a chromium thread because nsITimers* fire on the main thread
43 base::Thread
* mVsyncThread
;
44 RefPtr
<CancelableRunnable
> mCurrentVsyncTask
; // only access on vsync thread
45 bool mVsyncEnabled
; // Only access on main thread
48 DataMutex
<TimeDuration
> mVsyncRate
; // can be accessed on any thread
51 } // namespace mozilla::gfx
53 #endif /* GFX_SOFTWARE_VSYNC_SOURCE_H */