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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
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 { 24 namespace {
25 25
26 // TODO(oshima): This feature is obsolete. Remove this after m38. 26 // TODO(oshima): This feature is obsolete. Remove this after m38.
27 bool allow_upgrade_to_high_dpi = false; 27 bool allow_upgrade_to_high_dpi = false;
28 28
29 // Check the content of |spec| and fill |bounds| and |device_scale_factor|.
30 // Returns true when |bounds| is found.
31 bool GetDisplayBounds(
32 const std::string& spec, gfx::Rect* bounds, float* device_scale_factor) {
33 int width = 0;
34 int height = 0;
35 int x = 0;
36 int y = 0;
37 if (sscanf(spec.c_str(), "%dx%d*%f",
38 &width, &height, device_scale_factor) >= 2 ||
39 sscanf(spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height,
40 device_scale_factor) >= 4) {
41 bounds->SetRect(x, y, width, height);
42 return true;
43 }
44 return false;
45 }
46
29 } 47 }
30 48
31 DisplayMode::DisplayMode() 49 DisplayMode::DisplayMode()
32 : refresh_rate(0.0f), 50 : refresh_rate(0.0f),
33 interlaced(false), 51 interlaced(false),
34 native(false), 52 native(false),
35 ui_scale(1.0f), 53 ui_scale(1.0f),
36 device_scale_factor(1.0f) {} 54 device_scale_factor(1.0f) {}
37 55
38 DisplayMode::DisplayMode(const gfx::Size& size, 56 DisplayMode::DisplayMode(const gfx::Size& size,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 rotation = gfx::Display::ROTATE_180; 137 rotation = gfx::Display::ROTATE_180;
120 break; 138 break;
121 case 'l': // rotate 90 degrees to 'left'. 139 case 'l': // rotate 90 degrees to 'left'.
122 rotation = gfx::Display::ROTATE_270; 140 rotation = gfx::Display::ROTATE_270;
123 break; 141 break;
124 } 142 }
125 } 143 }
126 } 144 }
127 } 145 }
128 146
129 int x = 0, y = 0, width, height;
130 float device_scale_factor = 1.0f; 147 float device_scale_factor = 1.0f;
131 if (sscanf(main_spec.c_str(), "%dx%d*%f", 148 if (!GetDisplayBounds(main_spec, &bounds_in_native, &device_scale_factor)) {
132 &width, &height, &device_scale_factor) >= 2 ||
133 sscanf(main_spec.c_str(), "%d+%d-%dx%d*%f", &x, &y, &width, &height,
134 &device_scale_factor) >= 4) {
135 bounds_in_native.SetRect(x, y, width, height);
136 } else {
137 #if defined(OS_WIN) 149 #if defined(OS_WIN)
138 if (gfx::IsHighDPIEnabled()) { 150 if (gfx::IsHighDPIEnabled()) {
139 device_scale_factor = gfx::GetDPIScale(); 151 device_scale_factor = gfx::GetDPIScale();
140 } 152 }
141 #endif 153 #endif
142 } 154 }
143 155
144 std::vector<DisplayMode> display_modes; 156 std::vector<DisplayMode> display_modes;
145 if (Tokenize(main_spec, "#", &parts) == 2) { 157 if (Tokenize(main_spec, "#", &parts) == 2) {
146 size_t native_mode = 0; 158 size_t native_mode = 0;
147 int largest_area = -1; 159 int largest_area = -1;
148 float highest_refresh_rate = -1.0f; 160 float highest_refresh_rate = -1.0f;
149 main_spec = parts[0]; 161 main_spec = parts[0];
150 std::string resolution_list = parts[1]; 162 std::string resolution_list = parts[1];
151 count = Tokenize(resolution_list, "|", &parts); 163 count = Tokenize(resolution_list, "|", &parts);
152 for (size_t i = 0; i < count; ++i) { 164 for (size_t i = 0; i < count; ++i) {
153 std::string resolution = parts[i]; 165 DisplayMode mode;
154 int width, height; 166 gfx::Rect mode_bounds;
155 float refresh_rate = 0.0f; 167 std::vector<std::string> resolution;
156 if (sscanf(resolution.c_str(), 168 Tokenize(parts[i], "%", &resolution);
157 "%dx%d%%%f", 169 if (GetDisplayBounds(
158 &width, 170 resolution[0], &mode_bounds, &mode.device_scale_factor)) {
159 &height, 171 mode.size = mode_bounds.size();
160 &refresh_rate) >= 2) { 172 if (resolution.size() > 1)
161 if (width * height >= largest_area && 173 sscanf(resolution[1].c_str(), "%f", &mode.refresh_rate);
162 refresh_rate > highest_refresh_rate) { 174 if (mode.size.GetArea() >= largest_area &&
175 mode.refresh_rate > highest_refresh_rate) {
163 // Use mode with largest area and highest refresh rate as native. 176 // Use mode with largest area and highest refresh rate as native.
164 largest_area = width * height; 177 largest_area = mode.size.GetArea();
165 highest_refresh_rate = refresh_rate; 178 highest_refresh_rate = mode.refresh_rate;
166 native_mode = i; 179 native_mode = i;
167 } 180 }
168 display_modes.push_back( 181 display_modes.push_back(mode);
169 DisplayMode(gfx::Size(width, height), refresh_rate, false, false));
170 } 182 }
171 } 183 }
172 display_modes[native_mode].native = true; 184 display_modes[native_mode].native = true;
173 } 185 }
174 186
175 if (id == gfx::Display::kInvalidDisplayID) 187 if (id == gfx::Display::kInvalidDisplayID)
176 id = synthesized_display_id++; 188 id = synthesized_display_id++;
177 DisplayInfo display_info( 189 DisplayInfo display_info(
178 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); 190 id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan);
179 display_info.set_device_scale_factor(device_scale_factor); 191 display_info.set_device_scale_factor(device_scale_factor);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } 372 }
361 373
362 bool DisplayInfo::IsColorProfileAvailable( 374 bool DisplayInfo::IsColorProfileAvailable(
363 ui::ColorCalibrationProfile profile) const { 375 ui::ColorCalibrationProfile profile) const {
364 return std::find(available_color_profiles_.begin(), 376 return std::find(available_color_profiles_.begin(),
365 available_color_profiles_.end(), 377 available_color_profiles_.end(),
366 profile) != available_color_profiles_.end(); 378 profile) != available_color_profiles_.end();
367 } 379 }
368 380
369 } // namespace ash 381 } // namespace ash
OLDNEW
« 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