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 CONTENT_BROWSER_RENDERER_HOST_DISPLAY_LINK_MAC_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_DISPLAY_LINK_MAC_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_DISPLAY_LINK_MAC_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_DISPLAY_LINK_MAC_H_ |
7 | 7 |
8 #include <QuartzCore/CVDisplayLink.h> | 8 #include <QuartzCore/CVDisplayLink.h> |
9 #include <map> | 9 #include <map> |
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/observer_list.h" |
14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
17 | 18 |
18 namespace content { | 19 namespace content { |
19 | 20 |
20 class DisplayLinkMac : public base::RefCounted<DisplayLinkMac> { | 21 class DisplayLinkMac : public base::RefCounted<DisplayLinkMac> { |
21 public: | 22 public: |
22 static scoped_refptr<DisplayLinkMac> GetForDisplay( | 23 class Observer { |
| 24 public: |
| 25 void OnVSync(base::TimeTicks timebase, base::TimeDelta interval) = 0; |
| 26 }; |
| 27 |
| 28 static scoped_refptr<DisplayLinkMac> GetForDisplay( |
23 CGDirectDisplayID display_id); | 29 CGDirectDisplayID display_id); |
24 | 30 |
25 // Get vsync scheduling parameters. | 31 // Get vsync scheduling parameters. |
26 bool GetVSyncParameters( | 32 bool GetVSyncParameters( |
27 base::TimeTicks* timebase, | 33 base::TimeTicks* timebase, |
28 base::TimeDelta* interval); | 34 base::TimeDelta* interval); |
29 | 35 |
| 36 void AddObserver(Observer* observer); |
| 37 void RemoveObserver(Observer* observer); |
| 38 |
30 private: | 39 private: |
31 friend class base::RefCounted<DisplayLinkMac>; | 40 friend class base::RefCounted<DisplayLinkMac>; |
32 | 41 |
33 DisplayLinkMac( | 42 DisplayLinkMac( |
34 CGDirectDisplayID display_id, | 43 CGDirectDisplayID display_id, |
35 base::ScopedTypeRef<CVDisplayLinkRef> display_link); | 44 base::ScopedTypeRef<CVDisplayLinkRef> display_link); |
36 virtual ~DisplayLinkMac(); | 45 virtual ~DisplayLinkMac(); |
37 | 46 |
38 void StartOrContinueDisplayLink(); | 47 void StartOrContinueDisplayLink(); |
39 void StopDisplayLink(); | 48 void StopDisplayLink(); |
(...skipping 18 matching lines...) Expand all Loading... |
58 base::DelayTimer<DisplayLinkMac> stop_timer_; | 67 base::DelayTimer<DisplayLinkMac> stop_timer_; |
59 | 68 |
60 // VSync parameters computed during Tick. | 69 // VSync parameters computed during Tick. |
61 bool timebase_and_interval_valid_; | 70 bool timebase_and_interval_valid_; |
62 base::TimeTicks timebase_; | 71 base::TimeTicks timebase_; |
63 base::TimeDelta interval_; | 72 base::TimeDelta interval_; |
64 | 73 |
65 // Lock for sharing data between UI thread and display-link thread. | 74 // Lock for sharing data between UI thread and display-link thread. |
66 base::Lock lock_; | 75 base::Lock lock_; |
67 | 76 |
| 77 base::ObserverList<Observer> observer_list_; |
| 78 |
68 // Each display link instance consumes a non-negligible number of cycles, so | 79 // Each display link instance consumes a non-negligible number of cycles, so |
69 // make all display links on the same screen share the same object. | 80 // make all display links on the same screen share the same object. |
70 typedef std::map<CGDirectDisplayID, DisplayLinkMac*> DisplayMap; | 81 typedef std::map<CGDirectDisplayID, DisplayLinkMac*> DisplayMap; |
71 static base::LazyInstance<DisplayMap> display_map_; | 82 static base::LazyInstance<DisplayMap> display_map_; |
72 }; | 83 }; |
73 | 84 |
74 } // content | 85 } // content |
75 | 86 |
76 #endif // CONTENT_BROWSER_RENDERER_HOST_DISPLAY_LINK_MAC_H_ | 87 #endif // CONTENT_BROWSER_RENDERER_HOST_DISPLAY_LINK_MAC_H_ |
OLD | NEW |