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/Monitor.h"
11 #include "mozilla/RefPtr.h"
12 #include "mozilla/TimeStamp.h"
13 #include "base/thread.h"
14 #include "nsISupportsImpl.h"
15 #include "VsyncSource.h"
17 class SoftwareDisplay final
: public mozilla::gfx::VsyncSource::Display
{
20 void EnableVsync() override
;
21 void DisableVsync() override
;
22 bool IsVsyncEnabled() override
;
23 bool IsInSoftwareVsyncThread();
24 void NotifyVsync(const mozilla::TimeStamp
& aVsyncTimestamp
,
25 const mozilla::TimeStamp
& aOutputTimestamp
) override
;
26 mozilla::TimeDuration
GetVsyncRate() override
;
27 void ScheduleNextVsync(mozilla::TimeStamp aVsyncTimestamp
);
28 void Shutdown() override
;
30 virtual ~SoftwareDisplay();
33 mozilla::TimeDuration mVsyncRate
;
34 // Use a chromium thread because nsITimers* fire on the main thread
35 base::Thread
* mVsyncThread
;
36 RefPtr
<mozilla::CancelableRunnable
>
37 mCurrentVsyncTask
; // only access on vsync thread
38 bool mVsyncEnabled
; // Only access on main thread
41 // Fallback option to use a software timer to mimic vsync. Useful for gtests
42 // To mimic a hardware vsync thread, we create a dedicated software timer
44 class SoftwareVsyncSource
: public mozilla::gfx::VsyncSource
{
46 SoftwareVsyncSource();
47 virtual ~SoftwareVsyncSource();
49 Display
& GetGlobalDisplay() override
{
50 MOZ_ASSERT(mGlobalDisplay
!= nullptr);
51 return *mGlobalDisplay
;
55 RefPtr
<SoftwareDisplay
> mGlobalDisplay
;
58 #endif /* GFX_SOFTWARE_VSYNC_SOURCE_H */