DSWaylandCompositor: make DSWaylandSurface. 19/241619/1
authorSooChan Lim <sc1.lim@samsung.com>
Mon, 13 Jul 2020 09:50:22 +0000 (18:50 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Thu, 20 Aug 2020 09:53:49 +0000 (18:53 +0900)
Change-Id: Ibf72f2be2e8a708b02b4c7087352a9d9c84a1b0d

src/DSWaylandServer/DSWaylandCompositor.cpp
src/DSWaylandServer/DSWaylandCompositorPrivate.h
src/DSWaylandServer/DSWaylandSurface.cpp
src/DSWaylandServer/DSWaylandSurface.h
src/DSWaylandServer/DSWaylandSurfacePrivate.h
tests/DSWaylandSurface-test.cpp

index 49e1eac..41043eb 100644 (file)
@@ -1,6 +1,7 @@
 #include "DSWaylandCompositor.h"
 #include "DSWaylandCompositorPrivate.h"
 #include "DSWaylandClient.h"
+#include "DSWaylandSurface.h"
 #include "DSDebugLog.h"
 
 namespace display_server
@@ -214,7 +215,9 @@ void DSWaylandCompositorPrivate::compositor_destroy_resource(wl_compositor::Reso
 
 void DSWaylandCompositorPrivate::compositor_create_surface(wl_compositor::Resource *resource, uint32_t id)
 {
-       //TODO : Create DSWindow here.
+       DSWaylandClient *waylandClient = DSWaylandClient::fromWlClient(resource->client());
+       auto waylandSruface = std::make_shared<DSWaylandSurface>(waylandClient, id);
+       //TODO: add window to the zone
 }
 
 void DSWaylandCompositorPrivate::compositor_create_region(wl_compositor::Resource *resource, uint32_t id)
index 0cce28d..f33c4b4 100644 (file)
@@ -8,6 +8,7 @@
 #include "DSDebugLog.h"
 
 #include <wayland-server-core.h>
+#include <memory>
 #include <Ecore.h>
 
 namespace display_server
index 29429c6..5fc903f 100644 (file)
@@ -5,13 +5,21 @@ namespace display_server
 {
 
 DSWaylandSurfacePrivate::DSWaylandSurfacePrivate(DSWaylandSurface *p_ptr)
-    : DSObjectPrivate(p_ptr)
+       : DSObjectPrivate(p_ptr),
+         __p_ptr(p_ptr)
+{}
+
+DSWaylandSurfacePrivate::DSWaylandSurfacePrivate(DSWaylandSurface *p_ptr, DSWaylandClient *waylandClient, uint32_t id)
+       : DSObjectPrivate(p_ptr),
+         __p_ptr(p_ptr)
 {
+       if (id > 0) {
+               wl_surface::init(waylandClient->wlClient(), (int)id, 4);
+       }
 }
 
 DSWaylandSurfacePrivate::~DSWaylandSurfacePrivate()
-{
-}
+{}
 
 void DSWaylandSurfacePrivate::surface_bind_resource(Resource *resource)
 {
@@ -62,12 +70,14 @@ void DSWaylandSurfacePrivate::surface_damage_buffer(Resource *resource, int32_t
 }
 
 DSWaylandSurface::DSWaylandSurface()
-    : DSObject(std::make_unique<DSWaylandSurfacePrivate>(this))
-{
-}
+    : DS_INIT_PRIVATE_PTR(DSWaylandSurface)
+{}
+
+DSWaylandSurface::DSWaylandSurface(DSWaylandClient *waylandClient, uint32_t id)
+    : _d_ptr(std::make_unique<DSWaylandSurfacePrivate>(this, waylandClient, id))
+{}
 
 DSWaylandSurface::~DSWaylandSurface()
-{
-}
+{}
 
 } /* namespace display_server */
index f662ce9..6773f21 100644 (file)
@@ -1,7 +1,9 @@
-#ifndef _DS_WAYLAND_SURFACE_H_
-#define _DS_WAYLAND_SURFACE_H_
+#ifndef __DS_WAYLAND_SURFACE_H__
+#define __DS_WAYLAND_SURFACE_H__
 
 #include <DSObject.h>
+#include "DSWaylandClient.h"
+#include <memory>
 
 namespace display_server
 {
@@ -11,22 +13,11 @@ class DSWaylandSurfacePrivate;
 
 class DSWaylandSurface : public DSObject
 {
+DS_PIMPL_USE_PRIVATE(DSWaylandSurface);
 public:
-    DSWaylandSurface();
-    virtual ~DSWaylandSurface();
-
-private:
-    inline DSWaylandSurfacePrivate *__d_func()
-    {
-        return reinterpret_cast<DSWaylandSurfacePrivate *>(_d_ptr.get());
-    }
-
-    inline const DSWaylandSurfacePrivate *__d_func() const
-    {
-        return reinterpret_cast<DSWaylandSurfacePrivate *>(_d_ptr.get());
-    }
-
-    friend class DSWaylandSurfacePrivate;
+       DSWaylandSurface();
+       DSWaylandSurface(DSWaylandClient *waylandClient, uint32_t id);
+       virtual ~DSWaylandSurface();
 };
 
 } /* namespace display_server */
index 7434c6a..46324fe 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef _DS_WAYLAND_SURFACE_PRIVATE_H_
-#define _DS_WAYLAND_SURFACE_PRIVATE_H_
+#ifndef __DS_WAYLAND_SURFACE_PRIVATE_H__
+#define __DS_WAYLAND_SURFACE_PRIVATE_H__
 
 #include "dswayland-server-wayland.h"
 #include "DSWaylandSurface.h"
@@ -7,30 +7,33 @@
 namespace display_server
 {
 
+class DSWaylandSurface;
+
 class DSWaylandSurfacePrivate : public DSObjectPrivate, public DSWaylandServer::wl_surface
 {
+DS_PIMPL_USE_PUBLIC(DSWaylandSurface);
 public:
-    DSWaylandSurfacePrivate() = delete;
-    DSWaylandSurfacePrivate(DSWaylandSurface *p_ptr);
-    ~DSWaylandSurfacePrivate() override;
+       DSWaylandSurfacePrivate() = delete;
+       DSWaylandSurfacePrivate(DSWaylandSurface *p_ptr);
+       DSWaylandSurfacePrivate(DSWaylandSurface *p_ptr, DSWaylandClient *waylandClient, uint32_t id);
+       ~DSWaylandSurfacePrivate() override;
 
 protected:
-    void surface_bind_resource(Resource *resource) override;
-    void surface_destroy_resource(Resource *resource) override;
-
-    void surface_destroy(Resource *resource) override;
-    void surface_attach(Resource *resource, struct ::wl_resource *buffer, int32_t x, int32_t y) override;
-    void surface_damage(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
-    void surface_frame(Resource *resource, uint32_t callback) override;
-    void surface_set_opaque_region(Resource *resource, struct ::wl_resource *region) override;
-    void surface_set_input_region(Resource *resource, struct ::wl_resource *region) override;
-    void surface_commit(Resource *resource) override;
-    void surface_set_buffer_transform(Resource *resource, int32_t transform) override;
-    void surface_set_buffer_scale(Resource *resource, int32_t scale) override;
-    void surface_damage_buffer(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
+       void surface_bind_resource(Resource *resource) override;
+       void surface_destroy_resource(Resource *resource) override;
+
+       void surface_destroy(Resource *resource) override;
+       void surface_attach(Resource *resource, struct ::wl_resource *buffer, int32_t x, int32_t y) override;
+       void surface_damage(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
+       void surface_frame(Resource *resource, uint32_t callback) override;
+       void surface_set_opaque_region(Resource *resource, struct ::wl_resource *region) override;
+       void surface_set_input_region(Resource *resource, struct ::wl_resource *region) override;
+       void surface_commit(Resource *resource) override;
+       void surface_set_buffer_transform(Resource *resource, int32_t transform) override;
+       void surface_set_buffer_scale(Resource *resource, int32_t scale) override;
+       void surface_damage_buffer(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override;
 
 private:
-
 };
 
 } /*namespace display_server */
index 87b91cd..c29dcb5 100644 (file)
@@ -1,4 +1,5 @@
 #include "libds-tests.h"
+#include "DSWaylandCompositor.h"
 #include "DSWaylandSurface.h"
 
 using namespace display_server;
@@ -14,7 +15,16 @@ public:
 
 TEST_F(DSWaylandSurfaceTest, NewDSWaylandSurface)
 {
-       DSWaylandSurface *surface = new DSWaylandSurface;
-       delete surface;
+       auto waylandSurface = std::make_unique<DSWaylandSurface>();
+       EXPECT_TRUE(waylandSurface != nullptr);
+}
+
+TEST_F(DSWaylandSurfaceTest, NewDSWaylandSurfaceWithPrams)
+{
+       DSWaylandCompositor *waylandCompositor = new DSWaylandCompositor(new DSObject);
+       DSWaylandClient *waylandClient = new DSWaylandClient(waylandCompositor, (wl_client *)nullptr);
+       auto waylandSurface = std::make_unique<DSWaylandSurface>(waylandClient, 0);
        EXPECT_TRUE(true);
+       delete waylandClient;
+       delete waylandCompositor;
 }