OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_ | 5 #ifndef UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_ |
6 #define UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_ | 6 #define UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_ |
7 | 7 |
| 8 #include <QuartzCore/CVDisplayLink.h> |
8 #include <map> | 9 #include <map> |
9 #include <QuartzCore/CVDisplayLink.h> | |
10 | 10 |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/mac/scoped_typeref.h" | 12 #include "base/mac/scoped_typeref.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
17 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" | 17 #include "ui/accelerated_widget_mac/accelerated_widget_mac_export.h" |
18 | 18 |
19 namespace ui { | 19 namespace ui { |
20 | 20 |
21 class ACCELERATED_WIDGET_MAC_EXPORT DisplayLinkMac : | 21 class ACCELERATED_WIDGET_MAC_EXPORT DisplayLinkMac : |
22 public base::RefCounted<DisplayLinkMac> { | 22 public base::RefCounted<DisplayLinkMac> { |
23 public: | 23 public: |
24 static scoped_refptr<DisplayLinkMac> GetForDisplay( | 24 static scoped_refptr<DisplayLinkMac> GetForDisplay( |
25 CGDirectDisplayID display_id); | 25 CGDirectDisplayID display_id); |
26 | 26 |
27 CGDirectDisplayID display_id() const { return display_id_; } | |
28 | |
29 // Get vsync scheduling parameters. | 27 // Get vsync scheduling parameters. |
30 bool GetVSyncParameters( | 28 bool GetVSyncParameters( |
31 base::TimeTicks* timebase, | 29 base::TimeTicks* timebase, |
32 base::TimeDelta* interval); | 30 base::TimeDelta* interval); |
33 | 31 |
34 // Return the time of |interval_fraction| of the way through the next | |
35 // vsync period that starts after |from|. If the vsync parameters have | |
36 // not yet been computed, return |from|. | |
37 base::TimeTicks GetNextVSyncTimeAfter( | |
38 const base::TimeTicks& from, double interval_fraction); | |
39 | |
40 private: | 32 private: |
41 friend class base::RefCounted<DisplayLinkMac>; | 33 friend class base::RefCounted<DisplayLinkMac>; |
42 | 34 |
43 DisplayLinkMac( | 35 DisplayLinkMac( |
44 CGDirectDisplayID display_id, | 36 CGDirectDisplayID display_id, |
45 base::ScopedTypeRef<CVDisplayLinkRef> display_link); | 37 base::ScopedTypeRef<CVDisplayLinkRef> display_link); |
46 virtual ~DisplayLinkMac(); | 38 virtual ~DisplayLinkMac(); |
47 | 39 |
48 void StartOrContinueDisplayLink(); | 40 void StartOrContinueDisplayLink(); |
49 void StopDisplayLink(); | 41 void StopDisplayLink(); |
(...skipping 21 matching lines...) Expand all Loading... |
71 | 63 |
72 // The display that this display link is attached to. | 64 // The display that this display link is attached to. |
73 CGDirectDisplayID display_id_; | 65 CGDirectDisplayID display_id_; |
74 | 66 |
75 // CVDisplayLink for querying VSync timing info. | 67 // CVDisplayLink for querying VSync timing info. |
76 base::ScopedTypeRef<CVDisplayLinkRef> display_link_; | 68 base::ScopedTypeRef<CVDisplayLinkRef> display_link_; |
77 | 69 |
78 // VSync parameters computed during Tick. | 70 // VSync parameters computed during Tick. |
79 bool timebase_and_interval_valid_; | 71 bool timebase_and_interval_valid_; |
80 base::TimeTicks timebase_; | 72 base::TimeTicks timebase_; |
81 base::TimeTicks timebase_remainder_; | |
82 base::TimeDelta interval_; | 73 base::TimeDelta interval_; |
83 | 74 |
84 // Each display link instance consumes a non-negligible number of cycles, so | 75 // Each display link instance consumes a non-negligible number of cycles, so |
85 // make all display links on the same screen share the same object. | 76 // make all display links on the same screen share the same object. |
86 typedef std::map<CGDirectDisplayID, DisplayLinkMac*> DisplayMap; | 77 typedef std::map<CGDirectDisplayID, DisplayLinkMac*> DisplayMap; |
87 static base::LazyInstance<DisplayMap> display_map_; | 78 static base::LazyInstance<DisplayMap> display_map_; |
88 }; | 79 }; |
89 | 80 |
90 } // ui | 81 } // ui |
91 | 82 |
92 #endif // UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_ | 83 #endif // UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_ |
OLD | NEW |