Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
wayland: Add bits required to run as a wayland client.
  • Loading branch information
soreau committed Jan 19, 2014
1 parent 3b25bf2 commit 84aa98a
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/GLInterface/EGL.cpp
Expand Up @@ -28,7 +28,7 @@ void cInterfaceEGL::UpdateFPSDisplay(const char *text)
}
void cInterfaceEGL::Swap()
{
eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf);
Platform.SwapBuffers();
}
void cInterfaceEGL::SwapInterval(int Interval)
{
Expand Down
14 changes: 13 additions & 1 deletion Source/Core/DolphinWX/GLInterface/Platform.cpp
Expand Up @@ -117,7 +117,6 @@ bool cPlatform::SelectDisplay(void)
if (GLWin.dpy)
{
XCloseDisplay(GLWin.dpy);
XCloseDisplay(GLWin.evdpy);
}
}
#endif
Expand Down Expand Up @@ -219,3 +218,16 @@ cPlatform::ToggleFullscreen(bool fullscreen)
// Only wayland uses this function
#endif
}

void
cPlatform::SwapBuffers()
{
#if HAVE_WAYLAND
if (cPlatform::platform == EGL_PLATFORM_WAYLAND)
WaylandInterface.SwapBuffers();
#endif
#if HAVE_X11
if (cPlatform::platform == EGL_PLATFORM_X11)
XInterface.SwapBuffers();
#endif
}
3 changes: 2 additions & 1 deletion Source/Core/DolphinWX/GLInterface/Platform.h
Expand Up @@ -63,6 +63,7 @@ class cPlatform
void DestroyWindow(void);
void UpdateFPSDisplay(const char *text);
void ToggleFullscreen(bool fullscreen);
void SwapBuffers();
};

#include "GLInterface/EGL.h"
Expand Down Expand Up @@ -129,7 +130,7 @@ typedef struct {
struct wl_surface *wl_surface;
struct wl_shell_surface *wl_shell_surface;
struct wl_callback *wl_callback;
bool fullscreen, configured, frame_drawn, swap_complete, running;
bool fullscreen, running;
#endif
#if HAVE_X11
int screen;
Expand Down
95 changes: 23 additions & 72 deletions Source/Core/DolphinWX/GLInterface/Wayland_Util.cpp
Expand Up @@ -21,38 +21,6 @@
#include <linux/input.h>
#include <sys/mman.h>


static void
redraw(void *data, struct wl_callback *callback, uint32_t time);

static const struct wl_callback_listener frame_listener = {
redraw
};

static void
redraw(void *data, struct wl_callback *callback, uint32_t time)
{
if (GLWin.wl_callback != callback) {
printf("Got wrong callback from wayland server\n");
exit(-1);
}

GLWin.wl_callback = NULL;

if (callback)
wl_callback_destroy(callback);

if (!GLWin.configured)
return;

// Reset the frame callback
GLWin.wl_callback = wl_surface_frame(GLWin.wl_surface);
wl_callback_add_listener(GLWin.wl_callback, &frame_listener, 0);

// Present rendered buffer on screen
//eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf);
}

static void
hide_cursor(void)
{
Expand All @@ -63,21 +31,6 @@ hide_cursor(void)
GLWin.pointer.serial, NULL, 0, 0);
}

static void
configure_callback(void *data, struct wl_callback *callback, uint32_t time)
{
wl_callback_destroy(callback);

GLWin.configured = true;

if (GLWin.wl_callback == NULL)
redraw(data, NULL, time);
}

static struct wl_callback_listener configure_callback_listener = {
configure_callback,
};

