ozone/wayland: Convert SkPath to DIPs before converted to rectangles
SkPath from |PlatformWindowDelegate::GetWindowMaskForWindowShape|
needs to be transformed in DIPs by the given |buffer_scale_|
before converted to rectangles.
TEST: test with --force-device-scale-factor
Bug: 1126828
Change-Id: I268e7266ba9131cf8eba481b1c30b93d2f1c3788
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2637098
Reviewed-by: Nick Yamane <nickdiego@igalia.com>
Commit-Queue: MINJU KIM <mkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#845961}
diff --git a/ui/ozone/platform/wayland/common/wayland_util.cc b/ui/ozone/platform/wayland/common/wayland_util.cc
index dbc1b51..d4c29913 100644
--- a/ui/ozone/platform/wayland/common/wayland_util.cc
+++ b/ui/ozone/platform/wayland/common/wayland_util.cc
@@ -11,6 +11,7 @@
#include "third_party/skia/include/core/SkRegion.h"
#include "ui/base/hit_test.h"
#include "ui/gfx/skia_util.h"
+#include "ui/gfx/transform.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_shm_buffer.h"
#include "ui/ozone/platform/wayland/host/wayland_surface.h"
@@ -292,4 +293,13 @@
return rects;
}
+SkPath ConvertPathToDIP(const SkPath& path_in_pixels, const int32_t scale) {
+ SkScalar sk_scale = SkFloatToScalar(1.0f / scale);
+ gfx::Transform transform;
+ transform.Scale(sk_scale, sk_scale);
+ SkPath path_in_dips;
+ path_in_pixels.transform(SkMatrix(transform.matrix()), &path_in_dips);
+ return path_in_dips;
+}
+
} // namespace wl
diff --git a/ui/ozone/platform/wayland/common/wayland_util.h b/ui/ozone/platform/wayland/common/wayland_util.h
index e472820..8d8b12f 100644
--- a/ui/ozone/platform/wayland/common/wayland_util.h
+++ b/ui/ozone/platform/wayland/common/wayland_util.h
@@ -91,6 +91,9 @@
// Returns rectangles dictated by SkPath.
std::vector<gfx::Rect> CreateRectsFromSkPath(const SkPath& path);
+// Returns converted SkPath in DIPs from the one in pixels.
+SkPath ConvertPathToDIP(const SkPath& path_in_pixels, const int32_t scale);
+
} // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_COMMON_WAYLAND_UTIL_H_
diff --git a/ui/ozone/platform/wayland/host/wayland_surface.cc b/ui/ozone/platform/wayland/host/wayland_surface.cc
index 30167899..d2105cfb 100644
--- a/ui/ozone/platform/wayland/host/wayland_surface.cc
+++ b/ui/ozone/platform/wayland/host/wayland_surface.cc
@@ -225,10 +225,11 @@
region_dip.width(), region_dip.height());
};
- if (root_window_->GetWindowShape().has_value()) {
- std::vector<gfx::Rect> rectangles = root_window_->GetWindowShape().value();
- for (const auto& rect : rectangles)
- add_region(rect);
+ auto window_shape_in_dips = root_window_->GetWindowShape();
+ if (window_shape_in_dips.has_value()) {
+ for (const auto& rect : window_shape_in_dips.value())
+ wl_region_add(region.get(), rect.x(), rect.y(), rect.width(),
+ rect.height());
} else {
add_region(region_px);
}
diff --git a/ui/ozone/platform/wayland/host/wayland_toplevel_window.cc b/ui/ozone/platform/wayland/host/wayland_toplevel_window.cc
index 14a19290..c24855b9 100644
--- a/ui/ozone/platform/wayland/host/wayland_toplevel_window.cc
+++ b/ui/ozone/platform/wayland/host/wayland_toplevel_window.cc
@@ -231,7 +231,7 @@
base::Optional<std::vector<gfx::Rect>> WaylandToplevelWindow::GetWindowShape()
const {
- return window_shape_;
+ return window_shape_in_dips_;
}
void WaylandToplevelWindow::HandleSurfaceConfigure(int32_t width,
@@ -438,15 +438,18 @@
}
void WaylandToplevelWindow::UpdateWindowShape() {
- // Create |window_shape_| using the window mask of PlatformWindowDelegate
- // otherwise resets it.
- base::Optional<SkPath> window_mask = delegate()->GetWindowMaskForWindowShape(
- gfx::Size(GetBounds().width(), GetBounds().height()));
- if (window_mask.has_value()) {
- window_shape_ = wl::CreateRectsFromSkPath(window_mask.value());
- } else {
- window_shape_.reset();
+ // Create |window_shape_in_dips_| using the window mask of
+ // PlatformWindowDelegate otherwise resets it.
+ base::Optional<SkPath> window_mask_in_pixels =
+ delegate()->GetWindowMaskForWindowShape(
+ gfx::Size(GetBounds().width(), GetBounds().height()));
+ if (!window_mask_in_pixels.has_value()) {
+ window_shape_in_dips_.reset();
+ return;
}
+ SkPath window_mask_in_dips =
+ wl::ConvertPathToDIP(window_mask_in_pixels.value(), buffer_scale());
+ window_shape_in_dips_ = wl::CreateRectsFromSkPath(window_mask_in_dips);
}
} // namespace ui
diff --git a/ui/ozone/platform/wayland/host/wayland_toplevel_window.h b/ui/ozone/platform/wayland/host/wayland_toplevel_window.h
index 32d555c..e6747bc 100644
--- a/ui/ozone/platform/wayland/host/wayland_toplevel_window.h
+++ b/ui/ozone/platform/wayland/host/wayland_toplevel_window.h
@@ -150,7 +150,7 @@
// e.g. lacros-taskmanager.
bool use_native_frame_ = false;
- base::Optional<std::vector<gfx::Rect>> window_shape_;
+ base::Optional<std::vector<gfx::Rect>> window_shape_in_dips_;
};
} // namespace ui