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