Commit cc47e2c4 authored by Minju Kim's avatar Minju Kim Committed by Chromium LUCI CQ

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/+/2637098Reviewed-by: default avatarNick Yamane <nickdiego@igalia.com>
Commit-Queue: MINJU KIM <mkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#845961}
parent ad6485da
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "third_party/skia/include/core/SkRegion.h" #include "third_party/skia/include/core/SkRegion.h"
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/gfx/skia_util.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_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_shm_buffer.h" #include "ui/ozone/platform/wayland/host/wayland_shm_buffer.h"
#include "ui/ozone/platform/wayland/host/wayland_surface.h" #include "ui/ozone/platform/wayland/host/wayland_surface.h"
...@@ -292,4 +293,13 @@ std::vector<gfx::Rect> CreateRectsFromSkPath(const SkPath& path) { ...@@ -292,4 +293,13 @@ std::vector<gfx::Rect> CreateRectsFromSkPath(const SkPath& path) {
return rects; 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 } // namespace wl
...@@ -91,6 +91,9 @@ gfx::Rect TranslateWindowBoundsToParentDIP(ui::WaylandWindow* window, ...@@ -91,6 +91,9 @@ gfx::Rect TranslateWindowBoundsToParentDIP(ui::WaylandWindow* window,
// Returns rectangles dictated by SkPath. // Returns rectangles dictated by SkPath.
std::vector<gfx::Rect> CreateRectsFromSkPath(const SkPath& path); 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 } // namespace wl
#endif // UI_OZONE_PLATFORM_WAYLAND_COMMON_WAYLAND_UTIL_H_ #endif // UI_OZONE_PLATFORM_WAYLAND_COMMON_WAYLAND_UTIL_H_
...@@ -225,10 +225,11 @@ wl::Object<wl_region> WaylandSurface::CreateAndAddRegion( ...@@ -225,10 +225,11 @@ wl::Object<wl_region> WaylandSurface::CreateAndAddRegion(
region_dip.width(), region_dip.height()); region_dip.width(), region_dip.height());
}; };
if (root_window_->GetWindowShape().has_value()) { auto window_shape_in_dips = root_window_->GetWindowShape();
std::vector<gfx::Rect> rectangles = root_window_->GetWindowShape().value(); if (window_shape_in_dips.has_value()) {
for (const auto& rect : rectangles) for (const auto& rect : window_shape_in_dips.value())
add_region(rect); wl_region_add(region.get(), rect.x(), rect.y(), rect.width(),
rect.height());
} else { } else {
add_region(region_px); add_region(region_px);
} }
......
...@@ -231,7 +231,7 @@ bool WaylandToplevelWindow::ShouldUseNativeFrame() const { ...@@ -231,7 +231,7 @@ bool WaylandToplevelWindow::ShouldUseNativeFrame() const {
base::Optional<std::vector<gfx::Rect>> WaylandToplevelWindow::GetWindowShape() base::Optional<std::vector<gfx::Rect>> WaylandToplevelWindow::GetWindowShape()
const { const {
return window_shape_; return window_shape_in_dips_;
} }
void WaylandToplevelWindow::HandleSurfaceConfigure(int32_t width, void WaylandToplevelWindow::HandleSurfaceConfigure(int32_t width,
...@@ -438,15 +438,18 @@ void WaylandToplevelWindow::UpdateWindowMask() { ...@@ -438,15 +438,18 @@ void WaylandToplevelWindow::UpdateWindowMask() {
} }
void WaylandToplevelWindow::UpdateWindowShape() { void WaylandToplevelWindow::UpdateWindowShape() {
// Create |window_shape_| using the window mask of PlatformWindowDelegate // Create |window_shape_in_dips_| using the window mask of
// otherwise resets it. // PlatformWindowDelegate otherwise resets it.
base::Optional<SkPath> window_mask = delegate()->GetWindowMaskForWindowShape( base::Optional<SkPath> window_mask_in_pixels =
delegate()->GetWindowMaskForWindowShape(
gfx::Size(GetBounds().width(), GetBounds().height())); gfx::Size(GetBounds().width(), GetBounds().height()));
if (window_mask.has_value()) { if (!window_mask_in_pixels.has_value()) {
window_shape_ = wl::CreateRectsFromSkPath(window_mask.value()); window_shape_in_dips_.reset();
} else { return;
window_shape_.reset();
} }
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 } // namespace ui
...@@ -150,7 +150,7 @@ class WaylandToplevelWindow : public WaylandWindow, ...@@ -150,7 +150,7 @@ class WaylandToplevelWindow : public WaylandWindow,
// e.g. lacros-taskmanager. // e.g. lacros-taskmanager.
bool use_native_frame_ = false; 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 } // namespace ui
......
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