Chromium Code Reviews| 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 "third_party/skia/include/core/SkCanvas.h" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "ui/gfx/geometry/point.h" | 10 #include "ui/gfx/geometry/point.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 ScreenManager::ScreenManager(DriWrapper* dri, | 62 ScreenManager::ScreenManager(DriWrapper* dri, |
| 63 ScanoutBufferGenerator* buffer_generator) | 63 ScanoutBufferGenerator* buffer_generator) |
| 64 : dri_(dri), buffer_generator_(buffer_generator) { | 64 : dri_(dri), buffer_generator_(buffer_generator) { |
| 65 } | 65 } |
| 66 | 66 |
| 67 ScreenManager::~ScreenManager() { | 67 ScreenManager::~ScreenManager() { |
| 68 DCHECK_EQ(0u, observers_.size()); | |
| 68 } | 69 } |
| 69 | 70 |
| 70 void ScreenManager::AddDisplayController(DriWrapper* dri, | 71 void ScreenManager::AddDisplayController(DriWrapper* dri, |
| 71 uint32_t crtc, | 72 uint32_t crtc, |
| 72 uint32_t connector) { | 73 uint32_t connector) { |
| 73 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); | 74 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); |
| 74 // TODO(dnicoara): Turn this into a DCHECK when async display configuration is | 75 // TODO(dnicoara): Turn this into a DCHECK when async display configuration is |
| 75 // properly supported. (When there can't be a race between forcing initial | 76 // properly supported. (When there can't be a race between forcing initial |
| 76 // display configuration in ScreenManager and NativeDisplayDelegate creating | 77 // display configuration in ScreenManager and NativeDisplayDelegate creating |
| 77 // the display controllers.) | 78 // the display controllers.) |
| 78 if (it != controllers_.end()) { | 79 if (it != controllers_.end()) { |
| 79 LOG(WARNING) << "Display controller (crtc=" << crtc << ") already present."; | 80 LOG(WARNING) << "Display controller (crtc=" << crtc << ") already present."; |
| 80 return; | 81 return; |
| 81 } | 82 } |
| 82 | 83 |
| 83 controllers_.push_back(new HardwareDisplayController( | 84 controllers_.push_back(new HardwareDisplayController( |
| 84 scoped_ptr<CrtcController>(new CrtcController(dri, crtc, connector)))); | 85 scoped_ptr<CrtcController>(new CrtcController(dri, crtc, connector)))); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void ScreenManager::RemoveDisplayController(uint32_t crtc) { | 88 void ScreenManager::RemoveDisplayController(uint32_t crtc) { |
| 88 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); | 89 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); |
| 89 if (it != controllers_.end()) { | 90 if (it != controllers_.end()) { |
| 90 bool is_mirrored = (*it)->IsMirrored(); | 91 bool is_mirrored = (*it)->IsMirrored(); |
| 91 (*it)->RemoveCrtc(crtc); | 92 (*it)->RemoveCrtc(crtc); |
| 92 if (!is_mirrored) | 93 if (!is_mirrored) { |
| 94 FOR_EACH_OBSERVER(DisplayChangeObserver, observers_, | |
| 95 OnDisplayRemoved(*it)); | |
| 93 controllers_.erase(it); | 96 controllers_.erase(it); |
| 97 } | |
| 94 } | 98 } |
| 95 } | 99 } |
| 96 | 100 |
| 97 bool ScreenManager::ConfigureDisplayController(uint32_t crtc, | 101 bool ScreenManager::ConfigureDisplayController(uint32_t crtc, |
| 98 uint32_t connector, | 102 uint32_t connector, |
| 99 const gfx::Point& origin, | 103 const gfx::Point& origin, |
| 100 const drmModeModeInfo& mode) { | 104 const drmModeModeInfo& mode) { |
| 101 gfx::Rect modeset_bounds(origin.x(), origin.y(), mode.hdisplay, | 105 gfx::Rect modeset_bounds(origin.x(), origin.y(), mode.hdisplay, |
| 102 mode.vdisplay); | 106 mode.vdisplay); |
| 103 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); | 107 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); |
| 104 DCHECK(controllers_.end() != it) << "Display controller (crtc=" << crtc | 108 DCHECK(controllers_.end() != it) << "Display controller (crtc=" << crtc |
| 105 << ") doesn't exist."; | 109 << ") doesn't exist."; |
| 106 | 110 |
| 107 HardwareDisplayController* controller = *it; | 111 HardwareDisplayController* controller = *it; |
| 108 controller = *it; | |
| 109 // If nothing changed just enable the controller. Note, we perform an exact | 112 // If nothing changed just enable the controller. Note, we perform an exact |
| 110 // comparison on the mode since the refresh rate may have changed. | 113 // comparison on the mode since the refresh rate may have changed. |
| 111 if (SameMode(mode, controller->get_mode()) && | 114 if (SameMode(mode, controller->get_mode()) && |
| 112 origin == controller->origin()) { | 115 origin == controller->origin()) { |
| 113 if (controller->IsDisabled()) { | 116 if (controller->IsDisabled()) { |
| 114 HardwareDisplayControllers::iterator mirror = | 117 HardwareDisplayControllers::iterator mirror = |
| 115 FindActiveDisplayControllerByLocation(modeset_bounds); | 118 FindActiveDisplayControllerByLocation(modeset_bounds); |
| 116 // If there is an active controller at the same location then start mirror | 119 // If there is an active controller at the same location then start mirror |
| 117 // mode. | 120 // mode. |
| 118 if (mirror != controllers_.end()) | 121 if (mirror != controllers_.end()) |
| 119 return HandleMirrorMode(it, mirror, crtc, connector); | 122 return HandleMirrorMode(it, mirror, crtc, connector); |
| 120 } | 123 } |
| 121 | 124 |
| 125 FOR_EACH_OBSERVER(DisplayChangeObserver, observers_, | |
| 126 OnDisplayChanged(controller)); | |
| 122 // Just re-enable the controller to re-use the current state. | 127 // Just re-enable the controller to re-use the current state. |
| 123 return controller->Enable(); | 128 return controller->Enable(); |
| 124 } | 129 } |
| 125 | 130 |
| 126 // Either the mode or the location of the display changed, so exit mirror | 131 // Either the mode or the location of the display changed, so exit mirror |
| 127 // mode and configure the display independently. If the caller still wants | 132 // mode and configure the display independently. If the caller still wants |
| 128 // mirror mode, subsequent calls configuring the other controllers will | 133 // mirror mode, subsequent calls configuring the other controllers will |
| 129 // restore mirror mode. | 134 // restore mirror mode. |
| 130 if (controller->IsMirrored()) { | 135 if (controller->IsMirrored()) { |
| 131 controller = new HardwareDisplayController(controller->RemoveCrtc(crtc)); | 136 controller = new HardwareDisplayController(controller->RemoveCrtc(crtc)); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 152 } | 157 } |
| 153 | 158 |
| 154 (*it)->Disable(); | 159 (*it)->Disable(); |
| 155 return true; | 160 return true; |
| 156 } | 161 } |
| 157 | 162 |
| 158 LOG(ERROR) << "Failed to find display controller crtc=" << crtc; | 163 LOG(ERROR) << "Failed to find display controller crtc=" << crtc; |
| 159 return false; | 164 return false; |
| 160 } | 165 } |
| 161 | 166 |
| 162 base::WeakPtr<HardwareDisplayController> ScreenManager::GetDisplayController( | 167 HardwareDisplayController* ScreenManager::GetDisplayController( |
| 163 const gfx::Rect& bounds) { | 168 const gfx::Rect& bounds) { |
| 164 // TODO(dnicoara): Remove hack once TestScreen uses a simple Ozone display | 169 // TODO(dnicoara): Remove hack once TestScreen uses a simple Ozone display |
| 165 // configuration reader and ScreenManager is called from there to create the | 170 // configuration reader and ScreenManager is called from there to create the |
| 166 // one display needed by the content_shell target. | 171 // one display needed by the content_shell target. |
| 167 if (controllers_.empty()) | 172 if (controllers_.empty()) |
| 168 ForceInitializationOfPrimaryDisplay(); | 173 ForceInitializationOfPrimaryDisplay(); |
| 169 | 174 |
| 170 HardwareDisplayControllers::iterator it = | 175 HardwareDisplayControllers::iterator it = |
| 171 FindActiveDisplayControllerByLocation(bounds); | 176 FindActiveDisplayControllerByLocation(bounds); |
| 172 if (it != controllers_.end()) | 177 if (it != controllers_.end()) |
| 173 return (*it)->AsWeakPtr(); | 178 return *it; |
| 174 | 179 |
| 175 return base::WeakPtr<HardwareDisplayController>(); | 180 return nullptr; |
| 181 } | |
| 182 | |
| 183 void ScreenManager::AddObserver(DisplayChangeObserver* observer) { | |
| 184 observers_.AddObserver(observer); | |
| 185 } | |
| 186 | |
| 187 void ScreenManager::RemoveObserver(DisplayChangeObserver* observer) { | |
| 188 observers_.RemoveObserver(observer); | |
| 176 } | 189 } |
| 177 | 190 |
| 178 ScreenManager::HardwareDisplayControllers::iterator | 191 ScreenManager::HardwareDisplayControllers::iterator |
| 179 ScreenManager::FindDisplayController(uint32_t crtc) { | 192 ScreenManager::FindDisplayController(uint32_t crtc) { |
| 180 for (HardwareDisplayControllers::iterator it = controllers_.begin(); | 193 for (HardwareDisplayControllers::iterator it = controllers_.begin(); |
| 181 it != controllers_.end(); | 194 it != controllers_.end(); |
| 182 ++it) { | 195 ++it) { |
| 183 if ((*it)->HasCrtc(crtc)) | 196 if ((*it)->HasCrtc(crtc)) |
| 184 return it; | 197 return it; |
| 185 } | 198 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 return false; | 250 return false; |
| 238 } | 251 } |
| 239 | 252 |
| 240 FillModesetBuffer(dri_, controller, buffer.get()); | 253 FillModesetBuffer(dri_, controller, buffer.get()); |
| 241 | 254 |
| 242 if (!controller->Modeset(OverlayPlane(buffer), mode)) { | 255 if (!controller->Modeset(OverlayPlane(buffer), mode)) { |
| 243 LOG(ERROR) << "Failed to modeset controller"; | 256 LOG(ERROR) << "Failed to modeset controller"; |
| 244 return false; | 257 return false; |
| 245 } | 258 } |
| 246 | 259 |
| 260 FOR_EACH_OBSERVER(DisplayChangeObserver, observers_, | |
| 261 OnDisplayChanged(controller)); | |
| 247 return true; | 262 return true; |
| 248 } | 263 } |
| 249 | 264 |
| 250 bool ScreenManager::HandleMirrorMode( | 265 bool ScreenManager::HandleMirrorMode( |
| 251 HardwareDisplayControllers::iterator original, | 266 HardwareDisplayControllers::iterator original, |
| 252 HardwareDisplayControllers::iterator mirror, | 267 HardwareDisplayControllers::iterator mirror, |
| 253 uint32_t crtc, | 268 uint32_t crtc, |
| 254 uint32_t connector) { | 269 uint32_t connector) { |
| 255 (*mirror)->AddCrtc((*original)->RemoveCrtc(crtc)); | 270 (*mirror)->AddCrtc((*original)->RemoveCrtc(crtc)); |
| 256 if ((*mirror)->Enable()) { | 271 if ((*mirror)->Enable()) { |
| 272 FOR_EACH_OBSERVER(DisplayChangeObserver, observers_, | |
| 273 OnDisplayRemoved(*original)); | |
| 274 FOR_EACH_OBSERVER(DisplayChangeObserver, observers_, | |
| 275 OnDisplayChanged(*mirror)); | |
| 257 controllers_.erase(original); | 276 controllers_.erase(original); |
| 258 return true; | 277 return true; |
| 259 } | 278 } |
| 260 | 279 |
| 261 LOG(ERROR) << "Failed to switch to mirror mode"; | 280 LOG(ERROR) << "Failed to switch to mirror mode"; |
| 262 | 281 |
| 263 // When things go wrong revert back to the previous configuration since | 282 // When things go wrong revert back to the previous configuration since |
| 264 // it is expected that the configuration would not have changed if | 283 // it is expected that the configuration would not have changed if |
| 265 // things fail. | 284 // things fail. |
| 266 (*original)->AddCrtc((*mirror)->RemoveCrtc(crtc)); | 285 (*original)->AddCrtc((*mirror)->RemoveCrtc(crtc)); |
|
alexst (slow to review)
2015/01/12 18:49:10
The expectation here is that the config is going t
dnicoara
2015/01/12 18:57:11
Not necessarily. The enable operation may fail, bu
| |
| 267 (*original)->Enable(); | 286 (*original)->Enable(); |
| 268 return false; | 287 return false; |
| 269 } | 288 } |
| 270 | 289 |
| 271 } // namespace ui | 290 } // namespace ui |
| OLD | NEW |