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/host/drm_display_host_manager.h" | 5 #include "ui/ozone/platform/drm/host/drm_display_host_manager.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <xf86drm.h> | 8 #include <xf86drm.h> |
9 | 9 |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 91 } |
92 DVLOG(1) << "Don't support VGEM"; | 92 DVLOG(1) << "Don't support VGEM"; |
93 return base::FilePath(); | 93 return base::FilePath(); |
94 } | 94 } |
95 | 95 |
96 class FindDrmDisplayHostById { | 96 class FindDrmDisplayHostById { |
97 public: | 97 public: |
98 explicit FindDrmDisplayHostById(int64_t display_id) | 98 explicit FindDrmDisplayHostById(int64_t display_id) |
99 : display_id_(display_id) {} | 99 : display_id_(display_id) {} |
100 | 100 |
101 bool operator()(const DrmDisplayHost* display) const { | 101 bool operator()(const scoped_ptr<DrmDisplayHost>& display) const { |
102 return display->snapshot()->display_id() == display_id_; | 102 return display->snapshot()->display_id() == display_id_; |
103 } | 103 } |
104 | 104 |
105 private: | 105 private: |
106 int64_t display_id_; | 106 int64_t display_id_; |
107 }; | 107 }; |
108 | 108 |
109 } // namespace | 109 } // namespace |
110 | 110 |
111 DrmDisplayHostManager::DrmDisplayHostManager( | 111 DrmDisplayHostManager::DrmDisplayHostManager( |
(...skipping 20 matching lines...) Expand all Loading... |
132 vgem_card_path_ = GetVgemCardPath(); | 132 vgem_card_path_ = GetVgemCardPath(); |
133 } | 133 } |
134 | 134 |
135 device_manager_->AddObserver(this); | 135 device_manager_->AddObserver(this); |
136 proxy_->RegisterHandler(this); | 136 proxy_->RegisterHandler(this); |
137 | 137 |
138 ScopedVector<HardwareDisplayControllerInfo> display_infos = | 138 ScopedVector<HardwareDisplayControllerInfo> display_infos = |
139 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); | 139 GetAvailableDisplayControllerInfos(primary_drm_device_handle_->fd()); |
140 has_dummy_display_ = !display_infos.empty(); | 140 has_dummy_display_ = !display_infos.empty(); |
141 for (size_t i = 0; i < display_infos.size(); ++i) { | 141 for (size_t i = 0; i < display_infos.size(); ++i) { |
142 displays_.push_back(new DrmDisplayHost( | 142 displays_.push_back(make_scoped_ptr(new DrmDisplayHost( |
143 proxy_, CreateDisplaySnapshotParams(display_infos[i], | 143 proxy_, CreateDisplaySnapshotParams(display_infos[i], |
144 primary_drm_device_handle_->fd(), 0, | 144 primary_drm_device_handle_->fd(), 0, |
145 gfx::Point()), | 145 gfx::Point()), |
146 true /* is_dummy */)); | 146 true /* is_dummy */))); |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 DrmDisplayHostManager::~DrmDisplayHostManager() { | 150 DrmDisplayHostManager::~DrmDisplayHostManager() { |
151 device_manager_->RemoveObserver(this); | 151 device_manager_->RemoveObserver(this); |
152 proxy_->UnregisterHandler(this); | 152 proxy_->UnregisterHandler(this); |
153 } | 153 } |
154 | 154 |
155 DrmDisplayHost* DrmDisplayHostManager::GetDisplay(int64_t display_id) { | 155 DrmDisplayHost* DrmDisplayHostManager::GetDisplay(int64_t display_id) { |
156 auto it = std::find_if(displays_.begin(), displays_.end(), | 156 auto it = std::find_if(displays_.begin(), displays_.end(), |
157 FindDrmDisplayHostById(display_id)); | 157 FindDrmDisplayHostById(display_id)); |
158 if (it == displays_.end()) | 158 if (it == displays_.end()) |
159 return nullptr; | 159 return nullptr; |
160 | 160 |
161 return *it; | 161 return it->get(); |
162 } | 162 } |
163 | 163 |
164 void DrmDisplayHostManager::AddDelegate(DrmNativeDisplayDelegate* delegate) { | 164 void DrmDisplayHostManager::AddDelegate(DrmNativeDisplayDelegate* delegate) { |
165 DCHECK(!delegate_); | 165 DCHECK(!delegate_); |
166 delegate_ = delegate; | 166 delegate_ = delegate; |
167 } | 167 } |
168 | 168 |
169 void DrmDisplayHostManager::RemoveDelegate(DrmNativeDisplayDelegate* delegate) { | 169 void DrmDisplayHostManager::RemoveDelegate(DrmNativeDisplayDelegate* delegate) { |
170 DCHECK_EQ(delegate_, delegate); | 170 DCHECK_EQ(delegate_, delegate); |
171 delegate_ = nullptr; | 171 delegate_ = nullptr; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 IPC_MESSAGE_HANDLER(OzoneHostMsg_DisplayControlRelinquished, | 360 IPC_MESSAGE_HANDLER(OzoneHostMsg_DisplayControlRelinquished, |
361 OnRelinquishDisplayControl) | 361 OnRelinquishDisplayControl) |
362 IPC_MESSAGE_UNHANDLED(handled = false) | 362 IPC_MESSAGE_UNHANDLED(handled = false) |
363 IPC_END_MESSAGE_MAP() | 363 IPC_END_MESSAGE_MAP() |
364 | 364 |
365 return handled; | 365 return handled; |
366 } | 366 } |
367 | 367 |
368 void DrmDisplayHostManager::OnUpdateNativeDisplays( | 368 void DrmDisplayHostManager::OnUpdateNativeDisplays( |
369 const std::vector<DisplaySnapshot_Params>& params) { | 369 const std::vector<DisplaySnapshot_Params>& params) { |
370 ScopedVector<DrmDisplayHost> old_displays(displays_.Pass()); | 370 std::vector<scoped_ptr<DrmDisplayHost>> old_displays; |
| 371 displays_.swap(old_displays); |
371 for (size_t i = 0; i < params.size(); ++i) { | 372 for (size_t i = 0; i < params.size(); ++i) { |
372 auto it = std::find_if(old_displays.begin(), old_displays.end(), | 373 auto it = std::find_if(old_displays.begin(), old_displays.end(), |
373 FindDrmDisplayHostById(params[i].display_id)); | 374 FindDrmDisplayHostById(params[i].display_id)); |
374 if (it == old_displays.end()) { | 375 if (it == old_displays.end()) { |
375 displays_.push_back( | 376 displays_.push_back(make_scoped_ptr( |
376 new DrmDisplayHost(proxy_, params[i], false /* is_dummy */)); | 377 new DrmDisplayHost(proxy_, params[i], false /* is_dummy */))); |
377 } else { | 378 } else { |
378 (*it)->UpdateDisplaySnapshot(params[i]); | 379 (*it)->UpdateDisplaySnapshot(params[i]); |
379 displays_.push_back(*it); | 380 displays_.push_back(std::move(*it)); |
380 old_displays.weak_erase(it); | 381 old_displays.erase(it); |
381 } | 382 } |
382 } | 383 } |
383 | 384 |
384 if (!get_displays_callback_.is_null()) { | 385 if (!get_displays_callback_.is_null()) { |
385 base::ThreadTaskRunnerHandle::Get()->PostTask( | 386 base::ThreadTaskRunnerHandle::Get()->PostTask( |
386 FROM_HERE, | 387 FROM_HERE, |
387 base::Bind(&DrmDisplayHostManager::RunUpdateDisplaysCallback, | 388 base::Bind(&DrmDisplayHostManager::RunUpdateDisplaysCallback, |
388 weak_ptr_factory_.GetWeakPtr(), get_displays_callback_)); | 389 weak_ptr_factory_.GetWeakPtr(), get_displays_callback_)); |
389 get_displays_callback_.Reset(); | 390 get_displays_callback_.Reset(); |
390 } | 391 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 | 455 |
455 base::ThreadTaskRunnerHandle::Get()->PostTask( | 456 base::ThreadTaskRunnerHandle::Get()->PostTask( |
456 FROM_HERE, base::Bind(relinquish_display_control_callback_, status)); | 457 FROM_HERE, base::Bind(relinquish_display_control_callback_, status)); |
457 relinquish_display_control_callback_.Reset(); | 458 relinquish_display_control_callback_.Reset(); |
458 display_control_change_pending_ = false; | 459 display_control_change_pending_ = false; |
459 } | 460 } |
460 | 461 |
461 void DrmDisplayHostManager::RunUpdateDisplaysCallback( | 462 void DrmDisplayHostManager::RunUpdateDisplaysCallback( |
462 const GetDisplaysCallback& callback) const { | 463 const GetDisplaysCallback& callback) const { |
463 std::vector<DisplaySnapshot*> snapshots; | 464 std::vector<DisplaySnapshot*> snapshots; |
464 for (auto* display : displays_) | 465 for (const auto& display : displays_) |
465 snapshots.push_back(display->snapshot()); | 466 snapshots.push_back(display->snapshot()); |
466 | 467 |
467 callback.Run(snapshots); | 468 callback.Run(snapshots); |
468 } | 469 } |
469 | 470 |
470 void DrmDisplayHostManager::NotifyDisplayDelegate() const { | 471 void DrmDisplayHostManager::NotifyDisplayDelegate() const { |
471 if (delegate_) | 472 if (delegate_) |
472 delegate_->OnConfigurationChanged(); | 473 delegate_->OnConfigurationChanged(); |
473 } | 474 } |
474 | 475 |
475 } // namespace ui | 476 } // namespace ui |
OLD | NEW |