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

Side by Side Diff: services/ui/display/screen_manager_ozone.cc

Issue 2476663003: PlatformScreenOzone using DisplayManager (Closed)
Patch Set: Cleanup. Created 4 years 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/ui/display/screen_manager_ozone.h" 5 #include "services/ui/display/screen_manager_ozone.h"
6 6
7 #include <memory> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/sys_info.h" 12 #include "base/sys_info.h"
13 #include "base/threading/thread_task_runner_handle.h" 13 #include "base/threading/thread_task_runner_handle.h"
14 #include "services/service_manager/public/cpp/interface_registry.h" 14 #include "services/service_manager/public/cpp/interface_registry.h"
15 #include "third_party/skia/include/core/SkColor.h" 15 #include "third_party/skia/include/core/SkColor.h"
16 #include "ui/display/manager/chromeos/display_change_observer.h"
17 #include "ui/display/manager/display_layout_store.h"
18 #include "ui/display/manager/display_manager_utilities.h"
19 #include "ui/display/screen.h"
20 #include "ui/display/screen_base.h"
16 #include "ui/display/types/display_snapshot.h" 21 #include "ui/display/types/display_snapshot.h"
22 #include "ui/display/types/fake_display_controller.h"
17 #include "ui/display/types/native_display_delegate.h" 23 #include "ui/display/types/native_display_delegate.h"
18 #include "ui/gfx/geometry/rect.h" 24 #include "ui/gfx/geometry/rect.h"
19 #include "ui/ozone/public/ozone_platform.h" 25 #include "ui/ozone/public/ozone_platform.h"
20 26
21 namespace display { 27 namespace display {
22 namespace { 28 namespace {
23 29
24 // Needed for DisplayConfigurator::ForceInitialConfigure. 30 // Needed for DisplayConfigurator::ForceInitialConfigure.
25 const SkColor kChromeOsBootColor = SkColorSetRGB(0xfe, 0xfe, 0xfe); 31 const SkColor kChromeOsBootColor = SkColorSetRGB(0xfe, 0xfe, 0xfe);
26 32
27 const float kInchInMm = 25.4f; 33 // Recursively swaps the displays in a DisplayLayout to change the primary
34 // display but keep the same relative display layout.
35 // TODO(kylechar): This is copied from WTHM. The concept of getting the same
msw 2016/12/19 20:02:52 nit: Try to avoid acronyms (ditto for NDD below, a
kylechar 2016/12/20 15:19:46 Done.
36 // relative display layout with a different primary display id should become a
37 // function on DisplayLayout itself to avoid reimplementing it here.
38 void SwapRecursive(const std::map<int64_t, DisplayPlacement*>& id_to_placement,
39 int64_t current_primary_id,
40 int64_t display_id) {
41 if (display_id == current_primary_id)
42 return;
28 43
29 float ComputeDisplayDPI(const gfx::Size& pixel_size, 44 DCHECK(id_to_placement.count(display_id));
30 const gfx::Size& physical_size) { 45 DisplayPlacement* placement = id_to_placement.at(display_id);
31 // The physical_size is broken for some devices, return standard DPI. See 46 DCHECK(placement);
32 // crbug.com/669554. 47 SwapRecursive(id_to_placement, current_primary_id,
33 if (physical_size.IsEmpty()) { 48 placement->parent_display_id);
34 LOG(ERROR) << "Display has empty phsical_size"; 49 placement->Swap();
35 return 96.0f;
36 }
37
38 return (pixel_size.width() / static_cast<float>(physical_size.width())) *
39 kInchInMm;
40 }
41
42 // Finds the device scale factor based on the display DPI. Will use forced
43 // device scale factor if provided via command line.
44 float FindDeviceScaleFactor(float dpi) {
45 if (Display::HasForceDeviceScaleFactor())
46 return Display::GetForcedDeviceScaleFactor();
47
48 // TODO(kylechar): If dpi > 150 then ash uses 1.25 now. Ignoring that for now.
49 if (dpi > 200.0)
50 return 2.0f;
51 else
52 return 1.0f;
53 } 50 }
54 51
55 } // namespace 52 } // namespace
56 53
57 // static 54 // static
58 std::unique_ptr<ScreenManager> ScreenManager::Create() { 55 std::unique_ptr<ScreenManager> ScreenManager::Create() {
59 return base::MakeUnique<ScreenManagerOzone>(); 56 return base::MakeUnique<ScreenManagerOzone>();
60 } 57 }
61 58
62 ScreenManagerOzone::ScreenManagerOzone() {} 59 ScreenManagerOzone::ScreenManagerOzone() {}
63 60
64 ScreenManagerOzone::~ScreenManagerOzone() { 61 ScreenManagerOzone::~ScreenManagerOzone() {
65 // We are shutting down and don't want to make anymore display changes. 62 // We are shutting down and don't want to make anymore display changes.
66 fake_display_controller_ = nullptr; 63 fake_display_controller_ = nullptr;
67 display_configurator_.RemoveObserver(this); 64
65 if (display_manager_)
66 display_manager_->RemoveObserver(this);
67
68 if (display_change_observer_) {
69 display_configurator_.RemoveObserver(display_change_observer_.get());
70 display_change_observer_.reset();
71 }
72
73 if (display_manager_)
74 display_manager_.reset();
75 }
76
77 void ScreenManagerOzone::SetPrimaryDisplayId(int64_t display_id) {
78 DCHECK_NE(kInvalidDisplayId, display_id);
79 if (primary_display_id_ == display_id)
80 return;
81
82 const Display& new_primary_display =
83 display_manager_->GetDisplayForId(display_id);
84 if (!new_primary_display.is_valid()) {
85 LOG(ERROR) << "Invalid or non-existent display is requested:"
86 << new_primary_display.ToString();
87 return;
88 }
89
90 int64_t old_primary_display_id = primary_display_id_;
91
92 const DisplayLayout& layout = display_manager_->GetCurrentDisplayLayout();
93 // The requested primary id can be same as one in the stored layout
94 // when the primary id is set after new displays are connected.
95 // Only update the layout if it is requested to swap primary display.
96 if (layout.primary_id != new_primary_display.id()) {
97 std::unique_ptr<DisplayLayout> swapped_layout(layout.Copy());
98
99 std::map<int64_t, DisplayPlacement*> id_to_placement;
100 for (auto& placement : swapped_layout->placement_list)
101 id_to_placement[placement.display_id] = &placement;
102 SwapRecursive(id_to_placement, primary_display_id_,
103 new_primary_display.id());
104
105 std::sort(swapped_layout->placement_list.begin(),
106 swapped_layout->placement_list.end(),
107 [](const DisplayPlacement& d1, const DisplayPlacement& d2) {
108 return d1.display_id < d2.display_id;
109 });
110
111 swapped_layout->primary_id = new_primary_display.id();
112 DisplayIdList list = display_manager_->GetCurrentDisplayIdList();
113 display_manager_->layout_store()->RegisterLayoutForDisplayIdList(
114 list, std::move(swapped_layout));
115 }
116
117 primary_display_id_ = new_primary_display.id();
118 screen_->display_list().UpdateDisplay(new_primary_display,
119 DisplayList::Type::PRIMARY);
120
121 // Force updating display bounds for new primary display.
122 display_manager_->set_force_bounds_changed(true);
123 display_manager_->UpdateDisplays();
124 display_manager_->set_force_bounds_changed(false);
125
126 DVLOG(1) << "Primary display changed from " << old_primary_display_id
127 << " to " << primary_display_id_;
128 delegate_->OnPrimaryDisplayChanged(primary_display_id_);
68 } 129 }
69 130
70 void ScreenManagerOzone::AddInterfaces( 131 void ScreenManagerOzone::AddInterfaces(
71 service_manager::InterfaceRegistry* registry) { 132 service_manager::InterfaceRegistry* registry) {
72 registry->AddInterface<mojom::DisplayController>(this); 133 registry->AddInterface<mojom::DisplayController>(this);
73 registry->AddInterface<mojom::TestDisplayController>(this); 134 registry->AddInterface<mojom::TestDisplayController>(this);
74 } 135 }
75 136
76 void ScreenManagerOzone::Init(ScreenManagerDelegate* delegate) { 137 void ScreenManagerOzone::Init(ScreenManagerDelegate* delegate) {
77 DCHECK(delegate); 138 DCHECK(delegate);
78 delegate_ = delegate; 139 delegate_ = delegate;
79 140
80 std::unique_ptr<ui::NativeDisplayDelegate> native_display_delegate = 141 // Tests may inject a NDD, otherwise get it from OzonePlatform.
81 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); 142 if (!native_display_delegate_) {
143 native_display_delegate_ =
144 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate();
145 }
82 146
83 // The FakeDisplayController gives us a way to make the NativeDisplayDelegate 147 // The FakeDisplayController gives us a way to make the NativeDisplayDelegate
84 // pretend something display related has happened. 148 // pretend something display related has happened.
85 if (!base::SysInfo::IsRunningOnChromeOS()) { 149 if (!base::SysInfo::IsRunningOnChromeOS()) {
86 fake_display_controller_ = 150 fake_display_controller_ =
87 native_display_delegate->GetFakeDisplayController(); 151 native_display_delegate_->GetFakeDisplayController();
88 } 152 }
89 153
154 // Create a new Screen instance.
155 std::unique_ptr<ScreenBase> screen = base::MakeUnique<ScreenBase>();
156 Screen::SetScreenInstance(screen.get());
157 screen_ = screen.get();
158
159 // Configure display manager. ScreenManager acts as an observer to find out
160 // display changes and as a delegate to find out when changes start/stop.
161 display_manager_ = base::MakeUnique<DisplayManager>(std::move(screen));
162 display_manager_->set_configure_displays(true);
163 display_manager_->AddObserver(this);
164 display_manager_->set_delegate(this);
165
166 // DisplayChangeObserver observes DisplayConfigurator and sends updates to
167 // DisplayManager.
168 display_change_observer_ = base::MakeUnique<DisplayChangeObserver>(
169 &display_configurator_, display_manager_.get());
170
90 // We want display configuration to happen even off device to keep the control 171 // We want display configuration to happen even off device to keep the control
91 // flow similar. 172 // flow similar.
92 display_configurator_.set_configure_display(true); 173 display_configurator_.set_configure_display(true);
93 display_configurator_.AddObserver(this); 174 display_configurator_.AddObserver(display_change_observer_.get());
94 display_configurator_.set_state_controller(this); 175 display_configurator_.set_state_controller(display_change_observer_.get());
95 display_configurator_.Init(std::move(native_display_delegate), false); 176 display_configurator_.set_mirroring_controller(display_manager_.get());
177
178 // Perform initial configuration.
179 display_configurator_.Init(std::move(native_display_delegate_), false);
96 display_configurator_.ForceInitialConfigure(kChromeOsBootColor); 180 display_configurator_.ForceInitialConfigure(kChromeOsBootColor);
97 } 181 }
98 182
99 void ScreenManagerOzone::RequestCloseDisplay(int64_t display_id) { 183 void ScreenManagerOzone::RequestCloseDisplay(int64_t display_id) {
100 if (!fake_display_controller_ || wait_for_display_config_update_) 184 if (!fake_display_controller_)
101 return; 185 return;
102 186
103 CachedDisplayIterator iter = GetCachedDisplayIterator(display_id); 187 // Tell the NDD to remove the display. ScreenManager will get an update
104 if (iter != cached_displays_.end()) { 188 // that the display configuration has changed and the display will be gone.
105 // Tell the NDD to remove the display. ScreenManager will get an update 189 fake_display_controller_->RemoveDisplay(display_id);
106 // that the display configuration has changed and the display will be gone.
107 wait_for_display_config_update_ =
108 fake_display_controller_->RemoveDisplay(iter->id);
109 }
110 } 190 }
111 191
112 int64_t ScreenManagerOzone::GetPrimaryDisplayId() const { 192 int64_t ScreenManagerOzone::GetPrimaryDisplayId() const {
113 return primary_display_id_; 193 return primary_display_id_;
114 } 194 }
115 195
116 void ScreenManagerOzone::ToggleAddRemoveDisplay() { 196 void ScreenManagerOzone::ToggleAddRemoveDisplay() {
117 if (!fake_display_controller_ || wait_for_display_config_update_) 197 if (!fake_display_controller_)
118 return; 198 return;
199 DVLOG(1) << "ToggleAddRemoveDisplay";
119 200
120 if (cached_displays_.size() == 1) { 201 int num_displays = display_manager_->GetNumDisplays();
121 const gfx::Size& pixel_size = cached_displays_[0].metrics.pixel_size; 202 if (num_displays == 1) {
122 wait_for_display_config_update_ = 203 const gfx::Size& pixel_size =
123 fake_display_controller_->AddDisplay(pixel_size) != kInvalidDisplayId; 204 display_manager_->GetDisplayInfo(display_manager_->GetDisplayAt(0).id())
124 } else if (cached_displays_.size() > 1) { 205 .bounds_in_native()
125 wait_for_display_config_update_ = 206 .size();
126 fake_display_controller_->RemoveDisplay(cached_displays_.back().id); 207 fake_display_controller_->AddDisplay(pixel_size);
127 } else { 208 } else if (num_displays > 1) {
128 NOTREACHED(); 209 DisplayIdList displays = display_manager_->GetCurrentDisplayIdList();
210 fake_display_controller_->RemoveDisplay(displays.back());
129 } 211 }
130 } 212 }
131 213
132 void ScreenManagerOzone::ToggleDisplayResolution() { 214 void ScreenManagerOzone::ToggleDisplayResolution() {
133 DisplayInfo& display = cached_displays_[0]; 215 if (primary_display_id_ == kInvalidDisplayId)
216 return;
134 217
135 // Toggle the display size to use. 218 // Internal displays don't have alternate resolutions.
136 size_t num_sizes = display.supported_sizes.size(); 219 if (Display::HasInternalDisplay() &&
137 for (size_t i = 0; i < num_sizes; i++) { 220 primary_display_id_ == Display::InternalDisplayId())
138 if (display.supported_sizes[i] == display.requested_size) { 221 return;
139 if (i + 1 == num_sizes)
140 display.requested_size = display.supported_sizes[0];
141 else
142 display.requested_size = display.supported_sizes[i + 1];
143 break;
144 }
145 }
146 222
147 display_configurator_.OnConfigurationChanged(); 223 DVLOG(1) << "ToggleDisplayResolution";
224
225 const ManagedDisplayInfo& info =
226 display_manager_->GetDisplayInfo(primary_display_id_);
227 scoped_refptr<ManagedDisplayMode> mode =
228 GetDisplayModeForNextResolution(info, true);
229
230 // Loop back to first mode from last.
231 if (mode->size() == info.bounds_in_native().size())
232 mode = info.display_modes()[0];
233
234 // Set mode only if it's different from current.
235 if (mode->size() != info.bounds_in_native().size())
236 display_manager_->SetDisplayMode(primary_display_id_, mode);
148 } 237 }
149 238
150 void ScreenManagerOzone::IncreaseInternalDisplayZoom() { 239 void ScreenManagerOzone::IncreaseInternalDisplayZoom() {
151 NOTIMPLEMENTED(); 240 if (Display::HasInternalDisplay())
241 display_manager_->ZoomInternalDisplay(false);
152 } 242 }
153 243
154 void ScreenManagerOzone::DecreaseInternalDisplayZoom() { 244 void ScreenManagerOzone::DecreaseInternalDisplayZoom() {
155 NOTIMPLEMENTED(); 245 if (Display::HasInternalDisplay())
246 display_manager_->ZoomInternalDisplay(true);
156 } 247 }
157 248
158 void ScreenManagerOzone::ResetInternalDisplayZoom() { 249 void ScreenManagerOzone::ResetInternalDisplayZoom() {
159 NOTIMPLEMENTED(); 250 if (Display::HasInternalDisplay())
251 display_manager_->ResetInternalDisplayZoom();
160 } 252 }
161 253
162 void ScreenManagerOzone::RotateCurrentDisplayCW() { 254 void ScreenManagerOzone::RotateCurrentDisplayCW() {
163 NOTIMPLEMENTED(); 255 NOTIMPLEMENTED();
164 } 256 }
165 257
166 void ScreenManagerOzone::SwapPrimaryDisplay() { 258 void ScreenManagerOzone::SwapPrimaryDisplay() {
167 const size_t num_displays = cached_displays_.size(); 259 // Can't swap if there is only 1 display and swapping isn't supported for 3 or
168 if (num_displays <= 1) 260 // more displays.
261 if (display_manager_->GetNumDisplays() != 2)
169 return; 262 return;
170 263
171 // Find index of current primary display. 264 DVLOG(1) << "SwapPrimaryDisplay()";
172 size_t primary_display_index = 0;
173 for (size_t i = 0; i < num_displays; i++) {
174 if (cached_displays_[i].id == primary_display_id_) {
175 primary_display_index = i;
176 break;
177 }
178 }
179 265
180 // Set next display index as primary, or loop back to first display if last. 266 DisplayIdList display_ids = display_manager_->GetCurrentDisplayIdList();
181 if (primary_display_index + 1 == num_displays) {
182 primary_display_id_ = cached_displays_[0].id;
183 } else {
184 primary_display_id_ = cached_displays_[primary_display_index + 1].id;
185 }
186 267
187 delegate_->OnPrimaryDisplayChanged(primary_display_id_); 268 // Find the next primary display.
269 if (primary_display_id_ == display_ids[0])
270 SetPrimaryDisplayId(display_ids[1]);
271 else
272 SetPrimaryDisplayId(display_ids[0]);
188 } 273 }
189 274
190 void ScreenManagerOzone::ToggleMirrorMode() { 275 void ScreenManagerOzone::ToggleMirrorMode() {
191 NOTIMPLEMENTED(); 276 NOTIMPLEMENTED();
192 } 277 }
193 278
194 void ScreenManagerOzone::SetDisplayWorkArea(int64_t display_id, 279 void ScreenManagerOzone::SetDisplayWorkArea(int64_t display_id,
195 const gfx::Size& size, 280 const gfx::Size& size,
196 const gfx::Insets& insets) { 281 const gfx::Insets& insets) {
197 CachedDisplayIterator iter = GetCachedDisplayIterator(display_id); 282 // TODO(kylechar): Check the size of the display matches the current size.
198 if (iter == cached_displays_.end()) { 283 display_manager_->UpdateWorkAreaOfDisplay(display_id, insets);
199 NOTREACHED() << display_id;
200 return;
201 }
202
203 DisplayInfo& display_info = *iter;
204 if (display_info.metrics.bounds.size() == size) {
205 gfx::Rect new_work_area = display_info.metrics.bounds;
206 new_work_area.Inset(insets);
207
208 if (new_work_area != display_info.metrics.work_area) {
209 display_info.last_work_area_insets = insets;
210 display_info.metrics.work_area = new_work_area;
211 display_info.modified = true;
212 UpdateCachedDisplays();
213 }
214 }
215 }
216
217 ScreenManagerOzone::DisplayInfo::DisplayInfo() = default;
218 ScreenManagerOzone::DisplayInfo::DisplayInfo(const DisplayInfo& other) =
219 default;
220 ScreenManagerOzone::DisplayInfo::~DisplayInfo() = default;
221
222 void ScreenManagerOzone::ProcessRemovedDisplays(
223 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
224 std::vector<int64_t> current_ids;
225 for (ui::DisplaySnapshot* snapshot : snapshots)
226 current_ids.push_back(snapshot->display_id());
227
228 // Find cached displays with no matching snapshot and mark as removed.
229 for (DisplayInfo& display : cached_displays_) {
230 if (std::find(current_ids.begin(), current_ids.end(), display.id) ==
231 current_ids.end()) {
232 display.removed = true;
233 if (primary_display_id_ == display.id)
234 primary_display_id_ = kInvalidDisplayId;
235 }
236 }
237 }
238
239 void ScreenManagerOzone::ProcessModifiedDisplays(
240 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
241 for (ui::DisplaySnapshot* snapshot : snapshots) {
242 auto iter = GetCachedDisplayIterator(snapshot->display_id());
243 if (iter != cached_displays_.end()) {
244 DisplayInfo& display_info = *iter;
245 ViewportMetrics new_metrics =
246 MetricsFromSnapshot(*snapshot, display_info.metrics.bounds.origin());
247 new_metrics.work_area.Inset(display_info.last_work_area_insets);
248
249 if (new_metrics != display_info.metrics) {
250 display_info.metrics = new_metrics;
251 display_info.modified = true;
252 }
253 }
254 }
255 }
256
257 void ScreenManagerOzone::UpdateCachedDisplays() {
258 // Walk through cached displays after processing the snapshots to find any
259 // removed or modified displays. This ensures that we only send one update per
260 // display to the delegate.
261 next_display_origin_.SetPoint(0, 0);
262 for (auto iter = cached_displays_.begin(); iter != cached_displays_.end();) {
263 DisplayInfo& display_info = *iter;
264 if (display_info.removed) {
265 // Update delegate and remove from cache.
266 delegate_->OnDisplayRemoved(display_info.id);
267 iter = cached_displays_.erase(iter);
268 } else {
269 // Check if the display origin needs to be updated.
270 if (next_display_origin_ != display_info.metrics.bounds.origin()) {
271 display_info.metrics.bounds.set_origin(next_display_origin_);
272 display_info.metrics.work_area.set_origin(next_display_origin_);
273 display_info.modified = true;
274 }
275 next_display_origin_.Offset(display_info.metrics.bounds.width(), 0);
276
277 // Check if the window bounds have changed and update delegate.
278 if (display_info.modified) {
279 display_info.modified = false;
280 delegate_->OnDisplayModified(display_info.id, display_info.metrics);
281 }
282 ++iter;
283 }
284 }
285 }
286
287 void ScreenManagerOzone::AddNewDisplays(
288 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
289 for (ui::DisplaySnapshot* snapshot : snapshots) {
290 const int64_t id = snapshot->display_id();
291
292 // Check if display already exists and skip.
293 if (GetCachedDisplayIterator(id) != cached_displays_.end())
294 continue;
295
296 DisplayInfo display_info;
297 display_info.id = snapshot->display_id();
298 display_info.metrics = MetricsFromSnapshot(*snapshot, next_display_origin_);
299
300 // Store the display mode sizes so we can toggle through them.
301 for (auto& mode : snapshot->modes()) {
302 display_info.supported_sizes.push_back(mode->size());
303 if (mode.get() == snapshot->current_mode())
304 display_info.requested_size = mode->size();
305 }
306
307 // Move the origin so that next display is to the right of current display.
308 next_display_origin_.Offset(display_info.metrics.bounds.width(), 0);
309
310 cached_displays_.push_back(display_info);
311 delegate_->OnDisplayAdded(display_info.id, display_info.metrics);
312
313 // If we have no primary display then this one should be it.
314 if (primary_display_id_ == kInvalidDisplayId) {
315 primary_display_id_ = id;
316 delegate_->OnPrimaryDisplayChanged(primary_display_id_);
317 }
318 }
319 }
320
321 ScreenManagerOzone::CachedDisplayIterator
322 ScreenManagerOzone::GetCachedDisplayIterator(int64_t display_id) {
323 return std::find_if(cached_displays_.begin(), cached_displays_.end(),
324 [display_id](const DisplayInfo& display_info) {
325 return display_info.id == display_id;
326 });
327 }
328
329 ViewportMetrics ScreenManagerOzone::MetricsFromSnapshot(
330 const ui::DisplaySnapshot& snapshot,
331 const gfx::Point& origin) {
332 const ui::DisplayMode* current_mode = snapshot.current_mode();
333 DCHECK(current_mode);
334
335 ViewportMetrics metrics;
336 metrics.pixel_size = current_mode->size();
337 metrics.device_scale_factor = FindDeviceScaleFactor(
338 ComputeDisplayDPI(current_mode->size(), snapshot.physical_size()));
339 // Get DIP size based on device scale factor. We are assuming the
340 // ui scale factor is always 1.0 here for now.
341 gfx::Size scaled_size = gfx::ScaleToRoundedSize(
342 current_mode->size(), 1.0f / metrics.device_scale_factor);
343 metrics.bounds = gfx::Rect(origin, scaled_size);
344 metrics.work_area = metrics.bounds;
345 return metrics;
346 }
347
348 void ScreenManagerOzone::OnDisplayModeChanged(
349 const ui::DisplayConfigurator::DisplayStateList& displays) {
350 ProcessRemovedDisplays(displays);
351 ProcessModifiedDisplays(displays);
352
353 // If the primary display is marked as removed we'll try to find a new primary
354 // display and update the delegate before removing the old primary display.
355 if (primary_display_id_ == kInvalidDisplayId) {
356 for (const DisplayInfo& display : cached_displays_) {
357 if (!display.removed) {
358 primary_display_id_ = display.id;
359 delegate_->OnPrimaryDisplayChanged(primary_display_id_);
360 break;
361 }
362 }
363 }
364
365 UpdateCachedDisplays();
366 AddNewDisplays(displays);
367
368 wait_for_display_config_update_ = false;
369 }
370
371 void ScreenManagerOzone::OnDisplayModeChangeFailed(
372 const ui::DisplayConfigurator::DisplayStateList& displays,
373 ui::MultipleDisplayState failed_new_state) {
374 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator";
375 wait_for_display_config_update_ = false;
376 } 284 }
377 285
378 void ScreenManagerOzone::Create( 286 void ScreenManagerOzone::Create(
379 const service_manager::Identity& remote_identity, 287 const service_manager::Identity& remote_identity,
380 mojom::DisplayControllerRequest request) { 288 mojom::DisplayControllerRequest request) {
381 controller_bindings_.AddBinding(this, std::move(request)); 289 controller_bindings_.AddBinding(this, std::move(request));
382 } 290 }
383 291
384 ui::MultipleDisplayState ScreenManagerOzone::GetStateForDisplayIds(
385 const ui::DisplayConfigurator::DisplayStateList& display_states) const {
386 return (display_states.size() == 1
387 ? ui::MULTIPLE_DISPLAY_STATE_SINGLE
388 : ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED);
389 }
390
391 bool ScreenManagerOzone::GetResolutionForDisplayId(int64_t display_id,
392 gfx::Size* size) const {
393 for (const DisplayInfo& display : cached_displays_) {
394 if (display.id == display_id) {
395 *size = display.requested_size;
396 return true;
397 }
398 }
399
400 return false;
401 }
402
403 void ScreenManagerOzone::Create( 292 void ScreenManagerOzone::Create(
404 const service_manager::Identity& remote_identity, 293 const service_manager::Identity& remote_identity,
405 mojom::TestDisplayControllerRequest request) { 294 mojom::TestDisplayControllerRequest request) {
406 test_bindings_.AddBinding(this, std::move(request)); 295 test_bindings_.AddBinding(this, std::move(request));
407 } 296 }
408 297
298 ViewportMetrics ScreenManagerOzone::GetViewportMetricsForDisplay(
299 const Display& display) {
300 const ManagedDisplayInfo& managed_info =
301 display_manager_->GetDisplayInfo(display.id());
302
303 ViewportMetrics metrics;
304 metrics.bounds = display.bounds();
305 metrics.work_area = display.work_area();
306 metrics.pixel_size = managed_info.bounds_in_native().size();
307 metrics.rotation = display.rotation();
308 metrics.touch_support = display.touch_support();
309 metrics.device_scale_factor = display.device_scale_factor();
310 metrics.ui_scale_factor = managed_info.configured_ui_scale();
311
312 return metrics;
313 }
314
315 void ScreenManagerOzone::CreateOrUpdateMirroringDisplay(
316 const DisplayInfoList& display_info_list) {
317 NOTIMPLEMENTED();
318 }
319
320 void ScreenManagerOzone::CloseMirroringDisplayIfNotNecessary() {
321 NOTIMPLEMENTED();
322 }
323
324 void ScreenManagerOzone::PreDisplayConfigurationChange(bool clear_focus) {
325 DVLOG(1) << "PreDisplayConfigurationChange";
326 }
327
328 void ScreenManagerOzone::PostDisplayConfigurationChange(
329 bool must_clear_window) {
330 // Set primary display if not set yet.
331 if (primary_display_id_ == kInvalidDisplayId) {
332 const Display& primary_display =
333 display_manager_->GetPrimaryDisplayCandidate();
334 if (primary_display.is_valid()) {
335 primary_display_id_ = primary_display.id();
336 DVLOG(1) << "Set primary display to " << primary_display_id_;
337 screen_->display_list().UpdateDisplay(primary_display,
338 DisplayList::Type::PRIMARY);
339 delegate_->OnPrimaryDisplayChanged(primary_display_id_);
340 }
341 }
342
343 DVLOG(1) << "PostDisplayConfigurationChange";
344 }
345
346 ui::DisplayConfigurator* ScreenManagerOzone::display_configurator() {
347 return &display_configurator_;
348 }
349
350 void ScreenManagerOzone::OnDisplayAdded(const Display& display) {
351 ViewportMetrics metrics = GetViewportMetricsForDisplay(display);
352 DVLOG(1) << "OnDisplayAdded: " << display.ToString() << "\n "
353 << metrics.ToString();
354 screen_->display_list().AddDisplay(display, DisplayList::Type::NOT_PRIMARY);
355 delegate_->OnDisplayAdded(display.id(), metrics);
356 }
357
358 void ScreenManagerOzone::OnDisplayRemoved(const Display& display) {
359 // TODO(kylechar): If we're removing the primary display we need to first set
360 // a new primary display. This will crash until then.
361
362 DVLOG(1) << "OnDisplayRemoved: " << display.ToString();
363 screen_->display_list().RemoveDisplay(display.id());
364 delegate_->OnDisplayRemoved(display.id());
365 }
366
367 void ScreenManagerOzone::OnDisplayMetricsChanged(const Display& display,
368 uint32_t changed_metrics) {
369 ViewportMetrics metrics = GetViewportMetricsForDisplay(display);
370 DVLOG(1) << "OnDisplayModified: " << display.ToString() << "\n "
371 << metrics.ToString();
372 screen_->display_list().UpdateDisplay(display);
373 delegate_->OnDisplayModified(display.id(), metrics);
374 }
375
409 } // namespace display 376 } // namespace display
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698