| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stdio.h> | 5 #include <stdio.h> |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/display/display_layout_store.h" | 8 #include "ash/display/display_layout_store.h" |
| 9 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
| 10 #include "ash/display/display_util.h" | 10 #include "ash/display/display_util.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "ui/gfx/display.h" | 14 #include "ui/gfx/display.h" |
| 15 | 15 |
| 16 namespace ash { | 16 namespace ash { |
| 17 | 17 |
| 18 DisplayLayoutStore::DisplayLayoutStore() | 18 DisplayLayoutStore::DisplayLayoutStore() |
| 19 : default_display_placement_(DisplayPlacement::RIGHT, 0) { | 19 : default_display_placement_(display::DisplayPlacement::RIGHT, 0) { |
| 20 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 20 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 21 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) { | 21 if (command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) { |
| 22 std::string value = command_line->GetSwitchValueASCII( | 22 std::string value = command_line->GetSwitchValueASCII( |
| 23 switches::kAshSecondaryDisplayLayout); | 23 switches::kAshSecondaryDisplayLayout); |
| 24 char layout; | 24 char layout; |
| 25 int offset = 0; | 25 int offset = 0; |
| 26 if (sscanf(value.c_str(), "%c,%d", &layout, &offset) == 2) { | 26 if (sscanf(value.c_str(), "%c,%d", &layout, &offset) == 2) { |
| 27 if (layout == 't') | 27 if (layout == 't') |
| 28 default_display_placement_.position = DisplayPlacement::TOP; | 28 default_display_placement_.position = display::DisplayPlacement::TOP; |
| 29 else if (layout == 'b') | 29 else if (layout == 'b') |
| 30 default_display_placement_.position = DisplayPlacement::BOTTOM; | 30 default_display_placement_.position = display::DisplayPlacement::BOTTOM; |
| 31 else if (layout == 'r') | 31 else if (layout == 'r') |
| 32 default_display_placement_.position = DisplayPlacement::RIGHT; | 32 default_display_placement_.position = display::DisplayPlacement::RIGHT; |
| 33 else if (layout == 'l') | 33 else if (layout == 'l') |
| 34 default_display_placement_.position = DisplayPlacement::LEFT; | 34 default_display_placement_.position = display::DisplayPlacement::LEFT; |
| 35 default_display_placement_.offset = offset; | 35 default_display_placement_.offset = offset; |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 DisplayLayoutStore::~DisplayLayoutStore() { | 40 DisplayLayoutStore::~DisplayLayoutStore() { |
| 41 } | 41 } |
| 42 | 42 |
| 43 void DisplayLayoutStore::SetDefaultDisplayPlacement( | 43 void DisplayLayoutStore::SetDefaultDisplayPlacement( |
| 44 const DisplayPlacement& placement) { | 44 const display::DisplayPlacement& placement) { |
| 45 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 45 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 46 if (!command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) | 46 if (!command_line->HasSwitch(switches::kAshSecondaryDisplayLayout)) |
| 47 default_display_placement_ = placement; | 47 default_display_placement_ = placement; |
| 48 } | 48 } |
| 49 | 49 |
| 50 void DisplayLayoutStore::RegisterLayoutForDisplayIdList( | 50 void DisplayLayoutStore::RegisterLayoutForDisplayIdList( |
| 51 const DisplayIdList& list, | 51 const display::DisplayIdList& list, |
| 52 scoped_ptr<DisplayLayout> layout) { | 52 scoped_ptr<display::DisplayLayout> layout) { |
| 53 // m50/51 dev/beta channel may have bad layout data saved in local state. | 53 // m50/51 dev/beta channel may have bad layout data saved in local state. |
| 54 // TODO(oshima): Consider removing this after m53. | 54 // TODO(oshima): Consider removing this after m53. |
| 55 if (list.size() == 2 && layout->placement_list.size() > 1) | 55 if (list.size() == 2 && layout->placement_list.size() > 1) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 // Do not overwrite the valid data with old invalid date. | 58 // Do not overwrite the valid data with old invalid date. |
| 59 if (layouts_.count(list) && !CompareDisplayIds(list[0], list[1])) | 59 if (layouts_.count(list) && !CompareDisplayIds(list[0], list[1])) |
| 60 return; | 60 return; |
| 61 | 61 |
| 62 // Old data may not have the display_id/parent_display_id. | 62 // Old data may not have the display_id/parent_display_id. |
| 63 // Guess these values based on the saved primary_id. | 63 // Guess these values based on the saved primary_id. |
| 64 if (layout->placement_list.size() >= 1 && | 64 if (layout->placement_list.size() >= 1 && |
| 65 layout->placement_list[0].display_id == gfx::Display::kInvalidDisplayID) { | 65 layout->placement_list[0].display_id == gfx::Display::kInvalidDisplayID) { |
| 66 if (layout->primary_id == list[1]) { | 66 if (layout->primary_id == list[1]) { |
| 67 layout->placement_list[0].display_id = list[0]; | 67 layout->placement_list[0].display_id = list[0]; |
| 68 layout->placement_list[0].parent_display_id = list[1]; | 68 layout->placement_list[0].parent_display_id = list[1]; |
| 69 } else { | 69 } else { |
| 70 layout->placement_list[0].display_id = list[1]; | 70 layout->placement_list[0].display_id = list[1]; |
| 71 layout->placement_list[0].parent_display_id = list[0]; | 71 layout->placement_list[0].parent_display_id = list[0]; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 DCHECK(DisplayLayout::Validate(list, *layout.get())) | 74 DCHECK(display::DisplayLayout::Validate(list, *layout.get())) |
| 75 << "ids=" << DisplayIdListToString(list) | 75 << "ids=" << DisplayIdListToString(list) |
| 76 << ", layout=" << layout->ToString(); | 76 << ", layout=" << layout->ToString(); |
| 77 layouts_[list] = std::move(layout); | 77 layouts_[list] = std::move(layout); |
| 78 } | 78 } |
| 79 | 79 |
| 80 const DisplayLayout& DisplayLayoutStore::GetRegisteredDisplayLayout( | 80 const display::DisplayLayout& DisplayLayoutStore::GetRegisteredDisplayLayout( |
| 81 const DisplayIdList& list) { | 81 const display::DisplayIdList& list) { |
| 82 DCHECK_NE(1u, list.size()); | 82 DCHECK_NE(1u, list.size()); |
| 83 const auto iter = layouts_.find(list); | 83 const auto iter = layouts_.find(list); |
| 84 const DisplayLayout* layout = iter != layouts_.end() | 84 const display::DisplayLayout* layout = iter != layouts_.end() |
| 85 ? iter->second.get() | 85 ? iter->second.get() |
| 86 : CreateDefaultDisplayLayout(list); | 86 : CreateDefaultDisplayLayout(list); |
| 87 DCHECK(DisplayLayout::Validate(list, *layout)) << layout->ToString(); | 87 DCHECK(display::DisplayLayout::Validate(list, *layout)) << layout->ToString(); |
| 88 DCHECK_NE(layout->primary_id, gfx::Display::kInvalidDisplayID); | 88 DCHECK_NE(layout->primary_id, gfx::Display::kInvalidDisplayID); |
| 89 return *layout; | 89 return *layout; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void DisplayLayoutStore::UpdateMultiDisplayState(const DisplayIdList& list, | 92 void DisplayLayoutStore::UpdateMultiDisplayState( |
| 93 bool mirrored, | 93 const display::DisplayIdList& list, |
| 94 bool default_unified) { | 94 bool mirrored, |
| 95 bool default_unified) { |
| 95 DCHECK(layouts_.find(list) != layouts_.end()); | 96 DCHECK(layouts_.find(list) != layouts_.end()); |
| 96 if (layouts_.find(list) == layouts_.end()) | 97 if (layouts_.find(list) == layouts_.end()) |
| 97 CreateDefaultDisplayLayout(list); | 98 CreateDefaultDisplayLayout(list); |
| 98 | 99 |
| 99 layouts_[list]->mirrored = mirrored; | 100 layouts_[list]->mirrored = mirrored; |
| 100 layouts_[list]->default_unified = default_unified; | 101 layouts_[list]->default_unified = default_unified; |
| 101 } | 102 } |
| 102 | 103 |
| 103 DisplayLayout* DisplayLayoutStore::CreateDefaultDisplayLayout( | 104 display::DisplayLayout* DisplayLayoutStore::CreateDefaultDisplayLayout( |
| 104 const DisplayIdList& list) { | 105 const display::DisplayIdList& list) { |
| 105 scoped_ptr<DisplayLayout> layout(new DisplayLayout); | 106 scoped_ptr<display::DisplayLayout> layout(new display::DisplayLayout); |
| 106 // The first display is the primary by default. | 107 // The first display is the primary by default. |
| 107 layout->primary_id = list[0]; | 108 layout->primary_id = list[0]; |
| 108 layout->placement_list.clear(); | 109 layout->placement_list.clear(); |
| 109 for (size_t i = 0; i < list.size() - 1; i++) { | 110 for (size_t i = 0; i < list.size() - 1; i++) { |
| 110 DisplayPlacement placement(default_display_placement_); | 111 display::DisplayPlacement placement(default_display_placement_); |
| 111 placement.display_id = list[i + 1]; | 112 placement.display_id = list[i + 1]; |
| 112 placement.parent_display_id = list[i]; | 113 placement.parent_display_id = list[i]; |
| 113 layout->placement_list.push_back(placement); | 114 layout->placement_list.push_back(placement); |
| 114 } | 115 } |
| 115 layouts_[list] = std::move(layout); | 116 layouts_[list] = std::move(layout); |
| 116 auto iter = layouts_.find(list); | 117 auto iter = layouts_.find(list); |
| 117 return iter->second.get(); | 118 return iter->second.get(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 } // namespace ash | 121 } // namespace ash |
| OLD | NEW |