Commit a260fe4b authored by Alexander Dunaev's avatar Alexander Dunaev Committed by Commit Bot

[ozone/wayland] Fixed handling of forced scale factor in the display.

Accessor methods for the display::Display::device_scale_factor_ don't respect
the forced device scale factor, which causes bugs in some scenarios.

This CL fixes the setter so it only sets the value if there is no forced one.

Bug: 910797
Change-Id: Ib9c3e6b2f8dacba5da424af40c71001c674feda4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1613986
Auto-Submit: Alexander Dunaev <adunaev@igalia.com>
Commit-Queue: Dominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660724}
parent abbb8f34
...@@ -166,7 +166,7 @@ void BrowserCompositorMac::UpdateSurfaceFromChild( ...@@ -166,7 +166,7 @@ void BrowserCompositorMac::UpdateSurfaceFromChild(
const viz::LocalSurfaceIdAllocation& child_local_surface_id_allocation) { const viz::LocalSurfaceIdAllocation& child_local_surface_id_allocation) {
if (dfh_local_surface_id_allocator_.UpdateFromChild( if (dfh_local_surface_id_allocator_.UpdateFromChild(
child_local_surface_id_allocation)) { child_local_surface_id_allocation)) {
dfh_display_.set_device_scale_factor(new_device_scale_factor); dfh_display_.SetDeviceScaleFactor(new_device_scale_factor);
dfh_size_dip_ = gfx::ConvertSizeToDIP(dfh_display_.device_scale_factor(), dfh_size_dip_ = gfx::ConvertSizeToDIP(dfh_display_.device_scale_factor(),
new_size_in_pixels); new_size_in_pixels);
dfh_size_pixels_ = new_size_in_pixels; dfh_size_pixels_ = new_size_in_pixels;
...@@ -402,7 +402,7 @@ void BrowserCompositorMac::SetParentUiLayer(ui::Layer* new_parent_ui_layer) { ...@@ -402,7 +402,7 @@ void BrowserCompositorMac::SetParentUiLayer(ui::Layer* new_parent_ui_layer) {
bool BrowserCompositorMac::ForceNewSurfaceForTesting() { bool BrowserCompositorMac::ForceNewSurfaceForTesting() {
display::Display new_display(dfh_display_); display::Display new_display(dfh_display_);
new_display.set_device_scale_factor(new_display.device_scale_factor() * 2.0f); new_display.SetDeviceScaleFactor(new_display.device_scale_factor() * 2.0f);
return UpdateSurfaceFromNSView(dfh_size_dip_, new_display); return UpdateSurfaceFromNSView(dfh_size_dip_, new_display);
} }
......
...@@ -126,7 +126,7 @@ TEST(WebCursorTest, CursorScaleFactor) { ...@@ -126,7 +126,7 @@ TEST(WebCursorTest, CursorScaleFactor) {
WebCursor cursor(info); WebCursor cursor(info);
display::Display display; display::Display display;
display.set_device_scale_factor(4.2f); display.SetDeviceScaleFactor(4.2f);
cursor.SetDisplayInfo(display); cursor.SetDisplayInfo(display);
#if defined(USE_OZONE) #if defined(USE_OZONE)
...@@ -171,7 +171,7 @@ void ScaleCursor(float scale, int hotspot_x, int hotspot_y) { ...@@ -171,7 +171,7 @@ void ScaleCursor(float scale, int hotspot_x, int hotspot_y) {
WebCursor cursor(info); WebCursor cursor(info);
display::Display display; display::Display display;
display.set_device_scale_factor(scale); display.SetDeviceScaleFactor(scale);
cursor.SetDisplayInfo(display); cursor.SetDisplayInfo(display);
HCURSOR windows_cursor_handle = cursor.GetNativeCursor().platform(); HCURSOR windows_cursor_handle = cursor.GetNativeCursor().platform();
......
...@@ -79,7 +79,7 @@ void DisplayAndroidManager::DoUpdateDisplay(display::Display* display, ...@@ -79,7 +79,7 @@ void DisplayAndroidManager::DoUpdateDisplay(display::Display* display,
int bitsPerComponent, int bitsPerComponent,
bool isWideColorGamut) { bool isWideColorGamut) {
if (!Display::HasForceDeviceScaleFactor()) if (!Display::HasForceDeviceScaleFactor())
display->set_device_scale_factor(dipScale); display->SetDeviceScaleFactor(dipScale);
if (!Display::HasForceDisplayColorProfile()) { if (!Display::HasForceDisplayColorProfile()) {
if (isWideColorGamut) { if (isWideColorGamut) {
display->set_color_space(gfx::ColorSpace::CreateDisplayP3D65()); display->set_color_space(gfx::ColorSpace::CreateDisplayP3D65());
......
...@@ -228,6 +228,12 @@ Display Display::GetDefaultDisplay() { ...@@ -228,6 +228,12 @@ Display Display::GetDefaultDisplay() {
return Display(kDefaultDisplayId, gfx::Rect(0, 0, 1920, 1080)); return Display(kDefaultDisplayId, gfx::Rect(0, 0, 1920, 1080));
} }
void Display::SetDeviceScaleFactor(float scale) {
if (HasForceDeviceScaleFactor())
return;
device_scale_factor_ = scale;
}
int Display::RotationAsDegree() const { int Display::RotationAsDegree() const {
switch (rotation_) { switch (rotation_) {
case ROTATE_0: case ROTATE_0:
......
...@@ -148,12 +148,12 @@ class DISPLAY_EXPORT Display final { ...@@ -148,12 +148,12 @@ class DISPLAY_EXPORT Display final {
const gfx::Rect& work_area() const { return work_area_; } const gfx::Rect& work_area() const { return work_area_; }
void set_work_area(const gfx::Rect& work_area) { work_area_ = work_area; } void set_work_area(const gfx::Rect& work_area) { work_area_ = work_area; }
// Output device's pixel scale factor. This specifies how much the // Pixel scale factor. This specifies how much the UI should be scaled when
// UI should be scaled when the actual output has more pixels than // rendering on the actual output. This is needed when the latter has more
// standard displays (which is around 100~120dpi.) The potential return // pixels than standard displays (which is around 100~120dpi). The potential
// values depend on each platforms. // return values depend on each platforms.
float device_scale_factor() const { return device_scale_factor_; } float device_scale_factor() const { return device_scale_factor_; }
void set_device_scale_factor(float scale) { device_scale_factor_ = scale; } void SetDeviceScaleFactor(float scale);
Rotation rotation() const { return rotation_; } Rotation rotation() const { return rotation_; }
void set_rotation(Rotation rotation) { rotation_ = rotation; } void set_rotation(Rotation rotation) { rotation_ = rotation; }
...@@ -178,7 +178,7 @@ class DISPLAY_EXPORT Display final { ...@@ -178,7 +178,7 @@ class DISPLAY_EXPORT Display final {
gfx::Insets GetWorkAreaInsets() const; gfx::Insets GetWorkAreaInsets() const;
// Sets the device scale factor and display bounds in pixel. This // Sets the device scale factor and display bounds in pixel. This
// updates the work are using the same insets between old bounds and // updates the work area using the same insets between old bounds and
// work area. // work area.
void SetScaleAndBounds(float device_scale_factor, void SetScaleAndBounds(float device_scale_factor,
const gfx::Rect& bounds_in_pixel); const gfx::Rect& bounds_in_pixel);
...@@ -187,7 +187,7 @@ class DISPLAY_EXPORT Display final { ...@@ -187,7 +187,7 @@ class DISPLAY_EXPORT Display final {
// between old bounds and work area. // between old bounds and work area.
void SetSize(const gfx::Size& size_in_pixel); void SetSize(const gfx::Size& size_in_pixel);
// Computes and updates the display's work are using // Computes and updates the display's work area using
// |work_area_insets| and the bounds. // |work_area_insets| and the bounds.
void UpdateWorkAreaFromInsets(const gfx::Insets& work_area_insets); void UpdateWorkAreaFromInsets(const gfx::Insets& work_area_insets);
...@@ -239,9 +239,7 @@ class DISPLAY_EXPORT Display final { ...@@ -239,9 +239,7 @@ class DISPLAY_EXPORT Display final {
// The number of bits per pixel. Used by media query APIs. // The number of bits per pixel. Used by media query APIs.
int color_depth() const { return color_depth_; } int color_depth() const { return color_depth_; }
void set_color_depth(int color_depth) { void set_color_depth(int color_depth) { color_depth_ = color_depth; }
color_depth_ = color_depth;
}
// The number of bits per color component (all color components are assumed to // The number of bits per color component (all color components are assumed to
// have the same number of bits). Used by media query APIs. // have the same number of bits). Used by media query APIs.
......
...@@ -412,9 +412,9 @@ TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_DSF) { ...@@ -412,9 +412,9 @@ TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_DSF) {
std::vector<Display> old_displays, new_displays; std::vector<Display> old_displays, new_displays;
old_displays.push_back(Display(1)); old_displays.push_back(Display(1));
old_displays[0].set_device_scale_factor(1.f); old_displays[0].SetDeviceScaleFactor(1.f);
new_displays.push_back(Display(1)); new_displays.push_back(Display(1));
new_displays[0].set_device_scale_factor(2.f); new_displays[0].SetDeviceScaleFactor(2.f);
change_notifier.NotifyDisplaysChanged(old_displays, new_displays); change_notifier.NotifyDisplaysChanged(old_displays, new_displays);
EXPECT_EQ(1, observer.display_changed()); EXPECT_EQ(1, observer.display_changed());
...@@ -436,8 +436,8 @@ TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_Multi_Displays) { ...@@ -436,8 +436,8 @@ TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_Multi_Displays) {
new_displays.push_back(Display(2)); new_displays.push_back(Display(2));
new_displays.push_back(Display(3)); new_displays.push_back(Display(3));
old_displays[0].set_device_scale_factor(1.f); old_displays[0].SetDeviceScaleFactor(1.f);
new_displays[0].set_device_scale_factor(2.f); new_displays[0].SetDeviceScaleFactor(2.f);
old_displays[1].set_bounds(gfx::Rect(0, 0, 200, 200)); old_displays[1].set_bounds(gfx::Rect(0, 0, 200, 200));
new_displays[1].set_bounds(gfx::Rect(0, 0, 400, 400)); new_displays[1].set_bounds(gfx::Rect(0, 0, 400, 400));
...@@ -456,11 +456,11 @@ TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_Multi_Metrics) { ...@@ -456,11 +456,11 @@ TEST(DisplayChangeNotifierTest, NotifyDisplaysChanged_Changed_Multi_Metrics) {
std::vector<Display> old_displays, new_displays; std::vector<Display> old_displays, new_displays;
old_displays.push_back(Display(1, gfx::Rect(0, 0, 200, 200))); old_displays.push_back(Display(1, gfx::Rect(0, 0, 200, 200)));
old_displays[0].set_device_scale_factor(1.f); old_displays[0].SetDeviceScaleFactor(1.f);
old_displays[0].SetRotationAsDegree(0); old_displays[0].SetRotationAsDegree(0);
new_displays.push_back(Display(1, gfx::Rect(100, 100, 200, 200))); new_displays.push_back(Display(1, gfx::Rect(100, 100, 200, 200)));
new_displays[0].set_device_scale_factor(2.f); new_displays[0].SetDeviceScaleFactor(2.f);
new_displays[0].SetRotationAsDegree(90); new_displays[0].SetRotationAsDegree(90);
change_notifier.NotifyDisplaysChanged(old_displays, new_displays); change_notifier.NotifyDisplaysChanged(old_displays, new_displays);
......
...@@ -90,7 +90,7 @@ uint32_t DisplayList::UpdateDisplay(const Display& display, Type type) { ...@@ -90,7 +90,7 @@ uint32_t DisplayList::UpdateDisplay(const Display& display, Type type) {
changed_values |= DisplayObserver::DISPLAY_METRIC_ROTATION; changed_values |= DisplayObserver::DISPLAY_METRIC_ROTATION;
} }
if (local_display->device_scale_factor() != display.device_scale_factor()) { if (local_display->device_scale_factor() != display.device_scale_factor()) {
local_display->set_device_scale_factor(display.device_scale_factor()); local_display->SetDeviceScaleFactor(display.device_scale_factor());
changed_values |= DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; changed_values |= DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR;
} }
if (local_display->color_space() != display.color_space() || if (local_display->color_space() != display.color_space() ||
......
...@@ -65,10 +65,16 @@ TEST(DisplayTest, ForcedDeviceScaleFactorByCommandLine) { ...@@ -65,10 +65,16 @@ TEST(DisplayTest, ForcedDeviceScaleFactorByCommandLine) {
} }
TEST(DisplayTest, ForcedDeviceScaleFactor) { TEST(DisplayTest, ForcedDeviceScaleFactor) {
Display::SetForceDeviceScaleFactor(2); const float kForcedScaleFactor = 2;
EXPECT_EQ(2, Display::GetForcedDeviceScaleFactor()); Display::SetForceDeviceScaleFactor(kForcedScaleFactor);
EXPECT_EQ(kForcedScaleFactor, Display::GetForcedDeviceScaleFactor());
Display::ResetForceDeviceScaleFactorForTesting(); Display::ResetForceDeviceScaleFactorForTesting();
Display display;
display.SetDeviceScaleFactor(5);
EXPECT_EQ(display.device_scale_factor(), kForcedScaleFactor);
} }
TEST(DisplayTest, DisplayHDRValues) { TEST(DisplayTest, DisplayHDRValues) {
......
...@@ -17,7 +17,7 @@ class ScreenIos : public ScreenBase { ...@@ -17,7 +17,7 @@ class ScreenIos : public ScreenBase {
UIScreen* mainScreen = [UIScreen mainScreen]; UIScreen* mainScreen = [UIScreen mainScreen];
CHECK(mainScreen); CHECK(mainScreen);
Display display(0, gfx::Rect(mainScreen.bounds)); Display display(0, gfx::Rect(mainScreen.bounds));
display.set_device_scale_factor([mainScreen scale]); display.SetDeviceScaleFactor([mainScreen scale]);
ProcessDisplayChanged(display, true /* is_primary */); ProcessDisplayChanged(display, true /* is_primary */);
} }
......
...@@ -79,7 +79,7 @@ Display BuildDisplayForScreen(NSScreen* screen) { ...@@ -79,7 +79,7 @@ Display BuildDisplayForScreen(NSScreen* screen) {
CGFloat scale = [screen backingScaleFactor]; CGFloat scale = [screen backingScaleFactor];
if (Display::HasForceDeviceScaleFactor()) if (Display::HasForceDeviceScaleFactor())
scale = Display::GetForcedDeviceScaleFactor(); scale = Display::GetForcedDeviceScaleFactor();
display.set_device_scale_factor(scale); display.SetDeviceScaleFactor(scale);
// Compute the color profile. // Compute the color profile.
gfx::ICCProfile icc_profile; gfx::ICCProfile icc_profile;
......
...@@ -126,7 +126,7 @@ bool StructTraits<display::mojom::DisplayDataView, display::Display>::Read( ...@@ -126,7 +126,7 @@ bool StructTraits<display::mojom::DisplayDataView, display::Display>::Read(
if (!data.ReadWorkArea(&out->work_area_)) if (!data.ReadWorkArea(&out->work_area_))
return false; return false;
out->set_device_scale_factor(data.device_scale_factor()); out->SetDeviceScaleFactor(data.device_scale_factor());
if (!data.ReadRotation(&out->rotation_)) if (!data.ReadRotation(&out->rotation_))
return false; return false;
......
...@@ -132,7 +132,7 @@ TEST(DisplayStructTraitsTest, SetAllDisplayValues) { ...@@ -132,7 +132,7 @@ TEST(DisplayStructTraitsTest, SetAllDisplayValues) {
Display input(246345234, bounds); Display input(246345234, bounds);
input.set_work_area(work_area); input.set_work_area(work_area);
input.set_device_scale_factor(2.0f); input.SetDeviceScaleFactor(2.0f);
input.set_rotation(Display::ROTATE_270); input.set_rotation(Display::ROTATE_270);
input.set_touch_support(Display::TouchSupport::AVAILABLE); input.set_touch_support(Display::TouchSupport::AVAILABLE);
input.set_accelerometer_support(Display::AccelerometerSupport::UNAVAILABLE); input.set_accelerometer_support(Display::AccelerometerSupport::UNAVAILABLE);
......
...@@ -172,7 +172,7 @@ Display CreateDisplayFromDisplayInfo(const DisplayInfo& display_info, ...@@ -172,7 +172,7 @@ Display CreateDisplayFromDisplayInfo(const DisplayInfo& display_info,
bool hdr_enabled) { bool hdr_enabled) {
Display display(display_info.id()); Display display(display_info.id());
float scale_factor = display_info.device_scale_factor(); float scale_factor = display_info.device_scale_factor();
display.set_device_scale_factor(scale_factor); display.SetDeviceScaleFactor(scale_factor);
display.set_work_area( display.set_work_area(
gfx::ScaleToEnclosingRect(display_info.screen_work_rect(), gfx::ScaleToEnclosingRect(display_info.screen_work_rect(),
1.0f / scale_factor)); 1.0f / scale_factor));
......
...@@ -14,7 +14,7 @@ namespace { ...@@ -14,7 +14,7 @@ namespace {
Display CreateDisplayFromDisplayInfo(const DisplayInfo& display_info) { Display CreateDisplayFromDisplayInfo(const DisplayInfo& display_info) {
Display display(display_info.id()); Display display(display_info.id());
float scale_factor = display_info.device_scale_factor(); float scale_factor = display_info.device_scale_factor();
display.set_device_scale_factor(scale_factor); display.SetDeviceScaleFactor(scale_factor);
display.set_work_area( display.set_work_area(
gfx::ScaleToEnclosingRect(display_info.screen_work_rect(), gfx::ScaleToEnclosingRect(display_info.screen_work_rect(),
1.0f / scale_factor)); 1.0f / scale_factor));
......
...@@ -55,7 +55,7 @@ void ScenicScreen::OnWindowMetrics(int32_t window_id, ...@@ -55,7 +55,7 @@ void ScenicScreen::OnWindowMetrics(int32_t window_id,
}); });
DCHECK(display_it != displays_.end()); DCHECK(display_it != displays_.end());
display_it->set_device_scale_factor(device_pixel_ratio); display_it->SetDeviceScaleFactor(device_pixel_ratio);
for (auto& observer : observers_) { for (auto& observer : observers_) {
observer.OnDisplayMetricsChanged( observer.OnDisplayMetricsChanged(
*display_it, *display_it,
......
...@@ -51,7 +51,7 @@ void WaylandScreen::OnOutputMetricsChanged(uint32_t output_id, ...@@ -51,7 +51,7 @@ void WaylandScreen::OnOutputMetricsChanged(uint32_t output_id,
const gfx::Rect& new_bounds, const gfx::Rect& new_bounds,
float device_pixel_ratio) { float device_pixel_ratio) {
display::Display changed_display(output_id); display::Display changed_display(output_id);
changed_display.set_device_scale_factor(device_pixel_ratio); changed_display.SetDeviceScaleFactor(device_pixel_ratio);
changed_display.set_bounds(new_bounds); changed_display.set_bounds(new_bounds);
changed_display.set_work_area(new_bounds); changed_display.set_work_area(new_bounds);
......
...@@ -42,7 +42,7 @@ void DesktopScreenOzone::OnHostDisplaysReady( ...@@ -42,7 +42,7 @@ void DesktopScreenOzone::OnHostDisplaysReady(
display::Display display(display_snapshot->display_id()); display::Display display(display_snapshot->display_id());
display.set_bounds(gfx::Rect(scaled_size)); display.set_bounds(gfx::Rect(scaled_size));
display.set_work_area(display.bounds()); display.set_work_area(display.bounds());
display.set_device_scale_factor(device_scale_factor); display.SetDeviceScaleFactor(device_scale_factor);
ProcessDisplayChanged(display, true /* is_primary */); ProcessDisplayChanged(display, true /* is_primary */);
} }
......
...@@ -440,25 +440,25 @@ TEST_F(DesktopScreenX11Test, DeviceScaleFactorChange) { ...@@ -440,25 +440,25 @@ TEST_F(DesktopScreenX11Test, DeviceScaleFactorChange) {
NotifyDisplaysChanged(displays); NotifyDisplaysChanged(displays);
ResetDisplayChanges(); ResetDisplayChanges();
displays[0].set_device_scale_factor(2.5f); displays[0].SetDeviceScaleFactor(2.5f);
NotifyDisplaysChanged(displays); NotifyDisplaysChanged(displays);
EXPECT_EQ(1u, changed_display_.size()); EXPECT_EQ(1u, changed_display_.size());
EXPECT_EQ(2.5f, gfx::GetFontRenderParamsDeviceScaleFactor()); EXPECT_EQ(2.5f, gfx::GetFontRenderParamsDeviceScaleFactor());
displays[1].set_device_scale_factor(2.5f); displays[1].SetDeviceScaleFactor(2.5f);
NotifyDisplaysChanged(displays); NotifyDisplaysChanged(displays);
EXPECT_EQ(2u, changed_display_.size()); EXPECT_EQ(2u, changed_display_.size());
displays[0].set_device_scale_factor(2.5f); displays[0].SetDeviceScaleFactor(2.5f);
NotifyDisplaysChanged(displays); NotifyDisplaysChanged(displays);
EXPECT_EQ(2u, changed_display_.size()); EXPECT_EQ(2u, changed_display_.size());
displays[1].set_device_scale_factor(2.5f); displays[1].SetDeviceScaleFactor(2.5f);
NotifyDisplaysChanged(displays); NotifyDisplaysChanged(displays);
EXPECT_EQ(2u, changed_display_.size()); EXPECT_EQ(2u, changed_display_.size());
displays[0].set_device_scale_factor(1.f); displays[0].SetDeviceScaleFactor(1.f);
displays[1].set_device_scale_factor(1.f); displays[1].SetDeviceScaleFactor(1.f);
NotifyDisplaysChanged(displays); NotifyDisplaysChanged(displays);
EXPECT_EQ(4u, changed_display_.size()); EXPECT_EQ(4u, changed_display_.size());
EXPECT_EQ(1.f, gfx::GetFontRenderParamsDeviceScaleFactor()); EXPECT_EQ(1.f, gfx::GetFontRenderParamsDeviceScaleFactor());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment