| 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/dri/screen_manager.h" | 5 #include "ui/ozone/platform/dri/screen_manager.h" |
| 6 | 6 |
| 7 #include <xf86drmMode.h> | 7 #include <xf86drmMode.h> |
| 8 | 8 |
| 9 #include "ui/gfx/geometry/point.h" | 9 #include "ui/gfx/geometry/point.h" |
| 10 #include "ui/gfx/geometry/rect.h" | 10 #include "ui/gfx/geometry/rect.h" |
| 11 #include "ui/gfx/geometry/size.h" | 11 #include "ui/gfx/geometry/size.h" |
| 12 #include "ui/ozone/platform/dri/crtc_state.h" | 12 #include "ui/ozone/platform/dri/crtc_state.h" |
| 13 #include "ui/ozone/platform/dri/dri_util.h" | 13 #include "ui/ozone/platform/dri/dri_util.h" |
| 14 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 14 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
| 15 #include "ui/ozone/platform/dri/scanout_buffer.h" | 15 #include "ui/ozone/platform/dri/scanout_buffer.h" |
| 16 | 16 |
| 17 namespace ui { | 17 namespace ui { |
| 18 | 18 |
| 19 namespace { |
| 20 |
| 21 gfx::Size GetModeSize(const drmModeModeInfo& mode) { |
| 22 return gfx::Size(mode.hdisplay, mode.vdisplay); |
| 23 } |
| 24 |
| 25 } // namespace |
| 26 |
| 19 ScreenManager::ScreenManager( | 27 ScreenManager::ScreenManager( |
| 20 DriWrapper* dri, ScanoutBufferGenerator* buffer_generator) | 28 DriWrapper* dri, ScanoutBufferGenerator* buffer_generator) |
| 21 : dri_(dri), buffer_generator_(buffer_generator), last_added_widget_(0) { | 29 : dri_(dri), buffer_generator_(buffer_generator), last_added_widget_(0) { |
| 22 } | 30 } |
| 23 | 31 |
| 24 ScreenManager::~ScreenManager() { | 32 ScreenManager::~ScreenManager() { |
| 25 STLDeleteContainerPairSecondPointers( | 33 STLDeleteContainerPairSecondPointers( |
| 26 controllers_.begin(), controllers_.end()); | 34 controllers_.begin(), controllers_.end()); |
| 27 } | 35 } |
| 28 | 36 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 if (controllers_.empty() && last_added_widget_ == 0) | 112 if (controllers_.empty() && last_added_widget_ == 0) |
| 105 ForceInitializationOfPrimaryDisplay(); | 113 ForceInitializationOfPrimaryDisplay(); |
| 106 | 114 |
| 107 HardwareDisplayControllerMap::iterator it = controllers_.find(widget); | 115 HardwareDisplayControllerMap::iterator it = controllers_.find(widget); |
| 108 if (it != controllers_.end()) | 116 if (it != controllers_.end()) |
| 109 return it->second->AsWeakPtr(); | 117 return it->second->AsWeakPtr(); |
| 110 | 118 |
| 111 return base::WeakPtr<HardwareDisplayController>(); | 119 return base::WeakPtr<HardwareDisplayController>(); |
| 112 } | 120 } |
| 113 | 121 |
| 122 base::WeakPtr<HardwareDisplayController> ScreenManager::GetDisplayController( |
| 123 const gfx::Rect& bounds) { |
| 124 // TODO(dnicoara): Remove hack once TestScreen uses a simple Ozone display |
| 125 // configuration reader and ScreenManager is called from there to create the |
| 126 // one display needed by the content_shell target. |
| 127 if (controllers_.empty()) |
| 128 ForceInitializationOfPrimaryDisplay(); |
| 129 |
| 130 HardwareDisplayControllerMap::iterator it = |
| 131 FindActiveDisplayControllerByLocation(bounds); |
| 132 if (it != controllers_.end()) |
| 133 return it->second->AsWeakPtr(); |
| 134 |
| 135 return base::WeakPtr<HardwareDisplayController>(); |
| 136 } |
| 137 |
| 114 ScreenManager::HardwareDisplayControllerMap::iterator | 138 ScreenManager::HardwareDisplayControllerMap::iterator |
| 115 ScreenManager::FindDisplayController(uint32_t crtc) { | 139 ScreenManager::FindDisplayController(uint32_t crtc) { |
| 116 for (HardwareDisplayControllerMap::iterator it = controllers_.begin(); | 140 for (HardwareDisplayControllerMap::iterator it = controllers_.begin(); |
| 117 it != controllers_.end(); | 141 it != controllers_.end(); |
| 118 ++it) { | 142 ++it) { |
| 119 if (it->second->HasCrtc(crtc)) | 143 if (it->second->HasCrtc(crtc)) |
| 120 return it; | 144 return it; |
| 121 } | 145 } |
| 122 | 146 |
| 123 return controllers_.end(); | 147 return controllers_.end(); |
| 124 } | 148 } |
| 125 | 149 |
| 126 ScreenManager::HardwareDisplayControllerMap::iterator | 150 ScreenManager::HardwareDisplayControllerMap::iterator |
| 127 ScreenManager::FindDisplayControllerByOrigin(const gfx::Point& origin) { | 151 ScreenManager::FindDisplayControllerByOrigin(const gfx::Point& origin) { |
| 128 for (HardwareDisplayControllerMap::iterator it = controllers_.begin(); | 152 for (HardwareDisplayControllerMap::iterator it = controllers_.begin(); |
| 129 it != controllers_.end(); | 153 it != controllers_.end(); |
| 130 ++it) { | 154 ++it) { |
| 131 if (it->second->origin() == origin) | 155 if (it->second->origin() == origin) |
| 132 return it; | 156 return it; |
| 133 } | 157 } |
| 134 | 158 |
| 135 return controllers_.end(); | 159 return controllers_.end(); |
| 136 } | 160 } |
| 137 | 161 |
| 162 ScreenManager::HardwareDisplayControllerMap::iterator |
| 163 ScreenManager::FindActiveDisplayControllerByLocation(const gfx::Rect& bounds) { |
| 164 for (HardwareDisplayControllerMap::iterator it = controllers_.begin(); |
| 165 it != controllers_.end(); |
| 166 ++it) { |
| 167 gfx::Rect controller_bounds(it->second->origin(), |
| 168 GetModeSize(it->second->get_mode())); |
| 169 // We don't perform a strict check since content_shell will have windows |
| 170 // smaller than the display size. |
| 171 if (controller_bounds.Contains(bounds)) |
| 172 return it; |
| 173 } |
| 174 |
| 175 return controllers_.end(); |
| 176 } |
| 177 |
| 138 void ScreenManager::ForceInitializationOfPrimaryDisplay() { | 178 void ScreenManager::ForceInitializationOfPrimaryDisplay() { |
| 139 ScopedVector<HardwareDisplayControllerInfo> displays = | 179 ScopedVector<HardwareDisplayControllerInfo> displays = |
| 140 GetAvailableDisplayControllerInfos(dri_->get_fd()); | 180 GetAvailableDisplayControllerInfos(dri_->get_fd()); |
| 141 | 181 |
| 142 DCHECK_NE(0u, displays.size()); | 182 DCHECK_NE(0u, displays.size()); |
| 143 | 183 |
| 144 ScopedDrmPropertyPtr dpms( | 184 ScopedDrmPropertyPtr dpms( |
| 145 dri_->GetProperty(displays[0]->connector(), "DPMS")); | 185 dri_->GetProperty(displays[0]->connector(), "DPMS")); |
| 146 if (dpms) | 186 if (dpms) |
| 147 dri_->SetProperty(displays[0]->connector()->connector_id, | 187 dri_->SetProperty(displays[0]->connector()->connector_id, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 | 232 |
| 193 // When things go wrong revert back to the previous configuration since | 233 // When things go wrong revert back to the previous configuration since |
| 194 // it is expected that the configuration would not have changed if | 234 // it is expected that the configuration would not have changed if |
| 195 // things fail. | 235 // things fail. |
| 196 original->second->AddCrtc(mirror->second->RemoveCrtc(crtc)); | 236 original->second->AddCrtc(mirror->second->RemoveCrtc(crtc)); |
| 197 original->second->Enable(); | 237 original->second->Enable(); |
| 198 return false; | 238 return false; |
| 199 } | 239 } |
| 200 | 240 |
| 201 } // namespace ui | 241 } // namespace ui |
| OLD | NEW |