From dec9feb5a90383513b4b556cf1e7b5b134ffa2e5 Mon Sep 17 00:00:00 2001 From: abc12133 Date: Wed, 13 Sep 2023 09:58:37 +0800 Subject: [PATCH] add wayland sub Signed-off-by: abc12133 --- wayland_adapter/framework/BUILD.gn | 2 + .../framework/core/wayland_subcompositor.cpp | 79 +++++++++++++++++++ .../framework/core/wayland_subcompositor.h | 51 ++++++++++++ .../framework/core/wayland_subsurface.cpp | 65 +++++++++++++++ .../framework/core/wayland_subsurface.h | 42 ++++++++++ wayland_adapter/test/wayland_demo.cpp | 2 +- wayland_adapter/wayland_server.cpp | 3 + wayland_adapter/wayland_server.h | 2 + 8 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 wayland_adapter/framework/core/wayland_subcompositor.cpp create mode 100644 wayland_adapter/framework/core/wayland_subcompositor.h create mode 100644 wayland_adapter/framework/core/wayland_subsurface.cpp create mode 100644 wayland_adapter/framework/core/wayland_subsurface.h diff --git a/wayland_adapter/framework/BUILD.gn b/wayland_adapter/framework/BUILD.gn index 7ebb236..cefbbb6 100644 --- a/wayland_adapter/framework/BUILD.gn +++ b/wayland_adapter/framework/BUILD.gn @@ -31,6 +31,8 @@ ft_source_set("wayland_framewok_sources") { "core/wayland_pointer.cpp", "core/wayland_keyboard.cpp", "core/wayland_output.cpp", + "core/wayland_subcompositor.cpp", + "core/wayland_subsurface.cpp", ] sources += [ diff --git a/wayland_adapter/framework/core/wayland_subcompositor.cpp b/wayland_adapter/framework/core/wayland_subcompositor.cpp new file mode 100644 index 0000000..70c4ec5 --- /dev/null +++ b/wayland_adapter/framework/core/wayland_subcompositor.cpp @@ -0,0 +1,79 @@ +/* + * 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_subcompositor.h" + +#include "wayland_subsurface.h" +#include "wayland_objects_pool.h" +#include "version.h" + +namespace FT { +namespace Wayland { +namespace { + constexpr HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WAYLAND, "WaylandSubCompositor"}; +} + +struct wl_subcompositor_interface IWaylandSubCompositor::impl_ = { + .destroy = WaylandResourceObject::DefaultDestroyResource, + .get_subsurface = IWaylandSubCompositor::GetSubSurface}; + +void IWaylandSubCompositor::GetSubSurface(struct wl_client *client, struct wl_resource *resource, + uint32_t id, struct wl_resource *surface, struct wl_resource *parent) +{ + CAST_OBJECT_AND_CALL_FUNC(WaylandSubCompositorObject, resource, + "OECompositorInterface::CreateRegion: failed to find object.", CreateSubSurface, id, surface, parent); +} + +OHOS::sptr WaylandSubCompositor::Create(struct wl_display *display) +{ + if (display == nullptr) { + LOG_ERROR("display is nullptr"); + return nullptr; + } + + return OHOS::sptr(new WaylandSubCompositor(display)); +} + +WaylandSubCompositor::WaylandSubCompositor(struct wl_display *display) + : WaylandGlobal(display, &wl_subcompositor_interface, WL_SUBCOMPOSITOR_MAX_VERSION) {} + +WaylandSubCompositor::~WaylandSubCompositor() noexcept {} + +void WaylandSubCompositor::Bind(struct wl_client *client, uint32_t version, uint32_t id) +{ + auto object = OHOS::sptr(new WaylandSubCompositorObject(client, version, id)); + if (object == nullptr) { + LOG_ERROR("no memory"); + return; + } + WaylandObjectsPool::GetInstance().AddObject(ObjectId(object->WlClient(), object->Id()), object); +} + +WaylandSubCompositorObject::WaylandSubCompositorObject(struct wl_client *client, + uint32_t version, uint32_t id) + : WaylandResourceObject(client, &wl_subcompositor_interface, version, id, &IWaylandSubCompositor::impl_) {} + +WaylandSubCompositorObject::~WaylandSubCompositorObject() noexcept {} + +void WaylandSubCompositorObject::CreateSubSurface(uint32_t id, struct wl_resource *surface, struct wl_resource *parent) +{ + auto subSurface = WaylandSubSurface::Create(WlClient(), wl_resource_get_version(WlResource()), id, surface, parent); + if (subSurface == nullptr) { + LOG_ERROR("no memory"); + return; + } +} +} // namespace Wayland +} // namespace FT diff --git a/wayland_adapter/framework/core/wayland_subcompositor.h b/wayland_adapter/framework/core/wayland_subcompositor.h new file mode 100644 index 0000000..2925beb --- /dev/null +++ b/wayland_adapter/framework/core/wayland_subcompositor.h @@ -0,0 +1,51 @@ +/* + * 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 "wayland_global.h" + +namespace FT { +namespace Wayland { +struct IWaylandSubCompositor { + static void GetSubSurface(struct wl_client *client, struct wl_resource *resource, + uint32_t id, struct wl_resource *surface, struct wl_resource *parent); + static struct wl_subcompositor_interface impl_; +}; + +class WaylandSubCompositor final : public WaylandGlobal { + friend struct IWaylandSubCompositor; + +public: + static OHOS::sptr Create(struct wl_display *display); + ~WaylandSubCompositor() noexcept override; + +private: + WaylandSubCompositor(struct wl_display *display); + void Bind(struct wl_client *client, uint32_t version, uint32_t id) override; +}; + +class WaylandSubCompositorObject final : public WaylandResourceObject { + friend struct IWaylandSubCompositor; + +public: + WaylandSubCompositorObject(struct wl_client *client, uint32_t version, uint32_t id); + ~WaylandSubCompositorObject() noexcept; + +private: + void CreateSubSurface(uint32_t id, struct wl_resource *surface, struct wl_resource *parent); +}; +} // namespace Wayland +} // namespace FT diff --git a/wayland_adapter/framework/core/wayland_subsurface.cpp b/wayland_adapter/framework/core/wayland_subsurface.cpp new file mode 100644 index 0000000..009315c --- /dev/null +++ b/wayland_adapter/framework/core/wayland_subsurface.cpp @@ -0,0 +1,65 @@ +/* + * 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_subsurface.h" + +#include "wayland_objects_pool.h" + +namespace FT { +namespace Wayland { +namespace { + constexpr HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WAYLAND, "WaylandSubSurface"}; +} + +struct wl_subsurface_interface IWaylandSubSurface::impl_ = { + .destroy = WaylandResourceObject::DefaultDestroyResource, + .set_position = IWaylandSubSurface::SetPosition, + .place_above = IWaylandSubSurface::PlaceAbove, + .place_below = IWaylandSubSurface::PlaceBelow, + .set_sync = IWaylandSubSurface::SetSync, + .set_desync = IWaylandSubSurface::SetDesync, +}; + +void IWaylandSubSurface::SetPosition(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y) {} + +void IWaylandSubSurface::PlaceAbove(struct wl_client *client, struct wl_resource *resource, + struct wl_resource *sibling) {} + +void IWaylandSubSurface::PlaceBelow(struct wl_client *client, struct wl_resource *resource, + struct wl_resource *sibling) {} + +void IWaylandSubSurface::SetSync(struct wl_client *client, struct wl_resource *resource) {} + +void IWaylandSubSurface::SetDesync(struct wl_client *client, struct wl_resource *resource) {} + +OHOS::sptr WaylandSubSurface::Create(struct wl_client *client, uint32_t version, + uint32_t id, struct wl_resource *surface, struct wl_resource *parent) +{ + if (client == nullptr) { + return nullptr; + } + + auto subSurface = OHOS::sptr(new WaylandSubSurface(client, version, id, surface, parent)); + WaylandObjectsPool::GetInstance().AddObject(ObjectId(subSurface->WlClient(), subSurface->Id()), subSurface); + return subSurface; +} + +WaylandSubSurface::WaylandSubSurface(struct wl_client *client, uint32_t version, uint32_t id, + struct wl_resource *surface, struct wl_resource *parent) + : WaylandResourceObject(client, &wl_subsurface_interface, version, id, &IWaylandSubSurface::impl_) {} + +WaylandSubSurface::~WaylandSubSurface() noexcept {} +} // namespace Wayland +} // namespace FT diff --git a/wayland_adapter/framework/core/wayland_subsurface.h b/wayland_adapter/framework/core/wayland_subsurface.h new file mode 100644 index 0000000..fffa6b4 --- /dev/null +++ b/wayland_adapter/framework/core/wayland_subsurface.h @@ -0,0 +1,42 @@ +/* + * 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 "wayland_resource_object.h" + +namespace FT { +namespace Wayland { +struct IWaylandSubSurface { + static void SetPosition(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y); + static void PlaceAbove(struct wl_client *client, struct wl_resource *resource, struct wl_resource *sibling); + static void PlaceBelow(struct wl_client *client, struct wl_resource *resource, struct wl_resource *sibling); + static void SetSync(struct wl_client *client, struct wl_resource *resource); + static void SetDesync(struct wl_client *client, struct wl_resource *resource); + static struct wl_subsurface_interface impl_; +}; + +class WaylandSubSurface : public WaylandResourceObject { +public: + static OHOS::sptr Create(struct wl_client *client, uint32_t version, uint32_t id, + struct wl_resource *surface, struct wl_resource *parent); + ~WaylandSubSurface() noexcept override; + +private: + WaylandSubSurface(struct wl_client *client, uint32_t version, uint32_t id, + struct wl_resource *surface, struct wl_resource *parent); +}; +} // namespace Wayland +} // namespace FT diff --git a/wayland_adapter/test/wayland_demo.cpp b/wayland_adapter/test/wayland_demo.cpp index 8dcc262..10930be 100644 --- a/wayland_adapter/test/wayland_demo.cpp +++ b/wayland_adapter/test/wayland_demo.cpp @@ -314,7 +314,7 @@ public: return; } - canvas_->clear(SK_ColorTRANSPARENT); + canvas_->clear(SK_ColorGRAY); { // draw circle diff --git a/wayland_adapter/wayland_server.cpp b/wayland_adapter/wayland_server.cpp index 8ee00f9..a3e5692 100644 --- a/wayland_adapter/wayland_server.cpp +++ b/wayland_adapter/wayland_server.cpp @@ -39,6 +39,7 @@ void WaylandServer::CreateGlobalObjects() compositorGlobal_ = WaylandCompositor::Create(display_); xdgWmBaseGlobal_ = WaylandXdgWmBase::Create(display_); outputGlobal_ = WaylandOutput::Create(display_); + subCompositorGlobal_ = WaylandSubCompositor::Create(display_); wl_display_add_shm_format(display_, WL_SHM_FORMAT_RGBA8888); wl_display_init_shm(display_); } @@ -102,6 +103,8 @@ void WaylandServer::OnStop() loop_ = nullptr; compositorGlobal_ = nullptr; xdgWmBaseGlobal_ = nullptr; + outputGlobal_ = nullptr; + subCompositorGlobal_ = nullptr; } void WaylandServer::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) diff --git a/wayland_adapter/wayland_server.h b/wayland_adapter/wayland_server.h index aa88d18..f17770b 100644 --- a/wayland_adapter/wayland_server.h +++ b/wayland_adapter/wayland_server.h @@ -24,6 +24,7 @@ #include "wayland_compositor.h" #include "wayland_xdg_wm_base.h" #include "wayland_output.h" +#include "wayland_subcompositor.h" namespace FT { namespace Wayland { @@ -52,6 +53,7 @@ private: OHOS::sptr compositorGlobal_; OHOS::sptr xdgWmBaseGlobal_; OHOS::sptr outputGlobal_; + OHOS::sptr subCompositorGlobal_; }; } // namespace Wayland } // namespace FT -- Gitee