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

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

Issue 2286523002: Relocate reuseable portions of ash/display/display_util.* (Closed)
Patch Set: fixed ozone build Created 4 years, 3 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/display/display_manager.h ('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 <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 19 matching lines...) Expand all
30 #include "base/strings/string_number_conversions.h" 30 #include "base/strings/string_number_conversions.h"
31 #include "base/strings/string_split.h" 31 #include "base/strings/string_split.h"
32 #include "base/strings/stringprintf.h" 32 #include "base/strings/stringprintf.h"
33 #include "base/strings/utf_string_conversions.h" 33 #include "base/strings/utf_string_conversions.h"
34 #include "base/threading/thread_task_runner_handle.h" 34 #include "base/threading/thread_task_runner_handle.h"
35 #include "grit/ash_strings.h" 35 #include "grit/ash_strings.h"
36 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/display/display.h" 37 #include "ui/display/display.h"
38 #include "ui/display/display_observer.h" 38 #include "ui/display/display_observer.h"
39 #include "ui/display/manager/display_layout_store.h" 39 #include "ui/display/manager/display_layout_store.h"
40 #include "ui/display/manager/display_manager_utilities.h"
40 #include "ui/display/manager/managed_display_info.h" 41 #include "ui/display/manager/managed_display_info.h"
41 #include "ui/display/screen.h" 42 #include "ui/display/screen.h"
42 #include "ui/gfx/font_render_params.h" 43 #include "ui/gfx/font_render_params.h"
43 #include "ui/gfx/geometry/rect.h" 44 #include "ui/gfx/geometry/rect.h"
44 #include "ui/gfx/geometry/size_conversions.h" 45 #include "ui/gfx/geometry/size_conversions.h"
45 46
46 #if defined(USE_X11) 47 #if defined(USE_X11)
47 #include "ui/base/x/x11_util.h" // nogncheck 48 #include "ui/base/x/x11_util.h" // nogncheck
48 #endif 49 #endif
49 50
(...skipping 12 matching lines...) Expand all
62 // We need to keep this in order for unittests to tell if 63 // We need to keep this in order for unittests to tell if
63 // the object in display::Screen::GetScreenByType is for shutdown. 64 // the object in display::Screen::GetScreenByType is for shutdown.
64 display::Screen* screen_for_shutdown = nullptr; 65 display::Screen* screen_for_shutdown = nullptr;
65 66
66 // The number of pixels to overlap between the primary and secondary displays, 67 // The number of pixels to overlap between the primary and secondary displays,
67 // in case that the offset value is too large. 68 // in case that the offset value is too large.
68 const int kMinimumOverlapForInvalidOffset = 100; 69 const int kMinimumOverlapForInvalidOffset = 100;
69 70
70 struct DisplaySortFunctor { 71 struct DisplaySortFunctor {
71 bool operator()(const display::Display& a, const display::Display& b) { 72 bool operator()(const display::Display& a, const display::Display& b) {
72 return CompareDisplayIds(a.id(), b.id()); 73 return display::CompareDisplayIds(a.id(), b.id());
73 } 74 }
74 }; 75 };
75 76
76 struct DisplayInfoSortFunctor { 77 struct DisplayInfoSortFunctor {
77 bool operator()(const display::ManagedDisplayInfo& a, 78 bool operator()(const display::ManagedDisplayInfo& a,
78 const display::ManagedDisplayInfo& b) { 79 const display::ManagedDisplayInfo& b) {
79 return CompareDisplayIds(a.id(), b.id()); 80 return display::CompareDisplayIds(a.id(), b.id());
80 } 81 }
81 }; 82 };
82 83
83 display::Display& GetInvalidDisplay() { 84 display::Display& GetInvalidDisplay() {
84 static display::Display* invalid_display = new display::Display(); 85 static display::Display* invalid_display = new display::Display();
85 return *invalid_display; 86 return *invalid_display;
86 } 87 }
87 88
88 display::ManagedDisplayInfo::ManagedDisplayModeList::const_iterator 89 display::ManagedDisplayInfo::ManagedDisplayModeList::const_iterator
89 FindDisplayMode(const display::ManagedDisplayInfo& info, 90 FindDisplayMode(const display::ManagedDisplayInfo& info,
90 const scoped_refptr<display::ManagedDisplayMode>& target_mode) { 91 const scoped_refptr<display::ManagedDisplayMode>& target_mode) {
91 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = 92 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes =
92 info.display_modes(); 93 info.display_modes();
93 return std::find_if( 94 return std::find_if(
94 modes.begin(), modes.end(), 95 modes.begin(), modes.end(),
95 [target_mode](const scoped_refptr<display::ManagedDisplayMode>& mode) { 96 [target_mode](const scoped_refptr<display::ManagedDisplayMode>& mode) {
96 return target_mode->IsEquivalent(mode); 97 return target_mode->IsEquivalent(mode);
97 }); 98 });
98 } 99 }
99 100
100 void SetInternalManagedDisplayModeList(display::ManagedDisplayInfo* info) { 101 void SetInternalManagedDisplayModeList(display::ManagedDisplayInfo* info) {
101 scoped_refptr<display::ManagedDisplayMode> native_mode = 102 scoped_refptr<display::ManagedDisplayMode> native_mode =
102 new display::ManagedDisplayMode( 103 new display::ManagedDisplayMode(
103 info->bounds_in_native().size(), 0.0 /* refresh_rate */, 104 info->bounds_in_native().size(), 0.0 /* refresh_rate */,
104 false /* interlaced */, false /* native_mode */, 1.0 /* ui_scale */, 105 false /* interlaced */, false /* native_mode */, 1.0 /* ui_scale */,
105 info->device_scale_factor()); 106 info->device_scale_factor());
106 info->SetManagedDisplayModes( 107 info->SetManagedDisplayModes(
107 CreateInternalManagedDisplayModeList(native_mode)); 108 display::CreateInternalManagedDisplayModeList(native_mode));
108 } 109 }
109 110
110 void MaybeInitInternalDisplay(display::ManagedDisplayInfo* info) { 111 void MaybeInitInternalDisplay(display::ManagedDisplayInfo* info) {
111 int64_t id = info->id(); 112 int64_t id = info->id();
112 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 113 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
113 if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal)) { 114 if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal)) {
114 display::Display::SetInternalDisplayId(id); 115 display::Display::SetInternalDisplayId(id);
115 SetInternalManagedDisplayModeList(info); 116 SetInternalManagedDisplayModeList(info);
116 } 117 }
117 } 118 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 } 221 }
221 LOG(ERROR) << "DisplayLayout is requested for single display"; 222 LOG(ERROR) << "DisplayLayout is requested for single display";
222 // On release build, just fallback to default instead of blowing up. 223 // On release build, just fallback to default instead of blowing up.
223 static display::DisplayLayout layout; 224 static display::DisplayLayout layout;
224 layout.primary_id = active_display_list_[0].id(); 225 layout.primary_id = active_display_list_[0].id();
225 return layout; 226 return layout;
226 } 227 }
227 228
228 display::DisplayIdList DisplayManager::GetCurrentDisplayIdList() const { 229 display::DisplayIdList DisplayManager::GetCurrentDisplayIdList() const {
229 if (IsInUnifiedMode()) { 230 if (IsInUnifiedMode()) {
230 return CreateDisplayIdList(software_mirroring_display_list_); 231 return display::CreateDisplayIdList(software_mirroring_display_list_);
231 } else if (IsInMirrorMode()) { 232 } else if (IsInMirrorMode()) {
232 if (software_mirroring_enabled()) { 233 if (software_mirroring_enabled()) {
233 CHECK_EQ(2u, num_connected_displays()); 234 CHECK_EQ(2u, num_connected_displays());
234 // This comment is to make it easy to distinguish the crash 235 // This comment is to make it easy to distinguish the crash
235 // between two checks. 236 // between two checks.
236 CHECK_EQ(1u, active_display_list_.size()); 237 CHECK_EQ(1u, active_display_list_.size());
237 } 238 }
238 int64_t ids[] = {active_display_list_[0].id(), mirroring_display_id_}; 239 int64_t ids[] = {active_display_list_[0].id(), mirroring_display_id_};
239 return ash::GenerateDisplayIdList(std::begin(ids), std::end(ids)); 240 return display::GenerateDisplayIdList(std::begin(ids), std::end(ids));
240 } else { 241 } else {
241 CHECK_LE(2u, active_display_list_.size()); 242 CHECK_LE(2u, active_display_list_.size());
242 return CreateDisplayIdList(active_display_list_); 243 return display::CreateDisplayIdList(active_display_list_);
243 } 244 }
244 } 245 }
245 246
246 void DisplayManager::SetLayoutForCurrentDisplays( 247 void DisplayManager::SetLayoutForCurrentDisplays(
247 std::unique_ptr<display::DisplayLayout> layout) { 248 std::unique_ptr<display::DisplayLayout> layout) {
248 if (GetNumDisplays() == 1) 249 if (GetNumDisplays() == 1)
249 return; 250 return;
250 const display::DisplayIdList list = GetCurrentDisplayIdList(); 251 const display::DisplayIdList list = GetCurrentDisplayIdList();
251 252
252 DCHECK(display::DisplayLayout::Validate(list, *layout)); 253 DCHECK(display::DisplayLayout::Validate(list, *layout));
(...skipping 24 matching lines...) Expand all
277 } 278 }
278 279
279 const display::Display& DisplayManager::GetDisplayForId(int64_t id) const { 280 const display::Display& DisplayManager::GetDisplayForId(int64_t id) const {
280 display::Display* display = 281 display::Display* display =
281 const_cast<DisplayManager*>(this)->FindDisplayForId(id); 282 const_cast<DisplayManager*>(this)->FindDisplayForId(id);
282 return display ? *display : GetInvalidDisplay(); 283 return display ? *display : GetInvalidDisplay();
283 } 284 }
284 285
285 const display::Display& DisplayManager::FindDisplayContainingPoint( 286 const display::Display& DisplayManager::FindDisplayContainingPoint(
286 const gfx::Point& point_in_screen) const { 287 const gfx::Point& point_in_screen) const {
287 int index = 288 int index = display::FindDisplayIndexContainingPoint(active_display_list_,
288 FindDisplayIndexContainingPoint(active_display_list_, point_in_screen); 289 point_in_screen);
289 return index < 0 ? GetInvalidDisplay() : active_display_list_[index]; 290 return index < 0 ? GetInvalidDisplay() : active_display_list_[index];
290 } 291 }
291 292
292 bool DisplayManager::UpdateWorkAreaOfDisplay(int64_t display_id, 293 bool DisplayManager::UpdateWorkAreaOfDisplay(int64_t display_id,
293 const gfx::Insets& insets) { 294 const gfx::Insets& insets) {
294 display::Display* display = FindDisplayForId(display_id); 295 display::Display* display = FindDisplayForId(display_id);
295 DCHECK(display); 296 DCHECK(display);
296 gfx::Rect old_work_area = display->work_area(); 297 gfx::Rect old_work_area = display->work_area();
297 display->UpdateWorkAreaFromInsets(insets); 298 display->UpdateWorkAreaFromInsets(insets);
298 bool workarea_changed = old_work_area != display->work_area(); 299 bool workarea_changed = old_work_area != display->work_area();
(...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 1090
1090 void DisplayManager::UpdateInternalManagedDisplayModeListForTest() { 1091 void DisplayManager::UpdateInternalManagedDisplayModeListForTest() {
1091 if (!display::Display::HasInternalDisplay() || 1092 if (!display::Display::HasInternalDisplay() ||
1092 display_info_.count(display::Display::InternalDisplayId()) == 0) 1093 display_info_.count(display::Display::InternalDisplayId()) == 0)
1093 return; 1094 return;
1094 display::ManagedDisplayInfo* info = 1095 display::ManagedDisplayInfo* info =
1095 &display_info_[display::Display::InternalDisplayId()]; 1096 &display_info_[display::Display::InternalDisplayId()];
1096 SetInternalManagedDisplayModeList(info); 1097 SetInternalManagedDisplayModeList(info);
1097 } 1098 }
1098 1099
1100 bool DisplayManager::ZoomInternalDisplay(bool up) {
1101 int64_t display_id =
1102 IsInUnifiedMode() ? kUnifiedDisplayId : GetDisplayIdForUIScaling();
1103 const display::ManagedDisplayInfo& display_info = GetDisplayInfo(display_id);
1104
1105 scoped_refptr<display::ManagedDisplayMode> mode;
1106 if (IsInUnifiedMode()) {
1107 mode = GetDisplayModeForNextResolution(display_info, up);
1108 } else {
1109 if (!IsActiveDisplayId(display_info.id()) ||
1110 !display::Display::IsInternalDisplayId(display_info.id())) {
1111 return false;
1112 }
1113 mode = GetDisplayModeForNextUIScale(display_info, up);
1114 }
1115
1116 return mode ? SetDisplayMode(display_id, mode) : false;
1117 }
1118
1119 void DisplayManager::ResetInternalDisplayZoom() {
1120 if (IsInUnifiedMode()) {
1121 const display::ManagedDisplayInfo& display_info =
1122 GetDisplayInfo(DisplayManager::kUnifiedDisplayId);
1123 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes =
1124 display_info.display_modes();
1125 auto iter = std::find_if(
1126 modes.begin(), modes.end(),
1127 [](const scoped_refptr<display::ManagedDisplayMode>& mode) {
1128 return mode->native();
1129 });
1130 SetDisplayMode(kUnifiedDisplayId, *iter);
1131 } else {
1132 SetDisplayUIScale(GetDisplayIdForUIScaling(), 1.0f);
1133 }
1134 }
1135
1099 void DisplayManager::CreateSoftwareMirroringDisplayInfo( 1136 void DisplayManager::CreateSoftwareMirroringDisplayInfo(
1100 DisplayInfoList* display_info_list) { 1137 DisplayInfoList* display_info_list) {
1101 // Use the internal display or 1st as the mirror source, then scale 1138 // Use the internal display or 1st as the mirror source, then scale
1102 // the root window so that it matches the external display's 1139 // the root window so that it matches the external display's
1103 // resolution. This is necessary in order for scaling to work while 1140 // resolution. This is necessary in order for scaling to work while
1104 // mirrored. 1141 // mirrored.
1105 switch (multi_display_mode_) { 1142 switch (multi_display_mode_) {
1106 case MIRRORING: { 1143 case MIRRORING: {
1107 if (display_info_list->size() != 2) 1144 if (display_info_list->size() != 2)
1108 return; 1145 return;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 } 1365 }
1329 1366
1330 void DisplayManager::UpdateNonPrimaryDisplayBoundsForLayout( 1367 void DisplayManager::UpdateNonPrimaryDisplayBoundsForLayout(
1331 display::DisplayList* display_list, 1368 display::DisplayList* display_list,
1332 std::vector<size_t>* updated_indices) { 1369 std::vector<size_t>* updated_indices) {
1333 if (display_list->size() == 1u) 1370 if (display_list->size() == 1u)
1334 return; 1371 return;
1335 1372
1336 const display::DisplayLayout& layout = 1373 const display::DisplayLayout& layout =
1337 layout_store_->GetRegisteredDisplayLayout( 1374 layout_store_->GetRegisteredDisplayLayout(
1338 CreateDisplayIdList(*display_list)); 1375 display::CreateDisplayIdList(*display_list));
1339 1376
1340 // Ignore if a user has a old format (should be extremely rare) 1377 // Ignore if a user has a old format (should be extremely rare)
1341 // and this will be replaced with DCHECK. 1378 // and this will be replaced with DCHECK.
1342 if (layout.primary_id == display::Display::kInvalidDisplayID) 1379 if (layout.primary_id == display::Display::kInvalidDisplayID)
1343 return; 1380 return;
1344 1381
1345 // display_list does not have translation set, so ApplyDisplayLayout cannot 1382 // display_list does not have translation set, so ApplyDisplayLayout cannot
1346 // provide accurate change information. We'll find the changes after the call. 1383 // provide accurate change information. We'll find the changes after the call.
1347 ApplyDisplayLayout(layout, display_list, nullptr); 1384 ApplyDisplayLayout(layout, display_list, nullptr);
1348 size_t num_displays = display_list->size(); 1385 size_t num_displays = display_list->size();
(...skipping 21 matching lines...) Expand all
1370 layout.ApplyToDisplayList(display_list, updated_ids, 1407 layout.ApplyToDisplayList(display_list, updated_ids,
1371 kMinimumOverlapForInvalidOffset); 1408 kMinimumOverlapForInvalidOffset);
1372 } 1409 }
1373 1410
1374 void DisplayManager::RunPendingTasksForTest() { 1411 void DisplayManager::RunPendingTasksForTest() {
1375 if (!software_mirroring_display_list_.empty()) 1412 if (!software_mirroring_display_list_.empty())
1376 base::RunLoop().RunUntilIdle(); 1413 base::RunLoop().RunUntilIdle();
1377 } 1414 }
1378 1415
1379 } // namespace ash 1416 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_manager.h ('k') | ash/display/display_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698