From 301b76fd76b2eda73619acdb96611640dbb33c0e Mon Sep 17 00:00:00 2001 From: xieyijun Date: Tue, 12 Sep 2023 17:34:13 +0800 Subject: [PATCH] add wayland region Signed-off-by: x30034819 Signed-off-by: xieyijun3 --- wayland_adapter/framework/BUILD.gn | 2 + .../framework/core/wayland_compositor.cpp | 6 ++ .../framework/core/wayland_region.cpp | 81 +++++++++++++++++++ .../framework/core/wayland_region.h | 55 +++++++++++++ .../framework/core/wayland_surface.cpp | 16 ++++ wayland_adapter/test/wayland_demo.cpp | 8 ++ 6 files changed, 168 insertions(+) create mode 100644 wayland_adapter/framework/core/wayland_region.cpp create mode 100644 wayland_adapter/framework/core/wayland_region.h diff --git a/wayland_adapter/framework/BUILD.gn b/wayland_adapter/framework/BUILD.gn index b8feb35..ad6ddc9 100644 --- a/wayland_adapter/framework/BUILD.gn +++ b/wayland_adapter/framework/BUILD.gn @@ -27,6 +27,7 @@ ft_source_set("wayland_framewok_sources") { "core/wayland_compositor.cpp", "core/wayland_seat.cpp", "core/wayland_surface.cpp", + "core/wayland_region.cpp", "core/wayland_pointer.cpp", "core/wayland_keyboard.cpp", ] @@ -44,6 +45,7 @@ ft_source_set("wayland_framewok_sources") { } deps = [ + "$window_manager_path/dm/ft_build:libdm", "$window_manager_path/wm/ft_build:libwm", "$display_server_root/rosen/modules/render_service_base/ft_build:librender_service_base", "$display_server_root/rosen/modules/render_service_client/ft_build:librender_service_client", diff --git a/wayland_adapter/framework/core/wayland_compositor.cpp b/wayland_adapter/framework/core/wayland_compositor.cpp index 123ecf4..8772b0f 100644 --- a/wayland_adapter/framework/core/wayland_compositor.cpp +++ b/wayland_adapter/framework/core/wayland_compositor.cpp @@ -18,6 +18,7 @@ #include "wayland_surface.h" #include "wayland_objects_pool.h" #include "version.h" +#include "wayland_region.h" namespace FT { namespace Wayland { @@ -82,6 +83,11 @@ void WaylandCompositorObject::CreateSurface(struct wl_client *client, struct wl_ void WaylandCompositorObject::CreateRegion(struct wl_client *client, struct wl_resource *resource, uint32_t id) { + auto region = WaylandRegion::Create(client, resource, wl_resource_get_version(resource), id); + if (region == nullptr) { + LOG_ERROR("no memory"); + return; + } } } // namespace Wayland } // namespace FT diff --git a/wayland_adapter/framework/core/wayland_region.cpp b/wayland_adapter/framework/core/wayland_region.cpp new file mode 100644 index 0000000..0cf3b5d --- /dev/null +++ b/wayland_adapter/framework/core/wayland_region.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "wayland_region.h" +#include "wayland_objects_pool.h" + +namespace FT { +namespace Wayland { +namespace { + constexpr HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WAYLAND, "WaylandRegion"}; +} + +struct wl_region_interface IWaylandRegion::impl_ = { + .destroy = &WaylandResourceObject::DefaultDestroyResource, + .add = Add, + .subtract = Subtract}; + +void IWaylandRegion::Add(struct wl_client *client, struct wl_resource *resource, + int32_t x, int32_t y, int32_t width, int32_t height) +{ + CAST_OBJECT_AND_CALL_FUNC(WaylandRegion, resource, + "IWaylandRegion::Add: failed to find object.", Add, x, y, width, height); +} + +void IWaylandRegion::Subtract(struct wl_client *client, struct wl_resource *resource, + int32_t x, int32_t y, int32_t width, int32_t height) +{ + CAST_OBJECT_AND_CALL_FUNC(WaylandRegion, resource, + "IWaylandRegion::Subtract: failed to find object.", Subtract, x, y, width, height); +} + +OHOS::sptr WaylandRegion::Create(struct wl_client *client, + struct wl_resource *parent, uint32_t version, uint32_t id) +{ + if (client == nullptr) { + return nullptr; + } + + auto region = OHOS::sptr(new WaylandRegion(client, parent, version, id)); + WaylandObjectsPool::GetInstance().AddObject(ObjectId(region->WlClient(), region->Id()), region); + return region; +} + +WaylandRegion::WaylandRegion(struct wl_client *client, struct wl_resource *parent, uint32_t version, uint32_t id) + : WaylandResourceObject(client, &wl_region_interface, version, id, &IWaylandRegion::impl_), + parent_(parent) {} + +WaylandRegion::~WaylandRegion() noexcept {} + +void WaylandRegion::Add(int32_t x, int32_t y, int32_t width, int32_t height) +{ + LOG_DEBUG("WaylandRegion::Add, cover"); + rect_.x = x; + rect_.y = y; + rect_.width = width; + rect_.height = height; +} + +void WaylandRegion::Subtract(int32_t x, int32_t y, int32_t width, int32_t height) +{ + LOG_DEBUG("WaylandRegion::Subtract, ignore"); +} + +Rect WaylandRegion::GetRect() +{ + return rect_; +} +} // namespace Wayland +} // namespace FT diff --git a/wayland_adapter/framework/core/wayland_region.h b/wayland_adapter/framework/core/wayland_region.h new file mode 100644 index 0000000..270795e --- /dev/null +++ b/wayland_adapter/framework/core/wayland_region.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023 Huawei Technologies Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include "wayland_resource_object.h" +#include "wayalnd_utils.h" + +namespace FT { +namespace Wayland { +struct IWaylandRegion { + static void Destroy(struct wl_client *client, struct wl_resource *resource); + static void Add(struct wl_client *client, struct wl_resource *resource, + int32_t x, int32_t y, int32_t width, int32_t height); + static void Subtract(struct wl_client *client, struct wl_resource *resource, + int32_t x, int32_t y, int32_t width, int32_t height); + static struct wl_region_interface impl_; +}; + +class WaylandRegion final : public WaylandResourceObject { + friend struct IWaylandRegion; + +public: + static OHOS::sptr Create(struct wl_client *client, struct wl_resource *parent, + uint32_t version, uint32_t id); + ~WaylandRegion() noexcept override; + + Rect GetRect(); + +private: + WaylandRegion(struct wl_client *client, struct wl_resource *parent, uint32_t version, uint32_t id); + + void Destroy(struct wl_client *client, struct wl_resource *resource); + void Add(int32_t x, int32_t y, int32_t width, int32_t height); + void Subtract(int32_t x, int32_t y, int32_t width, int32_t height); + + struct wl_resource *parent_ = nullptr; + Rect rect_; +}; +} // namespace Wayland +} // namespace FT diff --git a/wayland_adapter/framework/core/wayland_surface.cpp b/wayland_adapter/framework/core/wayland_surface.cpp index a5103fb..d3866f6 100644 --- a/wayland_adapter/framework/core/wayland_surface.cpp +++ b/wayland_adapter/framework/core/wayland_surface.cpp @@ -17,6 +17,7 @@ #include "wayland_objects_pool.h" #include "ui/rs_surface_extractor.h" +#include "wayland_region.h" namespace FT { namespace Wayland { @@ -167,10 +168,25 @@ void WaylandSurface::Frame(uint32_t callback) void WaylandSurface::SetOpaqueRegion(struct wl_resource *regionResource) { + LOG_DEBUG("WaylandSurface::SetOpaqueRegion, ignore"); } void WaylandSurface::SetInputRegion(struct wl_resource *regionResource) { + if (regionResource == nullptr) { + return; + } + + auto region = CastFromResource(regionResource); + if (region == nullptr) { + LOG_ERROR("failed to cast WaylandRegion from regionResource, maybe resource is not valid."); + return; + } + + // input + Rect rect = region->GetRect(); + LOG_DEBUG("SetInputRegion, rect: x %{public}d, y %{public}d, width %{public}d, height %{public}d.", + rect.x, rect.y, rect.width, rect.height); } void WaylandSurface::Commit() diff --git a/wayland_adapter/test/wayland_demo.cpp b/wayland_adapter/test/wayland_demo.cpp index a5b7965..8dcc262 100644 --- a/wayland_adapter/test/wayland_demo.cpp +++ b/wayland_adapter/test/wayland_demo.cpp @@ -67,6 +67,7 @@ struct window { struct display *display; int32_t width, height; struct wl_surface *surface; + struct wl_region *region; struct xdg_surface *xdg_surface; struct xdg_toplevel *xdg_toplevel; struct buffer buffers[2]; @@ -235,6 +236,13 @@ static struct window *CreateWindow(struct display *display, int32_t width, int32 assert(0); } + // region test + pWindow->region = wl_compositor_create_region(display->compositor); + wl_region_add(pWindow->region, 0, 0, width, height); + wl_surface_set_opaque_region(pWindow->surface, pWindow->region); + wl_surface_set_input_region(pWindow->surface, pWindow->region); + wl_region_destroy(pWindow->region); + return pWindow; } -- Gitee