Chromium Code Reviews| Index: services/ui/display/screen_manager_ozone.cc |
| diff --git a/services/ui/display/screen_manager_ozone.cc b/services/ui/display/screen_manager_ozone.cc |
| index fc2d4bc1ef90332ec5cb57209e2c1f110021ceaa..a1a2aa1d58c938e79095c5391dee59ecfbc13ce2 100644 |
| --- a/services/ui/display/screen_manager_ozone.cc |
| +++ b/services/ui/display/screen_manager_ozone.cc |
| @@ -4,7 +4,7 @@ |
| #include "services/ui/display/screen_manager_ozone.h" |
| -#include <memory> |
| +#include <string> |
| #include <utility> |
| #include "base/command_line.h" |
| @@ -13,7 +13,13 @@ |
| #include "base/threading/thread_task_runner_handle.h" |
| #include "services/service_manager/public/cpp/interface_registry.h" |
| #include "third_party/skia/include/core/SkColor.h" |
| +#include "ui/display/manager/chromeos/display_change_observer.h" |
| +#include "ui/display/manager/display_layout_store.h" |
| +#include "ui/display/manager/display_manager_utilities.h" |
| +#include "ui/display/screen.h" |
| +#include "ui/display/screen_base.h" |
| #include "ui/display/types/display_snapshot.h" |
| +#include "ui/display/types/fake_display_controller.h" |
| #include "ui/display/types/native_display_delegate.h" |
| #include "ui/gfx/geometry/rect.h" |
| #include "ui/ozone/public/ozone_platform.h" |
| @@ -24,32 +30,18 @@ namespace { |
| // Needed for DisplayConfigurator::ForceInitialConfigure. |
| const SkColor kChromeOsBootColor = SkColorSetRGB(0xfe, 0xfe, 0xfe); |
| -const float kInchInMm = 25.4f; |
| - |
| -float ComputeDisplayDPI(const gfx::Size& pixel_size, |
| - const gfx::Size& physical_size) { |
| - // The physical_size is broken for some devices, return standard DPI. See |
| - // crbug.com/669554. |
| - if (physical_size.IsEmpty()) { |
| - LOG(ERROR) << "Display has empty phsical_size"; |
| - return 96.0f; |
| - } |
| - |
| - return (pixel_size.width() / static_cast<float>(physical_size.width())) * |
| - kInchInMm; |
| -} |
| - |
| -// Finds the device scale factor based on the display DPI. Will use forced |
| -// device scale factor if provided via command line. |
| -float FindDeviceScaleFactor(float dpi) { |
| - if (Display::HasForceDeviceScaleFactor()) |
| - return Display::GetForcedDeviceScaleFactor(); |
| +void SwapRecursive(const std::map<int64_t, DisplayPlacement*>& id_to_placement, |
|
rjkroege
2016/12/13 23:56:36
Please write more expansive docs about what this d
kylechar
2016/12/16 21:25:08
It's swapping DisplayPlacements owned by the Displ
|
| + int64_t current_primary_id, |
| + int64_t display_id) { |
| + if (display_id == current_primary_id) |
| + return; |
| - // TODO(kylechar): If dpi > 150 then ash uses 1.25 now. Ignoring that for now. |
| - if (dpi > 200.0) |
| - return 2.0f; |
| - else |
| - return 1.0f; |
| + DCHECK(id_to_placement.count(display_id)); |
| + DisplayPlacement* placement = id_to_placement.at(display_id); |
| + DCHECK(placement); |
| + SwapRecursive(id_to_placement, current_primary_id, |
| + placement->parent_display_id); |
| + placement->Swap(); |
| } |
| } // namespace |
| @@ -64,7 +56,71 @@ ScreenManagerOzone::ScreenManagerOzone() {} |
| ScreenManagerOzone::~ScreenManagerOzone() { |
|
rjkroege
2016/12/13 23:56:36
should we insert the configuration of the external
kylechar
2016/12/16 21:25:08
Maybe.. You mean shit+ctrl+f2 console right? Isn't
|
| // We are shutting down and don't want to make anymore display changes. |
| fake_display_controller_ = nullptr; |
| - display_configurator_.RemoveObserver(this); |
| + |
| + if (display_manager_) |
| + display_manager_->RemoveObserver(this); |
| + |
| + if (display_change_observer_) { |
| + display_configurator_.RemoveObserver(display_change_observer_.get()); |
| + display_change_observer_.reset(); |
| + } |
| + |
| + if (display_manager_) |
| + display_manager_.reset(); |
| +} |
| + |
| +void ScreenManagerOzone::SetPrimaryDisplayId(int64_t display_id) { |
| + DCHECK_NE(kInvalidDisplayId, display_id); |
| + if (primary_display_id_ == display_id) |
| + return; |
| + |
| + const Display& new_primary_display = |
| + display_manager_->GetDisplayForId(display_id); |
| + if (!new_primary_display.is_valid()) { |
| + LOG(ERROR) << "Invalid or non-existent display is requested:" |
| + << new_primary_display.ToString(); |
| + return; |
| + } |
| + |
| + int64_t old_primary_display_id = primary_display_id_; |
| + |
| + const DisplayLayout& layout = display_manager_->GetCurrentDisplayLayout(); |
| + // The requested primary id can be same as one in the stored layout |
| + // when the primary id is set after new displays are connected. |
| + // Only update the layout if it is requested to swap primary display. |
| + if (layout.primary_id != new_primary_display.id()) { |
| + std::unique_ptr<DisplayLayout> swapped_layout(layout.Copy()); |
| + |
| + std::map<int64_t, DisplayPlacement*> id_to_placement; |
| + for (auto& placement : swapped_layout->placement_list) |
| + id_to_placement[placement.display_id] = &placement; |
| + SwapRecursive(id_to_placement, primary_display_id_, |
| + new_primary_display.id()); |
| + |
| + std::sort(swapped_layout->placement_list.begin(), |
| + swapped_layout->placement_list.end(), |
| + [](const DisplayPlacement& d1, const DisplayPlacement& d2) { |
| + return d1.display_id < d2.display_id; |
| + }); |
| + |
| + swapped_layout->primary_id = new_primary_display.id(); |
| + DisplayIdList list = display_manager_->GetCurrentDisplayIdList(); |
| + display_manager_->layout_store()->RegisterLayoutForDisplayIdList( |
| + list, std::move(swapped_layout)); |
| + } |
| + |
| + primary_display_id_ = new_primary_display.id(); |
| + screen_->display_list().UpdateDisplay(new_primary_display, |
| + DisplayList::Type::PRIMARY); |
| + |
| + // Force updating display bounds for new primary display. |
| + display_manager_->set_force_bounds_changed(true); |
| + display_manager_->UpdateDisplays(); |
| + display_manager_->set_force_bounds_changed(false); |
| + |
| + DVLOG(1) << "Primary display changed from " << old_primary_display_id |
| + << " to " << primary_display_id_; |
| + delegate_->OnPrimaryDisplayChanged(primary_display_id_); |
| } |
| void ScreenManagerOzone::AddInterfaces( |
| @@ -77,36 +133,55 @@ void ScreenManagerOzone::Init(ScreenManagerDelegate* delegate) { |
| DCHECK(delegate); |
| delegate_ = delegate; |
| - std::unique_ptr<ui::NativeDisplayDelegate> native_display_delegate = |
| - ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); |
| + // Tests may inject a NDD, otherwise get it from OzonePlatform. |
| + if (!native_display_delegate_) { |
| + native_display_delegate_ = |
| + ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(); |
| + } |
| // The FakeDisplayController gives us a way to make the NativeDisplayDelegate |
| // pretend something display related has happened. |
| if (!base::SysInfo::IsRunningOnChromeOS()) { |
| fake_display_controller_ = |
| - native_display_delegate->GetFakeDisplayController(); |
| + native_display_delegate_->GetFakeDisplayController(); |
| } |
| + // Create a new Screen instance. |
| + std::unique_ptr<ScreenBase> screen = base::MakeUnique<ScreenBase>(); |
| + Screen::SetScreenInstance(screen.get()); |
| + screen_ = screen.get(); |
| + |
| + // Configure display manager. ScreenManager acts as an observer to find out |
| + // display changes and as a delegate to find out when changes start/stop. |
| + display_manager_ = base::MakeUnique<DisplayManager>(std::move(screen)); |
| + display_manager_->set_configure_displays(true); |
| + display_manager_->AddObserver(this); |
| + display_manager_->set_delegate(this); |
| + |
| + // DisplayChangeObserver observes DisplayConfigurator and sends updates to |
| + // DisplayManager. |
| + display_change_observer_ = base::MakeUnique<DisplayChangeObserver>( |
| + &display_configurator_, display_manager_.get()); |
| + |
| // We want display configuration to happen even off device to keep the control |
| // flow similar. |
| display_configurator_.set_configure_display(true); |
| - display_configurator_.AddObserver(this); |
| - display_configurator_.set_state_controller(this); |
| - display_configurator_.Init(std::move(native_display_delegate), false); |
| + display_configurator_.AddObserver(display_change_observer_.get()); |
| + display_configurator_.set_state_controller(display_change_observer_.get()); |
| + display_configurator_.set_mirroring_controller(display_manager_.get()); |
| + |
| + // Perform initial configuration. |
| + display_configurator_.Init(std::move(native_display_delegate_), false); |
| display_configurator_.ForceInitialConfigure(kChromeOsBootColor); |
| } |
| void ScreenManagerOzone::RequestCloseDisplay(int64_t display_id) { |
| - if (!fake_display_controller_ || wait_for_display_config_update_) |
| + if (!fake_display_controller_) |
| return; |
| - CachedDisplayIterator iter = GetCachedDisplayIterator(display_id); |
| - if (iter != cached_displays_.end()) { |
| - // Tell the NDD to remove the display. ScreenManager will get an update |
| - // that the display configuration has changed and the display will be gone. |
| - wait_for_display_config_update_ = |
| - fake_display_controller_->RemoveDisplay(iter->id); |
| - } |
| + // Tell the NDD to remove the display. ScreenManager will get an update |
| + // that the display configuration has changed and the display will be gone. |
| + fake_display_controller_->RemoveDisplay(display_id); |
| } |
| int64_t ScreenManagerOzone::GetPrimaryDisplayId() const { |
| @@ -114,49 +189,61 @@ int64_t ScreenManagerOzone::GetPrimaryDisplayId() const { |
| } |
| void ScreenManagerOzone::ToggleAddRemoveDisplay() { |
| - if (!fake_display_controller_ || wait_for_display_config_update_) |
| + if (!fake_display_controller_) |
| return; |
| - |
| - if (cached_displays_.size() == 1) { |
| - const gfx::Size& pixel_size = cached_displays_[0].metrics.pixel_size; |
| - wait_for_display_config_update_ = |
| - fake_display_controller_->AddDisplay(pixel_size) != kInvalidDisplayId; |
| - } else if (cached_displays_.size() > 1) { |
| - wait_for_display_config_update_ = |
| - fake_display_controller_->RemoveDisplay(cached_displays_.back().id); |
| - } else { |
| - NOTREACHED(); |
| + DVLOG(1) << "ToggleAddRemoveDisplay"; |
| + |
| + int num_displays = display_manager_->GetNumDisplays(); |
| + if (num_displays == 1) { |
| + const gfx::Size& pixel_size = |
| + display_manager_->GetDisplayInfo(display_manager_->GetDisplayAt(0).id()) |
| + .bounds_in_native() |
| + .size(); |
| + fake_display_controller_->AddDisplay(pixel_size); |
| + } else if (num_displays > 1) { |
| + DisplayIdList displays = display_manager_->GetCurrentDisplayIdList(); |
| + fake_display_controller_->RemoveDisplay(displays.back()); |
| } |
| } |
| void ScreenManagerOzone::ToggleDisplayResolution() { |
| - DisplayInfo& display = cached_displays_[0]; |
| - |
| - // Toggle the display size to use. |
| - size_t num_sizes = display.supported_sizes.size(); |
| - for (size_t i = 0; i < num_sizes; i++) { |
| - if (display.supported_sizes[i] == display.requested_size) { |
| - if (i + 1 == num_sizes) |
| - display.requested_size = display.supported_sizes[0]; |
| - else |
| - display.requested_size = display.supported_sizes[i + 1]; |
| - break; |
| - } |
| - } |
| + if (primary_display_id_ == kInvalidDisplayId) |
| + return; |
| + |
| + // Internal displays don't have alternate resolutions. |
| + if (Display::HasInternalDisplay() && |
|
rjkroege
2016/12/13 23:56:36
Observation not needing to be addressed: why is Ha
kylechar
2016/12/16 21:25:08
That would make things too easy probably :)
|
| + primary_display_id_ == Display::InternalDisplayId()) |
| + return; |
| + |
| + DVLOG(1) << "ToggleDisplayResolution"; |
| + |
| + const ManagedDisplayInfo& info = |
|
rjkroege
2016/12/13 23:56:36
Managed* should (ideally) become an internal detai
kylechar
2016/12/16 21:25:08
I don't think we'll be able to get away from using
|
| + display_manager_->GetDisplayInfo(primary_display_id_); |
| + scoped_refptr<ManagedDisplayMode> mode = |
| + GetDisplayModeForNextResolution(info, true); |
| - display_configurator_.OnConfigurationChanged(); |
| + // Loop back to first mode from last. |
| + if (mode->size() == info.bounds_in_native().size()) |
| + mode = info.display_modes()[0]; |
| + |
| + // Set mode only if it's different from current. |
| + if (mode->size() != info.bounds_in_native().size()) |
| + display_manager_->SetDisplayMode(primary_display_id_, mode); |
| } |
| void ScreenManagerOzone::IncreaseInternalDisplayZoom() { |
| - NOTIMPLEMENTED(); |
| + if (Display::HasInternalDisplay()) |
| + display_manager_->ZoomInternalDisplay(false); |
| } |
| void ScreenManagerOzone::DecreaseInternalDisplayZoom() { |
| - NOTIMPLEMENTED(); |
| + if (Display::HasInternalDisplay()) |
| + display_manager_->ZoomInternalDisplay(true); |
| } |
| void ScreenManagerOzone::ResetInternalDisplayZoom() { |
| - NOTIMPLEMENTED(); |
| + if (Display::HasInternalDisplay()) |
| + display_manager_->ResetInternalDisplayZoom(); |
| } |
| void ScreenManagerOzone::RotateCurrentDisplayCW() { |
| @@ -164,27 +251,20 @@ void ScreenManagerOzone::RotateCurrentDisplayCW() { |
| } |
| void ScreenManagerOzone::SwapPrimaryDisplay() { |
| - const size_t num_displays = cached_displays_.size(); |
| - if (num_displays <= 1) |
| + // Can't swap if there is only 1 display and swapping isn't supported for 3 or |
| + // more displays. |
| + if (display_manager_->GetNumDisplays() != 2) |
| return; |
| - // Find index of current primary display. |
| - size_t primary_display_index = 0; |
| - for (size_t i = 0; i < num_displays; i++) { |
| - if (cached_displays_[i].id == primary_display_id_) { |
| - primary_display_index = i; |
| - break; |
| - } |
| - } |
| + DVLOG(1) << "SwapPrimaryDisplay()"; |
| - // Set next display index as primary, or loop back to first display if last. |
| - if (primary_display_index + 1 == num_displays) { |
| - primary_display_id_ = cached_displays_[0].id; |
| - } else { |
| - primary_display_id_ = cached_displays_[primary_display_index + 1].id; |
| - } |
| + DisplayIdList display_ids = display_manager_->GetCurrentDisplayIdList(); |
| - delegate_->OnPrimaryDisplayChanged(primary_display_id_); |
| + // Find the next primary display. |
| + if (primary_display_id_ == display_ids[0]) |
| + SetPrimaryDisplayId(display_ids[1]); |
| + else |
| + SetPrimaryDisplayId(display_ids[0]); |
| } |
| void ScreenManagerOzone::ToggleMirrorMode() { |
| @@ -194,216 +274,98 @@ void ScreenManagerOzone::ToggleMirrorMode() { |
| void ScreenManagerOzone::SetDisplayWorkArea(int64_t display_id, |
| const gfx::Size& size, |
| const gfx::Insets& insets) { |
| - CachedDisplayIterator iter = GetCachedDisplayIterator(display_id); |
| - if (iter == cached_displays_.end()) { |
| - NOTREACHED() << display_id; |
| - return; |
| - } |
| - |
| - DisplayInfo& display_info = *iter; |
| - if (display_info.metrics.bounds.size() == size) { |
| - gfx::Rect new_work_area = display_info.metrics.bounds; |
| - new_work_area.Inset(insets); |
| - |
| - if (new_work_area != display_info.metrics.work_area) { |
| - display_info.last_work_area_insets = insets; |
| - display_info.metrics.work_area = new_work_area; |
| - display_info.modified = true; |
| - UpdateCachedDisplays(); |
| - } |
| - } |
| -} |
| - |
| -ScreenManagerOzone::DisplayInfo::DisplayInfo() = default; |
| -ScreenManagerOzone::DisplayInfo::DisplayInfo(const DisplayInfo& other) = |
| - default; |
| -ScreenManagerOzone::DisplayInfo::~DisplayInfo() = default; |
| - |
| -void ScreenManagerOzone::ProcessRemovedDisplays( |
| - const ui::DisplayConfigurator::DisplayStateList& snapshots) { |
| - std::vector<int64_t> current_ids; |
| - for (ui::DisplaySnapshot* snapshot : snapshots) |
| - current_ids.push_back(snapshot->display_id()); |
| - |
| - // Find cached displays with no matching snapshot and mark as removed. |
| - for (DisplayInfo& display : cached_displays_) { |
| - if (std::find(current_ids.begin(), current_ids.end(), display.id) == |
| - current_ids.end()) { |
| - display.removed = true; |
| - if (primary_display_id_ == display.id) |
| - primary_display_id_ = kInvalidDisplayId; |
| - } |
| - } |
| + // TODO(kylechar): Check the size of the display matches the current size. |
| + display_manager_->UpdateWorkAreaOfDisplay(display_id, insets); |
| } |
| -void ScreenManagerOzone::ProcessModifiedDisplays( |
| - const ui::DisplayConfigurator::DisplayStateList& snapshots) { |
| - for (ui::DisplaySnapshot* snapshot : snapshots) { |
| - auto iter = GetCachedDisplayIterator(snapshot->display_id()); |
| - if (iter != cached_displays_.end()) { |
| - DisplayInfo& display_info = *iter; |
| - ViewportMetrics new_metrics = |
| - MetricsFromSnapshot(*snapshot, display_info.metrics.bounds.origin()); |
| - new_metrics.work_area.Inset(display_info.last_work_area_insets); |
| - |
| - if (new_metrics != display_info.metrics) { |
| - display_info.metrics = new_metrics; |
| - display_info.modified = true; |
| - } |
| - } |
| - } |
| +void ScreenManagerOzone::Create( |
| + const service_manager::Identity& remote_identity, |
| + mojom::DisplayControllerRequest request) { |
| + controller_bindings_.AddBinding(this, std::move(request)); |
| } |
| -void ScreenManagerOzone::UpdateCachedDisplays() { |
| - // Walk through cached displays after processing the snapshots to find any |
| - // removed or modified displays. This ensures that we only send one update per |
| - // display to the delegate. |
| - next_display_origin_.SetPoint(0, 0); |
| - for (auto iter = cached_displays_.begin(); iter != cached_displays_.end();) { |
| - DisplayInfo& display_info = *iter; |
| - if (display_info.removed) { |
| - // Update delegate and remove from cache. |
| - delegate_->OnDisplayRemoved(display_info.id); |
| - iter = cached_displays_.erase(iter); |
| - } else { |
| - // Check if the display origin needs to be updated. |
| - if (next_display_origin_ != display_info.metrics.bounds.origin()) { |
| - display_info.metrics.bounds.set_origin(next_display_origin_); |
| - display_info.metrics.work_area.set_origin(next_display_origin_); |
| - display_info.modified = true; |
| - } |
| - next_display_origin_.Offset(display_info.metrics.bounds.width(), 0); |
| - |
| - // Check if the window bounds have changed and update delegate. |
| - if (display_info.modified) { |
| - display_info.modified = false; |
| - delegate_->OnDisplayModified(display_info.id, display_info.metrics); |
| - } |
| - ++iter; |
| - } |
| - } |
| +void ScreenManagerOzone::Create( |
| + const service_manager::Identity& remote_identity, |
| + mojom::TestDisplayControllerRequest request) { |
| + test_bindings_.AddBinding(this, std::move(request)); |
| } |
| -void ScreenManagerOzone::AddNewDisplays( |
| - const ui::DisplayConfigurator::DisplayStateList& snapshots) { |
| - for (ui::DisplaySnapshot* snapshot : snapshots) { |
| - const int64_t id = snapshot->display_id(); |
| +ViewportMetrics ScreenManagerOzone::GetViewportMetricsForDisplay( |
| + const Display& display) { |
| + const ManagedDisplayInfo& managed_info = |
|
rjkroege
2016/12/13 23:56:36
same comment about ManagedDisplayInfo as above.
|
| + display_manager_->GetDisplayInfo(display.id()); |
| - // Check if display already exists and skip. |
| - if (GetCachedDisplayIterator(id) != cached_displays_.end()) |
| - continue; |
| - |
| - DisplayInfo display_info; |
| - display_info.id = snapshot->display_id(); |
| - display_info.metrics = MetricsFromSnapshot(*snapshot, next_display_origin_); |
| - |
| - // Store the display mode sizes so we can toggle through them. |
| - for (auto& mode : snapshot->modes()) { |
| - display_info.supported_sizes.push_back(mode->size()); |
| - if (mode.get() == snapshot->current_mode()) |
| - display_info.requested_size = mode->size(); |
| - } |
| - |
| - // Move the origin so that next display is to the right of current display. |
| - next_display_origin_.Offset(display_info.metrics.bounds.width(), 0); |
| - |
| - cached_displays_.push_back(display_info); |
| - delegate_->OnDisplayAdded(display_info.id, display_info.metrics); |
| + ViewportMetrics metrics; |
| + metrics.bounds = display.bounds(); |
| + metrics.work_area = display.work_area(); |
| + metrics.pixel_size = managed_info.bounds_in_native().size(); |
| + metrics.rotation = display.rotation(); |
| + metrics.touch_support = display.touch_support(); |
| + metrics.device_scale_factor = display.device_scale_factor(); |
| + metrics.ui_scale_factor = managed_info.configured_ui_scale(); |
| - // If we have no primary display then this one should be it. |
| - if (primary_display_id_ == kInvalidDisplayId) { |
| - primary_display_id_ = id; |
| - delegate_->OnPrimaryDisplayChanged(primary_display_id_); |
| - } |
| - } |
| + return metrics; |
| } |
| -ScreenManagerOzone::CachedDisplayIterator |
| -ScreenManagerOzone::GetCachedDisplayIterator(int64_t display_id) { |
| - return std::find_if(cached_displays_.begin(), cached_displays_.end(), |
| - [display_id](const DisplayInfo& display_info) { |
| - return display_info.id == display_id; |
| - }); |
| +void ScreenManagerOzone::CreateOrUpdateMirroringDisplay( |
| + const DisplayInfoList& display_info_list) { |
| + NOTIMPLEMENTED(); |
| } |
| -ViewportMetrics ScreenManagerOzone::MetricsFromSnapshot( |
| - const ui::DisplaySnapshot& snapshot, |
| - const gfx::Point& origin) { |
| - const ui::DisplayMode* current_mode = snapshot.current_mode(); |
| - DCHECK(current_mode); |
| - |
| - ViewportMetrics metrics; |
| - metrics.pixel_size = current_mode->size(); |
| - metrics.device_scale_factor = FindDeviceScaleFactor( |
| - ComputeDisplayDPI(current_mode->size(), snapshot.physical_size())); |
| - // Get DIP size based on device scale factor. We are assuming the |
| - // ui scale factor is always 1.0 here for now. |
| - gfx::Size scaled_size = gfx::ScaleToRoundedSize( |
| - current_mode->size(), 1.0f / metrics.device_scale_factor); |
| - metrics.bounds = gfx::Rect(origin, scaled_size); |
| - metrics.work_area = metrics.bounds; |
| - return metrics; |
| +void ScreenManagerOzone::CloseMirroringDisplayIfNotNecessary() { |
| + NOTIMPLEMENTED(); |
| } |
| -void ScreenManagerOzone::OnDisplayModeChanged( |
| - const ui::DisplayConfigurator::DisplayStateList& displays) { |
| - ProcessRemovedDisplays(displays); |
| - ProcessModifiedDisplays(displays); |
| +void ScreenManagerOzone::PreDisplayConfigurationChange(bool clear_focus) { |
| + DVLOG(1) << "PreDisplayConfigurationChange"; |
| +} |
| - // If the primary display is marked as removed we'll try to find a new primary |
| - // display and update the delegate before removing the old primary display. |
| +void ScreenManagerOzone::PostDisplayConfigurationChange( |
|
rjkroege
2016/12/13 23:56:36
I think we need some UML sequence diagrams for thi
kylechar
2016/12/16 21:25:08
Agreed :)
|
| + bool must_clear_window) { |
| + // Set primary display if not set yet. |
| if (primary_display_id_ == kInvalidDisplayId) { |
| - for (const DisplayInfo& display : cached_displays_) { |
| - if (!display.removed) { |
| - primary_display_id_ = display.id; |
| - delegate_->OnPrimaryDisplayChanged(primary_display_id_); |
| - break; |
| - } |
| + const Display& primary_display = |
| + display_manager_->GetPrimaryDisplayCandidate(); |
| + if (primary_display.is_valid()) { |
| + primary_display_id_ = primary_display.id(); |
| + DVLOG(1) << "Set primary display to " << primary_display_id_; |
| + screen_->display_list().UpdateDisplay(primary_display, |
| + DisplayList::Type::PRIMARY); |
| + delegate_->OnPrimaryDisplayChanged(primary_display_id_); |
| } |
| } |
| - UpdateCachedDisplays(); |
| - AddNewDisplays(displays); |
| - |
| - wait_for_display_config_update_ = false; |
| + DVLOG(1) << "PostDisplayConfigurationChange"; |
| } |
| -void ScreenManagerOzone::OnDisplayModeChangeFailed( |
| - const ui::DisplayConfigurator::DisplayStateList& displays, |
| - ui::MultipleDisplayState failed_new_state) { |
| - LOG(ERROR) << "OnDisplayModeChangeFailed from DisplayConfigurator"; |
| - wait_for_display_config_update_ = false; |
| +ui::DisplayConfigurator* ScreenManagerOzone::display_configurator() { |
| + return &display_configurator_; |
| } |
| -void ScreenManagerOzone::Create( |
| - const service_manager::Identity& remote_identity, |
| - mojom::DisplayControllerRequest request) { |
| - controller_bindings_.AddBinding(this, std::move(request)); |
| -} |
| - |
| -ui::MultipleDisplayState ScreenManagerOzone::GetStateForDisplayIds( |
| - const ui::DisplayConfigurator::DisplayStateList& display_states) const { |
| - return (display_states.size() == 1 |
| - ? ui::MULTIPLE_DISPLAY_STATE_SINGLE |
| - : ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED); |
| +void ScreenManagerOzone::OnDisplayAdded(const Display& display) { |
| + ViewportMetrics metrics = GetViewportMetricsForDisplay(display); |
| + DVLOG(1) << "OnDisplayAdded " << display.ToString() << ", " |
| + << metrics.ToString(); |
| + screen_->display_list().AddDisplay(display, DisplayList::Type::NOT_PRIMARY); |
| + delegate_->OnDisplayAdded(display.id(), metrics); |
| } |
| -bool ScreenManagerOzone::GetResolutionForDisplayId(int64_t display_id, |
| - gfx::Size* size) const { |
| - for (const DisplayInfo& display : cached_displays_) { |
| - if (display.id == display_id) { |
| - *size = display.requested_size; |
| - return true; |
| - } |
| - } |
| +void ScreenManagerOzone::OnDisplayRemoved(const Display& display) { |
| + // TODO(kylechar): If we're removing the primary display we need to first set |
| + // a new primary display. This will crash until then. |
| - return false; |
| + DVLOG(1) << "OnDisplayRemoved " << display.ToString(); |
| + screen_->display_list().RemoveDisplay(display.id()); |
| + delegate_->OnDisplayRemoved(display.id()); |
| } |
| -void ScreenManagerOzone::Create( |
| - const service_manager::Identity& remote_identity, |
| - mojom::TestDisplayControllerRequest request) { |
| - test_bindings_.AddBinding(this, std::move(request)); |
| +void ScreenManagerOzone::OnDisplayMetricsChanged(const Display& display, |
| + uint32_t changed_metrics) { |
| + ViewportMetrics metrics = GetViewportMetricsForDisplay(display); |
| + DVLOG(1) << "OnDisplayModified " << display.ToString() << ", " |
| + << metrics.ToString(); |
| + screen_->display_list().UpdateDisplay(display); |
| + delegate_->OnDisplayModified(display.id(), metrics); |
| } |
| } // namespace display |