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

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: 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 104
104 void MaybeInitInternalDisplay(DisplayInfo* info) { 105 void MaybeInitInternalDisplay(DisplayInfo* info) {
105 int64 id = info->id(); 106 int64 id = info->id();
106 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 107 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
107 if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal)) { 108 if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal)) {
108 gfx::Display::SetInternalDisplayId(id); 109 gfx::Display::SetInternalDisplayId(id);
109 SetInternalDisplayModeList(info); 110 SetInternalDisplayModeList(info);
110 } 111 }
111 } 112 }
112 113
114 gfx::Size GetMaxNativeSize(const DisplayInfo& info) {
115 gfx::Size size;
116 for (auto& mode : info.display_modes()) {
117 if (mode.size.GetArea() > size.GetArea())
118 size = mode.size;
119 }
120 return size;
121 }
122
113 } // namespace 123 } // namespace
114 124
115 using std::string; 125 using std::string;
116 using std::vector; 126 using std::vector;
117 127
118 // static 128 // static
119 int64 DisplayManager::kUnifiedDisplayId = -10; 129 int64 DisplayManager::kUnifiedDisplayId = -10;
120 130
121 DisplayManager::DisplayManager() 131 DisplayManager::DisplayManager()
122 : delegate_(NULL), 132 : delegate_(NULL),
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 DisplayMode selected_mode; 456 DisplayMode selected_mode;
447 if (GetSelectedModeForDisplayId(display_id, &selected_mode)) 457 if (GetSelectedModeForDisplayId(display_id, &selected_mode))
448 return selected_mode; 458 return selected_mode;
449 459
450 // If 'selected' mode is empty, it should return the default mode. This means 460 // 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 461 // 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 462 // 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 463 // restored mode to |display_mode_|, so it needs to look up the mode whose
454 // UI-scale value matches. See the TODO in RegisterDisplayProperty(). 464 // UI-scale value matches. See the TODO in RegisterDisplayProperty().
455 const DisplayInfo& info = GetDisplayInfo(display_id); 465 const DisplayInfo& info = GetDisplayInfo(display_id);
456 const std::vector<DisplayMode>& display_modes = info.display_modes();
457 466
458 if (GetDisplayIdForUIScaling() == display_id) { 467 for (auto& mode : info.display_modes()) {
459 for (size_t i = 0; i < display_modes.size(); ++i) { 468 if (GetDisplayIdForUIScaling() == display_id) {
460 if (info.configured_ui_scale() == display_modes[i].ui_scale) 469 if (info.configured_ui_scale() == mode.ui_scale)
461 return display_modes[i]; 470 return mode;
462 } 471 } else if (mode.native) {
463 } else { 472 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 } 473 }
468 } 474 }
469 return selected_mode; 475 return selected_mode;
470 } 476 }
471 477
472 void DisplayManager::RegisterDisplayRotationProperties(bool rotation_lock, 478 void DisplayManager::RegisterDisplayRotationProperties(bool rotation_lock,
473 gfx::Display::Rotation rotation) { 479 gfx::Display::Rotation rotation) {
474 if (delegate_) 480 if (delegate_)
475 delegate_->PreDisplayConfigurationChange(false); 481 delegate_->PreDisplayConfigurationChange(false);
476 registered_internal_display_rotation_lock_ = rotation_lock; 482 registered_internal_display_rotation_lock_ = rotation_lock;
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 } 1113 }
1108 case UNIFIED: { 1114 case UNIFIED: {
1109 // TODO(oshima): Currently, all displays are laid out horizontally, 1115 // TODO(oshima): Currently, all displays are laid out horizontally,
1110 // from left to right. Allow more flexible layouts, such as 1116 // from left to right. Allow more flexible layouts, such as
1111 // right to left, or vertical layouts. 1117 // right to left, or vertical layouts.
1112 gfx::Rect unified_bounds; 1118 gfx::Rect unified_bounds;
1113 software_mirroring_display_list_.clear(); 1119 software_mirroring_display_list_.clear();
1114 1120
1115 // 1st Pass. Find the max size. 1121 // 1st Pass. Find the max size.
1116 int max_height = std::numeric_limits<int>::min(); 1122 int max_height = std::numeric_limits<int>::min();
1117 for (auto& info : *display_info_list) 1123
1124 int default_height = 0;
1125 float default_device_scale_factor = 1.0f;
1126 for (auto& info : *display_info_list) {
1118 max_height = std::max(max_height, info.size_in_pixel().height()); 1127 max_height = std::max(max_height, info.size_in_pixel().height());
1128 if (!default_height || gfx::Display::IsInternalDisplayId(info.id())) {
1129 default_height = info.size_in_pixel().height();
1130 default_device_scale_factor = info.device_scale_factor();
1131 }
1132 }
1119 1133
1120 std::vector<DisplayMode> display_mode_list; 1134 std::vector<DisplayMode> display_mode_list;
1121 std::set<float> scales; 1135 std::set<std::pair<float, float>> dsf_scale_list;
1122 1136
1123 // 2nd Pass. Compute the unified display size. 1137 // 2nd Pass. Compute the unified display size.
1124 for (auto& info : *display_info_list) { 1138 for (auto& info : *display_info_list) {
1125 InsertAndUpdateDisplayInfo(info); 1139 InsertAndUpdateDisplayInfo(info);
1126 gfx::Point origin(unified_bounds.right(), 0); 1140 gfx::Point origin(unified_bounds.right(), 0);
1127 float scale = 1141 float scale =
1128 info.size_in_pixel().height() / static_cast<float>(max_height); 1142 info.size_in_pixel().height() / static_cast<float>(max_height);
1129 // The display is scaled to fit the unified desktop size. 1143 // The display is scaled to fit the unified desktop size.
1130 gfx::Display display = CreateMirroringDisplayFromDisplayInfoById( 1144 gfx::Display display = CreateMirroringDisplayFromDisplayInfoById(
1131 info.id(), origin, 1.0f / scale); 1145 info.id(), origin, 1.0f / scale);
1132 unified_bounds.Union(display.bounds()); 1146 unified_bounds.Union(display.bounds());
1133 1147
1134 scales.insert(scale); 1148 dsf_scale_list.insert(
1149 std::make_pair(info.device_scale_factor(), scale));
1135 } 1150 }
1136 1151
1137 DisplayInfo info(kUnifiedDisplayId, "Unified Desktop", false); 1152 DisplayInfo info(kUnifiedDisplayId, "Unified Desktop", false);
1138 info.SetBounds(unified_bounds);
1139 1153
1140 DisplayMode native_mode(unified_bounds.size(), 60.0f, false, true); 1154 DisplayMode native_mode(unified_bounds.size(), 60.0f, false, true);
1141 info.SetDisplayModes(CreateUnifiedDisplayModeList(native_mode, scales)); 1155 std::vector<DisplayMode> modes =
1156 CreateUnifiedDisplayModeList(native_mode, dsf_scale_list);
1157
1158 // Find the default mode.
1159 auto iter = std::find_if(
1160 modes.begin(), modes.end(),
1161 [default_height,
1162 default_device_scale_factor](const DisplayMode& mode) {
1163 return mode.size.height() == default_height &&
1164 mode.device_scale_factor == default_device_scale_factor;
1165 });
1166 iter->native = true;
1167 info.SetDisplayModes(modes);
1168 info.set_device_scale_factor(iter->device_scale_factor);
1169 info.SetBounds(gfx::Rect(iter->size));
1142 1170
1143 // Forget the configured resolution if the original unified 1171 // Forget the configured resolution if the original unified
1144 // desktop resolution has changed. 1172 // desktop resolution has changed.
1145 if (display_info_.count(kUnifiedDisplayId) != 0 && 1173 if (display_info_.count(kUnifiedDisplayId) != 0 &&
1146 display_info_[kUnifiedDisplayId].size_in_pixel() != 1174 GetMaxNativeSize(display_info_[kUnifiedDisplayId]) !=
1147 info.size_in_pixel()) { 1175 unified_bounds.size()) {
1148 display_modes_.erase(kUnifiedDisplayId); 1176 display_modes_.erase(kUnifiedDisplayId);
1149 } 1177 }
1150 1178
1151 // 3rd Pass. Set the selected mode, then recompute the mirroring 1179 // 3rd Pass. Set the selected mode, then recompute the mirroring
1152 // display size. 1180 // display size.
1153 DisplayMode mode; 1181 DisplayMode mode;
1154 if (GetSelectedModeForDisplayId(kUnifiedDisplayId, &mode) && 1182 if (GetSelectedModeForDisplayId(kUnifiedDisplayId, &mode) &&
1155 FindDisplayMode(info, mode) != info.display_modes().end()) { 1183 FindDisplayMode(info, mode) != info.display_modes().end()) {
1156 // TODO(oshima): device scale factor. 1184 info.set_device_scale_factor(mode.device_scale_factor);
1157 info.SetBounds(gfx::Rect(mode.size)); 1185 info.SetBounds(gfx::Rect(mode.size));
1158 } else { 1186 } else {
1159 display_modes_.erase(kUnifiedDisplayId); 1187 display_modes_.erase(kUnifiedDisplayId);
1160 } 1188 }
1161 1189
1162 int unified_display_height = info.size_in_pixel().height(); 1190 int unified_display_height = info.size_in_pixel().height();
1163 gfx::Point origin; 1191 gfx::Point origin;
1164 for (auto& info : *display_info_list) { 1192 for (auto& info : *display_info_list) {
1165 float display_scale = info.size_in_pixel().height() / 1193 float display_scale = info.size_in_pixel().height() /
1166 static_cast<float>(unified_display_height); 1194 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())); 1395 gfx::Rect(new_secondary_origin, secondary_bounds.size()));
1368 secondary_display->UpdateWorkAreaFromInsets(insets); 1396 secondary_display->UpdateWorkAreaFromInsets(insets);
1369 } 1397 }
1370 1398
1371 void DisplayManager::RunPendingTasksForTest() { 1399 void DisplayManager::RunPendingTasksForTest() {
1372 if (!software_mirroring_display_list_.empty()) 1400 if (!software_mirroring_display_list_.empty())
1373 base::RunLoop().RunUntilIdle(); 1401 base::RunLoop().RunUntilIdle();
1374 } 1402 }
1375 1403
1376 } // namespace ash 1404 } // 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