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

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

Issue 2297743002: Process DisplaySnapshots in PlatformScreen. (Closed)
Patch Set: Address comments. 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)
71 << "Mus doesn't really support multiple displays, expect it to crash"; 71 current_ids.push_back(snapshot->display_id());
72
73 // Find cached displays with no matching snapshot and mark as removed.
74 for (DisplayInfo& display : cached_displays_) {
75 if (std::find(current_ids.begin(), current_ids.end(), display.id) ==
76 current_ids.end()) {
77 display.removed = true;
78 if (primary_display_id_ == display.id)
79 primary_display_id_ = display::Display::kInvalidDisplayID;
80 }
72 } 81 }
73 82
74 // TODO(kylechar): Use DisplayLayout/DisplayLayoutStore here when possible. 83 // If the primary display was removed find a new primary display id.
75 std::set<uint64_t> all_displays; 84 if (primary_display_id_ == display::Display::kInvalidDisplayID) {
76 for (ui::DisplaySnapshot* display : displays) { 85 for (const DisplayInfo& display : cached_displays_) {
77 const int64_t id = display->display_id(); 86 if (!display.removed) {
87 primary_display_id_ = display.id;
88 break;
89 }
90 }
91 }
92 }
78 93
79 all_displays.insert(id); 94 void PlatformScreenImplOzone::ProcessModifiedDisplays(
95 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
96 for (ui::DisplaySnapshot* snapshot : snapshots) {
97 auto iter = GetCachedDisplayIterator(snapshot->display_id());
98 if (iter != cached_displays_.end()) {
99 DisplayInfo& display_info = *iter;
100 const ui::DisplayMode* current_mode = snapshot->current_mode();
101 if (current_mode->size() != display_info.bounds.size()) {
sky 2016/09/02 16:03:21 no {}
kylechar 2016/09/02 17:19:47 Done. (Sorry, Java style guide habits are hard to
102 display_info.bounds.set_size(current_mode->size());
103 }
104 }
105 }
106 }
80 107
81 if (displays_.find(id) != displays_.end()) 108 void PlatformScreenImplOzone::UpdateCachedDisplays() {
109 // Walk through cached displays after processing the snapshots to find any
110 // removed or modified displays. This ensures that we only send one update per
111 // display to the delegate.
112 next_display_origin_.SetPoint(0, 0);
113 for (auto iter = cached_displays_.begin(); iter != cached_displays_.end();) {
114 DisplayInfo& display_info = *iter;
115 if (display_info.removed) {
116 // Update delegate and remove from cache.
117 delegate_->OnDisplayRemoved(display_info.id);
118 iter = cached_displays_.erase(iter);
119 } else {
120 // Check if the display origin needs to be updated.
121 if (next_display_origin_ != display_info.bounds.origin())
122 display_info.bounds.set_origin(next_display_origin_);
123 next_display_origin_.Offset(display_info.bounds.width(), 0);
124
125 // Check if the window bounds have changed and update delegate.
126 if (display_info.bounds != display_info.known_bounds) {
127 display_info.known_bounds = display_info.bounds;
128 delegate_->OnDisplayModified(display_info.id, display_info.bounds);
sky 2016/09/02 16:03:21 This is the only place I see you checking/setting
kylechar 2016/09/02 17:19:47 Hmm, right. I'm setting bounds in two places and c
129 }
130 ++iter;
131 }
132 }
133 }
134
135 void PlatformScreenImplOzone::AddNewDisplays(
136 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
137 for (ui::DisplaySnapshot* snapshot : snapshots) {
138 const int64_t id = snapshot->display_id();
139
140 // Check if display already exists and skip.
141 if (GetCachedDisplayIterator(id) != cached_displays_.end())
82 continue; 142 continue;
83 143
84 const ui::DisplayMode* current_mode = display->current_mode(); 144 const ui::DisplayMode* current_mode = snapshot->current_mode();
85 gfx::Rect bounds(next_display_origin_, current_mode->size()); 145 gfx::Rect bounds(next_display_origin_, current_mode->size());
86 146
87 // Move the origin so that next display is to the right of current display. 147 // Move the origin so that next display is to the right of current display.
88 next_display_origin_.Offset(current_mode->size().width(), 0); 148 next_display_origin_.Offset(current_mode->size().width(), 0);
89 149
90 // The first display added will be our primary display. 150 // If we have no primary display then this one should be it.
91 if (displays_.empty()) 151 if (primary_display_id_ == display::Display::kInvalidDisplayID)
92 primary_display_id_ = id; 152 primary_display_id_ = id;
93 153
94 // Keep track of what displays have already been added. 154 cached_displays_.push_back(DisplayInfo(id, bounds));
95 displays_.insert(display->display_id());
96
97 delegate_->OnDisplayAdded(this, id, bounds); 155 delegate_->OnDisplayAdded(this, id, bounds);
98 } 156 }
157 }
99 158
100 DCHECK(displays_ == all_displays) << "Removing displays is not supported."; 159 auto PlatformScreenImplOzone::GetCachedDisplayIterator(int64_t display_id)
kylechar 2016/09/02 15:18:34 std::vector<PlatformScreenImplOzone::DisplayInfo>:
sky 2016/09/02 16:03:21 I have to admit I'm surprised this actually compil
kylechar 2016/09/02 17:19:47 Changed. (I was surprised trailing return types we
160 -> CachedDisplayIterator {
161 return std::find_if(cached_displays_.begin(), cached_displays_.end(),
162 [display_id](const DisplayInfo& display_info) {
163 return display_info.id == display_id;
164 });
165 }
166
167 void PlatformScreenImplOzone::OnDisplayModeChanged(
168 const ui::DisplayConfigurator::DisplayStateList& displays) {
169 ProcessRemovedDisplays(displays);
170 ProcessModifiedDisplays(displays);
171 UpdateCachedDisplays();
172 AddNewDisplays(displays);
101 } 173 }
102 174
103 void PlatformScreenImplOzone::OnDisplayModeChangeFailed( 175 void PlatformScreenImplOzone::OnDisplayModeChangeFailed(
104 const ui::DisplayConfigurator::DisplayStateList& displays, 176 const ui::DisplayConfigurator::DisplayStateList& displays,
105 ui::MultipleDisplayState failed_new_state) { 177 ui::MultipleDisplayState failed_new_state) {
106 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; 178 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator";
107 } 179 }
108 180
109 } // namespace display 181 } // namespace display
OLDNEW
« no previous file with comments | « services/ui/display/platform_screen_impl_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