From 996546f65befaed7ec1fade81196a180b40ce00f Mon Sep 17 00:00:00 2001 From: xieyijun3 Date: Mon, 25 Sep 2023 09:13:17 +0800 Subject: [PATCH 1/3] fix firefox resize Signed-off-by: x30034819 Signed-off-by: xieyijun3 --- .../framework/core/wayland_surface.cpp | 38 +++++++++++++++++-- .../framework/core/wayland_surface.h | 3 ++ .../framework/stable/wayland_xdg_surface.cpp | 7 ++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/wayland_adapter/framework/core/wayland_surface.cpp b/wayland_adapter/framework/core/wayland_surface.cpp index 0707a96..8053082 100644 --- a/wayland_adapter/framework/core/wayland_surface.cpp +++ b/wayland_adapter/framework/core/wayland_surface.cpp @@ -698,6 +698,13 @@ void WaylandSurface::Close() window_->Close(); } +void WaylandSurface::SetWindowGeometry(Rect rect) +{ + LOG_DEBUG("Window %{public}s. x:%{public}d y:%{public}d width:%{public}d height:%{public}d", + windowTitle_.c_str(), rect.x, rect.y, rect.width, rect.height); + geometryRect_ = rect; +} + void WaylandSurface::WithTopLevel(bool toplevel) { withTopLevel_ = toplevel; @@ -742,7 +749,18 @@ void WaylandSurface::TriggerInnerCompose() LOG_ERROR("rsSurface_ is nullptr"); return; } - auto framePtr = rsSurface_->RequestFrame(srcBitmap_.width(), srcBitmap_.height()); + uint32_t width; + uint32_t height; + bool vailedGeometry = (geometryRect_.x >= 0 && geometryRect_.y >= 0 && \ + geometryRect_.width > 0 && geometryRect_.height > 0); + if (vailedGeometry) { + width = geometryRect_.width; + height = geometryRect_.height; + } else { + width = srcBitmap_.width(); + height = srcBitmap_.height(); + } + auto framePtr = rsSurface_->RequestFrame(width, height); if (framePtr == nullptr) { LOG_ERROR("RequestFrame failed"); return; @@ -754,14 +772,28 @@ void WaylandSurface::TriggerInnerCompose() return; } canvas->clear(SK_ColorTRANSPARENT); - canvas->drawBitmap(srcBitmap_, 0, 0); + if (vailedGeometry) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kFill_Style); + canvas->drawBitmapRect(srcBitmap_, + SkRect::MakeXYWH(geometryRect_.x, geometryRect_.y, geometryRect_.width, geometryRect_.height), + SkRect::MakeXYWH(0, 0, geometryRect_.width, geometryRect_.height), + &paint); + } else { + canvas->drawBitmap(srcBitmap_, 0, 0); + } for (auto &&[childKey, data] : childs_) { if (data.surface == nullptr) { continue; } LOG_DEBUG("Draw Child"); auto surfaceChild = CastFromResource(data.surface); - surfaceChild->ProcessSrcBitmap(canvas, data.offsetX, data.offsetY); + if (vailedGeometry) { + surfaceChild->ProcessSrcBitmap(canvas, data.offsetX - geometryRect_.x, data.offsetY - geometryRect_.y); + } else { + surfaceChild->ProcessSrcBitmap(canvas, data.offsetX, data.offsetY); + } } rsSurface_->FlushFrame(framePtr); } diff --git a/wayland_adapter/framework/core/wayland_surface.h b/wayland_adapter/framework/core/wayland_surface.h index a7bed11..b5c9f9e 100644 --- a/wayland_adapter/framework/core/wayland_surface.h +++ b/wayland_adapter/framework/core/wayland_surface.h @@ -76,6 +76,8 @@ public: void UnSetFullscreen(); void SetMinimized(); void Close(); + void SetWindowGeometry(Rect rect); + void WithTopLevel(bool toplevel); void AddChild(struct wl_resource *child, int32_t x, int32_t y); void AddParent(struct wl_resource *parent); @@ -104,6 +106,7 @@ private: std::list commitCallbacks_; std::list rectCallbacks_; Rect rect_; + Rect geometryRect_ = {0}; SurfaceState old_; SurfaceState new_; bool isPointerSurface_ = false; diff --git a/wayland_adapter/framework/stable/wayland_xdg_surface.cpp b/wayland_adapter/framework/stable/wayland_xdg_surface.cpp index cde7266..32aac04 100644 --- a/wayland_adapter/framework/stable/wayland_xdg_surface.cpp +++ b/wayland_adapter/framework/stable/wayland_xdg_surface.cpp @@ -131,6 +131,13 @@ void WaylandXdgSurface::GetPopup(uint32_t id, struct wl_resource *parent, struct void WaylandXdgSurface::SetWindowGeometry(int32_t x, int32_t y, int32_t width, int32_t height) { + LOG_DEBUG("Window %{public}s. x:%{public}d y:%{public}d width:%{public}d height:%{public}d", + windowTitle_.c_str(), x, y, width, height); + auto surface = surface_.promote(); + if (surface != nullptr) { + Rect rect = {x, y, (uint32_t)width, (uint32_t)height}; + surface->SetWindowGeometry(rect); + } } void WaylandXdgSurface::AckConfigure(uint32_t serial) -- Gitee From 8786c5eb068718e05f49f705d627215f777a5f18 Mon Sep 17 00:00:00 2001 From: xieyijun3 Date: Mon, 25 Sep 2023 09:57:41 +0800 Subject: [PATCH 2/3] fix firefox resize Signed-off-by: x30034819 Signed-off-by: xieyijun3 --- wayland_adapter/framework/stable/wayland_xdg_surface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wayland_adapter/framework/stable/wayland_xdg_surface.cpp b/wayland_adapter/framework/stable/wayland_xdg_surface.cpp index 32aac04..68120eb 100644 --- a/wayland_adapter/framework/stable/wayland_xdg_surface.cpp +++ b/wayland_adapter/framework/stable/wayland_xdg_surface.cpp @@ -135,7 +135,7 @@ void WaylandXdgSurface::SetWindowGeometry(int32_t x, int32_t y, int32_t width, i windowTitle_.c_str(), x, y, width, height); auto surface = surface_.promote(); if (surface != nullptr) { - Rect rect = {x, y, (uint32_t)width, (uint32_t)height}; + Rect rect = {x, y, static_cast(width), static_cast(height)}; surface->SetWindowGeometry(rect); } } -- Gitee From b445302937b9b4582af1d2367517d4898e76604f Mon Sep 17 00:00:00 2001 From: xieyijun3 Date: Mon, 25 Sep 2023 14:36:46 +0800 Subject: [PATCH 3/3] fix firefox point,Maximized Signed-off-by: x30034819 Signed-off-by: xieyijun3 --- .../framework/core/wayland_surface.cpp | 70 ++++++++++++------- .../framework/core/wayland_surface.h | 2 + 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/wayland_adapter/framework/core/wayland_surface.cpp b/wayland_adapter/framework/core/wayland_surface.cpp index 8053082..3b52b95 100644 --- a/wayland_adapter/framework/core/wayland_surface.cpp +++ b/wayland_adapter/framework/core/wayland_surface.cpp @@ -119,6 +119,11 @@ bool InputEventConsumer::OnInputEvent(const std::shared_ptrGetWindowGeometry(); + if (rect.x >= 0 && rect.y >= 0 && rect.width > 0 && rect.height > 0) { + pointerItem.SetWindowX(pointerItem.GetWindowX() + rect.x); + pointerItem.SetWindowY(pointerItem.GetWindowY() + rect.y); + } if (pointerEvent->GetPointerAction() == OHOS::MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW) { for (auto &pointer : pointerList) { pointer->OnPointerEnter(pointerItem.GetWindowX(), pointerItem.GetWindowY(), wlSurface_->WlResource()); @@ -393,10 +398,9 @@ void WaylandSurface::Commit() return; // it is pointer surface, we do not handle commit! } - if (withTopLevel_ && (window_ == nullptr)) { - CreateWindow(); - LOG_DEBUG("CreateWindow"); - + if (!WindowValid()) { + LOG_ERROR("window is invalid"); + return; } { HandleCommit(); @@ -491,6 +495,17 @@ void WaylandSurface::CheckIsPointerSurface() LOG_DEBUG("this surface Pointer Surface: %{public}d", isPointerSurface_); } +bool WaylandSurface::WindowValid() +{ + if (!withTopLevel_) { + return true; + } + if (window_ == nullptr) { + CreateWindow(); + } + return window_ != nullptr; +} + void WaylandSurface::CreateWindow() { CheckIsPointerSurface(); @@ -604,8 +619,8 @@ void WaylandSurface::SetTitle(const char *title) { LOG_DEBUG("Window %{public}s, set Title %{public}s.", windowTitle_.c_str(), title); windowTitle_ = std::to_string((long)((void *)this)) + std::string("-") + std::string(title); - if (window_ == nullptr) { - LOG_ERROR("window_ is nullptr"); + if (!WindowValid()) { + LOG_ERROR("window is invalid"); return; } window_->SetAPPWindowLabel(title); @@ -614,8 +629,8 @@ void WaylandSurface::SetTitle(const char *title) void WaylandSurface::Resize(uint32_t serial, uint32_t edges) { LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); - if (window_ == nullptr) { - LOG_ERROR("window_ is nullptr"); + if (!WindowValid()) { + LOG_ERROR("window is invalid"); return; } } @@ -623,8 +638,8 @@ void WaylandSurface::Resize(uint32_t serial, uint32_t edges) void WaylandSurface::SetMaxSize(int32_t width, int32_t height) { LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); - if (window_ == nullptr) { - LOG_ERROR("window_ is nullptr"); + if (!WindowValid()) { + LOG_ERROR("window is invalid"); return; } } @@ -632,8 +647,8 @@ void WaylandSurface::SetMaxSize(int32_t width, int32_t height) void WaylandSurface::SetMinSize(int32_t width, int32_t height) { LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); - if (window_ == nullptr) { - LOG_ERROR("window_ is nullptr"); + if (!WindowValid()) { + LOG_ERROR("window is invalid"); return; } } @@ -641,8 +656,8 @@ void WaylandSurface::SetMinSize(int32_t width, int32_t height) void WaylandSurface::SetMaximized() { LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); - if (window_ == nullptr) { - LOG_ERROR("window_ is nullptr"); + if (!WindowValid()) { + LOG_ERROR("window is invalid"); return; } window_->Maximize(); @@ -651,8 +666,8 @@ void WaylandSurface::SetMaximized() void WaylandSurface::UnSetMaximized() { LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); - if (window_ == nullptr) { - LOG_ERROR("window_ is nullptr"); + if (!WindowValid()) { + LOG_ERROR("window is invalid"); return; } window_->Recover(); @@ -661,8 +676,8 @@ void WaylandSurface::UnSetMaximized() void WaylandSurface::SetFullscreen() { LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); - if (window_ == nullptr) { - LOG_ERROR("window_ is nullptr"); + if (!WindowValid()) { + LOG_ERROR("window is invalid"); return; } window_->SetFullScreen(true); @@ -671,8 +686,8 @@ void WaylandSurface::SetFullscreen() void WaylandSurface::UnSetFullscreen() { LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); - if (window_ == nullptr) { - LOG_ERROR("window_ is nullptr"); + if (!WindowValid()) { + LOG_ERROR("window is invalid"); return; } window_->SetFullScreen(false); @@ -681,8 +696,8 @@ void WaylandSurface::UnSetFullscreen() void WaylandSurface::SetMinimized() { LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); - if (window_ == nullptr) { - LOG_ERROR("window_ is nullptr"); + if (!WindowValid()) { + LOG_ERROR("window is invalid"); return; } window_->Minimize(); @@ -691,8 +706,8 @@ void WaylandSurface::SetMinimized() void WaylandSurface::Close() { LOG_DEBUG("Window %{public}s.", windowTitle_.c_str()); - if (window_ == nullptr) { - LOG_ERROR("window_ is nullptr"); + if (!WindowValid()) { + LOG_ERROR("window is invalid"); return; } window_->Close(); @@ -705,6 +720,11 @@ void WaylandSurface::SetWindowGeometry(Rect rect) geometryRect_ = rect; } +Rect WaylandSurface::GetWindowGeometry() +{ + return geometryRect_; +} + void WaylandSurface::WithTopLevel(bool toplevel) { withTopLevel_ = toplevel; @@ -751,7 +771,7 @@ void WaylandSurface::TriggerInnerCompose() } uint32_t width; uint32_t height; - bool vailedGeometry = (geometryRect_.x >= 0 && geometryRect_.y >= 0 && \ + bool vailedGeometry = (geometryRect_.x >= 0 && geometryRect_.y >= 0 && geometryRect_.width > 0 && geometryRect_.height > 0); if (vailedGeometry) { width = geometryRect_.width; diff --git a/wayland_adapter/framework/core/wayland_surface.h b/wayland_adapter/framework/core/wayland_surface.h index b5c9f9e..12bbaa7 100644 --- a/wayland_adapter/framework/core/wayland_surface.h +++ b/wayland_adapter/framework/core/wayland_surface.h @@ -77,6 +77,7 @@ public: void SetMinimized(); void Close(); void SetWindowGeometry(Rect rect); + Rect GetWindowGeometry(); void WithTopLevel(bool toplevel); void AddChild(struct wl_resource *child, int32_t x, int32_t y); @@ -101,6 +102,7 @@ private: void CreateWindow(); void CopyBuffer(struct wl_shm_buffer *shm); void CheckIsPointerSurface(); + bool WindowValid(); struct wl_resource *parent_ = nullptr; std::list commitCallbacks_; -- Gitee