Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: ui/accelerated_widget_mac/display_link_mac.cc

Issue 1273563002: Mac Overlays: Add GPU back-pressure (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use default fences Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "ui/accelerated_widget_mac/display_link_mac.h" 5 #include "ui/accelerated_widget_mac/display_link_mac.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/trace_event/trace_event.h" 9 #include "base/trace_event/trace_event.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 template<> 13 template<>
14 struct ScopedTypeRefTraits<CVDisplayLinkRef> { 14 struct ScopedTypeRefTraits<CVDisplayLinkRef> {
15 static void Retain(CVDisplayLinkRef object) { 15 static void Retain(CVDisplayLinkRef object) {
16 CVDisplayLinkRetain(object); 16 CVDisplayLinkRetain(object);
17 } 17 }
18 static void Release(CVDisplayLinkRef object) { 18 static void Release(CVDisplayLinkRef object) {
19 CVDisplayLinkRelease(object); 19 CVDisplayLinkRelease(object);
20 } 20 }
21 }; 21 };
22 22
23 } // namespace base 23 } // namespace base
24 24
25 namespace ui { 25 namespace ui {
26 26
27 // static 27 // static
28 scoped_refptr<DisplayLinkMac> DisplayLinkMac::GetForDisplay( 28 scoped_refptr<DisplayLinkMac> DisplayLinkMac::GetForDisplay(
29 CGDirectDisplayID display_id) { 29 CGDirectDisplayID display_id) {
30 if (!display_id)
31 return nullptr;
32
30 // Return the existing display link for this display, if it exists. 33 // Return the existing display link for this display, if it exists.
31 DisplayMap::iterator found = display_map_.Get().find(display_id); 34 DisplayMap::iterator found = display_map_.Get().find(display_id);
32 if (found != display_map_.Get().end()) { 35 if (found != display_map_.Get().end()) {
33 return found->second; 36 return found->second;
34 } 37 }
35 38
36 CVReturn ret = kCVReturnSuccess; 39 CVReturn ret = kCVReturnSuccess;
37 40
38 base::ScopedTypeRef<CVDisplayLinkRef> display_link; 41 base::ScopedTypeRef<CVDisplayLinkRef> display_link;
39 ret = CVDisplayLinkCreateWithCGDisplay( 42 ret = CVDisplayLinkCreateWithCGDisplay(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (!timebase_and_interval_valid_) { 101 if (!timebase_and_interval_valid_) {
99 StartOrContinueDisplayLink(); 102 StartOrContinueDisplayLink();
100 return false; 103 return false;
101 } 104 }
102 105
103 *timebase = timebase_; 106 *timebase = timebase_;
104 *interval = interval_; 107 *interval = interval_;
105 return true; 108 return true;
106 } 109 }
107 110
111 base::TimeTicks DisplayLinkMac::GetNextVSyncTimeAfter(
112 const base::TimeTicks& from, double interval_fraction) {
113 if (!timebase_and_interval_valid_) {
114 StartOrContinueDisplayLink();
115 return from;
116 }
117
118 // Compute the previous vsync time.
119 base::TimeTicks previous_vsync =
120 interval_ * ((from - timebase_remainder_) / interval_) +
121 timebase_remainder_;
122
123 // Return |interval_fraction| through the next vsync.
124 return previous_vsync + (1 + interval_fraction) * interval_;
125 }
126
108 void DisplayLinkMac::Tick(const CVTimeStamp& cv_time) { 127 void DisplayLinkMac::Tick(const CVTimeStamp& cv_time) {
109 TRACE_EVENT0("ui", "DisplayLinkMac::Tick"); 128 TRACE_EVENT0("ui", "DisplayLinkMac::Tick");
110 129
111 // Verify that videoRefreshPeriod is 32 bits. 130 // Verify that videoRefreshPeriod is 32 bits.
112 DCHECK((cv_time.videoRefreshPeriod & ~0xffffFFFFull) == 0ull); 131 DCHECK((cv_time.videoRefreshPeriod & ~0xffffFFFFull) == 0ull);
113 132
114 // Verify that the numerator and denominator make some sense. 133 // Verify that the numerator and denominator make some sense.
115 uint32 numerator = static_cast<uint32>(cv_time.videoRefreshPeriod); 134 uint32 numerator = static_cast<uint32>(cv_time.videoRefreshPeriod);
116 uint32 denominator = cv_time.videoTimeScale; 135 uint32 denominator = cv_time.videoTimeScale;
117 if (numerator <= 0 || denominator <= 0) { 136 if (numerator <= 0 || denominator <= 0) {
118 LOG(WARNING) << "Unexpected numerator or denominator, bailing."; 137 LOG(WARNING) << "Unexpected numerator or denominator, bailing.";
119 return; 138 return;
120 } 139 }
121 140
122 timebase_ = base::TimeTicks::FromInternalValue( 141 timebase_ = base::TimeTicks::FromInternalValue(
123 cv_time.hostTime / 1000); 142 cv_time.hostTime / 1000);
124 interval_ = base::TimeDelta::FromMicroseconds( 143 interval_ = base::TimeDelta::FromMicroseconds(
125 1000000 * static_cast<int64>(numerator) / denominator); 144 1000000 * static_cast<int64>(numerator) / denominator);
145 // Compute |timebase_remainder_| to be the first vsync after time zero.
146 timebase_remainder_ =
147 timebase_ - interval_ * ((timebase_ - base::TimeTicks()) / interval_);
126 timebase_and_interval_valid_ = true; 148 timebase_and_interval_valid_ = true;
127 149
128 StopDisplayLink(); 150 StopDisplayLink();
129 } 151 }
130 152
131 void DisplayLinkMac::StartOrContinueDisplayLink() { 153 void DisplayLinkMac::StartOrContinueDisplayLink() {
132 if (CVDisplayLinkIsRunning(display_link_)) 154 if (CVDisplayLinkIsRunning(display_link_))
133 return; 155 return;
134 156
135 CVReturn ret = CVDisplayLinkStart(display_link_); 157 CVReturn ret = CVDisplayLinkStart(display_link_);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 DisplayLinkMac* display_link_mac = found->second; 197 DisplayLinkMac* display_link_mac = found->second;
176 display_link_mac->timebase_and_interval_valid_ = false; 198 display_link_mac->timebase_and_interval_valid_ = false;
177 } 199 }
178 200
179 // static 201 // static
180 base::LazyInstance<DisplayLinkMac::DisplayMap> 202 base::LazyInstance<DisplayLinkMac::DisplayMap>
181 DisplayLinkMac::display_map_ = LAZY_INSTANCE_INITIALIZER; 203 DisplayLinkMac::display_map_ = LAZY_INSTANCE_INITIALIZER;
182 204
183 } // ui 205 } // ui
184 206
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698