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

Side by Side Diff: ui/views/mus/screen_mus.cc

Issue 1984393002: Refactors std::vector<Display> out of ScreenMus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix deps and DEPS Created 4 years, 7 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
« mash/wm/test/wm_test_screen.cc ('K') | « ui/views/mus/screen_mus.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "ui/views/mus/screen_mus.h" 5 #include "ui/views/mus/screen_mus.h"
6 6
7 #include "mojo/converters/geometry/geometry_type_converters.h" 7 #include "mojo/converters/geometry/geometry_type_converters.h"
8 #include "services/shell/public/cpp/connection.h" 8 #include "services/shell/public/cpp/connection.h"
9 #include "services/shell/public/cpp/connector.h" 9 #include "services/shell/public/cpp/connector.h"
10 #include "ui/aura/window.h" 10 #include "ui/aura/window.h"
(...skipping 18 matching lines...) Expand all
29 return result; 29 return result;
30 } 30 }
31 }; 31 };
32 32
33 } // namespace mojo 33 } // namespace mojo
34 34
35 namespace views { 35 namespace views {
36 36
37 ScreenMus::ScreenMus(ScreenMusDelegate* delegate) 37 ScreenMus::ScreenMus(ScreenMusDelegate* delegate)
38 : delegate_(delegate), 38 : delegate_(delegate),
39 primary_display_index_(0),
40 display_manager_observer_binding_(this) { 39 display_manager_observer_binding_(this) {
41 } 40 }
42 41
43 ScreenMus::~ScreenMus() {} 42 ScreenMus::~ScreenMus() {}
44 43
45 void ScreenMus::Init(shell::Connector* connector) { 44 void ScreenMus::Init(shell::Connector* connector) {
46 display::Screen::SetScreenInstance(this); 45 display::Screen::SetScreenInstance(this);
47 46
48 connector->ConnectToInterface("mojo:mus", &display_manager_); 47 connector->ConnectToInterface("mojo:mus", &display_manager_);
49 48
50 display_manager_->AddObserver( 49 display_manager_->AddObserver(
51 display_manager_observer_binding_.CreateInterfacePtrAndBind()); 50 display_manager_observer_binding_.CreateInterfacePtrAndBind());
52 51
53 // We need the set of displays before we can continue. Wait for it. 52 // We need the set of displays before we can continue. Wait for it.
54 // 53 //
55 // TODO(rockot): Do something better here. This should not have to block tasks 54 // TODO(rockot): Do something better here. This should not have to block tasks
56 // from running on the calling thread. http://crbug.com/594852. 55 // from running on the calling thread. http://crbug.com/594852.
57 bool success = display_manager_observer_binding_.WaitForIncomingMethodCall(); 56 bool success = display_manager_observer_binding_.WaitForIncomingMethodCall();
58 57
59 // The WaitForIncomingMethodCall() should have supplied the set of Displays, 58 // The WaitForIncomingMethodCall() should have supplied the set of Displays,
60 // unless mus is going down, in which case encountered_error() is true, or the 59 // unless mus is going down, in which case encountered_error() is true, or the
61 // call to WaitForIncomingMethodCall() failed. 60 // call to WaitForIncomingMethodCall() failed.
62 if (displays_.empty()) { 61 if (display_list_.displays().empty()) {
63 DCHECK(display_manager_.encountered_error() || !success); 62 DCHECK(display_manager_.encountered_error() || !success);
64 // In this case we install a default display and assume the process is 63 // In this case we install a default display and assume the process is
65 // going to exit shortly so that the real value doesn't matter. 64 // going to exit shortly so that the real value doesn't matter.
66 displays_.push_back( 65 display_list_.AddDisplay(
67 display::Display(0xFFFFFFFF, gfx::Rect(0, 0, 801, 802))); 66 display::Display(0xFFFFFFFF, gfx::Rect(0, 0, 801, 802)),
67 DisplayList::Type::PRIMARY);
68 } 68 }
69 } 69 }
70 70
71 int ScreenMus::FindDisplayIndexById(int64_t id) const {
72 for (size_t i = 0; i < displays_.size(); ++i) {
73 if (displays_[i].id() == id)
74 return static_cast<int>(i);
75 }
76 return -1;
77 }
78
79 void ScreenMus::ProcessDisplayChanged(const display::Display& changed_display, 71 void ScreenMus::ProcessDisplayChanged(const display::Display& changed_display,
80 bool is_primary) { 72 bool is_primary) {
81 const int display_index = FindDisplayIndexById(changed_display.id()); 73 if (display_list_.FindDisplayById(changed_display.id()) ==
82 if (display_index == -1) { 74 display_list_.displays().end()) {
83 displays_.push_back(changed_display); 75 display_list_.AddDisplay(changed_display,
84 if (is_primary) 76 is_primary ? DisplayList::Type::PRIMARY
85 primary_display_index_ = static_cast<int>(displays_.size()) - 1; 77 : DisplayList::Type::NOT_PRIMARY);
86 FOR_EACH_OBSERVER(display::DisplayObserver, observers_,
87 OnDisplayAdded(changed_display));
88 return; 78 return;
89 } 79 }
90 80 display_list_.UpdateDisplay(
91 display::Display* local_display = &displays_[display_index]; 81 changed_display,
92 uint32_t changed_values = 0; 82 is_primary ? DisplayList::Type::PRIMARY : DisplayList::Type::NOT_PRIMARY);
93 if (is_primary && display_index != primary_display_index_) {
94 primary_display_index_ = display_index;
95 // ash::DisplayManager only notifies for the Display gaining primary, not
96 // the one losing it.
97 changed_values |= display::DisplayObserver::DISPLAY_METRIC_PRIMARY;
98 }
99 if (local_display->bounds() != changed_display.bounds()) {
100 local_display->set_bounds(changed_display.bounds());
101 changed_values |= display::DisplayObserver::DISPLAY_METRIC_BOUNDS;
102 }
103 if (local_display->work_area() != changed_display.work_area()) {
104 local_display->set_work_area(changed_display.work_area());
105 changed_values |= display::DisplayObserver::DISPLAY_METRIC_WORK_AREA;
106 }
107 if (local_display->rotation() != changed_display.rotation()) {
108 local_display->set_rotation(changed_display.rotation());
109 changed_values |= display::DisplayObserver::DISPLAY_METRIC_ROTATION;
110 }
111 if (local_display->device_scale_factor() !=
112 changed_display.device_scale_factor()) {
113 local_display->set_device_scale_factor(
114 changed_display.device_scale_factor());
115 changed_values |=
116 display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR;
117 }
118 FOR_EACH_OBSERVER(display::DisplayObserver, observers_,
119 OnDisplayMetricsChanged(*local_display, changed_values));
120 } 83 }
121 84
122 gfx::Point ScreenMus::GetCursorScreenPoint() { 85 gfx::Point ScreenMus::GetCursorScreenPoint() {
123 if (!delegate_) { 86 if (!delegate_) {
124 // TODO(erg): If we need the cursor point in the window manager, we'll need 87 // TODO(erg): If we need the cursor point in the window manager, we'll need
125 // to make |delegate_| required. It only recently changed to be optional. 88 // to make |delegate_| required. It only recently changed to be optional.
126 NOTIMPLEMENTED(); 89 NOTIMPLEMENTED();
127 return gfx::Point(); 90 return gfx::Point();
128 } 91 }
129 92
130 return delegate_->GetCursorScreenPoint(); 93 return delegate_->GetCursorScreenPoint();
131 } 94 }
132 95
133 bool ScreenMus::IsWindowUnderCursor(gfx::NativeWindow window) { 96 bool ScreenMus::IsWindowUnderCursor(gfx::NativeWindow window) {
134 if (!window) 97 if (!window)
135 return false; 98 return false;
136 99
137 return window->IsVisible() && 100 return window->IsVisible() &&
138 window->GetBoundsInScreen().Contains(GetCursorScreenPoint()); 101 window->GetBoundsInScreen().Contains(GetCursorScreenPoint());
139 } 102 }
140 103
141 gfx::NativeWindow ScreenMus::GetWindowAtScreenPoint(const gfx::Point& point) { 104 gfx::NativeWindow ScreenMus::GetWindowAtScreenPoint(const gfx::Point& point) {
142 NOTIMPLEMENTED(); 105 NOTIMPLEMENTED();
143 return nullptr; 106 return nullptr;
144 } 107 }
145 108
146 display::Display ScreenMus::GetPrimaryDisplay() const { 109 display::Display ScreenMus::GetPrimaryDisplay() const {
147 return displays_[primary_display_index_]; 110 return *display_list_.GetPrimaryDisplayIterator();
148 } 111 }
149 112
150 display::Display ScreenMus::GetDisplayNearestWindow( 113 display::Display ScreenMus::GetDisplayNearestWindow(
151 gfx::NativeView view) const { 114 gfx::NativeView view) const {
152 //NOTIMPLEMENTED(); 115 //NOTIMPLEMENTED();
153 return GetPrimaryDisplay(); 116 return *display_list_.GetPrimaryDisplayIterator();
154 } 117 }
155 118
156 display::Display ScreenMus::GetDisplayNearestPoint( 119 display::Display ScreenMus::GetDisplayNearestPoint(
157 const gfx::Point& point) const { 120 const gfx::Point& point) const {
158 return *display::FindDisplayNearestPoint(displays_, point); 121 return *display::FindDisplayNearestPoint(display_list_.displays(), point);
159 } 122 }
160 123
161 int ScreenMus::GetNumDisplays() const { 124 int ScreenMus::GetNumDisplays() const {
162 return static_cast<int>(displays_.size()); 125 return static_cast<int>(display_list_.displays().size());
163 } 126 }
164 127
165 std::vector<display::Display> ScreenMus::GetAllDisplays() const { 128 std::vector<display::Display> ScreenMus::GetAllDisplays() const {
166 return displays_; 129 return display_list_.displays();
167 } 130 }
168 131
169 display::Display ScreenMus::GetDisplayMatching( 132 display::Display ScreenMus::GetDisplayMatching(
170 const gfx::Rect& match_rect) const { 133 const gfx::Rect& match_rect) const {
171 const display::Display* match = 134 const display::Display* match = display::FindDisplayWithBiggestIntersection(
172 display::FindDisplayWithBiggestIntersection(displays_, match_rect); 135 display_list_.displays(), match_rect);
173 return match ? *match : GetPrimaryDisplay(); 136 return match ? *match : GetPrimaryDisplay();
174 } 137 }
175 138
176 void ScreenMus::AddObserver(display::DisplayObserver* observer) { 139 void ScreenMus::AddObserver(display::DisplayObserver* observer) {
177 observers_.AddObserver(observer); 140 display_list_.AddObserver(observer);
178 } 141 }
179 142
180 void ScreenMus::RemoveObserver(display::DisplayObserver* observer) { 143 void ScreenMus::RemoveObserver(display::DisplayObserver* observer) {
181 observers_.RemoveObserver(observer); 144 display_list_.RemoveObserver(observer);
182 } 145 }
183 146
184 void ScreenMus::OnDisplays(mojo::Array<mus::mojom::DisplayPtr> displays) { 147 void ScreenMus::OnDisplays(
148 mojo::Array<mus::mojom::DisplayPtr> transport_displays) {
185 // This should only be called once from Init() before any observers have been 149 // This should only be called once from Init() before any observers have been
186 // added. 150 // added.
187 DCHECK(displays_.empty()); 151 DCHECK(display_list_.displays().empty());
188 displays_ = displays.To<std::vector<display::Display>>(); 152 std::vector<display::Display> displays =
189 DCHECK(!displays_.empty()); 153 transport_displays.To<std::vector<display::Display>>();
190 for (size_t i = 0; i < displays.size(); ++i) { 154 for (size_t i = 0; i < displays.size(); ++i) {
191 if (displays[i]->is_primary) { 155 const bool is_primary = transport_displays[i]->is_primary;
192 primary_display_index_ = static_cast<int>(i); 156 display_list_.AddDisplay(displays[i], is_primary
157 ? DisplayList::Type::PRIMARY
158 : DisplayList::Type::NOT_PRIMARY);
159 if (is_primary) {
193 // TODO(sky): Make WindowManagerFrameValues per display. 160 // TODO(sky): Make WindowManagerFrameValues per display.
194 WindowManagerFrameValues frame_values = 161 WindowManagerFrameValues frame_values =
195 displays[i]->frame_decoration_values.To<WindowManagerFrameValues>(); 162 transport_displays[i]
163 ->frame_decoration_values.To<WindowManagerFrameValues>();
196 WindowManagerFrameValues::SetInstance(frame_values); 164 WindowManagerFrameValues::SetInstance(frame_values);
197 } 165 }
198 } 166 }
167 DCHECK(!display_list_.displays().empty());
199 } 168 }
200 169
201 void ScreenMus::OnDisplaysChanged( 170 void ScreenMus::OnDisplaysChanged(
202 mojo::Array<mus::mojom::DisplayPtr> transport_displays) { 171 mojo::Array<mus::mojom::DisplayPtr> transport_displays) {
203 for (size_t i = 0; i < transport_displays.size(); ++i) { 172 for (size_t i = 0; i < transport_displays.size(); ++i) {
204 const bool is_primary = transport_displays[i]->is_primary; 173 const bool is_primary = transport_displays[i]->is_primary;
205 ProcessDisplayChanged(transport_displays[i].To<display::Display>(), 174 ProcessDisplayChanged(transport_displays[i].To<display::Display>(),
206 is_primary); 175 is_primary);
207 if (is_primary) { 176 if (is_primary) {
208 WindowManagerFrameValues frame_values = 177 WindowManagerFrameValues frame_values =
209 transport_displays[i] 178 transport_displays[i]
210 ->frame_decoration_values.To<WindowManagerFrameValues>(); 179 ->frame_decoration_values.To<WindowManagerFrameValues>();
211 WindowManagerFrameValues::SetInstance(frame_values); 180 WindowManagerFrameValues::SetInstance(frame_values);
212 if (delegate_) 181 if (delegate_)
213 delegate_->OnWindowManagerFrameValuesChanged(); 182 delegate_->OnWindowManagerFrameValuesChanged();
214 } 183 }
215 } 184 }
216 } 185 }
217 186
218 void ScreenMus::OnDisplayRemoved(int64_t id) { 187 void ScreenMus::OnDisplayRemoved(int64_t id) {
219 const int index = FindDisplayIndexById(id); 188 display_list_.RemoveDisplay(id);
220 DCHECK_NE(-1, index);
221 // Another display must become primary before the existing primary is
222 // removed.
223 DCHECK_NE(index, primary_display_index_);
224 const display::Display display = displays_[index];
225 FOR_EACH_OBSERVER(display::DisplayObserver, observers_,
226 OnDisplayRemoved(display));
227 } 189 }
228 190
229 } // namespace views 191 } // namespace views
OLDNEW
« mash/wm/test/wm_test_screen.cc ('K') | « ui/views/mus/screen_mus.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698