Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Side by Side Diff: ui/ozone/platform/drm/gpu/screen_manager.cc

Issue 1438343002: Remove deprecated ScopedVector usage from ui/ozone and ui/events/ozone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove HDCI stuff Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/screen_manager.h" 5 #include "ui/ozone/platform/drm/gpu/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 15 matching lines...) Expand all
26 // to the new modeset buffer |buffer|. 26 // to the new modeset buffer |buffer|.
27 void FillModesetBuffer(const scoped_refptr<DrmDevice>& drm, 27 void FillModesetBuffer(const scoped_refptr<DrmDevice>& drm,
28 HardwareDisplayController* controller, 28 HardwareDisplayController* controller,
29 ScanoutBuffer* buffer) { 29 ScanoutBuffer* buffer) {
30 DrmConsoleBuffer modeset_buffer(drm, buffer->GetFramebufferId()); 30 DrmConsoleBuffer modeset_buffer(drm, buffer->GetFramebufferId());
31 if (!modeset_buffer.Initialize()) { 31 if (!modeset_buffer.Initialize()) {
32 VLOG(2) << "Failed to grab framebuffer " << buffer->GetFramebufferId(); 32 VLOG(2) << "Failed to grab framebuffer " << buffer->GetFramebufferId();
33 return; 33 return;
34 } 34 }
35 35
36 auto crtcs = controller->crtc_controllers(); 36 DCHECK(!controller->crtc_controllers().empty());
37 DCHECK(!crtcs.empty()); 37 CrtcController* first_crtc = controller->crtc_controllers()[0].get();
38 38 ScopedDrmCrtcPtr saved_crtc(drm->GetCrtc(first_crtc->crtc()));
39 ScopedDrmCrtcPtr saved_crtc(drm->GetCrtc(crtcs[0]->crtc()));
40 if (!saved_crtc || !saved_crtc->buffer_id) { 39 if (!saved_crtc || !saved_crtc->buffer_id) {
41 VLOG(2) << "Crtc has no saved state or wasn't modeset"; 40 VLOG(2) << "Crtc has no saved state or wasn't modeset";
42 return; 41 return;
43 } 42 }
44 43
45 // If the display controller is in mirror mode, the CRTCs should be sharing 44 // If the display controller is in mirror mode, the CRTCs should be sharing
46 // the same framebuffer. 45 // the same framebuffer.
47 DrmConsoleBuffer saved_buffer(drm, saved_crtc->buffer_id); 46 DrmConsoleBuffer saved_buffer(drm, saved_crtc->buffer_id);
48 if (!saved_buffer.Initialize()) { 47 if (!saved_buffer.Initialize()) {
49 VLOG(2) << "Failed to grab saved framebuffer " << saved_crtc->buffer_id; 48 VLOG(2) << "Failed to grab saved framebuffer " << saved_crtc->buffer_id;
(...skipping 11 matching lines...) Expand all
61 skia::RefPtr<SkImage> image = saved_buffer.image(); 60 skia::RefPtr<SkImage> image = saved_buffer.image();
62 SkPaint paint; 61 SkPaint paint;
63 // Copy the source buffer. Do not perform any blending. 62 // Copy the source buffer. Do not perform any blending.
64 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 63 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
65 modeset_buffer.canvas()->drawImage(image.get(), 0, 0, &paint); 64 modeset_buffer.canvas()->drawImage(image.get(), 0, 0, &paint);
66 } 65 }
67 66
68 CrtcController* GetCrtcController(HardwareDisplayController* controller, 67 CrtcController* GetCrtcController(HardwareDisplayController* controller,
69 const scoped_refptr<DrmDevice>& drm, 68 const scoped_refptr<DrmDevice>& drm,
70 uint32_t crtc) { 69 uint32_t crtc) {
71 for (CrtcController* crtc_controller : controller->crtc_controllers()) { 70 for (const auto& crtc_controller : controller->crtc_controllers()) {
72 if (crtc_controller->crtc() == crtc) 71 if (crtc_controller->crtc() == crtc)
73 return crtc_controller; 72 return crtc_controller.get();
74 } 73 }
75 74
76 NOTREACHED(); 75 NOTREACHED();
77 return nullptr; 76 return nullptr;
78 } 77 }
79 78
80 } // namespace 79 } // namespace
81 80
82 ScreenManager::ScreenManager(ScanoutBufferGenerator* buffer_generator) 81 ScreenManager::ScreenManager(ScanoutBufferGenerator* buffer_generator)
83 : buffer_generator_(buffer_generator) { 82 : buffer_generator_(buffer_generator) {
84 } 83 }
85 84
86 ScreenManager::~ScreenManager() { 85 ScreenManager::~ScreenManager() {
87 DCHECK(window_map_.empty()); 86 DCHECK(window_map_.empty());
88 } 87 }
89 88
90 void ScreenManager::AddDisplayController(const scoped_refptr<DrmDevice>& drm, 89 void ScreenManager::AddDisplayController(const scoped_refptr<DrmDevice>& drm,
91 uint32_t crtc, 90 uint32_t crtc,
92 uint32_t connector) { 91 uint32_t connector) {
93 HardwareDisplayControllers::iterator it = FindDisplayController(drm, crtc); 92 HardwareDisplayControllers::iterator it = FindDisplayController(drm, crtc);
94 // TODO(dnicoara): Turn this into a DCHECK when async display configuration is 93 // TODO(dnicoara): Turn this into a DCHECK when async display configuration is
95 // properly supported. (When there can't be a race between forcing initial 94 // properly supported. (When there can't be a race between forcing initial
96 // display configuration in ScreenManager and NativeDisplayDelegate creating 95 // display configuration in ScreenManager and NativeDisplayDelegate creating
97 // the display controllers.) 96 // the display controllers.)
98 if (it != controllers_.end()) { 97 if (it != controllers_.end()) {
99 LOG(WARNING) << "Display controller (crtc=" << crtc << ") already present."; 98 LOG(WARNING) << "Display controller (crtc=" << crtc << ") already present.";
100 return; 99 return;
101 } 100 }
102 101
103 controllers_.push_back(new HardwareDisplayController( 102 controllers_.push_back(make_scoped_ptr(new HardwareDisplayController(
104 scoped_ptr<CrtcController>(new CrtcController(drm, crtc, connector)), 103 scoped_ptr<CrtcController>(new CrtcController(drm, crtc, connector)),
105 gfx::Point())); 104 gfx::Point())));
106 } 105 }
107 106
108 void ScreenManager::RemoveDisplayController(const scoped_refptr<DrmDevice>& drm, 107 void ScreenManager::RemoveDisplayController(const scoped_refptr<DrmDevice>& drm,
109 uint32_t crtc) { 108 uint32_t crtc) {
110 HardwareDisplayControllers::iterator it = FindDisplayController(drm, crtc); 109 HardwareDisplayControllers::iterator it = FindDisplayController(drm, crtc);
111 if (it != controllers_.end()) { 110 if (it != controllers_.end()) {
112 bool is_mirrored = (*it)->IsMirrored(); 111 bool is_mirrored = (*it)->IsMirrored();
113 (*it)->RemoveCrtc(drm, crtc); 112 (*it)->RemoveCrtc(drm, crtc);
114 if (!is_mirrored) { 113 if (!is_mirrored) {
115 controllers_.erase(it); 114 controllers_.erase(it);
(...skipping 21 matching lines...) Expand all
137 uint32_t crtc, 136 uint32_t crtc,
138 uint32_t connector, 137 uint32_t connector,
139 const gfx::Point& origin, 138 const gfx::Point& origin,
140 const drmModeModeInfo& mode) { 139 const drmModeModeInfo& mode) {
141 gfx::Rect modeset_bounds(origin.x(), origin.y(), mode.hdisplay, 140 gfx::Rect modeset_bounds(origin.x(), origin.y(), mode.hdisplay,
142 mode.vdisplay); 141 mode.vdisplay);
143 HardwareDisplayControllers::iterator it = FindDisplayController(drm, crtc); 142 HardwareDisplayControllers::iterator it = FindDisplayController(drm, crtc);
144 DCHECK(controllers_.end() != it) << "Display controller (crtc=" << crtc 143 DCHECK(controllers_.end() != it) << "Display controller (crtc=" << crtc
145 << ") doesn't exist."; 144 << ") doesn't exist.";
146 145
147 HardwareDisplayController* controller = *it; 146 HardwareDisplayController* controller = it->get();
148 CrtcController* crtc_controller = GetCrtcController(controller, drm, crtc); 147 CrtcController* crtc_controller = GetCrtcController(controller, drm, crtc);
149 // If nothing changed just enable the controller. Note, we perform an exact 148 // If nothing changed just enable the controller. Note, we perform an exact
150 // comparison on the mode since the refresh rate may have changed. 149 // comparison on the mode since the refresh rate may have changed.
151 if (SameMode(mode, crtc_controller->mode()) && 150 if (SameMode(mode, crtc_controller->mode()) &&
152 origin == controller->origin()) { 151 origin == controller->origin()) {
153 if (controller->IsDisabled()) { 152 if (controller->IsDisabled()) {
154 HardwareDisplayControllers::iterator mirror = 153 HardwareDisplayControllers::iterator mirror =
155 FindActiveDisplayControllerByLocation(modeset_bounds); 154 FindActiveDisplayControllerByLocation(modeset_bounds);
156 // If there is an active controller at the same location then start mirror 155 // If there is an active controller at the same location then start mirror
157 // mode. 156 // mode.
158 if (mirror != controllers_.end()) 157 if (mirror != controllers_.end())
159 return HandleMirrorMode(it, mirror, drm, crtc, connector, mode); 158 return HandleMirrorMode(it, mirror, drm, crtc, connector, mode);
160 } 159 }
161 160
162 // Just re-enable the controller to re-use the current state. 161 // Just re-enable the controller to re-use the current state.
163 return EnableController(controller); 162 return EnableController(controller);
164 } 163 }
165 164
166 // Either the mode or the location of the display changed, so exit mirror 165 // Either the mode or the location of the display changed, so exit mirror
167 // mode and configure the display independently. If the caller still wants 166 // mode and configure the display independently. If the caller still wants
168 // mirror mode, subsequent calls configuring the other controllers will 167 // mirror mode, subsequent calls configuring the other controllers will
169 // restore mirror mode. 168 // restore mirror mode.
170 if (controller->IsMirrored()) { 169 if (controller->IsMirrored()) {
171 controller = new HardwareDisplayController( 170 controllers_.push_back(make_scoped_ptr(new HardwareDisplayController(
172 controller->RemoveCrtc(drm, crtc), controller->origin()); 171 controller->RemoveCrtc(drm, crtc), controller->origin())));
173 controllers_.push_back(controller);
174 it = controllers_.end() - 1; 172 it = controllers_.end() - 1;
173 controller = it->get();
175 } 174 }
176 175
177 HardwareDisplayControllers::iterator mirror = 176 HardwareDisplayControllers::iterator mirror =
178 FindActiveDisplayControllerByLocation(modeset_bounds); 177 FindActiveDisplayControllerByLocation(modeset_bounds);
179 // Handle mirror mode. 178 // Handle mirror mode.
180 if (mirror != controllers_.end() && it != mirror) 179 if (mirror != controllers_.end() && it != mirror)
181 return HandleMirrorMode(it, mirror, drm, crtc, connector, mode); 180 return HandleMirrorMode(it, mirror, drm, crtc, connector, mode);
182 181
183 return ModesetController(controller, origin, mode); 182 return ModesetController(controller, origin, mode);
184 } 183 }
185 184
186 bool ScreenManager::DisableDisplayController( 185 bool ScreenManager::DisableDisplayController(
187 const scoped_refptr<DrmDevice>& drm, 186 const scoped_refptr<DrmDevice>& drm,
188 uint32_t crtc) { 187 uint32_t crtc) {
189 HardwareDisplayControllers::iterator it = FindDisplayController(drm, crtc); 188 HardwareDisplayControllers::iterator it = FindDisplayController(drm, crtc);
190 if (it != controllers_.end()) { 189 if (it != controllers_.end()) {
191 HardwareDisplayController* controller = *it; 190 HardwareDisplayController* controller = it->get();
192 if (controller->IsMirrored()) { 191 if (controller->IsMirrored()) {
193 controller = new HardwareDisplayController( 192 controllers_.push_back(make_scoped_ptr(new HardwareDisplayController(
194 controller->RemoveCrtc(drm, crtc), controller->origin()); 193 controller->RemoveCrtc(drm, crtc), controller->origin())));
195 controllers_.push_back(controller); 194 controller = controllers_.back().get();
196 } 195 }
197 196
198 controller->Disable(); 197 controller->Disable();
199 UpdateControllerToWindowMapping(); 198 UpdateControllerToWindowMapping();
200 return true; 199 return true;
201 } 200 }
202 201
203 LOG(ERROR) << "Failed to find display controller crtc=" << crtc; 202 LOG(ERROR) << "Failed to find display controller crtc=" << crtc;
204 return false; 203 return false;
205 } 204 }
206 205
207 HardwareDisplayController* ScreenManager::GetDisplayController( 206 HardwareDisplayController* ScreenManager::GetDisplayController(
208 const gfx::Rect& bounds) { 207 const gfx::Rect& bounds) {
209 HardwareDisplayControllers::iterator it = 208 HardwareDisplayControllers::iterator it =
210 FindActiveDisplayControllerByLocation(bounds); 209 FindActiveDisplayControllerByLocation(bounds);
211 if (it != controllers_.end()) 210 if (it != controllers_.end())
212 return *it; 211 return it->get();
213 212
214 return nullptr; 213 return nullptr;
215 } 214 }
216 215
217 void ScreenManager::AddWindow(gfx::AcceleratedWidget widget, 216 void ScreenManager::AddWindow(gfx::AcceleratedWidget widget,
218 scoped_ptr<DrmWindow> window) { 217 scoped_ptr<DrmWindow> window) {
219 std::pair<WidgetToWindowMap::iterator, bool> result = 218 std::pair<WidgetToWindowMap::iterator, bool> result =
220 window_map_.add(widget, window.Pass()); 219 window_map_.add(widget, window.Pass());
221 DCHECK(result.second) << "Window already added."; 220 DCHECK(result.second) << "Window already added.";
222 UpdateControllerToWindowMapping(); 221 UpdateControllerToWindowMapping();
(...skipping 11 matching lines...) Expand all
234 WidgetToWindowMap::iterator it = window_map_.find(widget); 233 WidgetToWindowMap::iterator it = window_map_.find(widget);
235 if (it != window_map_.end()) 234 if (it != window_map_.end())
236 return it->second; 235 return it->second;
237 236
238 return nullptr; 237 return nullptr;
239 } 238 }
240 239
241 ScreenManager::HardwareDisplayControllers::iterator 240 ScreenManager::HardwareDisplayControllers::iterator
242 ScreenManager::FindDisplayController(const scoped_refptr<DrmDevice>& drm, 241 ScreenManager::FindDisplayController(const scoped_refptr<DrmDevice>& drm,
243 uint32_t crtc) { 242 uint32_t crtc) {
244 for (HardwareDisplayControllers::iterator it = controllers_.begin(); 243 for (auto it = controllers_.begin(); it != controllers_.end(); ++it) {
245 it != controllers_.end(); ++it) {
246 if ((*it)->HasCrtc(drm, crtc)) 244 if ((*it)->HasCrtc(drm, crtc))
247 return it; 245 return it;
248 } 246 }
249 247
250 return controllers_.end(); 248 return controllers_.end();
251 } 249 }
252 250
253 ScreenManager::HardwareDisplayControllers::iterator 251 ScreenManager::HardwareDisplayControllers::iterator
254 ScreenManager::FindActiveDisplayControllerByLocation(const gfx::Rect& bounds) { 252 ScreenManager::FindActiveDisplayControllerByLocation(const gfx::Rect& bounds) {
255 for (HardwareDisplayControllers::iterator it = controllers_.begin(); 253 for (auto it = controllers_.begin(); it != controllers_.end(); ++it) {
256 it != controllers_.end(); ++it) {
257 gfx::Rect controller_bounds((*it)->origin(), (*it)->GetModeSize()); 254 gfx::Rect controller_bounds((*it)->origin(), (*it)->GetModeSize());
258 if (controller_bounds == bounds && !(*it)->IsDisabled()) 255 if (controller_bounds == bounds && !(*it)->IsDisabled())
259 return it; 256 return it;
260 } 257 }
261 258
262 return controllers_.end(); 259 return controllers_.end();
263 } 260 }
264 261
265 bool ScreenManager::HandleMirrorMode( 262 bool ScreenManager::HandleMirrorMode(
266 HardwareDisplayControllers::iterator original, 263 HardwareDisplayControllers::iterator original,
267 HardwareDisplayControllers::iterator mirror, 264 HardwareDisplayControllers::iterator mirror,
268 const scoped_refptr<DrmDevice>& drm, 265 const scoped_refptr<DrmDevice>& drm,
269 uint32_t crtc, 266 uint32_t crtc,
270 uint32_t connector, 267 uint32_t connector,
271 const drmModeModeInfo& mode) { 268 const drmModeModeInfo& mode) {
272 gfx::Point last_origin = (*original)->origin(); 269 gfx::Point last_origin = (*original)->origin();
273 // There should only be one CRTC in this controller. 270 // There should only be one CRTC in this controller.
274 drmModeModeInfo last_mode = (*original)->crtc_controllers()[0]->mode(); 271 drmModeModeInfo last_mode = (*original)->crtc_controllers()[0]->mode();
275 272
276 // Modeset the CRTC with its mode in the original controller so that only this 273 // Modeset the CRTC with its mode in the original controller so that only this
277 // CRTC is affected by the mode. Otherwise it could apply a mode with the same 274 // CRTC is affected by the mode. Otherwise it could apply a mode with the same
278 // resolution and refresh rate but with different timings to the other CRTC. 275 // resolution and refresh rate but with different timings to the other CRTC.
279 // TODO(dnicoara): This is hacky, instead the DrmDisplay and CrtcController 276 // TODO(dnicoara): This is hacky, instead the DrmDisplay and CrtcController
280 // should be merged and picking the mode should be done properly within 277 // should be merged and picking the mode should be done properly within
281 // HardwareDisplayController. 278 // HardwareDisplayController.
282 if (ModesetController(*original, (*mirror)->origin(), mode)) { 279 if (ModesetController(original->get(), (*mirror)->origin(), mode)) {
283 (*mirror)->AddCrtc((*original)->RemoveCrtc(drm, crtc)); 280 (*mirror)->AddCrtc((*original)->RemoveCrtc(drm, crtc));
284 controllers_.erase(original); 281 controllers_.erase(original);
285 return true; 282 return true;
286 } 283 }
287 284
288 LOG(ERROR) << "Failed to switch to mirror mode"; 285 LOG(ERROR) << "Failed to switch to mirror mode";
289 286
290 // When things go wrong revert back to the previous configuration since 287 // When things go wrong revert back to the previous configuration since
291 // it is expected that the configuration would not have changed if 288 // it is expected that the configuration would not have changed if
292 // things fail. 289 // things fail.
293 ModesetController(*original, last_origin, last_mode); 290 ModesetController(original->get(), last_origin, last_mode);
294 return false; 291 return false;
295 } 292 }
296 293
297 void ScreenManager::UpdateControllerToWindowMapping() { 294 void ScreenManager::UpdateControllerToWindowMapping() {
298 std::map<DrmWindow*, HardwareDisplayController*> window_to_controller_map; 295 std::map<DrmWindow*, HardwareDisplayController*> window_to_controller_map;
299 // First create a unique mapping between a window and a controller. Note, a 296 // First create a unique mapping between a window and a controller. Note, a
300 // controller may be associated with at most 1 window. 297 // controller may be associated with at most 1 window.
301 for (HardwareDisplayController* controller : controllers_) { 298 for (const auto& controller : controllers_) {
302 if (controller->IsDisabled()) 299 if (controller->IsDisabled())
303 continue; 300 continue;
304 301
305 DrmWindow* window = FindWindowAt( 302 DrmWindow* window = FindWindowAt(
306 gfx::Rect(controller->origin(), controller->GetModeSize())); 303 gfx::Rect(controller->origin(), controller->GetModeSize()));
307 if (!window) 304 if (!window)
308 continue; 305 continue;
309 306
310 window_to_controller_map[window] = controller; 307 window_to_controller_map[window] = controller.get();
311 } 308 }
312 309
313 // Apply the new mapping to all windows. 310 // Apply the new mapping to all windows.
314 for (auto pair : window_map_) { 311 for (auto pair : window_map_) {
315 auto it = window_to_controller_map.find(pair.second); 312 auto it = window_to_controller_map.find(pair.second);
316 HardwareDisplayController* controller = nullptr; 313 HardwareDisplayController* controller = nullptr;
317 if (it != window_to_controller_map.end()) 314 if (it != window_to_controller_map.end())
318 controller = it->second; 315 controller = it->second;
319 316
320 bool should_enable = 317 bool should_enable =
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 DrmWindow* ScreenManager::FindWindowAt(const gfx::Rect& bounds) const { 381 DrmWindow* ScreenManager::FindWindowAt(const gfx::Rect& bounds) const {
385 for (auto pair : window_map_) { 382 for (auto pair : window_map_) {
386 if (pair.second->bounds() == bounds) 383 if (pair.second->bounds() == bounds)
387 return pair.second; 384 return pair.second;
388 } 385 }
389 386
390 return nullptr; 387 return nullptr;
391 } 388 }
392 389
393 } // namespace ui 390 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/gpu/screen_manager.h ('k') | ui/ozone/platform/drm/gpu/screen_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698