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

Side by Side Diff: ash/display/multi_display_manager.cc

Issue 10905288: Switch primary display (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comment Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/display/multi_display_manager.h" 5 #include "ash/display/multi_display_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/display/display_controller.h" 10 #include "ash/display/display_controller.h"
(...skipping 12 matching lines...) Expand all
23 #if defined(USE_X11) 23 #if defined(USE_X11)
24 #include "ui/base/x/x11_util.h" 24 #include "ui/base/x/x11_util.h"
25 #endif 25 #endif
26 26
27 #if defined(OS_CHROMEOS) 27 #if defined(OS_CHROMEOS)
28 #include "base/chromeos/chromeos_version.h" 28 #include "base/chromeos/chromeos_version.h"
29 #include "chromeos/display/output_configurator.h" 29 #include "chromeos/display/output_configurator.h"
30 #endif 30 #endif
31 31
32 DECLARE_WINDOW_PROPERTY_TYPE(int64); 32 DECLARE_WINDOW_PROPERTY_TYPE(int64);
33 typedef std::vector<gfx::Display> DisplayList;
33 34
34 namespace ash { 35 namespace ash {
35 namespace internal { 36 namespace internal {
36 namespace { 37 namespace {
37 38
39 struct DisplaySortFunctor {
40 bool operator()(const gfx::Display& a, const gfx::Display& b) {
41 return a.id() < b.id();
42 }
43 };
44
38 gfx::Display& GetInvalidDisplay() { 45 gfx::Display& GetInvalidDisplay() {
39 static gfx::Display* invalid_display = new gfx::Display(); 46 static gfx::Display* invalid_display = new gfx::Display();
40 return *invalid_display; 47 return *invalid_display;
41 } 48 }
42 49
50 #if defined(OS_CHROMEOS)
51 int64 GetDisplayIdForOutput(XID output) {
52 uint16 manufacturer_id = 0;
53 uint32 serial_number = 0;
54 ui::GetOutputDeviceData(
55 output, &manufacturer_id, &serial_number, NULL);
56 return gfx::Display::GetID(manufacturer_id, serial_number);
57 }
58 #endif
59
43 } // namespace 60 } // namespace
44 61
45 using aura::RootWindow; 62 using aura::RootWindow;
46 using aura::Window; 63 using aura::Window;
47 using std::string; 64 using std::string;
48 using std::vector; 65 using std::vector;
49 66
50 DEFINE_WINDOW_PROPERTY_KEY(int64, kDisplayIdKey, 67 DEFINE_WINDOW_PROPERTY_KEY(int64, kDisplayIdKey,
51 gfx::Display::kInvalidDisplayID); 68 gfx::Display::kInvalidDisplayID);
52 69
53 MultiDisplayManager::MultiDisplayManager() : 70 MultiDisplayManager::MultiDisplayManager() :
54 internal_display_id_(gfx::Display::kInvalidDisplayID) { 71 internal_display_id_(gfx::Display::kInvalidDisplayID),
72 force_bounds_changed_(false) {
55 Init(); 73 Init();
56 } 74 }
57 75
58 MultiDisplayManager::~MultiDisplayManager() { 76 MultiDisplayManager::~MultiDisplayManager() {
59 } 77 }
60 78
61 // static 79 // static
62 void MultiDisplayManager::CycleDisplay() { 80 void MultiDisplayManager::CycleDisplay() {
63 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( 81 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>(
64 aura::Env::GetInstance()->display_manager()); 82 aura::Env::GetInstance()->display_manager());
65 manager->CycleDisplayImpl(); 83 manager->CycleDisplayImpl();
66 } 84 }
67 85
68 // static 86 // static
69 void MultiDisplayManager::ToggleDisplayScale() { 87 void MultiDisplayManager::ToggleDisplayScale() {
70 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>( 88 MultiDisplayManager* manager = static_cast<MultiDisplayManager*>(
71 aura::Env::GetInstance()->display_manager()); 89 aura::Env::GetInstance()->display_manager());
72 manager->ScaleDisplayImpl(); 90 manager->ScaleDisplayImpl();
73 } 91 }
74 92
75 void MultiDisplayManager::InitInternalDisplayInfo() { 93 bool MultiDisplayManager::IsActiveDisplay(const gfx::Display& display) const {
76 #if defined(OS_CHROMEOS) 94 for (DisplayList::const_iterator iter = displays_.begin();
77 if (!base::chromeos::IsRunningOnChromeOS()) 95 iter != displays_.end(); ++iter) {
78 return; 96 if ((*iter).id() == display.id())
79 std::vector<XID> outputs; 97 return true;
80 ui::GetOutputDeviceHandles(&outputs);
81 std::vector<std::string> output_names = ui::GetOutputNames(outputs);
82 for (size_t i = 0; i < output_names.size(); ++i) {
83 if (chromeos::OutputConfigurator::IsInternalOutputName(
84 output_names[i])) {
85 XID internal_output = outputs[i];
86 uint16 manufacturer_id = 0;
87 uint32 serial_number = 0;
88 ui::GetOutputDeviceData(
89 internal_output, &manufacturer_id, &serial_number, NULL);
90 internal_display_id_ =
91 gfx::Display::GetID(manufacturer_id, serial_number);
92 return;
93 }
94 } 98 }
95 #endif 99 return false;
96 } 100 }
97 101
98 bool MultiDisplayManager::HasInternalDisplay() const { 102 bool MultiDisplayManager::HasInternalDisplay() const {
99 return internal_display_id_ != gfx::Display::kInvalidDisplayID; 103 return internal_display_id_ != gfx::Display::kInvalidDisplayID;
100 } 104 }
101 105
106 bool MultiDisplayManager::IsInternalDisplayId(int64 id) const {
107 return internal_display_id_ == id;
108 }
109
102 bool MultiDisplayManager::UpdateWorkAreaOfDisplayNearestWindow( 110 bool MultiDisplayManager::UpdateWorkAreaOfDisplayNearestWindow(
103 const aura::Window* window, 111 const aura::Window* window,
104 const gfx::Insets& insets) { 112 const gfx::Insets& insets) {
105 const RootWindow* root = window->GetRootWindow(); 113 const RootWindow* root = window->GetRootWindow();
106 gfx::Display& display = FindDisplayForRootWindow(root); 114 gfx::Display& display = FindDisplayForRootWindow(root);
107 gfx::Rect old_work_area = display.work_area(); 115 gfx::Rect old_work_area = display.work_area();
108 display.UpdateWorkAreaFromInsets(insets); 116 display.UpdateWorkAreaFromInsets(insets);
109 return old_work_area != display.work_area(); 117 return old_work_area != display.work_area();
110 } 118 }
111 119
112 const gfx::Display& MultiDisplayManager::FindDisplayContainingPoint( 120 const gfx::Display& MultiDisplayManager::FindDisplayContainingPoint(
113 const gfx::Point& point_in_screen) const { 121 const gfx::Point& point_in_screen) const {
114 for (std::vector<gfx::Display>::const_iterator iter = displays_.begin(); 122 for (DisplayList::const_iterator iter = displays_.begin();
115 iter != displays_.end(); ++iter) { 123 iter != displays_.end(); ++iter) {
116 const gfx::Display& display = *iter; 124 const gfx::Display& display = *iter;
117 if (display.bounds().Contains(point_in_screen)) 125 if (display.bounds().Contains(point_in_screen))
118 return display; 126 return display;
119 } 127 }
120 return GetInvalidDisplay(); 128 return GetInvalidDisplay();
121 } 129 }
122 130
123 void MultiDisplayManager::OnNativeDisplaysChanged( 131 void MultiDisplayManager::OnNativeDisplaysChanged(
124 const std::vector<gfx::Display>& updated_displays) { 132 const std::vector<gfx::Display>& updated_displays) {
125 if (updated_displays.size() == 0) { 133 if (updated_displays.empty()) {
126 // Don't update the displays when all displays are disconnected. 134 // Don't update the displays when all displays are disconnected.
127 // This happens when: 135 // This happens when:
128 // - the device is idle and powerd requested to turn off all displays. 136 // - the device is idle and powerd requested to turn off all displays.
129 // - the device is suspended. (kernel turns off all displays) 137 // - the device is suspended. (kernel turns off all displays)
130 // - the internal display's brightness is set to 0 and no external 138 // - the internal display's brightness is set to 0 and no external
131 // display is connected. 139 // display is connected.
132 // - the internal display's brightness is 0 and external display is 140 // - the internal display's brightness is 0 and external display is
133 // disconnected. 141 // disconnected.
134 // The display will be updated when one of displays is turned on, and the 142 // The display will be updated when one of displays is turned on, and the
135 // display list will be updated correctly. 143 // display list will be updated correctly.
136 return; 144 return;
137 } 145 }
138 std::vector<gfx::Display> new_displays; 146 DisplayList new_displays = updated_displays;
139 if (internal_display_id_ != gfx::Display::kInvalidDisplayID) { 147 if (internal_display_id_ != gfx::Display::kInvalidDisplayID) {
140 bool internal_display_connected = false; 148 bool internal_display_connected = false;
141 for (Displays::const_iterator iter = updated_displays.begin(); 149 for (DisplayList::const_iterator iter = updated_displays.begin();
142 iter != updated_displays.end(); ++iter) { 150 iter != updated_displays.end(); ++iter) {
143 if ((*iter).id() == internal_display_id_) { 151 if ((*iter).id() == internal_display_id_) {
144 internal_display_connected = true; 152 internal_display_connected = true;
145 // Update the internal display cache. 153 // Update the internal display cache.
146 internal_display_.reset(new gfx::Display); 154 internal_display_.reset(new gfx::Display);
147 *internal_display_.get() = *iter; 155 *internal_display_.get() = *iter;
148 break; 156 break;
149 } 157 }
150 } 158 }
151 // If the internal display wasn't connected, use the cached value. 159 // If the internal display wasn't connected, use the cached value.
152 if (!internal_display_connected) 160 if (!internal_display_connected) {
161 // Internal display may be reported as disconnect during startup time.
162 if (!internal_display_.get())
163 internal_display_.reset(new gfx::Display(internal_display_id_));
153 new_displays.push_back(*internal_display_.get()); 164 new_displays.push_back(*internal_display_.get());
154 new_displays.insert( 165 }
155 new_displays.end(), updated_displays.begin(), updated_displays.end());
156 } else { 166 } else {
157 new_displays = updated_displays; 167 new_displays = updated_displays;
158 } 168 }
159 169
160 size_t min = std::min(displays_.size(), new_displays.size()); 170 std::sort(displays_.begin(), displays_.end(), DisplaySortFunctor());
171 std::sort(new_displays.begin(), new_displays.end(), DisplaySortFunctor());
172 DisplayList removed_displays;
173 std::vector<size_t> changed_display_indices;
174 std::vector<size_t> added_display_indices;
161 175
162 // TODO(oshima): Fix this so that we can differentiate outputs 176 for (DisplayList::iterator curr_iter = displays_.begin(),
163 // and keep a content on one display stays on the same display 177 new_iter = new_displays.begin();
164 // when a display is added or removed. 178 curr_iter != displays_.end() || new_iter != new_displays.end();) {
165 for (size_t i = 0; i < min; ++i) { 179 if (curr_iter == displays_.end()) {
166 gfx::Display& current_display = displays_[i]; 180 // more displays in new list.
167 const gfx::Display& new_display = new_displays[i]; 181 added_display_indices.push_back(new_iter - new_displays.begin());
168 if (current_display.bounds_in_pixel() != new_display.bounds_in_pixel() || 182 ++new_iter;
169 current_display.device_scale_factor() != 183 } else if (new_iter == new_displays.end()) {
170 new_display.device_scale_factor()) { 184 // more displays in current list.
171 current_display.SetScaleAndBounds(new_display.device_scale_factor(), 185 removed_displays.push_back(*curr_iter);
172 new_display.bounds_in_pixel()); 186 ++curr_iter;
173 NotifyBoundsChanged(current_display); 187 } else if ((*curr_iter).id() == (*new_iter).id()) {
188 const gfx::Display& current_display = *curr_iter;
189 gfx::Display& new_display = *new_iter;
190 if (force_bounds_changed_ ||
191 current_display.bounds_in_pixel() != new_display.bounds_in_pixel() ||
192 current_display.device_scale_factor() !=
193 new_display.device_scale_factor()) {
194 changed_display_indices.push_back(new_iter - new_displays.begin());
195 }
196 // TODO(oshima): This is ugly. Consolidate following operations
197 // into single update method.
198 new_display.SetScaleAndBounds(
199 new_display.device_scale_factor(),
200 new_display.bounds_in_pixel());
201 // Copy current displays' origin and workarea insets.
202 new_display.set_bounds(gfx::Rect(current_display.bounds().origin(),
203 new_display.bounds().size()));
204 new_display.UpdateWorkAreaFromInsets(current_display.GetWorkAreaInsets());
205 ++curr_iter;
206 ++new_iter;
207 } else if ((*curr_iter).id() < (*new_iter).id()) {
208 // more displays in current list between ids, which means it is deleted.
209 removed_displays.push_back(*curr_iter);
210 ++curr_iter;
211 } else {
212 // more displays in new list between ids, which means it is added.
213 added_display_indices.push_back(new_iter - new_displays.begin());
214 ++new_iter;
174 } 215 }
175 } 216 }
217 displays_ = new_displays;
218 // Temporarily add displays to be removed because display object
219 // being removed are accessed during shutting down the root.
220 displays_.insert(displays_.end(), removed_displays.begin(),
221 removed_displays.end());
222 for (std::vector<size_t>::iterator iter = changed_display_indices.begin();
223 iter != changed_display_indices.end(); ++iter) {
224 NotifyBoundsChanged(displays_[*iter]);
225 }
226 for (std::vector<size_t>::iterator iter = added_display_indices.begin();
227 iter != added_display_indices.end(); ++iter) {
228 NotifyDisplayAdded(displays_[*iter]);
229 }
176 230
177 if (displays_.size() < new_displays.size()) { 231 for (DisplayList::const_reverse_iterator iter = removed_displays.rbegin();
178 // New displays added 232 iter != removed_displays.rend(); ++iter) {
179 for (size_t i = min; i < new_displays.size(); ++i) { 233 NotifyDisplayRemoved(displays_.back());
180 const gfx::Display& new_display = new_displays[i]; 234 displays_.pop_back();
181 displays_.push_back(gfx::Display(new_display.id()));
182 gfx::Display& display = displays_.back();
183 display.SetScaleAndBounds(new_display.device_scale_factor(),
184 new_display.bounds_in_pixel());
185 NotifyDisplayAdded(display);
186 }
187 } else {
188 // Displays are removed. We keep the display for the primary
189 // display (at index 0) because it needs the display information
190 // even if it doesn't exit.
191 while (displays_.size() > new_displays.size() && displays_.size() > 1) {
192 Displays::reverse_iterator iter = displays_.rbegin();
193 NotifyDisplayRemoved(*iter);
194 displays_.erase(iter.base() - 1);
195 }
196 } 235 }
197 } 236 }
198 237
199 RootWindow* MultiDisplayManager::CreateRootWindowForDisplay( 238 RootWindow* MultiDisplayManager::CreateRootWindowForDisplay(
200 const gfx::Display& display) { 239 const gfx::Display& display) {
201 RootWindow* root_window = 240 RootWindow* root_window =
202 new RootWindow(RootWindow::CreateParams(display.bounds_in_pixel())); 241 new RootWindow(RootWindow::CreateParams(display.bounds_in_pixel()));
203 // No need to remove RootWindowObserver because 242 // No need to remove RootWindowObserver because
204 // the DisplayManager object outlives RootWindow objects. 243 // the DisplayManager object outlives RootWindow objects.
205 root_window->AddRootWindowObserver(this); 244 root_window->AddRootWindowObserver(this);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 int area = intersect.width() * intersect.height(); 286 int area = intersect.width() * intersect.height();
248 if (area > max) { 287 if (area > max) {
249 max = area; 288 max = area;
250 matching = &(*iter); 289 matching = &(*iter);
251 } 290 }
252 } 291 }
253 // Fallback to the primary display if there is no matching display. 292 // Fallback to the primary display if there is no matching display.
254 return matching ? *matching : displays_[0]; 293 return matching ? *matching : displays_[0];
255 } 294 }
256 295
257 std::string MultiDisplayManager::GetDisplayNameAt(size_t index) { 296 std::string MultiDisplayManager::GetDisplayNameFor(
297 const gfx::Display& display) {
258 #if defined(USE_X11) 298 #if defined(USE_X11)
259 gfx::Display* display = GetDisplayAt(index);
260 std::vector<XID> outputs; 299 std::vector<XID> outputs;
261 if (display && display->id() != gfx::Display::kInvalidDisplayID && 300 if (display.id() != gfx::Display::kInvalidDisplayID &&
262 ui::GetOutputDeviceHandles(&outputs)) { 301 ui::GetOutputDeviceHandles(&outputs)) {
263 for (size_t i = 0; i < outputs.size(); ++i) { 302 for (size_t i = 0; i < outputs.size(); ++i) {
264 uint16 manufacturer_id = 0; 303 uint16 manufacturer_id = 0;
265 uint32 serial_number = 0; 304 uint32 serial_number = 0;
266 std::string name; 305 std::string name;
267 if (ui::GetOutputDeviceData( 306 if (ui::GetOutputDeviceData(
268 outputs[i], &manufacturer_id, &serial_number, &name) && 307 outputs[i], &manufacturer_id, &serial_number, &name) &&
269 display->id() == 308 display.id() ==
270 gfx::Display::GetID(manufacturer_id, serial_number)) { 309 gfx::Display::GetID(manufacturer_id, serial_number)) {
271 return name; 310 return name;
272 } 311 }
273 } 312 }
274 } 313 }
275 #endif 314 #endif
276 315 return base::StringPrintf("Display %d", static_cast<int>(display.id()));
277 return base::StringPrintf("Display %d", static_cast<int>(index + 1));
278 } 316 }
279 317
280 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root, 318 void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root,
281 const gfx::Size& old_size) { 319 const gfx::Size& old_size) {
282 if (!use_fullscreen_host_window()) { 320 if (!use_fullscreen_host_window()) {
283 gfx::Display& display = FindDisplayForRootWindow(root); 321 gfx::Display& display = FindDisplayForRootWindow(root);
284 if (display.size() != root->GetHostSize()) { 322 if (display.size() != root->GetHostSize()) {
285 display.SetSize(root->GetHostSize()); 323 display.SetSize(root->GetHostSize());
286 NotifyBoundsChanged(display); 324 NotifyBoundsChanged(display);
287 } 325 }
288 } 326 }
289 } 327 }
290 328
291 void MultiDisplayManager::Init() { 329 void MultiDisplayManager::Init() {
330 #if defined(OS_CHROMEOS)
331 if (base::chromeos::IsRunningOnChromeOS()) {
332 std::vector<XID> outputs;
333 ui::GetOutputDeviceHandles(&outputs);
334 std::vector<std::string> output_names = ui::GetOutputNames(outputs);
335 for (size_t i = 0; i < output_names.size(); ++i) {
336 if (chromeos::OutputConfigurator::IsInternalOutputName(
337 output_names[i])) {
338 internal_display_id_ = GetDisplayIdForOutput(outputs[i]);
339 break;
340 }
341 }
342 }
343 #endif
344
292 // TODO(oshima): Move this logic to DisplayChangeObserver. 345 // TODO(oshima): Move this logic to DisplayChangeObserver.
293 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 346 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
294 switches::kAuraHostWindowSize); 347 switches::kAuraHostWindowSize);
295 vector<string> parts; 348 vector<string> parts;
296 base::SplitString(size_str, ',', &parts); 349 base::SplitString(size_str, ',', &parts);
297 for (vector<string>::const_iterator iter = parts.begin(); 350 for (vector<string>::const_iterator iter = parts.begin();
298 iter != parts.end(); ++iter) { 351 iter != parts.end(); ++iter) {
299 AddDisplayFromSpec(*iter); 352 AddDisplayFromSpec(*iter);
300 } 353 }
354 #if defined(OS_CHROMEOS)
355 // Create default display only if it's running on linux desktop.
356 if (displays_.empty() && !base::chromeos::IsRunningOnChromeOS())
357 #else
301 if (displays_.empty()) 358 if (displays_.empty())
359 #endif
302 AddDisplayFromSpec(std::string() /* default */); 360 AddDisplayFromSpec(std::string() /* default */);
303 } 361 }
304 362
305 void MultiDisplayManager::CycleDisplayImpl() { 363 void MultiDisplayManager::CycleDisplayImpl() {
306 std::vector<gfx::Display> new_displays; 364 std::vector<gfx::Display> new_displays;
307 if (displays_.size() > 1) { 365 if (displays_.size() > 1) {
308 // Remove if there is more than one display. 366 // Remove if there is more than one display.
309 int count = displays_.size() - 1; 367 int count = displays_.size() - 1;
310 for (Displays::const_iterator iter = displays_.begin(); count-- > 0; ++iter) 368 for (DisplayList::const_iterator iter = displays_.begin();
369 count-- > 0; ++iter) {
311 new_displays.push_back(*iter); 370 new_displays.push_back(*iter);
371 }
312 } else { 372 } else {
313 // Add if there is only one display. 373 // Add if there is only one display.
314 new_displays.push_back(displays_[0]); 374 new_displays.push_back(displays_[0]);
315 new_displays.push_back(CreateDisplayFromSpec("100+200-500x400")); 375 new_displays.push_back(CreateDisplayFromSpec("100+200-500x400"));
316 } 376 }
317 if (new_displays.size()) 377 if (new_displays.size())
318 OnNativeDisplaysChanged(new_displays); 378 OnNativeDisplaysChanged(new_displays);
319 } 379 }
320 380
321 void MultiDisplayManager::ScaleDisplayImpl() { 381 void MultiDisplayManager::ScaleDisplayImpl() {
322 if (displays_.size() > 0) { 382 if (displays_.size() > 0) {
323 std::vector<gfx::Display> new_displays; 383 std::vector<gfx::Display> new_displays;
324 for (Displays::const_iterator iter = displays_.begin(); 384 for (DisplayList::const_iterator iter = displays_.begin();
325 iter != displays_.end(); ++iter) { 385 iter != displays_.end(); ++iter) {
326 gfx::Display display = *iter; 386 gfx::Display display = *iter;
327 float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f; 387 float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f;
328 display.SetScaleAndBounds( 388 display.SetScaleAndBounds(
329 factor, gfx::Rect(display.bounds_in_pixel().origin(), 389 factor, gfx::Rect(display.bounds_in_pixel().origin(),
330 display.size().Scale(factor))); 390 display.size().Scale(factor)));
331 new_displays.push_back(display); 391 new_displays.push_back(display);
332 } 392 }
333 OnNativeDisplaysChanged(new_displays); 393 OnNativeDisplaysChanged(new_displays);
334 } 394 }
335 } 395 }
336 396
337 gfx::Display& MultiDisplayManager::FindDisplayForRootWindow( 397 gfx::Display& MultiDisplayManager::FindDisplayForRootWindow(
338 const aura::RootWindow* root_window) { 398 const aura::RootWindow* root_window) {
339 int64 id = root_window->GetProperty(kDisplayIdKey); 399 int64 id = root_window->GetProperty(kDisplayIdKey);
340 // if id is |kInvaildDisplayID|, it's being deleted. 400 // if id is |kInvaildDisplayID|, it's being deleted.
341 DCHECK(id != gfx::Display::kInvalidDisplayID); 401 DCHECK(id != gfx::Display::kInvalidDisplayID);
342 for (Displays::iterator iter = displays_.begin(); 402 return FindDisplayForId(id);
403 }
404
405 gfx::Display& MultiDisplayManager::FindDisplayForId(int64 id) {
406 for (DisplayList::iterator iter = displays_.begin();
343 iter != displays_.end(); ++iter) { 407 iter != displays_.end(); ++iter) {
344 if ((*iter).id() == id) 408 if ((*iter).id() == id)
345 return *iter; 409 return *iter;
346 } 410 }
347 DLOG(FATAL) << "Could not find display by id:" << id; 411 DLOG(FATAL) << "Could not find display:" << id;
348 return GetInvalidDisplay(); 412 return GetInvalidDisplay();
349 } 413 }
350 414
351 void MultiDisplayManager::AddDisplayFromSpec(const std::string& spec) { 415 void MultiDisplayManager::AddDisplayFromSpec(const std::string& spec) {
352 gfx::Display display = CreateDisplayFromSpec(spec); 416 gfx::Display display = CreateDisplayFromSpec(spec);
353 417
354 const gfx::Insets insets = display.GetWorkAreaInsets(); 418 const gfx::Insets insets = display.GetWorkAreaInsets();
355 const gfx::Rect& native_bounds = display.bounds_in_pixel(); 419 const gfx::Rect& native_bounds = display.bounds_in_pixel();
356 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds); 420 display.SetScaleAndBounds(display.device_scale_factor(), native_bounds);
357 display.UpdateWorkAreaFromInsets(insets); 421 display.UpdateWorkAreaFromInsets(insets);
358 displays_.push_back(display); 422 displays_.push_back(display);
359 } 423 }
360 424
361 int64 MultiDisplayManager::EnableInternalDisplayForTest() { 425 int64 MultiDisplayManager::SetFirstDisplayAsInternalDisplayForTest() {
362 const int64 kInternalDisplayIdForTest = 9999; 426 internal_display_id_ = displays_[0].id();
363 internal_display_id_ = kInternalDisplayIdForTest; 427 internal_display_.reset(new gfx::Display);
364 internal_display_.reset(new gfx::Display(internal_display_id_, 428 *internal_display_ = displays_[0];
365 gfx::Rect(800, 600))); 429 return internal_display_id_;
366 return kInternalDisplayIdForTest; 430 }
431
432 void MultiDisplayManager::SetDisplayIdsForTest(DisplayList* to_update) const {
433 DisplayList::iterator iter_to_update = to_update->begin();
434 DisplayList::const_iterator iter = displays_.begin();
435 for (; iter != displays_.end() && iter_to_update != to_update->end();
436 ++iter, ++iter_to_update) {
437 (*iter_to_update).set_id((*iter).id());
438 }
367 } 439 }
368 440
369 } // namespace internal 441 } // namespace internal
370 } // namespace ash 442 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698