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

Unified Diff: ash/display/display_info.cc

Issue 455443002: Remember the configured device scale factor for external displays. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/display/display_change_observer_chromeos.cc ('k') | ash/display/display_info_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/display/display_info.cc
diff --git a/ash/display/display_info.cc b/ash/display/display_info.cc
index bffaf3e3516f46353667354c16ef4fca4274b5f8..dc37650f3c81cb2f7875d2ed1697d50c71bf9aaa 100644
--- a/ash/display/display_info.cc
+++ b/ash/display/display_info.cc
@@ -26,6 +26,24 @@ namespace {
// TODO(oshima): This feature is obsolete. Remove this after m38.
bool allow_upgrade_to_high_dpi = false;
+// Check the content of |spec| and fill |bounds| and |device_scale_factor|.
+// Returns true when |bounds| is found.
+bool GetDisplayBounds(
+ const std::string& spec, gfx::Rect* bounds, float* device_scale_factor) {
+ int width = 0;
+ int height = 0;
+ int x = 0;
+ int y = 0;
+ if (sscanf(spec.c_str(), "%dx%d*%f",
+ &width, &height, device_scale_factor) >= 2 ||
+ sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height,
+ device_scale_factor) >= 4) {
+ bounds->SetRect(x, y, width, height);
+ return true;
+ }
+ return false;
+}
+
}
DisplayMode::DisplayMode()
@@ -126,14 +144,8 @@ DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec,
}
}
- int x = 0, y = 0, width, height;
float device_scale_factor = 1.0f;
- if (sscanf(main_spec.c_str(), "%dx%d*%f",
- &width, &height, &device_scale_factor) >= 2 ||
- sscanf(main_spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height,
- &device_scale_factor) >= 4) {
- bounds_in_native.SetRect(x, y, width, height);
- } else {
+ if (!GetDisplayBounds(main_spec, &bounds_in_native, &device_scale_factor)) {
#if defined(OS_WIN)
if (gfx::IsHighDPIEnabled()) {
device_scale_factor = gfx::GetDPIScale();
@@ -150,23 +162,23 @@ DisplayInfo DisplayInfo::CreateFromSpecWithID(const std::string& spec,
std::string resolution_list = parts[1];
count = Tokenize(resolution_list, "|", &parts);
for (size_t i = 0; i < count; ++i) {
- std::string resolution = parts[i];
- int width, height;
- float refresh_rate = 0.0f;
- if (sscanf(resolution.c_str(),
- "%dx%d%%%f",
- &width,
- &height,
- &refresh_rate) >= 2) {
- if (width * height >= largest_area &&
- refresh_rate > highest_refresh_rate) {
+ DisplayMode mode;
+ gfx::Rect mode_bounds;
+ std::vector<std::string> resolution;
+ Tokenize(parts[i], "%", &resolution);
+ if (GetDisplayBounds(
+ resolution[0], &mode_bounds, &mode.device_scale_factor)) {
+ mode.size = mode_bounds.size();
+ if (resolution.size() > 1)
+ sscanf(resolution[1].c_str(), "%f", &mode.refresh_rate);
+ if (mode.size.GetArea() >= largest_area &&
+ mode.refresh_rate > highest_refresh_rate) {
// Use mode with largest area and highest refresh rate as native.
- largest_area = width * height;
- highest_refresh_rate = refresh_rate;
+ largest_area = mode.size.GetArea();
+ highest_refresh_rate = mode.refresh_rate;
native_mode = i;
}
- display_modes.push_back(
- DisplayMode(gfx::Size(width, height), refresh_rate, false, false));
+ display_modes.push_back(mode);
}
}
display_modes[native_mode].native = true;
« no previous file with comments | « ash/display/display_change_observer_chromeos.cc ('k') | ash/display/display_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698