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

Side by Side Diff: chrome/browser/extensions/display_info_provider_chromeos.cc

Issue 2002773002: Add overscanCalibration methods to system_display.idl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix non-chromeos + tests Created 4 years, 7 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/extensions/display_info_provider_chromeos.h" 5 #include "chrome/browser/extensions/display_info_provider_chromeos.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "ash/display/display_configuration_controller.h" 9 #include "ash/display/display_configuration_controller.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
11 #include "ash/display/resolution_notification_controller.h" 11 #include "ash/display/resolution_notification_controller.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "chrome/browser/chromeos/display/display_preferences.h" 14 #include "chrome/browser/chromeos/display/display_preferences.h"
15 #include "chrome/browser/chromeos/display/overscan_calibrator.h"
15 #include "extensions/common/api/system_display.h" 16 #include "extensions/common/api/system_display.h"
16 #include "ui/display/display.h" 17 #include "ui/display/display.h"
17 #include "ui/display/manager/display_layout.h" 18 #include "ui/display/manager/display_layout.h"
18 #include "ui/gfx/geometry/point.h" 19 #include "ui/gfx/geometry/point.h"
19 #include "ui/gfx/geometry/rect.h" 20 #include "ui/gfx/geometry/rect.h"
20 21
21 namespace extensions { 22 namespace extensions {
22 23
23 using api::system_display::Bounds; 24 using api::system_display::Bounds;
24 using api::system_display::DisplayUnitInfo; 25 using api::system_display::DisplayUnitInfo;
25 using api::system_display::DisplayProperties; 26 using api::system_display::DisplayProperties;
26 using api::system_display::Insets; 27 using api::system_display::Insets;
27 28
28 namespace { 29 namespace {
29 30
30 // Maximum allowed bounds origin absolute value. 31 // Maximum allowed bounds origin absolute value.
31 const int kMaxBoundsOrigin = 200 * 1000; 32 const int kMaxBoundsOrigin = 200 * 1000;
32 33
34 // Gets the display with the provided string id.
35 display::Display GetDisplay(const std::string& display_id_str) {
36 int64_t display_id;
37 if (!base::StringToInt64(display_id_str, &display_id))
38 return display::Display();
39 return ash::Shell::GetInstance()->display_manager()->GetDisplayForId(
40 display_id);
41 }
42
33 // Checks if the given integer value is valid display rotation in degrees. 43 // Checks if the given integer value is valid display rotation in degrees.
34 bool IsValidRotationValue(int rotation) { 44 bool IsValidRotationValue(int rotation) {
35 return rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270; 45 return rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270;
36 } 46 }
37 47
38 // Converts integer integer value in degrees to Rotation enum value. 48 // Converts integer integer value in degrees to Rotation enum value.
39 display::Display::Rotation DegreesToRotation(int degrees) { 49 display::Display::Rotation DegreesToRotation(int degrees) {
40 DCHECK(IsValidRotationValue(degrees)); 50 DCHECK(IsValidRotationValue(degrees));
41 switch (degrees) { 51 switch (degrees) {
42 case 0: 52 case 0:
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 ash::DisplayManager* display_manager, 198 ash::DisplayManager* display_manager,
189 int64_t primary_display_id, 199 int64_t primary_display_id,
190 std::string* error) { 200 std::string* error) {
191 int64_t id = display.id(); 201 int64_t id = display.id();
192 bool is_primary = 202 bool is_primary =
193 id == primary_display_id || (info.is_primary && *info.is_primary); 203 id == primary_display_id || (info.is_primary && *info.is_primary);
194 204
195 // If mirroring source id is set, a display with the given id should exist, 205 // If mirroring source id is set, a display with the given id should exist,
196 // and if should not be the same as the target display's id. 206 // and if should not be the same as the target display's id.
197 if (info.mirroring_source_id && !info.mirroring_source_id->empty()) { 207 if (info.mirroring_source_id && !info.mirroring_source_id->empty()) {
198 int64_t mirroring_id; 208 int64_t mirroring_id = GetDisplay(*info.mirroring_source_id).id();
199 if (!base::StringToInt64(*info.mirroring_source_id, &mirroring_id) || 209 if (mirroring_id == display::Display::kInvalidDisplayID) {
200 display_manager->GetDisplayForId(mirroring_id).id() ==
201 display::Display::kInvalidDisplayID) {
202 *error = "Display " + *info.mirroring_source_id + " not found."; 210 *error = "Display " + *info.mirroring_source_id + " not found.";
203 return false; 211 return false;
204 } 212 }
205 213
206 if (*info.mirroring_source_id == base::Int64ToString(id)) { 214 if (*info.mirroring_source_id == base::Int64ToString(id)) {
207 *error = "Not allowed to mirror self."; 215 *error = "Not allowed to mirror self.";
208 return false; 216 return false;
209 } 217 }
210 } 218 }
211 219
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // change. 312 // change.
305 ash::Shell::GetInstance() 313 ash::Shell::GetInstance()
306 ->resolution_notification_controller() 314 ->resolution_notification_controller()
307 ->PrepareNotification(id, current_mode, new_mode, 315 ->PrepareNotification(id, current_mode, new_mode,
308 base::Bind(&chromeos::StoreDisplayPrefs)); 316 base::Bind(&chromeos::StoreDisplayPrefs));
309 } 317 }
310 } 318 }
311 return true; 319 return true;
312 } 320 }
313 321
314 // Gets the display with the provided string id.
315 display::Display GetTargetDisplay(const std::string& display_id_str,
316 ash::DisplayManager* manager) {
317 int64_t display_id;
318 if (!base::StringToInt64(display_id_str, &display_id)) {
319 // This should return invalid display.
320 return display::Display();
321 }
322 return manager->GetDisplayForId(display_id);
323 }
324
325 extensions::api::system_display::DisplayMode GetDisplayMode( 322 extensions::api::system_display::DisplayMode GetDisplayMode(
326 ash::DisplayManager* display_manager, 323 ash::DisplayManager* display_manager,
327 const ash::DisplayInfo& display_info, 324 const ash::DisplayInfo& display_info,
328 const ash::DisplayMode& display_mode) { 325 const ash::DisplayMode& display_mode) {
329 extensions::api::system_display::DisplayMode result; 326 extensions::api::system_display::DisplayMode result;
330 327
331 bool is_internal = display::Display::HasInternalDisplay() && 328 bool is_internal = display::Display::HasInternalDisplay() &&
332 display::Display::InternalDisplayId() == display_info.id(); 329 display::Display::InternalDisplayId() == display_info.id();
333 gfx::Size size_dip = display_mode.GetSizeInDIP(is_internal); 330 gfx::Size size_dip = display_mode.GetSizeInDIP(is_internal);
334 result.width = size_dip.width(); 331 result.width = size_dip.width();
(...skipping 17 matching lines...) Expand all
352 } 349 }
353 350
354 bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str, 351 bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str,
355 const DisplayProperties& info, 352 const DisplayProperties& info,
356 std::string* error) { 353 std::string* error) {
357 ash::DisplayManager* display_manager = 354 ash::DisplayManager* display_manager =
358 ash::Shell::GetInstance()->display_manager(); 355 ash::Shell::GetInstance()->display_manager();
359 ash::DisplayConfigurationController* display_configuration_controller = 356 ash::DisplayConfigurationController* display_configuration_controller =
360 ash::Shell::GetInstance()->display_configuration_controller(); 357 ash::Shell::GetInstance()->display_configuration_controller();
361 358
362 const display::Display target = 359 const display::Display target = GetDisplay(display_id_str);
363 GetTargetDisplay(display_id_str, display_manager);
364 360
365 if (target.id() == display::Display::kInvalidDisplayID) { 361 if (target.id() == display::Display::kInvalidDisplayID) {
366 *error = "Display not found."; 362 *error = "Display not found.";
367 return false; 363 return false;
368 } 364 }
369 365
370 int64_t display_id = target.id(); 366 int64_t display_id = target.id();
371 const display::Display& primary = 367 const display::Display& primary =
372 display::Screen::GetScreen()->GetPrimaryDisplay(); 368 display::Screen::GetScreen()->GetPrimaryDisplay();
373 369
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 DisplayUnitInfoList all_displays; 471 DisplayUnitInfoList all_displays;
476 for (const display::Display& display : displays) { 472 for (const display::Display& display : displays) {
477 api::system_display::DisplayUnitInfo unit = 473 api::system_display::DisplayUnitInfo unit =
478 CreateDisplayUnitInfo(display, primary_id); 474 CreateDisplayUnitInfo(display, primary_id);
479 UpdateDisplayUnitInfoForPlatform(display, &unit); 475 UpdateDisplayUnitInfoForPlatform(display, &unit);
480 all_displays.push_back(std::move(unit)); 476 all_displays.push_back(std::move(unit));
481 } 477 }
482 return all_displays; 478 return all_displays;
483 } 479 }
484 480
481 bool DisplayInfoProviderChromeOS::OverscanCalibrationStart(
482 const std::string& id) {
483 VLOG(1) << "OverscanCalibrationStart: " << id;
484 const display::Display display = GetDisplay(id);
485 if (display.id() == display::Display::kInvalidDisplayID)
486 return false;
487 auto insets =
488 ash::Shell::GetInstance()->window_tree_host_manager()->GetOverscanInsets(
489 display.id());
490 overscan_calibrators_[id].reset(
491 new chromeos::OverscanCalibrator(display, insets));
492 return true;
493 }
494
495 bool DisplayInfoProviderChromeOS::OverscanCalibrationAdjust(
496 const std::string& id,
497 const api::system_display::Insets& delta) {
498 VLOG(1) << "OverscanCalibrationAdjust: " << id;
499 chromeos::OverscanCalibrator* calibrator = GetCalibrator(id);
500 if (!calibrator)
501 return false;
502 gfx::Insets insets = calibrator->insets();
503 insets += gfx::Insets(delta.top, delta.left, delta.bottom, delta.right);
504 calibrator->UpdateInsets(insets);
505 return true;
506 }
507
508 bool DisplayInfoProviderChromeOS::OverscanCalibrationReset(
509 const std::string& id) {
510 VLOG(1) << "OverscanCalibrationReset: " << id;
511 chromeos::OverscanCalibrator* calibrator = GetCalibrator(id);
512 if (!calibrator)
513 return false;
514 calibrator->Reset();
515 return true;
516 }
517
518 bool DisplayInfoProviderChromeOS::OverscanCalibrationComplete(
519 const std::string& id) {
520 VLOG(1) << "OverscanCalibrationComplete: " << id;
521 chromeos::OverscanCalibrator* calibrator = GetCalibrator(id);
522 if (!calibrator)
523 return false;
524 calibrator->Commit();
525 overscan_calibrators_[id].reset();
526 return true;
527 }
528
529 chromeos::OverscanCalibrator* DisplayInfoProviderChromeOS::GetCalibrator(
530 const std::string& id) {
531 auto iter = overscan_calibrators_.find(id);
532 if (iter == overscan_calibrators_.end())
533 return nullptr;
534 return iter->second.get();
535 }
536
485 // static 537 // static
486 DisplayInfoProvider* DisplayInfoProvider::Create() { 538 DisplayInfoProvider* DisplayInfoProvider::Create() {
487 return new DisplayInfoProviderChromeOS(); 539 return new DisplayInfoProviderChromeOS();
488 } 540 }
489 541
490 } // namespace extensions 542 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698