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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/display_options_handler.cc

Issue 138903025: Read compositor VSync information from platform, when possible (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 4b969456 piman@ comments; refactor logic into CompositorVSyncManager 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/webui/options/chromeos/display_options_handler.h" 5 #include "chrome/browser/ui/webui/options/chromeos/display_options_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/display/display_controller.h" 9 #include "ash/display/display_controller.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 int64 display_id = gfx::Display::kInvalidDisplayID; 48 int64 display_id = gfx::Display::kInvalidDisplayID;
49 if (!base::StringToInt64(id_value, &display_id)) { 49 if (!base::StringToInt64(id_value, &display_id)) {
50 LOG(ERROR) << "Invalid display id: " << id_value; 50 LOG(ERROR) << "Invalid display id: " << id_value;
51 return gfx::Display::kInvalidDisplayID; 51 return gfx::Display::kInvalidDisplayID;
52 } 52 }
53 53
54 return display_id; 54 return display_id;
55 } 55 }
56 56
57 bool CompareResolution(ash::internal::Resolution r1, 57 bool CompareDisplayMode(ash::internal::DisplayMode d1,
58 ash::internal::Resolution r2) { 58 ash::internal::DisplayMode d2) {
59 return r1.size.GetArea() < r2.size.GetArea(); 59 if (d1.size.GetArea() == d2.size.GetArea())
60 return d1.refresh_rate < d2.refresh_rate;
61 return d1.size.GetArea() < d2.size.GetArea();
60 } 62 }
61 63
62 } // namespace 64 } // namespace
63 65
64 DisplayOptionsHandler::DisplayOptionsHandler() { 66 DisplayOptionsHandler::DisplayOptionsHandler() {
65 ash::Shell::GetInstance()->display_controller()->AddObserver(this); 67 ash::Shell::GetInstance()->display_controller()->AddObserver(this);
66 } 68 }
67 69
68 DisplayOptionsHandler::~DisplayOptionsHandler() { 70 DisplayOptionsHandler::~DisplayOptionsHandler() {
69 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); 71 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 js_display->SetInteger("x", bounds.x()); 182 js_display->SetInteger("x", bounds.x());
181 js_display->SetInteger("y", bounds.y()); 183 js_display->SetInteger("y", bounds.y());
182 js_display->SetInteger("width", bounds.width()); 184 js_display->SetInteger("width", bounds.width());
183 js_display->SetInteger("height", bounds.height()); 185 js_display->SetInteger("height", bounds.height());
184 js_display->SetString("name", 186 js_display->SetString("name",
185 display_manager->GetDisplayNameForId(display.id())); 187 display_manager->GetDisplayNameForId(display.id()));
186 js_display->SetBoolean("isPrimary", display.id() == primary_id); 188 js_display->SetBoolean("isPrimary", display.id() == primary_id);
187 js_display->SetBoolean("isInternal", display.IsInternal()); 189 js_display->SetBoolean("isInternal", display.IsInternal());
188 js_display->SetInteger("orientation", 190 js_display->SetInteger("orientation",
189 static_cast<int>(display_info.rotation())); 191 static_cast<int>(display_info.rotation()));
190 std::vector<ash::internal::Resolution> resolutions; 192 std::vector<ash::internal::DisplayMode> display_modes;
191 std::vector<float> ui_scales; 193 std::vector<float> ui_scales;
192 if (display.IsInternal()) { 194 if (display.IsInternal()) {
193 ui_scales = DisplayManager::GetScalesForDisplay(display_info); 195 ui_scales = DisplayManager::GetScalesForDisplay(display_info);
194 gfx::SizeF base_size = display_info.bounds_in_native().size(); 196 gfx::SizeF base_size = display_info.bounds_in_native().size();
195 base_size.Scale(1.0f / display_info.device_scale_factor()); 197 base_size.Scale(1.0f / display_info.device_scale_factor());
196 if (display_info.rotation() == gfx::Display::ROTATE_90 || 198 if (display_info.rotation() == gfx::Display::ROTATE_90 ||
197 display_info.rotation() == gfx::Display::ROTATE_270) { 199 display_info.rotation() == gfx::Display::ROTATE_270) {
198 float tmp = base_size.width(); 200 float tmp = base_size.width();
199 base_size.set_width(base_size.height()); 201 base_size.set_width(base_size.height());
200 base_size.set_height(tmp); 202 base_size.set_height(tmp);
201 } 203 }
202 for (size_t i = 0; i < ui_scales.size(); ++i) { 204 for (size_t i = 0; i < ui_scales.size(); ++i) {
203 gfx::SizeF new_size = base_size; 205 gfx::SizeF new_size = base_size;
204 new_size.Scale(ui_scales[i]); 206 new_size.Scale(ui_scales[i]);
205 resolutions.push_back(ash::internal::Resolution( 207 display_modes.push_back(ash::internal::DisplayMode(
206 gfx::ToFlooredSize(new_size), false /* interlaced */)); 208 gfx::ToFlooredSize(new_size), -1.0f, false, false));
207 } 209 }
208 } else { 210 } else {
209 for (size_t i = 0; i < display_info.resolutions().size(); ++i) 211 for (size_t i = 0; i < display_info.display_modes().size(); ++i)
210 resolutions.push_back(display_info.resolutions()[i]); 212 display_modes.push_back(display_info.display_modes()[i]);
211 } 213 }
212 std::sort(resolutions.begin(), resolutions.end(), CompareResolution); 214 std::sort(display_modes.begin(), display_modes.end(), CompareDisplayMode);
213 215
214 base::ListValue* js_resolutions = new base::ListValue(); 216 base::ListValue* js_resolutions = new base::ListValue();
215 gfx::Size current_size = display_info.bounds_in_native().size(); 217 gfx::Size current_size = display_info.bounds_in_native().size();
216 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); 218 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel();
217 for (size_t i = 0; i < resolutions.size(); ++i) { 219 for (size_t i = 0; i < display_modes.size(); ++i) {
218 base::DictionaryValue* resolution_info = new base::DictionaryValue(); 220 base::DictionaryValue* resolution_info = new base::DictionaryValue();
219 gfx::Size resolution = resolutions[i].size; 221 gfx::Size resolution = display_modes[i].size;
220 if (!ui_scales.empty()) { 222 if (!ui_scales.empty()) {
221 resolution_info->SetDouble("scale", ui_scales[i]); 223 resolution_info->SetDouble("scale", ui_scales[i]);
222 if (ui_scales[i] == 1.0f) 224 if (ui_scales[i] == 1.0f)
223 resolution_info->SetBoolean("isBest", true); 225 resolution_info->SetBoolean("isBest", true);
224 resolution_info->SetBoolean( 226 resolution_info->SetBoolean(
225 "selected", display_info.configured_ui_scale() == ui_scales[i]); 227 "selected", display_info.configured_ui_scale() == ui_scales[i]);
226 } else { 228 } else {
227 // Picks the largest one as the "best", which is the last element 229 // Picks the largest one as the "best", which is the last element
228 // because |resolutions| is sorted by its area. 230 // because |display_modes| is sorted by its area.
229 if (i == resolutions.size() - 1) 231 if (i == display_modes.size() - 1)
230 resolution_info->SetBoolean("isBest", true); 232 resolution_info->SetBoolean("isBest", true);
231 resolution_info->SetBoolean("selected", (resolution == current_size)); 233 resolution_info->SetBoolean("selected", (resolution == current_size));
232 resolution.Enlarge( 234 resolution.Enlarge(
233 -current_overscan.width(), -current_overscan.height()); 235 -current_overscan.width(), -current_overscan.height());
234 } 236 }
235 resolution_info->SetInteger("width", resolution.width()); 237 resolution_info->SetInteger("width", resolution.width());
236 resolution_info->SetInteger("height", resolution.height()); 238 resolution_info->SetInteger("height", resolution.height());
piman 2014/02/04 04:51:01 nit: it'd be nice to surface the refresh rate here
sheu 2014/02/04 22:01:45 Sure.
237 js_resolutions->Append(resolution_info); 239 js_resolutions->Append(resolution_info);
238 } 240 }
239 js_display->Set("resolutions", js_resolutions); 241 js_display->Set("resolutions", js_resolutions);
240 js_displays.Append(js_display); 242 js_displays.Append(js_display);
241 } 243 }
242 244
243 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue()); 245 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue());
244 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue()); 246 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue());
245 if (display_manager->GetNumDisplays() > 1) { 247 if (display_manager->GetNumDisplays() > 1) {
246 const ash::DisplayLayout layout = 248 const ash::DisplayLayout layout =
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 347 }
346 348
347 const ash::internal::DisplayInfo& display_info = 349 const ash::internal::DisplayInfo& display_info =
348 GetDisplayManager()->GetDisplayInfo(display_id); 350 GetDisplayManager()->GetDisplayInfo(display_id);
349 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); 351 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel();
350 gfx::Size new_resolution = gfx::ToFlooredSize(gfx::SizeF(width, height)); 352 gfx::Size new_resolution = gfx::ToFlooredSize(gfx::SizeF(width, height));
351 new_resolution.Enlarge(current_overscan.width(), current_overscan.height()); 353 new_resolution.Enlarge(current_overscan.width(), current_overscan.height());
352 gfx::Size old_resolution = display_info.bounds_in_native().size(); 354 gfx::Size old_resolution = display_info.bounds_in_native().size();
353 bool has_new_resolution = false; 355 bool has_new_resolution = false;
354 bool has_old_resolution = false; 356 bool has_old_resolution = false;
355 for (size_t i = 0; i < display_info.resolutions().size(); ++i) { 357 for (size_t i = 0; i < display_info.display_modes().size(); ++i) {
356 ash::internal::Resolution resolution = display_info.resolutions()[i]; 358 ash::internal::DisplayMode display_mode = display_info.display_modes()[i];
357 if (resolution.size == new_resolution) 359 if (display_mode.size == new_resolution)
358 has_new_resolution = true; 360 has_new_resolution = true;
359 if (resolution.size == old_resolution) 361 if (display_mode.size == old_resolution)
360 has_old_resolution = true; 362 has_old_resolution = true;
361 } 363 }
362 if (!has_new_resolution) { 364 if (!has_new_resolution) {
363 LOG(ERROR) << "No new resolution " << new_resolution.ToString() 365 LOG(ERROR) << "No new resolution " << new_resolution.ToString()
364 << " is found in the display info " << display_info.ToString(); 366 << " is found in the display info " << display_info.ToString();
365 return; 367 return;
366 } 368 }
367 if (!has_old_resolution) { 369 if (!has_old_resolution) {
368 LOG(ERROR) << "No old resolution " << old_resolution.ToString() 370 LOG(ERROR) << "No old resolution " << old_resolution.ToString()
369 << " is found in the display info " << display_info.ToString(); 371 << " is found in the display info " << display_info.ToString();
(...skipping 26 matching lines...) Expand all
396 else if (rotation_value == "270") 398 else if (rotation_value == "270")
397 new_rotation = gfx::Display::ROTATE_270; 399 new_rotation = gfx::Display::ROTATE_270;
398 else if (rotation_value != "0") 400 else if (rotation_value != "0")
399 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; 401 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0";
400 402
401 GetDisplayManager()->SetDisplayRotation(display_id, new_rotation); 403 GetDisplayManager()->SetDisplayRotation(display_id, new_rotation);
402 } 404 }
403 405
404 } // namespace options 406 } // namespace options
405 } // namespace chromeos 407 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698