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 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h" | 5 #include "ui/ozone/platform/drm/gpu/hardware_display_controller.h" |
6 | 6 |
7 #include <drm.h> | 7 #include <drm.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <xf86drm.h> | 9 #include <xf86drm.h> |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 HardwareDisplayController::~HardwareDisplayController() { | 40 HardwareDisplayController::~HardwareDisplayController() { |
41 // Reset the cursor. | 41 // Reset the cursor. |
42 UnsetCursor(); | 42 UnsetCursor(); |
43 } | 43 } |
44 | 44 |
45 bool HardwareDisplayController::Modeset(const OverlayPlane& primary, | 45 bool HardwareDisplayController::Modeset(const OverlayPlane& primary, |
46 drmModeModeInfo mode) { | 46 drmModeModeInfo mode) { |
47 TRACE_EVENT0("drm", "HDC::Modeset"); | 47 TRACE_EVENT0("drm", "HDC::Modeset"); |
48 DCHECK(primary.buffer.get()); | 48 DCHECK(primary.buffer.get()); |
49 bool status = true; | 49 bool status = true; |
50 for (size_t i = 0; i < crtc_controllers_.size(); ++i) | 50 for (const auto& controller : crtc_controllers_) |
51 status &= crtc_controllers_[i]->Modeset(primary, mode); | 51 status &= controller->Modeset(primary, mode); |
52 | 52 |
53 is_disabled_ = false; | 53 is_disabled_ = false; |
54 | 54 |
55 return status; | 55 return status; |
56 } | 56 } |
57 | 57 |
58 bool HardwareDisplayController::Enable(const OverlayPlane& primary) { | 58 bool HardwareDisplayController::Enable(const OverlayPlane& primary) { |
59 TRACE_EVENT0("drm", "HDC::Enable"); | 59 TRACE_EVENT0("drm", "HDC::Enable"); |
60 DCHECK(primary.buffer.get()); | 60 DCHECK(primary.buffer.get()); |
61 bool status = true; | 61 bool status = true; |
62 for (size_t i = 0; i < crtc_controllers_.size(); ++i) { | 62 for (const auto& controller : crtc_controllers_) |
63 status &= | 63 status &= controller->Modeset(primary, controller->mode()); |
64 crtc_controllers_[i]->Modeset(primary, crtc_controllers_[i]->mode()); | |
65 } | |
66 | 64 |
67 is_disabled_ = false; | 65 is_disabled_ = false; |
68 | 66 |
69 return status; | 67 return status; |
70 } | 68 } |
71 | 69 |
72 void HardwareDisplayController::Disable() { | 70 void HardwareDisplayController::Disable() { |
73 TRACE_EVENT0("drm", "HDC::Disable"); | 71 TRACE_EVENT0("drm", "HDC::Disable"); |
74 for (size_t i = 0; i < crtc_controllers_.size(); ++i) | 72 for (const auto& controller : crtc_controllers_) |
75 crtc_controllers_[i]->Disable(); | 73 controller->Disable(); |
76 | |
77 | 74 |
78 is_disabled_ = true; | 75 is_disabled_ = true; |
79 } | 76 } |
80 | 77 |
81 void HardwareDisplayController::SchedulePageFlip( | 78 void HardwareDisplayController::SchedulePageFlip( |
82 const OverlayPlaneList& plane_list, | 79 const OverlayPlaneList& plane_list, |
83 const PageFlipCallback& callback) { | 80 const PageFlipCallback& callback) { |
84 ActualSchedulePageFlip(plane_list, false /* test_only */, callback); | 81 ActualSchedulePageFlip(plane_list, false /* test_only */, callback); |
85 } | 82 } |
86 | 83 |
(...skipping 27 matching lines...) Expand all Loading... |
114 }); | 111 }); |
115 if (pending_planes.front().z_order != 0) { | 112 if (pending_planes.front().z_order != 0) { |
116 callback.Run(gfx::SwapResult::SWAP_FAILED); | 113 callback.Run(gfx::SwapResult::SWAP_FAILED); |
117 return false; | 114 return false; |
118 } | 115 } |
119 | 116 |
120 for (const auto& planes : owned_hardware_planes_) | 117 for (const auto& planes : owned_hardware_planes_) |
121 planes.first->plane_manager()->BeginFrame(planes.second); | 118 planes.first->plane_manager()->BeginFrame(planes.second); |
122 | 119 |
123 bool status = true; | 120 bool status = true; |
124 for (size_t i = 0; i < crtc_controllers_.size(); ++i) { | 121 for (const auto& controller : crtc_controllers_) { |
125 status &= crtc_controllers_[i]->SchedulePageFlip( | 122 status &= controller->SchedulePageFlip( |
126 owned_hardware_planes_.get(crtc_controllers_[i]->drm().get()), | 123 owned_hardware_planes_.get(controller->drm().get()), pending_planes, |
127 pending_planes, test_only, page_flip_request); | 124 test_only, page_flip_request); |
128 } | 125 } |
129 | 126 |
130 for (const auto& planes : owned_hardware_planes_) { | 127 for (const auto& planes : owned_hardware_planes_) { |
131 if (!planes.first->plane_manager()->Commit(planes.second, test_only)) { | 128 if (!planes.first->plane_manager()->Commit(planes.second, test_only)) { |
132 status = false; | 129 status = false; |
133 } | 130 } |
134 } | 131 } |
135 | 132 |
136 return status; | 133 return status; |
137 } | 134 } |
(...skipping 18 matching lines...) Expand all Loading... |
156 return plane_ids; | 153 return plane_ids; |
157 } | 154 } |
158 | 155 |
159 bool HardwareDisplayController::SetCursor( | 156 bool HardwareDisplayController::SetCursor( |
160 const scoped_refptr<ScanoutBuffer>& buffer) { | 157 const scoped_refptr<ScanoutBuffer>& buffer) { |
161 bool status = true; | 158 bool status = true; |
162 | 159 |
163 if (is_disabled_) | 160 if (is_disabled_) |
164 return true; | 161 return true; |
165 | 162 |
166 for (size_t i = 0; i < crtc_controllers_.size(); ++i) | 163 for (const auto& controller : crtc_controllers_) |
167 status &= crtc_controllers_[i]->SetCursor(buffer); | 164 status &= controller->SetCursor(buffer); |
168 | 165 |
169 return status; | 166 return status; |
170 } | 167 } |
171 | 168 |
172 bool HardwareDisplayController::UnsetCursor() { | 169 bool HardwareDisplayController::UnsetCursor() { |
173 bool status = true; | 170 bool status = true; |
174 for (size_t i = 0; i < crtc_controllers_.size(); ++i) | 171 for (const auto& controller : crtc_controllers_) |
175 status &= crtc_controllers_[i]->SetCursor(nullptr); | 172 status &= controller->SetCursor(nullptr); |
176 | 173 |
177 return status; | 174 return status; |
178 } | 175 } |
179 | 176 |
180 bool HardwareDisplayController::MoveCursor(const gfx::Point& location) { | 177 bool HardwareDisplayController::MoveCursor(const gfx::Point& location) { |
181 if (is_disabled_) | 178 if (is_disabled_) |
182 return true; | 179 return true; |
183 | 180 |
184 bool status = true; | 181 bool status = true; |
185 for (size_t i = 0; i < crtc_controllers_.size(); ++i) | 182 for (const auto& controller : crtc_controllers_) |
186 status &= crtc_controllers_[i]->MoveCursor(location); | 183 status &= controller->MoveCursor(location); |
187 | 184 |
188 return status; | 185 return status; |
189 } | 186 } |
190 | 187 |
191 void HardwareDisplayController::AddCrtc(scoped_ptr<CrtcController> controller) { | 188 void HardwareDisplayController::AddCrtc(scoped_ptr<CrtcController> controller) { |
192 scoped_refptr<DrmDevice> drm = controller->drm(); | 189 scoped_refptr<DrmDevice> drm = controller->drm(); |
193 owned_hardware_planes_.add(drm.get(), scoped_ptr<HardwareDisplayPlaneList>( | 190 owned_hardware_planes_.add(drm.get(), scoped_ptr<HardwareDisplayPlaneList>( |
194 new HardwareDisplayPlaneList())); | 191 new HardwareDisplayPlaneList())); |
195 | 192 |
196 // Check if this controller owns any planes and ensure we keep track of them. | 193 // Check if this controller owns any planes and ensure we keep track of them. |
197 const ScopedVector<HardwareDisplayPlane>& all_planes = | 194 const std::vector<scoped_ptr<HardwareDisplayPlane>>& all_planes = |
198 drm->plane_manager()->planes(); | 195 drm->plane_manager()->planes(); |
199 HardwareDisplayPlaneList* crtc_plane_list = | 196 HardwareDisplayPlaneList* crtc_plane_list = |
200 owned_hardware_planes_.get(drm.get()); | 197 owned_hardware_planes_.get(drm.get()); |
201 uint32_t crtc = controller->crtc(); | 198 uint32_t crtc = controller->crtc(); |
202 for (auto* plane : all_planes) { | 199 for (const auto& plane : all_planes) { |
203 if (plane->in_use() && (plane->owning_crtc() == crtc)) | 200 if (plane->in_use() && (plane->owning_crtc() == crtc)) |
204 crtc_plane_list->old_plane_list.push_back(plane); | 201 crtc_plane_list->old_plane_list.push_back(plane.get()); |
205 } | 202 } |
206 | 203 |
207 crtc_controllers_.push_back(controller.Pass()); | 204 crtc_controllers_.push_back(controller.Pass()); |
208 } | 205 } |
209 | 206 |
210 scoped_ptr<CrtcController> HardwareDisplayController::RemoveCrtc( | 207 scoped_ptr<CrtcController> HardwareDisplayController::RemoveCrtc( |
211 const scoped_refptr<DrmDevice>& drm, | 208 const scoped_refptr<DrmDevice>& drm, |
212 uint32_t crtc) { | 209 uint32_t crtc) { |
213 for (ScopedVector<CrtcController>::iterator it = crtc_controllers_.begin(); | 210 for (auto it = crtc_controllers_.begin(); it != crtc_controllers_.end(); |
214 it != crtc_controllers_.end(); ++it) { | 211 ++it) { |
215 if ((*it)->drm() == drm && (*it)->crtc() == crtc) { | 212 if ((*it)->drm() == drm && (*it)->crtc() == crtc) { |
216 scoped_ptr<CrtcController> controller(*it); | 213 scoped_ptr<CrtcController> controller(std::move(*it)); |
217 crtc_controllers_.weak_erase(it); | 214 crtc_controllers_.erase(it); |
| 215 |
218 // Remove entry from |owned_hardware_planes_| iff no other crtcs share it. | 216 // Remove entry from |owned_hardware_planes_| iff no other crtcs share it. |
219 bool found = false; | 217 bool found = false; |
220 for (ScopedVector<CrtcController>::iterator it = | 218 for (auto it = crtc_controllers_.begin(); it != crtc_controllers_.end(); |
221 crtc_controllers_.begin(); | 219 ++it) { |
222 it != crtc_controllers_.end(); ++it) { | |
223 if ((*it)->drm() == controller->drm()) { | 220 if ((*it)->drm() == controller->drm()) { |
224 found = true; | 221 found = true; |
225 break; | 222 break; |
226 } | 223 } |
227 } | 224 } |
228 if (found) { | 225 if (found) { |
229 std::vector<HardwareDisplayPlane*> all_planes; | 226 std::vector<HardwareDisplayPlane*> all_planes; |
230 HardwareDisplayPlaneList* plane_list = | 227 HardwareDisplayPlaneList* plane_list = |
231 owned_hardware_planes_.get(drm.get()); | 228 owned_hardware_planes_.get(drm.get()); |
232 all_planes.swap(plane_list->old_plane_list); | 229 all_planes.swap(plane_list->old_plane_list); |
233 for (auto* plane : all_planes) { | 230 for (auto* plane : all_planes) { |
234 if (plane->owning_crtc() != crtc) | 231 if (plane->owning_crtc() != crtc) |
235 plane_list->old_plane_list.push_back(plane); | 232 plane_list->old_plane_list.push_back(plane); |
236 } | 233 } |
237 } else { | 234 } else { |
238 owned_hardware_planes_.erase(controller->drm().get()); | 235 owned_hardware_planes_.erase(controller->drm().get()); |
239 } | 236 } |
240 | 237 |
241 return controller.Pass(); | 238 return controller.Pass(); |
242 } | 239 } |
243 } | 240 } |
244 | 241 |
245 return nullptr; | 242 return nullptr; |
246 } | 243 } |
247 | 244 |
248 bool HardwareDisplayController::HasCrtc(const scoped_refptr<DrmDevice>& drm, | 245 bool HardwareDisplayController::HasCrtc(const scoped_refptr<DrmDevice>& drm, |
249 uint32_t crtc) const { | 246 uint32_t crtc) const { |
250 for (size_t i = 0; i < crtc_controllers_.size(); ++i) | 247 for (const auto& controller : crtc_controllers_) { |
251 if (crtc_controllers_[i]->drm() == drm && | 248 if (controller->drm() == drm && controller->crtc() == crtc) |
252 crtc_controllers_[i]->crtc() == crtc) | |
253 return true; | 249 return true; |
| 250 } |
254 | 251 |
255 return false; | 252 return false; |
256 } | 253 } |
257 | 254 |
258 bool HardwareDisplayController::IsMirrored() const { | 255 bool HardwareDisplayController::IsMirrored() const { |
259 return crtc_controllers_.size() > 1; | 256 return crtc_controllers_.size() > 1; |
260 } | 257 } |
261 | 258 |
262 bool HardwareDisplayController::IsDisabled() const { | 259 bool HardwareDisplayController::IsDisabled() const { |
263 return is_disabled_; | 260 return is_disabled_; |
264 } | 261 } |
265 | 262 |
266 gfx::Size HardwareDisplayController::GetModeSize() const { | 263 gfx::Size HardwareDisplayController::GetModeSize() const { |
267 // If there are multiple CRTCs they should all have the same size. | 264 // If there are multiple CRTCs they should all have the same size. |
268 return gfx::Size(crtc_controllers_[0]->mode().hdisplay, | 265 return gfx::Size(crtc_controllers_[0]->mode().hdisplay, |
269 crtc_controllers_[0]->mode().vdisplay); | 266 crtc_controllers_[0]->mode().vdisplay); |
270 } | 267 } |
271 | 268 |
272 uint64_t HardwareDisplayController::GetTimeOfLastFlip() const { | 269 uint64_t HardwareDisplayController::GetTimeOfLastFlip() const { |
273 uint64_t time = 0; | 270 uint64_t time = 0; |
274 for (size_t i = 0; i < crtc_controllers_.size(); ++i) | 271 for (const auto& controller : crtc_controllers_) { |
275 if (time < crtc_controllers_[i]->time_of_last_flip()) | 272 if (time < controller->time_of_last_flip()) |
276 time = crtc_controllers_[i]->time_of_last_flip(); | 273 time = controller->time_of_last_flip(); |
| 274 } |
277 | 275 |
278 return time; | 276 return time; |
279 } | 277 } |
280 | 278 |
281 scoped_refptr<DrmDevice> HardwareDisplayController::GetAllocationDrmDevice() | 279 scoped_refptr<DrmDevice> HardwareDisplayController::GetAllocationDrmDevice() |
282 const { | 280 const { |
283 DCHECK(!crtc_controllers_.empty()); | 281 DCHECK(!crtc_controllers_.empty()); |
284 // TODO(dnicoara) When we support mirroring across DRM devices, figure out | 282 // TODO(dnicoara) When we support mirroring across DRM devices, figure out |
285 // which device should be used for allocations. | 283 // which device should be used for allocations. |
286 return crtc_controllers_[0]->drm(); | 284 return crtc_controllers_[0]->drm(); |
287 } | 285 } |
288 | 286 |
289 } // namespace ui | 287 } // namespace ui |
OLD | NEW |