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

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

Issue 138903025: Read compositor VSync information from platform, when possible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 287efe04 Rebase, oshima@ nits. Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
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 "ash/display/display_change_observer_chromeos.h" 5 #include "ash/display/display_change_observer_chromeos.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 19 matching lines...) Expand all
30 30
31 namespace { 31 namespace {
32 32
33 // The DPI threshold to detect high density screen. 33 // The DPI threshold to detect high density screen.
34 // Higher DPI than this will use device_scale_factor=2. 34 // Higher DPI than this will use device_scale_factor=2.
35 const unsigned int kHighDensityDPIThreshold = 160; 35 const unsigned int kHighDensityDPIThreshold = 160;
36 36
37 // 1 inch in mm. 37 // 1 inch in mm.
38 const float kInchInMm = 25.4f; 38 const float kInchInMm = 25.4f;
39 39
40 // Resolution list are sorted by the area in pixels and the larger 40 // Display mode list is sorted by (in descending priority):
41 // one comes first. 41 // * the area in pixels.
42 struct ResolutionSorter { 42 // * refresh rate.
43 bool operator()(const Resolution& a, const Resolution& b) { 43 struct DisplayModeSorter {
44 return a.size.width() * a.size.height() > b.size.width() * b.size.height(); 44 bool operator()(const DisplayMode& a, const DisplayMode& b) {
45 if (a.size.GetArea() == b.size.GetArea())
46 return (a.refresh_rate > b.refresh_rate);
47 return (a.size.GetArea() > b.size.GetArea());
45 } 48 }
46 }; 49 };
47 50
48 } // namespace 51 } // namespace
49 52
50 // static 53 // static
51 std::vector<Resolution> DisplayChangeObserver::GetResolutionList( 54 std::vector<DisplayMode> DisplayChangeObserver::GetDisplayModeList(
52 const OutputConfigurator::OutputSnapshot& output) { 55 const OutputConfigurator::OutputSnapshot& output) {
53 typedef std::map<std::pair<int,int>, Resolution> ResolutionMap; 56 typedef std::map<std::pair<int, int>, DisplayMode> DisplayModeMap;
54 ResolutionMap resolution_map; 57 DisplayModeMap display_mode_map;
55 58
56 for (std::map<RRMode, OutputConfigurator::ModeInfo>::const_iterator it = 59 for (std::map<RRMode, OutputConfigurator::ModeInfo>::const_iterator it =
57 output.mode_infos.begin(); it != output.mode_infos.end(); ++it) { 60 output.mode_infos.begin(); it != output.mode_infos.end(); ++it) {
58 const OutputConfigurator::ModeInfo& mode_info = it->second; 61 const OutputConfigurator::ModeInfo& mode_info = it->second;
59 const std::pair<int, int> size(mode_info.width, mode_info.height); 62 const std::pair<int, int> size(mode_info.width, mode_info.height);
60 const Resolution resolution(gfx::Size(mode_info.width, mode_info.height), 63 const DisplayMode display_mode(gfx::Size(mode_info.width, mode_info.height),
61 mode_info.interlaced); 64 mode_info.refresh_rate,
65 mode_info.interlaced,
66 output.native_mode == it->first);
62 67
63 // Add the resolution if it isn't already present and override interlaced 68 // Add the display mode if it isn't already present and override interlaced
64 // resolutions with non-interlaced ones. 69 // display modes with non-interlaced ones.
65 ResolutionMap::iterator resolution_it = resolution_map.find(size); 70 DisplayModeMap::iterator display_mode_it = display_mode_map.find(size);
66 if (resolution_it == resolution_map.end()) 71 if (display_mode_it == display_mode_map.end())
67 resolution_map.insert(std::make_pair(size, resolution)); 72 display_mode_map.insert(std::make_pair(size, display_mode));
68 else if (resolution_it->second.interlaced && !resolution.interlaced) 73 else if (display_mode_it->second.interlaced && !display_mode.interlaced)
69 resolution_it->second = resolution; 74 display_mode_it->second = display_mode;
70 } 75 }
71 76
72 std::vector<Resolution> resolution_list; 77 std::vector<DisplayMode> display_mode_list;
73 for (ResolutionMap::const_iterator iter = resolution_map.begin(); 78 for (DisplayModeMap::const_iterator iter = display_mode_map.begin();
74 iter != resolution_map.end(); 79 iter != display_mode_map.end();
75 ++iter) { 80 ++iter) {
76 resolution_list.push_back(iter->second); 81 display_mode_list.push_back(iter->second);
77 } 82 }
78 std::sort(resolution_list.begin(), resolution_list.end(), ResolutionSorter()); 83 std::sort(
79 return resolution_list; 84 display_mode_list.begin(), display_mode_list.end(), DisplayModeSorter());
85 return display_mode_list;
80 } 86 }
81 87
82 DisplayChangeObserver::DisplayChangeObserver() { 88 DisplayChangeObserver::DisplayChangeObserver() {
83 Shell::GetInstance()->AddShellObserver(this); 89 Shell::GetInstance()->AddShellObserver(this);
84 } 90 }
85 91
86 DisplayChangeObserver::~DisplayChangeObserver() { 92 DisplayChangeObserver::~DisplayChangeObserver() {
87 Shell::GetInstance()->RemoveShellObserver(this); 93 Shell::GetInstance()->RemoveShellObserver(this);
88 } 94 }
89 95
90 chromeos::OutputState DisplayChangeObserver::GetStateForDisplayIds( 96 chromeos::OutputState DisplayChangeObserver::GetStateForDisplayIds(
91 const std::vector<int64>& display_ids) const { 97 const std::vector<int64>& display_ids) const {
92 if (CommandLine::ForCurrentProcess()->HasSwitch( 98 if (CommandLine::ForCurrentProcess()->HasSwitch(
93 switches::kAshForceMirrorMode)) { 99 switches::kAshForceMirrorMode)) {
94 return chromeos::STATE_DUAL_MIRROR; 100 return chromeos::STATE_DUAL_MIRROR;
95 } 101 }
96 102
97 CHECK_EQ(2U, display_ids.size()); 103 CHECK_EQ(2U, display_ids.size());
98 DisplayIdPair pair = std::make_pair(display_ids[0], display_ids[1]); 104 DisplayIdPair pair = std::make_pair(display_ids[0], display_ids[1]);
99 DisplayLayout layout = Shell::GetInstance()->display_manager()-> 105 DisplayLayout layout = Shell::GetInstance()->display_manager()->
100 layout_store()->GetRegisteredDisplayLayout(pair); 106 layout_store()->GetRegisteredDisplayLayout(pair);
101 return layout.mirrored ? 107 return layout.mirrored ?
102 chromeos::STATE_DUAL_MIRROR : chromeos::STATE_DUAL_EXTENDED; 108 chromeos::STATE_DUAL_MIRROR : chromeos::STATE_DUAL_EXTENDED;
103 } 109 }
104 110
105 bool DisplayChangeObserver::GetResolutionForDisplayId(int64 display_id, 111 bool DisplayChangeObserver::GetResolutionForDisplayId(int64 display_id,
106 int* width, 112 int* width,
107 int* height) const { 113 int* height) const {
108 gfx::Size resolution; 114 DisplayMode mode;
109 if (!Shell::GetInstance()->display_manager()-> 115 if (!Shell::GetInstance()->display_manager()->GetSelectedModeForDisplayId(
110 GetSelectedResolutionForDisplayId(display_id, &resolution)) { 116 display_id, &mode))
111 return false; 117 return false;
112 }
113 118
114 *width = resolution.width(); 119 *width = mode.size.width();
115 *height = resolution.height(); 120 *height = mode.size.height();
116 return true; 121 return true;
117 } 122 }
118 123
119 void DisplayChangeObserver::OnDisplayModeChanged( 124 void DisplayChangeObserver::OnDisplayModeChanged(
120 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) { 125 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) {
121 std::vector<DisplayInfo> displays; 126 std::vector<DisplayInfo> displays;
122 std::set<int64> ids; 127 std::set<int64> ids;
123 for (size_t i = 0; i < outputs.size(); ++i) { 128 for (size_t i = 0; i < outputs.size(); ++i) {
124 const OutputConfigurator::OutputSnapshot& output = outputs[i]; 129 const OutputConfigurator::OutputSnapshot& output = outputs[i];
125 130
(...skipping 12 matching lines...) Expand all
138 143
139 float device_scale_factor = 1.0f; 144 float device_scale_factor = 1.0f;
140 if (!ui::IsXDisplaySizeBlackListed(output.width_mm, output.height_mm) && 145 if (!ui::IsXDisplaySizeBlackListed(output.width_mm, output.height_mm) &&
141 (kInchInMm * mode_info->width / output.width_mm) > 146 (kInchInMm * mode_info->width / output.width_mm) >
142 kHighDensityDPIThreshold) { 147 kHighDensityDPIThreshold) {
143 device_scale_factor = 2.0f; 148 device_scale_factor = 2.0f;
144 } 149 }
145 gfx::Rect display_bounds( 150 gfx::Rect display_bounds(
146 output.x, output.y, mode_info->width, mode_info->height); 151 output.x, output.y, mode_info->width, mode_info->height);
147 152
148 std::vector<Resolution> resolutions; 153 std::vector<DisplayMode> display_modes = GetDisplayModeList(output);
149 if (output.type != chromeos::OUTPUT_TYPE_INTERNAL)
150 resolutions = GetResolutionList(output);
151 154
152 std::string name = output.type == chromeos::OUTPUT_TYPE_INTERNAL ? 155 std::string name = output.type == chromeos::OUTPUT_TYPE_INTERNAL ?
153 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) : 156 l10n_util::GetStringUTF8(IDS_ASH_INTERNAL_DISPLAY_NAME) :
154 chromeos::GetDisplayName(output.output); 157 chromeos::GetDisplayName(output.output);
155 if (name.empty()) 158 if (name.empty())
156 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); 159 name = l10n_util::GetStringUTF8(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
157 160
158 bool has_overscan = false; 161 bool has_overscan = false;
159 chromeos::GetOutputOverscanFlag(output.output, &has_overscan); 162 chromeos::GetOutputOverscanFlag(output.output, &has_overscan);
160 163
161 int64 id = output.display_id; 164 int64 id = output.display_id;
162 if (id == gfx::Display::kInvalidDisplayID || ids.find(id) != ids.end()) 165 if (id == gfx::Display::kInvalidDisplayID || ids.find(id) != ids.end())
163 id = output.index; 166 id = output.index;
164 ids.insert(id); 167 ids.insert(id);
165 168
166 displays.push_back(DisplayInfo(id, name, has_overscan)); 169 displays.push_back(DisplayInfo(id, name, has_overscan));
167 displays.back().set_device_scale_factor(device_scale_factor); 170 displays.back().set_device_scale_factor(device_scale_factor);
168 displays.back().SetBounds(display_bounds); 171 displays.back().SetBounds(display_bounds);
169 displays.back().set_native(true); 172 displays.back().set_native(true);
170 displays.back().set_resolutions(resolutions); 173 displays.back().set_display_modes(display_modes);
171 displays.back().set_touch_support( 174 displays.back().set_touch_support(
172 output.touch_device_id == 0 ? gfx::Display::TOUCH_SUPPORT_UNAVAILABLE : 175 output.touch_device_id == 0 ? gfx::Display::TOUCH_SUPPORT_UNAVAILABLE :
173 gfx::Display::TOUCH_SUPPORT_AVAILABLE); 176 gfx::Display::TOUCH_SUPPORT_AVAILABLE);
174 } 177 }
175 178
176 // DisplayManager can be null during the boot. 179 // DisplayManager can be null during the boot.
177 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays); 180 Shell::GetInstance()->display_manager()->OnNativeDisplaysChanged(displays);
178 } 181 }
179 182
180 void DisplayChangeObserver::OnAppTerminating() { 183 void DisplayChangeObserver::OnAppTerminating() {
181 #if defined(USE_ASH) 184 #if defined(USE_ASH)
182 // Stop handling display configuration events once the shutdown 185 // Stop handling display configuration events once the shutdown
183 // process starts. crbug.com/177014. 186 // process starts. crbug.com/177014.
184 Shell::GetInstance()->output_configurator()->Stop(); 187 Shell::GetInstance()->output_configurator()->Stop();
185 #endif 188 #endif
186 } 189 }
187 190
188 } // namespace internal 191 } // namespace internal
189 } // namespace ash 192 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_change_observer_chromeos.h ('k') | ash/display/display_change_observer_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698