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

Side by Side Diff: ui/ozone/platform/dri/screen_manager.cc

Issue 554083002: Reland of: [Ozone-GBM] Handle GPU crashes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 months 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/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 ScreenManager::ScreenManager(DriWrapper* dri, 19 ScreenManager::ScreenManager(DriWrapper* dri,
20 ScanoutBufferGenerator* buffer_generator) 20 ScanoutBufferGenerator* buffer_generator)
21 : dri_(dri), buffer_generator_(buffer_generator) { 21 : dri_(dri), buffer_generator_(buffer_generator) {
22 } 22 }
23 23
24 ScreenManager::~ScreenManager() { 24 ScreenManager::~ScreenManager() {
25 } 25 }
26 26
27 void ScreenManager::AddDisplayController(uint32_t crtc, uint32_t connector) {
28 HardwareDisplayControllers::iterator it = FindDisplayController(crtc);
29 // TODO(dnicoara): Turn this into a DCHECK when async display configuration is
30 // properly supported. (When there can't be a race between forcing initial
31 // display configuration in ScreenManager and NativeDisplayDelegate creating
32 // the display controllers.)
33 if (it != controllers_.end()) {
34 LOG(WARNING) << "Display controller (crtc=" << crtc << ") already present.";
35 return;
36 }
37
38 controllers_.push_back(new HardwareDisplayController(
39 dri_, scoped_ptr<CrtcState>(new CrtcState(dri_, crtc, connector))));
40 }
41
27 void ScreenManager::RemoveDisplayController(uint32_t crtc) { 42 void ScreenManager::RemoveDisplayController(uint32_t crtc) {
28 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); 43 HardwareDisplayControllers::iterator it = FindDisplayController(crtc);
29 if (it != controllers_.end()) { 44 if (it != controllers_.end()) {
30 bool is_mirrored = (*it)->IsMirrored(); 45 bool is_mirrored = (*it)->IsMirrored();
31 (*it)->RemoveCrtc(crtc); 46 (*it)->RemoveCrtc(crtc);
32 if (!is_mirrored) 47 if (!is_mirrored)
33 controllers_.erase(it); 48 controllers_.erase(it);
34 } 49 }
35 } 50 }
36 51
37 bool ScreenManager::ConfigureDisplayController(uint32_t crtc, 52 bool ScreenManager::ConfigureDisplayController(uint32_t crtc,
38 uint32_t connector, 53 uint32_t connector,
39 const gfx::Point& origin, 54 const gfx::Point& origin,
40 const drmModeModeInfo& mode) { 55 const drmModeModeInfo& mode) {
41 gfx::Rect modeset_bounds( 56 gfx::Rect modeset_bounds(
42 origin.x(), origin.y(), mode.hdisplay, mode.vdisplay); 57 origin.x(), origin.y(), mode.hdisplay, mode.vdisplay);
43 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); 58 HardwareDisplayControllers::iterator it = FindDisplayController(crtc);
44 HardwareDisplayController* controller = NULL; 59 DCHECK(controllers_.end() != it) << "Display controller (crtc=" << crtc
45 if (it != controllers_.end()) { 60 << ") doesn't exist.";
46 controller = *it;
47 // If nothing changed just enable the controller. Note, we perform an exact
48 // comparison on the mode since the refresh rate may have changed.
49 if (SameMode(mode, controller->get_mode()) &&
50 origin == controller->origin() && !controller->IsDisabled())
51 return controller->Enable();
52 61
53 // Either the mode or the location of the display changed, so exit mirror 62 HardwareDisplayController* controller = *it;
54 // mode and configure the display independently. If the caller still wants 63 controller = *it;
55 // mirror mode, subsequent calls configuring the other controllers will 64 // If nothing changed just enable the controller. Note, we perform an exact
56 // restore mirror mode. 65 // comparison on the mode since the refresh rate may have changed.
57 if (controller->IsMirrored()) { 66 if (SameMode(mode, controller->get_mode()) &&
58 controller = 67 origin == controller->origin() && !controller->IsDisabled())
59 new HardwareDisplayController(dri_, controller->RemoveCrtc(crtc)); 68 return controller->Enable();
60 controllers_.push_back(controller);
61 it = --controllers_.end();
62 }
63 69
64 HardwareDisplayControllers::iterator mirror = 70 // Either the mode or the location of the display changed, so exit mirror
65 FindActiveDisplayControllerByLocation(modeset_bounds); 71 // mode and configure the display independently. If the caller still wants
66 // Handle mirror mode. 72 // mirror mode, subsequent calls configuring the other controllers will
67 if (mirror != controllers_.end() && it != mirror) 73 // restore mirror mode.
68 return HandleMirrorMode(it, mirror, crtc, connector); 74 if (controller->IsMirrored()) {
69 } else { 75 controller =
70 HardwareDisplayControllers::iterator mirror = 76 new HardwareDisplayController(dri_, controller->RemoveCrtc(crtc));
71 FindActiveDisplayControllerByLocation(modeset_bounds); 77 controllers_.push_back(controller);
72 if (mirror != controllers_.end()) { 78 it = controllers_.end() - 1;
73 (*mirror)->AddCrtc(
74 scoped_ptr<CrtcState>(new CrtcState(dri_, crtc, connector)));
75 return (*mirror)->Enable();
76 }
77 } 79 }
78 80
79 if (!controller) { 81 HardwareDisplayControllers::iterator mirror =
80 controller = new HardwareDisplayController( 82 FindActiveDisplayControllerByLocation(modeset_bounds);
81 dri_, 83 // Handle mirror mode.
82 scoped_ptr<CrtcState>(new CrtcState(dri_, crtc, connector))); 84 if (mirror != controllers_.end() && it != mirror)
83 controllers_.push_back(controller); 85 return HandleMirrorMode(it, mirror, crtc, connector);
84 }
85 86
86 return ModesetDisplayController(controller, origin, mode); 87 return ModesetDisplayController(controller, origin, mode);
87 } 88 }
88 89
89 bool ScreenManager::DisableDisplayController(uint32_t crtc) { 90 bool ScreenManager::DisableDisplayController(uint32_t crtc) {
90 HardwareDisplayControllers::iterator it = FindDisplayController(crtc); 91 HardwareDisplayControllers::iterator it = FindDisplayController(crtc);
91 if (it != controllers_.end()) { 92 if (it != controllers_.end()) {
92 if ((*it)->IsMirrored()) { 93 if ((*it)->IsMirrored()) {
93 HardwareDisplayController* controller = 94 HardwareDisplayController* controller =
94 new HardwareDisplayController(dri_, (*it)->RemoveCrtc(crtc)); 95 new HardwareDisplayController(dri_, (*it)->RemoveCrtc(crtc));
(...skipping 14 matching lines...) Expand all
109 // configuration reader and ScreenManager is called from there to create the 110 // configuration reader and ScreenManager is called from there to create the
110 // one display needed by the content_shell target. 111 // one display needed by the content_shell target.
111 if (controllers_.empty()) 112 if (controllers_.empty())
112 ForceInitializationOfPrimaryDisplay(); 113 ForceInitializationOfPrimaryDisplay();
113 114
114 HardwareDisplayControllers::iterator it = 115 HardwareDisplayControllers::iterator it =
115 FindActiveDisplayControllerByLocation(bounds); 116 FindActiveDisplayControllerByLocation(bounds);
116 if (it != controllers_.end()) 117 if (it != controllers_.end())
117 return (*it)->AsWeakPtr(); 118 return (*it)->AsWeakPtr();
118 119
120 // If no active controllers then pick the first controller at the location.
121 // TODO(dnicoara): Remove once async display configuration is fully supported.
122 it = FindDisplayControllerByLocation(bounds);
123 if (it != controllers_.end())
124 return (*it)->AsWeakPtr();
125
119 return base::WeakPtr<HardwareDisplayController>(); 126 return base::WeakPtr<HardwareDisplayController>();
120 } 127 }
121 128
122 ScreenManager::HardwareDisplayControllers::iterator 129 ScreenManager::HardwareDisplayControllers::iterator
123 ScreenManager::FindDisplayController(uint32_t crtc) { 130 ScreenManager::FindDisplayController(uint32_t crtc) {
124 for (HardwareDisplayControllers::iterator it = controllers_.begin(); 131 for (HardwareDisplayControllers::iterator it = controllers_.begin();
125 it != controllers_.end(); 132 it != controllers_.end();
126 ++it) { 133 ++it) {
127 if ((*it)->HasCrtc(crtc)) 134 if ((*it)->HasCrtc(crtc))
128 return it; 135 return it;
(...skipping 10 matching lines...) Expand all
139 gfx::Rect controller_bounds((*it)->origin(), (*it)->GetModeSize()); 146 gfx::Rect controller_bounds((*it)->origin(), (*it)->GetModeSize());
140 // We don't perform a strict check since content_shell will have windows 147 // We don't perform a strict check since content_shell will have windows
141 // smaller than the display size. 148 // smaller than the display size.
142 if (controller_bounds.Contains(bounds) && !(*it)->IsDisabled()) 149 if (controller_bounds.Contains(bounds) && !(*it)->IsDisabled())
143 return it; 150 return it;
144 } 151 }
145 152
146 return controllers_.end(); 153 return controllers_.end();
147 } 154 }
148 155
156 ScreenManager::HardwareDisplayControllers::iterator
157 ScreenManager::FindDisplayControllerByLocation(const gfx::Rect& bounds) {
158 for (HardwareDisplayControllers::iterator it = controllers_.begin();
159 it != controllers_.end();
160 ++it) {
161 gfx::Rect controller_bounds((*it)->origin(), (*it)->GetModeSize());
162 // We don't perform a strict check since content_shell will have windows
163 // smaller than the display size.
164 if (controller_bounds.Contains(bounds))
165 return it;
166 }
167
168 return controllers_.end();
169 }
170
149 void ScreenManager::ForceInitializationOfPrimaryDisplay() { 171 void ScreenManager::ForceInitializationOfPrimaryDisplay() {
150 LOG(WARNING) << "Forcing initialization of primary display."; 172 LOG(WARNING) << "Forcing initialization of primary display.";
151 ScopedVector<HardwareDisplayControllerInfo> displays = 173 ScopedVector<HardwareDisplayControllerInfo> displays =
152 GetAvailableDisplayControllerInfos(dri_->get_fd()); 174 GetAvailableDisplayControllerInfos(dri_->get_fd());
153 175
154 DCHECK_NE(0u, displays.size()); 176 DCHECK_NE(0u, displays.size());
155 177
156 ScopedDrmPropertyPtr dpms( 178 ScopedDrmPropertyPtr dpms(
157 dri_->GetProperty(displays[0]->connector(), "DPMS")); 179 dri_->GetProperty(displays[0]->connector(), "DPMS"));
158 if (dpms) 180 if (dpms)
159 dri_->SetProperty(displays[0]->connector()->connector_id, 181 dri_->SetProperty(displays[0]->connector()->connector_id,
160 dpms->prop_id, 182 dpms->prop_id,
161 DRM_MODE_DPMS_ON); 183 DRM_MODE_DPMS_ON);
162 184
185 AddDisplayController(displays[0]->crtc()->crtc_id,
186 displays[0]->connector()->connector_id);
163 ConfigureDisplayController(displays[0]->crtc()->crtc_id, 187 ConfigureDisplayController(displays[0]->crtc()->crtc_id,
164 displays[0]->connector()->connector_id, 188 displays[0]->connector()->connector_id,
165 gfx::Point(), 189 gfx::Point(),
166 displays[0]->connector()->modes[0]); 190 displays[0]->connector()->modes[0]);
167 } 191 }
168 192
169 bool ScreenManager::ModesetDisplayController( 193 bool ScreenManager::ModesetDisplayController(
170 HardwareDisplayController* controller, 194 HardwareDisplayController* controller,
171 const gfx::Point& origin, 195 const gfx::Point& origin,
172 const drmModeModeInfo& mode) { 196 const drmModeModeInfo& mode) {
(...skipping 30 matching lines...) Expand all
203 227
204 // When things go wrong revert back to the previous configuration since 228 // When things go wrong revert back to the previous configuration since
205 // it is expected that the configuration would not have changed if 229 // it is expected that the configuration would not have changed if
206 // things fail. 230 // things fail.
207 (*original)->AddCrtc((*mirror)->RemoveCrtc(crtc)); 231 (*original)->AddCrtc((*mirror)->RemoveCrtc(crtc));
208 (*original)->Enable(); 232 (*original)->Enable();
209 return false; 233 return false;
210 } 234 }
211 235
212 } // namespace ui 236 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/screen_manager.h ('k') | ui/ozone/platform/dri/screen_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698