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

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

Issue 2297743002: Process DisplaySnapshots in PlatformScreen. (Closed)
Patch Set: Update tests. Created 4 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 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_impl_ozone.h" 5 #include "services/ui/display/platform_screen_impl_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
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 PlatformScreenImplOzone::GetPrimaryDisplayId() const { 63 int64_t PlatformScreenImplOzone::GetPrimaryDisplayId() const {
64 return primary_display_id_; 64 return primary_display_id_;
65 } 65 }
66 66
67 void PlatformScreenImplOzone::OnDisplayModeChanged( 67 void PlatformScreenImplOzone::ProcessRemovedDisplays(
68 const ui::DisplayConfigurator::DisplayStateList& displays) { 68 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
69 if (displays.size() > 1) { 69 std::vector<int64_t> current_ids;
70 LOG(ERROR) 70 for (ui::DisplaySnapshot* snapshot : snapshots) {
sky 2016/09/01 19:25:08 no {}
kylechar 2016/09/02 15:18:33 Done.
71 << "Mus doesn't really support multiple displays, expect it to crash"; 71 current_ids.push_back(snapshot->display_id());
72 } 72 }
73 73
74 // TODO(kylechar): Use DisplayLayout/DisplayLayoutStore here when possible. 74 // Find cached displays with no matching snapshot and mark as removed.
75 std::set<uint64_t> all_displays; 75 for (DisplayInfo& display : cached_displays_) {
76 for (ui::DisplaySnapshot* display : displays) { 76 if (std::find(current_ids.begin(), current_ids.end(), display.id) ==
77 const int64_t id = display->display_id(); 77 current_ids.end()) {
78 display.removed = true;
79 if (primary_display_id_ == display.id)
80 primary_display_id_ = display::Display::kInvalidDisplayID;
81 }
82 }
78 83
79 all_displays.insert(id); 84 // If the primary display was removed find a new primary display id.
85 if (primary_display_id_ == display::Display::kInvalidDisplayID) {
86 for (const DisplayInfo& display : cached_displays_) {
87 if (!display.removed) {
88 primary_display_id_ = display.id;
89 break;
90 }
91 }
92 }
93 }
80 94
81 if (displays_.find(id) != displays_.end()) 95 void PlatformScreenImplOzone::ProcessModifiedDisplays(
96 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
97 for (ui::DisplaySnapshot* snapshot : snapshots) {
98 DisplayInfo* display_info = nullptr;
99 for (DisplayInfo& current_info : cached_displays_) {
100 if (current_info.id == snapshot->display_id()) {
101 display_info = &current_info;
102 break;
103 }
104 }
105
106 if (display_info) {
sky 2016/09/01 19:25:08 Move inside look on 101 so you don't need local.
kylechar 2016/09/02 15:18:33 Done.
107 const ui::DisplayMode* current_mode = snapshot->current_mode();
108 if (current_mode->size() != display_info->bounds.size()) {
109 display_info->bounds.set_size(current_mode->size());
110 }
111 }
112 }
113 }
114
115 void PlatformScreenImplOzone::UpdateCachedDisplays() {
116 // Walk through cached displays after processing the snapshots to find any
117 // removed or modified displays. This ensures that we only send one update per
118 // display to the delegate.
119 next_display_origin_.SetPoint(0, 0);
120 auto iter = cached_displays_.begin();
121 while (iter != cached_displays_.end()) {
sky 2016/09/01 19:25:08 Use a for loop, that way iter stays local to the l
kylechar 2016/09/02 15:18:33 Done.
122 DisplayInfo& display_info = *iter;
123 if (display_info.removed) {
124 // Update delegate and remove from cache.
125 delegate_->OnDisplayRemoved(display_info.id);
sky 2016/09/01 19:25:07 Did you consider updating cached_displays_ and the
kylechar 2016/09/02 15:18:34 Done.
126 iter = cached_displays_.erase(iter);
127 } else {
128 // Check if the display origin needs to be updated.
129 if (next_display_origin_ != display_info.bounds.origin()) {
sky 2016/09/01 19:25:08 no {}
kylechar 2016/09/02 15:18:34 Done. (Java styleguide habits are hard to kick.)
130 display_info.bounds.set_origin(next_display_origin_);
131 }
132 next_display_origin_.Offset(display_info.bounds.width(), 0);
133
134 // Check if the window bounds have changed and update delegate.
135 if (display_info.bounds != display_info.known_bounds) {
136 delegate_->OnDisplayModified(display_info.id, display_info.bounds);
137 display_info.known_bounds = display_info.bounds;
138 }
139 iter++;
sky 2016/09/01 19:25:08 ++iter.
kylechar 2016/09/02 15:18:34 Done.
140 }
141 }
142 }
143
144 void PlatformScreenImplOzone::AddNewDisplays(
145 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
146 for (ui::DisplaySnapshot* snapshot : snapshots) {
147 const int64_t id = snapshot->display_id();
148
149 // Check if display already exists and skip.
150 if (std::find_if(cached_displays_.begin(), cached_displays_.end(),
sky 2016/09/01 19:25:07 It seems worth a function for this, given the loop
kylechar 2016/09/02 15:18:34 I had something similar in patch 3 but removed it.
151 [id](const DisplayInfo& display_info) {
152 return display_info.id == id;
153 }) != cached_displays_.end())
82 continue; 154 continue;
83 155
84 const ui::DisplayMode* current_mode = display->current_mode(); 156 const ui::DisplayMode* current_mode = snapshot->current_mode();
85 gfx::Rect bounds(next_display_origin_, current_mode->size()); 157 gfx::Rect bounds(next_display_origin_, current_mode->size());
86 158
87 // Move the origin so that next display is to the right of current display. 159 // Move the origin so that next display is to the right of current display.
88 next_display_origin_.Offset(current_mode->size().width(), 0); 160 next_display_origin_.Offset(current_mode->size().width(), 0);
89 161
90 // The first display added will be our primary display. 162 // If we have no primary display then this one should be it.
91 if (displays_.empty()) 163 if (primary_display_id_ == display::Display::kInvalidDisplayID)
92 primary_display_id_ = id; 164 primary_display_id_ = id;
93 165
94 // Keep track of what displays have already been added. 166 cached_displays_.push_back(DisplayInfo(id, bounds));
95 displays_.insert(display->display_id());
96
97 delegate_->OnDisplayAdded(this, id, bounds); 167 delegate_->OnDisplayAdded(this, id, bounds);
98 } 168 }
169 }
99 170
100 DCHECK(displays_ == all_displays) << "Removing displays is not supported."; 171 void PlatformScreenImplOzone::OnDisplayModeChanged(
172 const ui::DisplayConfigurator::DisplayStateList& displays) {
173 ProcessRemovedDisplays(displays);
174 ProcessModifiedDisplays(displays);
175 UpdateCachedDisplays();
176 AddNewDisplays(displays);
101 } 177 }
102 178
103 void PlatformScreenImplOzone::OnDisplayModeChangeFailed( 179 void PlatformScreenImplOzone::OnDisplayModeChangeFailed(
104 const ui::DisplayConfigurator::DisplayStateList& displays, 180 const ui::DisplayConfigurator::DisplayStateList& displays,
105 ui::MultipleDisplayState failed_new_state) { 181 ui::MultipleDisplayState failed_new_state) {
106 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; 182 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator";
107 } 183 }
108 184
109 } // namespace display 185 } // namespace display
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698