| OLD | NEW |
| 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/gfx/display_finder.h" | 10 #include "ui/gfx/display_finder.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 display_manager_->AddObserver( | 92 display_manager_->AddObserver( |
| 93 display_manager_observer_binding_.CreateInterfacePtrAndBind()); | 93 display_manager_observer_binding_.CreateInterfacePtrAndBind()); |
| 94 | 94 |
| 95 // We need the set of displays before we can continue. Wait for it. | 95 // We need the set of displays before we can continue. Wait for it. |
| 96 // | 96 // |
| 97 // TODO(rockot): Do something better here. This should not have to block tasks | 97 // TODO(rockot): Do something better here. This should not have to block tasks |
| 98 // from running on the calling thread. http://crbug.com/594852. | 98 // from running on the calling thread. http://crbug.com/594852. |
| 99 display_manager_observer_binding_.WaitForIncomingMethodCall(); | 99 display_manager_observer_binding_.WaitForIncomingMethodCall(); |
| 100 | 100 |
| 101 // The WaitForIncomingMethodCall() should have supplied the set of Displays, | 101 // The WaitForIncomingMethodCall() should have supplied the set of Displays. |
| 102 // unless mus is going down, in which case encountered_error() is true. | 102 DCHECK(displays_.size()); |
| 103 if (displays_.empty()) { | |
| 104 DCHECK(display_manager_.encountered_error()); | |
| 105 // In this case we install a default display and assume the process is | |
| 106 // going to exit shortly so that the real value doesn't matter. | |
| 107 displays_.push_back(gfx::Display(0xFFFFFFFF, gfx::Rect(0, 0, 801, 802))); | |
| 108 } | |
| 109 } | 103 } |
| 110 | 104 |
| 111 int ScreenMus::FindDisplayIndexById(int64_t id) const { | 105 int ScreenMus::FindDisplayIndexById(int64_t id) const { |
| 112 for (size_t i = 0; i < displays_.size(); ++i) { | 106 for (size_t i = 0; i < displays_.size(); ++i) { |
| 113 if (displays_[i].id() == id) | 107 if (displays_[i].id() == id) |
| 114 return static_cast<int>(i); | 108 return static_cast<int>(i); |
| 115 } | 109 } |
| 116 return -1; | 110 return -1; |
| 117 } | 111 } |
| 118 | 112 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 200 |
| 207 void ScreenMus::RemoveObserver(gfx::DisplayObserver* observer) { | 201 void ScreenMus::RemoveObserver(gfx::DisplayObserver* observer) { |
| 208 observers_.RemoveObserver(observer); | 202 observers_.RemoveObserver(observer); |
| 209 } | 203 } |
| 210 | 204 |
| 211 void ScreenMus::OnDisplays(mojo::Array<mus::mojom::DisplayPtr> displays) { | 205 void ScreenMus::OnDisplays(mojo::Array<mus::mojom::DisplayPtr> displays) { |
| 212 // This should only be called once from Init() before any observers have been | 206 // This should only be called once from Init() before any observers have been |
| 213 // added. | 207 // added. |
| 214 DCHECK(displays_.empty()); | 208 DCHECK(displays_.empty()); |
| 215 displays_ = displays.To<std::vector<gfx::Display>>(); | 209 displays_ = displays.To<std::vector<gfx::Display>>(); |
| 216 DCHECK(!displays_.empty()); | |
| 217 for (size_t i = 0; i < displays.size(); ++i) { | 210 for (size_t i = 0; i < displays.size(); ++i) { |
| 218 if (displays[i]->is_primary) { | 211 if (displays[i]->is_primary) { |
| 219 primary_display_index_ = static_cast<int>(i); | 212 primary_display_index_ = static_cast<int>(i); |
| 220 // TODO(sky): Make WindowManagerFrameValues per display. | 213 // TODO(sky): Make WindowManagerFrameValues per display. |
| 221 WindowManagerFrameValues frame_values = | 214 WindowManagerFrameValues frame_values = |
| 222 displays[i]->frame_decoration_values.To<WindowManagerFrameValues>(); | 215 displays[i]->frame_decoration_values.To<WindowManagerFrameValues>(); |
| 223 WindowManagerFrameValues::SetInstance(frame_values); | 216 WindowManagerFrameValues::SetInstance(frame_values); |
| 224 } | 217 } |
| 225 } | 218 } |
| 226 } | 219 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 245 DCHECK_NE(-1, index); | 238 DCHECK_NE(-1, index); |
| 246 // Another display must become primary before the existing primary is | 239 // Another display must become primary before the existing primary is |
| 247 // removed. | 240 // removed. |
| 248 DCHECK_NE(index, primary_display_index_); | 241 DCHECK_NE(index, primary_display_index_); |
| 249 const gfx::Display display = displays_[index]; | 242 const gfx::Display display = displays_[index]; |
| 250 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, | 243 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, |
| 251 OnDisplayRemoved(display)); | 244 OnDisplayRemoved(display)); |
| 252 } | 245 } |
| 253 | 246 |
| 254 } // namespace views | 247 } // namespace views |
| OLD | NEW |