diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-07-12 14:07:37 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-07-17 10:29:26 +0000 |
commit | ec02ee4181c49b61fce1c8fb99292dbb8139cc90 (patch) | |
tree | 25cde714b2b71eb639d1cd53f5a22e9ba76e14ef /chromium/ui/display | |
parent | bb09965444b5bb20b096a291445170876225268d (diff) | |
download | qtwebengine-chromium-ec02ee4181c49b61fce1c8fb99292dbb8139cc90.tar.gz |
BASELINE: Update Chromium to 59.0.3071.134
Change-Id: Id02ef6fb2204c5fd21668a1c3e6911c83b17585a
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/ui/display')
74 files changed, 2009 insertions, 438 deletions
diff --git a/chromium/ui/display/BUILD.gn b/chromium/ui/display/BUILD.gn index 643971c6e53..c8f42a9022f 100644 --- a/chromium/ui/display/BUILD.gn +++ b/chromium/ui/display/BUILD.gn @@ -32,6 +32,7 @@ component("display") { "mac/screen_mac.mm", "screen.cc", "screen.h", + "screen_android.cc", "screen_aura.cc", "screen_base.cc", "screen_base.h", @@ -147,6 +148,7 @@ test("display_unittests") { "manager/chromeos/touchscreen_util_unittest.cc", "manager/chromeos/update_display_configuration_task_unittest.cc", "manager/display_manager_utilities_unittest.cc", + "manager/json_converter_unittest.cc", "manager/managed_display_info_unittest.cc", "mojo/display_struct_traits_unittest.cc", "screen_unittest.cc", diff --git a/chromium/ui/display/display.cc b/chromium/ui/display/display.cc index fb534b97d5e..ae0eb511899 100644 --- a/chromium/ui/display/display.cc +++ b/chromium/ui/display/display.cc @@ -20,6 +20,12 @@ namespace display { namespace { +constexpr int DEFAULT_BITS_PER_PIXEL = 24; +constexpr int DEFAULT_BITS_PER_COMPONENT = 8; + +constexpr int HDR_BITS_PER_PIXEL = 48; +constexpr int HDR_BITS_PER_COMPONENT = 16; + // This variable tracks whether the forced device scale factor switch needs to // be read from the command line, i.e. if it is set to -1 then the command line // is checked. @@ -73,9 +79,6 @@ void Display::ResetForceDeviceScaleFactorForTesting() { g_forced_device_scale_factor = -1.0; } -constexpr int DEFAULT_BITS_PER_PIXEL = 24; -constexpr int DEFAULT_BITS_PER_COMPONENT = 8; - Display::Display() : Display(kInvalidDisplayId) {} Display::Display(int64_t id) : Display(id, gfx::Rect()) {} @@ -87,6 +90,10 @@ Display::Display(int64_t id, const gfx::Rect& bounds) device_scale_factor_(GetForcedDeviceScaleFactor()), color_depth_(DEFAULT_BITS_PER_PIXEL), depth_per_component_(DEFAULT_BITS_PER_COMPONENT) { + if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableHDR)) { + color_depth_ = HDR_BITS_PER_PIXEL; + depth_per_component_ = HDR_BITS_PER_COMPONENT; + } #if defined(USE_AURA) SetScaleAndBounds(device_scale_factor_, bounds); #endif diff --git a/chromium/ui/display/display_finder.cc b/chromium/ui/display/display_finder.cc index 82a9eb04b0a..c4e42f82d9d 100644 --- a/chromium/ui/display/display_finder.cc +++ b/chromium/ui/display/display_finder.cc @@ -4,6 +4,7 @@ #include "ui/display/display_finder.h" +#include <algorithm> #include <limits> #include "base/logging.h" @@ -13,9 +14,15 @@ namespace display { -const Display* FindDisplayNearestPoint(const std::vector<Display>& displays, +using Displays = std::vector<Display>; + +const Display* FindDisplayNearestPoint(const Displays& displays, const gfx::Point& point) { DCHECK(!displays.empty()); + auto iter = FindDisplayContainingPoint(displays, point); + if (iter != displays.end()) + return &(*iter); + int min_distance = std::numeric_limits<int>::max(); const Display* nearest_display = nullptr; for (const auto& display : displays) { @@ -30,9 +37,8 @@ const Display* FindDisplayNearestPoint(const std::vector<Display>& displays, return nearest_display; } -const Display* FindDisplayWithBiggestIntersection( - const std::vector<Display>& displays, - const gfx::Rect& rect) { +const Display* FindDisplayWithBiggestIntersection(const Displays& displays, + const gfx::Rect& rect) { DCHECK(!displays.empty()); int max_area = 0; const Display* matching = nullptr; @@ -47,4 +53,13 @@ const Display* FindDisplayWithBiggestIntersection( return matching; } +Displays::const_iterator FindDisplayContainingPoint( + const Displays& displays, + const gfx::Point& point_in_screen) { + return std::find_if(displays.begin(), displays.end(), + [point_in_screen](const Display& display) { + return display.bounds().Contains(point_in_screen); + }); +} + } // namespace display diff --git a/chromium/ui/display/display_finder.h b/chromium/ui/display/display_finder.h index d63925923c7..7381b15e18e 100644 --- a/chromium/ui/display/display_finder.h +++ b/chromium/ui/display/display_finder.h @@ -17,7 +17,8 @@ class Rect; namespace display { class Display; -// Returns the display in |displays| closest to |point|. +// Returns the display containing |point|. If no displays contain |point|, then +// this returns the display closest to |point|. DISPLAY_EXPORT const Display* FindDisplayNearestPoint( const std::vector<Display>& displays, const gfx::Point& point); @@ -28,6 +29,13 @@ DISPLAY_EXPORT const Display* FindDisplayWithBiggestIntersection( const std::vector<Display>& displays, const gfx::Rect& rect); +// Returns an iterator into |displays| of the Display whose bounds contains +// |point_in_screen|, or displays.end() if no Displays contains +// |point_in_screen|. +DISPLAY_EXPORT std::vector<Display>::const_iterator FindDisplayContainingPoint( + const std::vector<Display>& displays, + const gfx::Point& point_in_screen); + } // namespace display #endif // UI_DISPLAY_DISPLAY_FINDER_H_ diff --git a/chromium/ui/display/display_layout.cc b/chromium/ui/display/display_layout.cc index fe514e134c4..70784947b1c 100644 --- a/chromium/ui/display/display_layout.cc +++ b/chromium/ui/display/display_layout.cc @@ -8,6 +8,7 @@ #include <map> #include <set> #include <sstream> +#include <unordered_map> #include "base/logging.h" #include "base/strings/string_number_conversions.h" @@ -37,6 +38,10 @@ bool IsIdInList(int64_t id, const DisplayIdList& list) { return iter != list.end(); } +bool ComparePlacements(const DisplayPlacement& d1, const DisplayPlacement& d2) { + return d1.display_id < d2.display_id; +} + // Extracts the displays IDs list from the displays list. DisplayIdList DisplayListToDisplayIdList(const Displays& displays) { DisplayIdList list; @@ -101,10 +106,7 @@ bool AreDisplaysTouching(const Display& child_display, // IDs. void UpdatePlacementList(Displays* display_list, std::vector<DisplayPlacement>* placement_list) { - std::sort(placement_list->begin(), placement_list->end(), - [](const DisplayPlacement& p1, const DisplayPlacement& p2) { - return p1.display_id < p2.display_id; - }); + std::sort(placement_list->begin(), placement_list->end(), ComparePlacements); for (DisplayPlacement& placement : *placement_list) { const Display* child_display = @@ -580,6 +582,27 @@ std::unique_ptr<DisplayLayout> DisplayLayout::Copy() const { return copy; } +void DisplayLayout::SwapPrimaryDisplay(int64_t new_primary_id) { + if (primary_id == new_primary_id) + return; + + // Build a map of the *original* |display_id| for each placement. + std::unordered_map<int64_t, DisplayPlacement*> id_to_placement; + for (auto& placement : placement_list) + id_to_placement[placement.display_id] = &placement; + + // Swap placements so that |new_primary_id| is the display that placements are + // anchored on and set |primary_id|. + int64_t swap_display_id = new_primary_id; + while (swap_display_id != primary_id) { + DisplayPlacement* placement = id_to_placement.at(swap_display_id); + swap_display_id = placement->parent_display_id; + placement->Swap(); + } + std::sort(placement_list.begin(), placement_list.end(), ComparePlacements); + primary_id = new_primary_id; +} + bool DisplayLayout::HasSamePlacementList(const DisplayLayout& layout) const { return placement_list == layout.placement_list; } diff --git a/chromium/ui/display/display_layout.h b/chromium/ui/display/display_layout.h index 6fcde093539..f9f8c46ed4c 100644 --- a/chromium/ui/display/display_layout.h +++ b/chromium/ui/display/display_layout.h @@ -111,6 +111,10 @@ class DISPLAY_EXPORT DisplayLayout final { std::unique_ptr<DisplayLayout> Copy() const; + // Swaps the primary display so it is |new_primary_id|. This modifies the + // display placements such so they are anchored on |new_primary_id|. + void SwapPrimaryDisplay(int64_t new_primary_id); + // Test if the |layout| has the same placement list. Other fields such // as mirrored, primary_id are ignored. bool HasSamePlacementList(const DisplayLayout& layout) const; diff --git a/chromium/ui/display/display_layout_unittest.cc b/chromium/ui/display/display_layout_unittest.cc index bc940f061fb..d5abf695cda 100644 --- a/chromium/ui/display/display_layout_unittest.cc +++ b/chromium/ui/display/display_layout_unittest.cc @@ -13,6 +13,8 @@ namespace display { +using Position = DisplayPlacement::Position; + TEST(DisplayLayoutTest, Empty) { Displays display_list; std::vector<int64_t> updated_ids; @@ -52,6 +54,73 @@ TEST(DisplayLayoutTest, SingleDisplayNonRelevantPlacement) { EXPECT_EQ(gfx::Rect(0, 0, 800, 600), display_list[0].bounds()); } +TEST(DisplayLayoutTest, SwapPrimaryDisplay) { + std::unique_ptr<DisplayLayout> layout = + DisplayLayoutBuilder(123) + .AddDisplayPlacement(456, 123, Position::LEFT, 150) + .Build(); + + // Initial layout will be 123 <-- 456 + EXPECT_EQ(123, layout->primary_id); + EXPECT_EQ(456, layout->placement_list[0].display_id); + EXPECT_EQ(123, layout->placement_list[0].parent_display_id); + EXPECT_EQ(Position::LEFT, layout->placement_list[0].position); + EXPECT_EQ(150, layout->placement_list[0].offset); + + // Swap layout to 123 --> 456. + layout->SwapPrimaryDisplay(456); + EXPECT_EQ(456, layout->primary_id); + EXPECT_EQ(123, layout->placement_list[0].display_id); + EXPECT_EQ(456, layout->placement_list[0].parent_display_id); + EXPECT_EQ(Position::RIGHT, layout->placement_list[0].position); + EXPECT_EQ(-150, layout->placement_list[0].offset); + + // Swap layout back to 123 <-- 456. + layout->SwapPrimaryDisplay(123); + EXPECT_EQ(123, layout->primary_id); + EXPECT_EQ(456, layout->placement_list[0].display_id); + EXPECT_EQ(123, layout->placement_list[0].parent_display_id); + EXPECT_EQ(Position::LEFT, layout->placement_list[0].position); + EXPECT_EQ(150, layout->placement_list[0].offset); +} + +TEST(DisplayLayoutTest, SwapPrimaryDisplayThreeDisplays) { + std::unique_ptr<DisplayLayout> layout = + DisplayLayoutBuilder(456) + .AddDisplayPlacement(123, 456, Position::LEFT, 0) + .AddDisplayPlacement(789, 456, Position::RIGHT, 0) + .Build(); + + // Initial layout will be 123 --> 456 <-- 789. + EXPECT_EQ(456, layout->primary_id); + EXPECT_EQ(123, layout->placement_list[0].display_id); + EXPECT_EQ(456, layout->placement_list[0].parent_display_id); + EXPECT_EQ(Position::LEFT, layout->placement_list[0].position); + EXPECT_EQ(789, layout->placement_list[1].display_id); + EXPECT_EQ(456, layout->placement_list[1].parent_display_id); + EXPECT_EQ(Position::RIGHT, layout->placement_list[1].position); + + // Swap layout to 123 --> 456 --> 789. + layout->SwapPrimaryDisplay(789); + EXPECT_EQ(789, layout->primary_id); + EXPECT_EQ(123, layout->placement_list[0].display_id); + EXPECT_EQ(456, layout->placement_list[0].parent_display_id); + EXPECT_EQ(Position::LEFT, layout->placement_list[0].position); + EXPECT_EQ(456, layout->placement_list[1].display_id); + EXPECT_EQ(789, layout->placement_list[1].parent_display_id); + EXPECT_EQ(Position::LEFT, layout->placement_list[1].position); + + // Swap layout to 123 <-- 456 <-- 789. + layout->SwapPrimaryDisplay(123); + EXPECT_EQ(123, layout->primary_id); + EXPECT_EQ(456, layout->placement_list[0].display_id); + EXPECT_EQ(123, layout->placement_list[0].parent_display_id); + EXPECT_EQ(Position::RIGHT, layout->placement_list[0].position); + EXPECT_EQ(789, layout->placement_list[1].display_id); + EXPECT_EQ(456, layout->placement_list[1].parent_display_id); + EXPECT_EQ(Position::RIGHT, layout->placement_list[1].position); +} + namespace { class TwoDisplays diff --git a/chromium/ui/display/display_list.cc b/chromium/ui/display/display_list.cc index c558ea37600..b5f830a8b25 100644 --- a/chromium/ui/display/display_list.cc +++ b/chromium/ui/display/display_list.cc @@ -52,11 +52,11 @@ std::unique_ptr<DisplayListObserverLock> DisplayList::SuspendObserverUpdates() { return base::WrapUnique(new DisplayListObserverLock(this)); } -void DisplayList::UpdateDisplay(const Display& display) { - UpdateDisplay(display, GetTypeByDisplayId(display.id())); +uint32_t DisplayList::UpdateDisplay(const Display& display) { + return UpdateDisplay(display, GetTypeByDisplayId(display.id())); } -void DisplayList::UpdateDisplay(const Display& display, Type type) { +uint32_t DisplayList::UpdateDisplay(const Display& display, Type type) { auto iter = FindDisplayByIdInternal(display.id()); DCHECK(iter != displays_.end()); @@ -90,6 +90,7 @@ void DisplayList::UpdateDisplay(const Display& display, Type type) { for (DisplayObserver& observer : observers_) observer.OnDisplayMetricsChanged(*local_display, changed_values); } + return changed_values; } void DisplayList::AddDisplay(const Display& display, Type type) { diff --git a/chromium/ui/display/display_list.h b/chromium/ui/display/display_list.h index 630e4a54e8e..20a454d4625 100644 --- a/chromium/ui/display/display_list.h +++ b/chromium/ui/display/display_list.h @@ -64,12 +64,15 @@ class DISPLAY_EXPORT DisplayList { // callers release the last lock they call the observers appropriately. std::unique_ptr<DisplayListObserverLock> SuspendObserverUpdates(); - // Updates the cached display based on display.id(). - void UpdateDisplay(const Display& display); + // Updates the cached display based on display.id(). This returns a bitmask + // of the changed values suitable for passing to + // DisplayObserver::OnDisplayMetricsChanged(). + uint32_t UpdateDisplay(const Display& display); // Updates the cached display based on display.id(). Also updates the primary - // display if |type| indicates |display| is the primary display. - void UpdateDisplay(const Display& display, Type type); + // display if |type| indicates |display| is the primary display. See single + // argument version for description of return value. + uint32_t UpdateDisplay(const Display& display, Type type); // Adds a new Display. void AddDisplay(const Display& display, Type type); diff --git a/chromium/ui/display/display_observer.h b/chromium/ui/display/display_observer.h index 92afb1a4069..df866542fa7 100644 --- a/chromium/ui/display/display_observer.h +++ b/chromium/ui/display/display_observer.h @@ -24,6 +24,7 @@ class DISPLAY_EXPORT DisplayObserver { DISPLAY_METRIC_DEVICE_SCALE_FACTOR = 1 << 2, DISPLAY_METRIC_ROTATION = 1 << 3, DISPLAY_METRIC_PRIMARY = 1 << 4, + DISPLAY_METRIC_MIRROR_STATE = 1 << 5, }; // Called when |new_display| has been added. diff --git a/chromium/ui/display/display_switches.cc b/chromium/ui/display/display_switches.cc index 945635dfe99..891715618a1 100644 --- a/chromium/ui/display/display_switches.cc +++ b/chromium/ui/display/display_switches.cc @@ -38,6 +38,9 @@ const char kScreenConfig[] = "screen-config"; // This is for debugging on linux desktop. const char kUseFirstDisplayAsInternal[] = "use-first-display-as-internal"; +// Use an fp16 scRGB swap chain compatible with HDR output. +const char kEnableHDR[] = "enable-hdr"; + #if defined(OS_CHROMEOS) const char kDisableDisplayColorCalibration[] = "disable-display-color-calibration"; diff --git a/chromium/ui/display/display_switches.h b/chromium/ui/display/display_switches.h index 57ceb048fa2..93b741bb2f9 100644 --- a/chromium/ui/display/display_switches.h +++ b/chromium/ui/display/display_switches.h @@ -19,6 +19,7 @@ DISPLAY_EXPORT extern const char kHostWindowBounds[]; DISPLAY_EXPORT extern const char kScreenConfig[]; DISPLAY_EXPORT extern const char kSecondaryDisplayLayout[]; DISPLAY_EXPORT extern const char kUseFirstDisplayAsInternal[]; +DISPLAY_EXPORT extern const char kEnableHDR[]; #if defined(OS_CHROMEOS) DISPLAY_EXPORT extern const char kDisableDisplayColorCalibration[]; diff --git a/chromium/ui/display/display_unittest.cc b/chromium/ui/display/display_unittest.cc index 62f6b58dfcf..dee754b4d96 100644 --- a/chromium/ui/display/display_unittest.cc +++ b/chromium/ui/display/display_unittest.cc @@ -5,6 +5,7 @@ #include "ui/display/display.h" #include "base/command_line.h" +#include "base/test/scoped_command_line.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/display/display_switches.h" #include "ui/gfx/geometry/insets.h" @@ -52,14 +53,32 @@ TEST(DisplayTest, Scale) { // https://crbug.com/517944 TEST(DisplayTest, ForcedDeviceScaleFactorByCommandLine) { + base::test::ScopedCommandLine scoped_command_line; + base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine(); + Display::ResetForceDeviceScaleFactorForTesting(); - // Look ma, no value! - base::CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kForceDeviceScaleFactor); + command_line->AppendSwitch(switches::kForceDeviceScaleFactor); EXPECT_EQ(1, Display::GetForcedDeviceScaleFactor()); Display::ResetForceDeviceScaleFactorForTesting(); } +TEST(DisplayTest, DisplayHDRValues) { + base::test::ScopedCommandLine scoped_command_line; + base::CommandLine* command_line = scoped_command_line.GetProcessCommandLine(); + { + Display display; + EXPECT_EQ(24, display.color_depth()); + EXPECT_EQ(8, display.depth_per_component()); + } + + command_line->AppendSwitch(switches::kEnableHDR); + { + Display display; + EXPECT_EQ(48, display.color_depth()); + EXPECT_EQ(16, display.depth_per_component()); + } +} + } // namespace display diff --git a/chromium/ui/display/fake_display_snapshot.cc b/chromium/ui/display/fake_display_snapshot.cc index ea2b52e150f..c7294a56fb9 100644 --- a/chromium/ui/display/fake_display_snapshot.cc +++ b/chromium/ui/display/fake_display_snapshot.cc @@ -60,8 +60,6 @@ std::string DisplayConnectionTypeString(DisplayConnectionType type) { return "dp"; case DISPLAY_CONNECTION_TYPE_NETWORK: return "network"; - case DISPLAY_CONNECTION_TYPE_VIRTUAL: - return "virtual"; } NOTREACHED(); return ""; diff --git a/chromium/ui/display/ios/screen_ios.mm b/chromium/ui/display/ios/screen_ios.mm index 23efa97dfd3..cb3c47b282b 100644 --- a/chromium/ui/display/ios/screen_ios.mm +++ b/chromium/ui/display/ios/screen_ios.mm @@ -51,6 +51,11 @@ class ScreenIos : public ScreenBase { } // namespace +// static +gfx::NativeWindow Screen::GetWindowForView(gfx::NativeView view) { + return [view window]; +} + Screen* CreateNativeScreen() { return new ScreenIos; } diff --git a/chromium/ui/display/mac/screen_mac.mm b/chromium/ui/display/mac/screen_mac.mm index fb25b0cd636..060d3108ce1 100644 --- a/chromium/ui/display/mac/screen_mac.mm +++ b/chromium/ui/display/mac/screen_mac.mm @@ -153,16 +153,11 @@ class ScreenMac : public Screen { return displays_; } - Display GetDisplayNearestWindow(gfx::NativeView view) const override { + Display GetDisplayNearestWindow(gfx::NativeWindow window) const override { EnsureDisplaysValid(); if (displays_.size() == 1) return displays_[0]; - NSWindow* window = nil; -#if !defined(USE_AURA) - if (view) - window = [view window]; -#endif if (!window) return GetPrimaryDisplay(); @@ -329,6 +324,15 @@ class ScreenMac : public Screen { } // namespace +// static +gfx::NativeWindow Screen::GetWindowForView(gfx::NativeView view) { + NSWindow* window = nil; +#if !defined(USE_AURA) + window = [view window]; +#endif + return window; +} + #if !defined(USE_AURA) Screen* CreateNativeScreen() { return new ScreenMac; diff --git a/chromium/ui/display/manager/BUILD.gn b/chromium/ui/display/manager/BUILD.gn index 16c9e99778c..af4d1ee0873 100644 --- a/chromium/ui/display/manager/BUILD.gn +++ b/chromium/ui/display/manager/BUILD.gn @@ -15,8 +15,6 @@ component("manager") { "chromeos/display_configurator.cc", "chromeos/display_configurator.h", "chromeos/display_layout_manager.h", - "chromeos/display_snapshot_virtual.cc", - "chromeos/display_snapshot_virtual.h", "chromeos/display_util.cc", "chromeos/display_util.h", "chromeos/query_content_protection_task.cc", @@ -34,6 +32,11 @@ component("manager") { "display_manager_export.h", "display_manager_utilities.cc", "display_manager_utilities.h", + "display_pref_util.h", + "forwarding_display_delegate.cc", + "forwarding_display_delegate.h", + "json_converter.cc", + "json_converter.h", "managed_display_info.cc", "managed_display_info.h", ] @@ -45,6 +48,7 @@ component("manager") { deps = [ "//base", "//ui/base", + "//ui/display/mojo:interfaces", "//ui/display/util", "//ui/events/devices", "//ui/strings", diff --git a/chromium/ui/display/manager/chromeos/apply_content_protection_task.cc b/chromium/ui/display/manager/chromeos/apply_content_protection_task.cc index c7a4fcd8283..612a563cf24 100644 --- a/chromium/ui/display/manager/chromeos/apply_content_protection_task.cc +++ b/chromium/ui/display/manager/chromeos/apply_content_protection_task.cc @@ -28,7 +28,6 @@ bool GetHDCPCapableDisplays( case DISPLAY_CONNECTION_TYPE_INTERNAL: case DISPLAY_CONNECTION_TYPE_VGA: case DISPLAY_CONNECTION_TYPE_NETWORK: - case DISPLAY_CONNECTION_TYPE_VIRTUAL: // No protections for these types. Do nothing. break; case DISPLAY_CONNECTION_TYPE_NONE: diff --git a/chromium/ui/display/manager/chromeos/configure_displays_task.cc b/chromium/ui/display/manager/chromeos/configure_displays_task.cc index 5464998ce24..b1a866f7f17 100644 --- a/chromium/ui/display/manager/chromeos/configure_displays_task.cc +++ b/chromium/ui/display/manager/chromeos/configure_displays_task.cc @@ -55,9 +55,12 @@ ConfigureDisplaysTask::ConfigureDisplaysTask( weak_ptr_factory_(this) { for (size_t i = 0; i < requests_.size(); ++i) pending_request_indexes_.push(i); + delegate_->AddObserver(this); } -ConfigureDisplaysTask::~ConfigureDisplaysTask() {} +ConfigureDisplaysTask::~ConfigureDisplaysTask() { + delegate_->RemoveObserver(this); +} void ConfigureDisplaysTask::Run() { // Synchronous configurators will recursively call Run(). In that case just @@ -91,6 +94,17 @@ void ConfigureDisplaysTask::Run() { callback_.Run(task_status_); } +void ConfigureDisplaysTask::OnConfigurationChanged() {} + +void ConfigureDisplaysTask::OnDisplaySnapshotsInvalidated() { + std::queue<size_t> empty_queue; + pending_request_indexes_.swap(empty_queue); + // From now on, don't access |requests_[index]->display|; they're invalid. + task_status_ = ERROR; + weak_ptr_factory_.InvalidateWeakPtrs(); + Run(); +} + void ConfigureDisplaysTask::OnConfigured(size_t index, bool success) { DisplayConfigureRequest* request = &requests_[index]; VLOG(2) << "Configured status=" << success diff --git a/chromium/ui/display/manager/chromeos/configure_displays_task.h b/chromium/ui/display/manager/chromeos/configure_displays_task.h index d9e3ace1228..db4da8aad4b 100644 --- a/chromium/ui/display/manager/chromeos/configure_displays_task.h +++ b/chromium/ui/display/manager/chromeos/configure_displays_task.h @@ -14,6 +14,7 @@ #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "ui/display/manager/display_manager_export.h" +#include "ui/display/types/native_display_observer.h" #include "ui/gfx/geometry/point.h" namespace display { @@ -33,7 +34,8 @@ struct DISPLAY_MANAGER_EXPORT DisplayConfigureRequest { }; // Applies the display configuration asynchronously. -class DISPLAY_MANAGER_EXPORT ConfigureDisplaysTask { +class DISPLAY_MANAGER_EXPORT ConfigureDisplaysTask + : public NativeDisplayObserver { public: enum Status { // At least one of the displays failed to apply any mode it supports. @@ -52,11 +54,15 @@ class DISPLAY_MANAGER_EXPORT ConfigureDisplaysTask { ConfigureDisplaysTask(NativeDisplayDelegate* delegate, const std::vector<DisplayConfigureRequest>& requests, const ResponseCallback& callback); - ~ConfigureDisplaysTask(); + ~ConfigureDisplaysTask() override; // Starts the configuration task. void Run(); + // display::NativeDisplayObserver: + void OnConfigurationChanged() override; + void OnDisplaySnapshotsInvalidated() override; + private: void OnConfigured(size_t index, bool success); diff --git a/chromium/ui/display/manager/chromeos/display_change_observer.cc b/chromium/ui/display/manager/chromeos/display_change_observer.cc index f4206c7e83d..8934783a937 100644 --- a/chromium/ui/display/manager/chromeos/display_change_observer.cc +++ b/chromium/ui/display/manager/chromeos/display_change_observer.cc @@ -38,7 +38,8 @@ struct DeviceScaleFactorDPIThreshold { }; const DeviceScaleFactorDPIThreshold kThresholdTable[] = { - {200.0f, 2.0f}, + {220.0f, 2.0f}, + {180.0f, 1.5f}, {150.0f, 1.25f}, {0.0f, 1.0f}, }; @@ -220,17 +221,9 @@ void DisplayChangeObserver::OnDisplayModeChanged( } gfx::Rect display_bounds(state->origin(), mode_info->size()); - std::string name; - switch (state->type()) { - case DISPLAY_CONNECTION_TYPE_INTERNAL: - name = l10n_util::GetStringUTF8(IDS_DISPLAY_NAME_INTERNAL); - break; - case DISPLAY_CONNECTION_TYPE_VIRTUAL: - name = l10n_util::GetStringUTF8(IDS_DISPLAY_NAME_VIRTUAL); - break; - default: - name = state->display_name(); - } + std::string name = (state->type() == DISPLAY_CONNECTION_TYPE_INTERNAL) + ? l10n_util::GetStringUTF8(IDS_DISPLAY_NAME_INTERNAL) + : state->display_name(); if (name.empty()) name = l10n_util::GetStringUTF8(IDS_DISPLAY_NAME_UNKNOWN); diff --git a/chromium/ui/display/manager/chromeos/display_change_observer_unittest.cc b/chromium/ui/display/manager/chromeos/display_change_observer_unittest.cc index e0d4ad5c9e0..754d9c81893 100644 --- a/chromium/ui/display/manager/chromeos/display_change_observer_unittest.cc +++ b/chromium/ui/display/manager/chromeos/display_change_observer_unittest.cc @@ -330,18 +330,21 @@ TEST(DisplayChangeObserverTest, FindDeviceScaleFactor) { // 12.1" 1280x800 EXPECT_EQ(1.0f, ComputeDeviceScaleFactor(12.1f, gfx::Rect(1280, 800))); - // 11.6" 1920x1080 - EXPECT_EQ(1.25f, ComputeDeviceScaleFactor(11.6f, gfx::Rect(1920, 1080))); - // 13.3" 1920x1080 EXPECT_EQ(1.25f, ComputeDeviceScaleFactor(13.3f, gfx::Rect(1920, 1080))); // 14" 1920x1080 EXPECT_EQ(1.25f, ComputeDeviceScaleFactor(14.0f, gfx::Rect(1920, 1080))); + // 11.6" 1920x1080 + EXPECT_EQ(1.5f, ComputeDeviceScaleFactor(11.6f, gfx::Rect(1920, 1080))); + // 12.85" 2560x1700 EXPECT_EQ(2.0f, ComputeDeviceScaleFactor(12.85f, gfx::Rect(2560, 1700))); + // 12.3" 2400x1600 + EXPECT_EQ(2.0f, ComputeDeviceScaleFactor(12.3f, gfx::Rect(2400, 1600))); + // Erroneous values should still work. EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(-100.0f)); EXPECT_EQ(1.0f, DisplayChangeObserver::FindDeviceScaleFactor(0.0f)); diff --git a/chromium/ui/display/manager/chromeos/display_configurator.cc b/chromium/ui/display/manager/chromeos/display_configurator.cc index bc6f9fdf5d2..64201c08908 100644 --- a/chromium/ui/display/manager/chromeos/display_configurator.cc +++ b/chromium/ui/display/manager/chromeos/display_configurator.cc @@ -18,7 +18,6 @@ #include "ui/display/display_switches.h" #include "ui/display/manager/chromeos/apply_content_protection_task.h" #include "ui/display/manager/chromeos/display_layout_manager.h" -#include "ui/display/manager/chromeos/display_snapshot_virtual.h" #include "ui/display/manager/chromeos/display_util.h" #include "ui/display/manager/chromeos/update_display_configuration_task.h" #include "ui/display/types/display_mode.h" @@ -32,9 +31,6 @@ namespace { typedef std::vector<const DisplayMode*> DisplayModeList; -// The EDID specification marks the top bit of the manufacturer id as reserved. -const int16_t kReservedManufacturerID = static_cast<int16_t>(1 << 15); - struct DisplayState { DisplaySnapshot* display = nullptr; // Not owned. @@ -1037,7 +1033,6 @@ void DisplayConfigurator::RunPendingConfiguration() { requested_display_state_, pending_power_state_, pending_power_flags_, 0, force_configure_, base::Bind(&DisplayConfigurator::OnConfigured, weak_ptr_factory_.GetWeakPtr()))); - configuration_task_->SetVirtualDisplaySnapshots(virtual_display_snapshots_); // Reset the flags before running the task; otherwise it may end up scheduling // another configuration. @@ -1154,44 +1149,6 @@ void DisplayConfigurator::NotifyPowerStateObservers() { observer.OnPowerStateChanged(current_power_state_); } -int64_t DisplayConfigurator::AddVirtualDisplay(const gfx::Size& display_size) { - if (last_virtual_display_id_ == 0xff) { - LOG(WARNING) << "Exceeded virtual display id limit"; - return kInvalidDisplayId; - } - - int64_t display_id = GenerateDisplayID(kReservedManufacturerID, 0x0, - ++last_virtual_display_id_); - virtual_display_snapshots_.push_back( - base::MakeUnique<DisplaySnapshotVirtual>(display_id, display_size)); - ConfigureDisplays(); - - return display_id; -} - -bool DisplayConfigurator::RemoveVirtualDisplay(int64_t display_id) { - bool display_found = false; - for (auto it = virtual_display_snapshots_.begin(); - it != virtual_display_snapshots_.end(); ++it) { - if ((*it)->display_id() == display_id) { - virtual_display_snapshots_.erase(it); - ConfigureDisplays(); - display_found = true; - break; - } - } - - if (!display_found) - return false; - - int64_t max_display_id = 0; - for (const auto& display : virtual_display_snapshots_) - max_display_id = std::max(max_display_id, display->display_id()); - last_virtual_display_id_ = max_display_id & 0xff; - - return true; -} - bool DisplayConfigurator::IsDisplayOn() const { return current_power_state_ != chromeos::DISPLAY_POWER_ALL_OFF; } diff --git a/chromium/ui/display/manager/chromeos/display_configurator.h b/chromium/ui/display/manager/chromeos/display_configurator.h index d6cd96895d4..adf467e0f58 100644 --- a/chromium/ui/display/manager/chromeos/display_configurator.h +++ b/chromium/ui/display/manager/chromeos/display_configurator.h @@ -19,7 +19,6 @@ #include "base/observer_list.h" #include "base/timer/timer.h" #include "third_party/cros_system_api/dbus/service_constants.h" -#include "ui/display/manager/chromeos/display_snapshot_virtual.h" #include "ui/display/manager/chromeos/query_content_protection_task.h" #include "ui/display/manager/display_manager_export.h" #include "ui/display/types/display_constants.h" @@ -153,7 +152,7 @@ class DISPLAY_MANAGER_EXPORT DisplayConfigurator // The delay to perform configuration after RRNotify. See the comment for // |configure_timer_|. - static const int kConfigureDelayMs = 500; + static const int kConfigureDelayMs = 1000; // The delay to perform configuration after waking up from suspend when in // multi display mode. Should be bigger than |kConfigureDelayMs|. Generally @@ -284,10 +283,6 @@ class DISPLAY_MANAGER_EXPORT DisplayConfigurator bool SetColorCalibrationProfile(int64_t display_id, ColorCalibrationProfile new_profile); - // Enables/disables virtual display. - int64_t AddVirtualDisplay(const gfx::Size& display_size); - bool RemoveVirtualDisplay(int64_t display_id); - // Returns true if there is at least one display on. bool IsDisplayOn() const; @@ -463,12 +458,6 @@ class DISPLAY_MANAGER_EXPORT DisplayConfigurator // Whether the displays are currently suspended. bool displays_suspended_; - // Virtual display control. - std::vector<std::unique_ptr<DisplaySnapshot>> virtual_display_snapshots_; - - // Last used virtual display id. - uint8_t last_virtual_display_id_ = 0; - std::unique_ptr<DisplayLayoutManager> layout_manager_; std::unique_ptr<UpdateDisplayConfigurationTask> configuration_task_; diff --git a/chromium/ui/display/manager/chromeos/display_configurator_unittest.cc b/chromium/ui/display/manager/chromeos/display_configurator_unittest.cc index 4bca2fde4ff..a366630ab85 100644 --- a/chromium/ui/display/manager/chromeos/display_configurator_unittest.cc +++ b/chromium/ui/display/manager/chromeos/display_configurator_unittest.cc @@ -412,162 +412,6 @@ TEST_F(DisplayConfiguratorTest, FindDisplayModeMatchingSize) { *output, gfx::Size(1440, 900))); } -TEST_F(DisplayConfiguratorTest, EnableVirtualDisplay) { - InitWithSingleOutput(); - - observer_.Reset(); - const DisplayConfigurator::DisplayStateList& cached = - configurator_.cached_displays(); - ASSERT_EQ(static_cast<size_t>(1u), cached.size()); - EXPECT_EQ(small_mode_.size(), cached[0]->current_mode()->size()); - - // Add virtual display. - int64_t virtual_display_id = - configurator_.AddVirtualDisplay(big_mode_.size()); - EXPECT_EQ(GenerateDisplayID(0x8000, 0x0, 1), virtual_display_id); - EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); - EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, - configurator_.display_state()); - - // Virtual should not trigger addition of added crtc but does change FB - // height. - const int kVirtualHeight = small_mode_.size().height() + - DisplayConfigurator::kVerticalGap + - big_mode_.size().height(); - EXPECT_EQ( - JoinActions( - kGrab, GetFramebufferAction( - gfx::Size(big_mode_.size().width(), kVirtualHeight), - outputs_[0].get(), nullptr) - .c_str(), - GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), - kUngrab, nullptr), - log_->GetActionsAndClear()); - EXPECT_EQ(1, observer_.num_changes()); - ASSERT_EQ(static_cast<size_t>(2u), cached.size()); - EXPECT_EQ(small_mode_.size(), cached[0]->current_mode()->size()); - EXPECT_EQ(big_mode_.size(), cached[1]->current_mode()->size()); - EXPECT_EQ(virtual_display_id, cached[1]->display_id()); - - // Remove virtual display. - observer_.Reset(); - EXPECT_TRUE(configurator_.RemoveVirtualDisplay(virtual_display_id)); - EXPECT_EQ( - JoinActions( - kGrab, - GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr) - .c_str(), - GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), - kUngrab, nullptr), - log_->GetActionsAndClear()); - EXPECT_EQ(1, observer_.num_changes()); - ASSERT_EQ(static_cast<size_t>(1u), cached.size()); - EXPECT_EQ(small_mode_.size(), cached[0]->current_mode()->size()); - EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); -} - -TEST_F(DisplayConfiguratorTest, EnableTwoVirtualDisplays) { - InitWithSingleOutput(); - - observer_.Reset(); - const DisplayConfigurator::DisplayStateList& cached = - configurator_.cached_displays(); - ASSERT_EQ(static_cast<size_t>(1u), cached.size()); - EXPECT_EQ(small_mode_.size(), cached[0]->current_mode()->size()); - - // Add 1st virtual display. - int64_t virtual_display_id_1 = - configurator_.AddVirtualDisplay(big_mode_.size()); - EXPECT_EQ(GenerateDisplayID(0x8000, 0x0, 1), virtual_display_id_1); - EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); - EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, - configurator_.display_state()); - - // Virtual should not trigger addition of added crtc but does change FB - // height. - const int kSingleVirtualHeight = small_mode_.size().height() + - DisplayConfigurator::kVerticalGap + - big_mode_.size().height(); - EXPECT_EQ( - JoinActions( - kGrab, GetFramebufferAction( - gfx::Size(big_mode_.size().width(), kSingleVirtualHeight), - outputs_[0].get(), nullptr) - .c_str(), - GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), - kUngrab, nullptr), - log_->GetActionsAndClear()); - EXPECT_EQ(1, observer_.num_changes()); - ASSERT_EQ(static_cast<size_t>(2), cached.size()); - EXPECT_EQ(small_mode_.size(), cached[0]->current_mode()->size()); - EXPECT_EQ(big_mode_.size(), cached[1]->current_mode()->size()); - EXPECT_EQ(virtual_display_id_1, cached[1]->display_id()); - - // Add 2nd virtual display - int64_t virtual_display_id_2 = - configurator_.AddVirtualDisplay(big_mode_.size()); - EXPECT_EQ(GenerateDisplayID(0x8000, 0x0, 2), virtual_display_id_2); - EXPECT_FALSE(mirroring_controller_.SoftwareMirroringEnabled()); - EXPECT_EQ(MULTIPLE_DISPLAY_STATE_MULTI_EXTENDED, - configurator_.display_state()); - - const int kDualVirtualHeight = - small_mode_.size().height() + - (DisplayConfigurator::kVerticalGap + big_mode_.size().height()) * 2; - EXPECT_EQ( - JoinActions( - kGrab, GetFramebufferAction( - gfx::Size(big_mode_.size().width(), kDualVirtualHeight), - outputs_[0].get(), nullptr) - .c_str(), - GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), - kUngrab, nullptr), - log_->GetActionsAndClear()); - EXPECT_EQ(2, observer_.num_changes()); - ASSERT_EQ(static_cast<size_t>(3u), cached.size()); - EXPECT_EQ(small_mode_.size(), cached[0]->current_mode()->size()); - EXPECT_EQ(big_mode_.size(), cached[1]->current_mode()->size()); - EXPECT_EQ(big_mode_.size(), cached[2]->current_mode()->size()); - EXPECT_EQ(virtual_display_id_1, cached[1]->display_id()); - EXPECT_EQ(virtual_display_id_2, cached[2]->display_id()); - - // Remove 1st virtual display. - observer_.Reset(); - EXPECT_TRUE(configurator_.RemoveVirtualDisplay(virtual_display_id_1)); - EXPECT_EQ( - JoinActions( - kGrab, GetFramebufferAction( - gfx::Size(big_mode_.size().width(), kSingleVirtualHeight), - outputs_[0].get(), nullptr) - .c_str(), - GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), - kUngrab, nullptr), - log_->GetActionsAndClear()); - EXPECT_EQ(1, observer_.num_changes()); - ASSERT_EQ(static_cast<size_t>(2u), cached.size()); - EXPECT_EQ(small_mode_.size(), cached[0]->current_mode()->size()); - EXPECT_EQ(big_mode_.size(), cached[1]->current_mode()->size()); - EXPECT_EQ(virtual_display_id_2, cached[1]->display_id()); - EXPECT_EQ(MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED, - configurator_.display_state()); - - // Remove 2nd virtual display. - observer_.Reset(); - EXPECT_TRUE(configurator_.RemoveVirtualDisplay(virtual_display_id_2)); - EXPECT_EQ( - JoinActions( - kGrab, - GetFramebufferAction(small_mode_.size(), outputs_[0].get(), nullptr) - .c_str(), - GetCrtcAction(*outputs_[0], &small_mode_, gfx::Point(0, 0)).c_str(), - kUngrab, nullptr), - log_->GetActionsAndClear()); - EXPECT_EQ(1, observer_.num_changes()); - ASSERT_EQ(static_cast<size_t>(1), cached.size()); - EXPECT_EQ(small_mode_.size(), cached[0]->current_mode()->size()); - EXPECT_EQ(MULTIPLE_DISPLAY_STATE_SINGLE, configurator_.display_state()); -} - TEST_F(DisplayConfiguratorTest, ConnectSecondOutput) { InitWithSingleOutput(); diff --git a/chromium/ui/display/manager/chromeos/display_snapshot_virtual.cc b/chromium/ui/display/manager/chromeos/display_snapshot_virtual.cc deleted file mode 100644 index b3c32c9b560..00000000000 --- a/chromium/ui/display/manager/chromeos/display_snapshot_virtual.cc +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2014 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/manager/chromeos/display_snapshot_virtual.h" - -#include <inttypes.h> - -#include "base/strings/stringprintf.h" -#include "ui/display/types/display_mode.h" - -namespace display { - -namespace { - -// For a non hi-DPI display (96 dpi) use a pitch of 265µm. -static const float kVirtualDisplayPitchMM = 0.265; - -} // namespace - -DisplaySnapshotVirtual::DisplaySnapshotVirtual(int64_t display_id, - const gfx::Size& display_size) - : DisplaySnapshot(display_id, - gfx::Point(0, 0), - // Calculate physical size assuming 96dpi display. - gfx::Size(display_size.width() * kVirtualDisplayPitchMM, - display_size.height() * kVirtualDisplayPitchMM), - DISPLAY_CONNECTION_TYPE_VIRTUAL, - false, - false, - false, - "Virtual display", - base::FilePath(), - std::vector<std::unique_ptr<const DisplayMode>>(), - std::vector<uint8_t>(), // Virtual displays have no EDID. - nullptr, - nullptr) { - mode_.reset(new DisplayMode(display_size, false, 30)); - modes_.push_back(mode_->Clone()); - - native_mode_ = modes_.front().get(); -} - -DisplaySnapshotVirtual::~DisplaySnapshotVirtual() {} - -std::string DisplaySnapshotVirtual::ToString() const { - return base::StringPrintf( - "Virtual id=%" PRId64 " current_mode=%s physical_size=%s", display_id_, - current_mode_ ? current_mode_->ToString().c_str() : "nullptr", - physical_size_.ToString().c_str()); -} - -} // namespace display diff --git a/chromium/ui/display/manager/chromeos/display_snapshot_virtual.h b/chromium/ui/display/manager/chromeos/display_snapshot_virtual.h deleted file mode 100644 index 2a542fdf1b0..00000000000 --- a/chromium/ui/display/manager/chromeos/display_snapshot_virtual.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2014 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_MANAGER_CHROMEOS_DISPLAY_SNAPSHOT_VIRTUAL_H_ -#define UI_DISPLAY_MANAGER_CHROMEOS_DISPLAY_SNAPSHOT_VIRTUAL_H_ - -#include <stdint.h> - -#include <memory> - -#include "base/macros.h" -#include "ui/display/manager/display_manager_export.h" -#include "ui/display/types/display_mode.h" -#include "ui/display/types/display_snapshot.h" - -namespace display { - -// This class represents a virtual display to be enabled on demand. The display -// is constructed for the desired pixel resolution. -class DISPLAY_MANAGER_EXPORT DisplaySnapshotVirtual : public DisplaySnapshot { - public: - // |display_id| is the numerical identifier for the virtual display, - // |display_size| is the pixel dimensions for the display. - DisplaySnapshotVirtual(int64_t display_id, const gfx::Size& display_size); - ~DisplaySnapshotVirtual() override; - - // DisplaySnapshot overrides. - std::string ToString() const override; - - private: - std::unique_ptr<DisplayMode> mode_; - DISALLOW_COPY_AND_ASSIGN(DisplaySnapshotVirtual); -}; - -} // namespace display - -#endif // UI_DISPLAY_MANAGER_CHROMEOS_DISPLAY_SNAPSHOT_VIRTUAL_H_ diff --git a/chromium/ui/display/manager/chromeos/display_util.cc b/chromium/ui/display/manager/chromeos/display_util.cc index 645cd8ed923..c9f78e72e1a 100644 --- a/chromium/ui/display/manager/chromeos/display_util.cc +++ b/chromium/ui/display/manager/chromeos/display_util.cc @@ -57,7 +57,6 @@ int GetDisplayPower(const std::vector<DisplaySnapshot*>& displays, for (size_t i = 0; i < displays.size(); ++i) { bool internal = displays[i]->type() == DISPLAY_CONNECTION_TYPE_INTERNAL; bool on = - displays[i]->type() == DISPLAY_CONNECTION_TYPE_VIRTUAL || state == chromeos::DISPLAY_POWER_ALL_ON || (state == chromeos::DISPLAY_POWER_INTERNAL_OFF_EXTERNAL_ON && !internal) || @@ -71,8 +70,7 @@ int GetDisplayPower(const std::vector<DisplaySnapshot*>& displays, } bool IsPhysicalDisplayType(DisplayConnectionType type) { - return !(type & - (DISPLAY_CONNECTION_TYPE_NETWORK | DISPLAY_CONNECTION_TYPE_VIRTUAL)); + return !(type & DISPLAY_CONNECTION_TYPE_NETWORK); } } // namespace display diff --git a/chromium/ui/display/manager/chromeos/display_util.h b/chromium/ui/display/manager/chromeos/display_util.h index 1e3043da4a9..3da69e16416 100644 --- a/chromium/ui/display/manager/chromeos/display_util.h +++ b/chromium/ui/display/manager/chromeos/display_util.h @@ -31,8 +31,8 @@ GetDisplayPower(const std::vector<DisplaySnapshot*>& displays, std::vector<bool>* display_power); // Returns whether the DisplayConnectionType |type| is a physically connected -// display. Currently DISPLAY_CONNECTION_TYPE_VIRTUAL and -// DISPLAY_CONNECTION_TYPE_NETWORK return false. All other types return true. +// display. Currently only DISPLAY_CONNECTION_TYPE_NETWORK return false. +// All other types return true. bool IsPhysicalDisplayType(DisplayConnectionType type); } // namespace display diff --git a/chromium/ui/display/manager/chromeos/query_content_protection_task.cc b/chromium/ui/display/manager/chromeos/query_content_protection_task.cc index 812f83549d8..d454970d740 100644 --- a/chromium/ui/display/manager/chromeos/query_content_protection_task.cc +++ b/chromium/ui/display/manager/chromeos/query_content_protection_task.cc @@ -45,7 +45,6 @@ void QueryContentProtectionTask::Run() { case DISPLAY_CONNECTION_TYPE_INTERNAL: case DISPLAY_CONNECTION_TYPE_VGA: case DISPLAY_CONNECTION_TYPE_NETWORK: - case DISPLAY_CONNECTION_TYPE_VIRTUAL: // No protections for these types. Do nothing. break; case DISPLAY_CONNECTION_TYPE_NONE: diff --git a/chromium/ui/display/manager/chromeos/update_display_configuration_task.cc b/chromium/ui/display/manager/chromeos/update_display_configuration_task.cc index 7ba78c2a325..581c7c624a8 100644 --- a/chromium/ui/display/manager/chromeos/update_display_configuration_task.cc +++ b/chromium/ui/display/manager/chromeos/update_display_configuration_task.cc @@ -4,8 +4,6 @@ #include "ui/display/manager/chromeos/update_display_configuration_task.h" -#include <algorithm> - #include "ui/display/manager/chromeos/configure_displays_task.h" #include "ui/display/manager/chromeos/display_layout_manager.h" #include "ui/display/manager/chromeos/display_util.h" @@ -32,36 +30,40 @@ UpdateDisplayConfigurationTask::UpdateDisplayConfigurationTask( force_configure_(force_configure), callback_(callback), force_dpms_(false), + requesting_displays_(false), weak_ptr_factory_(this) { delegate_->GrabServer(); + delegate_->AddObserver(this); } UpdateDisplayConfigurationTask::~UpdateDisplayConfigurationTask() { + delegate_->RemoveObserver(this); delegate_->UngrabServer(); } void UpdateDisplayConfigurationTask::Run() { + requesting_displays_ = true; delegate_->GetDisplays( base::Bind(&UpdateDisplayConfigurationTask::OnDisplaysUpdated, weak_ptr_factory_.GetWeakPtr())); } -void UpdateDisplayConfigurationTask::SetVirtualDisplaySnapshots( - const std::vector<std::unique_ptr<DisplaySnapshot>>& snapshots) { - virtual_display_snapshots_.resize(snapshots.size()); - std::transform( - snapshots.cbegin(), snapshots.cend(), virtual_display_snapshots_.begin(), - [](const std::unique_ptr<DisplaySnapshot>& item) { return item.get(); }); +void UpdateDisplayConfigurationTask::OnConfigurationChanged() {} + +void UpdateDisplayConfigurationTask::OnDisplaySnapshotsInvalidated() { + cached_displays_.clear(); + if (!requesting_displays_ && weak_ptr_factory_.HasWeakPtrs()) { + // This task has already been run and getting the displays request is not in + // flight. We need to re-run it to get updated displays snapshots. + weak_ptr_factory_.InvalidateWeakPtrs(); + Run(); + } } void UpdateDisplayConfigurationTask::OnDisplaysUpdated( const std::vector<DisplaySnapshot*>& displays) { cached_displays_ = displays; - - // Add virtual displays after retrieving the physical displays from the NDD. - cached_displays_.insert(cached_displays_.end(), - virtual_display_snapshots_.begin(), - virtual_display_snapshots_.end()); + requesting_displays_ = false; if (cached_displays_.size() > 1 && background_color_argb_) delegate_->SetBackgroundColor(background_color_argb_); diff --git a/chromium/ui/display/manager/chromeos/update_display_configuration_task.h b/chromium/ui/display/manager/chromeos/update_display_configuration_task.h index 270dc8fec0a..e76ba8cdf79 100644 --- a/chromium/ui/display/manager/chromeos/update_display_configuration_task.h +++ b/chromium/ui/display/manager/chromeos/update_display_configuration_task.h @@ -14,13 +14,15 @@ #include "base/memory/weak_ptr.h" #include "ui/display/manager/chromeos/configure_displays_task.h" #include "ui/display/manager/chromeos/display_configurator.h" +#include "ui/display/types/native_display_observer.h" namespace display { class DisplaySnapshot; class NativeDisplayDelegate; -class DISPLAY_MANAGER_EXPORT UpdateDisplayConfigurationTask { +class DISPLAY_MANAGER_EXPORT UpdateDisplayConfigurationTask + : public NativeDisplayObserver { public: typedef base::Callback<void( bool /* success */, @@ -38,15 +40,14 @@ class DISPLAY_MANAGER_EXPORT UpdateDisplayConfigurationTask { uint32_t background_color_argb, bool force_configure, const ResponseCallback& callback); - ~UpdateDisplayConfigurationTask(); - - // The pointers to the DisplaySnapshots in this vector are owned by - // DisplayConfigurator. - void SetVirtualDisplaySnapshots( - const std::vector<std::unique_ptr<DisplaySnapshot>>& snapshots); + ~UpdateDisplayConfigurationTask() override; void Run(); + // display::NativeDisplayObserver: + void OnConfigurationChanged() override; + void OnDisplaySnapshotsInvalidated() override; + private: // Callback to NativeDisplayDelegate::GetDisplays(). void OnDisplaysUpdated(const std::vector<DisplaySnapshot*>& displays); @@ -99,12 +100,11 @@ class DISPLAY_MANAGER_EXPORT UpdateDisplayConfigurationTask { bool force_dpms_; + bool requesting_displays_; + // List of updated displays. std::vector<DisplaySnapshot*> cached_displays_; - // Vector of unowned VirtualDisplaySnapshots to be added when doing the task. - std::vector<DisplaySnapshot*> virtual_display_snapshots_; - gfx::Size framebuffer_size_; std::unique_ptr<ConfigureDisplaysTask> configure_task_; diff --git a/chromium/ui/display/manager/display_manager.cc b/chromium/ui/display/manager/display_manager.cc index 68b7abf0427..0a7bd1363d2 100644 --- a/chromium/ui/display/manager/display_manager.cc +++ b/chromium/ui/display/manager/display_manager.cc @@ -27,6 +27,7 @@ #include "base/threading/thread_task_runner_handle.h" #include "ui/base/l10n/l10n_util.h" #include "ui/display/display.h" +#include "ui/display/display_finder.h" #include "ui/display/display_observer.h" #include "ui/display/display_switches.h" #include "ui/display/manager/display_layout_store.h" @@ -264,16 +265,21 @@ void DisplayManager::SetLayoutForCurrentDisplays( delegate_->PostDisplayConfigurationChange(false); } -const Display& DisplayManager::GetDisplayForId(int64_t id) const { - Display* display = const_cast<DisplayManager*>(this)->FindDisplayForId(id); +const Display& DisplayManager::GetDisplayForId(int64_t display_id) const { + Display* display = + const_cast<DisplayManager*>(this)->FindDisplayForId(display_id); return display ? *display : GetInvalidDisplay(); } +bool DisplayManager::IsDisplayIdValid(int64_t display_id) const { + return GetDisplayForId(display_id).is_valid(); +} + const Display& DisplayManager::FindDisplayContainingPoint( const gfx::Point& point_in_screen) const { - int index = - FindDisplayIndexContainingPoint(active_display_list_, point_in_screen); - return index < 0 ? GetInvalidDisplay() : active_display_list_[index]; + auto iter = display::FindDisplayContainingPoint(active_display_list_, + point_in_screen); + return iter == active_display_list_.end() ? GetInvalidDisplay() : *iter; } bool DisplayManager::UpdateWorkAreaOfDisplay(int64_t display_id, @@ -371,27 +377,37 @@ bool DisplayManager::SetDisplayMode( display_property_changed = true; } else { display_modes_[display_id] = *iter; - if (info.bounds_in_native().size() != display_mode->size()) + if (info.bounds_in_native().size() != display_mode->size()) { + // If resolution changes, then we can break right here. No need to + // continue to fill |display_info_list|, since we won't be + // synchronously updating the displays here. resolution_changed = true; + break; + } if (info.device_scale_factor() != display_mode->device_scale_factor()) { info.set_device_scale_factor(display_mode->device_scale_factor()); display_property_changed = true; } } } - display_info_list.push_back(info); + display_info_list.emplace_back(info); } - if (display_property_changed) { + + if (display_property_changed && !resolution_changed) { + // We shouldn't synchronously update the displays here if the resolution + // changed. This should happen asynchronously when configuration is + // triggered. AddMirrorDisplayInfoIfAny(&display_info_list); UpdateDisplaysWith(display_info_list); } - if (resolution_changed && IsInUnifiedMode()) { + + if (resolution_changed && IsInUnifiedMode()) ReconfigureDisplays(); #if defined(OS_CHROMEOS) - } else if (resolution_changed && configure_displays_) { + else if (resolution_changed && configure_displays_) delegate_->display_configurator()->OnConfigurationChanged(); -#endif - } +#endif // defined(OS_CHROMEOS) + return resolution_changed || display_property_changed; } @@ -481,6 +497,21 @@ scoped_refptr<ManagedDisplayMode> DisplayManager::GetSelectedModeForDisplayId( return iter->second; } +void DisplayManager::SetSelectedModeForDisplayId( + int64_t display_id, + const scoped_refptr<ManagedDisplayMode>& display_mode) { + ManagedDisplayInfo info = GetDisplayInfo(display_id); + auto iter = FindDisplayMode(info, display_mode); + if (iter == info.display_modes().end()) { + LOG(WARNING) << "Unsupported display mode was requested:" + << "size=" << display_mode->size().ToString() + << ", ui scale=" << display_mode->ui_scale() + << ", scale factor=" << display_mode->device_scale_factor(); + } + + display_modes_[display_id] = *iter; +} + bool DisplayManager::IsDisplayUIScalingEnabled() const { return GetDisplayIdForUIScaling() != kInvalidDisplayId; } @@ -816,23 +847,32 @@ void DisplayManager::UpdateDisplaysWith( NotifyMetricsChanged(updated_display, metrics); } + uint32_t primary_metrics = 0; + if (notify_primary_change) { // This happens when a primary display has moved to anther display without // bounds change. const Display& primary = screen_->GetPrimaryDisplay(); if (primary.id() != old_primary.id()) { - uint32_t metrics = DisplayObserver::DISPLAY_METRIC_PRIMARY; + primary_metrics = DisplayObserver::DISPLAY_METRIC_PRIMARY; if (primary.size() != old_primary.size()) { - metrics |= (DisplayObserver::DISPLAY_METRIC_BOUNDS | - DisplayObserver::DISPLAY_METRIC_WORK_AREA); + primary_metrics |= (DisplayObserver::DISPLAY_METRIC_BOUNDS | + DisplayObserver::DISPLAY_METRIC_WORK_AREA); } if (primary.device_scale_factor() != old_primary.device_scale_factor()) - metrics |= DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; - - NotifyMetricsChanged(primary, metrics); + primary_metrics |= DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; } } + bool mirror_mode = IsInMirrorMode(); + if (mirror_mode != mirror_mode_for_metrics_) { + primary_metrics |= DisplayObserver::DISPLAY_METRIC_MIRROR_STATE; + mirror_mode_for_metrics_ = mirror_mode; + } + + if (delegate_ && primary_metrics) + NotifyMetricsChanged(screen_->GetPrimaryDisplay(), primary_metrics); + bool must_clear_window = false; #if defined(USE_X11) && defined(OS_CHROMEOS) must_clear_window = diff --git a/chromium/ui/display/manager/display_manager.h b/chromium/ui/display/manager/display_manager.h index c6644029c60..9de768fcc5f 100644 --- a/chromium/ui/display/manager/display_manager.h +++ b/chromium/ui/display/manager/display_manager.h @@ -138,8 +138,11 @@ class DISPLAY_MANAGER_EXPORT DisplayManager // locaion of the displays relative to their parents. void SetLayoutForCurrentDisplays(std::unique_ptr<DisplayLayout> layout); - // Returns display for given |id|; - const Display& GetDisplayForId(int64_t id) const; + // Returns display for given |display_id|. + const Display& GetDisplayForId(int64_t display_id) const; + + // Checks the validity of given |display_id|. + bool IsDisplayIdValid(int64_t display_id) const; // Finds the display that contains |point| in screeen coordinates. Returns // invalid display if there is no display that can satisfy the condition. @@ -205,11 +208,18 @@ class DISPLAY_MANAGER_EXPORT DisplayManager scoped_refptr<ManagedDisplayMode> GetActiveModeForDisplayId( int64_t display_id) const; - // Returns the display's selected mode. This returns false and doesn't set - // |mode_out| if the display mode is in default. + // Returns the display's selected mode. scoped_refptr<ManagedDisplayMode> GetSelectedModeForDisplayId( int64_t display_id) const; + // Sets the selected mode of |display_id| to |display_mode| if it's a + // supported mode. This doesn't trigger reconfiguration or observers + // notifications. This is suitable to be used from within an observer + // notification to prevent reentrance to UpdateDisplaysWith(). + void SetSelectedModeForDisplayId( + int64_t display_id, + const scoped_refptr<ManagedDisplayMode>& display_mode); + // Tells if the virtual resolution feature is enabled. bool IsDisplayUIScalingEnabled() const; @@ -468,6 +478,9 @@ class DISPLAY_MANAGER_EXPORT DisplayManager int64_t mirroring_display_id_ = kInvalidDisplayId; Displays software_mirroring_display_list_; + // Cached mirror mode for metrics changed notification. + bool mirror_mode_for_metrics_ = false; + // User preference for rotation lock of the internal display. bool registered_internal_display_rotation_lock_ = false; diff --git a/chromium/ui/display/manager/display_manager_utilities.cc b/chromium/ui/display/manager/display_manager_utilities.cc index 5ec37b409a2..af1c42d5bcb 100644 --- a/chromium/ui/display/manager/display_manager_utilities.cc +++ b/chromium/ui/display/manager/display_manager_utilities.cc @@ -266,15 +266,6 @@ bool ComputeBoundary(const Display& a_display, return true; } -int FindDisplayIndexContainingPoint(const std::vector<Display>& displays, - const gfx::Point& point_in_screen) { - auto iter = std::find_if(displays.begin(), displays.end(), - [point_in_screen](const Display& display) { - return display.bounds().Contains(point_in_screen); - }); - return iter == displays.end() ? -1 : (iter - displays.begin()); -} - DisplayIdList CreateDisplayIdList(const Displays& list) { return GenerateDisplayIdList( list.begin(), list.end(), diff --git a/chromium/ui/display/manager/display_manager_utilities.h b/chromium/ui/display/manager/display_manager_utilities.h index ca00405531e..77f413b0266 100644 --- a/chromium/ui/display/manager/display_manager_utilities.h +++ b/chromium/ui/display/manager/display_manager_utilities.h @@ -13,7 +13,6 @@ #include "ui/display/manager/managed_display_info.h" namespace gfx { -class Point; class Rect; class Size; } @@ -62,12 +61,6 @@ DISPLAY_MANAGER_EXPORT bool ComputeBoundary( gfx::Rect* primary_edge_in_screen, gfx::Rect* secondary_edge_in_screen); -// Returns the index in the displays whose bounds contains |point_in_screen|. -// Returns -1 if no such display exist. -DISPLAY_MANAGER_EXPORT int FindDisplayIndexContainingPoint( - const std::vector<Display>& displays, - const gfx::Point& point_in_screen); - // Sorts id list using |CompareDisplayIds| below. DISPLAY_MANAGER_EXPORT void SortDisplayIdList(DisplayIdList* list); diff --git a/chromium/ui/display/manager/display_pref_util.h b/chromium/ui/display/manager/display_pref_util.h new file mode 100644 index 00000000000..dea15cface2 --- /dev/null +++ b/chromium/ui/display/manager/display_pref_util.h @@ -0,0 +1,64 @@ +// Copyright (c) 2013 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_MANAGER_DISPLAY_PREF_UTIL_H +#define UI_DISPLAY_MANAGER_DISPLAY_PREF_UTIL_H + +#include <map> +#include <string> + +#include "base/strings/string_piece.h" + +namespace display { + +// Utility templates to create enum to string map and +// a function to find an enum value from a string. +template <typename T> +std::map<T, std::string>* CreateToStringMap(T k1, + const std::string& v1, + T k2, + const std::string& v2, + T k3, + const std::string& v3, + T k4, + const std::string& v4) { + std::map<T, std::string>* map = new std::map<T, std::string>(); + (*map)[k1] = v1; + (*map)[k2] = v2; + (*map)[k3] = v3; + (*map)[k4] = v4; + return map; +} + +template <typename T> +std::map<T, std::string>* CreateToStringMap(T k1, + const std::string& v1, + T k2, + const std::string& v2, + T k3, + const std::string& v3) { + std::map<T, std::string>* map = new std::map<T, std::string>(); + (*map)[k1] = v1; + (*map)[k2] = v2; + (*map)[k3] = v3; + return map; +} + +template <typename T> +bool ReverseFind(const std::map<T, std::string>* map, + const base::StringPiece& value, + T* key) { + typename std::map<T, std::string>::const_iterator iter = map->begin(); + for (; iter != map->end(); ++iter) { + if (iter->second == value) { + *key = iter->first; + return true; + } + } + return false; +} + +} // namespace display + +#endif // UI_DISPLAY_MANAGER_DISPLAY_PREF_UTIL_H diff --git a/chromium/ui/display/manager/forwarding_display_delegate.cc b/chromium/ui/display/manager/forwarding_display_delegate.cc new file mode 100644 index 00000000000..0a0813da8ca --- /dev/null +++ b/chromium/ui/display/manager/forwarding_display_delegate.cc @@ -0,0 +1,132 @@ +// 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. + +#include "ui/display/manager/forwarding_display_delegate.h" + +#include <utility> + +#include "base/bind.h" +#include "ui/display/types/display_snapshot_mojo.h" + +namespace display { + +ForwardingDisplayDelegate::ForwardingDisplayDelegate( + mojom::NativeDisplayDelegatePtr delegate) + : delegate_(std::move(delegate)), binding_(this) {} + +ForwardingDisplayDelegate::~ForwardingDisplayDelegate() {} + +void ForwardingDisplayDelegate::Initialize() { + delegate_->Initialize(binding_.CreateInterfacePtrAndBind()); +} + +void ForwardingDisplayDelegate::GrabServer() {} + +void ForwardingDisplayDelegate::UngrabServer() {} + +void ForwardingDisplayDelegate::TakeDisplayControl( + const DisplayControlCallback& callback) { + delegate_->TakeDisplayControl(callback); +} + +void ForwardingDisplayDelegate::RelinquishDisplayControl( + const DisplayControlCallback& callback) { + delegate_->TakeDisplayControl(callback); +} + +void ForwardingDisplayDelegate::SyncWithServer() {} + +void ForwardingDisplayDelegate::SetBackgroundColor(uint32_t color_argb) {} + +void ForwardingDisplayDelegate::ForceDPMSOn() {} + +void ForwardingDisplayDelegate::GetDisplays( + const GetDisplaysCallback& callback) { + delegate_->GetDisplays( + base::Bind(&ForwardingDisplayDelegate::StoreAndForwardDisplays, + base::Unretained(this), callback)); +} + +void ForwardingDisplayDelegate::AddMode(const DisplaySnapshot& snapshot, + const DisplayMode* mode) {} + +void ForwardingDisplayDelegate::Configure(const DisplaySnapshot& snapshot, + const DisplayMode* mode, + const gfx::Point& origin, + const ConfigureCallback& callback) { + delegate_->Configure(snapshot.display_id(), mode->Clone(), origin, callback); +} + +void ForwardingDisplayDelegate::CreateFrameBuffer(const gfx::Size& size) {} + +void ForwardingDisplayDelegate::GetHDCPState( + const DisplaySnapshot& snapshot, + const GetHDCPStateCallback& callback) { + delegate_->GetHDCPState(snapshot.display_id(), callback); +} + +void ForwardingDisplayDelegate::SetHDCPState( + const DisplaySnapshot& snapshot, + HDCPState state, + const SetHDCPStateCallback& callback) { + delegate_->SetHDCPState(snapshot.display_id(), state, callback); +} + +std::vector<ColorCalibrationProfile> +ForwardingDisplayDelegate::GetAvailableColorCalibrationProfiles( + const DisplaySnapshot& output) { + return std::vector<ColorCalibrationProfile>(); +} + +bool ForwardingDisplayDelegate::SetColorCalibrationProfile( + const DisplaySnapshot& output, + ColorCalibrationProfile new_profile) { + return false; +} + +bool ForwardingDisplayDelegate::SetColorCorrection( + const DisplaySnapshot& output, + const std::vector<GammaRampRGBEntry>& degamma_lut, + const std::vector<GammaRampRGBEntry>& gamma_lut, + const std::vector<float>& correction_matrix) { + delegate_->SetColorCorrection(output.display_id(), degamma_lut, gamma_lut, + correction_matrix); + // DrmNativeDisplayDelegate always returns true so this will too. + return true; +} + +void ForwardingDisplayDelegate::AddObserver( + display::NativeDisplayObserver* observer) { + observers_.AddObserver(observer); +} + +void ForwardingDisplayDelegate::RemoveObserver( + display::NativeDisplayObserver* observer) { + observers_.RemoveObserver(observer); +} + +FakeDisplayController* ForwardingDisplayDelegate::GetFakeDisplayController() { + return nullptr; +} + +void ForwardingDisplayDelegate::OnConfigurationChanged() { + // Forward OnConfigurationChanged received over Mojo to local observers. + for (auto& observer : observers_) + observer.OnConfigurationChanged(); +} + +void ForwardingDisplayDelegate::StoreAndForwardDisplays( + const GetDisplaysCallback& callback, + std::vector<std::unique_ptr<DisplaySnapshotMojo>> snapshots) { + for (auto& observer : observers_) + observer.OnDisplaySnapshotsInvalidated(); + snapshots_ = std::move(snapshots); + + std::vector<DisplaySnapshot*> snapshot_ptrs; + for (auto& snapshot : snapshots_) + snapshot_ptrs.push_back(snapshot.get()); + callback.Run(snapshot_ptrs); +} + +} // namespace display diff --git a/chromium/ui/display/manager/forwarding_display_delegate.h b/chromium/ui/display/manager/forwarding_display_delegate.h new file mode 100644 index 00000000000..4e548754d7c --- /dev/null +++ b/chromium/ui/display/manager/forwarding_display_delegate.h @@ -0,0 +1,91 @@ +// 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. + +#ifndef UI_DISPLAY_MANAGER_FORWARDING_DISPLAY_DELEGATE_H_ +#define UI_DISPLAY_MANAGER_FORWARDING_DISPLAY_DELEGATE_H_ + +#include <memory> +#include <vector> + +#include "base/compiler_specific.h" +#include "base/macros.h" +#include "base/observer_list.h" +#include "mojo/public/cpp/bindings/binding.h" +#include "ui/display/manager/display_manager_export.h" +#include "ui/display/mojo/native_display_delegate.mojom.h" +#include "ui/display/types/native_display_delegate.h" +#include "ui/display/types/native_display_observer.h" + +namespace display { + +class DisplaySnapshotMojo; + +// NativeDisplayDelegate implementation that forwards calls to a real +// NativeDisplayDelegate in another process. Only forwards the methods +// implemented by Ozone DRM, other method won't do anything. +class DISPLAY_MANAGER_EXPORT ForwardingDisplayDelegate + : public NativeDisplayDelegate, + public NON_EXPORTED_BASE(mojom::NativeDisplayObserver) { + public: + explicit ForwardingDisplayDelegate(mojom::NativeDisplayDelegatePtr delegate); + ~ForwardingDisplayDelegate() override; + + // display::NativeDisplayDelegate: + void Initialize() override; + void GrabServer() override; + void UngrabServer() override; + void TakeDisplayControl(const DisplayControlCallback& callback) override; + void RelinquishDisplayControl( + const DisplayControlCallback& callback) override; + void SyncWithServer() override; + void SetBackgroundColor(uint32_t color_argb) override; + void ForceDPMSOn() override; + void GetDisplays(const GetDisplaysCallback& callback) override; + void AddMode(const DisplaySnapshot& output, const DisplayMode* mode) override; + void Configure(const DisplaySnapshot& output, + const DisplayMode* mode, + const gfx::Point& origin, + const ConfigureCallback& callback) override; + void CreateFrameBuffer(const gfx::Size& size) override; + void GetHDCPState(const DisplaySnapshot& output, + const GetHDCPStateCallback& callback) override; + void SetHDCPState(const DisplaySnapshot& output, + HDCPState state, + const SetHDCPStateCallback& callback) override; + std::vector<ColorCalibrationProfile> GetAvailableColorCalibrationProfiles( + const DisplaySnapshot& output) override; + bool SetColorCalibrationProfile(const DisplaySnapshot& output, + ColorCalibrationProfile new_profile) override; + bool SetColorCorrection(const DisplaySnapshot& output, + const std::vector<GammaRampRGBEntry>& degamma_lut, + const std::vector<GammaRampRGBEntry>& gamma_lut, + const std::vector<float>& correction_matrix) override; + void AddObserver(display::NativeDisplayObserver* observer) override; + void RemoveObserver(display::NativeDisplayObserver* observer) override; + FakeDisplayController* GetFakeDisplayController() override; + + // display::mojom::NativeDisplayObserver: + void OnConfigurationChanged() override; + + private: + // Stores display snapshots and forards them to |callback|. + void StoreAndForwardDisplays( + const GetDisplaysCallback& callback, + std::vector<std::unique_ptr<DisplaySnapshotMojo>> snapshots); + + mojom::NativeDisplayDelegatePtr delegate_; + mojo::Binding<mojom::NativeDisplayObserver> binding_; + + // Display snapshots are owned here but accessed via raw pointers elsewhere. + // Call OnDisplaySnapshotsInvalidated() on observers before invalidating them. + std::vector<std::unique_ptr<DisplaySnapshotMojo>> snapshots_; + + base::ObserverList<display::NativeDisplayObserver> observers_; + + DISALLOW_COPY_AND_ASSIGN(ForwardingDisplayDelegate); +}; + +} // namespace display + +#endif // UI_DISPLAY_MANAGER_FORWARDING_DISPLAY_DELEGATE_H_ diff --git a/chromium/ui/display/manager/json_converter.cc b/chromium/ui/display/manager/json_converter.cc new file mode 100644 index 00000000000..2520d1d6838 --- /dev/null +++ b/chromium/ui/display/manager/json_converter.cc @@ -0,0 +1,197 @@ +// 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. + +#include "ui/display/manager/json_converter.h" + +#include <memory> +#include <string> + +#include "base/logging.h" +#include "base/strings/string_number_conversions.h" +#include "base/values.h" +#include "ui/display/display_layout.h" +#include "ui/display/manager/display_pref_util.h" + +namespace display { + +namespace { + +// Persistent key names +const char kMirroredKey[] = "mirrored"; +const char kDefaultUnifiedKey[] = "default_unified"; +const char kPrimaryIdKey[] = "primary-id"; +const char kDisplayPlacementKey[] = "display_placement"; + +// DisplayPlacement key names +const char kPositionKey[] = "position"; +const char kOffsetKey[] = "offset"; +const char kDisplayPlacementDisplayIdKey[] = "display_id"; +const char kDisplayPlacementParentDisplayIdKey[] = "parent_display_id"; + +bool AddLegacyValuesFromValue(const base::Value& value, DisplayLayout* layout) { + const base::DictionaryValue* dict_value = nullptr; + if (!value.GetAsDictionary(&dict_value)) + return false; + int offset; + if (dict_value->GetInteger(kOffsetKey, &offset)) { + DisplayPlacement::Position position; + std::string position_str; + if (!dict_value->GetString(kPositionKey, &position_str)) + return false; + DisplayPlacement::StringToPosition(position_str, &position); + layout->placement_list.emplace_back(position, offset); + } + return true; +} + +// Returns true if +// The key is missing - output is left unchanged +// The key matches the type - output is updated to the value. +template <typename Getter, typename Output> +bool UpdateFromDict(const base::DictionaryValue* dict_value, + const std::string& field_name, + Getter getter, + Output* output) { + const base::Value* field = nullptr; + if (!dict_value->Get(field_name, &field)) { + LOG(WARNING) << "Missing field: " << field_name; + return true; + } + + return (field->*getter)(output); +} + +// No implementation here as specialization is required. +template <typename Output> +bool UpdateFromDict(const base::DictionaryValue* dict_value, + const std::string& field_name, + Output* output); + +template <> +bool UpdateFromDict(const base::DictionaryValue* dict_value, + const std::string& field_name, + bool* output) { + return UpdateFromDict(dict_value, field_name, &base::Value::GetAsBoolean, + output); +} + +template <> +bool UpdateFromDict(const base::DictionaryValue* dict_value, + const std::string& field_name, + int* output) { + return UpdateFromDict(dict_value, field_name, &base::Value::GetAsInteger, + output); +} + +template <> +bool UpdateFromDict(const base::DictionaryValue* dict_value, + const std::string& field_name, + DisplayPlacement::Position* output) { + bool (base::Value::*getter)(std::string*) const = &base::Value::GetAsString; + std::string value; + if (!UpdateFromDict(dict_value, field_name, getter, &value)) + return false; + + return value.empty() ? true + : DisplayPlacement::StringToPosition(value, output); +} + +template <> +bool UpdateFromDict(const base::DictionaryValue* dict_value, + const std::string& field_name, + int64_t* output) { + bool (base::Value::*getter)(std::string*) const = &base::Value::GetAsString; + std::string value; + if (!UpdateFromDict(dict_value, field_name, getter, &value)) + return false; + + return value.empty() ? true : base::StringToInt64(value, output); +} + +template <> +bool UpdateFromDict(const base::DictionaryValue* dict_value, + const std::string& field_name, + std::vector<DisplayPlacement>* output) { + bool (base::Value::*getter)(const base::ListValue**) const = + &base::Value::GetAsList; + const base::ListValue* list = nullptr; + if (!UpdateFromDict(dict_value, field_name, getter, &list)) + return false; + + if (list == nullptr) + return true; + + output->reserve(list->GetSize()); + for (const auto& list_item : *list) { + const base::DictionaryValue* item_values = nullptr; + if (!list_item.GetAsDictionary(&item_values)) + return false; + + DisplayPlacement item; + if (!UpdateFromDict(item_values, kOffsetKey, &item.offset) || + !UpdateFromDict(item_values, kPositionKey, &item.position) || + !UpdateFromDict(item_values, kDisplayPlacementDisplayIdKey, + &item.display_id) || + !UpdateFromDict(item_values, kDisplayPlacementParentDisplayIdKey, + &item.parent_display_id)) { + return false; + } + + output->push_back(item); + } + return true; +} + +} // namespace + +bool JsonToDisplayLayout(const base::Value& value, DisplayLayout* layout) { + layout->placement_list.clear(); + const base::DictionaryValue* dict_value = nullptr; + if (!value.GetAsDictionary(&dict_value)) + return false; + + if (!UpdateFromDict(dict_value, kMirroredKey, &layout->mirrored) || + !UpdateFromDict(dict_value, kDefaultUnifiedKey, + &layout->default_unified) || + !UpdateFromDict(dict_value, kPrimaryIdKey, &layout->primary_id)) { + return false; + } + + UpdateFromDict(dict_value, kDisplayPlacementKey, &layout->placement_list); + + if (layout->placement_list.size() != 0u) + return true; + + // For compatibility with old format. + return AddLegacyValuesFromValue(value, layout); +} + +bool DisplayLayoutToJson(const DisplayLayout& layout, base::Value* value) { + base::DictionaryValue* dict_value = nullptr; + if (!value->GetAsDictionary(&dict_value)) + return false; + + dict_value->SetBoolean(kMirroredKey, layout.mirrored); + dict_value->SetBoolean(kDefaultUnifiedKey, layout.default_unified); + dict_value->SetString(kPrimaryIdKey, base::Int64ToString(layout.primary_id)); + + std::unique_ptr<base::ListValue> placement_list(new base::ListValue); + for (const auto& placement : layout.placement_list) { + std::unique_ptr<base::DictionaryValue> placement_value( + new base::DictionaryValue); + placement_value->SetString( + kPositionKey, DisplayPlacement::PositionToString(placement.position)); + placement_value->SetInteger(kOffsetKey, placement.offset); + placement_value->SetString(kDisplayPlacementDisplayIdKey, + base::Int64ToString(placement.display_id)); + placement_value->SetString( + kDisplayPlacementParentDisplayIdKey, + base::Int64ToString(placement.parent_display_id)); + placement_list->Append(std::move(placement_value)); + } + dict_value->Set(kDisplayPlacementKey, std::move(placement_list)); + return true; +} + +} // namespace display diff --git a/chromium/ui/display/manager/json_converter.h b/chromium/ui/display/manager/json_converter.h new file mode 100644 index 00000000000..5082e761c01 --- /dev/null +++ b/chromium/ui/display/manager/json_converter.h @@ -0,0 +1,25 @@ +// 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. + +#ifndef UI_DISPLAY_MANAGER_JSON_CONVERTER_H_ +#define UI_DISPLAY_MANAGER_JSON_CONVERTER_H_ + +#include "ui/display/manager/display_manager_export.h" + +namespace base { +class Value; +} + +namespace display { +class DisplayLayout; + +DISPLAY_MANAGER_EXPORT bool JsonToDisplayLayout(const base::Value& value, + DisplayLayout* layout); + +DISPLAY_MANAGER_EXPORT bool DisplayLayoutToJson(const DisplayLayout& layout, + base::Value* value); + +} // namespace display + +#endif // UI_DISPLAY_MANAGER_JSON_CONVERTER_H_ diff --git a/chromium/ui/display/manager/json_converter_unittest.cc b/chromium/ui/display/manager/json_converter_unittest.cc new file mode 100644 index 00000000000..ec30d5177bc --- /dev/null +++ b/chromium/ui/display/manager/json_converter_unittest.cc @@ -0,0 +1,94 @@ +// 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. + +#include "ui/display/manager/json_converter.h" + +#include <memory> + +#include "base/json/json_reader.h" +#include "base/values.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/display/display_layout.h" + +namespace display { + +TEST(JsonConverterTest, JsonFromToDisplayLayout) { + DisplayLayout layout; + layout.primary_id = 1; + layout.mirrored = true; + layout.default_unified = false; + layout.placement_list.push_back(DisplayPlacement()); + layout.placement_list.push_back(DisplayPlacement()); + layout.placement_list[0].display_id = 2; + layout.placement_list[0].parent_display_id = 1; + layout.placement_list[0].position = DisplayPlacement::BOTTOM; + + layout.placement_list[1].display_id = 3; + layout.placement_list[1].parent_display_id = 2; + layout.placement_list[1].position = DisplayPlacement::LEFT; + layout.placement_list[1].offset = 30; + + base::DictionaryValue value; + DisplayLayoutToJson(layout, &value); + + const char data[] = + "{\n" + " \"primary-id\": \"1\",\n" + " \"mirrored\": true,\n" + " \"default_unified\": false,\n" + " \"display_placement\": [{\n" + " \"display_id\": \"2\",\n" + " \"parent_display_id\": \"1\",\n" + " \"position\": \"bottom\",\n" + " \"offset\": 0\n" + " },{\n" + " \"display_id\": \"3\",\n" + " \"parent_display_id\": \"2\",\n" + " \"position\": \"left\",\n" + " \"offset\": 30\n" + " }]\n" + "}"; + int error_code = 0, error_line, error_column; + std::string error_msg; + std::unique_ptr<base::Value> read_value(base::JSONReader::ReadAndReturnError( + data, 0, &error_code, &error_msg, &error_line, &error_column)); + ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":" + << error_column; + EXPECT_TRUE(value.Equals(read_value.get())); + + DisplayLayout read_layout; + EXPECT_TRUE(JsonToDisplayLayout(*read_value, &read_layout)); + EXPECT_EQ(read_layout.mirrored, layout.mirrored); + EXPECT_EQ(read_layout.primary_id, layout.primary_id); + EXPECT_EQ(read_layout.default_unified, layout.default_unified); + EXPECT_TRUE(read_layout.HasSamePlacementList(layout)); +} + +TEST(JsonConverterTest, OldJsonToDisplayLayout) { + const char data[] = + "{\n" + " \"primary-id\": \"1\",\n" + " \"mirrored\": true,\n" + " \"default_unified\": false,\n" + " \"position\": \"bottom\",\n" + " \"offset\": 20\n" + "}"; + int error_code = 0, error_line, error_column; + std::string error_msg; + std::unique_ptr<base::Value> read_value(base::JSONReader::ReadAndReturnError( + data, 0, &error_code, &error_msg, &error_line, &error_column)); + ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":" + << error_column; + + DisplayLayout read_layout; + EXPECT_TRUE(JsonToDisplayLayout(*read_value, &read_layout)); + EXPECT_EQ(true, read_layout.mirrored); + EXPECT_EQ(1, read_layout.primary_id); + EXPECT_FALSE(read_layout.default_unified); + ASSERT_EQ(1u, read_layout.placement_list.size()); + EXPECT_EQ(DisplayPlacement::BOTTOM, read_layout.placement_list[0].position); + EXPECT_EQ(20, read_layout.placement_list[0].offset); +} + +} // namespace display diff --git a/chromium/ui/display/mojo/BUILD.gn b/chromium/ui/display/mojo/BUILD.gn index 8be72888bf5..c32d3435212 100644 --- a/chromium/ui/display/mojo/BUILD.gn +++ b/chromium/ui/display/mojo/BUILD.gn @@ -7,11 +7,16 @@ import("//mojo/public/tools/bindings/mojom.gni") mojom("interfaces") { sources = [ "display.mojom", + "display_constants.mojom", "display_layout.mojom", "display_mode.mojom", + "display_snapshot_mojo.mojom", + "gamma_ramp_rgb_entry.mojom", + "native_display_delegate.mojom", ] public_deps = [ + "//mojo/common:common_custom_types", "//ui/gfx/geometry/mojo", ] } diff --git a/chromium/ui/display/mojo/display_constants.mojom b/chromium/ui/display/mojo/display_constants.mojom new file mode 100644 index 00000000000..a10d8d39f40 --- /dev/null +++ b/chromium/ui/display/mojo/display_constants.mojom @@ -0,0 +1,24 @@ +// 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. + +module display.mojom; + +// Corresponding to display::DisplayConnectionType. +enum DisplayConnectionType { + DISPLAY_CONNECTION_TYPE_NONE = 0, + DISPLAY_CONNECTION_TYPE_UNKNOWN = 1, + DISPLAY_CONNECTION_TYPE_INTERNAL = 2, + DISPLAY_CONNECTION_TYPE_VGA = 4, + DISPLAY_CONNECTION_TYPE_HDMI = 8, + DISPLAY_CONNECTION_TYPE_DVI = 16, + DISPLAY_CONNECTION_TYPE_DISPLAYPORT = 32, + DISPLAY_CONNECTION_TYPE_NETWORK = 64, +}; + +// Corresponding to display::HDCPState. +enum HDCPState { + HDCP_STATE_UNDESIRED, + HDCP_STATE_DESIRED, + HDCP_STATE_ENABLED, +};
\ No newline at end of file diff --git a/chromium/ui/display/mojo/display_constants.typemap b/chromium/ui/display/mojo/display_constants.typemap new file mode 100644 index 00000000000..4c0b4ae1b59 --- /dev/null +++ b/chromium/ui/display/mojo/display_constants.typemap @@ -0,0 +1,17 @@ +# 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/mojo/display_constants.mojom" +public_headers = [ "//ui/display/types/display_constants.h" ] +traits_headers = [ "//ui/display/mojo/display_constants_struct_traits.h" ] +sources = [ + "//ui/display/mojo/display_constants_struct_traits.cc", +] +public_deps = [ + "//ui/display", +] +type_mappings = [ + "display.mojom.DisplayConnectionType=display::DisplayConnectionType", + "display.mojom.HDCPState=display::HDCPState", +] diff --git a/chromium/ui/display/mojo/display_constants_struct_traits.cc b/chromium/ui/display/mojo/display_constants_struct_traits.cc new file mode 100644 index 00000000000..c5cc01342d5 --- /dev/null +++ b/chromium/ui/display/mojo/display_constants_struct_traits.cc @@ -0,0 +1,111 @@ +// 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. + +#include "ui/display/mojo/display_constants_struct_traits.h" + +namespace mojo { + +display::mojom::DisplayConnectionType EnumTraits< + display::mojom::DisplayConnectionType, + display::DisplayConnectionType>::ToMojom(display::DisplayConnectionType + type) { + switch (type) { + case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NONE: + return display::mojom::DisplayConnectionType:: + DISPLAY_CONNECTION_TYPE_NONE; + case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_UNKNOWN: + return display::mojom::DisplayConnectionType:: + DISPLAY_CONNECTION_TYPE_UNKNOWN; + case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_INTERNAL: + return display::mojom::DisplayConnectionType:: + DISPLAY_CONNECTION_TYPE_INTERNAL; + case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_VGA: + return display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_VGA; + case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_HDMI: + return display::mojom::DisplayConnectionType:: + DISPLAY_CONNECTION_TYPE_HDMI; + case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_DVI: + return display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_DVI; + case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_DISPLAYPORT: + return display::mojom::DisplayConnectionType:: + DISPLAY_CONNECTION_TYPE_DISPLAYPORT; + case display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NETWORK: + return display::mojom::DisplayConnectionType:: + DISPLAY_CONNECTION_TYPE_NETWORK; + } + NOTREACHED(); + return display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NONE; +} + +bool EnumTraits<display::mojom::DisplayConnectionType, + display::DisplayConnectionType>:: + FromMojom(display::mojom::DisplayConnectionType type, + display::DisplayConnectionType* out) { + switch (type) { + case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NONE: + *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NONE; + return true; + case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_UNKNOWN: + *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_UNKNOWN; + return true; + case display::mojom::DisplayConnectionType:: + DISPLAY_CONNECTION_TYPE_INTERNAL: + *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_INTERNAL; + return true; + case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_VGA: + *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_VGA; + return true; + case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_HDMI: + *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_HDMI; + return true; + case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_DVI: + *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_DVI; + return true; + case display::mojom::DisplayConnectionType:: + DISPLAY_CONNECTION_TYPE_DISPLAYPORT: + *out = + display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_DISPLAYPORT; + return true; + case display::mojom::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NETWORK: + *out = display::DisplayConnectionType::DISPLAY_CONNECTION_TYPE_NETWORK; + return true; + } + return false; +} + +// static +display::mojom::HDCPState +EnumTraits<display::mojom::HDCPState, display::HDCPState>::ToMojom( + display::HDCPState type) { + switch (type) { + case display::HDCPState::HDCP_STATE_UNDESIRED: + return display::mojom::HDCPState::HDCP_STATE_UNDESIRED; + case display::HDCPState::HDCP_STATE_DESIRED: + return display::mojom::HDCPState::HDCP_STATE_DESIRED; + case display::HDCPState::HDCP_STATE_ENABLED: + return display::mojom::HDCPState::HDCP_STATE_ENABLED; + } + NOTREACHED(); + return display::mojom::HDCPState::HDCP_STATE_UNDESIRED; +} + +// static +bool EnumTraits<display::mojom::HDCPState, display::HDCPState>::FromMojom( + display::mojom::HDCPState type, + display::HDCPState* out) { + switch (type) { + case display::mojom::HDCPState::HDCP_STATE_UNDESIRED: + *out = display::HDCPState::HDCP_STATE_UNDESIRED; + return true; + case display::mojom::HDCPState::HDCP_STATE_DESIRED: + *out = display::HDCPState::HDCP_STATE_DESIRED; + return true; + case display::mojom::HDCPState::HDCP_STATE_ENABLED: + *out = display::HDCPState::HDCP_STATE_ENABLED; + return true; + } + return false; +} + +} // namespace mojo diff --git a/chromium/ui/display/mojo/display_constants_struct_traits.h b/chromium/ui/display/mojo/display_constants_struct_traits.h new file mode 100644 index 00000000000..ca7d9c2980a --- /dev/null +++ b/chromium/ui/display/mojo/display_constants_struct_traits.h @@ -0,0 +1,31 @@ +// 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. + +#ifndef UI_DISPLAY_MOJO_DISPLAY_CONSTANTS_STRUCT_TRAITS_H_ +#define UI_DISPLAY_MOJO_DISPLAY_CONSTANTS_STRUCT_TRAITS_H_ + +#include "ui/display/mojo/display_constants.mojom.h" +#include "ui/display/types/display_constants.h" + +namespace mojo { + +template <> +struct EnumTraits<display::mojom::DisplayConnectionType, + display::DisplayConnectionType> { + static display::mojom::DisplayConnectionType ToMojom( + display::DisplayConnectionType type); + static bool FromMojom(display::mojom::DisplayConnectionType type, + display::DisplayConnectionType* out); +}; + +template <> +struct EnumTraits<display::mojom::HDCPState, display::HDCPState> { + static display::mojom::HDCPState ToMojom(display::HDCPState type); + static bool FromMojom(display::mojom::HDCPState type, + display::HDCPState* out); +}; + +}; // namespace mojo + +#endif // UI_DISPLAY_MOJO_DISPLAY_CONSTANTS_STRUCT_TRAITS_H_
\ No newline at end of file diff --git a/chromium/ui/display/mojo/display_mode.typemap b/chromium/ui/display/mojo/display_mode.typemap index c37f44507d5..fc1f37d4174 100644 --- a/chromium/ui/display/mojo/display_mode.typemap +++ b/chromium/ui/display/mojo/display_mode.typemap @@ -5,6 +5,9 @@ mojom = "//ui/display/mojo/display_mode.mojom" public_headers = [ "//ui/display/types/display_mode.h" ] traits_headers = [ "//ui/display/mojo/display_mode_struct_traits.h" ] +sources = [ + "//ui/display/mojo/display_mode_struct_traits.cc", +] public_deps = [ "//ui/display", ] diff --git a/chromium/ui/display/mojo/display_mode_struct_traits.cc b/chromium/ui/display/mojo/display_mode_struct_traits.cc new file mode 100644 index 00000000000..2c5d7910326 --- /dev/null +++ b/chromium/ui/display/mojo/display_mode_struct_traits.cc @@ -0,0 +1,24 @@ +// 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. + +#include "ui/display/mojo/display_mode_struct_traits.h" + +#include "ui/gfx/geometry/mojo/geometry_struct_traits.h" + +namespace mojo { + +// static +bool StructTraits<display::mojom::DisplayModeDataView, + std::unique_ptr<display::DisplayMode>>:: + Read(display::mojom::DisplayModeDataView data, + std::unique_ptr<display::DisplayMode>* out) { + gfx::Size size; + if (!data.ReadSize(&size)) + return false; + *out = base::MakeUnique<display::DisplayMode>(size, data.is_interlaced(), + data.refresh_rate()); + return true; +}; + +} // namespace mojo diff --git a/chromium/ui/display/mojo/display_mode_struct_traits.h b/chromium/ui/display/mojo/display_mode_struct_traits.h index 8d7d2bc08c4..2990846de19 100644 --- a/chromium/ui/display/mojo/display_mode_struct_traits.h +++ b/chromium/ui/display/mojo/display_mode_struct_traits.h @@ -30,14 +30,7 @@ struct StructTraits<display::mojom::DisplayModeDataView, } static bool Read(display::mojom::DisplayModeDataView data, - std::unique_ptr<display::DisplayMode>* out) { - gfx::Size size; - if (!data.ReadSize(&size)) - return false; - *out = base::MakeUnique<display::DisplayMode>(size, data.is_interlaced(), - data.refresh_rate()); - return true; - } + std::unique_ptr<display::DisplayMode>* out); }; } // namespace mojo diff --git a/chromium/ui/display/mojo/display_snapshot_mojo.mojom b/chromium/ui/display/mojo/display_snapshot_mojo.mojom new file mode 100644 index 00000000000..8b7ce1c5075 --- /dev/null +++ b/chromium/ui/display/mojo/display_snapshot_mojo.mojom @@ -0,0 +1,31 @@ +// 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. + +module display.mojom; + +import "mojo/common/file_path.mojom"; +import "ui/display/mojo/display_constants.mojom"; +import "ui/display/mojo/display_mode.mojom"; +import "ui/gfx/geometry/mojo/geometry.mojom"; + +// Corresponds to display::DisplaySnapshotMojo. +struct DisplaySnapshotMojo { + int64 display_id; + gfx.mojom.Point origin; + gfx.mojom.Size physical_size; + display.mojom.DisplayConnectionType type; + bool is_aspect_preserving_scaling; + bool has_overscan; + bool has_color_correction_matrix; + string display_name; + mojo.common.mojom.FilePath sys_path; + array<display.mojom.DisplayMode> modes; + array<uint8> edid; + uint64 current_mode_index; + bool has_current_mode; + uint64 native_mode_index; + bool has_native_mode; + int64 product_id; + gfx.mojom.Size maximum_cursor_size; +}; diff --git a/chromium/ui/display/mojo/display_snapshot_mojo.typemap b/chromium/ui/display/mojo/display_snapshot_mojo.typemap new file mode 100644 index 00000000000..bd06b0fb742 --- /dev/null +++ b/chromium/ui/display/mojo/display_snapshot_mojo.typemap @@ -0,0 +1,17 @@ +# 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/mojo/display_snapshot_mojo.mojom" +public_headers = [ "//ui/display/types/display_snapshot_mojo.h" ] +traits_headers = [ "//ui/display/mojo/display_snapshot_mojo_struct_traits.h" ] +sources = [ + "//ui/display/mojo/display_snapshot_mojo_struct_traits.cc", +] +public_deps = [ + "//ui/display", +] +deps = [ + "//ui/gfx/geometry", +] +type_mappings = [ "display.mojom.DisplaySnapshotMojo=std::unique_ptr<display::DisplaySnapshotMojo>[move_only]" ] diff --git a/chromium/ui/display/mojo/display_snapshot_mojo_struct_traits.cc b/chromium/ui/display/mojo/display_snapshot_mojo_struct_traits.cc new file mode 100644 index 00000000000..0a490e5e26d --- /dev/null +++ b/chromium/ui/display/mojo/display_snapshot_mojo_struct_traits.cc @@ -0,0 +1,139 @@ +// 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. + +#include "ui/display/mojo/display_snapshot_mojo_struct_traits.h" + +#include "ipc/ipc_message_utils.h" +#include "ui/display/mojo/display_constants_struct_traits.h" +#include "ui/display/mojo/display_mode_struct_traits.h" +#include "ui/display/types/display_constants.h" +#include "ui/gfx/geometry/mojo/geometry_struct_traits.h" +#include "ui/gfx/geometry/size.h" + +namespace mojo { + +namespace { + +// Returns the index of |mode| in |modes| or not found. +static uint64_t GetModeIndex( + const display::DisplaySnapshot::DisplayModeList& modes, + const display::DisplayMode* mode) { + if (!mode) + return std::numeric_limits<uint64_t>::max(); + + for (size_t i = 0; i < modes.size(); ++i) { + if (modes[i].get()->size() == mode->size() && + modes[i].get()->is_interlaced() == mode->is_interlaced() && + modes[i].get()->refresh_rate() == mode->refresh_rate()) + return i; + } + NOTREACHED(); + return std::numeric_limits<uint64_t>::max(); +} + +} // namespace + +// static +std::vector<std::unique_ptr<display::DisplayMode>> +StructTraits<display::mojom::DisplaySnapshotMojoDataView, + std::unique_ptr<display::DisplaySnapshotMojo>>:: + modes( + const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { + std::vector<std::unique_ptr<display::DisplayMode>> display_mode_list; + + for (const auto& display_mode : display_snapshot->modes()) + display_mode_list.push_back(display_mode->Clone()); + + return display_mode_list; +} + +// static +uint64_t StructTraits<display::mojom::DisplaySnapshotMojoDataView, + std::unique_ptr<display::DisplaySnapshotMojo>>:: + current_mode_index( + const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { + return GetModeIndex(display_snapshot->modes(), + display_snapshot->current_mode()); +} + +// static +uint64_t StructTraits<display::mojom::DisplaySnapshotMojoDataView, + std::unique_ptr<display::DisplaySnapshotMojo>>:: + native_mode_index( + const std::unique_ptr<display::DisplaySnapshotMojo>& display_snapshot) { + return GetModeIndex(display_snapshot->modes(), + display_snapshot->native_mode()); +} + +// static +bool StructTraits<display::mojom::DisplaySnapshotMojoDataView, + std::unique_ptr<display::DisplaySnapshotMojo>>:: + Read(display::mojom::DisplaySnapshotMojoDataView data, + std::unique_ptr<display::DisplaySnapshotMojo>* out) { + gfx::Point origin; + if (!data.ReadOrigin(&origin)) + return false; + + gfx::Size physical_size; + if (!data.ReadPhysicalSize(&physical_size)) + return false; + + display::DisplayConnectionType type; + if (!data.ReadType(&type)) + return false; + + std::string display_name; + if (!data.ReadDisplayName(&display_name)) + return false; + + base::FilePath file_path; + if (!data.ReadSysPath(&file_path)) + return false; + + // There is a type mismatch between vectors containing unique_ptr<T> vs + // unique_ptr<const T>. We deserialize into a vector of unique_ptr<T> + // then create a vector of unique_ptr<const T> after. + std::vector<std::unique_ptr<display::DisplayMode>> non_const_modes; + if (!data.ReadModes(&non_const_modes)) + return false; + display::DisplaySnapshot::DisplayModeList modes; + for (auto& mode : non_const_modes) + modes.push_back(std::move(mode)); + + // Get current_mode pointer from modes array. + const display::DisplayMode* current_mode = nullptr; + if (data.has_current_mode()) { + size_t current_mode_index = data.current_mode_index(); + if (current_mode_index >= modes.size()) + return false; + current_mode = modes[current_mode_index].get(); + } + + // Get native_mode pointer from modes array. + const display::DisplayMode* native_mode = nullptr; + if (data.has_native_mode()) { + size_t native_mode_index = data.native_mode_index(); + if (native_mode_index >= modes.size()) + return false; + native_mode = modes[native_mode_index].get(); + } + + std::vector<uint8_t> edid; + if (!data.ReadEdid(&edid)) + return false; + + gfx::Size maximum_cursor_size; + if (!data.ReadMaximumCursorSize(&maximum_cursor_size)) + return false; + + *out = base::MakeUnique<display::DisplaySnapshotMojo>( + data.display_id(), origin, physical_size, type, + data.is_aspect_preserving_scaling(), data.has_overscan(), + data.has_color_correction_matrix(), display_name, file_path, + data.product_id(), std::move(modes), std::move(edid), current_mode, + native_mode, maximum_cursor_size); + return true; +} + +} // namespace mojo
\ No newline at end of file diff --git a/chromium/ui/display/mojo/display_snapshot_mojo_struct_traits.h b/chromium/ui/display/mojo/display_snapshot_mojo_struct_traits.h new file mode 100644 index 00000000000..0ce011efea5 --- /dev/null +++ b/chromium/ui/display/mojo/display_snapshot_mojo_struct_traits.h @@ -0,0 +1,102 @@ +// 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. + +#ifndef UI_DISPLAY_MOJO_DISPLAY_SNAPSHOT_MOJO_STRUCT_TRAITS_H_ +#define UI_DISPLAY_MOJO_DISPLAY_SNAPSHOT_MOJO_STRUCT_TRAITS_H_ + +#include "ui/display/mojo/display_snapshot_mojo.mojom.h" +#include "ui/display/types/display_mode.h" +#include "ui/display/types/display_snapshot_mojo.h" + +namespace mojo { + +template <> +struct StructTraits<display::mojom::DisplaySnapshotMojoDataView, + std::unique_ptr<display::DisplaySnapshotMojo>> { + static int64_t display_id( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->display_id(); + } + + static const gfx::Point& origin( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->origin(); + } + + static const gfx::Size& physical_size( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->physical_size(); + } + + static display::DisplayConnectionType type( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->type(); + } + + static bool is_aspect_preserving_scaling( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->is_aspect_preserving_scaling(); + } + + static bool has_overscan( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->has_overscan(); + } + + static bool has_color_correction_matrix( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->has_color_correction_matrix(); + } + + static std::string display_name( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->display_name(); + } + + static const base::FilePath& sys_path( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->sys_path(); + } + + static std::vector<uint8_t> edid( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->edid(); + } + + static std::vector<std::unique_ptr<display::DisplayMode>> modes( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot); + + static uint64_t current_mode_index( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot); + + static bool has_current_mode( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->current_mode() != nullptr; + } + + static uint64_t native_mode_index( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot); + + static bool has_native_mode( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->native_mode() != nullptr; + } + + static int64_t product_id( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->product_id(); + } + + static const gfx::Size& maximum_cursor_size( + const std::unique_ptr<display::DisplaySnapshotMojo>& snapshot) { + return snapshot->maximum_cursor_size(); + } + + static bool Read(display::mojom::DisplaySnapshotMojoDataView data, + std::unique_ptr<display::DisplaySnapshotMojo>* out); +}; + +} // namespace mojo + +#endif // UI_DISPLAY_MOJO_DISPLAY_SNAPSHOT_MOJO_STRUCT_TRAITS_H_ diff --git a/chromium/ui/display/mojo/display_struct_traits_test.mojom b/chromium/ui/display/mojo/display_struct_traits_test.mojom index d478a1f254d..ba18e611d81 100644 --- a/chromium/ui/display/mojo/display_struct_traits_test.mojom +++ b/chromium/ui/display/mojo/display_struct_traits_test.mojom @@ -5,8 +5,11 @@ module display.mojom; import "ui/display/mojo/display.mojom"; +import "ui/display/mojo/display_constants.mojom"; import "ui/display/mojo/display_layout.mojom"; import "ui/display/mojo/display_mode.mojom"; +import "ui/display/mojo/display_snapshot_mojo.mojom"; +import "ui/display/mojo/gamma_ramp_rgb_entry.mojom"; interface DisplayStructTraitsTest { [Sync] @@ -16,8 +19,18 @@ interface DisplayStructTraitsTest { EchoDisplayMode(DisplayMode in) => (DisplayMode out); [Sync] + EchoDisplaySnapshotMojo(DisplaySnapshotMojo in) => (DisplaySnapshotMojo + out); + + [Sync] EchoDisplayPlacement(DisplayPlacement in) => (DisplayPlacement out); [Sync] EchoDisplayLayout(DisplayLayout in) => (DisplayLayout out); + + [Sync] + EchoHDCPState(HDCPState in) => (HDCPState out); + + [Sync] + EchoGammaRampRGBEntry(GammaRampRGBEntry in) => (GammaRampRGBEntry out); };
\ No newline at end of file diff --git a/chromium/ui/display/mojo/display_struct_traits_unittest.cc b/chromium/ui/display/mojo/display_struct_traits_unittest.cc index e087e68d63e..1edac9f82c5 100644 --- a/chromium/ui/display/mojo/display_struct_traits_unittest.cc +++ b/chromium/ui/display/mojo/display_struct_traits_unittest.cc @@ -2,13 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <memory> + +#include "base/macros.h" #include "base/message_loop/message_loop.h" #include "mojo/public/cpp/bindings/binding_set.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/display/display.h" #include "ui/display/display_layout.h" #include "ui/display/mojo/display_struct_traits_test.mojom.h" +#include "ui/display/types/display_constants.h" #include "ui/display/types/display_mode.h" +#include "ui/display/types/display_snapshot_mojo.h" +#include "ui/display/types/gamma_ramp_rgb_entry.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" @@ -41,6 +47,12 @@ class DisplayStructTraitsTest : public testing::Test, callback.Run(std::move(in)); } + void EchoDisplaySnapshotMojo( + std::unique_ptr<DisplaySnapshotMojo> in, + const EchoDisplaySnapshotMojoCallback& callback) override { + callback.Run(std::move(in)); + } + void EchoDisplayPlacement( const DisplayPlacement& in, const EchoDisplayPlacementCallback& callback) override { @@ -52,6 +64,17 @@ class DisplayStructTraitsTest : public testing::Test, callback.Run(std::move(in)); } + void EchoHDCPState(display::HDCPState in, + const EchoHDCPStateCallback& callback) override { + callback.Run(in); + } + + void EchoGammaRampRGBEntry( + const GammaRampRGBEntry& in, + const EchoGammaRampRGBEntryCallback& callback) override { + callback.Run(in); + } + base::MessageLoop loop_; // A MessageLoop is needed for Mojo IPC to work. mojo::BindingSet<mojom::DisplayStructTraitsTest> traits_test_bindings_; @@ -78,6 +101,49 @@ void CheckDisplayLayoutsEqual(const DisplayLayout& input, EXPECT_EQ(input.primary_id, output.primary_id); } +bool CompareModes(const DisplayMode& lhs, const DisplayMode& rhs) { + return lhs.size() == rhs.size() && + lhs.is_interlaced() == rhs.is_interlaced() && + lhs.refresh_rate() == rhs.refresh_rate(); +} + +void CheckDisplaySnapShotMojoEqual(const DisplaySnapshotMojo& input, + const DisplaySnapshotMojo& output) { + // We want to test each component individually to make sure each data member + // was correctly serialized and deserialized. + EXPECT_NE(&input, &output); // Make sure they aren't the same object. + EXPECT_EQ(input.display_id(), output.display_id()); + EXPECT_EQ(input.origin(), output.origin()); + EXPECT_EQ(input.physical_size(), output.physical_size()); + EXPECT_EQ(input.type(), output.type()); + EXPECT_EQ(input.is_aspect_preserving_scaling(), + output.is_aspect_preserving_scaling()); + EXPECT_EQ(input.has_overscan(), output.has_overscan()); + EXPECT_EQ(input.has_color_correction_matrix(), + output.has_color_correction_matrix()); + EXPECT_EQ(input.display_name(), output.display_name()); + EXPECT_EQ(input.sys_path(), output.sys_path()); + EXPECT_EQ(input.product_id(), output.product_id()); + EXPECT_EQ(input.modes().size(), output.modes().size()); + + for (size_t i = 0; i < input.modes().size(); i++) + EXPECT_TRUE(CompareModes(*input.modes()[i], *output.modes()[i])); + + EXPECT_EQ(input.edid(), output.edid()); + + if (!input.current_mode()) + EXPECT_EQ(nullptr, output.current_mode()); + else + EXPECT_TRUE(CompareModes(*input.current_mode(), *output.current_mode())); + + if (!input.native_mode()) + EXPECT_EQ(nullptr, output.native_mode()); + else + EXPECT_TRUE(CompareModes(*input.native_mode(), *output.native_mode())); + + EXPECT_EQ(input.maximum_cursor_size(), output.maximum_cursor_size()); +} + } // namespace TEST_F(DisplayStructTraitsTest, DefaultDisplayValues) { @@ -219,4 +285,178 @@ TEST_F(DisplayStructTraitsTest, DisplayLayoutTwoMirrored) { CheckDisplayLayoutsEqual(*input, *output); } +TEST_F(DisplayStructTraitsTest, BasicGammaRampRGBEntry) { + const GammaRampRGBEntry input{259, 81, 16}; + + GammaRampRGBEntry output; + GetTraitsTestProxy()->EchoGammaRampRGBEntry(input, &output); + + EXPECT_EQ(input.r, output.r); + EXPECT_EQ(input.g, output.g); + EXPECT_EQ(input.b, output.b); +} + +// One display mode, current and native mode nullptr. +TEST_F(DisplayStructTraitsTest, DisplaySnapshotCurrentAndNativeModesNull) { + // Prepare sample input with random values. + const int64_t display_id = 7; + const gfx::Point origin(1, 2); + const gfx::Size physical_size(5, 9); + const gfx::Size maximum_cursor_size(3, 5); + const DisplayConnectionType type = + display::DISPLAY_CONNECTION_TYPE_DISPLAYPORT; + const bool is_aspect_preserving_scaling = true; + const bool has_overscan = true; + const bool has_color_correction_matrix = true; + const std::string display_name("whatever display_name"); + const base::FilePath sys_path = base::FilePath::FromUTF8Unsafe("a/cb"); + const int64_t product_id = 19; + + const DisplayMode display_mode(gfx::Size(13, 11), true, 40.0f); + + display::DisplaySnapshot::DisplayModeList modes; + modes.push_back(display_mode.Clone()); + + const DisplayMode* current_mode = nullptr; + const DisplayMode* native_mode = nullptr; + const std::vector<uint8_t> edid = {1}; + + std::unique_ptr<DisplaySnapshotMojo> input = + base::MakeUnique<DisplaySnapshotMojo>( + display_id, origin, physical_size, type, is_aspect_preserving_scaling, + has_overscan, has_color_correction_matrix, display_name, sys_path, + product_id, std::move(modes), edid, current_mode, native_mode, + maximum_cursor_size); + + std::unique_ptr<DisplaySnapshotMojo> output; + GetTraitsTestProxy()->EchoDisplaySnapshotMojo( + DisplaySnapshotMojo::CreateFrom(*input), &output); + + CheckDisplaySnapShotMojoEqual(*input, *output); +} + +// One display mode that is the native mode and no current mode. +TEST_F(DisplayStructTraitsTest, DisplaySnapshotCurrentModeNull) { + // Prepare sample input with random values. + const int64_t display_id = 6; + const gfx::Point origin(11, 32); + const gfx::Size physical_size(55, 49); + const gfx::Size maximum_cursor_size(13, 95); + const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_VGA; + const bool is_aspect_preserving_scaling = true; + const bool has_overscan = true; + const bool has_color_correction_matrix = true; + const std::string display_name("whatever display_name"); + const base::FilePath sys_path = base::FilePath::FromUTF8Unsafe("z/b"); + const int64_t product_id = 9; + + const DisplayMode display_mode(gfx::Size(13, 11), true, 50.0f); + + display::DisplaySnapshot::DisplayModeList modes; + modes.push_back(display_mode.Clone()); + + const DisplayMode* current_mode = nullptr; + const DisplayMode* native_mode = modes[0].get(); + const std::vector<uint8_t> edid = {1}; + + std::unique_ptr<DisplaySnapshotMojo> input = + base::MakeUnique<DisplaySnapshotMojo>( + display_id, origin, physical_size, type, is_aspect_preserving_scaling, + has_overscan, has_color_correction_matrix, display_name, sys_path, + product_id, std::move(modes), edid, current_mode, native_mode, + maximum_cursor_size); + + std::unique_ptr<DisplaySnapshotMojo> output; + GetTraitsTestProxy()->EchoDisplaySnapshotMojo( + DisplaySnapshotMojo::CreateFrom(*input), &output); + + CheckDisplaySnapShotMojoEqual(*input, *output); +} + +// Multiple display modes, both native and current mode set. +TEST_F(DisplayStructTraitsTest, DisplaySnapshotExternal) { + // Prepare sample input from external display. + const int64_t display_id = 9834293210466051; + const gfx::Point origin(0, 1760); + const gfx::Size physical_size(520, 320); + const gfx::Size maximum_cursor_size(4, 5); + const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_HDMI; + const bool is_aspect_preserving_scaling = false; + const bool has_overscan = false; + const bool has_color_correction_matrix = false; + const std::string display_name("HP Z24i"); + const base::FilePath sys_path = base::FilePath::FromUTF8Unsafe("a/cb"); + const int64_t product_id = 139; + + const DisplayMode display_mode(gfx::Size(1024, 768), false, 60.0f); + const DisplayMode display_current_mode(gfx::Size(1440, 900), false, 59.89f); + const DisplayMode display_native_mode(gfx::Size(1920, 1200), false, 59.89f); + + display::DisplaySnapshot::DisplayModeList modes; + modes.push_back(display_mode.Clone()); + modes.push_back(display_current_mode.Clone()); + modes.push_back(display_native_mode.Clone()); + + const DisplayMode* current_mode = modes[1].get(); + const DisplayMode* native_mode = modes[2].get(); + const std::vector<uint8_t> edid = {2, 3, 4, 5}; + + std::unique_ptr<DisplaySnapshotMojo> input = + base::MakeUnique<DisplaySnapshotMojo>( + display_id, origin, physical_size, type, is_aspect_preserving_scaling, + has_overscan, has_color_correction_matrix, display_name, sys_path, + product_id, std::move(modes), edid, current_mode, native_mode, + maximum_cursor_size); + + std::unique_ptr<DisplaySnapshotMojo> output; + GetTraitsTestProxy()->EchoDisplaySnapshotMojo( + DisplaySnapshotMojo::CreateFrom(*input), &output); + + CheckDisplaySnapShotMojoEqual(*input, *output); +} + +TEST_F(DisplayStructTraitsTest, DisplaySnapshotInternal) { + // Prepare sample input from Pixel's internal display. + const int64_t display_id = 13761487533244416; + const gfx::Point origin(0, 0); + const gfx::Size physical_size(270, 180); + const gfx::Size maximum_cursor_size(64, 64); + const DisplayConnectionType type = display::DISPLAY_CONNECTION_TYPE_INTERNAL; + const bool is_aspect_preserving_scaling = true; + const bool has_overscan = false; + const bool has_color_correction_matrix = false; + const std::string display_name(""); + const base::FilePath sys_path; + const int64_t product_id = 139; + + const DisplayMode display_mode(gfx::Size(2560, 1700), false, 95.96f); + + display::DisplaySnapshot::DisplayModeList modes; + modes.push_back(display_mode.Clone()); + + const DisplayMode* current_mode = modes[0].get(); + const DisplayMode* native_mode = modes[0].get(); + const std::vector<uint8_t> edid = {2, 3}; + + std::unique_ptr<DisplaySnapshotMojo> input = + base::MakeUnique<DisplaySnapshotMojo>( + display_id, origin, physical_size, type, is_aspect_preserving_scaling, + has_overscan, has_color_correction_matrix, display_name, sys_path, + product_id, std::move(modes), edid, current_mode, native_mode, + maximum_cursor_size); + + std::unique_ptr<DisplaySnapshotMojo> output; + GetTraitsTestProxy()->EchoDisplaySnapshotMojo( + DisplaySnapshotMojo::CreateFrom(*input), &output); + + CheckDisplaySnapShotMojoEqual(*input, *output); +} + +TEST_F(DisplayStructTraitsTest, HDCPStateBasic) { + const display::HDCPState input(HDCP_STATE_ENABLED); + display::HDCPState output; + GetTraitsTestProxy()->EchoHDCPState(input, &output); + EXPECT_EQ(input, output); +} + } // namespace display diff --git a/chromium/ui/display/mojo/gamma_ramp_rgb_entry.mojom b/chromium/ui/display/mojo/gamma_ramp_rgb_entry.mojom new file mode 100644 index 00000000000..db2d7ed3a7f --- /dev/null +++ b/chromium/ui/display/mojo/gamma_ramp_rgb_entry.mojom @@ -0,0 +1,12 @@ +// 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. + +module display.mojom; + +// Corresponds to display::GammaRampRGBEntry. +struct GammaRampRGBEntry { + uint16 r; + uint16 g; + uint16 b; +}; diff --git a/chromium/ui/display/mojo/gamma_ramp_rgb_entry.typemap b/chromium/ui/display/mojo/gamma_ramp_rgb_entry.typemap new file mode 100644 index 00000000000..2618fe9da0f --- /dev/null +++ b/chromium/ui/display/mojo/gamma_ramp_rgb_entry.typemap @@ -0,0 +1,14 @@ +# 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/mojo/gamma_ramp_rgb_entry.mojom" +public_headers = [ "//ui/display/types/gamma_ramp_rgb_entry.h" ] +traits_headers = [ "//ui/display/mojo/gamma_ramp_rgb_entry_struct_traits.h" ] +sources = [ + "//ui/display/mojo/gamma_ramp_rgb_entry_struct_traits.cc", +] +public_deps = [ + "//ui/display", +] +type_mappings = [ "display.mojom.GammaRampRGBEntry=display::GammaRampRGBEntry" ] diff --git a/chromium/ui/display/mojo/gamma_ramp_rgb_entry_struct_traits.cc b/chromium/ui/display/mojo/gamma_ramp_rgb_entry_struct_traits.cc new file mode 100644 index 00000000000..6ac8ecbcc63 --- /dev/null +++ b/chromium/ui/display/mojo/gamma_ramp_rgb_entry_struct_traits.cc @@ -0,0 +1,20 @@ +// 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. + +#include "ui/display/mojo/gamma_ramp_rgb_entry_struct_traits.h" + +namespace mojo { + +// static +bool StructTraits<display::mojom::GammaRampRGBEntryDataView, + display::GammaRampRGBEntry>:: + Read(display::mojom::GammaRampRGBEntryDataView data, + display::GammaRampRGBEntry* out) { + out->r = data.r(); + out->g = data.g(); + out->b = data.b(); + return true; +} + +} // namespace mojo diff --git a/chromium/ui/display/mojo/gamma_ramp_rgb_entry_struct_traits.h b/chromium/ui/display/mojo/gamma_ramp_rgb_entry_struct_traits.h new file mode 100644 index 00000000000..68c19f545e4 --- /dev/null +++ b/chromium/ui/display/mojo/gamma_ramp_rgb_entry_struct_traits.h @@ -0,0 +1,34 @@ +// 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. + +#ifndef UI_DISPLAY_MOJO_GAMMA_RAMP_RGB_ENTRY_STRUCT_TRAITS_H_ +#define UI_DISPLAY_MOJO_GAMMA_RAMP_RGB_ENTRY_STRUCT_TRAITS_H_ + +#include "ui/display/mojo/gamma_ramp_rgb_entry.mojom.h" +#include "ui/display/types/gamma_ramp_rgb_entry.h" + +namespace mojo { + +template <> +struct StructTraits<display::mojom::GammaRampRGBEntryDataView, + display::GammaRampRGBEntry> { + static uint16_t r(const display::GammaRampRGBEntry& gamma_ramp_rgb_entry) { + return gamma_ramp_rgb_entry.r; + } + + static uint16_t g(const display::GammaRampRGBEntry& gamma_ramp_rgb_entry) { + return gamma_ramp_rgb_entry.g; + } + + static uint16_t b(const display::GammaRampRGBEntry& gamma_ramp_rgb_entry) { + return gamma_ramp_rgb_entry.b; + } + + static bool Read(display::mojom::GammaRampRGBEntryDataView data, + display::GammaRampRGBEntry* out); +}; + +} // namespace mojo + +#endif // UI_DISPLAY_MOJO_GAMMA_RAMP_RGB_ENTRY_STRUCT_TRAITS_H_ diff --git a/chromium/ui/display/mojo/native_display_delegate.mojom b/chromium/ui/display/mojo/native_display_delegate.mojom new file mode 100644 index 00000000000..8a6ac594c77 --- /dev/null +++ b/chromium/ui/display/mojo/native_display_delegate.mojom @@ -0,0 +1,51 @@ +// 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. + +module display.mojom; + +import "ui/display/mojo/display_constants.mojom"; +import "ui/display/mojo/display_mode.mojom"; +import "ui/display/mojo/display_snapshot_mojo.mojom"; +import "ui/display/mojo/gamma_ramp_rgb_entry.mojom"; +import "ui/gfx/geometry/mojo/geometry.mojom"; + +// Corresponds to display::NativeDisplayObserver. +interface NativeDisplayObserver { + OnConfigurationChanged(); +}; + +// Corresponds to display::NativeDisplayDelegate. This only implements +// functionality that is used by Ozone DRM. +interface NativeDisplayDelegate { + // Initializes and registers the observer. + Initialize(NativeDisplayObserver observer); + + // Take control of the displays from any other controlling process. + TakeDisplayControl() => (bool result); + + // Let others control the displays. + RelinquishDisplayControl() => (bool result); + + // Queries for a list of fresh displays. + GetDisplays() => (array<DisplaySnapshotMojo> snapshots); + + // Configures the display represented by |display_id| to use |mode| and + // positions the display to |origin| in the framebuffer. |mode| can be null, + // which represents disabling the display. + Configure(int64 display_id, + DisplayMode mode, + gfx.mojom.Point origin) => (bool status); + + // Gets HDCP state of output. + GetHDCPState(int64 display_id) => (bool status, HDCPState state); + + // Sets HDCP state of output. + SetHDCPState(int64 display_id, HDCPState state) => (bool status); + + // Set the gamma tables and correction matrix for |display_id|. + SetColorCorrection(int64 display_id, + array<GammaRampRGBEntry> degamma_lut, + array<GammaRampRGBEntry> gamma_lut, + array<float> correction_matrix); +}; diff --git a/chromium/ui/display/mojo/typemaps.gni b/chromium/ui/display/mojo/typemaps.gni index 29652863f00..268ff25d0c4 100644 --- a/chromium/ui/display/mojo/typemaps.gni +++ b/chromium/ui/display/mojo/typemaps.gni @@ -4,6 +4,9 @@ typemaps = [ "//ui/display/mojo/display.typemap", + "//ui/display/mojo/display_constants.typemap", "//ui/display/mojo/display_layout.typemap", "//ui/display/mojo/display_mode.typemap", + "//ui/display/mojo/display_snapshot_mojo.typemap", + "//ui/display/mojo/gamma_ramp_rgb_entry.typemap", ] diff --git a/chromium/ui/display/screen.cc b/chromium/ui/display/screen.cc index f77133ace84..59dec1c71ec 100644 --- a/chromium/ui/display/screen.cc +++ b/chromium/ui/display/screen.cc @@ -34,15 +34,19 @@ void Screen::SetScreenInstance(Screen* instance) { g_screen = instance; } +Display Screen::GetDisplayNearestView(gfx::NativeView view) const { + return GetDisplayNearestWindow(GetWindowForView(view)); +} + gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeView view, const gfx::Rect& screen_rect) const { - float scale = GetDisplayNearestWindow(view).device_scale_factor(); + float scale = GetDisplayNearestView(view).device_scale_factor(); return ScaleToEnclosingRect(screen_rect, 1.0f / scale); } gfx::Rect Screen::DIPToScreenRectInWindow(gfx::NativeView view, const gfx::Rect& dip_rect) const { - float scale = GetDisplayNearestWindow(view).device_scale_factor(); + float scale = GetDisplayNearestView(view).device_scale_factor(); return ScaleToEnclosingRect(dip_rect, scale); } diff --git a/chromium/ui/display/screen.h b/chromium/ui/display/screen.h index 3bff5bdb640..b49a3ff4dfe 100644 --- a/chromium/ui/display/screen.h +++ b/chromium/ui/display/screen.h @@ -58,7 +58,12 @@ class DISPLAY_EXPORT Screen { // Returns the display nearest the specified window. // If the window is NULL or the window is not rooted to a display this will // return the primary display. - virtual Display GetDisplayNearestWindow(gfx::NativeView view) const = 0; + virtual Display GetDisplayNearestWindow(gfx::NativeWindow window) const = 0; + + // Returns the display nearest the specified view. It may still use the window + // that contains the view (i.e. if a window is spread over two displays, + // the location of the view within that window won't influence the result). + virtual Display GetDisplayNearestView(gfx::NativeView view) const; // Returns the display nearest the specified point. |point| should be in DIPs. virtual Display GetDisplayNearestPoint(const gfx::Point& point) const = 0; @@ -91,6 +96,8 @@ class DISPLAY_EXPORT Screen { bool GetDisplayWithDisplayId(int64_t display_id, Display* display) const; private: + static gfx::NativeWindow GetWindowForView(gfx::NativeView view); + DISALLOW_COPY_AND_ASSIGN(Screen); }; diff --git a/chromium/ui/display/screen_android.cc b/chromium/ui/display/screen_android.cc new file mode 100644 index 00000000000..cfb564306f0 --- /dev/null +++ b/chromium/ui/display/screen_android.cc @@ -0,0 +1,22 @@ +// 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. + +#include "ui/display/screen.h" + +#include "base/logging.h" + +namespace display { + +// static +gfx::NativeWindow Screen::GetWindowForView(gfx::NativeView view) { + // Android cannot use this method to convert |NativeView| to |NativeWindow| + // since it causes cyclic dependency. |GetDisplayNearestView| should be + // overriden directly. + NOTREACHED() << "Wrong screen instance is used. Make sure to use the correct " + "Screen instance that has proper implementation of " + "|GetDisplayNearestView| for Android."; + return nullptr; +} + +} // namespace display diff --git a/chromium/ui/display/screen_aura.cc b/chromium/ui/display/screen_aura.cc index a12d9a6de49..3d210b1353d 100644 --- a/chromium/ui/display/screen_aura.cc +++ b/chromium/ui/display/screen_aura.cc @@ -8,6 +8,11 @@ namespace display { +// static +gfx::NativeWindow Screen::GetWindowForView(gfx::NativeView view) { + return view; +} + Screen* CreateNativeScreen() { NOTREACHED() << "Implementation should be installed at higher level."; return NULL; diff --git a/chromium/ui/display/screen_base.cc b/chromium/ui/display/screen_base.cc index 21c8c270f2c..1180a1f4200 100644 --- a/chromium/ui/display/screen_base.cc +++ b/chromium/ui/display/screen_base.cc @@ -38,7 +38,7 @@ Display ScreenBase::GetPrimaryDisplay() const { return *iter; } -Display ScreenBase::GetDisplayNearestWindow(gfx::NativeView view) const { +Display ScreenBase::GetDisplayNearestWindow(gfx::NativeWindow window) const { // TODO(riajiang): Implement this for multi-displays either here or in // ScreenMus. NOTIMPLEMENTED(); @@ -58,6 +58,9 @@ const std::vector<Display>& ScreenBase::GetAllDisplays() const { } Display ScreenBase::GetDisplayMatching(const gfx::Rect& match_rect) const { + if (match_rect.IsEmpty()) + return GetDisplayNearestPoint(match_rect.origin()); + const Display* match = FindDisplayWithBiggestIntersection(display_list_.displays(), match_rect); return match ? *match : GetPrimaryDisplay(); diff --git a/chromium/ui/display/screen_base.h b/chromium/ui/display/screen_base.h index e1d9a9beeaf..04f548be53c 100644 --- a/chromium/ui/display/screen_base.h +++ b/chromium/ui/display/screen_base.h @@ -28,7 +28,7 @@ class DISPLAY_EXPORT ScreenBase : public Screen { bool IsWindowUnderCursor(gfx::NativeWindow window) override; gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; Display GetPrimaryDisplay() const override; - Display GetDisplayNearestWindow(gfx::NativeView view) const override; + Display GetDisplayNearestWindow(gfx::NativeWindow window) const override; Display GetDisplayNearestPoint(const gfx::Point& point) const override; int GetNumDisplays() const override; const std::vector<Display>& GetAllDisplays() const override; diff --git a/chromium/ui/display/types/BUILD.gn b/chromium/ui/display/types/BUILD.gn index b4053c4b031..9cef99b8f21 100644 --- a/chromium/ui/display/types/BUILD.gn +++ b/chromium/ui/display/types/BUILD.gn @@ -10,6 +10,8 @@ component("types") { "display_mode.h", "display_snapshot.cc", "display_snapshot.h", + "display_snapshot_mojo.cc", + "display_snapshot_mojo.h", "display_types_export.h", "fake_display_controller.h", "gamma_ramp_rgb_entry.h", diff --git a/chromium/ui/display/types/display_constants.h b/chromium/ui/display/types/display_constants.h index c5f68500ec9..ff524dd3dda 100644 --- a/chromium/ui/display/types/display_constants.h +++ b/chromium/ui/display/types/display_constants.h @@ -34,10 +34,9 @@ enum DisplayConnectionType { DISPLAY_CONNECTION_TYPE_DVI = 1 << 4, DISPLAY_CONNECTION_TYPE_DISPLAYPORT = 1 << 5, DISPLAY_CONNECTION_TYPE_NETWORK = 1 << 6, - DISPLAY_CONNECTION_TYPE_VIRTUAL = 1 << 7, // Update this when adding a new type. - DISPLAY_CONNECTION_TYPE_LAST = DISPLAY_CONNECTION_TYPE_VIRTUAL + DISPLAY_CONNECTION_TYPE_LAST = DISPLAY_CONNECTION_TYPE_NETWORK }; // Content protection methods applied on video output. diff --git a/chromium/ui/display/types/display_snapshot_mojo.cc b/chromium/ui/display/types/display_snapshot_mojo.cc new file mode 100644 index 00000000000..d3f4b36f9bb --- /dev/null +++ b/chromium/ui/display/types/display_snapshot_mojo.cc @@ -0,0 +1,76 @@ +// 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. + +#include "ui/display/types/display_snapshot_mojo.h" + +#include "base/memory/ptr_util.h" +#include "ui/display/types/display_constants.h" + +namespace display { + +// static +std::unique_ptr<DisplaySnapshotMojo> DisplaySnapshotMojo::CreateFrom( + const DisplaySnapshot& other) { + DisplayModeList clone_modes; + const DisplayMode* current_mode = nullptr; + const DisplayMode* native_mode = nullptr; + + // Clone the display modes and find equivalent pointers to the native and + // current mode. + for (auto& mode : other.modes()) { + clone_modes.push_back(mode->Clone()); + if (mode.get() == other.current_mode()) + current_mode = mode.get(); + if (mode.get() == other.native_mode()) + native_mode = mode.get(); + } + + return base::MakeUnique<DisplaySnapshotMojo>( + other.display_id(), other.origin(), other.physical_size(), other.type(), + other.is_aspect_preserving_scaling(), other.has_overscan(), + other.has_color_correction_matrix(), other.display_name(), + other.sys_path(), other.product_id(), std::move(clone_modes), + other.edid(), current_mode, native_mode, other.maximum_cursor_size()); +} + +DisplaySnapshotMojo::DisplaySnapshotMojo(int64_t display_id, + const gfx::Point& origin, + const gfx::Size& physical_size, + DisplayConnectionType type, + bool is_aspect_preserving_scaling, + bool has_overscan, + bool has_color_correction_matrix, + std::string display_name, + const base::FilePath& sys_path, + int64_t product_id, + DisplayModeList modes, + const std::vector<uint8_t>& edid, + const DisplayMode* current_mode, + const DisplayMode* native_mode, + const gfx::Size& maximum_cursor_size) + : DisplaySnapshot(display_id, + origin, + physical_size, + type, + is_aspect_preserving_scaling, + has_overscan, + has_color_correction_matrix, + display_name, + sys_path, + std::move(modes), + edid, + current_mode, + native_mode) { + product_id_ = product_id; + maximum_cursor_size_ = maximum_cursor_size; +} + +DisplaySnapshotMojo::~DisplaySnapshotMojo() = default; + +// TODO(thanhph): Implement ToString() for debugging purposes. +std::string DisplaySnapshotMojo::ToString() const { + return ""; +} + +} // namespace display diff --git a/chromium/ui/display/types/display_snapshot_mojo.h b/chromium/ui/display/types/display_snapshot_mojo.h new file mode 100644 index 00000000000..369ffb8af69 --- /dev/null +++ b/chromium/ui/display/types/display_snapshot_mojo.h @@ -0,0 +1,49 @@ +// 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. + +#ifndef UI_DISPLAY_TYPES_DISPLAY_SNAPSHOT_MOJO_H_ +#define UI_DISPLAY_TYPES_DISPLAY_SNAPSHOT_MOJO_H_ + +#include <memory> + +#include "base/macros.h" +#include "ui/display/types/display_snapshot.h" +#include "ui/display/types/display_types_export.h" + +namespace display { + +// DisplaySnapshot implementation that can be used with Mojo IPC. +class DISPLAY_TYPES_EXPORT DisplaySnapshotMojo : public DisplaySnapshot { + public: + // Create a new DisplaySnapshotMojo by copying |other|. + static std::unique_ptr<DisplaySnapshotMojo> CreateFrom( + const DisplaySnapshot& other); + + DisplaySnapshotMojo(int64_t display_id, + const gfx::Point& origin, + const gfx::Size& physical_size, + DisplayConnectionType type, + bool is_aspect_preserving_scaling, + bool has_overscan, + bool has_color_correction_matrix, + std::string display_name, + const base::FilePath& sys_path, + int64_t product_id, + DisplayModeList modes, + const std::vector<uint8_t>& edid, + const DisplayMode* current_mode, + const DisplayMode* native_mode, + const gfx::Size& maximum_cursor_size); + ~DisplaySnapshotMojo() override; + + // DisplaySnapshot: + std::string ToString() const override; + + private: + DISALLOW_COPY_AND_ASSIGN(DisplaySnapshotMojo); +}; + +} // namespace display + +#endif // UI_DISPLAY_TYPES_DISPLAY_SNAPSHOT_MOJO_H_ diff --git a/chromium/ui/display/win/screen_win.cc b/chromium/ui/display/win/screen_win.cc index 636eb90dc3a..a62cde1cd60 100644 --- a/chromium/ui/display/win/screen_win.cc +++ b/chromium/ui/display/win/screen_win.cc @@ -393,7 +393,7 @@ const std::vector<Display>& ScreenWin::GetAllDisplays() const { return displays_; } -Display ScreenWin::GetDisplayNearestWindow(gfx::NativeView window) const { +Display ScreenWin::GetDisplayNearestWindow(gfx::NativeWindow window) const { HWND window_hwnd = GetHWNDFromNativeView(window); if (!window_hwnd) { // When |window| isn't rooted to a display, we should just return the diff --git a/chromium/ui/display/win/screen_win.h b/chromium/ui/display/win/screen_win.h index 5a000d40385..eed87d9e45f 100644 --- a/chromium/ui/display/win/screen_win.h +++ b/chromium/ui/display/win/screen_win.h @@ -110,7 +110,7 @@ class DISPLAY_EXPORT ScreenWin : public Screen { static float GetSystemScaleFactor(); // Returns the HWND associated with the NativeView. - virtual HWND GetHWNDFromNativeView(gfx::NativeView window) const; + virtual HWND GetHWNDFromNativeView(gfx::NativeView view) const; // Returns the NativeView associated with the HWND. virtual gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const; @@ -122,7 +122,7 @@ class DISPLAY_EXPORT ScreenWin : public Screen { gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override; int GetNumDisplays() const override; const std::vector<Display>& GetAllDisplays() const override; - Display GetDisplayNearestWindow(gfx::NativeView window) const override; + Display GetDisplayNearestWindow(gfx::NativeWindow window) const override; Display GetDisplayNearestPoint(const gfx::Point& point) const override; Display GetDisplayMatching(const gfx::Rect& match_rect) const override; Display GetPrimaryDisplay() const override; |