| 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/drm_gpu_display_manager.h" | 5 #include "ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h" |
| 6 | 6 |
| 7 #include "ui/display/types/gamma_ramp_rgb_entry.h" | 7 #include "ui/display/types/gamma_ramp_rgb_entry.h" |
| 8 #include "ui/ozone/common/display_util.h" | 8 #include "ui/ozone/common/display_util.h" |
| 9 #include "ui/ozone/platform/drm/common/drm_util.h" | 9 #include "ui/ozone/platform/drm/common/drm_util.h" |
| 10 #include "ui/ozone/platform/drm/gpu/drm_device.h" | 10 #include "ui/ozone/platform/drm/gpu/drm_device.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 explicit DisplayComparator(const DrmDisplay* display) | 21 explicit DisplayComparator(const DrmDisplay* display) |
| 22 : drm_(display->drm()), | 22 : drm_(display->drm()), |
| 23 crtc_(display->crtc()), | 23 crtc_(display->crtc()), |
| 24 connector_(display->connector()) {} | 24 connector_(display->connector()) {} |
| 25 | 25 |
| 26 DisplayComparator(const scoped_refptr<DrmDevice>& drm, | 26 DisplayComparator(const scoped_refptr<DrmDevice>& drm, |
| 27 uint32_t crtc, | 27 uint32_t crtc, |
| 28 uint32_t connector) | 28 uint32_t connector) |
| 29 : drm_(drm), crtc_(crtc), connector_(connector) {} | 29 : drm_(drm), crtc_(crtc), connector_(connector) {} |
| 30 | 30 |
| 31 bool operator()(const DrmDisplay* other) const { | 31 bool operator()(const scoped_ptr<DrmDisplay>& other) const { |
| 32 return drm_ == other->drm() && connector_ == other->connector() && | 32 return drm_ == other->drm() && connector_ == other->connector() && |
| 33 crtc_ == other->crtc(); | 33 crtc_ == other->crtc(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 scoped_refptr<DrmDevice> drm_; | 37 scoped_refptr<DrmDevice> drm_; |
| 38 uint32_t crtc_; | 38 uint32_t crtc_; |
| 39 uint32_t connector_; | 39 uint32_t connector_; |
| 40 }; | 40 }; |
| 41 | 41 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 59 | 59 |
| 60 DrmGpuDisplayManager::DrmGpuDisplayManager(ScreenManager* screen_manager, | 60 DrmGpuDisplayManager::DrmGpuDisplayManager(ScreenManager* screen_manager, |
| 61 DrmDeviceManager* drm_device_manager) | 61 DrmDeviceManager* drm_device_manager) |
| 62 : screen_manager_(screen_manager), drm_device_manager_(drm_device_manager) { | 62 : screen_manager_(screen_manager), drm_device_manager_(drm_device_manager) { |
| 63 } | 63 } |
| 64 | 64 |
| 65 DrmGpuDisplayManager::~DrmGpuDisplayManager() { | 65 DrmGpuDisplayManager::~DrmGpuDisplayManager() { |
| 66 } | 66 } |
| 67 | 67 |
| 68 std::vector<DisplaySnapshot_Params> DrmGpuDisplayManager::GetDisplays() { | 68 std::vector<DisplaySnapshot_Params> DrmGpuDisplayManager::GetDisplays() { |
| 69 ScopedVector<DrmDisplay> old_displays(displays_.Pass()); | 69 std::vector<scoped_ptr<DrmDisplay>> old_displays; |
| 70 old_displays.swap(displays_); |
| 70 std::vector<DisplaySnapshot_Params> params_list; | 71 std::vector<DisplaySnapshot_Params> params_list; |
| 71 | 72 |
| 72 const DrmDeviceVector& devices = drm_device_manager_->GetDrmDevices(); | 73 const DrmDeviceVector& devices = drm_device_manager_->GetDrmDevices(); |
| 73 size_t device_index = 0; | 74 size_t device_index = 0; |
| 74 for (const auto& drm : devices) { | 75 for (const auto& drm : devices) { |
| 75 ScopedVector<HardwareDisplayControllerInfo> display_infos = | 76 std::vector<HardwareDisplayControllerInfo> display_infos = |
| 76 GetAvailableDisplayControllerInfos(drm->get_fd()); | 77 GetAvailableDisplayControllerInfos(drm->get_fd()); |
| 77 for (auto* display_info : display_infos) { | 78 for (const auto& display_info : display_infos) { |
| 78 auto it = std::find_if( | 79 auto it = std::find_if( |
| 79 old_displays.begin(), old_displays.end(), | 80 old_displays.begin(), old_displays.end(), |
| 80 DisplayComparator(drm, display_info->crtc()->crtc_id, | 81 DisplayComparator(drm, display_info.crtc()->crtc_id, |
| 81 display_info->connector()->connector_id)); | 82 display_info.connector()->connector_id)); |
| 82 if (it != old_displays.end()) { | 83 if (it != old_displays.end()) { |
| 83 displays_.push_back(*it); | 84 displays_.push_back(it->Pass()); |
| 84 old_displays.weak_erase(it); | 85 old_displays.erase(it); |
| 85 } else { | 86 } else { |
| 86 displays_.push_back(new DrmDisplay(screen_manager_, drm)); | 87 displays_.push_back( |
| 88 make_scoped_ptr(new DrmDisplay(screen_manager_, drm))); |
| 87 } | 89 } |
| 88 params_list.push_back( | 90 params_list.push_back( |
| 89 displays_.back()->Update(display_info, device_index)); | 91 displays_.back()->Update(display_info, device_index)); |
| 90 } | 92 } |
| 91 device_index++; | 93 device_index++; |
| 92 } | 94 } |
| 93 | 95 |
| 94 NotifyScreenManager(displays_.get(), old_displays.get()); | 96 NotifyScreenManager(displays_, old_displays); |
| 95 return params_list; | 97 return params_list; |
| 96 } | 98 } |
| 97 | 99 |
| 98 bool DrmGpuDisplayManager::TakeDisplayControl() { | 100 bool DrmGpuDisplayManager::TakeDisplayControl() { |
| 99 const DrmDeviceVector& devices = drm_device_manager_->GetDrmDevices(); | 101 const DrmDeviceVector& devices = drm_device_manager_->GetDrmDevices(); |
| 100 bool status = true; | 102 bool status = true; |
| 101 for (const auto& drm : devices) | 103 for (const auto& drm : devices) |
| 102 status &= drm->SetMaster(); | 104 status &= drm->SetMaster(); |
| 103 | 105 |
| 104 // Roll-back any successful operation. | 106 // Roll-back any successful operation. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 126 return false; | 128 return false; |
| 127 } | 129 } |
| 128 | 130 |
| 129 drmModeModeInfo mode; | 131 drmModeModeInfo mode; |
| 130 bool mode_found = FindMatchingMode(display->modes(), mode_param, &mode); | 132 bool mode_found = FindMatchingMode(display->modes(), mode_param, &mode); |
| 131 if (!mode_found) { | 133 if (!mode_found) { |
| 132 // If the display doesn't have the mode natively, then lookup the mode from | 134 // If the display doesn't have the mode natively, then lookup the mode from |
| 133 // other displays and try using it on the current display (some displays | 135 // other displays and try using it on the current display (some displays |
| 134 // support panel fitting and they can use different modes even if the mode | 136 // support panel fitting and they can use different modes even if the mode |
| 135 // isn't explicitly declared). | 137 // isn't explicitly declared). |
| 136 for (DrmDisplay* other : displays_) { | 138 for (const auto& other_display : displays_) { |
| 137 mode_found = FindMatchingMode(other->modes(), mode_param, &mode); | 139 mode_found = FindMatchingMode(other_display->modes(), mode_param, &mode); |
| 138 if (mode_found) | 140 if (mode_found) |
| 139 break; | 141 break; |
| 140 } | 142 } |
| 141 } | 143 } |
| 142 | 144 |
| 143 if (!mode_found) { | 145 if (!mode_found) { |
| 144 LOG(ERROR) << "Failed to find mode: size=" << mode_param.size.ToString() | 146 LOG(ERROR) << "Failed to find mode: size=" << mode_param.size.ToString() |
| 145 << " is_interlaced=" << mode_param.is_interlaced | 147 << " is_interlaced=" << mode_param.is_interlaced |
| 146 << " refresh_rate=" << mode_param.refresh_rate; | 148 << " refresh_rate=" << mode_param.refresh_rate; |
| 147 return false; | 149 return false; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 DrmDisplay* display = FindDisplay(display_id); | 188 DrmDisplay* display = FindDisplay(display_id); |
| 187 if (!display) { | 189 if (!display) { |
| 188 LOG(ERROR) << "There is no display with ID " << display_id; | 190 LOG(ERROR) << "There is no display with ID " << display_id; |
| 189 return; | 191 return; |
| 190 } | 192 } |
| 191 | 193 |
| 192 display->SetGammaRamp(lut); | 194 display->SetGammaRamp(lut); |
| 193 } | 195 } |
| 194 | 196 |
| 195 DrmDisplay* DrmGpuDisplayManager::FindDisplay(int64_t display_id) { | 197 DrmDisplay* DrmGpuDisplayManager::FindDisplay(int64_t display_id) { |
| 196 for (DrmDisplay* display : displays_) | 198 for (const auto& display : displays_) { |
| 197 if (display->display_id() == display_id) | 199 if (display->display_id() == display_id) |
| 198 return display; | 200 return display.get(); |
| 201 } |
| 199 | 202 |
| 200 return nullptr; | 203 return nullptr; |
| 201 } | 204 } |
| 202 | 205 |
| 203 void DrmGpuDisplayManager::NotifyScreenManager( | 206 void DrmGpuDisplayManager::NotifyScreenManager( |
| 204 const std::vector<DrmDisplay*>& new_displays, | 207 const std::vector<scoped_ptr<DrmDisplay>>& new_displays, |
| 205 const std::vector<DrmDisplay*>& old_displays) const { | 208 const std::vector<scoped_ptr<DrmDisplay>>& old_displays) const { |
| 206 for (size_t i = 0; i < old_displays.size(); ++i) { | 209 for (const auto& old_display : old_displays) { |
| 207 const std::vector<DrmDisplay*>::const_iterator it = | 210 auto it = std::find_if(new_displays.begin(), new_displays.end(), |
| 208 std::find_if(new_displays.begin(), new_displays.end(), | 211 DisplayComparator(old_display.get())); |
| 209 DisplayComparator(old_displays[i])); | |
| 210 | 212 |
| 211 if (it == new_displays.end()) { | 213 if (it == new_displays.end()) { |
| 212 screen_manager_->RemoveDisplayController(old_displays[i]->drm(), | 214 screen_manager_->RemoveDisplayController(old_display->drm(), |
| 213 old_displays[i]->crtc()); | 215 old_display->crtc()); |
| 214 } | 216 } |
| 215 } | 217 } |
| 216 | 218 |
| 217 for (size_t i = 0; i < new_displays.size(); ++i) { | 219 for (const auto& new_display : new_displays) { |
| 218 const std::vector<DrmDisplay*>::const_iterator it = | 220 auto it = std::find_if(old_displays.begin(), old_displays.end(), |
| 219 std::find_if(old_displays.begin(), old_displays.end(), | 221 DisplayComparator(new_display.get())); |
| 220 DisplayComparator(new_displays[i])); | |
| 221 | 222 |
| 222 if (it == old_displays.end()) { | 223 if (it == old_displays.end()) { |
| 223 screen_manager_->AddDisplayController(new_displays[i]->drm(), | 224 screen_manager_->AddDisplayController( |
| 224 new_displays[i]->crtc(), | 225 new_display->drm(), new_display->crtc(), new_display->connector()); |
| 225 new_displays[i]->connector()); | |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 } // namespace ui | 230 } // namespace ui |
| OLD | NEW |