From d4a11ba3ab6e761732e84047395cc22a5d8f7427 Mon Sep 17 00:00:00 2001 From: wouterlucas Date: Wed, 1 Feb 2017 15:54:06 -0800 Subject: [PATCH] [wpe-platform] Adding LG WPE patch for Wayland/Weston --- .../src/wayland-egl/renderer-backend.cpp | 7 +- .../src/wayland-egl/view-backend.cpp | 38 ++++++++- .../WPE-platform/src/wayland/display.cpp | 85 ++++++++++++++++--- .../WPE-platform/src/wayland/display.h | 23 +++++ 4 files changed, 135 insertions(+), 18 deletions(-) diff --git a/Source/ThirdParty/WPE-platform/src/wayland-egl/renderer-backend.cpp b/Source/ThirdParty/WPE-platform/src/wayland-egl/renderer-backend.cpp index 95eacf7ebb7f8..7c9829786256c 100644 --- a/Source/ThirdParty/WPE-platform/src/wayland-egl/renderer-backend.cpp +++ b/Source/ThirdParty/WPE-platform/src/wayland-egl/renderer-backend.cpp @@ -97,13 +97,14 @@ EGLTarget::EGLTarget(struct wpe_renderer_backend_egl_target* target, int hostFd) : target(target) { ipcClient.initialize(*this, hostFd); + Wayland::EventDispatcher::singleton().setIPC( ipcClient ); } void EGLTarget::initialize(Backend& backend, uint32_t width, uint32_t height) { m_backend = &backend; - m_surface = wl_compositor_create_surface(m_backend->display.interfaces().compositor); + if (!m_surface) { fprintf(stderr, "EGLTarget: unable to create wayland surface\n"); return; @@ -114,10 +115,10 @@ void EGLTarget::initialize(Backend& backend, uint32_t width, uint32_t height) if (m_shellSurface) { wl_shell_surface_add_listener(m_shellSurface, &shell_surface_listener, NULL); - wl_shell_surface_set_toplevel(m_shellSurface); + // wl_shell_surface_set_toplevel(m_shellSurface); + wl_shell_surface_set_fullscreen(m_shellSurface, WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT, 0, NULL); } } - struct wl_region *region; region = wl_compositor_create_region(m_backend->display.interfaces().compositor); wl_region_add(region, 0, 0, diff --git a/Source/ThirdParty/WPE-platform/src/wayland-egl/view-backend.cpp b/Source/ThirdParty/WPE-platform/src/wayland-egl/view-backend.cpp index 83998936dc0ba..6c44d765fb9b4 100644 --- a/Source/ThirdParty/WPE-platform/src/wayland-egl/view-backend.cpp +++ b/Source/ThirdParty/WPE-platform/src/wayland-egl/view-backend.cpp @@ -26,11 +26,15 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include - +#include "display.h" #include "ipc.h" #include "ipc-waylandegl.h" +#define WIDTH 1280 +#define HEIGHT 720 + namespace WaylandEGL { struct ViewBackend; @@ -44,6 +48,7 @@ struct ViewBackend : public IPC::Host::Handler { void handleMessage(char*, size_t) override; void ackBufferCommit(); + void initialize(); struct wpe_view_backend* backend; IPC::Host ipcHost; @@ -67,6 +72,30 @@ void ViewBackend::handleMessage(char* data, size_t size) auto& message = IPC::Message::cast(data); switch (message.messageCode) { + case Wayland::EventDispatcher::MsgType::AXIS: + { + struct wpe_input_axis_event * event = reinterpret_cast(std::addressof(message.messageData)); + wpe_view_backend_dispatch_axis_event(backend, event); + break; + } + case Wayland::EventDispatcher::MsgType::POINTER: + { + struct wpe_input_pointer_event * event = reinterpret_cast(std::addressof(message.messageData)); + wpe_view_backend_dispatch_pointer_event(backend, event); + break; + } + case Wayland::EventDispatcher::MsgType::TOUCH: + { + struct wpe_input_touch_event * event = reinterpret_cast(std::addressof(message.messageData)); + wpe_view_backend_dispatch_touch_event(backend, event); + break; + } + case Wayland::EventDispatcher::MsgType::KEYBOARD: + { + struct wpe_input_keyboard_event * event = reinterpret_cast(std::addressof(message.messageData)); + wpe_view_backend_dispatch_keyboard_event(backend, event); + break; + } case IPC::WaylandEGL::BufferCommit::code: { ackBufferCommit(); @@ -77,6 +106,11 @@ void ViewBackend::handleMessage(char* data, size_t size) } } +void ViewBackend::initialize() +{ + wpe_view_backend_dispatch_set_size( backend, WIDTH, HEIGHT ); +} + void ViewBackend::ackBufferCommit() { IPC::Message message; @@ -105,6 +139,8 @@ struct wpe_view_backend_interface wayland_egl_view_backend_interface = { // initialize [](void* data) { + auto& backend = *static_cast(data); + backend.initialize(); }, // get_renderer_host_fd [](void* data) -> int diff --git a/Source/ThirdParty/WPE-platform/src/wayland/display.cpp b/Source/ThirdParty/WPE-platform/src/wayland/display.cpp index 0cb537c0d3247..fec8c643b76a7 100644 --- a/Source/ThirdParty/WPE-platform/src/wayland/display.cpp +++ b/Source/ThirdParty/WPE-platform/src/wayland/display.cpp @@ -177,9 +177,10 @@ static const struct wl_pointer_listener g_pointerListener = { auto& pointer = static_cast(data)->pointer; pointer.coords = { x, y }; - if (pointer.target.first) { - struct wpe_input_pointer_event event = { wpe_input_pointer_event_type_motion, time, x, y, pointer.button, pointer.state }; + struct wpe_input_pointer_event event = { wpe_input_pointer_event_type_motion, time, x, y, pointer.button, pointer.state }; + EventDispatcher::singleton().sendEvent( event ); + if (pointer.target.first) { struct wpe_view_backend* backend = pointer.target.second; wpe_view_backend_dispatch_pointer_event(backend, &event); } @@ -200,9 +201,10 @@ static const struct wl_pointer_listener g_pointerListener = { pointer.button = !!state ? button : 0; pointer.state = state; - if (pointer.target.first) { - struct wpe_input_pointer_event event = { wpe_input_pointer_event_type_button, time, coords.first, coords.second, button, state }; + struct wpe_input_pointer_event event = { wpe_input_pointer_event_type_button, time, coords.first, coords.second, button, state }; + EventDispatcher::singleton().sendEvent( event ); + if (pointer.target.first) { struct wpe_view_backend* backend = pointer.target.second; wpe_view_backend_dispatch_pointer_event(backend, &event); } @@ -213,9 +215,10 @@ static const struct wl_pointer_listener g_pointerListener = { auto& pointer = static_cast(data)->pointer; auto& coords = pointer.coords; - if (pointer.target.first) { - struct wpe_input_axis_event event = { wpe_input_axis_event_type_motion, time, coords.first, coords.second, axis, -wl_fixed_to_int(value) }; + struct wpe_input_axis_event event = { wpe_input_axis_event_type_motion, time, coords.first, coords.second, axis, -wl_fixed_to_int(value) }; + EventDispatcher::singleton().sendEvent( event ); + if (pointer.target.first) { struct wpe_view_backend* backend = pointer.target.second; wpe_view_backend_dispatch_axis_event(backend, &event); } @@ -238,9 +241,10 @@ handleKeyEvent(Display::SeatData& seatData, uint32_t key, uint32_t state, uint32 unicode = xkb_keysym_to_utf32(keysym); } - if (seatData.keyboard.target.first) { - struct wpe_input_keyboard_event event = { time, keysym, unicode, !!state, xkb.modifiers }; + struct wpe_input_keyboard_event event = { time, keysym, unicode, !!state, xkb.modifiers }; + EventDispatcher::singleton().sendEvent( event ); + if (seatData.keyboard.target.first) { struct wpe_view_backend* backend = seatData.keyboard.target.second; wpe_view_backend_dispatch_keyboard_event(backend, &event); } @@ -318,7 +322,6 @@ static const struct wl_keyboard_listener g_keyboardListener = { { // IDK. key += 8; - auto& seatData = *static_cast(data); seatData.serial = serial; handleKeyEvent(seatData, key, state, time); @@ -501,6 +504,7 @@ static const struct wl_seat_listener g_seatListener = { [](void*, struct wl_seat*, const char*) { } }; + Display& Display::singleton() { static Display display; @@ -511,10 +515,8 @@ Display::Display() { m_display = wl_display_connect(nullptr); m_registry = wl_display_get_registry(m_display); - wl_registry_add_listener(m_registry, &g_registryListener, &m_interfaces); wl_display_roundtrip(m_display); - m_eventSource = g_source_new(&EventSource::sourceFuncs, sizeof(EventSource)); auto* source = reinterpret_cast(m_eventSource); source->display = m_display; @@ -523,18 +525,17 @@ Display::Display() source->pfd.events = G_IO_IN | G_IO_ERR | G_IO_HUP; source->pfd.revents = 0; g_source_add_poll(m_eventSource, &source->pfd); - g_source_set_name(m_eventSource, "[WPE] Display"); g_source_set_priority(m_eventSource, G_PRIORITY_HIGH + 30); g_source_set_can_recurse(m_eventSource, TRUE); g_source_attach(m_eventSource, g_main_context_get_thread_default()); - if (m_interfaces.xdg) { xdg_shell_add_listener(m_interfaces.xdg, &g_xdgShellListener, nullptr); xdg_shell_use_unstable_version(m_interfaces.xdg, 5); } - wl_seat_add_listener(m_interfaces.seat, &g_seatListener, &m_seatData); + if ( m_interfaces.seat ) + wl_seat_add_listener(m_interfaces.seat, &g_seatListener, &m_seatData); m_seatData.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); m_seatData.xkb.composeTable = xkb_compose_table_new_from_locale(m_seatData.xkb.context, setlocale(LC_CTYPE, nullptr), XKB_COMPOSE_COMPILE_NO_FLAGS); @@ -619,4 +620,60 @@ void Display::unregisterInputClient(struct wl_surface* surface) m_seatData.inputClients.erase(it); } + +EventDispatcher& EventDispatcher::singleton() +{ + static EventDispatcher event; + return event; +} + +void EventDispatcher::sendEvent( wpe_input_axis_event& event ) +{ + if ( m_ipc != nullptr ) + { + IPC::Message message; + message.messageCode = MsgType::AXIS; + memcpy( message.messageData, &event, sizeof(event) ); + m_ipc->sendMessage(IPC::Message::data(message), IPC::Message::size); + } +} + +void EventDispatcher::sendEvent( wpe_input_pointer_event& event ) +{ + if ( m_ipc != nullptr ) + { + IPC::Message message; + message.messageCode = MsgType::POINTER; + memcpy( message.messageData, &event, sizeof(event) ); + m_ipc->sendMessage(IPC::Message::data(message), IPC::Message::size); + } +} + +void EventDispatcher::sendEvent( wpe_input_touch_event& event ) +{ + if ( m_ipc != nullptr ) + { + IPC::Message message; + message.messageCode = MsgType::TOUCH; + memcpy( message.messageData, &event, sizeof(event) ); + m_ipc->sendMessage(IPC::Message::data(message), IPC::Message::size); + } +} + +void EventDispatcher::sendEvent( wpe_input_keyboard_event& event ) +{ + if ( m_ipc != nullptr ) + { + IPC::Message message; + message.messageCode = MsgType::KEYBOARD; + memcpy( message.messageData, &event, sizeof(event) ); + m_ipc->sendMessage(IPC::Message::data(message), IPC::Message::size); + } +} + +void EventDispatcher::setIPC( IPC::Client& ipcClient ) +{ + m_ipc = &ipcClient; +} + } // namespace Wayland diff --git a/Source/ThirdParty/WPE-platform/src/wayland/display.h b/Source/ThirdParty/WPE-platform/src/wayland/display.h index a5ab18f6a449d..65d0ac13bacbd 100644 --- a/Source/ThirdParty/WPE-platform/src/wayland/display.h +++ b/Source/ThirdParty/WPE-platform/src/wayland/display.h @@ -33,6 +33,7 @@ #include #include #include +#include "ipc.h" struct wpe_view_backend; @@ -54,6 +55,28 @@ typedef struct _GSource GSource; namespace Wayland { +class EventDispatcher +{ +public: + static EventDispatcher& singleton(); + void sendEvent( wpe_input_axis_event& event ); + void sendEvent( wpe_input_pointer_event& event ); + void sendEvent( wpe_input_touch_event& event ); + void sendEvent( wpe_input_keyboard_event& event ); + void setIPC( IPC::Client& ipcClient ); + enum MsgType + { + AXIS = 0x30, + POINTER, + TOUCH, + KEYBOARD + }; +private: + EventDispatcher() {}; + ~EventDispatcher() {}; + IPC::Client * m_ipc; +}; + class Display { public: static Display& singleton();