diff --git a/wayland_adapter/framework/BUILD.gn b/wayland_adapter/framework/BUILD.gn index dc7113ea0543f34bcb9c605e36bfcfb942f0b93b..b8feb357f14efd10c284f6c3957d8f59daa68dd5 100644 --- a/wayland_adapter/framework/BUILD.gn +++ b/wayland_adapter/framework/BUILD.gn @@ -25,7 +25,10 @@ config("wayland_framework_public_config") { ft_source_set("wayland_framewok_sources") { sources = [ "core/wayland_compositor.cpp", + "core/wayland_seat.cpp", "core/wayland_surface.cpp", + "core/wayland_pointer.cpp", + "core/wayland_keyboard.cpp", ] sources += [ diff --git a/wayland_adapter/framework/core/wayland_keyboard.cpp b/wayland_adapter/framework/core/wayland_keyboard.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ac5d37be30a9e6ef285d0966f86a4a7aac3ec605 --- /dev/null +++ b/wayland_adapter/framework/core/wayland_keyboard.cpp @@ -0,0 +1,48 @@ +/* + * 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_keyboard.h" + +#include "version.h" +#include "wayland_objects_pool.h" + +namespace FT { +namespace Wayland { +namespace { + constexpr HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WAYLAND, "WaylandKeyboard"}; +} + +struct wl_keyboard_interface IWaylandKeyboard::impl_ = { + .release = WaylandResourceObject::DefaultDestroyResource, +}; + +OHOS::sptr WaylandKeyboard::Create(struct wl_client *client, uint32_t version, uint32_t id) +{ + if (client == nullptr) { + return nullptr; + } + + auto keyboard = OHOS::sptr(new WaylandKeyboard(client, version, id)); + WaylandObjectsPool::GetInstance().AddObject(ObjectId(keyboard->WlClient(), keyboard->Id()), keyboard); + + return keyboard; +} + +WaylandKeyboard::WaylandKeyboard(struct wl_client *client, uint32_t version, uint32_t id) + : WaylandResourceObject(client, &wl_keyboard_interface, version, id, &IWaylandKeyboard::impl_) {} + +WaylandKeyboard::~WaylandKeyboard() noexcept {} +} // namespace Wayland +} // namespace FT \ No newline at end of file diff --git a/wayland_adapter/framework/core/wayland_keyboard.h b/wayland_adapter/framework/core/wayland_keyboard.h new file mode 100644 index 0000000000000000000000000000000000000000..91888f58a09c999314dec560a9eba089bcec58a3 --- /dev/null +++ b/wayland_adapter/framework/core/wayland_keyboard.h @@ -0,0 +1,37 @@ +/* + * 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 IWaylandKeyboard { + static struct wl_keyboard_interface impl_; +}; + +class WaylandKeyboard final : public WaylandResourceObject { + friend struct IWaylandKeyboard; + +public: + static OHOS::sptr Create(struct wl_client *client, uint32_t version, uint32_t id); + ~WaylandKeyboard() noexcept override; + +private: + WaylandKeyboard(struct wl_client *client, uint32_t version, uint32_t id); +}; +} // namespace Wayland +} // namespace FT \ No newline at end of file diff --git a/wayland_adapter/framework/core/wayland_pointer.cpp b/wayland_adapter/framework/core/wayland_pointer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3168935755051c458d1352fa01eaa15cfc02fa8b --- /dev/null +++ b/wayland_adapter/framework/core/wayland_pointer.cpp @@ -0,0 +1,58 @@ +/* + * 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_pointer.h" + +#include "version.h" +#include "wayland_objects_pool.h" + +namespace FT { +namespace Wayland { +namespace { + constexpr HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WAYLAND, "WaylandPointer"}; +} + +struct wl_pointer_interface IWaylandPointer::impl_ = { + .set_cursor = SetCursor, + .release = WaylandResourceObject::DefaultDestroyResource, +}; + +void IWaylandPointer::SetCursor(struct wl_client *client, struct wl_resource *resource, + uint32_t serial, struct wl_resource *surface, int32_t hotspot_x, int32_t hotspot_y) +{ + CAST_OBJECT_AND_CALL_FUNC(WaylandPointer, resource, "IWaylandPointer::SetCursor: failed to find object.", + SetCursor, serial, surface, hotspot_x, hotspot_y); +} + +OHOS::sptr WaylandPointer::Create(struct wl_client *client, uint32_t version, uint32_t id) +{ + if (client == nullptr) { + return nullptr; + } + + auto pointer = OHOS::sptr(new WaylandPointer(client, version, id)); + WaylandObjectsPool::GetInstance().AddObject(ObjectId(pointer->WlClient(), pointer->Id()), pointer); + + return pointer; +} + +WaylandPointer::WaylandPointer(struct wl_client *client, uint32_t version, uint32_t id) + : WaylandResourceObject(client, &wl_pointer_interface, version, id, &IWaylandPointer::impl_) {} + +WaylandPointer::~WaylandPointer() noexcept {} + +void WaylandPointer::SetCursor(uint32_t serial, struct wl_resource *surface, int32_t hotsPotx, int32_t hotsPoty) {} +} // namespace Wayland +} // namespace FT \ No newline at end of file diff --git a/wayland_adapter/framework/core/wayland_pointer.h b/wayland_adapter/framework/core/wayland_pointer.h new file mode 100644 index 0000000000000000000000000000000000000000..a7878973c2d2ad97ddc55c5e3b809b3653be8297 --- /dev/null +++ b/wayland_adapter/framework/core/wayland_pointer.h @@ -0,0 +1,40 @@ +/* + * 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 IWaylandPointer { + static void SetCursor(struct wl_client *client, struct wl_resource *resource, + uint32_t serial, struct wl_resource *surface, int32_t hotspot_x, int32_t hotspot_y); + static struct wl_pointer_interface impl_; +}; + +class WaylandPointer final : public WaylandResourceObject { + friend struct IWaylandPointer; + +public: + static OHOS::sptr Create(struct wl_client *client, uint32_t version, uint32_t id); + ~WaylandPointer() noexcept override; + +private: + WaylandPointer(struct wl_client *client, uint32_t version, uint32_t id); + void SetCursor(uint32_t serial, struct wl_resource *surface, int32_t hotsPotx, int32_t hotsPoty); +}; +} // namespace Wayland +} // namespace FT \ No newline at end of file diff --git a/wayland_adapter/framework/core/wayland_seat.cpp b/wayland_adapter/framework/core/wayland_seat.cpp new file mode 100644 index 0000000000000000000000000000000000000000..01909f288c25851c20916e006ffc87a7b6ed4a7a --- /dev/null +++ b/wayland_adapter/framework/core/wayland_seat.cpp @@ -0,0 +1,107 @@ +/* + * 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_seat.h" + +#include "wayland_objects_pool.h" +#include "version.h" + +namespace FT { +namespace Wayland { +namespace { + constexpr HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WAYLAND, "WaylandSeat"}; +} + +struct wl_seat_interface IWaylandSeat::impl_ = { + .get_pointer = GetPointer, + .get_keyboard = GetKeyboard, + .get_touch = GetTouch, + .release = WaylandResourceObject::DefaultDestroyResource,}; + +void IWaylandSeat::GetPointer(struct wl_client *client, struct wl_resource *resource, uint32_t id) +{ + CAST_OBJECT_AND_CALL_FUNC(WaylandSeatObject, resource, + "IWaylandSeat::GetPointer: failed to find object.", GetPointer, id); +} + +void IWaylandSeat::GetKeyboard(struct wl_client *client, struct wl_resource *resource, uint32_t id) +{ + CAST_OBJECT_AND_CALL_FUNC(WaylandSeatObject, resource, + "IWaylandSeat::GetKeyboard: failed to find object.", GetKeyboard, id); +} + +void IWaylandSeat::GetTouch(struct wl_client *client, struct wl_resource *resource, uint32_t id) +{ + CAST_OBJECT_AND_CALL_FUNC(WaylandSeatObject, resource, + "IWaylandSeat::GetTouch: failed to find object.", GetTouch, id); +} + +OHOS::sptr WaylandSeat::Create(struct wl_display *display) +{ + if (display == nullptr) { + LOG_ERROR("display is nullptr"); + return nullptr; + } + + return OHOS::sptr(new WaylandSeat(display)); +} + +WaylandSeat::WaylandSeat(struct wl_display *display) + : WaylandGlobal(display, &wl_seat_interface, WL_SEAT_MAX_VERSION) {} + +WaylandSeat::~WaylandSeat() noexcept {} + +void WaylandSeat::Bind(struct wl_client *client, uint32_t version, uint32_t id) +{ + auto object = OHOS::sptr(new WaylandSeatObject(client, version, id)); + if (object == nullptr) { + LOG_ERROR("no memory"); + return; + } + WaylandObjectsPool::GetInstance().AddObject(ObjectId(object->WlClient(), object->Id()), object); +} + +WaylandSeatObject::WaylandSeatObject(struct wl_client *client, uint32_t version, uint32_t id) + : WaylandResourceObject(client, &wl_seat_interface, version, id, &IWaylandSeat::impl_) {} + +WaylandSeatObject::~WaylandSeatObject() noexcept {} + +void WaylandSeatObject::GetPointer(uint32_t id) +{ + auto pointer = WaylandPointer::Create(WlClient(), wl_resource_get_version(WlResource()), id); + if (pointer == nullptr) { + LOG_ERROR("no memory"); + return; + } + + pointer_ = pointer; +} + +void WaylandSeatObject::GetKeyboard(uint32_t id) +{ + auto keyboard = WaylandKeyboard::Create(WlClient(), wl_resource_get_version(WlResource()), id); + if (keyboard == nullptr) { + LOG_ERROR("no memory"); + return; + } + + keyboard_ = keyboard; +} + +void WaylandSeatObject::GetTouch(uint32_t id) +{ +} +} // namespace Wayland +} // namespace FT diff --git a/wayland_adapter/framework/core/wayland_seat.h b/wayland_adapter/framework/core/wayland_seat.h new file mode 100644 index 0000000000000000000000000000000000000000..2afb70eba7e6035a0a8a8a3d56ac1638c3ac08a4 --- /dev/null +++ b/wayland_adapter/framework/core/wayland_seat.h @@ -0,0 +1,59 @@ +/* + * 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" +#include "wayland_pointer.h" +#include "wayland_keyboard.h" + +namespace FT { +namespace Wayland { +struct IWaylandSeat { + static void GetPointer(struct wl_client *client, struct wl_resource *resource, uint32_t id); + static void GetKeyboard(struct wl_client *client, struct wl_resource *resource, uint32_t id); + static void GetTouch(struct wl_client *client, struct wl_resource *resource, uint32_t id); + static struct wl_seat_interface impl_; +}; + +class WaylandSeat final : public WaylandGlobal { + friend struct IWaylandSeat; + +public: + static OHOS::sptr Create(struct wl_display *display); + ~WaylandSeat() noexcept override; + +private: + WaylandSeat(struct wl_display *display); + void Bind(struct wl_client *client, uint32_t version, uint32_t id) override; +}; + +class WaylandSeatObject final : public WaylandResourceObject { + friend struct IWaylandSeat; + +public: + WaylandSeatObject(struct wl_client *client, uint32_t version, uint32_t id); + ~WaylandSeatObject() noexcept; + +private: + void GetPointer(uint32_t id); + void GetKeyboard(uint32_t id); + void GetTouch(uint32_t id); + + OHOS::wptr pointer_; + OHOS::wptr keyboard_; +}; +} // namespace Wayland +} // namespace FT diff --git a/wayland_adapter/framework/core/wayland_surface.cpp b/wayland_adapter/framework/core/wayland_surface.cpp index 430214b2e360bf2014191b5a887bc583dc967220..e9a4ad5b045a292c69e28a6bbb4eaae73787a36f 100644 --- a/wayland_adapter/framework/core/wayland_surface.cpp +++ b/wayland_adapter/framework/core/wayland_surface.cpp @@ -143,6 +143,7 @@ void WaylandSurface::Attach(struct wl_resource *bufferResource, int32_t x, int32 } wl_shm_buffer_end_access(shm); + wl_callback_send_done(bufferResource, 0); } void WaylandSurface::Damage(int32_t x, int32_t y, int32_t width, int32_t height) @@ -151,6 +152,15 @@ void WaylandSurface::Damage(int32_t x, int32_t y, int32_t width, int32_t height) void WaylandSurface::Frame(uint32_t callback) { + auto cb = FrameCallback::Create(WlClient(), WAYLAND_VERSION_MAJOR, callback); + if (cb == nullptr) { + LOG_ERROR("no memory"); + return; + } + + WaylandObjectsPool::GetInstance().AddObject(ObjectId(cb->WlClient(), cb->Id()), cb); + wl_callback_send_done(cb->WlResource(), 0); + wl_resource_destroy(cb->WlResource()); } void WaylandSurface::SetOpaqueRegion(struct wl_resource *regionResource) @@ -183,5 +193,16 @@ void WaylandSurface::DamageBuffer(int32_t x, int32_t y, int32_t width, int32_t h void WaylandSurface::Offset(int32_t x, int32_t y) { } + +OHOS::sptr WaylandSurface::FrameCallback::Create(struct wl_client *client, + uint32_t version, uint32_t callback) +{ + return OHOS::sptr(new WaylandSurface::FrameCallback(client, version, callback)); +} + +WaylandSurface::FrameCallback::FrameCallback(struct wl_client *client, uint32_t version, uint32_t callback) + : WaylandResourceObject(client, &wl_callback_interface, version, callback, nullptr), serial_(callback) {} + +WaylandSurface::FrameCallback::~FrameCallback() noexcept {} } // namespace Wayland } // namespace FT diff --git a/wayland_adapter/framework/core/wayland_surface.h b/wayland_adapter/framework/core/wayland_surface.h index b5a539aa16df79c933d334c10f21cb26c634bf56..ed9b4d98e46c126b82e9ad4127fae721cdb5846d 100644 --- a/wayland_adapter/framework/core/wayland_surface.h +++ b/wayland_adapter/framework/core/wayland_surface.h @@ -45,7 +45,8 @@ class WaylandSurface final : public WaylandResourceObject { friend struct IWaylandSurface; public: - static OHOS::sptr Create(struct wl_client *client, struct wl_resource *parent, uint32_t version, uint32_t id); + static OHOS::sptr Create(struct wl_client *client, struct wl_resource *parent, + uint32_t version, uint32_t id); ~WaylandSurface() noexcept override; using SurfaceCommitCallback = std::function; @@ -67,6 +68,19 @@ private: void DamageBuffer(int32_t x, int32_t y, int32_t width, int32_t height); void Offset(int32_t x, int32_t y); + class FrameCallback final : public WaylandResourceObject { + public: + static OHOS::sptr Create(struct wl_client *client, uint32_t version, uint32_t callback); + uint32_t Serial() const + { + return serial_; + } + private: + FrameCallback(struct wl_client *client, uint32_t version, uint32_t callback); + ~FrameCallback() noexcept override; + uint32_t serial_; + }; + struct wl_resource *parent_ = nullptr; std::list commitCallbacks_; std::list attachCallbacks_; diff --git a/wayland_adapter/test/wayland_demo.cpp b/wayland_adapter/test/wayland_demo.cpp index b3dc48006e9944bfff4920fc4cfb26817d52e227..a5b79650dd421bee0df7963c5beebd82812a1cc5 100644 --- a/wayland_adapter/test/wayland_demo.cpp +++ b/wayland_adapter/test/wayland_demo.cpp @@ -466,7 +466,7 @@ private: auto hour = nowTm_->tm_hour; auto minute = nowTm_->tm_min; auto sec = nowTm_->tm_sec; - DrawHand(sec, std::min(width_, height_) * 0.34, SK_ColorRED, 2.0); + DrawHand(sec, std::min(width_, height_) * 0.34, SK_ColorBLACK, 2.0); DrawHand(minute + sec * 1.0 / 60, std::min(width_, height_) * 0.26, SK_ColorBLACK, 6.0); DrawHand(hour * 5 + minute * 1.0 / 60 * 5, std::min(width_, height_) * 0.2, SK_ColorBLACK, 8.0); }