#include "DSWaylandCompositor.h"
#include "DSWaylandCompositorPrivate.h"
#include "DSWaylandClient.h"
+#include "DSWaylandSurface.h"
#include "DSDebugLog.h"
namespace display_server
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)
{
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)
{
}
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 */
-#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
{
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 */
-#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"
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 */
#include "libds-tests.h"
+#include "DSWaylandCompositor.h"
#include "DSWaylandSurface.h"
using namespace display_server;
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;
}