| 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 <map> | 8 #include <map> |
| 9 #include <QuartzCore/CVDisplayLink.h> | 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 base { | 19 namespace base { |
| 20 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace ui { | 23 namespace ui { |
| 24 | 24 |
| 25 class ACCELERATED_WIDGET_MAC_EXPORT DisplayLinkMac : | 25 class ACCELERATED_WIDGET_MAC_EXPORT DisplayLinkMac |
| 26 public base::RefCounted<DisplayLinkMac> { | 26 : public base::RefCountedThreadSafe<DisplayLinkMac> { |
| 27 public: | 27 public: |
| 28 static scoped_refptr<DisplayLinkMac> GetForDisplay( | 28 static scoped_refptr<DisplayLinkMac> GetForDisplay( |
| 29 CGDirectDisplayID display_id); | 29 CGDirectDisplayID display_id); |
| 30 | 30 |
| 31 // Get vsync scheduling parameters. | 31 // Get vsync scheduling parameters. |
| 32 bool GetVSyncParameters( | 32 bool GetVSyncParameters( |
| 33 base::TimeTicks* timebase, | 33 base::TimeTicks* timebase, |
| 34 base::TimeDelta* interval); | 34 base::TimeDelta* interval); |
| 35 | 35 |
| 36 // The vsync parameters are cached, because re-computing them is expensive. | 36 // The vsync parameters are cached, because re-computing them is expensive. |
| 37 // The parameters also skew over time (astonishingly quickly -- 0.1 msec per | 37 // The parameters also skew over time (astonishingly quickly -- 0.1 msec per |
| 38 // second), so, use this method to tell the display link the current time. | 38 // second), so, use this method to tell the display link the current time. |
| 39 // If too much time has elapsed since the last time the vsync parameters were | 39 // If too much time has elapsed since the last time the vsync parameters were |
| 40 // calculated, re-calculate them. | 40 // calculated, re-calculate them. |
| 41 void NotifyCurrentTime(const base::TimeTicks& now); | 41 void NotifyCurrentTime(const base::TimeTicks& now); |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 friend class base::RefCounted<DisplayLinkMac>; | 44 friend class base::RefCountedThreadSafe<DisplayLinkMac>; |
| 45 | 45 |
| 46 DisplayLinkMac( | 46 DisplayLinkMac( |
| 47 CGDirectDisplayID display_id, | 47 CGDirectDisplayID display_id, |
| 48 base::ScopedTypeRef<CVDisplayLinkRef> display_link); | 48 base::ScopedTypeRef<CVDisplayLinkRef> display_link); |
| 49 virtual ~DisplayLinkMac(); | 49 virtual ~DisplayLinkMac(); |
| 50 | 50 |
| 51 void StartOrContinueDisplayLink(); | 51 void StartOrContinueDisplayLink(); |
| 52 void StopDisplayLink(); | 52 void StopDisplayLink(); |
| 53 void Tick(const CVTimeStamp& time); | 53 void Tick(const CVTimeStamp& time); |
| 54 | 54 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 // Each display link instance consumes a non-negligible number of cycles, so | 90 // Each display link instance consumes a non-negligible number of cycles, so |
| 91 // make all display links on the same screen share the same object. | 91 // make all display links on the same screen share the same object. |
| 92 typedef std::map<CGDirectDisplayID, DisplayLinkMac*> DisplayMap; | 92 typedef std::map<CGDirectDisplayID, DisplayLinkMac*> DisplayMap; |
| 93 static base::LazyInstance<DisplayMap> display_map_; | 93 static base::LazyInstance<DisplayMap> display_map_; |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 } // ui | 96 } // ui |
| 97 | 97 |
| 98 #endif // UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_ | 98 #endif // UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_ |
| OLD | NEW |