Intial Wayland EGL integration.
This commit is contained in:
parent
a4d3019f04
commit
6af296409a
20 changed files with 278 additions and 44 deletions
89
src/windows/ui_interfaces/wayland/WaylandEglInterface.h
Normal file
89
src/windows/ui_interfaces/wayland/WaylandEglInterface.h
Normal file
|
@ -0,0 +1,89 @@
|
|||
#pragma once
|
||||
|
||||
#include <wayland-egl.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
class WaylandEglInterface
|
||||
{
|
||||
public:
|
||||
|
||||
void initialize(wl_display* display)
|
||||
{
|
||||
mEglDisplay = eglGetDisplay((EGLNativeDisplayType) display);
|
||||
if (mEglDisplay == EGL_NO_DISPLAY)
|
||||
{
|
||||
fprintf(stderr, "Can't create egl display\n");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Created egl display\n");
|
||||
}
|
||||
|
||||
EGLint major{0};
|
||||
EGLint minor{0};
|
||||
if (eglInitialize(mEglDisplay, &major, &minor) != EGL_TRUE)
|
||||
{
|
||||
fprintf(stderr, "Can't initialise egl display\n");
|
||||
return;
|
||||
}
|
||||
printf("EGL major: %d, minor %d\n", major, minor);
|
||||
|
||||
EGLint count{0};
|
||||
eglGetConfigs(mEglDisplay, nullptr, 0, &count);
|
||||
printf("EGL has %d configs\n", count);
|
||||
|
||||
EGLConfig* configs;
|
||||
configs = static_cast<EGLConfig*>(calloc(count, sizeof* configs));
|
||||
|
||||
EGLint n{0};
|
||||
EGLint config_attribs[] = {
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
EGL_NONE
|
||||
};
|
||||
eglChooseConfig(mEglDisplay, config_attribs, configs, count, &n);
|
||||
EGLint size{0};
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
eglGetConfigAttrib(mEglDisplay, configs[i], EGL_BUFFER_SIZE, &size);
|
||||
printf("Buffer size for config %d is %d\n", i, size);
|
||||
eglGetConfigAttrib(mEglDisplay, configs[i], EGL_RED_SIZE, &size);
|
||||
printf("Red size for config %d is %d\n", i, size);
|
||||
|
||||
// just choose the first one
|
||||
mEglConfig = configs[i];
|
||||
break;
|
||||
}
|
||||
|
||||
static const EGLint context_attribs[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
mEglContext = eglCreateContext(mEglDisplay, mEglConfig, EGL_NO_CONTEXT, context_attribs);
|
||||
}
|
||||
|
||||
EGLDisplay getDisplay() const
|
||||
{
|
||||
return mEglDisplay;
|
||||
}
|
||||
|
||||
EGLConfig getConfig() const
|
||||
{
|
||||
return mEglConfig;
|
||||
}
|
||||
|
||||
EGLContext getContext() const
|
||||
{
|
||||
return mEglContext;
|
||||
}
|
||||
|
||||
private:
|
||||
EGLDisplay mEglDisplay;
|
||||
EGLConfig mEglConfig;
|
||||
EGLContext mEglContext;
|
||||
};
|
108
src/windows/ui_interfaces/wayland/WaylandEglWindowInterface.h
Normal file
108
src/windows/ui_interfaces/wayland/WaylandEglWindowInterface.h
Normal file
|
@ -0,0 +1,108 @@
|
|||
#pragma once
|
||||
|
||||
#include "WaylandEglInterface.h"
|
||||
|
||||
#include <wayland-egl.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <GLES2/gl2.h>
|
||||
|
||||
class WaylandEglWindowInterface
|
||||
{
|
||||
public:
|
||||
|
||||
WaylandEglWindowInterface(WaylandEglInterface* eglInterface)
|
||||
: mEglInterface(eglInterface)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void initialize(wl_surface* surface, int width, int height)
|
||||
{
|
||||
if (mEglSurface)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mEglWindow = wl_egl_window_create(surface, width, height);
|
||||
if (mEglWindow == EGL_NO_SURFACE)
|
||||
{
|
||||
fprintf(stderr, "Can't create egl window\n");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Created egl window\n");
|
||||
}
|
||||
|
||||
mEglSurface = eglCreateWindowSurface(mEglInterface->getDisplay(), mEglInterface->getConfig(), mEglWindow, nullptr);
|
||||
|
||||
if (!mEglSurface)
|
||||
{
|
||||
switch(eglGetError())
|
||||
{
|
||||
//case EGL_NO_SURFACE:
|
||||
//fprintf(stderr, "EGL_NO_SURFACE\n");
|
||||
//break;
|
||||
case EGL_BAD_DISPLAY:
|
||||
fprintf(stderr, "EGL_BAD_DISPLAY\n");
|
||||
break;
|
||||
case EGL_NOT_INITIALIZED:
|
||||
fprintf(stderr, "EGL_NOT_INITIALIZED\n");
|
||||
break;
|
||||
case EGL_BAD_CONFIG:
|
||||
fprintf(stderr, "EGL_BAD_CONFIG\n");
|
||||
break;
|
||||
case EGL_BAD_NATIVE_WINDOW:
|
||||
fprintf(stderr, "EGL_BAD_NATIVE_WINDOW\n");
|
||||
break;
|
||||
case EGL_BAD_ATTRIBUTE:
|
||||
fprintf(stderr, "EGL_BAD_ATTRIBUTE\n");
|
||||
break;
|
||||
case EGL_BAD_ALLOC:
|
||||
fprintf(stderr, "EGL_BAD_ALLOC\n");
|
||||
break;
|
||||
case EGL_BAD_MATCH:
|
||||
fprintf(stderr, "EGL_BAD_MATCH\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown EGL error\n");
|
||||
}
|
||||
|
||||
fprintf(stderr, "Created surface failed\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
if (!mEglSurface)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (eglMakeCurrent(mEglInterface->getDisplay(), mEglSurface, mEglSurface, mEglInterface->getContext()))
|
||||
{
|
||||
fprintf(stderr, "Made current\n");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Made current failed\n");
|
||||
}
|
||||
|
||||
glClearColor(1.0, 1.0, 0.0, 1.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glFlush();
|
||||
|
||||
if (eglSwapBuffers(mEglInterface->getDisplay(), mEglSurface))
|
||||
{
|
||||
fprintf(stderr, "Swapped buffers\n");
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Swapped buffers failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
wl_egl_window* mEglWindow{nullptr};
|
||||
EGLSurface mEglSurface;
|
||||
WaylandEglInterface* mEglInterface;
|
||||
};
|
|
@ -25,7 +25,7 @@ void WaylandKeyboard::keyboardPressedEvent(void *data, struct wl_keyboard *wl_ke
|
|||
|
||||
static void wl_keyboard_leave(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, struct wl_surface *surface)
|
||||
{
|
||||
fprintf(stderr, "keyboard leave\n");
|
||||
|
||||
}
|
||||
|
||||
static void wl_keyboard_repeat_info(void *data, struct wl_keyboard *wl_keyboard, int32_t rate, int32_t delay)
|
||||
|
@ -46,8 +46,6 @@ void WaylandKeyboard::onKeyboardModifier(uint32_t mods_depressed, uint32_t mods_
|
|||
|
||||
void WaylandKeyboard::onEnterEvent(struct wl_array *keys)
|
||||
{
|
||||
MLOG_INFO("keyboard enter; keys pressed are:");
|
||||
|
||||
void* key;
|
||||
wl_array_for_each(key, keys)
|
||||
{
|
||||
|
@ -56,9 +54,9 @@ void WaylandKeyboard::onEnterEvent(struct wl_array *keys)
|
|||
char buf[128];
|
||||
xkb_keysym_t sym = xkb_state_key_get_one_sym(mXkbState, *key_type + 8);
|
||||
xkb_keysym_get_name(sym, buf, sizeof(buf));
|
||||
fprintf(stderr, "sym: %-12s (%d), ", buf, sym);
|
||||
//fprintf(stderr, "sym: %-12s (%d), ", buf, sym);
|
||||
xkb_state_key_get_utf8(mXkbState, *key_type + 8, buf, sizeof(buf));
|
||||
fprintf(stderr, "utf8: '%s'\n", buf);
|
||||
//fprintf(stderr, "utf8: '%s'\n", buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,9 +67,9 @@ void WaylandKeyboard::onPressedEvent(uint32_t key, uint32_t state)
|
|||
xkb_keysym_t sym = xkb_state_key_get_one_sym(mXkbState, keycode);
|
||||
xkb_keysym_get_name(sym, buf, sizeof(buf));
|
||||
const char *action = state == WL_KEYBOARD_KEY_STATE_PRESSED ? "press" : "release";
|
||||
fprintf(stderr, "key %s: sym: %-12s (%d), ", action, buf, sym);
|
||||
//fprintf(stderr, "key %s: sym: %-12s (%d), ", action, buf, sym);
|
||||
xkb_state_key_get_utf8(mXkbState, keycode, buf, sizeof(buf));
|
||||
fprintf(stderr, "utf8: '%s'\n", buf);
|
||||
//fprintf(stderr, "utf8: '%s'\n", buf);
|
||||
}
|
||||
|
||||
void WaylandKeyboard::onKeymapEvent(struct wl_keyboard *wl_keyboard, uint32_t format, int32_t fd, uint32_t size)
|
||||
|
|
|
@ -63,11 +63,10 @@ void WaylandPointerInterface::onPointerFrame()
|
|||
{
|
||||
const auto locx = wl_fixed_to_double(mWorkingPointerEvent.surface_x);
|
||||
const auto locy = wl_fixed_to_double(mWorkingPointerEvent.surface_y);
|
||||
MLOG_INFO("Enter at " << locx << " , " << locy);
|
||||
}
|
||||
else if (mWorkingPointerEvent.event_mask & POINTER_EVENT_LEAVE)
|
||||
{
|
||||
MLOG_INFO("Leave);")
|
||||
|
||||
}
|
||||
else if (mWorkingPointerEvent.event_mask & POINTER_EVENT_MOTION)
|
||||
{
|
||||
|
@ -76,7 +75,6 @@ void WaylandPointerInterface::onPointerFrame()
|
|||
else if (mWorkingPointerEvent.event_mask & POINTER_EVENT_BUTTON)
|
||||
{
|
||||
const bool released = mWorkingPointerEvent.state == WL_POINTER_BUTTON_STATE_RELEASED;
|
||||
MLOG_INFO("Mouse button" << released ? "released" : "pressed");
|
||||
}
|
||||
mWorkingPointerEvent = WaylandPointerEvent();
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "WaylandSurface.h"
|
||||
|
||||
#include "WaylandEglWindowInterface.h"
|
||||
|
||||
WaylandSurface::WaylandSurface(mt::Window* window)
|
||||
: mWindow(window)
|
||||
{
|
||||
|
@ -11,9 +13,13 @@ WaylandSurface::~WaylandSurface()
|
|||
|
||||
}
|
||||
|
||||
void WaylandSurface::initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer)
|
||||
void WaylandSurface::initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer, WaylandEglInterface* eglInterface)
|
||||
{
|
||||
mBuffer = buffer;
|
||||
if (eglInterface)
|
||||
{
|
||||
mEglWindowInterface = std::make_unique<WaylandEglWindowInterface>(eglInterface);
|
||||
}
|
||||
|
||||
mSurface = wl_compositor_create_surface(compositor);
|
||||
mXdgSurface = xdg_wm_base_get_xdg_surface(xdg_wm_base, mSurface);
|
||||
|
@ -31,16 +37,28 @@ void WaylandSurface::initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_b
|
|||
xdg_toplevel_set_title(mXdgTopLevel, "Example client");
|
||||
|
||||
wl_surface_commit(mSurface);
|
||||
|
||||
auto region = wl_compositor_create_region(compositor);
|
||||
wl_region_add(region, 0, 0, mWindow->GetWidth(), mWindow->GetHeight());
|
||||
wl_surface_set_opaque_region(mSurface, region);
|
||||
}
|
||||
|
||||
void WaylandSurface::onConfigure(xdg_surface *xdg_surface, uint32_t serial)
|
||||
{
|
||||
xdg_surface_ack_configure(xdg_surface, serial);
|
||||
|
||||
auto buffer = drawFrame();
|
||||
wl_surface_attach(mSurface, buffer, 0, 0);
|
||||
//wl_surface_damage(mSurface, 0, 0, UINT32_MAX, UINT32_MAX);
|
||||
wl_surface_commit(mSurface);
|
||||
if (mEglWindowInterface)
|
||||
{
|
||||
mEglWindowInterface->initialize(mSurface, mWindow->GetWidth(), mWindow->GetHeight());
|
||||
mEglWindowInterface->draw();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
wl_buffer* WaylandSurface::drawFrame()
|
||||
|
|
|
@ -5,12 +5,15 @@
|
|||
|
||||
#include "Window.h"
|
||||
#include "SharedMemory.h"
|
||||
#include <WaylandBuffer.h>
|
||||
#include "WaylandBuffer.h"
|
||||
|
||||
struct wl_surface;
|
||||
struct xdg_surface;
|
||||
struct xdg_toplevel;
|
||||
|
||||
class WaylandEglInterface;
|
||||
class WaylandEglWindowInterface;
|
||||
|
||||
class WaylandSurface
|
||||
{
|
||||
|
||||
|
@ -19,7 +22,7 @@ public:
|
|||
|
||||
~WaylandSurface();
|
||||
|
||||
void initialize(wl_compositor* compositor, xdg_wm_base* xdg_wm_base, std::shared_ptr<WaylandBuffer> buffer);
|
||||
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);
|
||||
|
||||
|
@ -37,6 +40,7 @@ private:
|
|||
xdg_toplevel* mXdgTopLevel{nullptr};
|
||||
|
||||
std::shared_ptr<WaylandBuffer> mBuffer;
|
||||
std::unique_ptr<WaylandEglWindowInterface> mEglWindowInterface{nullptr};
|
||||
};
|
||||
|
||||
using WaylandSurfacePtr = std::unique_ptr<WaylandSurface>;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "WaylandSurface.h"
|
||||
#include "WaylandBuffer.h"
|
||||
#include "WaylandSeatInterface.h"
|
||||
#include "WaylandEglInterface.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
@ -72,6 +73,12 @@ void WaylandWindowInterface::initialize(DesktopManager* desktopManager)
|
|||
|
||||
wl_registry_add_listener(registry, &mRegistryListener, this);
|
||||
wl_display_roundtrip(mDisplay);
|
||||
|
||||
if (mUseHardwareRendering)
|
||||
{
|
||||
mEglInterface = std::make_unique<WaylandEglInterface>();
|
||||
mEglInterface->initialize(mDisplay);
|
||||
}
|
||||
}
|
||||
|
||||
void WaylandWindowInterface::setSeat(wl_seat* seat)
|
||||
|
@ -119,7 +126,7 @@ void WaylandWindowInterface::showWindow(mt::Window* window)
|
|||
return;
|
||||
}
|
||||
|
||||
mSurfaces[0]->initialize(mCompositor, mXdgBase, mBuffer);
|
||||
mSurfaces[0]->initialize(mCompositor, mXdgBase, mBuffer, mEglInterface.get());
|
||||
}
|
||||
|
||||
void WaylandWindowInterface::shutDown()
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
class WaylandSurface;
|
||||
class WaylandBuffer;
|
||||
class WaylandSeatInterface;
|
||||
class WaylandEglInterface;
|
||||
|
||||
class WaylandWindowInterface : public AbstractUIInterface
|
||||
{
|
||||
|
@ -56,4 +57,5 @@ private:
|
|||
std::vector<std::unique_ptr<WaylandSurface> > mSurfaces;
|
||||
std::shared_ptr<WaylandBuffer> mBuffer;
|
||||
std::unique_ptr<WaylandSeatInterface> mSeatInterface;
|
||||
std::unique_ptr<WaylandEglInterface> mEglInterface;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue