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 888f20a19d5671e35c3cb89fbbc0482138602942..ba003a0c26d0b4502c4a33fc99ae547063359c16 100644 |
--- a/services/ui/display/platform_screen_ozone.cc |
+++ b/services/ui/display/platform_screen_ozone.cc |
@@ -25,6 +25,26 @@ 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) { |
+ DCHECK(!physical_size.IsEmpty()); |
+ return (pixel_size.width() / static_cast<float>(physical_size.width())) * |
rjkroege
2016/09/21 13:23:46
This might need to be rounded?
kylechar
2016/09/21 16:31:12
Hmm, it's not rounded in DisplayChangeObserver cur
rjkroege
2016/09/23 13:56:23
OK. But I bet that's caused at least one bug. :-)
|
+ kInchInMm; |
+} |
+ |
+float FindDeviceScaleFactor(float dpi) { |
+ if (display::Display::HasForceDeviceScaleFactor()) |
+ return display::Display::GetForcedDeviceScaleFactor(); |
+ |
+ // TODO(kylechar): If dpi > 150 then ash uses 1.25 now. |
+ if (dpi > 200.0) |
+ return 2.0f; |
+ else |
+ return 1.0f; |
+} |
+ |
} // namespace |
// static |
@@ -86,9 +106,9 @@ void PlatformScreenOzone::ToggleVirtualDisplay() { |
return; |
if (cached_displays_.size() == 1) { |
- const gfx::Size& display_size = cached_displays_[0].bounds.size(); |
+ const gfx::Size& pixel_size = cached_displays_[0].pixel_size; |
wait_for_display_config_update_ = |
- fake_display_controller_->AddDisplay(display_size) != |
+ fake_display_controller_->AddDisplay(pixel_size) != |
Display::kInvalidDisplayID; |
} else if (cached_displays_.size() > 1) { |
wait_for_display_config_update_ = |
@@ -131,9 +151,11 @@ void PlatformScreenOzone::ProcessModifiedDisplays( |
auto iter = GetCachedDisplayIterator(snapshot->display_id()); |
if (iter != cached_displays_.end()) { |
DisplayInfo& display_info = *iter; |
- const ui::DisplayMode* current_mode = snapshot->current_mode(); |
- if (current_mode->size() != display_info.bounds.size()) { |
- display_info.bounds.set_size(current_mode->size()); |
+ DisplayInfo new_info = DisplayInfoFromSnapshot(snapshot); |
+ |
+ if (new_info.bounds.size() != display_info.bounds.size() || |
+ new_info.scale_factor != display_info.scale_factor) { |
+ display_info = DisplayInfoFromSnapshot(snapshot); |
display_info.modified = true; |
} |
} |
@@ -162,7 +184,9 @@ void PlatformScreenOzone::UpdateCachedDisplays() { |
// 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); |
+ delegate_->OnDisplayModified(display_info.id, display_info.bounds, |
+ display_info.pixel_size, |
+ display_info.scale_factor); |
} |
++iter; |
} |
@@ -178,18 +202,19 @@ void PlatformScreenOzone::AddNewDisplays( |
if (GetCachedDisplayIterator(id) != cached_displays_.end()) |
continue; |
- const ui::DisplayMode* current_mode = snapshot->current_mode(); |
- gfx::Rect bounds(next_display_origin_, current_mode->size()); |
- |
- // Move the origin so that next display is to the right of current display. |
- next_display_origin_.Offset(current_mode->size().width(), 0); |
- |
// If we have no primary display then this one should be it. |
- if (primary_display_id_ == display::Display::kInvalidDisplayID) |
+ if (primary_display_id_ == Display::kInvalidDisplayID) |
primary_display_id_ = id; |
- cached_displays_.push_back(DisplayInfo(id, bounds)); |
- delegate_->OnDisplayAdded(id, bounds); |
+ DisplayInfo display_info = DisplayInfoFromSnapshot(snapshot); |
+ |
+ // Move the origin so that next display is to the right of current display. |
+ next_display_origin_.Offset(display_info.bounds.width(), 0); |
+ |
+ cached_displays_.push_back(display_info); |
+ delegate_->OnDisplayAdded(display_info.id, display_info.bounds, |
+ display_info.pixel_size, |
+ display_info.scale_factor); |
} |
} |
@@ -210,6 +235,25 @@ void PlatformScreenOzone::OnDisplayModeChanged( |
wait_for_display_config_update_ = false; |
} |
+PlatformScreenOzone::DisplayInfo PlatformScreenOzone::DisplayInfoFromSnapshot( |
+ ui::DisplaySnapshot* snapshot) { |
+ 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.scale_factor = FindDeviceScaleFactor( |
+ ComputeDisplayDPI(current_mode->size(), snapshot->physical_size())); |
+ // Get DIP size based on device scale factor. |
+ display_info.bounds = |
+ gfx::Rect(next_display_origin_, |
+ gfx::ScaleToRoundedSize(current_mode->size(), |
+ 1.0f / display_info.scale_factor)); |
+ |
+ return display_info; |
+} |
+ |
void PlatformScreenOzone::OnDisplayModeChangeFailed( |
const ui::DisplayConfigurator::DisplayStateList& displays, |
ui::MultipleDisplayState failed_new_state) { |