From 324b39c970c6cca30254bd7cd59ac5e27acfaf31 Mon Sep 17 00:00:00 2001 From: Junkyeong Kim Date: Thu, 27 Aug 2020 17:21:21 +0900 Subject: [PATCH] add DSWaylandTizenSurface interface Change-Id: I695ee10c2f716682199baaf4736e9d0d51da8655 Signed-off-by: Junkyeong Kim --- src/DSWaylandServer/DSWaylandTizenSurface.cpp | 213 +++++++++++++++++++++ src/DSWaylandServer/DSWaylandTizenSurface.h | 66 +++++++ src/DSWaylandServer/DSWaylandTizenSurfacePrivate.h | 81 ++++++++ src/meson.build | 3 + tests/DSWaylandTizenSurface-test.cpp | 47 +++++ tests/meson.build | 1 + 6 files changed, 411 insertions(+) create mode 100644 src/DSWaylandServer/DSWaylandTizenSurface.cpp create mode 100644 src/DSWaylandServer/DSWaylandTizenSurface.h create mode 100644 src/DSWaylandServer/DSWaylandTizenSurfacePrivate.h create mode 100644 tests/DSWaylandTizenSurface-test.cpp diff --git a/src/DSWaylandServer/DSWaylandTizenSurface.cpp b/src/DSWaylandServer/DSWaylandTizenSurface.cpp new file mode 100644 index 0000000..0a693cb --- /dev/null +++ b/src/DSWaylandServer/DSWaylandTizenSurface.cpp @@ -0,0 +1,213 @@ +/* +* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#include "DSWaylandTizenSurface.h" +#include "DSWaylandTizenSurfacePrivate.h" + +namespace display_server +{ + +/* DSWaylandTizenSurface */ +DSWaylandTizenSurfacePrivate::DSWaylandTizenSurfacePrivate(DSWaylandTizenSurface *p_ptr, DSWaylandCompositor *compositor) + : DSObjectPrivate(p_ptr), + __p_ptr(p_ptr), + __resource_id_cnt(0) +{ + if (!compositor) + return; + + init(compositor->display(), 1); +} + +DSWaylandTizenSurfacePrivate::~DSWaylandTizenSurfacePrivate() +{ +} + +void DSWaylandTizenSurfacePrivate::tizen_surface_bind_resource(Resource *resource) +{ +} + +void DSWaylandTizenSurfacePrivate::tizen_surface_destroy_resource(Resource *resource) +{ +} + +void DSWaylandTizenSurfacePrivate::tizen_surface_get_tizen_resource(Resource *resource, uint32_t id, struct ::wl_resource *surface) +{ + DSWaylandTizenResource *tizenResource = nullptr; + + for (DSWaylandTizenResource *temp : __resourceList) + if (temp->getResourceSurface() == surface) return; + + tizenResource = new DSWaylandTizenResource(resource->client(), id, surface); + if (tizenResource == nullptr) + { + DSLOG_ERR("DSWaylandTizenSurface", "fail get tizen resource"); + return; + } + + __resource_id_cnt++; + tizenResource->setResourceId(__resource_id_cnt); + + __resourceList.push_back(tizenResource); + + tizenResource->sendResourceId(); +} + +void DSWaylandTizenSurfacePrivate::tizen_surface_destroy(Resource *resource) +{ +} + +DSWaylandTizenResource *DSWaylandTizenSurfacePrivate::getTizenResource(struct ::wl_resource *surface) +{ + DSWaylandTizenResource *tizenResource = nullptr; + + for (DSWaylandTizenResource *temp : __resourceList) + { + if (temp->getResourceSurface() == surface) + { + tizenResource = temp; + break; + } + } + + return tizenResource; +} + +void DSWaylandTizenSurfacePrivate::delTizenResource(DSWaylandTizenResource *tizenResource) +{ + __resourceList.remove(tizenResource); +} + +DSWaylandTizenSurface::DSWaylandTizenSurface(DSWaylandCompositor *compositor) + : _d_ptr(std::make_unique(this, compositor)) +{ +} + +DSWaylandTizenSurface::~DSWaylandTizenSurface() +{ +} + +DSWaylandTizenResource *DSWaylandTizenSurface::getTizenResource(struct ::wl_resource *surface) +{ + DS_GET_PRIV(DSWaylandTizenSurface); + + return priv->getTizenResource(surface); +} + +void DSWaylandTizenSurface::delTizenResource(DSWaylandTizenResource *tizenResource) +{ + DS_GET_PRIV(DSWaylandTizenSurface); + + priv->delTizenResource(tizenResource); +} + +/* DSWaylandTizenResource */ +DSWaylandTizenResourcePrivate::DSWaylandTizenResourcePrivate(DSWaylandTizenResource *p_ptr, struct ::wl_client *client, uint32_t id, struct ::wl_resource *surface) + : DSObjectPrivate(p_ptr), + __p_ptr(p_ptr), + __surface(surface), + __resource_id(0) +{ + init(client, id, 1); +} + +DSWaylandTizenResourcePrivate::~DSWaylandTizenResourcePrivate() +{ +} + +void DSWaylandTizenResourcePrivate::tizen_resource_bind_resource(Resource *resource) +{ +} + +void DSWaylandTizenResourcePrivate::tizen_resource_destroy_resource(Resource *resource) +{ +} + +void DSWaylandTizenResourcePrivate::tizen_resource_destroy(Resource *resource) +{ +} + +struct ::wl_resource *DSWaylandTizenResourcePrivate::getResourceSurface(void) +{ + return __surface; +} + +void DSWaylandTizenResourcePrivate::sendResourceId(void) +{ + send_resource_id(__resource_id); +} + +void DSWaylandTizenResourcePrivate::setResourceId(uint32_t tizenResourceId) +{ + __resource_id = tizenResourceId; +} + +uint32_t DSWaylandTizenResourcePrivate::getResourceId(void) +{ + return __resource_id; +} + +DSWaylandTizenResource::DSWaylandTizenResource(struct ::wl_client *client, uint32_t id, struct ::wl_resource *surface) + : _d_ptr(std::make_unique(this, client, id, surface)) +{ +} + +DSWaylandTizenResource::~DSWaylandTizenResource() +{ +} + +struct ::wl_resource *DSWaylandTizenResource::getResourceSurface(void) +{ + DS_GET_PRIV(DSWaylandTizenResource); + + return priv->getResourceSurface(); +} + +void DSWaylandTizenResource::sendResourceId(void) +{ + DS_GET_PRIV(DSWaylandTizenResource); + + DSLOG_INF("DSWaylandTizenResource", "send Resource Id"); + + priv->sendResourceId(); +} + +void DSWaylandTizenResource::setResourceId(uint32_t tizenResourceId) +{ + DS_GET_PRIV(DSWaylandTizenResource); + + DSLOG_INF("DSWaylandTizenResource", "send Resource Id"); + + priv->setResourceId(tizenResourceId); +} + +uint32_t DSWaylandTizenResource::getResourceId(void) +{ + DS_GET_PRIV(DSWaylandTizenResource); + + DSLOG_INF("DSWaylandTizenResource", "send Resource Id"); + + return priv->getResourceId(); +} + +} // namespace display_server diff --git a/src/DSWaylandServer/DSWaylandTizenSurface.h b/src/DSWaylandServer/DSWaylandTizenSurface.h new file mode 100644 index 0000000..6621b53 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandTizenSurface.h @@ -0,0 +1,66 @@ +/* +* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#ifndef _DS_WAYLAND_TIZEN_SURFACE_H_ +#define _DS_WAYLAND_TIZEN_SURFACE_H_ + +#include +#include +#include +#include + +namespace display_server +{ + +class DSWaylandTizenSurfacePrivate; +class DSWaylandTizenResourcePrivate; + +class DS_DECL_EXPORT DSWaylandTizenResource : public DSObject +{ +DS_PIMPL_USE_PRIVATE(DSWaylandTizenResource); + +public: + DSWaylandTizenResource(struct ::wl_client *client, uint32_t id, struct ::wl_resource *surface); + virtual ~DSWaylandTizenResource(); + + struct ::wl_resource *getResourceSurface(void); + void sendResourceId(void); + void setResourceId(uint32_t tizenResourceId); + uint32_t getResourceId(void); +}; + +class DS_DECL_EXPORT DSWaylandTizenSurface : public DSObject +{ +DS_PIMPL_USE_PRIVATE(DSWaylandTizenSurface); + +public: + DSWaylandTizenSurface(DSWaylandCompositor *compositor); + virtual ~DSWaylandTizenSurface(); + + DSWaylandTizenResource *getTizenResource(struct ::wl_resource *surface); + void delTizenResource(DSWaylandTizenResource *resource); +}; + +} + +#endif diff --git a/src/DSWaylandServer/DSWaylandTizenSurfacePrivate.h b/src/DSWaylandServer/DSWaylandTizenSurfacePrivate.h new file mode 100644 index 0000000..27ea899 --- /dev/null +++ b/src/DSWaylandServer/DSWaylandTizenSurfacePrivate.h @@ -0,0 +1,81 @@ +/* +* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#ifndef _DS_WAYLAND_TIZEN_SURFACE_PRIVATE_H_ +#define _DS_WAYLAND_TIZEN_SURFACE_PRIVATE_H_ + +#include "dswayland-server-tizen-extension.h" +#include "DSWaylandTizenSurface.h" + +namespace display_server +{ + +class DS_DECL_EXPORT DSWaylandTizenResourcePrivate : public DSObjectPrivate, public DSWaylandServer::tizen_resource +{ +DS_PIMPL_USE_PUBLIC(DSWaylandTizenResource); + +public: + DSWaylandTizenResourcePrivate() = delete; + DSWaylandTizenResourcePrivate(DSWaylandTizenResource *p_ptr, struct ::wl_client *client, uint32_t id, struct ::wl_resource *surface); + ~DSWaylandTizenResourcePrivate() override; + + struct ::wl_resource *getResourceSurface(void); + void sendResourceId(void); + void setResourceId(uint32_t tizenResourceId); + uint32_t getResourceId(void); + +protected: + void tizen_resource_bind_resource(Resource *resource) override; + void tizen_resource_destroy_resource(Resource *resource) override; + void tizen_resource_destroy(Resource *resource) override; +private: + struct ::wl_resource *__surface; + uint32_t __resource_id; +}; + +class DS_DECL_EXPORT DSWaylandTizenSurfacePrivate : public DSObjectPrivate, public DSWaylandServer::tizen_surface +{ +DS_PIMPL_USE_PUBLIC(DSWaylandTizenSurface); + +public: + DSWaylandTizenSurfacePrivate() = delete; + DSWaylandTizenSurfacePrivate(DSWaylandTizenSurface *p_ptr, DSWaylandCompositor *compositor); + ~DSWaylandTizenSurfacePrivate() override; + + DSWaylandTizenResource *getTizenResource(struct ::wl_resource *surface); + void delTizenResource(DSWaylandTizenResource *resource); + +protected: + void tizen_surface_bind_resource(Resource *resource) override; + void tizen_surface_destroy_resource(Resource *resource) override; + void tizen_surface_get_tizen_resource(Resource *resource, uint32_t id, struct ::wl_resource *surface) override; + void tizen_surface_destroy(Resource *resource) override; + +private: + std::list __resourceList; + uint32_t __resource_id_cnt; //TO DO : have to manage more proper class +}; + +} + +#endif diff --git a/src/meson.build b/src/meson.build index d008344..7042c46 100644 --- a/src/meson.build +++ b/src/meson.build @@ -117,6 +117,9 @@ libds_wayland_srcs = [ 'DSWaylandServer/DSWaylandTizenPolicy.cpp', 'DSWaylandServer/DSWaylandTizenPosition.cpp', 'DSWaylandServer/DSWaylandTizenVisibility.cpp', + 'DSWaylandServer/DSWaylandTizenSurface.cpp', + 'DSWaylandServer/DSWaylandTizenSurface.h', + 'DSWaylandServer/DSWaylandTizenSurfacePrivate.h', 'DSWaylandServer/DSWaylandTizenSurfaceShm.cpp', 'DSWaylandServer/DSWaylandTizenSurfaceShm.h', 'DSWaylandServer/DSWaylandTizenSurfaceShmPrivate.h', diff --git a/tests/DSWaylandTizenSurface-test.cpp b/tests/DSWaylandTizenSurface-test.cpp new file mode 100644 index 0000000..b4d04c7 --- /dev/null +++ b/tests/DSWaylandTizenSurface-test.cpp @@ -0,0 +1,47 @@ +/* +* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#include "libds-tests.h" +#include "DSWaylandTizenSurface.h" + +using namespace display_server; + +class DSWaylandTizenSurfaceTest : public ::testing::Test +{ +public: + void SetUp(void) override + {} + void TearDown(void) override + {} +}; + +TEST_F(DSWaylandTizenSurfaceTest, NewDSWaylandTizenSurface) +{ + DSWaylandCompositor *comp = DSWaylandCompositor::getInstance(); + DSWaylandTizenSurface *tizenSurface = new DSWaylandTizenSurface(comp); + EXPECT_TRUE(tizenSurface != nullptr); + + if (tizenSurface) + delete tizenSurface; + DSWaylandCompositor::releaseInstance(); +} diff --git a/tests/meson.build b/tests/meson.build index 1a91dbb..58a1ec4 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -27,6 +27,7 @@ libds_tests_srcs = [ 'DSWaylandTizenInputDeviceManager-test.cpp', 'DSWaylandTizenInputDevice-test.cpp', 'DSWaylandTizenPolicy-test.cpp', + 'DSWaylandTizenSurface-test.cpp', 'DSWaylandTizenSurfaceShm-test.cpp', 'DSWaylandTizenIndicator-test.cpp', 'DSWaylandTizenAppinfo-test.cpp', -- 2.7.4