Cleaning window managers for consistency.

This commit is contained in:
James Grogan 2022-11-12 15:34:54 +00:00
parent 5d984aa61d
commit 392a2b7889
28 changed files with 452 additions and 325 deletions

View file

@ -4,6 +4,11 @@
#include <wayland-egl.h>
WaylandEglInterface::WaylandEglInterface(wl_display* display)
{
initialize(display);
}
void WaylandEglInterface::initialize(wl_display* display)
{
mEglDisplay = eglGetDisplay((EGLNativeDisplayType) display);

View file

@ -7,8 +7,7 @@ struct wl_display;
class WaylandEglInterface
{
public:
void initialize(wl_display* display);
WaylandEglInterface(wl_display* display);
EGLDisplay getDisplay() const;
@ -17,6 +16,8 @@ public:
EGLContext getContext() const;
private:
void initialize(wl_display* display);
EGLDisplay mEglDisplay;
EGLConfig mEglConfig;
EGLContext mEglContext;

View file

@ -19,6 +19,6 @@ public:
private:
wl_egl_window* mEglWindow{nullptr};
EGLSurface mEglSurface;
EGLSurface mEglSurface{nullptr};
WaylandEglInterface* mEglInterface;
};

View file

@ -1,6 +1,9 @@
#include "WaylandInterface.h"
#include "FileLogger.h"
#include "DesktopManager.h"
#include "WindowManager.h"
#include "WaylandSurface.h"
#include "WaylandBuffer.h"
#include "WaylandSeatInterface.h"
@ -13,10 +16,9 @@ void WaylandInterface::registryHandleGlobalEvent(void *data, struct wl_registry
uint32_t name, const char *interface, uint32_t version)
{
auto thisClass = static_cast<WaylandInterface*>(data);
std::stringstream sstrm;
sstrm << "interface: " << interface << " version " << version << " name " << name;
MLOG_INFO(sstrm.str());
//MLOG_INFO(sstrm.str());
if (strcmp(interface, wl_compositor_interface.name) == 0)
{
@ -51,7 +53,7 @@ WaylandInterface::WaylandInterface(DesktopManager* desktopManager, bool useHardw
WaylandInterface::~WaylandInterface()
{
shutDown();
}
void WaylandInterface::initialize()
@ -76,9 +78,21 @@ void WaylandInterface::initialize()
if (mUseHardwareRendering)
{
mEglInterface = std::make_unique<WaylandEglInterface>();
mEglInterface->initialize(mDisplay);
initializeHardwareRendering();
}
const auto num_windows = mDesktopManager->GetWindowManager()->getNumWindows();
for(std::size_t idx=0; idx< num_windows; idx++)
{
addWindow(mDesktopManager->GetWindowManager()->getWindow(idx));
}
mDesktopManager->GetWindowManager()->GetMainWindow()->show();
}
void WaylandInterface::initializeHardwareRendering()
{
mEglInterface = std::make_unique<WaylandEglInterface>(mDisplay);
}
void WaylandInterface::setSeat(wl_seat* seat)
@ -115,18 +129,12 @@ void WaylandInterface::doXdgPong(uint32_t serial)
void WaylandInterface::addWindow(mt::Window* window)
{
auto surface = std::make_unique<WaylandSurface>(window);
mSurfaces.push_back(std::move(surface));
WaylandSurface::add(window, mCompositor, mXdgBase, mBuffer, mEglInterface.get());
}
void WaylandInterface::showWindow(mt::Window* window)
{
if (mSurfaces.empty())
{
return;
}
mSurfaces[0]->initialize(mCompositor, mXdgBase, mBuffer, mEglInterface.get());
window->show();
}
void WaylandInterface::shutDown()
@ -139,6 +147,8 @@ void WaylandInterface::shutDown()
void WaylandInterface::loop()
{
initialize();
while (wl_display_dispatch(mDisplay) != -1)
{
/* This space deliberately left blank */

View file

@ -10,7 +10,6 @@
#include <vector>
#include <memory>
class WaylandSurface;
class WaylandBuffer;
class WaylandSeatInterface;
class WaylandEglInterface;
@ -29,11 +28,13 @@ public:
void showWindow(mt::Window* window) override;
private:
void initialize() override;
void initializeHardwareRendering() override;
void shutDown() override;
private:
static void registryHandleGlobalEvent(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version);
static void registryHandleGlobalRemoveEvent(void *data, struct wl_registry *registry, uint32_t name);
@ -54,7 +55,6 @@ private:
xdg_wm_base* mXdgBase{nullptr};
xdg_wm_base_listener mXdgBaseListener;
std::vector<std::unique_ptr<WaylandSurface> > mSurfaces;
std::shared_ptr<WaylandBuffer> mBuffer;
std::unique_ptr<WaylandSeatInterface> mSeatInterface;
std::unique_ptr<WaylandEglInterface> mEglInterface;

View file

@ -3,10 +3,22 @@
#include "WaylandEglWindowInterface.h"
#include "ImagePrimitives.h"
WaylandSurface::WaylandSurface(mt::Window* window)
: IPlatformWindow(window)
void WaylandSurface::add(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface)
{
auto wayland_window = std::make_unique<WaylandSurface>(window, compositor, xdg_wm_base, buffer, eglInterface);
window->SetPlatformWindow(std::move(wayland_window));
}
WaylandSurface::WaylandSurface(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface)
: IPlatformWindow(window),
mCompositor(compositor),
mXdgWmBase(xdg_wm_base),
mBuffer(buffer)
{
if (eglInterface)
{
mEglWindowInterface = std::make_unique<WaylandEglWindowInterface>(eglInterface);
}
}
WaylandSurface::~WaylandSurface()
@ -14,16 +26,28 @@ WaylandSurface::~WaylandSurface()
}
void WaylandSurface::initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface)
void WaylandSurface::show()
{
mBuffer = buffer;
if (eglInterface)
{
mEglWindowInterface = std::make_unique<WaylandEglWindowInterface>(eglInterface);
}
map();
}
mSurface = wl_compositor_create_surface(compositor);
mXdgSurface = xdg_wm_base_get_xdg_surface(xdg_wm_base, mSurface);
void WaylandSurface::clear()
{
}
void WaylandSurface::map()
{
if (!mSurface)
{
initialize();
}
}
void WaylandSurface::initialize()
{
mSurface = wl_compositor_create_surface(mCompositor);
mXdgSurface = xdg_wm_base_get_xdg_surface(mXdgWmBase, mSurface);
auto xdg_surface_configure = [](void *data, struct xdg_surface *xdg_surface, uint32_t serial)
{
@ -37,7 +61,7 @@ void WaylandSurface::initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_b
mXdgTopLevel = xdg_surface_get_toplevel(mXdgSurface);
xdg_toplevel_set_title(mXdgTopLevel, "Example client");
auto region = wl_compositor_create_region(compositor);
auto region = wl_compositor_create_region(mCompositor);
wl_region_add(region, 0, 0, mWindow->GetWidth(), mWindow->GetHeight());
wl_surface_set_opaque_region(mSurface, region);
@ -47,7 +71,6 @@ void WaylandSurface::initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_b
void WaylandSurface::onConfigure(xdg_surface *xdg_surface, uint32_t serial)
{
xdg_surface_ack_configure(xdg_surface, serial);
paint(nullptr);
}
@ -55,18 +78,28 @@ void WaylandSurface::paint(mt::Screen* screen)
{
if (mEglWindowInterface)
{
mEglWindowInterface->initialize(mSurface, mWindow->GetWidth(), mWindow->GetHeight());
mEglWindowInterface->draw();
paintHardware();
}
else
{
auto buffer = drawFrame();
wl_surface_attach(mSurface, buffer, 0, 0);
//wl_surface_damage(mSurface, 0, 0, UINT32_MAX, UINT32_MAX);
wl_surface_commit(mSurface);
paintSoftware();
}
}
void WaylandSurface::paintHardware()
{
mEglWindowInterface->initialize(mSurface, mWindow->GetWidth(), mWindow->GetHeight());
mEglWindowInterface->draw();
}
void WaylandSurface::paintSoftware()
{
auto buffer = drawFrame();
wl_surface_attach(mSurface, buffer, 0, 0);
//wl_surface_damage(mSurface, 0, 0, UINT32_MAX, UINT32_MAX);
wl_surface_commit(mSurface);
}
wl_buffer* WaylandSurface::drawFrame()
{
const auto width = mWindow->GetWidth();

View file

@ -18,46 +18,45 @@ class WaylandEglWindowInterface;
class WaylandSurface : public IPlatformWindow
{
public:
WaylandSurface(mt::Window* window);
static void add(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface);
WaylandSurface(mt::Window* window, wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface);
~WaylandSurface();
void initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface);
void onConfigure(xdg_surface *xdg_surface, uint32_t serial);
void show();
void map();
void clear();
private:
void initialize();
void paint(mt::Screen* screen) override;
void paintHardware();
void paintSoftware();
wl_buffer* drawFrame();
void show() const
{
map();
}
void map() const
{
}
void clear() const
{
}
private:
void paint(mt::Screen* screen) override;
mt::Window* mWindow{nullptr};
wl_compositor* mCompositor{nullptr};
xdg_wm_base* mXdgWmBase{nullptr};
std::shared_ptr<WaylandBuffer> mBuffer;
std::unique_ptr<WaylandEglWindowInterface> mEglWindowInterface;
wl_surface* mSurface{nullptr};
xdg_surface* mXdgSurface{nullptr};
xdg_surface_listener mXdgSurfaceListener{nullptr};
xdg_surface_listener mXdgSurfaceListener;
xdg_toplevel* mXdgTopLevel{nullptr};
std::shared_ptr<WaylandBuffer> mBuffer;
std::unique_ptr<WaylandEglWindowInterface> mEglWindowInterface{nullptr};
};
using WaylandSurfacePtr = std::unique_ptr<WaylandSurface>;