Skip to content

Commit

Permalink
Merge pull request #204 from Metrological/lgi-rdk2brow-8
Browse files Browse the repository at this point in the history
[wpe-platform] Adding LG WPE patch for Wayland/Weston
  • Loading branch information
zdobersek authored Feb 2, 2017
2 parents 16e0f0b + d4a11ba commit f55216a
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
38 changes: 37 additions & 1 deletion Source/ThirdParty/WPE-platform/src/wayland-egl/view-backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <wpe/input.h>
#include <wpe/view-backend.h>

#include "display.h"
#include "ipc.h"
#include "ipc-waylandegl.h"

#define WIDTH 1280
#define HEIGHT 720

namespace WaylandEGL {

struct ViewBackend;
Expand All @@ -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;
Expand All @@ -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<wpe_input_axis_event*>(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<wpe_input_pointer_event*>(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<wpe_input_touch_event*>(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<wpe_input_keyboard_event*>(std::addressof(message.messageData));
wpe_view_backend_dispatch_keyboard_event(backend, event);
break;
}
case IPC::WaylandEGL::BufferCommit::code:
{
ackBufferCommit();
Expand All @@ -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;
Expand Down Expand Up @@ -105,6 +139,8 @@ struct wpe_view_backend_interface wayland_egl_view_backend_interface = {
// initialize
[](void* data)
{
auto& backend = *static_cast<WaylandEGL::ViewBackend*>(data);
backend.initialize();
},
// get_renderer_host_fd
[](void* data) -> int
Expand Down
85 changes: 71 additions & 14 deletions Source/ThirdParty/WPE-platform/src/wayland/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,10 @@ static const struct wl_pointer_listener g_pointerListener = {
auto& pointer = static_cast<Display::SeatData*>(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);
}
Expand All @@ -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);
}
Expand All @@ -213,9 +215,10 @@ static const struct wl_pointer_listener g_pointerListener = {
auto& pointer = static_cast<Display::SeatData*>(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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -318,7 +322,6 @@ static const struct wl_keyboard_listener g_keyboardListener = {
{
// IDK.
key += 8;

auto& seatData = *static_cast<Display::SeatData*>(data);
seatData.serial = serial;
handleKeyEvent(seatData, key, state, time);
Expand Down Expand Up @@ -501,6 +504,7 @@ static const struct wl_seat_listener g_seatListener = {
[](void*, struct wl_seat*, const char*) { }
};


Display& Display::singleton()
{
static Display display;
Expand All @@ -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<EventSource*>(m_eventSource);
source->display = m_display;
Expand All @@ -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);
Expand Down Expand Up @@ -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
23 changes: 23 additions & 0 deletions Source/ThirdParty/WPE-platform/src/wayland/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <wpe/input.h>
#include <xkbcommon/xkbcommon-compose.h>
#include <xkbcommon/xkbcommon.h>
#include "ipc.h"

struct wpe_view_backend;

Expand All @@ -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();
Expand Down

0 comments on commit f55216a

Please sign in to comment.