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

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

Issue 2461513002: Primary display change notifications. (Closed)
Patch Set: More fixes. Created 4 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 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 157 }
158 } 158 }
159 159
160 // Set next display index as primary, or loop back to first display if last. 160 // Set next display index as primary, or loop back to first display if last.
161 if (primary_display_index + 1 == num_displays) { 161 if (primary_display_index + 1 == num_displays) {
162 primary_display_id_ = cached_displays_[0].id; 162 primary_display_id_ = cached_displays_[0].id;
163 } else { 163 } else {
164 primary_display_id_ = cached_displays_[primary_display_index + 1].id; 164 primary_display_id_ = cached_displays_[primary_display_index + 1].id;
165 } 165 }
166 166
167 // TODO(kylechar): Update ws::DisplayManager. 167 delegate_->OnPrimaryDisplayChanged(primary_display_id_);
168 } 168 }
169 169
170 void PlatformScreenOzone::SetDisplayWorkArea(int64_t display_id, 170 void PlatformScreenOzone::SetDisplayWorkArea(int64_t display_id,
171 const gfx::Size& size, 171 const gfx::Size& size,
172 const gfx::Insets& insets) { 172 const gfx::Insets& insets) {
173 CachedDisplayIterator iter = GetCachedDisplayIterator(display_id); 173 CachedDisplayIterator iter = GetCachedDisplayIterator(display_id);
174 if (iter == cached_displays_.end()) { 174 if (iter == cached_displays_.end()) {
175 NOTREACHED() << display_id; 175 NOTREACHED() << display_id;
176 return; 176 return;
177 } 177 }
(...skipping 25 matching lines...) Expand all
203 203
204 // Find cached displays with no matching snapshot and mark as removed. 204 // Find cached displays with no matching snapshot and mark as removed.
205 for (DisplayInfo& display : cached_displays_) { 205 for (DisplayInfo& display : cached_displays_) {
206 if (std::find(current_ids.begin(), current_ids.end(), display.id) == 206 if (std::find(current_ids.begin(), current_ids.end(), display.id) ==
207 current_ids.end()) { 207 current_ids.end()) {
208 display.removed = true; 208 display.removed = true;
209 if (primary_display_id_ == display.id) 209 if (primary_display_id_ == display.id)
210 primary_display_id_ = Display::kInvalidDisplayID; 210 primary_display_id_ = Display::kInvalidDisplayID;
211 } 211 }
212 } 212 }
213
214 // If the primary display was removed find a new primary display id.
215 if (primary_display_id_ == Display::kInvalidDisplayID) {
216 for (const DisplayInfo& display : cached_displays_) {
217 if (!display.removed) {
218 primary_display_id_ = display.id;
219 break;
220 }
221 }
222 }
223 } 213 }
224 214
225 void PlatformScreenOzone::ProcessModifiedDisplays( 215 void PlatformScreenOzone::ProcessModifiedDisplays(
226 const ui::DisplayConfigurator::DisplayStateList& snapshots) { 216 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
227 for (ui::DisplaySnapshot* snapshot : snapshots) { 217 for (ui::DisplaySnapshot* snapshot : snapshots) {
228 auto iter = GetCachedDisplayIterator(snapshot->display_id()); 218 auto iter = GetCachedDisplayIterator(snapshot->display_id());
229 if (iter != cached_displays_.end()) { 219 if (iter != cached_displays_.end()) {
230 DisplayInfo& display_info = *iter; 220 DisplayInfo& display_info = *iter;
231 ViewportMetrics new_metrics = 221 ViewportMetrics new_metrics =
232 MetricsFromSnapshot(*snapshot, display_info.metrics.bounds.origin()); 222 MetricsFromSnapshot(*snapshot, display_info.metrics.bounds.origin());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 262
273 void PlatformScreenOzone::AddNewDisplays( 263 void PlatformScreenOzone::AddNewDisplays(
274 const ui::DisplayConfigurator::DisplayStateList& snapshots) { 264 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
275 for (ui::DisplaySnapshot* snapshot : snapshots) { 265 for (ui::DisplaySnapshot* snapshot : snapshots) {
276 const int64_t id = snapshot->display_id(); 266 const int64_t id = snapshot->display_id();
277 267
278 // Check if display already exists and skip. 268 // Check if display already exists and skip.
279 if (GetCachedDisplayIterator(id) != cached_displays_.end()) 269 if (GetCachedDisplayIterator(id) != cached_displays_.end())
280 continue; 270 continue;
281 271
282 // If we have no primary display then this one should be it.
283 if (primary_display_id_ == Display::kInvalidDisplayID)
284 primary_display_id_ = id;
285
286 DisplayInfo display_info; 272 DisplayInfo display_info;
287 display_info.id = snapshot->display_id(); 273 display_info.id = snapshot->display_id();
288 display_info.metrics = MetricsFromSnapshot(*snapshot, next_display_origin_); 274 display_info.metrics = MetricsFromSnapshot(*snapshot, next_display_origin_);
289 275
290 // Store the display mode sizes so we can toggle through them. 276 // Store the display mode sizes so we can toggle through them.
291 for (auto& mode : snapshot->modes()) { 277 for (auto& mode : snapshot->modes()) {
292 display_info.supported_sizes.push_back(mode->size()); 278 display_info.supported_sizes.push_back(mode->size());
293 if (mode.get() == snapshot->current_mode()) 279 if (mode.get() == snapshot->current_mode())
294 display_info.requested_size = mode->size(); 280 display_info.requested_size = mode->size();
295 } 281 }
296 282
297 // Move the origin so that next display is to the right of current display. 283 // Move the origin so that next display is to the right of current display.
298 next_display_origin_.Offset(display_info.metrics.bounds.width(), 0); 284 next_display_origin_.Offset(display_info.metrics.bounds.width(), 0);
299 285
300 cached_displays_.push_back(display_info); 286 cached_displays_.push_back(display_info);
301 delegate_->OnDisplayAdded(display_info.id, display_info.metrics); 287 delegate_->OnDisplayAdded(display_info.id, display_info.metrics);
288
289 // If we have no primary display then this one should be it.
290 if (primary_display_id_ == Display::kInvalidDisplayID) {
291 primary_display_id_ = id;
292 delegate_->OnPrimaryDisplayChanged(primary_display_id_);
293 }
302 } 294 }
303 } 295 }
304 296
305 PlatformScreenOzone::CachedDisplayIterator 297 PlatformScreenOzone::CachedDisplayIterator
306 PlatformScreenOzone::GetCachedDisplayIterator(int64_t display_id) { 298 PlatformScreenOzone::GetCachedDisplayIterator(int64_t display_id) {
307 return std::find_if(cached_displays_.begin(), cached_displays_.end(), 299 return std::find_if(cached_displays_.begin(), cached_displays_.end(),
308 [display_id](const DisplayInfo& display_info) { 300 [display_id](const DisplayInfo& display_info) {
309 return display_info.id == display_id; 301 return display_info.id == display_id;
310 }); 302 });
311 } 303 }
(...skipping 14 matching lines...) Expand all
326 current_mode->size(), 1.0f / metrics.device_scale_factor); 318 current_mode->size(), 1.0f / metrics.device_scale_factor);
327 metrics.bounds = gfx::Rect(origin, scaled_size); 319 metrics.bounds = gfx::Rect(origin, scaled_size);
328 metrics.work_area = metrics.bounds; 320 metrics.work_area = metrics.bounds;
329 return metrics; 321 return metrics;
330 } 322 }
331 323
332 void PlatformScreenOzone::OnDisplayModeChanged( 324 void PlatformScreenOzone::OnDisplayModeChanged(
333 const ui::DisplayConfigurator::DisplayStateList& displays) { 325 const ui::DisplayConfigurator::DisplayStateList& displays) {
334 ProcessRemovedDisplays(displays); 326 ProcessRemovedDisplays(displays);
335 ProcessModifiedDisplays(displays); 327 ProcessModifiedDisplays(displays);
328
329 // If the primary display is marked as removed we'll try to find a new primary
330 // display and update the delegate before removing the old primary display.
331 if (primary_display_id_ == Display::kInvalidDisplayID) {
332 for (const DisplayInfo& display : cached_displays_) {
333 if (!display.removed) {
334 primary_display_id_ = display.id;
335 delegate_->OnPrimaryDisplayChanged(primary_display_id_);
336 break;
337 }
338 }
339 }
340
336 UpdateCachedDisplays(); 341 UpdateCachedDisplays();
337 AddNewDisplays(displays); 342 AddNewDisplays(displays);
343
338 wait_for_display_config_update_ = false; 344 wait_for_display_config_update_ = false;
339 } 345 }
340 346
341 void PlatformScreenOzone::OnDisplayModeChangeFailed( 347 void PlatformScreenOzone::OnDisplayModeChangeFailed(
342 const ui::DisplayConfigurator::DisplayStateList& displays, 348 const ui::DisplayConfigurator::DisplayStateList& displays,
343 ui::MultipleDisplayState failed_new_state) { 349 ui::MultipleDisplayState failed_new_state) {
344 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; 350 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator";
345 wait_for_display_config_update_ = false; 351 wait_for_display_config_update_ = false;
346 } 352 }
347 353
(...skipping 22 matching lines...) Expand all
370 return false; 376 return false;
371 } 377 }
372 378
373 void PlatformScreenOzone::Create( 379 void PlatformScreenOzone::Create(
374 const service_manager::Identity& remote_identity, 380 const service_manager::Identity& remote_identity,
375 mojom::TestDisplayControllerRequest request) { 381 mojom::TestDisplayControllerRequest request) {
376 test_bindings_.AddBinding(this, std::move(request)); 382 test_bindings_.AddBinding(this, std::move(request));
377 } 383 }
378 384
379 } // namespace display 385 } // namespace display
OLDNEW
« no previous file with comments | « services/ui/display/platform_screen_ozone.h ('k') | services/ui/display/platform_screen_ozone_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698