diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-06 12:48:11 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:33:43 +0000 |
commit | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (patch) | |
tree | fa14ba0ca8d2683ba2efdabd246dc9b18a1229c6 /chromium/ui/display | |
parent | 79b4f909db1049fca459c07cca55af56a9b54fe3 (diff) | |
download | qtwebengine-chromium-7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3.tar.gz |
BASELINE: Update Chromium to 84.0.4147.141
Change-Id: Ib85eb4cfa1cbe2b2b81e5022c8cad5c493969535
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/ui/display')
58 files changed, 967 insertions, 476 deletions
diff --git a/chromium/ui/display/BUILD.gn b/chromium/ui/display/BUILD.gn index 6c2d7723415..2ce0eb72a65 100644 --- a/chromium/ui/display/BUILD.gn +++ b/chromium/ui/display/BUILD.gn @@ -58,18 +58,24 @@ jumbo_component("display") { if (is_win) { sources += [ + "win/base_window_finder_win.cc", + "win/base_window_finder_win.h", "win/color_profile_reader.cc", "win/color_profile_reader.h", "win/display_info.cc", "win/display_info.h", "win/dpi.cc", "win/dpi.h", + "win/local_process_window_finder_win.cc", + "win/local_process_window_finder_win.h", "win/scaling_util.cc", "win/scaling_util.h", "win/screen_win.cc", "win/screen_win.h", "win/screen_win_display.cc", "win/screen_win_display.h", + "win/topmost_window_finder_win.cc", + "win/topmost_window_finder_win.h", "win/uwp_text_scale_factor.cc", "win/uwp_text_scale_factor.h", ] diff --git a/chromium/ui/display/display_finder.cc b/chromium/ui/display/display_finder.cc index c4e42f82d9d..52e710e382d 100644 --- a/chromium/ui/display/display_finder.cc +++ b/chromium/ui/display/display_finder.cc @@ -7,7 +7,7 @@ #include <algorithm> #include <limits> -#include "base/logging.h" +#include "base/check.h" #include "ui/display/display.h" #include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/rect.h" diff --git a/chromium/ui/display/display_transform.cc b/chromium/ui/display/display_transform.cc index 883ef4633f4..e19a91c721d 100644 --- a/chromium/ui/display/display_transform.cc +++ b/chromium/ui/display/display_transform.cc @@ -4,6 +4,7 @@ #include "ui/display/display_transform.h" +#include "base/notreached.h" #include "ui/gfx/overlay_transform_utils.h" namespace display { diff --git a/chromium/ui/display/fake/fake_display_snapshot.cc b/chromium/ui/display/fake/fake_display_snapshot.cc index 94da2c4e398..af8fad503ca 100644 --- a/chromium/ui/display/fake/fake_display_snapshot.cc +++ b/chromium/ui/display/fake/fake_display_snapshot.cc @@ -9,6 +9,7 @@ #include <utility> #include <vector> +#include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "base/strings/stringprintf.h" diff --git a/chromium/ui/display/ios/screen_ios.mm b/chromium/ui/display/ios/screen_ios.mm index cb3c47b282b..dd048905453 100644 --- a/chromium/ui/display/ios/screen_ios.mm +++ b/chromium/ui/display/ios/screen_ios.mm @@ -4,7 +4,8 @@ #import <UIKit/UIKit.h> -#include "base/logging.h" +#include "base/check.h" +#include "base/notreached.h" #include "ui/display/display.h" #include "ui/display/screen_base.h" diff --git a/chromium/ui/display/mac/screen_mac.mm b/chromium/ui/display/mac/screen_mac.mm index de5994300fc..a4e374dd355 100644 --- a/chromium/ui/display/mac/screen_mac.mm +++ b/chromium/ui/display/mac/screen_mac.mm @@ -4,6 +4,7 @@ #include "ui/display/screen.h" +#import <AppKit/AppKit.h> #import <ApplicationServices/ApplicationServices.h> #import <Cocoa/Cocoa.h> #include <stdint.h> @@ -22,6 +23,7 @@ #include "ui/display/display.h" #include "ui/display/display_change_notifier.h" #include "ui/display/mac/display_link_mac.h" +#include "ui/gfx/geometry/point.h" #include "ui/gfx/icc_profile.h" #include "ui/gfx/mac/coordinate_conversion.h" @@ -32,10 +34,6 @@ Boolean CGDisplayUsesForceToGray(void); namespace display { namespace { -// The delay to handle the display configuration changes. This is in place to -// coalesce display update notifications and thereby avoid thrashing. -const int64_t kConfigureDelayMs = 500; - NSScreen* GetMatchingScreen(const gfx::Rect& match_rect) { // Default to the monitor with the current keyboard focus, in case // |match_rect| is not on any screen at all. @@ -85,8 +83,8 @@ Display BuildDisplayForScreen(NSScreen* screen) { // Examine the presence of HDR. bool enable_hdr = false; if (@available(macOS 10.15, *)) { - if ([screen maximumPotentialExtendedDynamicRangeColorComponentValue] >= - 2.0) { + if ([screen maximumPotentialExtendedDynamicRangeColorComponentValue] > + 1.0) { enable_hdr = true; } } @@ -148,6 +146,51 @@ Display BuildPrimaryDisplay() { return BuildDisplayForScreen([[NSScreen screens] firstObject]); } +std::vector<Display> BuildDisplaysFromQuartz() { + // Don't just return all online displays. This would include displays + // that mirror other displays, which are not desired in this list. It's + // tempting to use the count returned by CGGetActiveDisplayList, but active + // displays exclude sleeping displays, and those are desired. + + // It would be ridiculous to have this many displays connected, but + // CGDirectDisplayID is just an integer, so supporting up to this many + // doesn't hurt. + CGDirectDisplayID online_displays[1024]; + CGDisplayCount online_display_count = 0; + if (CGGetOnlineDisplayList(base::size(online_displays), online_displays, + &online_display_count) != kCGErrorSuccess) { + return std::vector<Display>(1, BuildPrimaryDisplay()); + } + + typedef std::map<int64_t, NSScreen*> ScreenIdsToScreensMap; + ScreenIdsToScreensMap screen_ids_to_screens; + for (NSScreen* screen in [NSScreen screens]) { + NSDictionary* screen_device_description = [screen deviceDescription]; + int64_t screen_id = [[screen_device_description + objectForKey:@"NSScreenNumber"] unsignedIntValue]; + screen_ids_to_screens[screen_id] = screen; + } + + std::vector<Display> displays; + for (CGDisplayCount online_display_index = 0; + online_display_index < online_display_count; ++online_display_index) { + CGDirectDisplayID online_display = online_displays[online_display_index]; + if (CGDisplayMirrorsDisplay(online_display) == kCGNullDirectDisplay) { + // If this display doesn't mirror any other, include it in the list. + // The primary display in a mirrored set will be counted, but those that + // mirror it will not be. + ScreenIdsToScreensMap::iterator foundScreen = + screen_ids_to_screens.find(online_display); + if (foundScreen != screen_ids_to_screens.end()) { + displays.push_back(BuildDisplayForScreen(foundScreen->second)); + } + } + } + + return displays.empty() ? std::vector<Display>(1, BuildPrimaryDisplay()) + : displays; +} + // Returns the minimum Manhattan distance from |point| to corners of |screen| // frame. CGFloat GetMinimumDistanceToCorner(const NSPoint& point, NSScreen* screen) { @@ -165,12 +208,8 @@ CGFloat GetMinimumDistanceToCorner(const NSPoint& point, NSScreen* screen) { class ScreenMac : public Screen { public: - ScreenMac() - : configure_timer_(FROM_HERE, - base::TimeDelta::FromMilliseconds(kConfigureDelayMs), - base::BindRepeating(&ScreenMac::ConfigureTimerFired, - base::Unretained(this))) { - old_displays_ = displays_ = BuildDisplaysFromQuartz(); + ScreenMac() { + displays_ = BuildDisplaysFromQuartz(); CGDisplayRegisterReconfigurationCallback( ScreenMac::DisplayReconfigurationCallBack, this); @@ -216,17 +255,39 @@ class ScreenMac : public Screen { return gfx::NativeWindow(); } + gfx::NativeWindow GetLocalProcessWindowAtPoint( + const gfx::Point& point, + const std::set<gfx::NativeWindow>& ignore) override { + const NSPoint ns_point = gfx::ScreenPointToNSPoint(point); + + // Note: [NSApp orderedWindows] doesn't include NSPanels. + for (NSWindow* window : [NSApp orderedWindows]) { + if (ignore.count(window)) + continue; + + if (![window isOnActiveSpace]) + continue; + + // NativeWidgetMac::Close() calls -orderOut: on NSWindows before actually + // closing them. + if (![window isVisible]) + continue; + + if (NSPointInRect(ns_point, [window frame])) + return window; + } + + return nil; + } + int GetNumDisplays() const override { return GetAllDisplays().size(); } const std::vector<Display>& GetAllDisplays() const override { - UpdateDisplaysIfNeeded(); return displays_; } Display GetDisplayNearestWindow( gfx::NativeWindow native_window) const override { - UpdateDisplaysIfNeeded(); - if (displays_.size() == 1) return displays_[0]; @@ -309,102 +370,32 @@ class ScreenMac : public Screen { private: Display GetCachedDisplayForScreen(NSScreen* screen) const { - UpdateDisplaysIfNeeded(); const CGDirectDisplayID display_id = [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue]; for (const Display& display : displays_) { if (display_id == display.id()) return display; } - // In theory, this should not be reached, because |displays_require_update_| - // should have been set prior to -[NSScreen screens] changing. In practice, - // on Catalina, it has been observed that -[NSScreen screens] changes before - // any notifications are received. + // In theory, this should not be reached, but in practice, on Catalina, it + // has been observed that -[NSScreen screens] changes before any + // notifications are received. // https://crbug.com/1021340. - OnNSScreensMayHaveChanged(); DLOG(ERROR) << "Value of -[NSScreen screens] changed before notification."; return BuildDisplayForScreen(screen); } - void UpdateDisplaysIfNeeded() const { - if (displays_require_update_) { - displays_ = BuildDisplaysFromQuartz(); - displays_require_update_ = false; - } - } - - void ConfigureTimerFired() { - UpdateDisplaysIfNeeded(); - change_notifier_.NotifyDisplaysChanged(old_displays_, displays_); - old_displays_ = displays_; - } - - std::vector<Display> BuildDisplaysFromQuartz() const { - // Don't just return all online displays. This would include displays - // that mirror other displays, which are not desired in this list. It's - // tempting to use the count returned by CGGetActiveDisplayList, but active - // displays exclude sleeping displays, and those are desired. - - // It would be ridiculous to have this many displays connected, but - // CGDirectDisplayID is just an integer, so supporting up to this many - // doesn't hurt. - CGDirectDisplayID online_displays[1024]; - CGDisplayCount online_display_count = 0; - if (CGGetOnlineDisplayList(base::size(online_displays), online_displays, - &online_display_count) != kCGErrorSuccess) { - return std::vector<Display>(1, BuildPrimaryDisplay()); - } - - typedef std::map<int64_t, NSScreen*> ScreenIdsToScreensMap; - ScreenIdsToScreensMap screen_ids_to_screens; - for (NSScreen* screen in [NSScreen screens]) { - NSDictionary* screen_device_description = [screen deviceDescription]; - int64_t screen_id = [[screen_device_description - objectForKey:@"NSScreenNumber"] unsignedIntValue]; - screen_ids_to_screens[screen_id] = screen; - } - - std::vector<Display> displays; - for (CGDisplayCount online_display_index = 0; - online_display_index < online_display_count; ++online_display_index) { - CGDirectDisplayID online_display = online_displays[online_display_index]; - if (CGDisplayMirrorsDisplay(online_display) == kCGNullDirectDisplay) { - // If this display doesn't mirror any other, include it in the list. - // The primary display in a mirrored set will be counted, but those that - // mirror it will not be. - ScreenIdsToScreensMap::iterator foundScreen = - screen_ids_to_screens.find(online_display); - if (foundScreen != screen_ids_to_screens.end()) { - displays.push_back(BuildDisplayForScreen(foundScreen->second)); - } - } - } - - return displays.empty() ? std::vector<Display>(1, BuildPrimaryDisplay()) - : displays; - } - - void OnNSScreensMayHaveChanged() const { - // Timer::Reset() ensures at least another interval passes before the - // associated task runs, effectively coalescing these events. - configure_timer_.Reset(); - displays_require_update_ = true; + void OnNSScreensMayHaveChanged() { + auto new_displays = BuildDisplaysFromQuartz(); + if (displays_ == new_displays) + return; + auto old_displays = std::move(displays_); + displays_ = std::move(new_displays); + change_notifier_.NotifyDisplaysChanged(old_displays, displays_); } // The displays currently attached to the device. Updated by - // UpdateDisplaysIfNeeded. - mutable std::vector<Display> displays_; - - // Whether or not |displays_| might need to be upated. Set in - // OnNSScreensMayHaveChanged, and un-set by UpdateDisplaysIfNeeded. - mutable bool displays_require_update_ = false; - - // The timer to delay configuring outputs and notifying observers (to coalesce - // several updates into one update). - mutable base::RetainingOneShotTimer configure_timer_; - - // The displays last communicated to the DisplayChangeNotifier. - std::vector<Display> old_displays_; + // OnNSScreensMayHaveChanged. + std::vector<Display> displays_; // The observers notified by NSScreenColorSpaceDidChangeNotification and // NSApplicationDidChangeScreenParametersNotification. diff --git a/chromium/ui/display/manager/content_protection_manager.cc b/chromium/ui/display/manager/content_protection_manager.cc index 986d9617d1b..4b3bda1ad4b 100644 --- a/chromium/ui/display/manager/content_protection_manager.cc +++ b/chromium/ui/display/manager/content_protection_manager.cc @@ -7,7 +7,7 @@ #include <algorithm> #include <utility> -#include "base/logging.h" +#include "base/check.h" #include "base/observer_list.h" #include "base/stl_util.h" #include "ui/display/manager/apply_content_protection_task.h" diff --git a/chromium/ui/display/manager/display_change_observer.cc b/chromium/ui/display/manager/display_change_observer.cc index 799d896d8e7..93961fa5a03 100644 --- a/chromium/ui/display/manager/display_change_observer.cc +++ b/chromium/ui/display/manager/display_change_observer.cc @@ -12,8 +12,8 @@ #include <utility> #include <vector> +#include "base/check_op.h" #include "base/command_line.h" -#include "base/logging.h" #include "base/stl_util.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/user_activity/user_activity_detector.h" diff --git a/chromium/ui/display/manager/display_layout_store.cc b/chromium/ui/display/manager/display_layout_store.cc index d9913a16c9a..82c903775c9 100644 --- a/chromium/ui/display/manager/display_layout_store.cc +++ b/chromium/ui/display/manager/display_layout_store.cc @@ -7,8 +7,9 @@ #include <string> #include <utility> +#include "base/check_op.h" #include "base/command_line.h" -#include "base/logging.h" +#include "base/notreached.h" #include "ui/display/display.h" #include "ui/display/display_switches.h" #include "ui/display/manager/display_layout_store.h" diff --git a/chromium/ui/display/manager/display_manager.cc b/chromium/ui/display/manager/display_manager.cc index 9d4a6bffa96..11423d46aae 100644 --- a/chromium/ui/display/manager/display_manager.cc +++ b/chromium/ui/display/manager/display_manager.cc @@ -49,6 +49,7 @@ #include "ui/display/manager/display_configurator.h" #include "ui/display/manager/display_util.h" #include "ui/display/types/native_display_delegate.h" +#include "ui/events/devices/touchscreen_device.h" #endif #if defined(OS_WIN) @@ -1472,25 +1473,25 @@ void DisplayManager::SetTouchCalibrationData( int64_t display_id, const TouchCalibrationData::CalibrationPointPairQuad& point_pair_quad, const gfx::Size& display_bounds, - const TouchDeviceIdentifier& touch_device_identifier) { + const ui::TouchscreenDevice& touchdevice) { // We do not proceed with setting the calibration and association if the // touch device identified by |touch_device_identifier| is an internal touch // device. - if (IsInternalTouchscreenDevice(touch_device_identifier)) + if (touchdevice.type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL) return; // Id of the display the touch device in context is currently associated // with. This display id will be equal to |display_id| if no reassociation is // being performed. int64_t previous_display_id = - touch_device_manager_->GetAssociatedDisplay(touch_device_identifier); + touch_device_manager_->GetAssociatedDisplay(touchdevice); bool update_add_support = false; bool update_remove_support = false; TouchCalibrationData calibration_data(point_pair_quad, display_bounds); - touch_device_manager_->AddTouchCalibrationData(touch_device_identifier, - display_id, calibration_data); + touch_device_manager_->AddTouchCalibrationData(touchdevice, display_id, + calibration_data); DisplayInfoList display_info_list; for (const auto& display : active_display_list_) { @@ -1531,10 +1532,9 @@ void DisplayManager::SetTouchCalibrationData( void DisplayManager::ClearTouchCalibrationData( int64_t display_id, - base::Optional<TouchDeviceIdentifier> touch_device_identifier) { - if (touch_device_identifier) { - touch_device_manager_->ClearTouchCalibrationData(*touch_device_identifier, - display_id); + base::Optional<ui::TouchscreenDevice> touchdevice) { + if (touchdevice) { + touch_device_manager_->ClearTouchCalibrationData(*touchdevice, display_id); } else { touch_device_manager_->ClearAllTouchCalibrationData(display_id); } diff --git a/chromium/ui/display/manager/display_manager.h b/chromium/ui/display/manager/display_manager.h index 883da148a28..d979f1f4e07 100644 --- a/chromium/ui/display/manager/display_manager.h +++ b/chromium/ui/display/manager/display_manager.h @@ -447,10 +447,10 @@ class DISPLAY_MANAGER_EXPORT DisplayManager int64_t display_id, const TouchCalibrationData::CalibrationPointPairQuad& point_pair_quad, const gfx::Size& display_bounds, - const TouchDeviceIdentifier& touch_device_identifier); + const ui::TouchscreenDevice& touchdevice); void ClearTouchCalibrationData( int64_t display_id, - base::Optional<TouchDeviceIdentifier> touch_device_identifier); + base::Optional<ui::TouchscreenDevice> touchdevice); void UpdateZoomFactor(int64_t display_id, float zoom_factor); bool HasUnassociatedDisplay() const; #endif diff --git a/chromium/ui/display/manager/display_manager_utilities.cc b/chromium/ui/display/manager/display_manager_utilities.cc index d3f7b015d55..ac8acd8910d 100644 --- a/chromium/ui/display/manager/display_manager_utilities.cc +++ b/chromium/ui/display/manager/display_manager_utilities.cc @@ -6,6 +6,8 @@ #include <algorithm> #include <set> +#include <sstream> +#include <vector> #include "base/command_line.h" #include "base/strings/string_number_conversions.h" diff --git a/chromium/ui/display/manager/display_util.cc b/chromium/ui/display/manager/display_util.cc index 8ce08efbd79..310e6293da6 100644 --- a/chromium/ui/display/manager/display_util.cc +++ b/chromium/ui/display/manager/display_util.cc @@ -9,7 +9,8 @@ #include <array> #include <cmath> -#include "base/logging.h" +#include "base/check_op.h" +#include "base/notreached.h" #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "ui/display/manager/managed_display_info.h" diff --git a/chromium/ui/display/manager/json_converter_unittest.cc b/chromium/ui/display/manager/json_converter_unittest.cc index 4bc838a318e..559e836d1dd 100644 --- a/chromium/ui/display/manager/json_converter_unittest.cc +++ b/chromium/ui/display/manager/json_converter_unittest.cc @@ -49,9 +49,8 @@ TEST(JsonConverterTest, JsonFromToDisplayLayout) { "}"; base::JSONReader::ValueWithError result = base::JSONReader::ReadAndReturnValueWithError(data, 0); - ASSERT_EQ(base::JSONReader::JSON_NO_ERROR, result.error_code) - << result.error_message << " at " << result.error_line << ":" - << result.error_column; + ASSERT_TRUE(result.value) << result.error_message << " at " + << result.error_line << ":" << result.error_column; EXPECT_EQ(value, result.value.value()); DisplayLayout read_layout; @@ -71,9 +70,8 @@ TEST(JsonConverterTest, OldJsonToDisplayLayout) { "}"; base::JSONReader::ValueWithError result = base::JSONReader::ReadAndReturnValueWithError(data, 0); - ASSERT_EQ(base::JSONReader::JSON_NO_ERROR, result.error_code) - << result.error_message << " at " << result.error_line << ":" - << result.error_column; + ASSERT_TRUE(result.value) << result.error_message << " at " + << result.error_line << ":" << result.error_column; DisplayLayout read_layout; EXPECT_TRUE(JsonToDisplayLayout(result.value.value(), &read_layout)); diff --git a/chromium/ui/display/manager/managed_display_info.cc b/chromium/ui/display/manager/managed_display_info.cc index 0cfb0609f82..e40b18c2cce 100644 --- a/chromium/ui/display/manager/managed_display_info.cc +++ b/chromium/ui/display/manager/managed_display_info.cc @@ -19,6 +19,7 @@ #include "ui/display/display.h" #include "ui/display/display_features.h" #include "ui/display/display_switches.h" +#include "ui/display/manager/display_manager_utilities.h" #include "ui/gfx/geometry/size_conversions.h" #include "ui/gfx/geometry/size_f.h" @@ -33,7 +34,7 @@ namespace { // Use larger than max int to catch overflow early. const int64_t kSynthesizedDisplayIdStart = 2200000000LL; -int64_t synthesized_display_id = kSynthesizedDisplayIdStart; +int64_t next_synthesized_display_id = kSynthesizedDisplayIdStart; const float kDpi96 = 96.0; @@ -234,8 +235,10 @@ ManagedDisplayInfo ManagedDisplayInfo::CreateFromSpecWithID( true, dm.device_scale_factor()); } - if (id == kInvalidDisplayId) - id = synthesized_display_id++; + if (id == kInvalidDisplayId) { + id = next_synthesized_display_id; + next_synthesized_display_id = GetNextSynthesizedDisplayId(id); + } ManagedDisplayInfo display_info( id, base::StringPrintf("Display-%d", static_cast<int>(id)), has_overscan); display_info.set_device_scale_factor(device_scale_factor); @@ -489,7 +492,17 @@ Display::Rotation ManagedDisplayInfo::GetRotationWithPanelOrientation( } void ResetDisplayIdForTest() { - synthesized_display_id = kSynthesizedDisplayIdStart; + next_synthesized_display_id = kSynthesizedDisplayIdStart; +} + +int64_t GetNextSynthesizedDisplayId(int64_t id) { + int next_output_index = id & 0xFF; + next_output_index++; + DCHECK_GT(0x100, next_output_index); + int64_t base = GetDisplayIdWithoutOutputIndex(id); + if (id == kSynthesizedDisplayIdStart) + return id + 0x100 + next_output_index; + return base + next_output_index; } } // namespace display diff --git a/chromium/ui/display/manager/managed_display_info.h b/chromium/ui/display/manager/managed_display_info.h index 263a4f618ae..e340223f8e0 100644 --- a/chromium/ui/display/manager/managed_display_info.h +++ b/chromium/ui/display/manager/managed_display_info.h @@ -383,6 +383,10 @@ class DISPLAY_MANAGER_EXPORT ManagedDisplayInfo { // is necessary to avoid overflowing the output index. void DISPLAY_MANAGER_EXPORT ResetDisplayIdForTest(); +// Generates a fake, synthesized display ID that will be used when the +// |kInvalidDisplayId| is passed to |ManagedDisplayInfo| constructor. +int64_t DISPLAY_MANAGER_EXPORT GetNextSynthesizedDisplayId(int64_t id); + } // namespace display #endif // UI_DISPLAY_MANAGER_MANAGED_DISPLAY_INFO_H_ diff --git a/chromium/ui/display/manager/touch_device_manager.cc b/chromium/ui/display/manager/touch_device_manager.cc index ee34bfff718..fc7499a38ca 100644 --- a/chromium/ui/display/manager/touch_device_manager.cc +++ b/chromium/ui/display/manager/touch_device_manager.cc @@ -198,6 +198,8 @@ uint32_t TouchDeviceIdentifier::GenerateIdentifier(std::string name, // static TouchDeviceIdentifier TouchDeviceIdentifier::FromDevice( const ui::TouchscreenDevice& touch_device) { + if (!touch_device.id) + return GetFallbackTouchDeviceIdentifier(); return TouchDeviceIdentifier( GenerateIdentifier(touch_device.name, touch_device.vendor_id, touch_device.product_id), @@ -594,9 +596,11 @@ void TouchDeviceManager::Associate(ManagedDisplayInfo* display, // Managing Touch device calibration data void TouchDeviceManager::AddTouchCalibrationData( - const TouchDeviceIdentifier& identifier, + const ui::TouchscreenDevice& device, int64_t display_id, const TouchCalibrationData& data) { + const TouchDeviceIdentifier identifier = + TouchDeviceIdentifier::FromDevice(device); if (!base::Contains(touch_associations_, identifier)) touch_associations_.emplace(identifier, AssociationInfoMap()); @@ -627,8 +631,10 @@ void TouchDeviceManager::AddTouchCalibrationData( } void TouchDeviceManager::ClearTouchCalibrationData( - const TouchDeviceIdentifier& identifier, + const ui::TouchscreenDevice& device, int64_t display_id) { + const TouchDeviceIdentifier identifier = + TouchDeviceIdentifier::FromDevice(device); if (base::Contains(touch_associations_, identifier)) { ClearCalibrationDataInMap(touch_associations_.at(identifier), display_id); } @@ -681,27 +687,36 @@ TouchCalibrationData TouchDeviceManager::GetCalibrationData( bool TouchDeviceManager::DisplayHasTouchDevice( int64_t display_id, - const TouchDeviceIdentifier& identifier) const { + const ui::TouchscreenDevice& device) const { + const TouchDeviceIdentifier identifier = + TouchDeviceIdentifier::FromDevice(device); return base::Contains(active_touch_associations_, identifier) && active_touch_associations_.at(identifier) == display_id; } int64_t TouchDeviceManager::GetAssociatedDisplay( - const TouchDeviceIdentifier& identifier) const { + const ui::TouchscreenDevice& device) const { + const TouchDeviceIdentifier identifier = + TouchDeviceIdentifier::FromDevice(device); if (base::Contains(active_touch_associations_, identifier)) return active_touch_associations_.at(identifier); return kInvalidDisplayId; } -std::vector<TouchDeviceIdentifier> +std::vector<ui::TouchscreenDevice> TouchDeviceManager::GetAssociatedTouchDevicesForDisplay( int64_t display_id) const { - std::vector<TouchDeviceIdentifier> identifiers; - for (const auto& association : active_touch_associations_) { - if (association.second == display_id) - identifiers.push_back(association.first); + std::vector<ui::TouchscreenDevice> result; + for (const auto& device : + ui::DeviceDataManager::GetInstance()->GetTouchscreenDevices()) { + const TouchDeviceIdentifier identifier = + TouchDeviceIdentifier::FromDevice(device); + + const auto it = active_touch_associations_.find(identifier); + if (it != active_touch_associations_.end() && it->second == display_id) + result.push_back(device); } - return identifiers; + return result; } void TouchDeviceManager::RegisterTouchAssociations( @@ -728,15 +743,4 @@ bool HasExternalTouchscreenDevice() { return false; } -bool IsInternalTouchscreenDevice(const TouchDeviceIdentifier& identifier) { - for (const auto& device : - ui::DeviceDataManager::GetInstance()->GetTouchscreenDevices()) { - if (TouchDeviceIdentifier::FromDevice(device) == identifier) - return device.type == ui::InputDeviceType::INPUT_DEVICE_INTERNAL; - } - VLOG(1) << "Touch device identified by " << identifier << " is currently" - << " not connected to the device or is an invalid device."; - return false; -} - } // namespace display diff --git a/chromium/ui/display/manager/touch_device_manager.h b/chromium/ui/display/manager/touch_device_manager.h index 53fd442602e..d45757516b4 100644 --- a/chromium/ui/display/manager/touch_device_manager.h +++ b/chromium/ui/display/manager/touch_device_manager.h @@ -145,17 +145,17 @@ class DISPLAY_MANAGER_EXPORT TouchDeviceManager { const std::vector<ui::TouchscreenDevice>& all_devices); // Adds/updates the touch calibration data for touch device identified by - // |identifier| and display with id |display_id|. This updates the mapping for + // |device| and display with id |display_id|. This updates the mapping for // |active_touch_associations_|. - void AddTouchCalibrationData(const TouchDeviceIdentifier& identifier, + void AddTouchCalibrationData(const ui::TouchscreenDevice& device, int64_t display_id, const TouchCalibrationData& data); // Clears any touch calibration data associated with the pair, touch device - // identified by |identifier| and display identified by |display_id|. + // identified by |device| and display identified by |display_id|. // NOTE: This does not disassociate the pair, it only resets the calibration // data. - void ClearTouchCalibrationData(const TouchDeviceIdentifier& identifier, + void ClearTouchCalibrationData(const ui::TouchscreenDevice& device, int64_t display_id); // Clears all touch calibration data associated with the display identified @@ -173,20 +173,20 @@ class DISPLAY_MANAGER_EXPORT TouchDeviceManager { int64_t display_id = kInvalidDisplayId) const; // Returns true of the display identified by |display_id| is associated with - // the touch device identified by |identifier|. + // the touch device identified by |device|. bool DisplayHasTouchDevice(int64_t display_id, - const TouchDeviceIdentifier& identifier) const; + const ui::TouchscreenDevice& device) const; // Returns the display id of the display that the touch device identified by - // |identifier| is currently associated with. Returns |kInvalidDisplayId| if + // |device| is currently associated with. Returns |kInvalidDisplayId| if // no display associated to touch device was found. - int64_t GetAssociatedDisplay(const TouchDeviceIdentifier& identifier) const; + int64_t GetAssociatedDisplay(const ui::TouchscreenDevice& device) const; // Returns a list of touch devices that are associated with the display with // id as |display_id|. This list only includes active associations, that is, // the devices that are currently connected to the system and associated with // this display. - std::vector<TouchDeviceIdentifier> GetAssociatedTouchDevicesForDisplay( + std::vector<ui::TouchscreenDevice> GetAssociatedTouchDevicesForDisplay( int64_t display_id) const; // Registers the touch associations and port associations retrieved from the @@ -259,11 +259,6 @@ DISPLAY_MANAGER_EXPORT std::ostream& operator<<( // Returns true if the device has any external touch devices attached. DISPLAY_MANAGER_EXPORT bool HasExternalTouchscreenDevice(); - -// Returns true if the touch device identified by |identifier| is an -// internal touchscreen device. -DISPLAY_MANAGER_EXPORT bool IsInternalTouchscreenDevice( - const TouchDeviceIdentifier& identifier); } // namespace display #endif // UI_DISPLAY_MANAGER_TOUCH_DEVICE_MANAGER_H_ diff --git a/chromium/ui/display/manager/touch_device_manager_unittest.cc b/chromium/ui/display/manager/touch_device_manager_unittest.cc index b94271d017a..aab804a0893 100644 --- a/chromium/ui/display/manager/touch_device_manager_unittest.cc +++ b/chromium/ui/display/manager/touch_device_manager_unittest.cc @@ -466,8 +466,7 @@ TEST_F(TouchAssociationFromPrefTest, UpdateMappingBeforeAssociation) { // Reassociate display with id 4 to touch device with id 3. This will // bring the display to the top of the priority list. touch_device_manager()->AddTouchCalibrationData( - TouchDeviceIdentifier::FromDevice(devices_[2]), displays_[3].id(), - TouchCalibrationData()); + devices_[2], displays_[3].id(), TouchCalibrationData()); touch_device_manager()->AssociateTouchscreens(&displays_, devices_); @@ -494,8 +493,7 @@ TEST_F(TouchAssociationFromPrefTest, UpdateMappingAfterAssociation) { // bring the display to the top of the priority list. This should work even // though the association of devices and displays is complete. touch_device_manager()->AddTouchCalibrationData( - TouchDeviceIdentifier::FromDevice(devices_[2]), displays_[3].id(), - TouchCalibrationData()); + devices_[2], displays_[3].id(), TouchCalibrationData()); EXPECT_EQ(GetTouchDeviceCount(displays_[0]), 1u); EXPECT_TRUE(AreAssociated(displays_[0], devices_[0])); @@ -517,8 +515,7 @@ TEST_F(TouchAssociationFromPrefTest, AssociatingDeviceToNewDisplay) { // Reassociate display with id 4 to touch device with id 3. This will // bring the display to the top of the priority list. touch_device_manager()->AddTouchCalibrationData( - TouchDeviceIdentifier::FromDevice(devices_[0]), displays_[2].id(), - TouchCalibrationData()); + devices_[0], displays_[2].id(), TouchCalibrationData()); touch_device_manager()->AssociateTouchscreens(&displays_, devices_); @@ -546,8 +543,7 @@ TEST_F(TouchAssociationFromPrefTest, // bring the display to the top of the priority list. This should work even // though the association of devices and displays is already complete. touch_device_manager()->AddTouchCalibrationData( - TouchDeviceIdentifier::FromDevice(devices_[0]), displays_[2].id(), - TouchCalibrationData()); + devices_[0], displays_[2].id(), TouchCalibrationData()); EXPECT_EQ(GetTouchDeviceCount(displays_[0]), 0u); @@ -791,8 +787,7 @@ TEST_F(TouchAssociationWithDuplicateDeviceTest, UpdatePortBeforeAssociation) { // bring the display to the top of the priority list and map the port the // device is connected to, to display 3. touch_device_manager()->AddTouchCalibrationData( - TouchDeviceIdentifier::FromDevice(devices_[2]), displays_[3].id(), - TouchCalibrationData()); + devices_[2], displays_[3].id(), TouchCalibrationData()); touch_device_manager()->AssociateTouchscreens(&displays_, devices_); @@ -821,8 +816,7 @@ TEST_F(TouchAssociationWithDuplicateDeviceTest, ChangeAssociation) { // bring the display to the top of the priority list and map the port the // device is connected to, to display 3. touch_device_manager()->AddTouchCalibrationData( - TouchDeviceIdentifier::FromDevice(devices_[2]), displays_[3].id(), - TouchCalibrationData()); + devices_[2], displays_[3].id(), TouchCalibrationData()); touch_device_manager()->AssociateTouchscreens(&displays_, devices_); diff --git a/chromium/ui/display/manager/touch_transform_controller.cc b/chromium/ui/display/manager/touch_transform_controller.cc index 8f49a26803a..62ce69c4fc5 100644 --- a/chromium/ui/display/manager/touch_transform_controller.cc +++ b/chromium/ui/display/manager/touch_transform_controller.cc @@ -23,18 +23,6 @@ namespace display { namespace { -ui::TouchscreenDevice FindTouchscreenByIdentifier( - const TouchDeviceIdentifier& identifier) { - const std::vector<ui::TouchscreenDevice>& touchscreens = - ui::DeviceDataManager::GetInstance()->GetTouchscreenDevices(); - for (const auto& touchscreen : touchscreens) { - if (TouchDeviceIdentifier::FromDevice(touchscreen) == identifier) - return touchscreen; - } - - return ui::TouchscreenDevice(); -} - // Given an array of touch point and display point pairs, this function computes // and returns the constants(defined below) using a least fit algorithm. // If (xt, yt) is a touch point then its corresponding (xd, yd) would be defined @@ -297,13 +285,12 @@ void TouchTransformController::UpdateTouchTransforms() const { void TouchTransformController::UpdateTouchRadius( const ManagedDisplayInfo& display, UpdateData* update_data) const { - for (const auto& identifier : + for (const auto& device : display_manager_->touch_device_manager() ->GetAssociatedTouchDevicesForDisplay(display.id())) { - DCHECK_EQ(0u, update_data->device_to_scale.count(identifier)); + DCHECK_EQ(0u, update_data->device_to_scale.count(device.id)); update_data->device_to_scale.emplace( - identifier, GetTouchResolutionScale( - display, FindTouchscreenByIdentifier(identifier))); + device.id, GetTouchResolutionScale(display, device)); } } @@ -314,14 +301,13 @@ void TouchTransformController::UpdateTouchTransform( UpdateData* update_data) const { ui::TouchDeviceTransform touch_device_transform; touch_device_transform.display_id = target_display_id; - for (const auto& identifier : + for (const auto& device : display_manager_->touch_device_manager() ->GetAssociatedTouchDevicesForDisplay(touch_display.id())) { - ui::TouchscreenDevice device = FindTouchscreenByIdentifier(identifier); touch_device_transform.device_id = device.id; touch_device_transform.transform = GetTouchTransform(target_display, touch_display, device); - auto device_to_scale_iter = update_data->device_to_scale.find(identifier); + auto device_to_scale_iter = update_data->device_to_scale.find(device.id); if (device_to_scale_iter != update_data->device_to_scale.end()) touch_device_transform.radius_scale = device_to_scale_iter->second; update_data->touch_device_transforms.push_back(touch_device_transform); diff --git a/chromium/ui/display/manager/touch_transform_controller.h b/chromium/ui/display/manager/touch_transform_controller.h index 00c7914aae6..2bf65b758f9 100644 --- a/chromium/ui/display/manager/touch_transform_controller.h +++ b/chromium/ui/display/manager/touch_transform_controller.h @@ -25,7 +25,6 @@ namespace display { class DisplayManager; class ManagedDisplayInfo; class TouchTransformSetter; -class TouchDeviceIdentifier; namespace test { class TouchTransformControllerTest; @@ -58,7 +57,7 @@ class DISPLAY_MANAGER_EXPORT TouchTransformController { UpdateData(); ~UpdateData(); - std::map<display::TouchDeviceIdentifier, double> device_to_scale; + std::map<int, double> device_to_scale; std::vector<ui::TouchDeviceTransform> touch_device_transforms; }; diff --git a/chromium/ui/display/manager/touch_transform_controller_unittest.cc b/chromium/ui/display/manager/touch_transform_controller_unittest.cc index 880611fe423..223cfa0bf32 100644 --- a/chromium/ui/display/manager/touch_transform_controller_unittest.cc +++ b/chromium/ui/display/manager/touch_transform_controller_unittest.cc @@ -557,9 +557,8 @@ TEST_F(TouchTransformControllerTest, AccurateUserTouchCalibration) { const std::string msg = GetTouchPointString(user_input); - touch_device_manager()->AddTouchCalibrationData( - display::TouchDeviceIdentifier::FromDevice(touchscreen), display.id(), - touch_data); + touch_device_manager()->AddTouchCalibrationData(touchscreen, display.id(), + touch_data); EXPECT_FALSE(touch_device_manager() ->GetCalibrationData(touchscreen, display.id()) @@ -607,9 +606,8 @@ TEST_F(TouchTransformControllerTest, ErrorProneUserTouchCalibration) { const std::string msg = GetTouchPointString(user_input); - touch_device_manager()->AddTouchCalibrationData( - display::TouchDeviceIdentifier::FromDevice(touchscreen), display.id(), - touch_data); + touch_device_manager()->AddTouchCalibrationData(touchscreen, display.id(), + touch_data); EXPECT_FALSE(touch_device_manager() ->GetCalibrationData(touchscreen, display.id()) @@ -659,9 +657,8 @@ TEST_F(TouchTransformControllerTest, ResolutionChangeUserTouchCalibration) { const std::string msg = GetTouchPointString(user_input); - touch_device_manager()->AddTouchCalibrationData( - display::TouchDeviceIdentifier::FromDevice(touchscreen), display.id(), - touch_data); + touch_device_manager()->AddTouchCalibrationData(touchscreen, display.id(), + touch_data); EXPECT_FALSE(touch_device_manager() ->GetCalibrationData(touchscreen, display.id()) @@ -706,9 +703,8 @@ TEST_F(TouchTransformControllerTest, DifferentBoundsUserTouchCalibration) { const std::string msg = GetTouchPointString(user_input); - touch_device_manager()->AddTouchCalibrationData( - display::TouchDeviceIdentifier::FromDevice(touchscreen), display.id(), - touch_data); + touch_device_manager()->AddTouchCalibrationData(touchscreen, display.id(), + touch_data); EXPECT_FALSE(touch_device_manager() ->GetCalibrationData(touchscreen, display.id()) @@ -770,8 +766,7 @@ TEST_F(TouchTransformControllerTest, LetterboxingUserTouchCalibration) { // The calibration was performed at the native display resolution. TouchCalibrationData touch_data(user_input, kNativeDisplaySize); touch_device_manager()->AddTouchCalibrationData( - display::TouchDeviceIdentifier::FromDevice(internal_touchscreen), - internal_display_info.id(), touch_data); + internal_touchscreen, internal_display_info.id(), touch_data); EXPECT_FALSE( touch_device_manager() @@ -849,8 +844,7 @@ TEST_F(TouchTransformControllerTest, PillarBoxingUserTouchCalibration) { TouchCalibrationData touch_data(user_input, kNativeDisplaySize); touch_device_manager()->AddTouchCalibrationData( - display::TouchDeviceIdentifier::FromDevice(internal_touchscreen), - internal_display_info.id(), touch_data); + internal_touchscreen, internal_display_info.id(), touch_data); EXPECT_FALSE( touch_device_manager() diff --git a/chromium/ui/display/mojom/BUILD.gn b/chromium/ui/display/mojom/BUILD.gn index a759490b15a..af12f462fb1 100644 --- a/chromium/ui/display/mojom/BUILD.gn +++ b/chromium/ui/display/mojom/BUILD.gn @@ -21,4 +21,136 @@ mojom("mojom") { "//ui/gfx/geometry/mojom", "//ui/gfx/mojom", ] + + shared_cpp_typemaps = [ + { + types = [ + { + mojom = "display.mojom.Rotation" + cpp = "::display::Display::Rotation" + }, + ] + traits_headers = [ "display_mojom_traits.h" ] + traits_public_deps = [ ":shared_mojom_traits" ] + }, + ] + + cpp_typemaps = [ + { + types = [ + { + mojom = "display.mojom.Display" + cpp = "::display::Display" + }, + { + mojom = "display.mojom.TouchSupport" + cpp = "::display::Display::TouchSupport" + }, + { + mojom = "display.mojom.AccelerometerSupport" + cpp = "::display::Display::AccelerometerSupport" + }, + ] + traits_headers = [ "display_mojom_traits.h" ] + traits_public_deps = [ ":shared_mojom_traits" ] + }, + { + types = [ + { + mojom = "display.mojom.DisplayConnectionType" + cpp = "::display::DisplayConnectionType" + }, + { + mojom = "display.mojom.HDCPState" + cpp = "::display::HDCPState" + }, + { + mojom = "display.mojom.PrivacyScreenState" + cpp = "::display::PrivacyScreenState" + }, + ] + traits_sources = [ "display_constants_mojom_traits.cc" ] + traits_headers = [ "display_constants_mojom_traits.h" ] + traits_public_deps = [ "//ui/display" ] + }, + { + types = [ + { + mojom = "display.mojom.Position" + cpp = "::display::DisplayPlacement::Position" + }, + { + mojom = "display.mojom.OffsetReference" + cpp = "::display::DisplayPlacement::OffsetReference" + }, + { + mojom = "display.mojom.DisplayPlacement" + cpp = "::display::DisplayPlacement" + }, + { + mojom = "display.mojom.DisplayLayout" + cpp = "::std::unique_ptr<::display::DisplayLayout>" + move_only = true + }, + ] + traits_sources = [ "display_layout_mojom_traits.cc" ] + traits_headers = [ "display_layout_mojom_traits.h" ] + traits_public_deps = [ "//ui/display" ] + }, + { + types = [ + { + mojom = "display.mojom.DisplayMode" + cpp = "::std::unique_ptr<::display::DisplayMode>" + move_only = true + }, + ] + traits_sources = [ "display_mode_mojom_traits.cc" ] + traits_headers = [ "display_mode_mojom_traits.h" ] + traits_public_deps = [ "//ui/display" ] + traits_deps = [ "//ui/gfx/geometry" ] + }, + { + types = [ + { + mojom = "display.mojom.DisplaySnapshot" + cpp = "::std::unique_ptr<::display::DisplaySnapshot>" + move_only = true + }, + ] + traits_sources = [ "display_snapshot_mojom_traits.cc" ] + traits_headers = [ "display_snapshot_mojom_traits.h" ] + traits_public_deps = [ "//ui/display" ] + traits_deps = [ "//ui/gfx/geometry" ] + }, + { + types = [ + { + mojom = "display.mojom.GammaRampRGBEntry" + cpp = "::display::GammaRampRGBEntry" + }, + ] + traits_sources = [ "gamma_ramp_rgb_entry_mojom_traits.cc" ] + traits_headers = [ "gamma_ramp_rgb_entry_mojom_traits.h" ] + traits_public_deps = [ "//ui/display" ] + }, + ] + + cpp_typemaps += shared_cpp_typemaps + blink_cpp_typemaps = shared_cpp_typemaps +} + +component("shared_mojom_traits") { + output_name = "display_shared_mojom_traits" + defines = [ "IS_DISPLAY_SHARED_MOJOM_TRAITS_IMPL" ] + sources = [ + "display_mojom_traits.cc", + "display_mojom_traits.h", + ] + public_deps = [ + ":mojom_shared", + "//base", + "//ui/display", + "//ui/gfx/mojom", + ] } diff --git a/chromium/ui/display/mojom/OWNERS b/chromium/ui/display/mojom/OWNERS index 7ed4e44a4d5..b36774dad1d 100644 --- a/chromium/ui/display/mojom/OWNERS +++ b/chromium/ui/display/mojom/OWNERS @@ -1,8 +1,4 @@ per-file *_mojom_traits*.*=set noparent per-file *_mojom_traits*.*=file://ipc/SECURITY_OWNERS - per-file *.mojom=set noparent per-file *.mojom=file://ipc/SECURITY_OWNERS - -per-file *.typemap=set noparent -per-file *.typemap=file://ipc/SECURITY_OWNERS diff --git a/chromium/ui/display/mojom/display.typemap b/chromium/ui/display/mojom/display.typemap deleted file mode 100644 index a9f26622978..00000000000 --- a/chromium/ui/display/mojom/display.typemap +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2016 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -mojom = "//ui/display/mojom/display.mojom" -public_headers = [ "//ui/display/display.h" ] -traits_headers = [ "//ui/display/mojom/display_mojom_traits.h" ] -sources = [ - "//ui/display/mojom/display_mojom_traits.cc", -] -public_deps = [ - "//ui/display", -] -deps = [ - "//ui/gfx/geometry", - "//ui/gfx/geometry/mojom:mojom_traits", -] - -type_mappings = [ - "display.mojom.Display=::display::Display", - "display.mojom.Rotation=::display::Display::Rotation", - "display.mojom.TouchSupport=::display::Display::TouchSupport", - "display.mojom.AccelerometerSupport=::display::Display::AccelerometerSupport", -] diff --git a/chromium/ui/display/mojom/display_constants.typemap b/chromium/ui/display/mojom/display_constants.typemap deleted file mode 100644 index c7a3db17313..00000000000 --- a/chromium/ui/display/mojom/display_constants.typemap +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2017 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -mojom = "//ui/display/mojom/display_constants.mojom" -public_headers = [ "//ui/display/types/display_constants.h" ] -traits_headers = [ "//ui/display/mojom/display_constants_mojom_traits.h" ] -sources = [ - "//ui/display/mojom/display_constants_mojom_traits.cc", -] -public_deps = [ - "//ui/display", -] -type_mappings = [ - "display.mojom.DisplayConnectionType=::display::DisplayConnectionType", - "display.mojom.HDCPState=::display::HDCPState", - "display.mojom.PrivacyScreenState=::display::PrivacyScreenState", -] diff --git a/chromium/ui/display/mojom/display_layout.typemap b/chromium/ui/display/mojom/display_layout.typemap deleted file mode 100644 index 45acef4c4d6..00000000000 --- a/chromium/ui/display/mojom/display_layout.typemap +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2017 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -mojom = "//ui/display/mojom/display_layout.mojom" -public_headers = [ "//ui/display/display_layout.h" ] -traits_headers = [ "//ui/display/mojom/display_layout_mojom_traits.h" ] -sources = [ - "//ui/display/mojom/display_layout_mojom_traits.cc", -] -public_deps = [ - "//ui/display", -] - -type_mappings = [ - "display.mojom.Position=::display::DisplayPlacement::Position", - "display.mojom.OffsetReference=::display::DisplayPlacement::OffsetReference", - "display.mojom.DisplayPlacement=::display::DisplayPlacement", - "display.mojom.DisplayLayout=::std::unique_ptr<::display::DisplayLayout>[move_only]", -] diff --git a/chromium/ui/display/mojom/display_mode.typemap b/chromium/ui/display/mojom/display_mode.typemap deleted file mode 100644 index a8a571a71f6..00000000000 --- a/chromium/ui/display/mojom/display_mode.typemap +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2017 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -mojom = "//ui/display/mojom/display_mode.mojom" -public_headers = [ "//ui/display/types/display_mode.h" ] -traits_headers = [ "//ui/display/mojom/display_mode_mojom_traits.h" ] -sources = [ - "//ui/display/mojom/display_mode_mojom_traits.cc", -] -public_deps = [ - "//ui/display", -] -deps = [ - "//ui/gfx/geometry", -] -type_mappings = [ "display.mojom.DisplayMode=::std::unique_ptr<::display::DisplayMode>[move_only]" ] diff --git a/chromium/ui/display/mojom/display_mojom_traits.h b/chromium/ui/display/mojom/display_mojom_traits.h index 303908ea785..fbd0f3086e7 100644 --- a/chromium/ui/display/mojom/display_mojom_traits.h +++ b/chromium/ui/display/mojom/display_mojom_traits.h @@ -5,23 +5,25 @@ #ifndef UI_DISPLAY_MOJOM_DISPLAY_MOJOM_TRAITS_H_ #define UI_DISPLAY_MOJOM_DISPLAY_MOJOM_TRAITS_H_ +#include "base/component_export.h" #include "ui/display/display.h" -#include "ui/display/mojom/display.mojom.h" +#include "ui/display/mojom/display.mojom-shared.h" #include "ui/gfx/geometry/mojom/geometry_mojom_traits.h" #include "ui/gfx/mojom/display_color_spaces_mojom_traits.h" namespace mojo { template <> -struct EnumTraits<display::mojom::Rotation, display::Display::Rotation> { +struct COMPONENT_EXPORT(DISPLAY_SHARED_MOJOM_TRAITS) + EnumTraits<display::mojom::Rotation, display::Display::Rotation> { static display::mojom::Rotation ToMojom(display::Display::Rotation type); static bool FromMojom(display::mojom::Rotation type, display::Display::Rotation* output); }; template <> -struct EnumTraits<display::mojom::TouchSupport, - display::Display::TouchSupport> { +struct COMPONENT_EXPORT(DISPLAY_SHARED_MOJOM_TRAITS) + EnumTraits<display::mojom::TouchSupport, display::Display::TouchSupport> { static display::mojom::TouchSupport ToMojom( display::Display::TouchSupport type); static bool FromMojom(display::mojom::TouchSupport type, @@ -29,8 +31,9 @@ struct EnumTraits<display::mojom::TouchSupport, }; template <> -struct EnumTraits<display::mojom::AccelerometerSupport, - display::Display::AccelerometerSupport> { +struct COMPONENT_EXPORT(DISPLAY_SHARED_MOJOM_TRAITS) + EnumTraits<display::mojom::AccelerometerSupport, + display::Display::AccelerometerSupport> { static display::mojom::AccelerometerSupport ToMojom( display::Display::AccelerometerSupport type); static bool FromMojom(display::mojom::AccelerometerSupport type, @@ -38,7 +41,8 @@ struct EnumTraits<display::mojom::AccelerometerSupport, }; template <> -struct StructTraits<display::mojom::DisplayDataView, display::Display> { +struct COMPONENT_EXPORT(DISPLAY_SHARED_MOJOM_TRAITS) + StructTraits<display::mojom::DisplayDataView, display::Display> { static int64_t id(const display::Display& display) { return display.id(); } static const gfx::Rect& bounds(const display::Display& display) { diff --git a/chromium/ui/display/mojom/display_mojom_traits_unittest.cc b/chromium/ui/display/mojom/display_mojom_traits_unittest.cc index 5b2f09231f5..dd4e5f96469 100644 --- a/chromium/ui/display/mojom/display_mojom_traits_unittest.cc +++ b/chromium/ui/display/mojom/display_mojom_traits_unittest.cc @@ -12,6 +12,7 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/display/display.h" #include "ui/display/display_layout.h" +#include "ui/display/mojom/display.mojom.h" #include "ui/display/mojom/display_layout_mojom_traits.h" #include "ui/display/mojom/display_mode_mojom_traits.h" #include "ui/display/mojom/display_mojom_traits.h" diff --git a/chromium/ui/display/mojom/display_rotation_for_blink.typemap b/chromium/ui/display/mojom/display_rotation_for_blink.typemap deleted file mode 100644 index b370d03e526..00000000000 --- a/chromium/ui/display/mojom/display_rotation_for_blink.typemap +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright 2018 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -mojom = "//ui/display/mojom/display.mojom" -public_headers = [ "//ui/display/display.h" ] -traits_headers = [ "//ui/display/mojom/display_mojom_traits.h" ] -public_deps = [ - "//ui/display", - "//ui/display/mojom:mojom", -] -type_mappings = [ "display.mojom.Rotation=::display::Display::Rotation" ] diff --git a/chromium/ui/display/mojom/display_snapshot.typemap b/chromium/ui/display/mojom/display_snapshot.typemap deleted file mode 100644 index eb0272c8a9d..00000000000 --- a/chromium/ui/display/mojom/display_snapshot.typemap +++ /dev/null @@ -1,17 +0,0 @@ -# Copyright 2017 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -mojom = "//ui/display/mojom/display_snapshot.mojom" -public_headers = [ "//ui/display/types/display_snapshot.h" ] -traits_headers = [ "//ui/display/mojom/display_snapshot_mojom_traits.h" ] -sources = [ - "//ui/display/mojom/display_snapshot_mojom_traits.cc", -] -public_deps = [ - "//ui/display", -] -deps = [ - "//ui/gfx/geometry", -] -type_mappings = [ "display.mojom.DisplaySnapshot=::std::unique_ptr<::display::DisplaySnapshot>[move_only]" ] diff --git a/chromium/ui/display/mojom/gamma_ramp_rgb_entry.typemap b/chromium/ui/display/mojom/gamma_ramp_rgb_entry.typemap deleted file mode 100644 index 045691f4bf3..00000000000 --- a/chromium/ui/display/mojom/gamma_ramp_rgb_entry.typemap +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2017 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -mojom = "//ui/display/mojom/gamma_ramp_rgb_entry.mojom" -public_headers = [ "//ui/display/types/gamma_ramp_rgb_entry.h" ] -traits_headers = [ "//ui/display/mojom/gamma_ramp_rgb_entry_mojom_traits.h" ] -sources = [ - "//ui/display/mojom/gamma_ramp_rgb_entry_mojom_traits.cc", -] -public_deps = [ - "//ui/display", -] -type_mappings = - [ "display.mojom.GammaRampRGBEntry=::display::GammaRampRGBEntry" ] diff --git a/chromium/ui/display/mojom/typemaps.gni b/chromium/ui/display/mojom/typemaps.gni deleted file mode 100644 index 1cbc47b18ee..00000000000 --- a/chromium/ui/display/mojom/typemaps.gni +++ /dev/null @@ -1,12 +0,0 @@ -# Copyright 2016 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -typemaps = [ - "//ui/display/mojom/display.typemap", - "//ui/display/mojom/display_constants.typemap", - "//ui/display/mojom/display_layout.typemap", - "//ui/display/mojom/display_mode.typemap", - "//ui/display/mojom/display_snapshot.typemap", - "//ui/display/mojom/gamma_ramp_rgb_entry.typemap", -] diff --git a/chromium/ui/display/screen.cc b/chromium/ui/display/screen.cc index 2fd96e83321..ef1d381d9e2 100644 --- a/chromium/ui/display/screen.cc +++ b/chromium/ui/display/screen.cc @@ -4,6 +4,9 @@ #include "ui/display/screen.h" +#include <utility> + +#include "base/logging.h" #include "ui/display/display.h" #include "ui/display/types/display_constants.h" #include "ui/gfx/geometry/rect.h" @@ -31,8 +34,8 @@ Screen* Screen::GetScreen() { } // static -void Screen::SetScreenInstance(Screen* instance) { - g_screen = instance; +Screen* Screen::SetScreenInstance(Screen* instance) { + return std::exchange(g_screen, instance); } Display Screen::GetDisplayNearestView(gfx::NativeView view) const { @@ -53,15 +56,15 @@ void Screen::SetDisplayForNewWindows(int64_t display_id) { display_id_for_new_windows_ = display_id; } -gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeView view, +gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeWindow window, const gfx::Rect& screen_rect) const { - float scale = GetDisplayNearestView(view).device_scale_factor(); + float scale = GetDisplayNearestWindow(window).device_scale_factor(); return ScaleToEnclosingRect(screen_rect, 1.0f / scale); } -gfx::Rect Screen::DIPToScreenRectInWindow(gfx::NativeView view, +gfx::Rect Screen::DIPToScreenRectInWindow(gfx::NativeWindow window, const gfx::Rect& dip_rect) const { - float scale = GetDisplayNearestView(view).device_scale_factor(); + float scale = GetDisplayNearestWindow(window).device_scale_factor(); return ScaleToEnclosingRect(dip_rect, scale); } diff --git a/chromium/ui/display/screen.h b/chromium/ui/display/screen.h index 53fb49afa95..2263985910f 100644 --- a/chromium/ui/display/screen.h +++ b/chromium/ui/display/screen.h @@ -5,6 +5,7 @@ #ifndef UI_DISPLAY_SCREEN_H_ #define UI_DISPLAY_SCREEN_H_ +#include <set> #include <vector> #include "base/macros.h" @@ -37,9 +38,10 @@ class DISPLAY_EXPORT Screen { // Retrieves the single Screen object. static Screen* GetScreen(); - // Sets the global screen. NOTE: this does not take ownership of |screen|. - // Tests must be sure to reset any state they install. - static void SetScreenInstance(Screen* instance); + // Sets the global screen. Returns the previously installed screen, if any. + // NOTE: this does not take ownership of |screen|. Tests must be sure to reset + // any state they install. + static Screen* SetScreenInstance(Screen* instance); // Returns the current absolute position of the mouse pointer. virtual gfx::Point GetCursorScreenPoint() = 0; @@ -50,6 +52,14 @@ class DISPLAY_EXPORT Screen { // Returns the window at the given screen coordinate |point|. virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) = 0; + // Finds the topmost visible chrome window at |screen_point|. This should + // return nullptr if |screen_point| is in another program's window which + // occludes the topmost chrome window. Ignores the windows in |ignore|, which + // contain windows such as the tab being dragged right now. + virtual gfx::NativeWindow GetLocalProcessWindowAtPoint( + const gfx::Point& point, + const std::set<gfx::NativeWindow>& ignore) = 0; + // Returns the number of displays. // Mirrored displays are excluded; this method is intended to return the // number of distinct, usable displays. @@ -90,16 +100,18 @@ class DISPLAY_EXPORT Screen { virtual void AddObserver(DisplayObserver* observer) = 0; virtual void RemoveObserver(DisplayObserver* observer) = 0; - // Converts |screen_rect| to DIP coordinates in the context of |view| clamping - // to the enclosing rect if the coordinates do not fall on pixel boundaries. - // If |view| is null, the primary display is used as the context. - virtual gfx::Rect ScreenToDIPRectInWindow(gfx::NativeView view, + // Converts |screen_rect| to DIP coordinates in the context of |window| + // clamping to the enclosing rect if the coordinates do not fall on pixel + // boundaries. If |window| is null, the primary display is used as the + // context. + virtual gfx::Rect ScreenToDIPRectInWindow(gfx::NativeWindow window, const gfx::Rect& screen_rect) const; - // Converts |dip_rect| to screen coordinates in the context of |view| clamping - // to the enclosing rect if the coordinates do not fall on pixel boundaries. - // If |view| is null, the primary display is used as the context. - virtual gfx::Rect DIPToScreenRectInWindow(gfx::NativeView view, + // Converts |dip_rect| to screen coordinates in the context of |window| + // clamping to the enclosing rect if the coordinates do not fall on pixel + // boundaries. If |window| is null, the primary display is used as the + // context. + virtual gfx::Rect DIPToScreenRectInWindow(gfx::NativeWindow window, const gfx::Rect& dip_rect) const; // Returns true if the display with |display_id| is found and returns that diff --git a/chromium/ui/display/screen_android.cc b/chromium/ui/display/screen_android.cc index cfb564306f0..4f13d4e1235 100644 --- a/chromium/ui/display/screen_android.cc +++ b/chromium/ui/display/screen_android.cc @@ -4,7 +4,7 @@ #include "ui/display/screen.h" -#include "base/logging.h" +#include "base/notreached.h" namespace display { diff --git a/chromium/ui/display/screen_aura.cc b/chromium/ui/display/screen_aura.cc index 3d210b1353d..81df76d9888 100644 --- a/chromium/ui/display/screen_aura.cc +++ b/chromium/ui/display/screen_aura.cc @@ -4,7 +4,7 @@ #include "ui/display/screen.h" -#include "base/logging.h" +#include "base/notreached.h" namespace display { diff --git a/chromium/ui/display/screen_base.cc b/chromium/ui/display/screen_base.cc index 9d49b776699..03d89f0a4ec 100644 --- a/chromium/ui/display/screen_base.cc +++ b/chromium/ui/display/screen_base.cc @@ -27,6 +27,13 @@ gfx::NativeWindow ScreenBase::GetWindowAtScreenPoint(const gfx::Point& point) { return nullptr; } +gfx::NativeWindow ScreenBase::GetLocalProcessWindowAtPoint( + const gfx::Point& screen_point, + const std::set<gfx::NativeWindow>& ignore) { + NOTIMPLEMENTED_LOG_ONCE(); + return nullptr; +} + Display ScreenBase::GetPrimaryDisplay() const { auto iter = display_list_.GetPrimaryDisplayIterator(); if (iter == display_list_.displays().end()) diff --git a/chromium/ui/display/screen_base.h b/chromium/ui/display/screen_base.h index 62b6e18a272..5013c0b959f 100644 --- a/chromium/ui/display/screen_base.h +++ b/chromium/ui/display/screen_base.h @@ -27,6 +27,9 @@ class DISPLAY_EXPORT ScreenBase : public Screen { gfx::Point GetCursorScreenPoint() override; bool IsWindowUnderCursor(gfx::NativeWindow window) override; gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; + gfx::NativeWindow GetLocalProcessWindowAtPoint( + const gfx::Point& screen_point, + const std::set<gfx::NativeWindow>& ignore) override; Display GetPrimaryDisplay() const override; Display GetDisplayNearestWindow(gfx::NativeWindow window) const override; Display GetDisplayNearestPoint(const gfx::Point& point) const override; diff --git a/chromium/ui/display/types/display_snapshot.cc b/chromium/ui/display/types/display_snapshot.cc index a4c556f7224..ff90d89a8f1 100644 --- a/chromium/ui/display/types/display_snapshot.cc +++ b/chromium/ui/display/types/display_snapshot.cc @@ -10,6 +10,7 @@ #include <sstream> #include <utility> +#include "base/notreached.h" #include "base/strings/stringprintf.h" namespace display { diff --git a/chromium/ui/display/util/display_util.cc b/chromium/ui/display/util/display_util.cc index e96043238e4..f5a0ab66b71 100644 --- a/chromium/ui/display/util/display_util.cc +++ b/chromium/ui/display/util/display_util.cc @@ -32,6 +32,19 @@ void EmitEdidColorSpaceChecksOutcomeUma(EdidColorSpaceChecksOutcome outcome) { outcome); } +// Returns true if each and all matrix values are within |epsilon| distance. +bool NearlyEqual(const skcms_Matrix3x3& lhs, + const skcms_Matrix3x3& rhs, + float epsilon) { + for (int r = 0; r < 3; r++) { + for (int c = 0; c < 3; c++) { + if (std::abs(lhs.vals[r][c] - rhs.vals[r][c]) > epsilon) + return false; + } + } + return true; +} + } // namespace bool IsDisplaySizeBlackListed(const gfx::Size& physical_size) { @@ -100,13 +113,21 @@ gfx::ColorSpace GetColorSpaceFromEdid(const display::EdidParser& edid_parser) { return gfx::ColorSpace(); } - skcms_Matrix3x3 color_space_as_matrix; - if (!primaries.toXYZD50(&color_space_as_matrix)) { + skcms_Matrix3x3 primaries_matrix; + if (!primaries.toXYZD50(&primaries_matrix)) { EmitEdidColorSpaceChecksOutcomeUma( EdidColorSpaceChecksOutcome::kErrorCannotExtractToXYZD50); return gfx::ColorSpace(); } + // Snap the primaries to those of BT.709/sRGB for performance purposes, see + // crbug.com/1073467. kPrimariesTolerance is an educated guess from various + // ChromeOS panels observations. + auto color_space_primaries = gfx::ColorSpace::PrimaryID::INVALID; + constexpr float kPrimariesTolerance = 0.025; + if (NearlyEqual(primaries_matrix, SkNamedGamut::kSRGB, kPrimariesTolerance)) + color_space_primaries = gfx::ColorSpace::PrimaryID::BT709; + const double gamma = edid_parser.gamma(); if (gamma < 1.0) { EmitEdidColorSpaceChecksOutcomeUma( @@ -115,8 +136,7 @@ gfx::ColorSpace GetColorSpaceFromEdid(const display::EdidParser& edid_parser) { } EmitEdidColorSpaceChecksOutcomeUma(EdidColorSpaceChecksOutcome::kSuccess); - gfx::ColorSpace::TransferID transfer_id = - gfx::ColorSpace::TransferID::INVALID; + auto transfer_id = gfx::ColorSpace::TransferID::INVALID; if (base::Contains(edid_parser.supported_color_primary_ids(), gfx::ColorSpace::PrimaryID::BT2020)) { if (base::Contains(edid_parser.supported_color_transfer_ids(), @@ -132,11 +152,20 @@ gfx::ColorSpace GetColorSpaceFromEdid(const display::EdidParser& edid_parser) { transfer_id = gfx::ColorSpace::TransferID::GAMMA24; } - if (transfer_id != gfx::ColorSpace::TransferID::INVALID) - return gfx::ColorSpace::CreateCustom(color_space_as_matrix, transfer_id); + // Prefer to return a name-based ColorSpace to ease subsequent calculations. + if (transfer_id != gfx::ColorSpace::TransferID::INVALID) { + if (color_space_primaries != gfx::ColorSpace::PrimaryID::INVALID) + return gfx::ColorSpace(color_space_primaries, transfer_id); + return gfx::ColorSpace::CreateCustom(primaries_matrix, transfer_id); + } skcms_TransferFunction transfer = {gamma, 1.f, 0.f, 0.f, 0.f, 0.f, 0.f}; - return gfx::ColorSpace::CreateCustom(color_space_as_matrix, transfer); + if (color_space_primaries == gfx::ColorSpace::PrimaryID::INVALID) + return gfx::ColorSpace::CreateCustom(primaries_matrix, transfer); + return gfx::ColorSpace( + color_space_primaries, gfx::ColorSpace::TransferID::CUSTOM, + gfx::ColorSpace::MatrixID::RGB, gfx::ColorSpace::RangeID::FULL, + /*custom_primary_matrix=*/nullptr, &transfer); } } // namespace display diff --git a/chromium/ui/display/util/display_util_unittest.cc b/chromium/ui/display/util/display_util_unittest.cc index 60b8c6bfadf..f4ab7470743 100644 --- a/chromium/ui/display/util/display_util_unittest.cc +++ b/chromium/ui/display/util/display_util_unittest.cc @@ -64,24 +64,24 @@ const unsigned char kEdidWithNoGamma[] = "\x02\x12\x01\x03\x80\x34\x21\xFF\xEE\xEF\x95\xA3\x54\x4C\x9B\x26" "\x0F\x50\x54\xA5\x6B\x80\x81\x40\x81\x80\x81\x99\x71\x00\xA9\x00"; -// A Samsung monitor that supports HDR metadata. +// Chromebook Samsung Galaxy (kohaku) that supports HDR metadata. constexpr unsigned char kHDR[] = - "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\x2d\xf6\x0d\x00\x0e\x00\x01" - "\x01\x1b\x01\x03\x80\x5f\x36\x78\x0a\x23\xad\xa4\x54\x4d\x99\x26" - "\x0f\x47\x4a\xbd\xef\x80\x71\x4f\x81\xc0\x81\x00\x81\x80\x95\x00" - "\xa9\xc0\xb3\x00\x01\x01\x04\x74\x00\x30\xf2\x70\x5a\x80\xb0\x58" - "\x8a\x00\x50\x1d\x74\x00\x00\x1e\x02\x3a\x80\x18\x71\x38\x2d\x40" - "\x58\x2c\x45\x00\x50\x1d\x74\x00\x00\x1e\x00\x00\x00\xfd\x00\x18" - "\x4b\x0f\x51\x1e\x00\x0a\x20\x20\x20\x20\x20\x20\x00\x00\x00\xfc" - "\x00\x53\x41\x4d\x53\x55\x4e\x47\x0a\x20\x20\x20\x20\x20\x01\x5a" - "\x02\x03\x4f\xf0\x53\x5f\x10\x1f\x04\x13\x05\x14\x20\x21\x22\x5d" - "\x5e\x62\x63\x64\x07\x16\x03\x12\x2c\x09\x07\x07\x15\x07\x50\x3d" - "\x04\xc0\x57\x07\x00\x83\x01\x00\x00\xe2\x00\x0f\xe3\x05\x83\x01" - "\x6e\x03\x0c\x00\x30\x00\xb8\x3c\x20\x00\x80\x01\x02\x03\x04\xe3" - "\x06\x0d\x01\xe5\x0e\x60\x61\x65\x66\xe5\x01\x8b\x84\x90\x01\x01" - "\x1d\x80\xd0\x72\x1c\x16\x20\x10\x2c\x25\x80\x50\x1d\x74\x00\x00" - "\x9e\x66\x21\x56\xaa\x51\x00\x1e\x30\x46\x8f\x33\x00\x50\x1d\x74" - "\x00\x00\x1e\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xbd"; + "\x00\xff\xff\xff\xff\xff\xff\x00\x4c\x83\x42\x41\x00\x00\x00\x00" + "\x13\x1d\x01\x04\xb5\x1d\x11\x78\x02\x38\xd1\xae\x51\x3b\xb8\x23" + "\x0b\x50\x54\x00\x00\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" + "\x01\x01\x01\x01\x01\x01\xb9\xd5\x00\x40\xf1\x70\x20\x80\x30\x20" + "\x88\x00\x26\xa5\x10\x00\x00\x1b\xb9\xd5\x00\x40\xf1\x70\x20\x80" + "\x30\x20\x88\x00\x26\xa5\x10\x00\x00\x1b\x00\x00\x00\x0f\x00\xff" + "\x09\x3c\xff\x09\x3c\x2c\x80\x00\x00\x00\x00\x00\x00\x00\x00\xfe" + "\x00\x41\x54\x4e\x41\x33\x33\x54\x50\x30\x34\x2d\x30\x20\x01\xba" + "\x02\x03\x0f\x00\xe3\x05\x80\x00\xe6\x06\x05\x01\x73\x6d\x07\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xab"; // EDID collected in the wild: valid but with primaries in the wrong order. const unsigned char kSST210[] = @@ -185,22 +185,22 @@ TEST(DisplayUtilTest, GetColorSpaceFromEdid) { EdidColorSpaceChecksOutcome::kSuccess), 2); - // Test with Chromebook Eve internal display. - constexpr SkColorSpacePrimaries expected_eve_primaries = {.fRX = 0.639648f, - .fRY = 0.329102f, - .fGX = 0.299805f, - .fGY = 0.599609f, - .fBX = 0.149414f, - .fBY = 0.059570f, - .fWX = 0.312500f, - .fWY = 0.328125f}; - skcms_Matrix3x3 expected_eve_toXYZ50_matrix; - expected_eve_primaries.toXYZD50(&expected_eve_toXYZ50_matrix); + // Test with Chromebook Eve internal display. The SkColorSpacePrimaries: + // SkColorSpacePrimaries expected_eve_primaries = {.fRX = 0.639648f, + // .fRY = 0.329102f, + // .fGX = 0.299805f, + // .fGY = 0.599609f, + // .fBX = 0.149414f, + // .fBY = 0.059570f, + // .fWX = 0.312500f, + // .fWY = 0.328125f}; + // are very close to the BT.709/sRGB ones, so they'll be rounded to those. + const skcms_TransferFunction eve_transfer({2.2, 1, 0, 0, 0, 0, 0}); + const gfx::ColorSpace expected_eve_color_space( + gfx::ColorSpace::PrimaryID::BT709, gfx::ColorSpace::TransferID::CUSTOM, + gfx::ColorSpace::MatrixID::RGB, gfx::ColorSpace::RangeID::FULL, + /*custom_primary_matrix=*/nullptr, &eve_transfer); const std::vector<uint8_t> eve_edid(kEve, kEve + base::size(kEve) - 1); - const gfx::ColorSpace expected_eve_color_space = - gfx::ColorSpace::CreateCustom( - expected_eve_toXYZ50_matrix, - skcms_TransferFunction({2.2, 1, 0, 0, 0, 0, 0})); EXPECT_EQ(expected_eve_color_space.ToString(), GetColorSpaceFromEdid(display::EdidParser(eve_edid)).ToString()); histogram_tester.ExpectBucketCount( @@ -209,15 +209,15 @@ TEST(DisplayUtilTest, GetColorSpaceFromEdid) { EdidColorSpaceChecksOutcome::kSuccess), 3); - // Test with a display that supports HDR. - constexpr SkColorSpacePrimaries expected_hdr_primaries = {.fRX = 0.640625f, - .fRY = 0.330078f, - .fGX = 0.300781f, - .fGY = 0.600586f, - .fBX = 0.150391f, - .fBY = 0.060547f, - .fWX = 0.280273f, - .fWY = 0.290039f}; + // Test with a display that supports HDR: Chromebook Samsung Galaxy (kohaku). + constexpr SkColorSpacePrimaries expected_hdr_primaries = {.fRX = 0.67960f, + .fRY = 0.31930f, + .fGX = 0.23240f, + .fGY = 0.71870f, + .fBX = 0.13965f, + .fBY = 0.04400f, + .fWX = 0.31250f, + .fWY = 0.32910f}; skcms_Matrix3x3 expected_hdr_toXYZ50_matrix; expected_hdr_primaries.toXYZD50(&expected_hdr_toXYZ50_matrix); const std::vector<uint8_t> hdr_edid(kHDR, kHDR + base::size(kHDR) - 1); diff --git a/chromium/ui/display/util/edid_parser.cc b/chromium/ui/display/util/edid_parser.cc index 724532e26a2..4664a3e5332 100644 --- a/chromium/ui/display/util/edid_parser.cc +++ b/chromium/ui/display/util/edid_parser.cc @@ -9,7 +9,9 @@ #include <algorithm> #include <bitset> +#include "base/check.h" #include "base/hash/hash.h" +#include "base/metrics/histogram_functions.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/sys_byteorder.h" @@ -19,6 +21,25 @@ #include "ui/gfx/geometry/size.h" namespace display { +namespace { + +constexpr char kParseEdidFailureMetric[] = "Display.ParseEdidFailure"; + +// These values are persisted to logs. Entries should not be renumbered and +// numeric values should never be reused. +enum class ParseEdidFailure { + kNoError = 0, + kManufacturerId = 1, + kProductId = 2, + kYearOfManufacture = 3, + kBitsPerChannel = 4, + kGamma = 5, + kChromaticityCoordinates = 6, + kDisplayName = 7, + kExtensions = 8, + kMaxValue = kExtensions, +}; +} // namespace EdidParser::EdidParser(const std::vector<uint8_t>& edid_blob) : manufacturer_id_(0), @@ -99,8 +120,8 @@ void EdidParser::ParseEdid(const std::vector<uint8_t>& edid) { constexpr size_t kProductIdLength = 2; if (edid.size() < kManufacturerOffset + kManufacturerLength) { - LOG(ERROR) << "Too short EDID data: manufacturer id"; - // TODO(mcasas): add UMA, https://crbug.com/821393. + base::UmaHistogramEnumeration(kParseEdidFailureMetric, + ParseEdidFailure::kManufacturerId); return; // Any other fields below are beyond this edid offset. } // ICC filename is generated based on these ids. We always read this as big @@ -109,8 +130,8 @@ void EdidParser::ParseEdid(const std::vector<uint8_t>& edid) { (edid[kManufacturerOffset] << 8) + edid[kManufacturerOffset + 1]; if (edid.size() < kProductIdOffset + kProductIdLength) { - LOG(ERROR) << "Too short EDID data: product id"; - // TODO(mcasas): add UMA, https://crbug.com/821393. + base::UmaHistogramEnumeration(kParseEdidFailureMetric, + ParseEdidFailure::kProductId); return; // Any other fields below are beyond this edid offset. } product_id_ = (edid[kProductIdOffset] << 8) + edid[kProductIdOffset + 1]; @@ -123,8 +144,8 @@ void EdidParser::ParseEdid(const std::vector<uint8_t>& edid) { constexpr int32_t kYearOffset = 1990; if (edid.size() < kYearOfManufactureOffset + 1) { - LOG(ERROR) << "Too short EDID data: year of manufacture"; - // TODO(mcasas): add UMA, https://crbug.com/821393. + base::UmaHistogramEnumeration(kParseEdidFailureMetric, + ParseEdidFailure::kYearOfManufacture); return; // Any other fields below are beyond this edid offset. } const uint8_t byte_data = edid[kYearOfManufactureOffset]; @@ -144,8 +165,8 @@ void EdidParser::ParseEdid(const std::vector<uint8_t>& edid) { constexpr uint8_t kColorBitDepthOffset = 4; if (edid.size() < kVideoInputDefinitionOffset + 1) { - LOG(ERROR) << "Too short EDID data: bits per channel"; - // TODO(mcasas): add UMA, https://crbug.com/821393. + base::UmaHistogramEnumeration(kParseEdidFailureMetric, + ParseEdidFailure::kBitsPerChannel); return; // Any other fields below are beyond this edid offset. } if (edid[kEDIDRevisionNumberOffset] >= kEDIDRevision4Value && @@ -164,8 +185,8 @@ void EdidParser::ParseEdid(const std::vector<uint8_t>& edid) { constexpr double kGammaBias = 100.0; if (edid.size() < kGammaOffset + 1) { - LOG(ERROR) << "Too short EDID data: gamma"; - // TODO(mcasas): add UMA, https://crbug.com/821393. + base::UmaHistogramEnumeration(kParseEdidFailureMetric, + ParseEdidFailure::kGamma); return; // Any other fields below are beyond this edid offset. } if (edid[kGammaOffset] != 0xFF) { @@ -209,8 +230,8 @@ void EdidParser::ParseEdid(const std::vector<uint8_t>& edid) { "EDID Parameter section length error"); if (edid.size() < kChromaticityOffset + kChromaticityLength) { - LOG(ERROR) << "Too short EDID data: chromaticity coordinates"; - // TODO(mcasas): add UMA, https://crbug.com/821393. + base::UmaHistogramEnumeration(kParseEdidFailureMetric, + ParseEdidFailure::kChromaticityCoordinates); return; // Any other fields below are beyond this edid offset. } @@ -311,8 +332,8 @@ void EdidParser::ParseEdid(const std::vector<uint8_t>& edid) { for (const char c : display_name_) { if (!isascii(c) || !isprint(c)) { display_name_.clear(); - LOG(ERROR) << "invalid EDID: human unreadable char in name"; - // TODO(mcasas): add UMA, https://crbug.com/821393. + base::UmaHistogramEnumeration(kParseEdidFailureMetric, + ParseEdidFailure::kDisplayName); } } @@ -365,8 +386,8 @@ void EdidParser::ParseEdid(const std::vector<uint8_t>& edid) { constexpr uint8_t kHDRStaticMetadataDataBlockLengthMask = 0x1F; if (edid.size() < kNumExtensionsOffset + 1) { - LOG(ERROR) << "Too short EDID data: extensions"; - // TODO(mcasas): add UMA, https://crbug.com/821393. + base::UmaHistogramEnumeration(kParseEdidFailureMetric, + ParseEdidFailure::kExtensions); return; // Any other fields below are beyond this edid offset. } const uint8_t num_extensions = edid[kNumExtensionsOffset]; @@ -471,6 +492,8 @@ void EdidParser::ParseEdid(const std::vector<uint8_t>& edid) { data_offset += payload_length + 1; } } + base::UmaHistogramEnumeration(kParseEdidFailureMetric, + ParseEdidFailure::kNoError); } } // namespace display diff --git a/chromium/ui/display/win/base_window_finder_win.cc b/chromium/ui/display/win/base_window_finder_win.cc new file mode 100644 index 00000000000..70624e1cfcf --- /dev/null +++ b/chromium/ui/display/win/base_window_finder_win.cc @@ -0,0 +1,30 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/display/win/base_window_finder_win.h" + +#include <objbase.h> + +namespace display { +namespace win { + +// Creates a BaseWindowFinderWin with the specified set of HWNDs to ignore. +BaseWindowFinderWin::BaseWindowFinderWin(const std::set<HWND>& ignore) + : ignore_(ignore) {} + +BaseWindowFinderWin::~BaseWindowFinderWin() = default; + +// static +BOOL CALLBACK BaseWindowFinderWin::WindowCallbackProc(HWND hwnd, + LPARAM lParam) { + // Cast must match that in as_lparam(). + BaseWindowFinderWin* finder = reinterpret_cast<BaseWindowFinderWin*>(lParam); + if (finder->ignore_.find(hwnd) != finder->ignore_.end()) + return TRUE; + + return finder->ShouldStopIterating(hwnd) ? FALSE : TRUE; +} + +} // namespace win +} // namespace display
\ No newline at end of file diff --git a/chromium/ui/display/win/base_window_finder_win.h b/chromium/ui/display/win/base_window_finder_win.h new file mode 100644 index 00000000000..7f769a2d117 --- /dev/null +++ b/chromium/ui/display/win/base_window_finder_win.h @@ -0,0 +1,46 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_DISPLAY_WIN_BASE_WINDOW_FINDER_WIN_H_ +#define UI_DISPLAY_WIN_BASE_WINDOW_FINDER_WIN_H_ + +#include <set> + +#include "base/win/windows_types.h" + +namespace display { +namespace win { + +// Base class used to locate a window. This is intended to be used with the +// various win32 functions that iterate over windows. +// +// A subclass need only override ShouldStopIterating to determine when +// iteration should stop. +class BaseWindowFinderWin { + public: + // Creates a BaseWindowFinderWin with the specified set of HWNDs to ignore. + explicit BaseWindowFinderWin(const std::set<HWND>& ignore); + BaseWindowFinderWin(const BaseWindowFinderWin& finder) = delete; + BaseWindowFinderWin& operator=(const BaseWindowFinderWin& finder) = delete; + virtual ~BaseWindowFinderWin(); + + protected: + static BOOL CALLBACK WindowCallbackProc(HWND hwnd, LPARAM lParam); + + LPARAM as_lparam() { + // Cast must match that in WindowCallbackProc(). + return reinterpret_cast<LPARAM>(static_cast<BaseWindowFinderWin*>(this)); + } + + // Returns true if iteration should stop, false if iteration should continue. + virtual bool ShouldStopIterating(HWND window) = 0; + + private: + const std::set<HWND>& ignore_; +}; + +} // namespace win +} // namespace display + +#endif // UI_DISPLAY_WIN_BASE_WINDOW_FINDER_WIN_H_
\ No newline at end of file diff --git a/chromium/ui/display/win/color_profile_reader.cc b/chromium/ui/display/win/color_profile_reader.cc index 212c7fa54c0..495fb5b1b86 100644 --- a/chromium/ui/display/win/color_profile_reader.cc +++ b/chromium/ui/display/win/color_profile_reader.cc @@ -11,6 +11,7 @@ #include "base/files/file_util.h" #include "base/task/post_task.h" #include "base/task/thread_pool.h" +#include "base/threading/scoped_thread_priority.h" #include "ui/display/win/display_info.h" #include "ui/gfx/icc_profile.h" @@ -79,6 +80,7 @@ void ColorProfileReader::UpdateIfNeeded() { // static ColorProfileReader::DeviceToPathMap ColorProfileReader::BuildDeviceToPathMapOnBackgroundThread() { + SCOPED_MAY_LOAD_LIBRARY_AT_BACKGROUND_PRIORITY(); DeviceToPathMap device_to_path_map; EnumDisplayMonitors(nullptr, nullptr, EnumMonitorForProfilePathCallback, reinterpret_cast<LPARAM>(&device_to_path_map)); diff --git a/chromium/ui/display/win/display_info.cc b/chromium/ui/display/win/display_info.cc index fe378ce87ab..91bc0872fa5 100644 --- a/chromium/ui/display/win/display_info.cc +++ b/chromium/ui/display/win/display_info.cc @@ -10,20 +10,23 @@ namespace display { namespace win { -DisplayInfo::DisplayInfo(const MONITORINFOEX& monitor_info, - float device_scale_factor, - float sdr_white_level, - Display::Rotation rotation, - int display_frequency, - const gfx::Vector2dF& pixels_per_inch) +DisplayInfo::DisplayInfo( + const MONITORINFOEX& monitor_info, + float device_scale_factor, + float sdr_white_level, + Display::Rotation rotation, + int display_frequency, + const gfx::Vector2dF& pixels_per_inch, + DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY output_technology) : id_(DeviceIdFromDeviceName(monitor_info.szDevice)), - rotation_(rotation), screen_rect_(monitor_info.rcMonitor), screen_work_rect_(monitor_info.rcWork), device_scale_factor_(device_scale_factor), sdr_white_level_(sdr_white_level), + rotation_(rotation), display_frequency_(display_frequency), - pixels_per_inch_(pixels_per_inch) {} + pixels_per_inch_(pixels_per_inch), + output_technology_(output_technology) {} DisplayInfo::~DisplayInfo() = default; diff --git a/chromium/ui/display/win/display_info.h b/chromium/ui/display/win/display_info.h index 2507221efb5..f6c689b9a8f 100644 --- a/chromium/ui/display/win/display_info.h +++ b/chromium/ui/display/win/display_info.h @@ -22,31 +22,36 @@ class DISPLAY_EXPORT DisplayInfo final { float sdr_white_level, Display::Rotation rotation, int display_frequency, - const gfx::Vector2dF& pixels_per_inch); + const gfx::Vector2dF& pixels_per_inch, + DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY output_technology); ~DisplayInfo(); static int64_t DeviceIdFromDeviceName(const wchar_t* device_name); int64_t id() const { return id_; } - Display::Rotation rotation() const { return rotation_; } const gfx::Rect& screen_rect() const { return screen_rect_; } const gfx::Rect& screen_work_rect() const { return screen_work_rect_; } float device_scale_factor() const { return device_scale_factor_; } float sdr_white_level() const { return sdr_white_level_; } + Display::Rotation rotation() const { return rotation_; } int display_frequency() const { return display_frequency_; } const gfx::Vector2dF& pixels_per_inch() const { return pixels_per_inch_; } + DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY output_technology() const { + return output_technology_; + } private: int64_t id_; - Display::Rotation rotation_; gfx::Rect screen_rect_; gfx::Rect screen_work_rect_; float device_scale_factor_; float sdr_white_level_; + Display::Rotation rotation_; int display_frequency_; // Pixels per inch of a display. This value will only be set for touch // monitors. In non-touch cases, it will be set to Zero. gfx::Vector2dF pixels_per_inch_; + DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY output_technology_; }; } // namespace win diff --git a/chromium/ui/display/win/local_process_window_finder_win.cc b/chromium/ui/display/win/local_process_window_finder_win.cc new file mode 100644 index 00000000000..d4be1b9f346 --- /dev/null +++ b/chromium/ui/display/win/local_process_window_finder_win.cc @@ -0,0 +1,67 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/display/win/local_process_window_finder_win.h" + +#include "base/win/windows_version.h" +#include "ui/display/win/screen_win.h" +#include "ui/display/win/topmost_window_finder_win.h" + +namespace display { +namespace win { + +// static +gfx::NativeWindow LocalProcessWindowFinder::GetProcessWindowAtPoint( + const gfx::Point& screen_loc, + const std::set<HWND>& ignore, + ScreenWin* screen_win) { + LocalProcessWindowFinder finder(screen_loc, ignore); + // Windows 8 has a window that appears first in the list of iterated + // windows, yet is not visually on top of everything. + // TODO(sky): figure out a better way to ignore this window. + if (finder.result_ && ((base::win::OSInfo::GetInstance()->version() >= + base::win::Version::WIN8) || + TopMostFinderWin::IsTopMostWindowAtPoint( + finder.result_, screen_loc, ignore))) { + return screen_win->GetNativeWindowFromHWND(finder.result_); + } + return nullptr; +} + +bool LocalProcessWindowFinder::ShouldStopIterating(HWND hwnd) { + RECT r; + + // Make sure the window is on the same virtual desktop. + if (virtual_desktop_manager_) { + BOOL on_current_desktop; + if (SUCCEEDED(virtual_desktop_manager_->IsWindowOnCurrentVirtualDesktop( + hwnd, &on_current_desktop)) && + !on_current_desktop) { + return false; + } + } + + if (IsWindowVisible(hwnd) && GetWindowRect(hwnd, &r) && + PtInRect(&r, screen_loc_.ToPOINT())) { + result_ = hwnd; + return true; + } + return false; +} + +LocalProcessWindowFinder::LocalProcessWindowFinder(const gfx::Point& screen_loc, + const std::set<HWND>& ignore) + : BaseWindowFinderWin(ignore), result_(nullptr) { + if (base::win::GetVersion() >= base::win::Version::WIN10) { + ::CoCreateInstance(__uuidof(VirtualDesktopManager), nullptr, CLSCTX_ALL, + IID_PPV_ARGS(&virtual_desktop_manager_)); + } + screen_loc_ = display::win::ScreenWin::DIPToScreenPoint(screen_loc); + EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, as_lparam()); +} + +LocalProcessWindowFinder::~LocalProcessWindowFinder() = default; + +} // namespace win +} // namespace display
\ No newline at end of file diff --git a/chromium/ui/display/win/local_process_window_finder_win.h b/chromium/ui/display/win/local_process_window_finder_win.h new file mode 100644 index 00000000000..13f14ca70c7 --- /dev/null +++ b/chromium/ui/display/win/local_process_window_finder_win.h @@ -0,0 +1,55 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_DISPLAY_WIN_LOCAL_PROCESS_WINDOW_FINDER_WIN_H_ +#define UI_DISPLAY_WIN_LOCAL_PROCESS_WINDOW_FINDER_WIN_H_ + +#include <shobjidl.h> +#include <wrl/client.h> + +#include "ui/display/win/base_window_finder_win.h" +#include "ui/gfx/geometry/point.h" +#include "ui/gfx/native_widget_types.h" + +namespace display { +namespace win { + +class ScreenWin; + +// Helper class to determine if a particular point contains a window from our +// process. +class LocalProcessWindowFinder : public BaseWindowFinderWin { + public: + // Returns the hwnd from our process at screen_loc that is not obscured by + // another window. Returns NULL otherwise. + static gfx::NativeWindow GetProcessWindowAtPoint(const gfx::Point& screen_loc, + const std::set<HWND>& ignore, + ScreenWin* screen_win); + + protected: + bool ShouldStopIterating(HWND hwnd) override; + + private: + LocalProcessWindowFinder(const gfx::Point& screen_loc, + const std::set<HWND>& ignore); + LocalProcessWindowFinder(const LocalProcessWindowFinder& finder) = delete; + LocalProcessWindowFinder& operator=(const LocalProcessWindowFinder& finder) = + delete; + ~LocalProcessWindowFinder() override; + + // Position of the mouse in pixel coordinates. + gfx::Point screen_loc_; + + // The resulting window. This is initially null but set to true in + // ShouldStopIterating if an appropriate window is found. + HWND result_; + + // Only used on Win10+. + Microsoft::WRL::ComPtr<IVirtualDesktopManager> virtual_desktop_manager_; +}; + +} // namespace win +} // namespace display + +#endif // UI_DISPLAY_WIN_LOCAL_PROCESS_WINDOW_FINDER_WIN_H_
\ No newline at end of file diff --git a/chromium/ui/display/win/scaling_util.cc b/chromium/ui/display/win/scaling_util.cc index a390ad314ac..2102a7d0475 100644 --- a/chromium/ui/display/win/scaling_util.cc +++ b/chromium/ui/display/win/scaling_util.cc @@ -6,6 +6,8 @@ #include <algorithm> +#include "base/check.h" +#include "base/notreached.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/safe_integer_conversions.h" #include "ui/gfx/geometry/size.h" diff --git a/chromium/ui/display/win/scaling_util_unittest.cc b/chromium/ui/display/win/scaling_util_unittest.cc index c3fc789731d..c6fd7f4c226 100644 --- a/chromium/ui/display/win/scaling_util_unittest.cc +++ b/chromium/ui/display/win/scaling_util_unittest.cc @@ -21,7 +21,7 @@ DisplayInfo CreateDisplayInfo(int x, int y, int width, int height, gfx::Rect(x, y, width, height), kFakeDisplayName); return DisplayInfo(monitor_info, scale_factor, 1.0f, Display::ROTATE_0, 60, - gfx::Vector2dF()); + gfx::Vector2dF(), DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER); } ::testing::AssertionResult AssertOffsetsEqual( diff --git a/chromium/ui/display/win/screen_win.cc b/chromium/ui/display/win/screen_win.cc index ee77605a6b0..0c789c42fa5 100644 --- a/chromium/ui/display/win/screen_win.cc +++ b/chromium/ui/display/win/screen_win.cc @@ -22,6 +22,7 @@ #include "ui/display/display_layout_builder.h" #include "ui/display/win/display_info.h" #include "ui/display/win/dpi.h" +#include "ui/display/win/local_process_window_finder_win.h" #include "ui/display/win/scaling_util.h" #include "ui/display/win/screen_win_display.h" #include "ui/gfx/geometry/point_conversions.h" @@ -126,19 +127,39 @@ base::Optional<DISPLAYCONFIG_PATH_INFO> GetPathInfo(HMONITOR monitor) { return base::nullopt; } -float GetMonitorSDRWhiteLevel(HMONITOR monitor) { - if (auto path_info = GetPathInfo(monitor)) { +float GetSDRWhiteLevel(const base::Optional<DISPLAYCONFIG_PATH_INFO>& path) { + if (path) { DISPLAYCONFIG_SDR_WHITE_LEVEL white_level = {}; white_level.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SDR_WHITE_LEVEL; white_level.header.size = sizeof(white_level); - white_level.header.adapterId = path_info->targetInfo.adapterId; - white_level.header.id = path_info->targetInfo.id; + white_level.header.adapterId = path->targetInfo.adapterId; + white_level.header.id = path->targetInfo.id; if (DisplayConfigGetDeviceInfo(&white_level.header) == ERROR_SUCCESS) return white_level.SDRWhiteLevel * 80.0 / 1000.0; } return 200.0f; } +DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY GetOutputTechnology( + const base::Optional<DISPLAYCONFIG_PATH_INFO>& path) { + if (path) + return path->targetInfo.outputTechnology; + return DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER; +} + +// Returns true if |tech| represents an internal display (eg. a laptop screen). +bool IsInternalOutputTechnology(DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY tech) { + switch (tech) { + case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL: + case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED: + case DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED: + return true; + + default: + return false; + } +} + Display::Rotation OrientationToRotation(DWORD orientation) { switch (orientation) { case DMDO_DEFAULT: @@ -423,13 +444,14 @@ BOOL CALLBACK EnumMonitorForDisplayInfoCallback(HMONITOR monitor, const gfx::Vector2dF pixels_per_inch = GetMonitorPixelsPerInch(monitor).value_or( GetDefaultMonitorPhysicalPixelsPerInch()); + const auto path_info = GetPathInfo(monitor); auto* display_infos = reinterpret_cast<std::vector<DisplayInfo>*>(data); DCHECK(display_infos); - display_infos->emplace_back(monitor_info, GetMonitorScaleFactor(monitor), - GetMonitorSDRWhiteLevel(monitor), - display_settings.rotation, - display_settings.frequency, pixels_per_inch); + display_infos->emplace_back( + monitor_info, GetMonitorScaleFactor(monitor), GetSDRWhiteLevel(path_info), + display_settings.rotation, display_settings.frequency, pixels_per_inch, + GetOutputTechnology(path_info)); return TRUE; } @@ -635,7 +657,7 @@ void ScreenWin::SetHDREnabled(bool hdr_enabled) { } } -HWND ScreenWin::GetHWNDFromNativeView(gfx::NativeView window) const { +HWND ScreenWin::GetHWNDFromNativeWindow(gfx::NativeWindow window) const { NOTREACHED(); return nullptr; } @@ -669,6 +691,20 @@ gfx::NativeWindow ScreenWin::GetWindowAtScreenPoint(const gfx::Point& point) { return GetNativeWindowFromHWND(WindowFromPoint(screen_point.ToPOINT())); } +gfx::NativeWindow ScreenWin::GetLocalProcessWindowAtPoint( + const gfx::Point& point, + const std::set<gfx::NativeWindow>& ignore) { + std::set<HWND> hwnd_set; + for (auto* const window : ignore) { + HWND w = GetHWNDFromNativeWindow(window); + if (w) + hwnd_set.emplace(w); + } + + return LocalProcessWindowFinder::GetProcessWindowAtPoint(point, hwnd_set, + this); +} + int ScreenWin::GetNumDisplays() const { return int{screen_win_displays_.size()}; } @@ -678,7 +714,7 @@ const std::vector<Display>& ScreenWin::GetAllDisplays() const { } Display ScreenWin::GetDisplayNearestWindow(gfx::NativeWindow window) const { - const HWND window_hwnd = window ? GetHWNDFromNativeView(window) : nullptr; + const HWND window_hwnd = window ? GetHWNDFromNativeWindow(window) : nullptr; // When |window| isn't rooted to a display, we should just return the default // display so we get some correct display information like the scaling factor. return window_hwnd ? GetScreenWinDisplayNearestHWND(window_hwnd).display() @@ -707,15 +743,15 @@ void ScreenWin::RemoveObserver(DisplayObserver* observer) { } gfx::Rect ScreenWin::ScreenToDIPRectInWindow( - gfx::NativeView view, + gfx::NativeWindow window, const gfx::Rect& screen_rect) const { - const HWND hwnd = view ? GetHWNDFromNativeView(view) : nullptr; + const HWND hwnd = window ? GetHWNDFromNativeWindow(window) : nullptr; return ScreenToDIPRect(hwnd, screen_rect); } -gfx::Rect ScreenWin::DIPToScreenRectInWindow(gfx::NativeView view, +gfx::Rect ScreenWin::DIPToScreenRectInWindow(gfx::NativeWindow window, const gfx::Rect& dip_rect) const { - const HWND hwnd = view ? GetHWNDFromNativeView(view) : nullptr; + const HWND hwnd = window ? GetHWNDFromNativeWindow(window) : nullptr; return DIPToScreenRect(hwnd, dip_rect); } @@ -724,6 +760,13 @@ void ScreenWin::UpdateFromDisplayInfos( screen_win_displays_ = DisplayInfosToScreenWinDisplays( display_infos, color_profile_reader_.get(), hdr_enabled_); displays_ = ScreenWinDisplaysToDisplays(screen_win_displays_); + for (const auto& display_info : display_infos) { + if (IsInternalOutputTechnology(display_info.output_technology())) { + // TODO(crbug.com/1078903): Support multiple internal displays. + Display::SetInternalDisplayId(display_info.id()); + break; + } + } } void ScreenWin::Initialize() { diff --git a/chromium/ui/display/win/screen_win.h b/chromium/ui/display/win/screen_win.h index 40c388cfbfd..dfffbeff3f5 100644 --- a/chromium/ui/display/win/screen_win.h +++ b/chromium/ui/display/win/screen_win.h @@ -148,10 +148,10 @@ class DISPLAY_EXPORT ScreenWin : public Screen, // to return that HDR is supported. static void SetHDREnabled(bool hdr_enabled); - // Returns the HWND associated with the NativeView. - virtual HWND GetHWNDFromNativeView(gfx::NativeView view) const; + // Returns the HWND associated with the NativeWindow. + virtual HWND GetHWNDFromNativeWindow(gfx::NativeWindow view) const; - // Returns the NativeView associated with the HWND. + // Returns the NativeWindow associated with the HWND. virtual gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const; protected: @@ -161,6 +161,9 @@ class DISPLAY_EXPORT ScreenWin : public Screen, gfx::Point GetCursorScreenPoint() override; bool IsWindowUnderCursor(gfx::NativeWindow window) override; gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; + gfx::NativeWindow GetLocalProcessWindowAtPoint( + const gfx::Point& point, + const std::set<gfx::NativeWindow>& ignore) override; int GetNumDisplays() const override; const std::vector<Display>& GetAllDisplays() const override; Display GetDisplayNearestWindow(gfx::NativeWindow window) const override; @@ -170,9 +173,10 @@ class DISPLAY_EXPORT ScreenWin : public Screen, void AddObserver(DisplayObserver* observer) override; void RemoveObserver(DisplayObserver* observer) override; gfx::Rect ScreenToDIPRectInWindow( - gfx::NativeView view, const gfx::Rect& screen_rect) const override; - gfx::Rect DIPToScreenRectInWindow( - gfx::NativeView view, const gfx::Rect& dip_rect) const override; + gfx::NativeWindow window, + const gfx::Rect& screen_rect) const override; + gfx::Rect DIPToScreenRectInWindow(gfx::NativeWindow window, + const gfx::Rect& dip_rect) const override; // ColorProfileReader::Client: void OnColorProfilesChanged() override; diff --git a/chromium/ui/display/win/screen_win_unittest.cc b/chromium/ui/display/win/screen_win_unittest.cc index 1b4f1543cd7..059c533c4f1 100644 --- a/chromium/ui/display/win/screen_win_unittest.cc +++ b/chromium/ui/display/win/screen_win_unittest.cc @@ -1,4 +1,4 @@ -// Copyright 2015 The Chromium Authors. All rights reserved. +// Copyright 2015 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -43,9 +43,9 @@ class TestScreenWin : public ScreenWin { protected: // win::ScreenWin: - HWND GetHWNDFromNativeView(gfx::NativeView window) const override { - // NativeView is only used as an identifier in these tests, so interchange - // a NativeView for an HWND for convenience. + HWND GetHWNDFromNativeWindow(gfx::NativeWindow window) const override { + // NativeWindow is only used as an identifier in these tests, so interchange + // a NativeWindow for an HWND for convenience. return reinterpret_cast<HWND>(window); } @@ -138,7 +138,9 @@ class TestScreenWinInitializer { virtual void AddMonitor(const gfx::Rect& pixel_bounds, const gfx::Rect& pixel_work, const wchar_t* device_name, - float device_scale_factor) = 0; + float device_scale_factor, + DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY tech = + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER) = 0; virtual HWND CreateFakeHwnd(const gfx::Rect& bounds) = 0; }; @@ -152,13 +154,15 @@ class TestScreenWinManager final : public TestScreenWinInitializer { void AddMonitor(const gfx::Rect& pixel_bounds, const gfx::Rect& pixel_work, const wchar_t* device_name, - float device_scale_factor) override { + float device_scale_factor, + DISPLAYCONFIG_VIDEO_OUTPUT_TECHNOLOGY tech = + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER) override { MONITORINFOEX monitor_info = win::test::CreateMonitorInfo(pixel_bounds, pixel_work, device_name); monitor_infos_.push_back(monitor_info); display_infos_.push_back(DisplayInfo(monitor_info, device_scale_factor, 1.0f, Display::ROTATE_0, 60, - gfx::Vector2dF())); + gfx::Vector2dF(), tech)); } HWND CreateFakeHwnd(const gfx::Rect& bounds) override { @@ -3493,5 +3497,34 @@ TEST_F(ScreenWinUninitializedForced2x, GetScaleFactorForHWND) { EXPECT_EQ(2.0, ScreenWin::GetScaleFactorForHWND(nullptr)); } +namespace { + +// Two Displays, one of which is internal (eg. a laptop screen). +class ScreenWinTestTwoDisplaysOneInternal : public ScreenWinTest { + public: + ScreenWinTestTwoDisplaysOneInternal() = default; + + void SetUpScreen(TestScreenWinInitializer* initializer) override { + initializer->AddMonitor(gfx::Rect(0, 0, 1920, 1200), + gfx::Rect(0, 0, 1920, 1100), L"primary", 1.0, + DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL); + initializer->AddMonitor(gfx::Rect(1920, 0, 800, 600), + gfx::Rect(1920, 0, 800, 600), L"secondary", 1.0); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ScreenWinTestTwoDisplaysOneInternal); +}; + +} // namespace + +TEST_F(ScreenWinTestTwoDisplaysOneInternal, InternalDisplayIdSet) { + EXPECT_NE(Display::InternalDisplayId(), kInvalidDisplayId); + std::vector<Display> displays = GetScreen()->GetAllDisplays(); + ASSERT_EQ(2u, displays.size()); + EXPECT_EQ(Display::InternalDisplayId(), displays[0].id()); + EXPECT_NE(Display::InternalDisplayId(), displays[1].id()); +} + } // namespace win } // namespace display diff --git a/chromium/ui/display/win/topmost_window_finder_win.cc b/chromium/ui/display/win/topmost_window_finder_win.cc new file mode 100644 index 00000000000..a3cc87ae585 --- /dev/null +++ b/chromium/ui/display/win/topmost_window_finder_win.cc @@ -0,0 +1,83 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/display/win/topmost_window_finder_win.h" + +#include "ui/display/win/screen_win.h" + +namespace display { +namespace win { + +// static +bool TopMostFinderWin::IsTopMostWindowAtPoint(HWND window, + const gfx::Point& screen_loc, + const std::set<HWND>& ignore) { + TopMostFinderWin finder(window, screen_loc, ignore); + return finder.is_top_most_; +} + +bool TopMostFinderWin::ShouldStopIterating(HWND hwnd) { + if (hwnd == target_) { + // Window is topmost, stop iterating. + is_top_most_ = true; + return true; + } + + if (!IsWindowVisible(hwnd)) { + // The window isn't visible, keep iterating. + return false; + } + + RECT r; + if (!GetWindowRect(hwnd, &r) || !PtInRect(&r, screen_loc_.ToPOINT())) { + // The window doesn't contain the point, keep iterating. + return false; + } + + LONG ex_styles = GetWindowLong(hwnd, GWL_EXSTYLE); + if (ex_styles & WS_EX_TRANSPARENT || ex_styles & WS_EX_LAYERED) { + // Mouse events fall through WS_EX_TRANSPARENT windows, so we ignore them. + // + // WS_EX_LAYERED is trickier. Apps like Switcher create a totally + // transparent WS_EX_LAYERED window that is always on top. If we don't + // ignore WS_EX_LAYERED windows and there are totally transparent + // WS_EX_LAYERED windows then there are effectively holes on the screen + // that the user can't reattach tabs to. So we ignore them. This is a bit + // problematic in so far as WS_EX_LAYERED windows need not be totally + // transparent in which case we treat chrome windows as not being obscured + // when they really are, but this is better than not being able to + // reattach tabs. + return false; + } + + // hwnd is at the point. Make sure the point is within the windows region. + if (GetWindowRgn(hwnd, tmp_region_.get()) == ERROR) { + // There's no region on the window and the window contains the point. Stop + // iterating. + return true; + } + + // The region is relative to the window's rect. + BOOL is_point_in_region = PtInRegion( + tmp_region_.get(), screen_loc_.x() - r.left, screen_loc_.y() - r.top); + tmp_region_.reset(CreateRectRgn(0, 0, 0, 0)); + // Stop iterating if the region contains the point. + return !!is_point_in_region; +} + +TopMostFinderWin::TopMostFinderWin(HWND window, + const gfx::Point& screen_loc, + const std::set<HWND>& ignore) + : BaseWindowFinderWin(ignore), + target_(window), + is_top_most_(false), + tmp_region_(CreateRectRgn(0, 0, 0, 0)) { + screen_loc_ = display::win::ScreenWin::DIPToScreenPoint(screen_loc); + EnumWindows(WindowCallbackProc, as_lparam()); +} + +TopMostFinderWin::~TopMostFinderWin() = default; + +} // namespace win +} // namespace display
\ No newline at end of file diff --git a/chromium/ui/display/win/topmost_window_finder_win.h b/chromium/ui/display/win/topmost_window_finder_win.h new file mode 100644 index 00000000000..95f32f6bb87 --- /dev/null +++ b/chromium/ui/display/win/topmost_window_finder_win.h @@ -0,0 +1,51 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_DISPLAY_WIN_TOPMOST_WINDOW_FINDER_WIN_H_ +#define UI_DISPLAY_WIN_TOPMOST_WINDOW_FINDER_WIN_H_ + +#include "base/win/scoped_gdi_object.h" +#include "ui/display/win/base_window_finder_win.h" +#include "ui/gfx/geometry/point.h" + +namespace display { +namespace win { + +// Helper class to determine if a particular point of a window is not obscured +// by another window. +class TopMostFinderWin : public BaseWindowFinderWin { + public: + // Returns true if |window| is the topmost window at the location + // |screen_loc|, not including the windows in |ignore|. + static bool IsTopMostWindowAtPoint(HWND window, + const gfx::Point& screen_loc, + const std::set<HWND>& ignore); + + bool ShouldStopIterating(HWND hwnd) override; + + private: + TopMostFinderWin(HWND window, + const gfx::Point& screen_loc, + const std::set<HWND>& ignore); + TopMostFinderWin(const TopMostFinderWin& finder) = delete; + TopMostFinderWin& operator=(const TopMostFinderWin& finder) = delete; + ~TopMostFinderWin() override; + + // The window we're looking for. + HWND target_; + + // Location of window to find in pixel coordinates. + gfx::Point screen_loc_; + + // Is target_ the top most window? This is initially false but set to true + // in ShouldStopIterating if target_ is passed in. + bool is_top_most_; + + base::win::ScopedRegion tmp_region_; +}; + +} // namespace win +} // namespace display + +#endif // UI_DISPLAY_WIN_TOPMOST_WINDOW_FINDER_WIN_H_
\ No newline at end of file |