| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef SERVICES_UI_DISPLAY_PLATFORM_SCREEN_OZONE_H_ | |
| 6 #define SERVICES_UI_DISPLAY_PLATFORM_SCREEN_OZONE_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <set> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/callback.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "mojo/public/cpp/bindings/binding_set.h" | |
| 16 #include "services/service_manager/public/cpp/connection.h" | |
| 17 #include "services/service_manager/public/cpp/interface_factory.h" | |
| 18 #include "services/ui/display/platform_screen.h" | |
| 19 #include "services/ui/display/viewport_metrics.h" | |
| 20 #include "services/ui/public/interfaces/display/display_controller.mojom.h" | |
| 21 #include "services/ui/public/interfaces/display/test_display_controller.mojom.h" | |
| 22 #include "ui/display/chromeos/display_configurator.h" | |
| 23 #include "ui/display/display.h" | |
| 24 #include "ui/display/types/display_constants.h" | |
| 25 #include "ui/display/types/fake_display_controller.h" | |
| 26 | |
| 27 namespace display { | |
| 28 | |
| 29 // PlatformScreenOzone provides the necessary functionality to configure all | |
| 30 // attached physical displays on the ozone platform. | |
| 31 class PlatformScreenOzone | |
| 32 : public PlatformScreen, | |
| 33 public ui::DisplayConfigurator::Observer, | |
| 34 public ui::DisplayConfigurator::StateController, | |
| 35 public service_manager::InterfaceFactory<mojom::DisplayController>, | |
| 36 public service_manager::InterfaceFactory<mojom::TestDisplayController>, | |
| 37 public mojom::DisplayController, | |
| 38 public mojom::TestDisplayController { | |
| 39 public: | |
| 40 PlatformScreenOzone(); | |
| 41 ~PlatformScreenOzone() override; | |
| 42 | |
| 43 // PlatformScreen: | |
| 44 void AddInterfaces(service_manager::InterfaceRegistry* registry) override; | |
| 45 void Init(PlatformScreenDelegate* delegate) override; | |
| 46 void RequestCloseDisplay(int64_t display_id) override; | |
| 47 int64_t GetPrimaryDisplayId() const override; | |
| 48 | |
| 49 // mojom::TestDisplayController: | |
| 50 void ToggleAddRemoveDisplay() override; | |
| 51 void ToggleDisplayResolution() override; | |
| 52 | |
| 53 // mojom::DisplayController: | |
| 54 void SwapPrimaryDisplay() override; | |
| 55 void SetDisplayWorkArea(int64_t display_id, | |
| 56 const gfx::Size& size, | |
| 57 const gfx::Insets& insets) override; | |
| 58 | |
| 59 private: | |
| 60 friend class PlatformScreenOzoneTest; | |
| 61 | |
| 62 // TODO(kylechar): This struct is just temporary until we migrate | |
| 63 // DisplayManager code out of ash so it can be used here. | |
| 64 struct DisplayInfo { | |
| 65 DisplayInfo(); | |
| 66 DisplayInfo(const DisplayInfo& other); | |
| 67 ~DisplayInfo(); | |
| 68 | |
| 69 int64_t id = kInvalidDisplayId; | |
| 70 // Information about display viewport. | |
| 71 ViewportMetrics metrics; | |
| 72 // Last insets received from WM. | |
| 73 gfx::Insets last_work_area_insets; | |
| 74 | |
| 75 // Temporary hack to allow changing display resolution. | |
| 76 std::vector<gfx::Size> supported_sizes; | |
| 77 gfx::Size requested_size; | |
| 78 | |
| 79 // The display bounds have been modified and delegate should be updated. | |
| 80 bool modified = false; | |
| 81 // The display has been removed and delegate should be updated. | |
| 82 bool removed = false; | |
| 83 }; | |
| 84 using CachedDisplayIterator = std::vector<DisplayInfo>::iterator; | |
| 85 | |
| 86 // Processes list of display snapshots and sets |removed| on any displays that | |
| 87 // have been removed. Updates |primary_display_id_| if the primary display was | |
| 88 // removed. Does not remove displays from |cached_displays_| or send updates | |
| 89 // to delegate. | |
| 90 void ProcessRemovedDisplays( | |
| 91 const ui::DisplayConfigurator::DisplayStateList& snapshots); | |
| 92 | |
| 93 // Processes list of display snapshots and updates the bounds of any displays | |
| 94 // in |cached_displays_| that have changed size. Does not send updates to | |
| 95 // delegate. | |
| 96 void ProcessModifiedDisplays( | |
| 97 const ui::DisplayConfigurator::DisplayStateList& snapshots); | |
| 98 | |
| 99 // Looks at |cached_displays_| for modified or removed displays. Also updates | |
| 100 // display bounds in response to modified or removed displays. Sends updates | |
| 101 // to the delegate when appropriate by calling OnDisplayModified() or | |
| 102 // OnDisplayRemoved(). Makes at most one call to delegate per display. | |
| 103 // | |
| 104 // Usually used after ProcessRemovedDisplays() and ProcessModifiedDisplays(). | |
| 105 void UpdateCachedDisplays(); | |
| 106 | |
| 107 // Processes list of display snapshots and adds any new displays to | |
| 108 // |cached_displays_|. Updates delegate by calling OnDisplayAdded(). | |
| 109 void AddNewDisplays( | |
| 110 const ui::DisplayConfigurator::DisplayStateList& snapshots); | |
| 111 | |
| 112 // Returns an iterator to the cached display with |display_id| or an end | |
| 113 // iterator if there is no display with that id. | |
| 114 CachedDisplayIterator GetCachedDisplayIterator(int64_t display_id); | |
| 115 | |
| 116 // Converts |snapshot| into ViewportMetrics. | |
| 117 ViewportMetrics MetricsFromSnapshot(const ui::DisplaySnapshot& snapshot, | |
| 118 const gfx::Point& origin); | |
| 119 | |
| 120 // ui::DisplayConfigurator::Observer: | |
| 121 void OnDisplayModeChanged( | |
| 122 const ui::DisplayConfigurator::DisplayStateList& displays) override; | |
| 123 void OnDisplayModeChangeFailed( | |
| 124 const ui::DisplayConfigurator::DisplayStateList& displays, | |
| 125 ui::MultipleDisplayState failed_new_state) override; | |
| 126 | |
| 127 // ui::DisplayConfigurator::StateController: | |
| 128 ui::MultipleDisplayState GetStateForDisplayIds( | |
| 129 const ui::DisplayConfigurator::DisplayStateList& display_states) | |
| 130 const override; | |
| 131 bool GetResolutionForDisplayId(int64_t display_id, | |
| 132 gfx::Size* size) const override; | |
| 133 | |
| 134 // mojo::InterfaceFactory<mojom::DisplayController>: | |
| 135 void Create(const service_manager::Identity& remote_identity, | |
| 136 mojom::DisplayControllerRequest request) override; | |
| 137 | |
| 138 // mojo::InterfaceFactory<mojom::TestDisplayController>: | |
| 139 void Create(const service_manager::Identity& remote_identity, | |
| 140 mojom::TestDisplayControllerRequest request) override; | |
| 141 | |
| 142 ui::DisplayConfigurator display_configurator_; | |
| 143 PlatformScreenDelegate* delegate_ = nullptr; | |
| 144 | |
| 145 // If not null it provides a way to modify the display state when running off | |
| 146 // device (eg. running mustash on Linux). | |
| 147 FakeDisplayController* fake_display_controller_ = nullptr; | |
| 148 | |
| 149 // Tracks if we've made a display configuration change and want to wait for | |
| 150 // the display configuration to update before making further changes. | |
| 151 bool wait_for_display_config_update_ = false; | |
| 152 | |
| 153 // TODO(kylechar): These values can/should be replaced by DisplayLayout. | |
| 154 int64_t primary_display_id_ = display::kInvalidDisplayId; | |
| 155 std::vector<DisplayInfo> cached_displays_; | |
| 156 gfx::Point next_display_origin_; | |
| 157 | |
| 158 mojo::BindingSet<mojom::DisplayController> controller_bindings_; | |
| 159 mojo::BindingSet<mojom::TestDisplayController> test_bindings_; | |
| 160 | |
| 161 DISALLOW_COPY_AND_ASSIGN(PlatformScreenOzone); | |
| 162 }; | |
| 163 | |
| 164 } // namespace display | |
| 165 | |
| 166 #endif // SERVICES_UI_DISPLAY_PLATFORM_SCREEN_OZONE_H_ | |
| OLD | NEW |