Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/thebes/VsyncSource.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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/. */
5
6
#ifndef GFX_VSYNCSOURCE_H
7
#define GFX_VSYNCSOURCE_H
8
9
#include "nsTArray.h"
10
#include "mozilla/RefPtr.h"
11
#include "mozilla/Mutex.h"
12
#include "mozilla/TimeStamp.h"
13
#include "nsISupportsImpl.h"
14
15
namespace mozilla {
16
class RefreshTimerVsyncDispatcher;
17
class CompositorVsyncDispatcher;
18
19
namespace gfx {
20
21
// Controls how and when to enable/disable vsync. Lives as long as the
22
// gfxPlatform does on the parent process
23
class VsyncSource
24
{
25
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(VsyncSource)
26
27
  typedef mozilla::RefreshTimerVsyncDispatcher RefreshTimerVsyncDispatcher;
28
  typedef mozilla::CompositorVsyncDispatcher CompositorVsyncDispatcher;
29
30
public:
31
  // Controls vsync unique to each display and unique on each platform
32
  class Display {
33
    public:
34
      Display();
35
      virtual ~Display();
36
37
      // Notified when this display's vsync occurs, on the vsync thread
38
      // The aVsyncTimestamp should normalize to the Vsync time that just occured
39
      // However, different platforms give different vsync notification times.
40
      // OSX - The vsync timestamp of the upcoming frame, in the future
41
      // Windows: It's messy, see gfxWindowsPlatform.
42
      // Android: TODO
43
      // All platforms should normalize to the vsync that just occured.
44
      // Large parts of Gecko assume TimeStamps should not be in the future such as animations
45
      virtual void NotifyVsync(TimeStamp aVsyncTimestamp);
46
47
      RefPtr<RefreshTimerVsyncDispatcher> GetRefreshTimerVsyncDispatcher();
48
49
      void AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
50
      void RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
51
      void NotifyRefreshTimerVsyncStatus(bool aEnable);
52
      virtual TimeDuration GetVsyncRate();
53
54
      // These should all only be called on the main thread
55
      virtual void EnableVsync() = 0;
56
      virtual void DisableVsync() = 0;
57
      virtual bool IsVsyncEnabled() = 0;
58
      virtual void Shutdown() = 0;
59
60
    private:
61
      void UpdateVsyncStatus();
62
63
      Mutex mDispatcherLock;
64
      bool mRefreshTimerNeedsVsync;
65
      nsTArray<RefPtr<CompositorVsyncDispatcher>> mCompositorVsyncDispatchers;
66
      RefPtr<RefreshTimerVsyncDispatcher> mRefreshTimerVsyncDispatcher;
67
  };
68
69
  void AddCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
70
  void RemoveCompositorVsyncDispatcher(CompositorVsyncDispatcher* aCompositorVsyncDispatcher);
71
72
  RefPtr<RefreshTimerVsyncDispatcher> GetRefreshTimerVsyncDispatcher();
73
  virtual Display& GetGlobalDisplay() = 0; // Works across all displays
74
  void Shutdown();
75
76
protected:
77
0
  virtual ~VsyncSource() {}
78
};
79
80
} // namespace gfx
81
} // namespace mozilla
82
83
#endif /* GFX_VSYNCSOURCE_H */