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