Fix compilation.
This commit is contained in:
parent
5d06b170ef
commit
92e7a78710
8 changed files with 343 additions and 298 deletions
|
@ -4,6 +4,8 @@
|
|||
#include "wayland-client.h"
|
||||
|
||||
#include "Window.h"
|
||||
#include "SharedMemory.h"
|
||||
#include <WaylandBuffer.h>
|
||||
|
||||
struct wl_surface;
|
||||
struct xdg_surface;
|
||||
|
@ -12,94 +14,19 @@ struct xdg_toplevel;
|
|||
class WaylandSurface
|
||||
{
|
||||
|
||||
WaylandSurface(mt::Window* window)
|
||||
: mWindow(window)
|
||||
{
|
||||
public:
|
||||
|
||||
}
|
||||
WaylandSurface(mt::Window* window);
|
||||
|
||||
~WaylandSurface();
|
||||
|
||||
void initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_base)
|
||||
{
|
||||
mSurface = wl_compositor_create_surface(compositor);
|
||||
mXdgSurface = xdg_wm_base_get_xdg_surface(xdg_wm_base, mSurface);
|
||||
void initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer);
|
||||
|
||||
auto xdg_surface_configure = [](void *data, struct xdg_surface *xdg_surface, uint32_t serial)
|
||||
{
|
||||
auto thisClass = static_cast<WaylandSurface*>(data);
|
||||
thisClass->onConfigure(xdg_surface, serial);
|
||||
};
|
||||
mXdgSurfaceListener.configure = xdg_surface_configure;
|
||||
void onConfigure(xdg_surface *xdg_surface, uint32_t serial);
|
||||
|
||||
xdg_surface_add_listener(mXdgSurface, &mXdgSurfaceListener, this);
|
||||
wl_buffer* drawFrame();
|
||||
|
||||
mXdgTopLevel = xdg_surface_get_toplevel(mXdgSurface);
|
||||
xdg_toplevel_set_title(mXdgTopLevel, "Example client");
|
||||
|
||||
wl_surface_commit(mSurface);
|
||||
}
|
||||
|
||||
void onConfigure(xdg_surface *xdg_surface, uint32_t serial)
|
||||
{
|
||||
xdg_surface_ack_configure(xdg_surface, serial);
|
||||
|
||||
auto buffer = draw_frame();
|
||||
wl_surface_attach(mSurface, buffer, 0, 0);
|
||||
//wl_surface_damage(mSurface, 0, 0, UINT32_MAX, UINT32_MAX);
|
||||
wl_surface_commit(mSurface);
|
||||
}
|
||||
|
||||
wl_buffer* draw_frame()
|
||||
{
|
||||
const auto width = mWindow->GetWidth();
|
||||
const auto height = mWindow->GetHeight();
|
||||
|
||||
const int bitDepth = 4;
|
||||
|
||||
const int stride = width * bitDepth;
|
||||
//const int numBuffers = 2; // i.e. front/back
|
||||
const int numBuffers = 1;
|
||||
const int shm_pool_size = height * stride * numBuffers;
|
||||
|
||||
initializeSharedBuffer(shm_pool_size);
|
||||
|
||||
if (!mSharedMemory->isValid())
|
||||
{
|
||||
std::cout << "Failed to allocate shared memory" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!mPoolData)
|
||||
{
|
||||
std::cout << "Failed to mmap pool" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto pool = wl_shm_create_pool(mWlSharedMemory, mSharedMemory->getFileDescriptor(), shm_pool_size);
|
||||
|
||||
int index = 0;
|
||||
// int offset = height * stride * index; // Two buffers, offset to starting point of second
|
||||
int offset = 0;
|
||||
|
||||
mWorkingBuffer = wl_shm_pool_create_buffer(pool, offset, width, height, stride, WL_SHM_FORMAT_XRGB8888);
|
||||
|
||||
wl_shm_pool_destroy(pool);
|
||||
close(mSharedMemory->getFileDescriptor());
|
||||
|
||||
drawCheckerboard(width, height, offset);
|
||||
|
||||
munmap(mPoolData, shm_pool_size);
|
||||
|
||||
auto wl_buffer_release = [](void *data, struct wl_buffer *wl_buffer)
|
||||
{
|
||||
wl_buffer_destroy(wl_buffer);
|
||||
};
|
||||
mBufferListener.release = wl_buffer_release;
|
||||
|
||||
wl_buffer_add_listener(mWorkingBuffer, &mBufferListener, nullptr);
|
||||
|
||||
return mWorkingBuffer;
|
||||
}
|
||||
void drawCheckerboard(int width, int height, int offset);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -110,6 +37,8 @@ private:
|
|||
xdg_surface_listener mXdgSurfaceListener{nullptr};
|
||||
|
||||
xdg_toplevel* mXdgTopLevel{nullptr};
|
||||
|
||||
std::shared_ptr<WaylandBuffer> mBuffer;
|
||||
};
|
||||
|
||||
using WaylandSurfacePtr = std::unique_ptr<WaylandSurface>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue