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 "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" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 ScreenManager::ScreenManager(DriWrapper* dri, | 27 ScreenManager::ScreenManager(DriWrapper* dri, |
| 28 ScanoutBufferGenerator* buffer_generator) | 28 ScanoutBufferGenerator* buffer_generator) |
| 29 : dri_(dri), buffer_generator_(buffer_generator) { | 29 : dri_(dri), buffer_generator_(buffer_generator) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 ScreenManager::~ScreenManager() { | 32 ScreenManager::~ScreenManager() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 void ScreenManager::AddDisplayController(uint32_t crtc, uint32_t connector) { | |
| 36 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); | |
| 37 if (it != controllers_.end()) { | |
| 38 LOG(WARNING) << "Display controller (crtc=" << crtc << ") already present."; | |
|
alexst (slow to review)
2014/09/04 14:44:45
Do you expect this to be a regular frequent occurr
dnicoara
2014/09/04 15:12:07
This is a by-product of having to support a forced
| |
| 39 return; | |
| 40 } | |
| 41 | |
| 42 controllers_.push_back(new HardwareDisplayController( | |
| 43 dri_, scoped_ptr<CrtcState>(new CrtcState(dri_, crtc, connector)))); | |
| 44 } | |
| 45 | |
| 35 void ScreenManager::RemoveDisplayController(uint32_t crtc) { | 46 void ScreenManager::RemoveDisplayController(uint32_t crtc) { |
| 36 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); | 47 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); |
| 37 if (it != controllers_.end()) { | 48 if (it != controllers_.end()) { |
| 38 bool is_mirrored = (*it)->IsMirrored(); | 49 bool is_mirrored = (*it)->IsMirrored(); |
| 39 (*it)->RemoveCrtc(crtc); | 50 (*it)->RemoveCrtc(crtc); |
| 40 if (!is_mirrored) | 51 if (!is_mirrored) |
| 41 controllers_.erase(it); | 52 controllers_.erase(it); |
| 42 } | 53 } |
| 43 } | 54 } |
| 44 | 55 |
| 45 bool ScreenManager::ConfigureDisplayController(uint32_t crtc, | 56 bool ScreenManager::ConfigureDisplayController(uint32_t crtc, |
| 46 uint32_t connector, | 57 uint32_t connector, |
| 47 const gfx::Point& origin, | 58 const gfx::Point& origin, |
| 48 const drmModeModeInfo& mode) { | 59 const drmModeModeInfo& mode) { |
| 49 gfx::Rect modeset_bounds(origin, GetModeSize(mode)); | 60 gfx::Rect modeset_bounds(origin, GetModeSize(mode)); |
| 50 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); | 61 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); |
| 51 HardwareDisplayController* controller = NULL; | 62 DCHECK(controllers_.end() != it) << "Display controller (crtc=" << crtc |
| 52 if (it != controllers_.end()) { | 63 << ") doesn't exist."; |
| 53 controller = *it; | |
| 54 // If nothing changed just enable the controller. Note, we perform an exact | |
| 55 // comparison on the mode since the refresh rate may have changed. | |
| 56 if (SameMode(mode, controller->get_mode()) && | |
| 57 origin == controller->origin() && !controller->IsDisabled()) | |
| 58 return controller->Enable(); | |
| 59 | 64 |
| 60 // Either the mode or the location of the display changed, so exit mirror | 65 HardwareDisplayController* controller = *it; |
| 61 // mode and configure the display independently. If the caller still wants | 66 controller = *it; |
| 62 // mirror mode, subsequent calls configuring the other controllers will | 67 // If nothing changed just enable the controller. Note, we perform an exact |
| 63 // restore mirror mode. | 68 // comparison on the mode since the refresh rate may have changed. |
| 64 if (controller->IsMirrored()) { | 69 if (SameMode(mode, controller->get_mode()) && |
| 65 controller = | 70 origin == controller->origin() && !controller->IsDisabled()) |
| 66 new HardwareDisplayController(dri_, controller->RemoveCrtc(crtc)); | 71 return controller->Enable(); |
| 67 controllers_.push_back(controller); | |
| 68 it = --controllers_.end(); | |
| 69 } | |
| 70 | 72 |
| 71 HardwareDisplayControllers::iterator mirror = | 73 // Either the mode or the location of the display changed, so exit mirror |
| 72 FindActiveDisplayControllerByLocation(modeset_bounds); | 74 // mode and configure the display independently. If the caller still wants |
| 73 // Handle mirror mode. | 75 // mirror mode, subsequent calls configuring the other controllers will |
| 74 if (mirror != controllers_.end() && it != mirror) | 76 // restore mirror mode. |
| 75 return HandleMirrorMode(it, mirror, crtc, connector); | 77 if (controller->IsMirrored()) { |
| 76 } else { | 78 controller = |
| 77 HardwareDisplayControllers::iterator mirror = | 79 new HardwareDisplayController(dri_, controller->RemoveCrtc(crtc)); |
| 78 FindActiveDisplayControllerByLocation(modeset_bounds); | 80 controllers_.push_back(controller); |
| 79 if (mirror != controllers_.end()) { | 81 it = --controllers_.end(); |
| 80 (*mirror)->AddCrtc( | |
| 81 scoped_ptr<CrtcState>(new CrtcState(dri_, crtc, connector))); | |
| 82 return (*mirror)->Enable(); | |
| 83 } | |
| 84 } | 82 } |
| 85 | 83 |
| 86 if (!controller) { | 84 HardwareDisplayControllers::iterator mirror = |
| 87 controller = new HardwareDisplayController( | 85 FindActiveDisplayControllerByLocation(modeset_bounds); |
| 88 dri_, | 86 // Handle mirror mode. |
| 89 scoped_ptr<CrtcState>(new CrtcState(dri_, crtc, connector))); | 87 if (mirror != controllers_.end() && it != mirror) |
| 90 controllers_.push_back(controller); | 88 return HandleMirrorMode(it, mirror, crtc, connector); |
| 91 } | |
| 92 | 89 |
| 93 return ModesetDisplayController(controller, origin, mode); | 90 return ModesetDisplayController(controller, origin, mode); |
| 94 } | 91 } |
| 95 | 92 |
| 96 bool ScreenManager::DisableDisplayController(uint32_t crtc) { | 93 bool ScreenManager::DisableDisplayController(uint32_t crtc) { |
| 97 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); | 94 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); |
| 98 if (it != controllers_.end()) { | 95 if (it != controllers_.end()) { |
| 99 if ((*it)->IsMirrored()) { | 96 if ((*it)->IsMirrored()) { |
| 100 HardwareDisplayController* controller = | 97 HardwareDisplayController* controller = |
| 101 new HardwareDisplayController(dri_, (*it)->RemoveCrtc(crtc)); | 98 new HardwareDisplayController(dri_, (*it)->RemoveCrtc(crtc)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 | 158 |
| 162 DCHECK_NE(0u, displays.size()); | 159 DCHECK_NE(0u, displays.size()); |
| 163 | 160 |
| 164 ScopedDrmPropertyPtr dpms( | 161 ScopedDrmPropertyPtr dpms( |
| 165 dri_->GetProperty(displays[0]->connector(), "DPMS")); | 162 dri_->GetProperty(displays[0]->connector(), "DPMS")); |
| 166 if (dpms) | 163 if (dpms) |
| 167 dri_->SetProperty(displays[0]->connector()->connector_id, | 164 dri_->SetProperty(displays[0]->connector()->connector_id, |
| 168 dpms->prop_id, | 165 dpms->prop_id, |
| 169 DRM_MODE_DPMS_ON); | 166 DRM_MODE_DPMS_ON); |
| 170 | 167 |
| 168 AddDisplayController(displays[0]->crtc()->crtc_id, | |
| 169 displays[0]->connector()->connector_id); | |
| 171 ConfigureDisplayController(displays[0]->crtc()->crtc_id, | 170 ConfigureDisplayController(displays[0]->crtc()->crtc_id, |
| 172 displays[0]->connector()->connector_id, | 171 displays[0]->connector()->connector_id, |
| 173 gfx::Point(), | 172 gfx::Point(), |
| 174 displays[0]->connector()->modes[0]); | 173 displays[0]->connector()->modes[0]); |
| 175 } | 174 } |
| 176 | 175 |
| 177 bool ScreenManager::ModesetDisplayController( | 176 bool ScreenManager::ModesetDisplayController( |
| 178 HardwareDisplayController* controller, | 177 HardwareDisplayController* controller, |
| 179 const gfx::Point& origin, | 178 const gfx::Point& origin, |
| 180 const drmModeModeInfo& mode) { | 179 const drmModeModeInfo& mode) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 211 | 210 |
| 212 // When things go wrong revert back to the previous configuration since | 211 // When things go wrong revert back to the previous configuration since |
| 213 // it is expected that the configuration would not have changed if | 212 // it is expected that the configuration would not have changed if |
| 214 // things fail. | 213 // things fail. |
| 215 (*original)->AddCrtc((*mirror)->RemoveCrtc(crtc)); | 214 (*original)->AddCrtc((*mirror)->RemoveCrtc(crtc)); |
| 216 (*original)->Enable(); | 215 (*original)->Enable(); |
| 217 return false; | 216 return false; |
| 218 } | 217 } |
| 219 | 218 |
| 220 } // namespace ui | 219 } // namespace ui |
| OLD | NEW |