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

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

Issue 2297743002: Process DisplaySnapshots in PlatformScreen. (Closed)
Patch Set: Fix test. 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"
11 #include "base/sys_info.h" 11 #include "base/sys_info.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "third_party/skia/include/core/SkColor.h" 13 #include "third_party/skia/include/core/SkColor.h"
14 #include "ui/display/types/display_constants.h" 14 #include "ui/display/types/display_constants.h"
15 #include "ui/display/types/display_snapshot.h" 15 #include "ui/display/types/display_snapshot.h"
16 #include "ui/display/types/native_display_delegate.h" 16 #include "ui/display/types/native_display_delegate.h"
17 #include "ui/gfx/geometry/rect.h" 17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/ozone/public/ozone_platform.h" 18 #include "ui/ozone/public/ozone_platform.h"
19 19
20 namespace display { 20 namespace display {
21 namespace { 21 namespace {
22 22
23 // Needed for DisplayConfigurator::ForceInitialConfigure. 23 // Needed for DisplayConfigurator::ForceInitialConfigure.
24 const SkColor kChromeOsBootColor = SkColorSetRGB(0xfe, 0xfe, 0xfe); 24 const SkColor kChromeOsBootColor = SkColorSetRGB(0xfe, 0xfe, 0xfe);
25 25
26 class DisplayIdPredicate {
rjkroege 2016/08/30 18:41:59 what is this for?
kylechar 2016/08/31 15:58:01 It's for find_if. We only have a int64_t id and we
27 public:
28 explicit DisplayIdPredicate(int64_t id) : id_(id) {}
29 bool operator()(const PlatformScreenImplOzone::DisplayInfo& display) const {
rjkroege 2016/08/30 18:41:59 why not operator== for a comparison op? Or perhaps
kylechar 2016/08/31 15:58:01 See above.
30 return display.id == id_;
31 }
32
33 private:
34 int64_t id_;
35 };
36
26 } // namespace 37 } // namespace
27 38
28 // static 39 // static
29 std::unique_ptr<PlatformScreen> PlatformScreen::Create() { 40 std::unique_ptr<PlatformScreen> PlatformScreen::Create() {
30 return base::MakeUnique<PlatformScreenImplOzone>(); 41 return base::MakeUnique<PlatformScreenImplOzone>();
31 } 42 }
32 43
33 PlatformScreenImplOzone::PlatformScreenImplOzone() {} 44 PlatformScreenImplOzone::PlatformScreenImplOzone() {}
34 45
35 PlatformScreenImplOzone::~PlatformScreenImplOzone() { 46 PlatformScreenImplOzone::~PlatformScreenImplOzone() {
(...skipping 21 matching lines...) Expand all
57 } else { 68 } else {
58 display_configurator_.AddVirtualDisplay(gfx::Size(1024, 768)); 69 display_configurator_.AddVirtualDisplay(gfx::Size(1024, 768));
59 } 70 }
60 } 71 }
61 } 72 }
62 73
63 int64_t PlatformScreenImplOzone::GetPrimaryDisplayId() const { 74 int64_t PlatformScreenImplOzone::GetPrimaryDisplayId() const {
64 return primary_display_id_; 75 return primary_display_id_;
65 } 76 }
66 77
67 void PlatformScreenImplOzone::OnDisplayModeChanged( 78 void PlatformScreenImplOzone::ProcessRemovedDisplays(
68 const ui::DisplayConfigurator::DisplayStateList& displays) { 79 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
69 if (displays.size() > 1) { 80 std::vector<int64_t> current_ids;
70 LOG(ERROR) 81 for (ui::DisplaySnapshot* snapshot : snapshots) {
71 << "Mus doesn't really support multiple displays, expect it to crash"; 82 current_ids.push_back(snapshot->display_id());
72 } 83 }
73 84
74 // TODO(kylechar): Use DisplayLayout/DisplayLayoutStore here when possible. 85 // Find cached displays with no matching snapshot and mark as removed.
rjkroege 2016/08/30 18:41:59 we should be replacing this code with the guts of
kylechar 2016/08/31 15:58:01 Yep something like that. I need some business logi
75 std::set<uint64_t> all_displays; 86 for (DisplayInfo& display : cached_displays_) {
76 for (ui::DisplaySnapshot* display : displays) { 87 if (std::find(current_ids.begin(), current_ids.end(), display.id) ==
77 const int64_t id = display->display_id(); 88 current_ids.end()) {
89 display.removed = true;
90 if (primary_display_id_ == display.id)
91 primary_display_id_ = display::Display::kInvalidDisplayID;
92 }
93 }
78 94
79 all_displays.insert(id); 95 // If the primary display was removed find a new primary display id.
96 if (primary_display_id_ == display::Display::kInvalidDisplayID) {
97 for (const DisplayInfo& display : cached_displays_) {
98 if (!display.removed) {
99 primary_display_id_ = display.id;
100 break;
101 }
102 }
103 }
104 }
80 105
81 if (displays_.find(id) != displays_.end()) 106 void PlatformScreenImplOzone::ProcessModifiedDisplays(
107 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
108 for (ui::DisplaySnapshot* snapshot : snapshots) {
109 auto iter = std::find_if(cached_displays_.begin(), cached_displays_.end(),
rjkroege 2016/08/30 18:41:59 I'm probably in the minority but I think that a fo
kylechar 2016/08/31 15:58:01 I think you're right here. I already had DisplayId
110 DisplayIdPredicate(snapshot->display_id()));
111
112 // If we have the display cached, check if the size matches the size from
113 // current mode of the snapshot and update if necessary.
114 if (iter != cached_displays_.end()) {
115 DisplayInfo& display_info = *iter;
116 const ui::DisplayMode* current_mode = snapshot->current_mode();
117
118 if (current_mode->size() != display_info.bounds.size()) {
119 display_info.bounds.set_size(current_mode->size());
120 }
121 }
122 }
123 }
124
125 void PlatformScreenImplOzone::UpdateCachedDisplays() {
126 // Walk through cached displays after processing the snapshots to find any
127 // removed or modified displays. This ensures that we only send one update per
rjkroege 2016/08/30 18:41:59 per displays? This is not clear to me.
kylechar 2016/08/31 15:58:01 It should be per display, typo. Fixed.
128 // displays to the delegate.
129 next_display_origin_.SetPoint(0, 0);
130 auto iter = cached_displays_.begin();
131 while (iter != cached_displays_.end()) {
132 DisplayInfo& display_info = *iter;
133 if (display_info.removed) {
134 // Update delegate and remove from cache.
135 delegate_->OnDisplayRemoved(display_info.id);
rjkroege 2016/08/30 18:41:59 we should have a discussion about the delegate_ ap
kylechar 2016/08/31 15:58:01 As per our offline discussion there are a bunch of
136 iter = cached_displays_.erase(iter);
137 } else {
138 // Check if the display origin needs to be updated.
139 if (next_display_origin_ != display_info.bounds.origin()) {
140 display_info.bounds.set_origin(next_display_origin_);
141 }
142 next_display_origin_.Offset(display_info.bounds.width(), 0);
143
144 // Check if the window bounds have changed and update delegate.
145 if (display_info.bounds != display_info.known_bounds) {
146 delegate_->OnDisplayModified(display_info.id, display_info.bounds);
147 display_info.known_bounds = display_info.bounds;
148 }
149 iter++;
150 }
151 }
152 }
153
154 void PlatformScreenImplOzone::AddNewDisplays(
155 const ui::DisplayConfigurator::DisplayStateList& snapshots) {
156 for (ui::DisplaySnapshot* snapshot : snapshots) {
157 const int64_t id = snapshot->display_id();
158
159 // Check if display already exists and skip.
160 if (std::find_if(cached_displays_.begin(), cached_displays_.end(),
161 DisplayIdPredicate(id)) != cached_displays_.end())
82 continue; 162 continue;
83 163
84 const ui::DisplayMode* current_mode = display->current_mode(); 164 const ui::DisplayMode* current_mode = snapshot->current_mode();
85 gfx::Rect bounds(next_display_origin_, current_mode->size()); 165 gfx::Rect bounds(next_display_origin_, current_mode->size());
86 166
87 // Move the origin so that next display is to the right of current display. 167 // Move the origin so that next display is to the right of current display.
88 next_display_origin_.Offset(current_mode->size().width(), 0); 168 next_display_origin_.Offset(current_mode->size().width(), 0);
89 169
90 // The first display added will be our primary display. 170 // If we have no primary display then this one should be it.
91 if (displays_.empty()) 171 if (primary_display_id_ == display::Display::kInvalidDisplayID)
92 primary_display_id_ = id; 172 primary_display_id_ = id;
93 173
94 // Keep track of what displays have already been added. 174 cached_displays_.push_back(DisplayInfo(id, bounds));
95 displays_.insert(display->display_id());
96
97 delegate_->OnDisplayAdded(this, id, bounds); 175 delegate_->OnDisplayAdded(this, id, bounds);
98 } 176 }
177 }
99 178
100 DCHECK(displays_ == all_displays) << "Removing displays is not supported."; 179 void PlatformScreenImplOzone::OnDisplayModeChanged(
180 const ui::DisplayConfigurator::DisplayStateList& displays) {
181 ProcessRemovedDisplays(displays);
182 ProcessModifiedDisplays(displays);
183 UpdateCachedDisplays();
184 AddNewDisplays(displays);
101 } 185 }
102 186
103 void PlatformScreenImplOzone::OnDisplayModeChangeFailed( 187 void PlatformScreenImplOzone::OnDisplayModeChangeFailed(
104 const ui::DisplayConfigurator::DisplayStateList& displays, 188 const ui::DisplayConfigurator::DisplayStateList& displays,
105 ui::MultipleDisplayState failed_new_state) { 189 ui::MultipleDisplayState failed_new_state) {
106 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; 190 LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator";
107 } 191 }
108 192
109 } // namespace display 193 } // namespace display
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698