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