Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: services/ui/display/platform_screen_ozone.cc

Issue 2434923002: Handle modified displays in mustash. (Closed)
Patch Set: Fix PlatformScreenStub for tests. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/ui/display/platform_screen_ozone.h ('k') | services/ui/display/platform_screen_ozone_unittests.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/display/platform_screen_ozone.cc
diff --git a/services/ui/display/platform_screen_ozone.cc b/services/ui/display/platform_screen_ozone.cc
index 664402847e820bc95fc30949302f3d1bd3e3c5b6..127fcd8f90ff2b9eb9f541e49c1b074d00587fb7 100644
--- a/services/ui/display/platform_screen_ozone.cc
+++ b/services/ui/display/platform_screen_ozone.cc
@@ -86,6 +86,7 @@ void PlatformScreenOzone::Init(PlatformScreenDelegate* delegate) {
// 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_.ForceInitialConfigure(kChromeOsBootColor);
}
@@ -112,7 +113,7 @@ void PlatformScreenOzone::ToggleAddRemoveDisplay() {
return;
if (cached_displays_.size() == 1) {
- const gfx::Size& pixel_size = cached_displays_[0].pixel_size;
+ const gfx::Size& pixel_size = cached_displays_[0].metrics.pixel_size;
wait_for_display_config_update_ =
fake_display_controller_->AddDisplay(pixel_size) !=
Display::kInvalidDisplayID;
@@ -124,6 +125,24 @@ void PlatformScreenOzone::ToggleAddRemoveDisplay() {
}
}
+void PlatformScreenOzone::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;
+ }
+ }
+
+ display_configurator_.OnConfigurationChanged();
+}
+
void PlatformScreenOzone::SwapPrimaryDisplay() {
const size_t num_displays = cached_displays_.size();
if (num_displays <= 1)
@@ -158,11 +177,24 @@ void PlatformScreenOzone::SetDisplayWorkArea(int64_t display_id,
}
DisplayInfo& display_info = *iter;
- if (display_info.bounds.size() == size) {
- // TODO(kylechar): Change workarea and update ws::DisplayManager.
+ 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();
+ }
}
}
+PlatformScreenOzone::DisplayInfo::DisplayInfo() = default;
+PlatformScreenOzone::DisplayInfo::DisplayInfo(const DisplayInfo& other) =
+ default;
+PlatformScreenOzone::DisplayInfo::~DisplayInfo() = default;
+
void PlatformScreenOzone::ProcessRemovedDisplays(
const ui::DisplayConfigurator::DisplayStateList& snapshots) {
std::vector<int64_t> current_ids;
@@ -196,11 +228,12 @@ void PlatformScreenOzone::ProcessModifiedDisplays(
auto iter = GetCachedDisplayIterator(snapshot->display_id());
if (iter != cached_displays_.end()) {
DisplayInfo& display_info = *iter;
- DisplayInfo new_info = DisplayInfoFromSnapshot(*snapshot);
+ ViewportMetrics new_metrics =
+ MetricsFromSnapshot(*snapshot, display_info.metrics.bounds.origin());
+ new_metrics.work_area.Inset(display_info.last_work_area_insets);
- if (new_info.bounds.size() != display_info.bounds.size() ||
- new_info.device_scale_factor != display_info.device_scale_factor) {
- display_info = new_info;
+ if (new_metrics != display_info.metrics) {
+ display_info.metrics = new_metrics;
display_info.modified = true;
}
}
@@ -220,18 +253,17 @@ void PlatformScreenOzone::UpdateCachedDisplays() {
iter = cached_displays_.erase(iter);
} else {
// Check if the display origin needs to be updated.
- if (next_display_origin_ != display_info.bounds.origin()) {
- display_info.bounds.set_origin(next_display_origin_);
+ 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.bounds.width(), 0);
+ 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.bounds,
- display_info.pixel_size,
- display_info.device_scale_factor);
+ delegate_->OnDisplayModified(display_info.id, display_info.metrics);
}
++iter;
}
@@ -251,15 +283,22 @@ void PlatformScreenOzone::AddNewDisplays(
if (primary_display_id_ == Display::kInvalidDisplayID)
primary_display_id_ = id;
- DisplayInfo display_info = DisplayInfoFromSnapshot(*snapshot);
+ 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.bounds.width(), 0);
+ next_display_origin_.Offset(display_info.metrics.bounds.width(), 0);
cached_displays_.push_back(display_info);
- delegate_->OnDisplayAdded(display_info.id, display_info.bounds,
- display_info.pixel_size,
- display_info.device_scale_factor);
+ delegate_->OnDisplayAdded(display_info.id, display_info.metrics);
}
}
@@ -271,22 +310,23 @@ PlatformScreenOzone::GetCachedDisplayIterator(int64_t display_id) {
});
}
-PlatformScreenOzone::DisplayInfo PlatformScreenOzone::DisplayInfoFromSnapshot(
- const ui::DisplaySnapshot& snapshot) {
+ViewportMetrics PlatformScreenOzone::MetricsFromSnapshot(
+ const ui::DisplaySnapshot& snapshot,
+ const gfx::Point& origin) {
const ui::DisplayMode* current_mode = snapshot.current_mode();
DCHECK(current_mode);
- DisplayInfo display_info;
- display_info.id = snapshot.display_id();
- display_info.pixel_size = current_mode->size();
- display_info.device_scale_factor = FindDeviceScaleFactor(
+ 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 / display_info.device_scale_factor);
- display_info.bounds = gfx::Rect(next_display_origin_, scaled_size);
- return display_info;
+ current_mode->size(), 1.0f / metrics.device_scale_factor);
+ metrics.bounds = gfx::Rect(origin, scaled_size);
+ metrics.work_area = metrics.bounds;
+ return metrics;
}
void PlatformScreenOzone::OnDisplayModeChanged(
@@ -311,6 +351,25 @@ void PlatformScreenOzone::Create(
controller_bindings_.AddBinding(this, std::move(request));
}
+ui::MultipleDisplayState PlatformScreenOzone::GetStateForDisplayIds(
+ const ui::DisplayConfigurator::DisplayStateList& display_states) const {
+ return (display_states.size() == 1
+ ? ui::MULTIPLE_DISPLAY_STATE_SINGLE
+ : ui::MULTIPLE_DISPLAY_STATE_DUAL_EXTENDED);
+}
+
+bool PlatformScreenOzone::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;
+ }
+ }
+
+ return false;
+}
+
void PlatformScreenOzone::Create(
const service_manager::Identity& remote_identity,
mojom::TestDisplayControllerRequest request) {
« no previous file with comments | « services/ui/display/platform_screen_ozone.h ('k') | services/ui/display/platform_screen_ozone_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698