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

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

Issue 469343003: [Ozone-GBM] Pumb DriWindowDelegate throughout the platform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 4 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 | Annotate | Revision Log
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 namespace { 19 namespace {
20 20
21 gfx::Size GetModeSize(const drmModeModeInfo& mode) { 21 gfx::Size GetModeSize(const drmModeModeInfo& mode) {
22 return gfx::Size(mode.hdisplay, mode.vdisplay); 22 return gfx::Size(mode.hdisplay, mode.vdisplay);
23 } 23 }
24 24
25 } // namespace 25 } // namespace
26 26
27 ScreenManager::ScreenManager( 27 ScreenManager::ScreenManager(DriWrapper* dri,
28 DriWrapper* dri, ScanoutBufferGenerator* buffer_generator) 28 ScanoutBufferGenerator* buffer_generator)
29 : dri_(dri), buffer_generator_(buffer_generator), last_added_widget_(0) { 29 : dri_(dri), buffer_generator_(buffer_generator) {
30 } 30 }
31 31
32 ScreenManager::~ScreenManager() { 32 ScreenManager::~ScreenManager() {
33 STLDeleteContainerPairSecondPointers(
34 controllers_.begin(), controllers_.end());
35 } 33 }
36 34
37 void ScreenManager::RemoveDisplayController(uint32_t crtc) { 35 void ScreenManager::RemoveDisplayController(uint32_t crtc) {
38 HardwareDisplayControllerMap::iterator it = FindDisplayController(crtc); 36 HardwareDisplayControllers::iterator it = FindDisplayController(crtc);
39 if (it != controllers_.end()) { 37 if (it != controllers_.end()) {
40 it->second->RemoveCrtc(crtc); 38 bool is_mirrored = (*it)->IsMirrored();
41 if (!it->second->HasCrtcs()) { 39 (*it)->RemoveCrtc(crtc);
42 delete it->second; 40 if (!is_mirrored)
43 controllers_.erase(it); 41 controllers_.erase(it);
44 }
45 } 42 }
46 } 43 }
47 44
48 bool ScreenManager::ConfigureDisplayController(uint32_t crtc, 45 bool ScreenManager::ConfigureDisplayController(uint32_t crtc,
49 uint32_t connector, 46 uint32_t connector,
50 const gfx::Point& origin, 47 const gfx::Point& origin,
51 const drmModeModeInfo& mode) { 48 const drmModeModeInfo& mode) {
52 HardwareDisplayControllerMap::iterator it = 49 gfx::Rect modeset_bounds(origin, GetModeSize(mode));
53 FindDisplayController(crtc); 50 HardwareDisplayControllers::iterator it = FindDisplayController(crtc);
54 HardwareDisplayController* controller = NULL; 51 HardwareDisplayController* controller = NULL;
55 if (it != controllers_.end()) { 52 if (it != controllers_.end()) {
56 // If nothing changed just enable the controller. 53 controller = *it;
57 if (SameMode(mode, it->second->get_mode()) && 54 // If nothing changed just enable the controller. Note, we perform an exact
58 origin == it->second->origin()) 55 // comparison on the mode since the refresh rate may have changed.
59 return it->second->Enable(); 56 if (SameMode(mode, controller->get_mode()) &&
57 origin == controller->origin() && !controller->IsDisabled())
58 return controller->Enable();
60 59
61 // Either the mode or the location of the display changed, so exit mirror 60 // Either the mode or the location of the display changed, so exit mirror
62 // mode and configure the display independently. If the caller still wants 61 // mode and configure the display independently. If the caller still wants
63 // mirror mode, subsequent calls configuring the other controllers will 62 // mirror mode, subsequent calls configuring the other controllers will
64 // restore mirror mode. 63 // restore mirror mode.
65 it->second->RemoveMirroredCrtcs(); 64 if (controller->IsMirrored()) {
66 HardwareDisplayControllerMap::iterator mirror = 65 controller =
67 FindDisplayControllerByOrigin(origin); 66 new HardwareDisplayController(dri_, controller->RemoveCrtc(crtc));
68 // Handle mirror mode. 67 controllers_.push_back(controller);
69 if (mirror != controllers_.end() && it != mirror) { 68 it = --controllers_.end();
70 DCHECK(SameMode(mode, mirror->second->get_mode()));
71 return HandleMirrorMode(it, mirror, crtc, connector);
72 } 69 }
73 70
74 controller = it->second; 71 HardwareDisplayControllers::iterator mirror =
72 FindActiveDisplayControllerByLocation(modeset_bounds);
73 // Handle mirror mode.
74 if (mirror != controllers_.end() && it != mirror)
75 return HandleMirrorMode(it, mirror, crtc, connector);
75 } else { 76 } else {
76 HardwareDisplayControllerMap::iterator mirror = 77 HardwareDisplayControllers::iterator mirror =
77 FindDisplayControllerByOrigin(origin); 78 FindActiveDisplayControllerByLocation(modeset_bounds);
78 if (mirror != controllers_.end()) { 79 if (mirror != controllers_.end()) {
79 mirror->second->AddCrtc(scoped_ptr<CrtcState>( 80 (*mirror)->AddCrtc(
80 new CrtcState(dri_, crtc, connector))); 81 scoped_ptr<CrtcState>(new CrtcState(dri_, crtc, connector)));
81 return mirror->second->Enable(); 82 return (*mirror)->Enable();
82 } 83 }
83 } 84 }
84 85
85 if (!controller) { 86 if (!controller) {
86 controller = new HardwareDisplayController( 87 controller = new HardwareDisplayController(
87 dri_, 88 dri_,
88 scoped_ptr<CrtcState>(new CrtcState(dri_, crtc, connector))); 89 scoped_ptr<CrtcState>(new CrtcState(dri_, crtc, connector)));
89 controllers_.insert(std::make_pair(++last_added_widget_, controller)); 90 controllers_.push_back(controller);
90 } 91 }
91 92
92 return ModesetDisplayController(controller, origin, mode); 93 return ModesetDisplayController(controller, origin, mode);
93 } 94 }
94 95
95 bool ScreenManager::DisableDisplayController(uint32_t crtc) { 96 bool ScreenManager::DisableDisplayController(uint32_t crtc) {
96 HardwareDisplayControllerMap::iterator it = FindDisplayController(crtc); 97 HardwareDisplayControllers::iterator it = FindDisplayController(crtc);
97 if (it != controllers_.end()) { 98 if (it != controllers_.end()) {
98 it->second->Disable(); 99 if ((*it)->IsMirrored()) {
100 HardwareDisplayController* controller =
101 new HardwareDisplayController(dri_, (*it)->RemoveCrtc(crtc));
102 controllers_.push_back(controller);
103 }
104
105 (*it)->Disable();
99 return true; 106 return true;
100 } 107 }
101 108
102 LOG(ERROR) << "Failed to find display controller" 109 LOG(ERROR) << "Failed to find display controller crtc=" << crtc;
103 << " crtc=" << crtc;
104 return false; 110 return false;
105 } 111 }
106 112
107 base::WeakPtr<HardwareDisplayController> ScreenManager::GetDisplayController( 113 base::WeakPtr<HardwareDisplayController> ScreenManager::GetDisplayController(
108 gfx::AcceleratedWidget widget) {
109 // TODO(dnicoara): Remove hack once TestScreen uses a simple Ozone display
110 // configuration reader and ScreenManager is called from there to create the
111 // one display needed by the content_shell target.
112 if (controllers_.empty() && last_added_widget_ == 0)
113 ForceInitializationOfPrimaryDisplay();
114
115 HardwareDisplayControllerMap::iterator it = controllers_.find(widget);
116 if (it != controllers_.end())
117 return it->second->AsWeakPtr();
118
119 return base::WeakPtr<HardwareDisplayController>();
120 }
121
122 base::WeakPtr<HardwareDisplayController> ScreenManager::GetDisplayController(
123 const gfx::Rect& bounds) { 114 const gfx::Rect& bounds) {
124 // TODO(dnicoara): Remove hack once TestScreen uses a simple Ozone display 115 // TODO(dnicoara): Remove hack once TestScreen uses a simple Ozone display
125 // configuration reader and ScreenManager is called from there to create the 116 // configuration reader and ScreenManager is called from there to create the
126 // one display needed by the content_shell target. 117 // one display needed by the content_shell target.
127 if (controllers_.empty()) 118 if (controllers_.empty())
128 ForceInitializationOfPrimaryDisplay(); 119 ForceInitializationOfPrimaryDisplay();
129 120
130 HardwareDisplayControllerMap::iterator it = 121 HardwareDisplayControllers::iterator it =
131 FindActiveDisplayControllerByLocation(bounds); 122 FindActiveDisplayControllerByLocation(bounds);
132 if (it != controllers_.end()) 123 if (it != controllers_.end())
133 return it->second->AsWeakPtr(); 124 return (*it)->AsWeakPtr();
134 125
135 return base::WeakPtr<HardwareDisplayController>(); 126 return base::WeakPtr<HardwareDisplayController>();
136 } 127 }
137 128
138 ScreenManager::HardwareDisplayControllerMap::iterator 129 ScreenManager::HardwareDisplayControllers::iterator
139 ScreenManager::FindDisplayController(uint32_t crtc) { 130 ScreenManager::FindDisplayController(uint32_t crtc) {
140 for (HardwareDisplayControllerMap::iterator it = controllers_.begin(); 131 for (HardwareDisplayControllers::iterator it = controllers_.begin();
141 it != controllers_.end(); 132 it != controllers_.end();
142 ++it) { 133 ++it) {
143 if (it->second->HasCrtc(crtc)) 134 if ((*it)->HasCrtc(crtc))
144 return it; 135 return it;
145 } 136 }
146 137
147 return controllers_.end(); 138 return controllers_.end();
148 } 139 }
149 140
150 ScreenManager::HardwareDisplayControllerMap::iterator 141 ScreenManager::HardwareDisplayControllers::iterator
151 ScreenManager::FindDisplayControllerByOrigin(const gfx::Point& origin) { 142 ScreenManager::FindActiveDisplayControllerByLocation(const gfx::Rect& bounds) {
152 for (HardwareDisplayControllerMap::iterator it = controllers_.begin(); 143 for (HardwareDisplayControllers::iterator it = controllers_.begin();
153 it != controllers_.end(); 144 it != controllers_.end();
154 ++it) { 145 ++it) {
155 if (it->second->origin() == origin) 146 gfx::Rect controller_bounds((*it)->origin(),
147 GetModeSize((*it)->get_mode()));
148 // We don't perform a strict check since content_shell will have windows
149 // smaller than the display size.
150 if (controller_bounds.Contains(bounds) && !(*it)->IsDisabled())
156 return it; 151 return it;
157 } 152 }
158 153
159 return controllers_.end();
160 }
161
162 ScreenManager::HardwareDisplayControllerMap::iterator
163 ScreenManager::FindActiveDisplayControllerByLocation(const gfx::Rect& bounds) {
164 for (HardwareDisplayControllerMap::iterator it = controllers_.begin();
165 it != controllers_.end();
166 ++it) {
167 gfx::Rect controller_bounds(it->second->origin(),
168 GetModeSize(it->second->get_mode()));
169 // We don't perform a strict check since content_shell will have windows
170 // smaller than the display size.
171 if (controller_bounds.Contains(bounds))
172 return it;
173 }
174
175 return controllers_.end(); 154 return controllers_.end();
176 } 155 }
177 156
178 void ScreenManager::ForceInitializationOfPrimaryDisplay() { 157 void ScreenManager::ForceInitializationOfPrimaryDisplay() {
158 LOG(WARNING) << "Forcing initialization of primary display.";
179 ScopedVector<HardwareDisplayControllerInfo> displays = 159 ScopedVector<HardwareDisplayControllerInfo> displays =
180 GetAvailableDisplayControllerInfos(dri_->get_fd()); 160 GetAvailableDisplayControllerInfos(dri_->get_fd());
181 161
182 DCHECK_NE(0u, displays.size()); 162 DCHECK_NE(0u, displays.size());
183 163
184 ScopedDrmPropertyPtr dpms( 164 ScopedDrmPropertyPtr dpms(
185 dri_->GetProperty(displays[0]->connector(), "DPMS")); 165 dri_->GetProperty(displays[0]->connector(), "DPMS"));
186 if (dpms) 166 if (dpms)
187 dri_->SetProperty(displays[0]->connector()->connector_id, 167 dri_->SetProperty(displays[0]->connector()->connector_id,
188 dpms->prop_id, 168 dpms->prop_id,
(...skipping 21 matching lines...) Expand all
210 190
211 if (!controller->Modeset(OverlayPlane(buffer), mode)) { 191 if (!controller->Modeset(OverlayPlane(buffer), mode)) {
212 LOG(ERROR) << "Failed to modeset controller"; 192 LOG(ERROR) << "Failed to modeset controller";
213 return false; 193 return false;
214 } 194 }
215 195
216 return true; 196 return true;
217 } 197 }
218 198
219 bool ScreenManager::HandleMirrorMode( 199 bool ScreenManager::HandleMirrorMode(
220 HardwareDisplayControllerMap::iterator original, 200 HardwareDisplayControllers::iterator original,
221 HardwareDisplayControllerMap::iterator mirror, 201 HardwareDisplayControllers::iterator mirror,
222 uint32_t crtc, 202 uint32_t crtc,
223 uint32_t connector) { 203 uint32_t connector) {
224 mirror->second->AddCrtc(original->second->RemoveCrtc(crtc)); 204 (*mirror)->AddCrtc((*original)->RemoveCrtc(crtc));
225 if (mirror->second->Enable()) { 205 if ((*mirror)->Enable()) {
226 delete original->second;
227 controllers_.erase(original); 206 controllers_.erase(original);
228 return true; 207 return true;
229 } 208 }
230 209
231 LOG(ERROR) << "Failed to switch to mirror mode"; 210 LOG(ERROR) << "Failed to switch to mirror mode";
232 211
233 // When things go wrong revert back to the previous configuration since 212 // When things go wrong revert back to the previous configuration since
234 // it is expected that the configuration would not have changed if 213 // it is expected that the configuration would not have changed if
235 // things fail. 214 // things fail.
236 original->second->AddCrtc(mirror->second->RemoveCrtc(crtc)); 215 (*original)->AddCrtc((*mirror)->RemoveCrtc(crtc));
237 original->second->Enable(); 216 (*original)->Enable();
238 return false; 217 return false;
239 } 218 }
240 219
241 } // namespace ui 220 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698