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

Side by Side Diff: ash/display/display_info.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
« no previous file with comments | « ash/display/display_info.h ('k') | ash/display/display_info_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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <stdio.h> 5 #include <stdio.h>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/display/display_info.h" 9 #include "ash/display/display_info.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "ui/gfx/display.h" 14 #include "ui/gfx/display.h"
15 #include "ui/gfx/size_conversions.h" 15 #include "ui/gfx/size_conversions.h"
16 #include "ui/gfx/size_f.h" 16 #include "ui/gfx/size_f.h"
17 17
18 #if defined(OS_WIN) 18 #if defined(OS_WIN)
19 #include "ui/aura/window_tree_host.h" 19 #include "ui/aura/window_tree_host.h"
20 #include "ui/gfx/win/dpi.h" 20 #include "ui/gfx/win/dpi.h"
21 #endif 21 #endif
22 22
23 namespace ash { 23 namespace ash {
24 namespace internal { 24 namespace internal {
25 25
26 DisplayMode::DisplayMode() 26 Resolution::Resolution(const gfx::Size& size, bool interlaced)
27 : refresh_rate(0.0f), interlaced(false), native(false) {}
28
29 DisplayMode::DisplayMode(const gfx::Size& size,
30 float refresh_rate,
31 bool interlaced,
32 bool native)
33 : size(size), 27 : size(size),
34 refresh_rate(refresh_rate), 28 interlaced(interlaced) {
35 interlaced(interlaced), 29 }
36 native(native) {}
37 30
38 // satic 31 // satic
39 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { 32 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) {
40 return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID); 33 return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID);
41 } 34 }
42 35
43 // static 36 // static
44 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, 37 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec,
45 int64 id) { 38 int64 id) {
46 // Default bounds for a display. 39 // Default bounds for a display.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 &device_scale_factor) >= 4) { 97 &device_scale_factor) >= 4) {
105 bounds_in_native.SetRect(x, y, width, height); 98 bounds_in_native.SetRect(x, y, width, height);
106 } else { 99 } else {
107 #if defined(OS_WIN) 100 #if defined(OS_WIN)
108 if (gfx::IsHighDPIEnabled()) { 101 if (gfx::IsHighDPIEnabled()) {
109 device_scale_factor = gfx::GetModernUIScale(); 102 device_scale_factor = gfx::GetModernUIScale();
110 } 103 }
111 #endif 104 #endif
112 } 105 }
113 106
114 std::vector<DisplayMode> display_modes; 107 std::vector<Resolution> resolutions;
115 if (Tokenize(main_spec, "#", &parts) == 2) { 108 if (Tokenize(main_spec, "#", &parts) == 2) {
116 size_t native_mode = 0;
117 int largest_area = -1;
118 float highest_refresh_rate = -1.0f;
119 main_spec = parts[0]; 109 main_spec = parts[0];
120 std::string resolution_list = parts[1]; 110 std::string resolution_list = parts[1];
121 count = Tokenize(resolution_list, "|", &parts); 111 count = Tokenize(resolution_list, "|", &parts);
122 for (size_t i = 0; i < count; ++i) { 112 for (size_t i = 0; i < count; ++i) {
123 std::string resolution = parts[i]; 113 std::string resolution = parts[i];
124 int width, height; 114 int width, height;
125 float refresh_rate = 0.0f; 115 if (sscanf(resolution.c_str(), "%dx%d", &width, &height) == 2)
126 if (sscanf(resolution.c_str(), 116 resolutions.push_back(Resolution(gfx::Size(width, height), false));
127 "%dx%d%%%f",
128 &width,
129 &height,
130 &refresh_rate) >= 2) {
131 if (width * height >= largest_area &&
132 refresh_rate > highest_refresh_rate) {
133 // Use mode with largest area and highest refresh rate as native.
134 largest_area = width * height;
135 highest_refresh_rate = refresh_rate;
136 native_mode = i;
137 }
138 display_modes.push_back(
139 DisplayMode(gfx::Size(width, height), refresh_rate, false, false));
140 }
141 } 117 }
142 display_modes[native_mode].native = true;
143 } 118 }
144 119
145 if (id == gfx::Display::kInvalidDisplayID) 120 if (id == gfx::Display::kInvalidDisplayID)
146 id = synthesized_display_id++; 121 id = synthesized_display_id++;
147 DisplayInfo display_info( 122 DisplayInfo display_info(
148 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); 123 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan);
149 display_info.set_device_scale_factor(device_scale_factor); 124 display_info.set_device_scale_factor(device_scale_factor);
150 display_info.set_rotation(rotation); 125 display_info.set_rotation(rotation);
151 display_info.set_configured_ui_scale(ui_scale); 126 display_info.set_configured_ui_scale(ui_scale);
152 display_info.SetBounds(bounds_in_native); 127 display_info.SetBounds(bounds_in_native);
153 display_info.set_display_modes(display_modes); 128 display_info.set_resolutions(resolutions);
154 129
155 // To test the overscan, it creates the default 5% overscan. 130 // To test the overscan, it creates the default 5% overscan.
156 if (has_overscan) { 131 if (has_overscan) {
157 int width = bounds_in_native.width() / device_scale_factor / 40; 132 int width = bounds_in_native.width() / device_scale_factor / 40;
158 int height = bounds_in_native.height() / device_scale_factor / 40; 133 int height = bounds_in_native.height() / device_scale_factor / 40;
159 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width)); 134 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width));
160 display_info.UpdateDisplaySize(); 135 display_info.UpdateDisplaySize();
161 } 136 }
162 137
163 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() 138 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString()
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 170
196 void DisplayInfo::Copy(const DisplayInfo& native_info) { 171 void DisplayInfo::Copy(const DisplayInfo& native_info) {
197 DCHECK(id_ == native_info.id_); 172 DCHECK(id_ == native_info.id_);
198 name_ = native_info.name_; 173 name_ = native_info.name_;
199 has_overscan_ = native_info.has_overscan_; 174 has_overscan_ = native_info.has_overscan_;
200 175
201 DCHECK(!native_info.bounds_in_native_.IsEmpty()); 176 DCHECK(!native_info.bounds_in_native_.IsEmpty());
202 bounds_in_native_ = native_info.bounds_in_native_; 177 bounds_in_native_ = native_info.bounds_in_native_;
203 size_in_pixel_ = native_info.size_in_pixel_; 178 size_in_pixel_ = native_info.size_in_pixel_;
204 device_scale_factor_ = native_info.device_scale_factor_; 179 device_scale_factor_ = native_info.device_scale_factor_;
205 display_modes_ = native_info.display_modes_; 180 resolutions_ = native_info.resolutions_;
206 touch_support_ = native_info.touch_support_; 181 touch_support_ = native_info.touch_support_;
207 182
208 // Copy overscan_insets_in_dip_ if it's not empty. This is for test 183 // Copy overscan_insets_in_dip_ if it's not empty. This is for test
209 // cases which use "/o" annotation which sets the overscan inset 184 // cases which use "/o" annotation which sets the overscan inset
210 // to native, and that overscan has to be propagated. This does not 185 // to native, and that overscan has to be propagated. This does not
211 // happen on the real environment. 186 // happen on the real environment.
212 if (!native_info.overscan_insets_in_dip_.empty()) 187 if (!native_info.overscan_insets_in_dip_.empty())
213 overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_; 188 overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_;
214 189
215 // Rotation_ and ui_scale_ are given by preference, or unit 190 // Rotation_ and ui_scale_ are given by preference, or unit
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 return base::StringPrintf( 242 return base::StringPrintf(
268 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " 243 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, "
269 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s", 244 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s",
270 static_cast<long long int>(id_), 245 static_cast<long long int>(id_),
271 bounds_in_native_.ToString().c_str(), 246 bounds_in_native_.ToString().c_str(),
272 size_in_pixel_.ToString().c_str(), 247 size_in_pixel_.ToString().c_str(),
273 device_scale_factor_, 248 device_scale_factor_,
274 overscan_insets_in_dip_.ToString().c_str(), 249 overscan_insets_in_dip_.ToString().c_str(),
275 rotation_degree, 250 rotation_degree,
276 configured_ui_scale_, 251 configured_ui_scale_,
277 touch_support_ == gfx::Display::TOUCH_SUPPORT_AVAILABLE 252 touch_support_ == gfx::Display::TOUCH_SUPPORT_AVAILABLE ? "yes" :
278 ? "yes" 253 touch_support_ == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE ? "no" :
279 : touch_support_ == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE 254 "unknown");
280 ? "no"
281 : "unknown");
282 } 255 }
283 256
284 std::string DisplayInfo::ToFullString() const { 257 std::string DisplayInfo::ToFullString() const {
285 std::string display_modes_str; 258 std::string resolutions_str;
286 std::vector<DisplayMode>::const_iterator iter = display_modes_.begin(); 259 std::vector<Resolution>::const_iterator iter = resolutions_.begin();
287 for (; iter != display_modes_.end(); ++iter) { 260 for (; iter != resolutions_.end(); ++iter) {
288 if (!display_modes_str.empty()) 261 if (!resolutions_str.empty())
289 display_modes_str += ","; 262 resolutions_str += ",";
290 base::StringAppendF(&display_modes_str, 263 resolutions_str += iter->size.ToString();
291 "(%dx%d@%f%c%s)", 264 if (iter->interlaced)
292 iter->size.width(), 265 resolutions_str += "(i)";
293 iter->size.height(),
294 iter->refresh_rate,
295 iter->interlaced ? 'I' : 'P',
296 iter->native ? "(N)" : "");
297 } 266 }
298 return ToString() + ", display_modes==" + display_modes_str; 267 return ToString() + ", resolutions=" + resolutions_str;
299 } 268 }
300 269
301 } // namespace internal 270 } // namespace internal
302 } // namespace ash 271 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_info.h ('k') | ash/display/display_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698