| OLD | NEW |
| 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 "ui/display/screen.h" | 5 #include "ui/display/screen.h" |
| 6 | 6 |
| 7 #import <ApplicationServices/ApplicationServices.h> | 7 #import <ApplicationServices/ApplicationServices.h> |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 | 13 |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
| 17 #include "base/mac/scoped_nsobject.h" |
| 17 #include "base/mac/sdk_forward_declarations.h" | 18 #include "base/mac/sdk_forward_declarations.h" |
| 18 #include "base/macros.h" | 19 #include "base/macros.h" |
| 19 #include "base/timer/timer.h" | 20 #include "base/timer/timer.h" |
| 20 #include "ui/display/display.h" | 21 #include "ui/display/display.h" |
| 21 #include "ui/display/display_change_notifier.h" | 22 #include "ui/display/display_change_notifier.h" |
| 22 #include "ui/gfx/color_space_switches.h" | 23 #include "ui/gfx/color_space_switches.h" |
| 23 #include "ui/gfx/icc_profile.h" | 24 #include "ui/gfx/icc_profile.h" |
| 24 #include "ui/gfx/mac/coordinate_conversion.h" | 25 #include "ui/gfx/mac/coordinate_conversion.h" |
| 25 | 26 |
| 26 extern "C" { | 27 extern "C" { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 83 |
| 83 // On Sierra, we need to operate in a single screen's color space because | 84 // On Sierra, we need to operate in a single screen's color space because |
| 84 // IOSurfaces do not opt-out of color correction. | 85 // IOSurfaces do not opt-out of color correction. |
| 85 // https://crbug.com/654488 | 86 // https://crbug.com/654488 |
| 86 CGColorSpaceRef color_space = [[screen colorSpace] CGColorSpace]; | 87 CGColorSpaceRef color_space = [[screen colorSpace] CGColorSpace]; |
| 87 static bool color_correct_rendering_enabled = | 88 static bool color_correct_rendering_enabled = |
| 88 base::FeatureList::IsEnabled(features::kColorCorrectRendering); | 89 base::FeatureList::IsEnabled(features::kColorCorrectRendering); |
| 89 if (base::mac::IsAtLeastOS10_12() && !color_correct_rendering_enabled) | 90 if (base::mac::IsAtLeastOS10_12() && !color_correct_rendering_enabled) |
| 90 color_space = base::mac::GetSystemColorSpace(); | 91 color_space = base::mac::GetSystemColorSpace(); |
| 91 | 92 |
| 92 display.set_color_space( | 93 if (!gfx::ICCProfile::HasForcedProfile()) { |
| 93 gfx::ICCProfile::FromCGColorSpace(color_space).GetColorSpace()); | 94 display.set_color_space( |
| 95 gfx::ICCProfile::FromCGColorSpace(color_space).GetColorSpace()); |
| 96 } |
| 94 display.set_color_depth(NSBitsPerPixelFromDepth([screen depth])); | 97 display.set_color_depth(NSBitsPerPixelFromDepth([screen depth])); |
| 95 display.set_depth_per_component(NSBitsPerSampleFromDepth([screen depth])); | 98 display.set_depth_per_component(NSBitsPerSampleFromDepth([screen depth])); |
| 96 display.set_is_monochrome(CGDisplayUsesForceToGray()); | 99 display.set_is_monochrome(CGDisplayUsesForceToGray()); |
| 97 | 100 |
| 98 // CGDisplayRotation returns a double. Display::SetRotationAsDegree will | 101 // CGDisplayRotation returns a double. Display::SetRotationAsDegree will |
| 99 // handle the unexpected situations were the angle is not a multiple of 90. | 102 // handle the unexpected situations were the angle is not a multiple of 90. |
| 100 display.SetRotationAsDegree(static_cast<int>(CGDisplayRotation(display_id))); | 103 display.SetRotationAsDegree(static_cast<int>(CGDisplayRotation(display_id))); |
| 101 return display; | 104 return display; |
| 102 } | 105 } |
| 103 | 106 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 124 public: | 127 public: |
| 125 ScreenMac() | 128 ScreenMac() |
| 126 : configure_timer_( | 129 : configure_timer_( |
| 127 FROM_HERE, | 130 FROM_HERE, |
| 128 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), | 131 base::TimeDelta::FromMilliseconds(kConfigureDelayMs), |
| 129 base::Bind(&ScreenMac::ConfigureTimerFired, base::Unretained(this)), | 132 base::Bind(&ScreenMac::ConfigureTimerFired, base::Unretained(this)), |
| 130 false) { | 133 false) { |
| 131 old_displays_ = displays_ = BuildDisplaysFromQuartz(); | 134 old_displays_ = displays_ = BuildDisplaysFromQuartz(); |
| 132 CGDisplayRegisterReconfigurationCallback( | 135 CGDisplayRegisterReconfigurationCallback( |
| 133 ScreenMac::DisplayReconfigurationCallBack, this); | 136 ScreenMac::DisplayReconfigurationCallBack, this); |
| 137 |
| 138 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 139 screen_color_change_observer_.reset( |
| 140 [[center addObserverForName:NSScreenColorSpaceDidChangeNotification |
| 141 object:nil |
| 142 queue:nil |
| 143 usingBlock:^(NSNotification* notification) { |
| 144 configure_timer_.Reset(); |
| 145 displays_require_update_ = true; |
| 146 }] retain]); |
| 134 } | 147 } |
| 135 | 148 |
| 136 ~ScreenMac() override { | 149 ~ScreenMac() override { |
| 150 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 151 [center removeObserver:screen_color_change_observer_]; |
| 152 |
| 137 CGDisplayRemoveReconfigurationCallback( | 153 CGDisplayRemoveReconfigurationCallback( |
| 138 ScreenMac::DisplayReconfigurationCallBack, this); | 154 ScreenMac::DisplayReconfigurationCallBack, this); |
| 139 } | 155 } |
| 140 | 156 |
| 141 gfx::Point GetCursorScreenPoint() override { | 157 gfx::Point GetCursorScreenPoint() override { |
| 142 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. | 158 // Flip coordinates to gfx (0,0 in top-left corner) using primary screen. |
| 143 return gfx::ScreenPointFromNSPoint([NSEvent mouseLocation]); | 159 return gfx::ScreenPointFromNSPoint([NSEvent mouseLocation]); |
| 144 } | 160 } |
| 145 | 161 |
| 146 bool IsWindowUnderCursor(gfx::NativeWindow window) override { | 162 bool IsWindowUnderCursor(gfx::NativeWindow window) override { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 // Set whenever the CGDisplayRegisterReconfigurationCallback is invoked and | 339 // Set whenever the CGDisplayRegisterReconfigurationCallback is invoked and |
| 324 // cleared when |displays_| is updated by BuildDisplaysFromQuartz(). | 340 // cleared when |displays_| is updated by BuildDisplaysFromQuartz(). |
| 325 mutable bool displays_require_update_ = false; | 341 mutable bool displays_require_update_ = false; |
| 326 | 342 |
| 327 // The displays last communicated to DisplayChangeNotifier. | 343 // The displays last communicated to DisplayChangeNotifier. |
| 328 std::vector<Display> old_displays_; | 344 std::vector<Display> old_displays_; |
| 329 | 345 |
| 330 // The timer to delay configuring outputs and notifying observers. | 346 // The timer to delay configuring outputs and notifying observers. |
| 331 base::Timer configure_timer_; | 347 base::Timer configure_timer_; |
| 332 | 348 |
| 349 // The observer notified by NSScreenColorSpaceDidChangeNotification. |
| 350 base::scoped_nsobject<id> screen_color_change_observer_; |
| 351 |
| 333 DisplayChangeNotifier change_notifier_; | 352 DisplayChangeNotifier change_notifier_; |
| 334 | 353 |
| 335 DISALLOW_COPY_AND_ASSIGN(ScreenMac); | 354 DISALLOW_COPY_AND_ASSIGN(ScreenMac); |
| 336 }; | 355 }; |
| 337 | 356 |
| 338 } // namespace | 357 } // namespace |
| 339 | 358 |
| 340 // static | 359 // static |
| 341 gfx::NativeWindow Screen::GetWindowForView(gfx::NativeView view) { | 360 gfx::NativeWindow Screen::GetWindowForView(gfx::NativeView view) { |
| 342 NSWindow* window = nil; | 361 NSWindow* window = nil; |
| 343 #if !defined(USE_AURA) | 362 #if !defined(USE_AURA) |
| 344 window = [view window]; | 363 window = [view window]; |
| 345 #endif | 364 #endif |
| 346 return window; | 365 return window; |
| 347 } | 366 } |
| 348 | 367 |
| 349 #if !defined(USE_AURA) | 368 #if !defined(USE_AURA) |
| 350 Screen* CreateNativeScreen() { | 369 Screen* CreateNativeScreen() { |
| 351 return new ScreenMac; | 370 return new ScreenMac; |
| 352 } | 371 } |
| 353 #endif | 372 #endif |
| 354 | 373 |
| 355 } // namespace display | 374 } // namespace display |
| OLD | NEW |