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

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

Issue 1263853002: Unified Desktop: Support 2xDSF display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix test Created 5 years, 4 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
« no previous file with comments | « ash/accelerators/accelerator_controller.cc ('k') | ash/display/display_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/display_manager.h" 5 #include "ash/display/display_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <utility>
11 #include <vector> 12 #include <vector>
12 13
13 #include "ash/ash_switches.h" 14 #include "ash/ash_switches.h"
14 #include "ash/display/display_layout_store.h" 15 #include "ash/display/display_layout_store.h"
15 #include "ash/display/display_util.h" 16 #include "ash/display/display_util.h"
16 #include "ash/display/extended_mouse_warp_controller.h" 17 #include "ash/display/extended_mouse_warp_controller.h"
17 #include "ash/display/null_mouse_warp_controller.h" 18 #include "ash/display/null_mouse_warp_controller.h"
18 #include "ash/display/screen_ash.h" 19 #include "ash/display/screen_ash.h"
19 #include "ash/display/unified_mouse_warp_controller.h" 20 #include "ash/display/unified_mouse_warp_controller.h"
20 #include "ash/screen_util.h" 21 #include "ash/screen_util.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 bool operator()(const DisplayInfo& a, const DisplayInfo& b) { 77 bool operator()(const DisplayInfo& a, const DisplayInfo& b) {
77 return a.id() < b.id(); 78 return a.id() < b.id();
78 } 79 }
79 }; 80 };
80 81
81 gfx::Display& GetInvalidDisplay() { 82 gfx::Display& GetInvalidDisplay() {
82 static gfx::Display* invalid_display = new gfx::Display(); 83 static gfx::Display* invalid_display = new gfx::Display();
83 return *invalid_display; 84 return *invalid_display;
84 } 85 }
85 86
87 template <typename F>
88 std::vector<DisplayMode>::const_iterator FindDisplayModeL(
Jun Mukai 2015/07/30 17:11:11 I am not sure what is the benefit of defining this
oshima 2015/07/30 18:43:28 Thanks for the catch. I was going to clean up but
89 const DisplayInfo& info,
90 F function) {
91 const std::vector<DisplayMode>& modes = info.display_modes();
92 return std::find_if(modes.begin(), modes.end(), function);
93 }
94
86 std::vector<DisplayMode>::const_iterator FindDisplayMode( 95 std::vector<DisplayMode>::const_iterator FindDisplayMode(
87 const DisplayInfo& info, 96 const DisplayInfo& info,
88 const DisplayMode& target_mode) { 97 const DisplayMode& target_mode) {
89 const std::vector<DisplayMode>& modes = info.display_modes(); 98 return FindDisplayModeL(info, [target_mode](const DisplayMode& mode) {
90 return std::find_if(modes.begin(), modes.end(), 99 return target_mode.IsEquivalent(mode);
91 [target_mode](const DisplayMode& mode) { 100 });
92 return target_mode.IsEquivalent(mode);
93 });
94 } 101 }
95 102
96 void SetInternalDisplayModeList(DisplayInfo* info) { 103 void SetInternalDisplayModeList(DisplayInfo* info) {
97 DisplayMode native_mode; 104 DisplayMode native_mode;
98 native_mode.size = info->bounds_in_native().size(); 105 native_mode.size = info->bounds_in_native().size();
99 native_mode.device_scale_factor = info->device_scale_factor(); 106 native_mode.device_scale_factor = info->device_scale_factor();
100 native_mode.ui_scale = 1.0f; 107 native_mode.ui_scale = 1.0f;
101 info->SetDisplayModes(CreateInternalDisplayModeList(native_mode)); 108 info->SetDisplayModes(CreateInternalDisplayModeList(native_mode));
102 } 109 }
103 110
104 void MaybeInitInternalDisplay(DisplayInfo* info) { 111 void MaybeInitInternalDisplay(DisplayInfo* info) {
105 int64 id = info->id(); 112 int64 id = info->id();
106 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 113 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
107 if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal)) { 114 if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal)) {
108 gfx::Display::SetInternalDisplayId(id); 115 gfx::Display::SetInternalDisplayId(id);
109 SetInternalDisplayModeList(info); 116 SetInternalDisplayModeList(info);
110 } 117 }
111 } 118 }
112 119
120 gfx::Size GetMaxNativeSize(const DisplayInfo& info) {
121 gfx::Size size;
122 for (auto& mode : info.display_modes()) {
123 if (mode.size.GetArea() > size.GetArea())
124 size = mode.size;
125 }
126 return size;
127 }
128
113 } // namespace 129 } // namespace
114 130
115 using std::string; 131 using std::string;
116 using std::vector; 132 using std::vector;
117 133
118 // static 134 // static
119 int64 DisplayManager::kUnifiedDisplayId = -10; 135 int64 DisplayManager::kUnifiedDisplayId = -10;
120 136
121 DisplayManager::DisplayManager() 137 DisplayManager::DisplayManager()
122 : delegate_(NULL), 138 : delegate_(NULL),
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 DisplayMode selected_mode; 462 DisplayMode selected_mode;
447 if (GetSelectedModeForDisplayId(display_id, &selected_mode)) 463 if (GetSelectedModeForDisplayId(display_id, &selected_mode))
448 return selected_mode; 464 return selected_mode;
449 465
450 // If 'selected' mode is empty, it should return the default mode. This means 466 // If 'selected' mode is empty, it should return the default mode. This means
451 // the native mode for the external display. Unfortunately this is not true 467 // the native mode for the external display. Unfortunately this is not true
452 // for the internal display because restoring UI-scale doesn't register the 468 // for the internal display because restoring UI-scale doesn't register the
453 // restored mode to |display_mode_|, so it needs to look up the mode whose 469 // restored mode to |display_mode_|, so it needs to look up the mode whose
454 // UI-scale value matches. See the TODO in RegisterDisplayProperty(). 470 // UI-scale value matches. See the TODO in RegisterDisplayProperty().
455 const DisplayInfo& info = GetDisplayInfo(display_id); 471 const DisplayInfo& info = GetDisplayInfo(display_id);
456 const std::vector<DisplayMode>& display_modes = info.display_modes();
457 472
458 if (GetDisplayIdForUIScaling() == display_id) { 473 for (auto& mode : info.display_modes()) {
459 for (size_t i = 0; i < display_modes.size(); ++i) { 474 if (GetDisplayIdForUIScaling() == display_id) {
460 if (info.configured_ui_scale() == display_modes[i].ui_scale) 475 if (info.configured_ui_scale() == mode.ui_scale)
461 return display_modes[i]; 476 return mode;
462 } 477 } else if (mode.native) {
463 } else { 478 return mode;
464 for (size_t i = 0; i < display_modes.size(); ++i) {
465 if (display_modes[i].native)
466 return display_modes[i];
467 } 479 }
468 } 480 }
469 return selected_mode; 481 return selected_mode;
470 } 482 }
471 483
472 void DisplayManager::RegisterDisplayRotationProperties(bool rotation_lock, 484 void DisplayManager::RegisterDisplayRotationProperties(bool rotation_lock,
473 gfx::Display::Rotation rotation) { 485 gfx::Display::Rotation rotation) {
474 if (delegate_) 486 if (delegate_)
475 delegate_->PreDisplayConfigurationChange(false); 487 delegate_->PreDisplayConfigurationChange(false);
476 registered_internal_display_rotation_lock_ = rotation_lock; 488 registered_internal_display_rotation_lock_ = rotation_lock;
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 } 1119 }
1108 case UNIFIED: { 1120 case UNIFIED: {
1109 // TODO(oshima): Currently, all displays are laid out horizontally, 1121 // TODO(oshima): Currently, all displays are laid out horizontally,
1110 // from left to right. Allow more flexible layouts, such as 1122 // from left to right. Allow more flexible layouts, such as
1111 // right to left, or vertical layouts. 1123 // right to left, or vertical layouts.
1112 gfx::Rect unified_bounds; 1124 gfx::Rect unified_bounds;
1113 software_mirroring_display_list_.clear(); 1125 software_mirroring_display_list_.clear();
1114 1126
1115 // 1st Pass. Find the max size. 1127 // 1st Pass. Find the max size.
1116 int max_height = std::numeric_limits<int>::min(); 1128 int max_height = std::numeric_limits<int>::min();
1117 for (auto& info : *display_info_list) 1129
1130 int default_height = 0;
1131 float default_device_scale_factor = 1.0f;
1132 for (auto& info : *display_info_list) {
1118 max_height = std::max(max_height, info.size_in_pixel().height()); 1133 max_height = std::max(max_height, info.size_in_pixel().height());
1134 if (!default_height || gfx::Display::IsInternalDisplayId(info.id())) {
1135 default_height = info.size_in_pixel().height();
1136 default_device_scale_factor = info.device_scale_factor();
1137 }
1138 }
1119 1139
1120 std::vector<DisplayMode> display_mode_list; 1140 std::vector<DisplayMode> display_mode_list;
1121 std::set<float> scales; 1141 std::set<std::pair<float, float>> dsf_scale_list;
1122 1142
1123 // 2nd Pass. Compute the unified display size. 1143 // 2nd Pass. Compute the unified display size.
1124 for (auto& info : *display_info_list) { 1144 for (auto& info : *display_info_list) {
1125 InsertAndUpdateDisplayInfo(info); 1145 InsertAndUpdateDisplayInfo(info);
1126 gfx::Point origin(unified_bounds.right(), 0); 1146 gfx::Point origin(unified_bounds.right(), 0);
1127 float scale = 1147 float scale =
1128 info.size_in_pixel().height() / static_cast<float>(max_height); 1148 info.size_in_pixel().height() / static_cast<float>(max_height);
1129 // The display is scaled to fit the unified desktop size. 1149 // The display is scaled to fit the unified desktop size.
1130 gfx::Display display = CreateMirroringDisplayFromDisplayInfoById( 1150 gfx::Display display = CreateMirroringDisplayFromDisplayInfoById(
1131 info.id(), origin, 1.0f / scale); 1151 info.id(), origin, 1.0f / scale);
1132 unified_bounds.Union(display.bounds()); 1152 unified_bounds.Union(display.bounds());
1133 1153
1134 scales.insert(scale); 1154 dsf_scale_list.insert(
1155 std::make_pair(info.device_scale_factor(), scale));
1135 } 1156 }
1136 1157
1137 DisplayInfo info(kUnifiedDisplayId, "Unified Desktop", false); 1158 DisplayInfo info(kUnifiedDisplayId, "Unified Desktop", false);
1138 info.SetBounds(unified_bounds);
1139 1159
1140 DisplayMode native_mode(unified_bounds.size(), 60.0f, false, true); 1160 DisplayMode native_mode(unified_bounds.size(), 60.0f, false, true);
1141 info.SetDisplayModes(CreateUnifiedDisplayModeList(native_mode, scales)); 1161 std::vector<DisplayMode> modes =
1162 CreateUnifiedDisplayModeList(native_mode, dsf_scale_list);
1163
1164 // Find the default mode.
1165 auto iter = std::find_if(
1166 modes.begin(), modes.end(),
1167 [default_height,
1168 default_device_scale_factor](const DisplayMode& mode) {
1169 return mode.size.height() == default_height &&
1170 mode.device_scale_factor == default_device_scale_factor;
1171 });
1172 iter->native = true;
1173 info.SetDisplayModes(modes);
1174 info.set_device_scale_factor(iter->device_scale_factor);
1175 info.SetBounds(gfx::Rect(iter->size));
1142 1176
1143 // Forget the configured resolution if the original unified 1177 // Forget the configured resolution if the original unified
1144 // desktop resolution has changed. 1178 // desktop resolution has changed.
1145 if (display_info_.count(kUnifiedDisplayId) != 0 && 1179 if (display_info_.count(kUnifiedDisplayId) != 0 &&
1146 display_info_[kUnifiedDisplayId].size_in_pixel() != 1180 GetMaxNativeSize(display_info_[kUnifiedDisplayId]) !=
1147 info.size_in_pixel()) { 1181 unified_bounds.size()) {
1148 display_modes_.erase(kUnifiedDisplayId); 1182 display_modes_.erase(kUnifiedDisplayId);
1149 } 1183 }
1150 1184
1151 // 3rd Pass. Set the selected mode, then recompute the mirroring 1185 // 3rd Pass. Set the selected mode, then recompute the mirroring
1152 // display size. 1186 // display size.
1153 DisplayMode mode; 1187 DisplayMode mode;
1154 if (GetSelectedModeForDisplayId(kUnifiedDisplayId, &mode) && 1188 if (GetSelectedModeForDisplayId(kUnifiedDisplayId, &mode) &&
1155 FindDisplayMode(info, mode) != info.display_modes().end()) { 1189 FindDisplayMode(info, mode) != info.display_modes().end()) {
1156 // TODO(oshima): device scale factor. 1190 info.set_device_scale_factor(mode.device_scale_factor);
1157 info.SetBounds(gfx::Rect(mode.size)); 1191 info.SetBounds(gfx::Rect(mode.size));
1158 } else { 1192 } else {
1159 display_modes_.erase(kUnifiedDisplayId); 1193 display_modes_.erase(kUnifiedDisplayId);
1160 } 1194 }
1161 1195
1162 int unified_display_height = info.size_in_pixel().height(); 1196 int unified_display_height = info.size_in_pixel().height();
1163 gfx::Point origin; 1197 gfx::Point origin;
1164 for (auto& info : *display_info_list) { 1198 for (auto& info : *display_info_list) {
1165 float display_scale = info.size_in_pixel().height() / 1199 float display_scale = info.size_in_pixel().height() /
1166 static_cast<float>(unified_display_height); 1200 static_cast<float>(unified_display_height);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1367 gfx::Rect(new_secondary_origin, secondary_bounds.size())); 1401 gfx::Rect(new_secondary_origin, secondary_bounds.size()));
1368 secondary_display->UpdateWorkAreaFromInsets(insets); 1402 secondary_display->UpdateWorkAreaFromInsets(insets);
1369 } 1403 }
1370 1404
1371 void DisplayManager::RunPendingTasksForTest() { 1405 void DisplayManager::RunPendingTasksForTest() {
1372 if (!software_mirroring_display_list_.empty()) 1406 if (!software_mirroring_display_list_.empty())
1373 base::RunLoop().RunUntilIdle(); 1407 base::RunLoop().RunUntilIdle();
1374 } 1408 }
1375 1409
1376 } // namespace ash 1410 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_controller.cc ('k') | ash/display/display_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698