static void
handle_ping(void *data, struct wl_shell_surface *wl_shell_surface,
uint32_t serial)
Expand All @@ -89,7 +42,6 @@ static void
handle_configure(void *data, struct wl_shell_surface *wl_shell_surface,
uint32_t edges, int32_t width, int32_t height)
{

if (GLWin.wl_egl_native)
wl_egl_window_resize(GLWin.wl_egl_native, width, height, 0, 0);

Expand Down Expand Up @@ -120,8 +72,7 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
{
GLWin.pointer.serial = serial;

if (GLWin.fullscreen)
hide_cursor();
hide_cursor();
}

static void
Expand Down Expand Up @@ -157,19 +108,10 @@ static const struct wl_pointer_listener pointer_listener = {
pointer_handle_axis,
};

void setup_callback_listener()
{
struct wl_callback *callback;

callback = wl_display_sync(GLWin.wl_display);
wl_callback_add_listener(callback, &configure_callback_listener, 0);
}

static void
toggle_fullscreen(bool fullscreen)
{
GLWin.fullscreen = fullscreen;
GLWin.configured = false;

if (fullscreen) {
wl_shell_surface_set_fullscreen(GLWin.wl_shell_surface,
Expand All @@ -181,8 +123,6 @@ toggle_fullscreen(bool fullscreen)
GLWin.window_size.width,
GLWin.window_size.height);
}

setup_callback_listener();
}

static void
Expand Down Expand Up @@ -251,9 +191,10 @@ keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
if (state == WL_KEYBOARD_KEY_STATE_RELEASED)
return;

if (key == KEY_ESC)
GLWin.running = false;
else if ((key == KEY_P) ||
if (key == KEY_ESC) {
Core::Stop();
GLWin.running = 0;
} else if ((key == KEY_P) ||
((key == KEY_ENTER) && (GLWin.keyboard.modifiers == 0)))
Core::SetState((Core::GetState() == Core::CORE_RUN) ?
Core::CORE_PAUSE : Core::CORE_RUN);
Expand Down Expand Up @@ -408,7 +349,8 @@ bool cWaylandInterface::Initialize(void *config)
wl_registry_add_listener(GLWin.wl_registry,
&registry_listener, NULL);

wl_display_dispatch(GLWin.wl_display);
while (!GLWin.wl_compositor)
wl_display_dispatch(GLWin.wl_display);

GLWin.wl_cursor_surface =
wl_compositor_create_surface(GLWin.wl_compositor);
Expand All @@ -430,8 +372,6 @@ void *cWaylandInterface::CreateWindow(void)
GLWin.window_size.width = 640;
GLWin.window_size.height = 480;
GLWin.fullscreen = true;
GLWin.frame_drawn = false;
GLWin.swap_complete = false;

GLWin.wl_surface = wl_compositor_create_surface(GLWin.wl_compositor);
GLWin.wl_shell_surface = wl_shell_get_shell_surface(GLWin.wl_shell,
Expand All @@ -443,11 +383,8 @@ void *cWaylandInterface::CreateWindow(void)
GLWin.wl_egl_native = wl_egl_window_create(GLWin.wl_surface,
GLWin.window_size.width,
GLWin.window_size.height);
#if HAVE_X11
return GLWin.wl_egl_native;
#else

return GLWin.wl_egl_native;
#endif
}

void cWaylandInterface::DestroyWindow(void)
Expand All @@ -468,5 +405,19 @@ void cWaylandInterface::UpdateFPSDisplay(const char *text)

void cWaylandInterface::ToggleFullscreen(bool fullscreen)
{
toggle_fullscreen(GLWin.fullscreen);
toggle_fullscreen(fullscreen);
}

void cWaylandInterface::SwapBuffers()
{
struct wl_region *region;

region = wl_compositor_create_region(GLWin.wl_compositor);
wl_region_add(region, 0, 0,
GLWin.geometry.width,
GLWin.geometry.height);
wl_surface_set_opaque_region(GLWin.wl_surface, region);
wl_region_destroy(region);

eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf);
}
1 change: 1 addition & 0 deletions Source/Core/DolphinWX/GLInterface/Wayland_Util.h
Expand Up @@ -37,6 +37,7 @@ class cWaylandInterface
void DestroyWindow(void);
void UpdateFPSDisplay(const char *text);
void ToggleFullscreen(bool fullscreen);
void SwapBuffers();
};

#endif
5 changes: 5 additions & 0 deletions Source/Core/DolphinWX/GLInterface/X11_Util.cpp
Expand Up @@ -120,6 +120,11 @@ void cXInterface::UpdateFPSDisplay(const char *text)
XStoreName(GLWin.evdpy, GLWin.win, text);
}

void cXInterface::SwapBuffers()
{
eglSwapBuffers(GLWin.egl_dpy, GLWin.egl_surf);
}

