OLD | NEW |
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/platform_screen_ozone.h" | 5 #include "services/ui/display/platform_screen_ozone.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } else { | 57 } else { |
58 display_configurator_.AddVirtualDisplay(gfx::Size(1024, 768)); | 58 display_configurator_.AddVirtualDisplay(gfx::Size(1024, 768)); |
59 } | 59 } |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 int64_t PlatformScreenOzone::GetPrimaryDisplayId() const { | 63 int64_t PlatformScreenOzone::GetPrimaryDisplayId() const { |
64 return primary_display_id_; | 64 return primary_display_id_; |
65 } | 65 } |
66 | 66 |
| 67 void PlatformScreenOzone::ToggleVirtualDisplay( |
| 68 const ToggleVirtualDisplayCallback& callback) { |
| 69 if (base::SysInfo::IsRunningOnChromeOS()) { |
| 70 callback.Run(false); |
| 71 return; |
| 72 } |
| 73 |
| 74 if (cached_displays_.size() == 1) { |
| 75 display_configurator_.AddVirtualDisplay(cached_displays_[0].bounds.size()); |
| 76 callback.Run(true); |
| 77 } else if (cached_displays_.size() > 1) { |
| 78 callback.Run( |
| 79 display_configurator_.RemoveVirtualDisplay(cached_displays_.back().id)); |
| 80 } else { |
| 81 NOTREACHED(); |
| 82 callback.Run(false); |
| 83 } |
| 84 } |
| 85 |
67 void PlatformScreenOzone::ProcessRemovedDisplays( | 86 void PlatformScreenOzone::ProcessRemovedDisplays( |
68 const ui::DisplayConfigurator::DisplayStateList& snapshots) { | 87 const ui::DisplayConfigurator::DisplayStateList& snapshots) { |
69 std::vector<int64_t> current_ids; | 88 std::vector<int64_t> current_ids; |
70 for (ui::DisplaySnapshot* snapshot : snapshots) | 89 for (ui::DisplaySnapshot* snapshot : snapshots) |
71 current_ids.push_back(snapshot->display_id()); | 90 current_ids.push_back(snapshot->display_id()); |
72 | 91 |
73 // Find cached displays with no matching snapshot and mark as removed. | 92 // Find cached displays with no matching snapshot and mark as removed. |
74 for (DisplayInfo& display : cached_displays_) { | 93 for (DisplayInfo& display : cached_displays_) { |
75 if (std::find(current_ids.begin(), current_ids.end(), display.id) == | 94 if (std::find(current_ids.begin(), current_ids.end(), display.id) == |
76 current_ids.end()) { | 95 current_ids.end()) { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 gfx::Rect bounds(next_display_origin_, current_mode->size()); | 167 gfx::Rect bounds(next_display_origin_, current_mode->size()); |
149 | 168 |
150 // Move the origin so that next display is to the right of current display. | 169 // Move the origin so that next display is to the right of current display. |
151 next_display_origin_.Offset(current_mode->size().width(), 0); | 170 next_display_origin_.Offset(current_mode->size().width(), 0); |
152 | 171 |
153 // If we have no primary display then this one should be it. | 172 // If we have no primary display then this one should be it. |
154 if (primary_display_id_ == display::Display::kInvalidDisplayID) | 173 if (primary_display_id_ == display::Display::kInvalidDisplayID) |
155 primary_display_id_ = id; | 174 primary_display_id_ = id; |
156 | 175 |
157 cached_displays_.push_back(DisplayInfo(id, bounds)); | 176 cached_displays_.push_back(DisplayInfo(id, bounds)); |
158 delegate_->OnDisplayAdded(this, id, bounds); | 177 delegate_->OnDisplayAdded(id, bounds); |
159 } | 178 } |
160 } | 179 } |
161 | 180 |
162 PlatformScreenOzone::CachedDisplayIterator | 181 PlatformScreenOzone::CachedDisplayIterator |
163 PlatformScreenOzone::GetCachedDisplayIterator(int64_t display_id) { | 182 PlatformScreenOzone::GetCachedDisplayIterator(int64_t display_id) { |
164 return std::find_if(cached_displays_.begin(), cached_displays_.end(), | 183 return std::find_if(cached_displays_.begin(), cached_displays_.end(), |
165 [display_id](const DisplayInfo& display_info) { | 184 [display_id](const DisplayInfo& display_info) { |
166 return display_info.id == display_id; | 185 return display_info.id == display_id; |
167 }); | 186 }); |
168 } | 187 } |
169 | 188 |
170 void PlatformScreenOzone::OnDisplayModeChanged( | 189 void PlatformScreenOzone::OnDisplayModeChanged( |
171 const ui::DisplayConfigurator::DisplayStateList& displays) { | 190 const ui::DisplayConfigurator::DisplayStateList& displays) { |
172 ProcessRemovedDisplays(displays); | 191 ProcessRemovedDisplays(displays); |
173 ProcessModifiedDisplays(displays); | 192 ProcessModifiedDisplays(displays); |
174 UpdateCachedDisplays(); | 193 UpdateCachedDisplays(); |
175 AddNewDisplays(displays); | 194 AddNewDisplays(displays); |
176 } | 195 } |
177 | 196 |
178 void PlatformScreenOzone::OnDisplayModeChangeFailed( | 197 void PlatformScreenOzone::OnDisplayModeChangeFailed( |
179 const ui::DisplayConfigurator::DisplayStateList& displays, | 198 const ui::DisplayConfigurator::DisplayStateList& displays, |
180 ui::MultipleDisplayState failed_new_state) { | 199 ui::MultipleDisplayState failed_new_state) { |
181 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; | 200 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; |
182 } | 201 } |
183 | 202 |
184 } // namespace display | 203 } // namespace display |
OLD | NEW |