| 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 | 16 |
| 16 namespace display { | 17 namespace display { |
| 17 | 18 |
| 18 namespace { | |
| 19 | |
| 20 // TODO(kylechar): Move these to ui/display/chromeos/display_util.cc/h. | |
| 21 bool CompareDisplayIds(int64_t id1, int64_t id2) { | |
| 22 DCHECK_NE(id1, id2); | |
| 23 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID | |
| 24 // in edid_parser.cc. | |
| 25 int index_1 = id1 & 0xFF; | |
| 26 int index_2 = id2 & 0xFF; | |
| 27 DCHECK_NE(index_1, index_2) << id1 << " and " << id2; | |
| 28 return Display::IsInternalDisplayId(id1) || | |
| 29 (index_1 < index_2 && !Display::IsInternalDisplayId(id2)); | |
| 30 } | |
| 31 | |
| 32 std::string DisplayIdListToString(const DisplayIdList& list) { | |
| 33 std::stringstream s; | |
| 34 const char* sep = ""; | |
| 35 for (int64_t id : list) { | |
| 36 s << sep << id; | |
| 37 sep = ","; | |
| 38 } | |
| 39 return s.str(); | |
| 40 } | |
| 41 | |
| 42 } // namespace | |
| 43 | |
| 44 DisplayLayoutStore::DisplayLayoutStore() | 19 DisplayLayoutStore::DisplayLayoutStore() |
| 45 : default_display_placement_(display::DisplayPlacement::RIGHT, 0) { | 20 : default_display_placement_(display::DisplayPlacement::RIGHT, 0) { |
| 46 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 21 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 47 if (command_line->HasSwitch(switches::kSecondaryDisplayLayout)) { | 22 if (command_line->HasSwitch(switches::kSecondaryDisplayLayout)) { |
| 48 std::string value = | 23 std::string value = |
| 49 command_line->GetSwitchValueASCII(switches::kSecondaryDisplayLayout); | 24 command_line->GetSwitchValueASCII(switches::kSecondaryDisplayLayout); |
| 50 char layout; | 25 char layout; |
| 51 int offset = 0; | 26 int offset = 0; |
| 52 if (sscanf(value.c_str(), "%c,%d", &layout, &offset) == 2) { | 27 if (sscanf(value.c_str(), "%c,%d", &layout, &offset) == 2) { |
| 53 if (layout == 't') | 28 if (layout == 't') |
| (...skipping 20 matching lines...) Expand all Loading... |
| 74 | 49 |
| 75 void DisplayLayoutStore::RegisterLayoutForDisplayIdList( | 50 void DisplayLayoutStore::RegisterLayoutForDisplayIdList( |
| 76 const display::DisplayIdList& list, | 51 const display::DisplayIdList& list, |
| 77 std::unique_ptr<display::DisplayLayout> layout) { | 52 std::unique_ptr<display::DisplayLayout> layout) { |
| 78 // 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. |
| 79 // TODO(oshima): Consider removing this after m53. | 54 // TODO(oshima): Consider removing this after m53. |
| 80 if (list.size() == 2 && layout->placement_list.size() > 1) | 55 if (list.size() == 2 && layout->placement_list.size() > 1) |
| 81 return; | 56 return; |
| 82 | 57 |
| 83 // Do not overwrite the valid data with old invalid date. | 58 // Do not overwrite the valid data with old invalid date. |
| 84 if (layouts_.count(list) && !CompareDisplayIds(list[0], list[1])) | 59 if (layouts_.count(list) && !ui::CompareDisplayIds(list[0], list[1])) |
| 85 return; | 60 return; |
| 86 | 61 |
| 87 // Old data may not have the display_id/parent_display_id. | 62 // Old data may not have the display_id/parent_display_id. |
| 88 // Guess these values based on the saved primary_id. | 63 // Guess these values based on the saved primary_id. |
| 89 if (layout->placement_list.size() >= 1 && | 64 if (layout->placement_list.size() >= 1 && |
| 90 layout->placement_list[0].display_id == | 65 layout->placement_list[0].display_id == |
| 91 display::Display::kInvalidDisplayID) { | 66 display::Display::kInvalidDisplayID) { |
| 92 if (layout->primary_id == list[1]) { | 67 if (layout->primary_id == list[1]) { |
| 93 layout->placement_list[0].display_id = list[0]; | 68 layout->placement_list[0].display_id = list[0]; |
| 94 layout->placement_list[0].parent_display_id = list[1]; | 69 layout->placement_list[0].parent_display_id = list[1]; |
| 95 } else { | 70 } else { |
| 96 layout->placement_list[0].display_id = list[1]; | 71 layout->placement_list[0].display_id = list[1]; |
| 97 layout->placement_list[0].parent_display_id = list[0]; | 72 layout->placement_list[0].parent_display_id = list[0]; |
| 98 } | 73 } |
| 99 } | 74 } |
| 100 DCHECK(display::DisplayLayout::Validate(list, *layout.get())) | 75 DCHECK(display::DisplayLayout::Validate(list, *layout.get())) |
| 101 << "ids=" << DisplayIdListToString(list) | 76 << "ids=" << ui::DisplayIdListToString(list) |
| 102 << ", layout=" << layout->ToString(); | 77 << ", layout=" << layout->ToString(); |
| 103 layouts_[list] = std::move(layout); | 78 layouts_[list] = std::move(layout); |
| 104 } | 79 } |
| 105 | 80 |
| 106 const display::DisplayLayout& DisplayLayoutStore::GetRegisteredDisplayLayout( | 81 const display::DisplayLayout& DisplayLayoutStore::GetRegisteredDisplayLayout( |
| 107 const display::DisplayIdList& list) { | 82 const display::DisplayIdList& list) { |
| 108 DCHECK_NE(1u, list.size()); | 83 DCHECK_NE(1u, list.size()); |
| 109 const auto iter = layouts_.find(list); | 84 const auto iter = layouts_.find(list); |
| 110 const display::DisplayLayout* layout = iter != layouts_.end() | 85 const display::DisplayLayout* layout = iter != layouts_.end() |
| 111 ? iter->second.get() | 86 ? iter->second.get() |
| (...skipping 26 matching lines...) Expand all Loading... |
| 138 placement.display_id = list[i + 1]; | 113 placement.display_id = list[i + 1]; |
| 139 placement.parent_display_id = list[i]; | 114 placement.parent_display_id = list[i]; |
| 140 layout->placement_list.push_back(placement); | 115 layout->placement_list.push_back(placement); |
| 141 } | 116 } |
| 142 layouts_[list] = std::move(layout); | 117 layouts_[list] = std::move(layout); |
| 143 auto iter = layouts_.find(list); | 118 auto iter = layouts_.find(list); |
| 144 return iter->second.get(); | 119 return iter->second.get(); |
| 145 } | 120 } |
| 146 | 121 |
| 147 } // namespace display | 122 } // namespace display |
| OLD | NEW |