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

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

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