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

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

Issue 138903025: Read compositor VSync information from platform, when possible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fd71f590e Resolution -> DisplayMode 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 (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 Resolution::Resolution(const gfx::Size& size, bool interlaced) 26 DisplayMode::DisplayMode()
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)
27 : size(size), 33 : size(size),
28 interlaced(interlaced) { 34 refresh_rate(refresh_rate),
29 } 35 interlaced(interlaced),
36 native(native) {}
30 37
31 // satic 38 // satic
32 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) { 39 DisplayInfo DisplayInfo::CreateFromSpec(const std::string& spec) {
33 return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID); 40 return CreateFromSpecWithID(spec, gfx::Display::kInvalidDisplayID);
34 } 41 }
35 42
36 // static 43 // static
37 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec, 44 DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec,
38 int64 id) { 45 int64 id) {
39 // Default bounds for a display. 46 // Default bounds for a display.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 &device_scale_factor) >= 4) { 104 &device_scale_factor) >= 4) {
98 bounds_in_native.SetRect(x, y, width, height); 105 bounds_in_native.SetRect(x, y, width, height);
99 } else { 106 } else {
100 #if defined(OS_WIN) 107 #if defined(OS_WIN)
101 if (gfx::IsHighDPIEnabled()) { 108 if (gfx::IsHighDPIEnabled()) {
102 device_scale_factor = gfx::GetModernUIScale(); 109 device_scale_factor = gfx::GetModernUIScale();
103 } 110 }
104 #endif 111 #endif
105 } 112 }
106 113
107 std::vector<Resolution> resolutions; 114 std::vector<DisplayMode> display_modes;
108 if (Tokenize(main_spec, "#", &parts) == 2) { 115 if (Tokenize(main_spec, "#", &parts) == 2) {
109 main_spec = parts[0]; 116 main_spec = parts[0];
110 std::string resolution_list = parts[1]; 117 std::string resolution_list = parts[1];
111 count = Tokenize(resolution_list, "|", &parts); 118 count = Tokenize(resolution_list, "|", &parts);
112 for (size_t i = 0; i < count; ++i) { 119 for (size_t i = 0; i < count; ++i) {
113 std::string resolution = parts[i]; 120 std::string resolution = parts[i];
114 int width, height; 121 int width, height;
115 if (sscanf(resolution.c_str(), "%dx%d", &width, &height) == 2) 122 float refresh_rate = 0.0f;
116 resolutions.push_back(Resolution(gfx::Size(width, height), false)); 123 if (sscanf(resolution.c_str(),
124 "%dx%d%%%f",
125 &width,
126 &height,
127 &refresh_rate) >= 2) {
128 bool native = false;
129 if (height == bounds_in_native.size().height() &&
130 width == bounds_in_native.size().width())
131 native = true;
oshima 2014/01/28 22:17:09 This will make the specified resolution always the
sheu 2014/01/29 00:14:11 OK, will do.
132 display_modes.push_back(
133 DisplayMode(gfx::Size(width, height), refresh_rate, false, native));
134 }
117 } 135 }
118 } 136 }
119 137
120 if (id == gfx::Display::kInvalidDisplayID) 138 if (id == gfx::Display::kInvalidDisplayID)
121 id = synthesized_display_id++; 139 id = synthesized_display_id++;
122 DisplayInfo display_info( 140 DisplayInfo display_info(
123 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); 141 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan);
124 display_info.set_device_scale_factor(device_scale_factor); 142 display_info.set_device_scale_factor(device_scale_factor);
125 display_info.set_rotation(rotation); 143 display_info.set_rotation(rotation);
126 display_info.set_configured_ui_scale(ui_scale); 144 display_info.set_configured_ui_scale(ui_scale);
127 display_info.SetBounds(bounds_in_native); 145 display_info.SetBounds(bounds_in_native);
128 display_info.set_resolutions(resolutions); 146 display_info.set_display_modes(display_modes);
129 147
130 // To test the overscan, it creates the default 5% overscan. 148 // To test the overscan, it creates the default 5% overscan.
131 if (has_overscan) { 149 if (has_overscan) {
132 int width = bounds_in_native.width() / device_scale_factor / 40; 150 int width = bounds_in_native.width() / device_scale_factor / 40;
133 int height = bounds_in_native.height() / device_scale_factor / 40; 151 int height = bounds_in_native.height() / device_scale_factor / 40;
134 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width)); 152 display_info.SetOverscanInsets(gfx::Insets(height, width, height, width));
135 display_info.UpdateDisplaySize(); 153 display_info.UpdateDisplaySize();
136 } 154 }
137 155
138 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString() 156 DVLOG(1) << "DisplayInfoFromSpec info=" << display_info.ToString()
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 188
171 void DisplayInfo::Copy(const DisplayInfo& native_info) { 189 void DisplayInfo::Copy(const DisplayInfo& native_info) {
172 DCHECK(id_ == native_info.id_); 190 DCHECK(id_ == native_info.id_);
173 name_ = native_info.name_; 191 name_ = native_info.name_;
174 has_overscan_ = native_info.has_overscan_; 192 has_overscan_ = native_info.has_overscan_;
175 193
176 DCHECK(!native_info.bounds_in_native_.IsEmpty()); 194 DCHECK(!native_info.bounds_in_native_.IsEmpty());
177 bounds_in_native_ = native_info.bounds_in_native_; 195 bounds_in_native_ = native_info.bounds_in_native_;
178 size_in_pixel_ = native_info.size_in_pixel_; 196 size_in_pixel_ = native_info.size_in_pixel_;
179 device_scale_factor_ = native_info.device_scale_factor_; 197 device_scale_factor_ = native_info.device_scale_factor_;
180 resolutions_ = native_info.resolutions_; 198 display_modes_ = native_info.display_modes_;
181 touch_support_ = native_info.touch_support_; 199 touch_support_ = native_info.touch_support_;
182 200
183 // Copy overscan_insets_in_dip_ if it's not empty. This is for test 201 // Copy overscan_insets_in_dip_ if it's not empty. This is for test
184 // cases which use "/o" annotation which sets the overscan inset 202 // cases which use "/o" annotation which sets the overscan inset
185 // to native, and that overscan has to be propagated. This does not 203 // to native, and that overscan has to be propagated. This does not
186 // happen on the real environment. 204 // happen on the real environment.
187 if (!native_info.overscan_insets_in_dip_.empty()) 205 if (!native_info.overscan_insets_in_dip_.empty())
188 overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_; 206 overscan_insets_in_dip_ = native_info.overscan_insets_in_dip_;
189 207
190 // Rotation_ and ui_scale_ are given by preference, or unit 208 // Rotation_ and ui_scale_ are given by preference, or unit
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 return base::StringPrintf( 260 return base::StringPrintf(
243 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, " 261 "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, "
244 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s", 262 "overscan=%s, rotation=%d, ui-scale=%f, touchscreen=%s",
245 static_cast<long long int>(id_), 263 static_cast<long long int>(id_),
246 bounds_in_native_.ToString().c_str(), 264 bounds_in_native_.ToString().c_str(),
247 size_in_pixel_.ToString().c_str(), 265 size_in_pixel_.ToString().c_str(),
248 device_scale_factor_, 266 device_scale_factor_,
249 overscan_insets_in_dip_.ToString().c_str(), 267 overscan_insets_in_dip_.ToString().c_str(),
250 rotation_degree, 268 rotation_degree,
251 configured_ui_scale_, 269 configured_ui_scale_,
252 touch_support_ == gfx::Display::TOUCH_SUPPORT_AVAILABLE ? "yes" : 270 touch_support_ == gfx::Display::TOUCH_SUPPORT_AVAILABLE
253 touch_support_ == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE ? "no" : 271 ? "yes"
254 "unknown"); 272 : touch_support_ == gfx::Display::TOUCH_SUPPORT_UNAVAILABLE
273 ? "no"
274 : "unknown");
255 } 275 }
256 276
257 std::string DisplayInfo::ToFullString() const { 277 std::string DisplayInfo::ToFullString() const {
258 std::string resolutions_str; 278 std::string display_modes_str;
259 std::vector<Resolution>::const_iterator iter = resolutions_.begin(); 279 std::vector<DisplayMode>::const_iterator iter = display_modes_.begin();
260 for (; iter != resolutions_.end(); ++iter) { 280 for (; iter != display_modes_.end(); ++iter) {
261 if (!resolutions_str.empty()) 281 if (!display_modes_str.empty())
262 resolutions_str += ","; 282 display_modes_str += ",";
263 resolutions_str += iter->size.ToString(); 283 base::StringAppendF(&display_modes_str,
264 if (iter->interlaced) 284 "(%dx%d@%f%c%s)",
265 resolutions_str += "(i)"; 285 iter->size.width(),
286 iter->size.height(),
287 iter->refresh_rate,
288 iter->interlaced ? 'I' : 'P',
289 iter->native ? "(N)" : "");
266 } 290 }
267 return ToString() + ", resolutions=" + resolutions_str; 291 return ToString() + ", display_modes==" + display_modes_str;
268 } 292 }
269 293
270 } // namespace internal 294 } // namespace internal
271 } // namespace ash 295 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698