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 #import <QuartzCore/CVDisplayLink.h> | 8 #include <QuartzCore/CVDisplayLink.h> |
9 | 9 |
| 10 #include "base/mac/scoped_typeref.h" |
10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
11 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "base/timer/timer.h" | 14 #include "base/timer/timer.h" |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 | 17 |
17 class DisplayLinkMac : public base::RefCounted<DisplayLinkMac> { | 18 class DisplayLinkMac : public base::RefCounted<DisplayLinkMac> { |
18 public: | 19 public: |
19 static scoped_refptr<DisplayLinkMac> Create(); | 20 static scoped_refptr<DisplayLinkMac> Create(); |
20 | 21 |
21 // Get vsync scheduling parameters. | 22 // Get vsync scheduling parameters. |
22 bool GetVSyncParameters( | 23 bool GetVSyncParameters( |
23 base::TimeTicks* timebase, | 24 base::TimeTicks* timebase, |
24 base::TimeDelta* interval); | 25 base::TimeDelta* interval); |
25 | 26 |
26 private: | 27 private: |
27 friend class base::RefCounted<DisplayLinkMac>; | 28 friend class base::RefCounted<DisplayLinkMac>; |
| 29 typedef base::ScopedTypeRef< |
| 30 CVDisplayLinkRef, |
| 31 CVDisplayLinkRef, |
| 32 CVDisplayLinkRetain, |
| 33 CVDisplayLinkRelease> |
| 34 ScopedCVDisplayLinkRef; |
28 | 35 |
29 DisplayLinkMac(CVDisplayLinkRef display_link); | 36 DisplayLinkMac(ScopedCVDisplayLinkRef display_link); |
30 virtual ~DisplayLinkMac(); | 37 virtual ~DisplayLinkMac(); |
31 | 38 |
32 void StartOrContinueDisplayLink(); | 39 void StartOrContinueDisplayLink(); |
33 void StopDisplayLink(); | 40 void StopDisplayLink(); |
34 void Tick(const CVTimeStamp* time); | 41 void Tick(const CVTimeStamp* time); |
35 | 42 |
36 static CVReturn DisplayLinkCallback( | 43 static CVReturn DisplayLinkCallback( |
37 CVDisplayLinkRef display_link, | 44 CVDisplayLinkRef display_link, |
38 const CVTimeStamp* now, | 45 const CVTimeStamp* now, |
39 const CVTimeStamp* output_time, | 46 const CVTimeStamp* output_time, |
40 CVOptionFlags flags_in, | 47 CVOptionFlags flags_in, |
41 CVOptionFlags* flags_out, | 48 CVOptionFlags* flags_out, |
42 void* context); | 49 void* context); |
43 | 50 |
44 // CVDisplayLink for querying VSync timing info. | 51 // CVDisplayLink for querying VSync timing info. |
45 CVDisplayLinkRef display_link_; | 52 ScopedCVDisplayLinkRef display_link_; |
46 | 53 |
47 // Timer for stopping the display link if it has not been queried in | 54 // Timer for stopping the display link if it has not been queried in |
48 // the last second. | 55 // the last second. |
49 base::DelayTimer<DisplayLinkMac> stop_timer_; | 56 base::DelayTimer<DisplayLinkMac> stop_timer_; |
50 | 57 |
51 // VSync parameters computed during Tick. | 58 // VSync parameters computed during Tick. |
52 bool timebase_and_interval_valid_; | 59 bool timebase_and_interval_valid_; |
53 base::TimeTicks timebase_; | 60 base::TimeTicks timebase_; |
54 base::TimeDelta interval_; | 61 base::TimeDelta interval_; |
55 | 62 |
56 // Lock for sharing data between UI thread and display-link thread. | 63 // Lock for sharing data between UI thread and display-link thread. |
57 base::Lock lock_; | 64 base::Lock lock_; |
58 }; | 65 }; |
59 | 66 |
60 } // content | 67 } // content |
61 | 68 |
62 #endif // CONTENT_BROWSER_RENDERER_HOST_DISPLAY_LINK_MAC_H_ | 69 #endif // CONTENT_BROWSER_RENDERER_HOST_DISPLAY_LINK_MAC_H_ |
OLD | NEW |