| 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 <QuartzCore/CVDisplayLink.h> | 9 #include <QuartzCore/CVDisplayLink.h> |
| 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/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 |
| 27 // Get vsync scheduling parameters. | 29 // Get vsync scheduling parameters. |
| 28 bool GetVSyncParameters( | 30 bool GetVSyncParameters( |
| 29 base::TimeTicks* timebase, | 31 base::TimeTicks* timebase, |
| 30 base::TimeDelta* interval); | 32 base::TimeDelta* interval); |
| 31 | 33 |
| 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 |
| 32 private: | 40 private: |
| 33 friend class base::RefCounted<DisplayLinkMac>; | 41 friend class base::RefCounted<DisplayLinkMac>; |
| 34 | 42 |
| 35 DisplayLinkMac( | 43 DisplayLinkMac( |
| 36 CGDirectDisplayID display_id, | 44 CGDirectDisplayID display_id, |
| 37 base::ScopedTypeRef<CVDisplayLinkRef> display_link); | 45 base::ScopedTypeRef<CVDisplayLinkRef> display_link); |
| 38 virtual ~DisplayLinkMac(); | 46 virtual ~DisplayLinkMac(); |
| 39 | 47 |
| 40 void StartOrContinueDisplayLink(); | 48 void StartOrContinueDisplayLink(); |
| 41 void StopDisplayLink(); | 49 void StopDisplayLink(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 63 | 71 |
| 64 // The display that this display link is attached to. | 72 // The display that this display link is attached to. |
| 65 CGDirectDisplayID display_id_; | 73 CGDirectDisplayID display_id_; |
| 66 | 74 |
| 67 // CVDisplayLink for querying VSync timing info. | 75 // CVDisplayLink for querying VSync timing info. |
| 68 base::ScopedTypeRef<CVDisplayLinkRef> display_link_; | 76 base::ScopedTypeRef<CVDisplayLinkRef> display_link_; |
| 69 | 77 |
| 70 // VSync parameters computed during Tick. | 78 // VSync parameters computed during Tick. |
| 71 bool timebase_and_interval_valid_; | 79 bool timebase_and_interval_valid_; |
| 72 base::TimeTicks timebase_; | 80 base::TimeTicks timebase_; |
| 81 base::TimeTicks timebase_remainder_; |
| 73 base::TimeDelta interval_; | 82 base::TimeDelta interval_; |
| 74 | 83 |
| 75 // Each display link instance consumes a non-negligible number of cycles, so | 84 // Each display link instance consumes a non-negligible number of cycles, so |
| 76 // make all display links on the same screen share the same object. | 85 // make all display links on the same screen share the same object. |
| 77 typedef std::map<CGDirectDisplayID, DisplayLinkMac*> DisplayMap; | 86 typedef std::map<CGDirectDisplayID, DisplayLinkMac*> DisplayMap; |
| 78 static base::LazyInstance<DisplayMap> display_map_; | 87 static base::LazyInstance<DisplayMap> display_map_; |
| 79 }; | 88 }; |
| 80 | 89 |
| 81 } // ui | 90 } // ui |
| 82 | 91 |
| 83 #endif // UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_ | 92 #endif // UI_ACCELERATED_WIDGET_MAC_DISPLAY_LINK_MAC_H_ |
| OLD | NEW |