void cXInterface::XEventThread()
#else
void cX11Window::CreateXWindow(void)
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinWX/GLInterface/X11_Util.h
Expand Up @@ -33,6 +33,7 @@ class cXInterface
void *CreateWindow(void);
void DestroyWindow(void);
void UpdateFPSDisplay(const char *text);
void SwapBuffers();
};
#else
class cX11Window
Expand Down
54 changes: 49 additions & 5 deletions Source/Core/DolphinWX/MainNoGUI.cpp
Expand Up @@ -10,12 +10,17 @@
#include "Common.h"
#include "FileUtil.h"

#if defined HAVE_X11 && HAVE_X11
#if HAVE_X11
#include <X11/keysym.h>
#include "State.h"
#include "X11Utils.h"
#endif

#if HAVE_WAYLAND
#include <wayland-client.h>
#include "GLInterface/Platform.h"
#endif

#ifdef __APPLE__
#import <Cocoa/Cocoa.h>
#endif
Expand Down Expand Up @@ -122,7 +127,7 @@ void Host_SysMessage(const char *fmt, ...)

void Host_SetWiiMoteConnectionState(int _State) {}

#if defined(HAVE_X11) && HAVE_X11
#if HAVE_X11
void X11_MainLoop()
{
bool fullscreen = SConfig::GetInstance().m_LocalCoreStartupParameter.bFullscreen;
Expand Down Expand Up @@ -256,6 +261,23 @@ void X11_MainLoop()
}
#endif

#if HAVE_WAYLAND
void Wayland_MainLoop()
{
// Wait for display to be initialized
while(!GLWin.wl_display)
usleep(20000);

GLWin.running = 1;

while (GLWin.running)
wl_display_dispatch(GLWin.wl_display);

if (GLWin.wl_display)
wl_display_disconnect(GLWin.wl_display);
}
#endif

int main(int argc, char* argv[])
{
#ifdef __APPLE__
Expand Down Expand Up @@ -304,9 +326,34 @@ int main(int argc, char* argv[])
m_LocalCoreStartupParameter.m_strVideoBackend);
WiimoteReal::LoadSettings();

#if USE_EGL
GLWin.platform = EGL_PLATFORM_NONE;
#endif
#if HAVE_WAYLAND
GLWin.wl_display = NULL;
#endif

// No use running the loop when booting fails
if (BootManager::BootCore(argv[optind]))
{
#if USE_EGL
while (GLWin.platform == EGL_PLATFORM_NONE)
usleep(20000);
#endif
#if HAVE_WAYLAND
if (GLWin.platform == EGL_PLATFORM_WAYLAND)
Wayland_MainLoop();
#endif
#if HAVE_X11
#if USE_EGL
if (GLWin.platform == EGL_PLATFORM_X11) {
#endif
XInitThreads();
X11_MainLoop();
#if USE_EGL
}
#endif
#endif
#ifdef __APPLE__
while (running)
{
Expand All @@ -328,9 +375,6 @@ int main(int argc, char* argv[])

[event release];
[pool release];
#elif defined HAVE_X11 && HAVE_X11
XInitThreads();
X11_MainLoop();
#else
while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN)
updateMainFrameEvent.Wait();
Expand Down
@@ -1,5 +1,9 @@
#include "ControllerInterface.h"

#if USE_EGL
#include "GLInterface/Platform.h"
#endif

#ifdef CIFACE_USE_XINPUT
#include "XInput/XInput.h"
#endif
Expand Down Expand Up @@ -50,10 +54,16 @@ void ControllerInterface::Initialize()
ciface::XInput::Init(m_devices);
#endif
#ifdef CIFACE_USE_XLIB
#if USE_EGL
if (GLWin.platform == EGL_PLATFORM_X11) {
#endif
ciface::Xlib::Init(m_devices, m_hwnd);
#ifdef CIFACE_USE_X11_XINPUT2
ciface::XInput2::Init(m_devices, m_hwnd);
#endif
#if USE_EGL
}
#endif
#endif
#ifdef CIFACE_USE_OSX
ciface::OSX::Init(m_devices, m_hwnd);
Expand Down

0 comments on commit 84aa98a

Please sign in to comment.