Skip to content

Commit a126688

Browse files
committed
latest
1 parent fa80899 commit a126688

File tree

3 files changed

+58
-34
lines changed

3 files changed

+58
-34
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@ pkg_check_modules(WAYLANDPP_CURSOR REQUIRED "wayland-cursor++>=0.2.7")
4545
pkg_check_modules(WAYLANDPP_EGL REQUIRED "wayland-egl++>=0.2.7")
4646
pkg_check_modules(WAYLANDPP_CLIENT_EXTRA REQUIRED "wayland-client-extra++>=0.2.7")
4747
pkg_check_modules(EGL REQUIRED egl)
48+
pkg_check_modules(OPENGL REQUIRED gl)
4849

49-
# Executable
5050
set(FLUTTER_WAYLAND_SRC
51-
#src/flutter_application.cc
52-
#src/flutter_application.h
5351
src/utils.cc
5452
src/utils.h
5553
src/wayland_display.cc
@@ -62,12 +60,13 @@ link_directories(${CMAKE_BINARY_DIR})
6260
add_executable(flutter_wayland ${FLUTTER_WAYLAND_SRC})
6361

6462
target_link_libraries(flutter_wayland
63+
flutter_engine
6564
${WAYLANDPP_CLIENT_LIBRARIES}
6665
${WAYLANDPP_EGL_LIBRARIES}
6766
${WAYLANDPP_CURSOR_LIBRARIES}
6867
${WAYLANDPP_CLIENT_EXTRA_LIBRARIES}
69-
flutter_engine
7068
${EGL_LDFLAGS}
69+
${OPENGL_LDFLAGS}
7170
)
7271

7372
target_include_directories(flutter_wayland
@@ -76,6 +75,7 @@ target_include_directories(flutter_wayland
7675
${WAYLANDPP_CURSOR_INCLUDE_DIRS}
7776
${WAYLANDPP_EGL_INCLUDE_DIRS}
7877
${WAYLANDPP_CLIENT_EXTRA_INCLUDE_DIRS}
78+
${OPENGL_INCLUDE_DIRS}
7979
${CMAKE_BINARY_DIR}
8080
)
8181

src/wayland_display.cc

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ void WaylandDisplay::InitializeApplication(
6666
return reinterpret_cast<WaylandDisplay*>(userdata)
6767
->OnApplicationGetOnscreenFBO();
6868
};
69+
#if 0
70+
config.open_gl.make_resource_current = [](void* userdata) -> bool {
71+
return reinterpret_cast<WaylandDisplay*>(userdata)
72+
->OnApplicationMakeResouceCurrent();
73+
};
74+
#endif
6975
config.open_gl.gl_proc_resolver = [](void* userdata,
7076
const char* name) -> void* {
7177
auto address = eglGetProcAddress(name);
@@ -91,12 +97,15 @@ void WaylandDisplay::InitializeApplication(
9197
command_line_args_c.push_back(arg.c_str());
9298
}
9399

94-
FlutterProjectArgs args = {
95-
.struct_size = sizeof(FlutterProjectArgs),
96-
.assets_path = bundle_path.c_str(),
97-
.icu_data_path = icu_data_path.c_str(),
98-
.command_line_argc = static_cast<int>(command_line_args_c.size()),
99-
.command_line_argv = command_line_args_c.data(),
100+
FlutterProjectArgs args = {};
101+
args.struct_size = sizeof(FlutterProjectArgs);
102+
args.assets_path = bundle_path.c_str();
103+
args.icu_data_path = icu_data_path.c_str();
104+
args.command_line_argc = static_cast<int>(command_line_args_c.size());
105+
args.command_line_argv = command_line_args_c.data();
106+
args.platform_message_callback = [](const FlutterPlatformMessage* msg,
107+
void* userdata) -> void {
108+
return reinterpret_cast<WaylandDisplay*>(userdata)->OnPlatformMessage(msg);
100109
};
101110

102111
FlutterEngine engine = nullptr;
@@ -187,9 +196,6 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height,
187196

188197
display.roundtrip();
189198

190-
// Get input devices
191-
// touch = seat.get_touch();
192-
193199
// load cursor theme
194200
#if 0
195201
cursor_theme_t cursor_theme = cursor_theme_t("default", 16, shm);
@@ -203,13 +209,16 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height,
203209

204210
if(has_touch)
205211
{
212+
std::cout << "Touch Present" << std::endl;
206213
touch = seat.get_touch();
214+
static FlutterPointerPhase TouchPhase = kUp;
207215

208216
touch.on_down() = [&] (uint32_t serial, uint32_t time, surface_t surface, int32_t id, double x, double y)
209217
{
210218
FlutterPointerEvent event = {};
211219
event.struct_size = sizeof(event);
212220
event.phase = kDown;
221+
TouchPhase = event.phase;
213222
cur_x = x;
214223
cur_y = y;
215224
event.x = x;
@@ -226,6 +235,7 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height,
226235
FlutterPointerEvent event = {};
227236
event.struct_size = sizeof(event);
228237
event.phase = kUp;
238+
TouchPhase = event.phase;
229239
event.x = cur_x;
230240
event.y = cur_y;
231241
event.timestamp =
@@ -242,7 +252,7 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height,
242252

243253
FlutterPointerEvent event = {};
244254
event.struct_size = sizeof(event);
245-
event.phase = kMove;
255+
event.phase = (TouchPhase == kUp) ? kHover : kMove;
246256
event.x = cur_x;
247257
event.y = cur_y;
248258
event.timestamp =
@@ -255,7 +265,9 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height,
255265

256266
if(has_pointer)
257267
{
268+
std::cout << "Pointer Present" << std::endl;
258269
pointer = seat.get_pointer();
270+
static FlutterPointerPhase PointerPhase = kUp;
259271

260272
pointer.on_enter() = [&] (uint32_t serial, surface_t surface, int32_t surface_x, int32_t surface_y)
261273
{
@@ -283,14 +295,15 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height,
283295
FlutterEngineSendPointerEvent(engine_, &event, 1);
284296
};
285297

286-
pointer.on_motion() = [&] (uint32_t time, double surface_x, double surface_y)
298+
static bool button = false;
299+
pointer.on_motion() = [&] (uint32_t time, double surface_x, double surface_y)
287300
{
288301
cur_x = surface_x;
289302
cur_y = surface_y;
290303

291304
FlutterPointerEvent event = {};
292305
event.struct_size = sizeof(event);
293-
event.phase = kMove;
306+
event.phase = (PointerPhase == kUp) ? kHover : kMove;
294307
event.x = surface_x;
295308
event.y = surface_y;
296309
event.timestamp =
@@ -305,6 +318,7 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height,
305318
FlutterPointerEvent event = {};
306319
event.struct_size = sizeof(event);
307320
event.phase = (state == pointer_button_state::pressed) ? kDown : kUp;
321+
PointerPhase = event.phase;
308322
switch(button)
309323
{
310324
case BTN_LEFT:
@@ -324,15 +338,6 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height,
324338
std::chrono::high_resolution_clock::now().time_since_epoch())
325339
.count();
326340
FlutterEngineSendPointerEvent(engine_, &event, 1);
327-
#if 0
328-
if(button == BTN_LEFT && state == pointer_button_state::pressed)
329-
{
330-
if(xdg_toplevel)
331-
xdg_toplevel.move(seat, serial);
332-
else
333-
shell_surface.move(seat, serial);
334-
}
335-
#endif
336341
};
337342

338343
pointer.on_axis() = [&] (uint32_t time, pointer_axis axis, double value)
@@ -381,7 +386,7 @@ WaylandDisplay::~WaylandDisplay() noexcept(false) {
381386

382387
void WaylandDisplay::init_egl()
383388
{
384-
if(eglBindAPI(EGL_OPENGL_ES_API) == EGL_FALSE)
389+
if(eglBindAPI(EGL_OPENGL_API) == EGL_FALSE)
385390
throw std::runtime_error("eglBindAPI");
386391

387392
egldisplay = eglGetDisplay(display);
@@ -543,4 +548,26 @@ uint32_t WaylandDisplay::OnApplicationGetOnscreenFBO() {
543548
return 0; // FBO0
544549
}
545550

551+
/// This is an optional callback. Flutter will ask the emebdder to create a GL
552+
/// context current on a background thread. If the embedder is able to do so,
553+
/// Flutter will assume that this context is in the same sharegroup as the
554+
/// main rendering context and use this context for asynchronous texture
555+
/// uploads.
556+
bool WaylandDisplay::OnApplicationMakeResouceCurrent() {
557+
return true;
558+
}
559+
560+
void WaylandDisplay::OnPlatformMessage(const FlutterPlatformMessage* msg)
561+
{
562+
FLWAY_LOG << "Channel: " << msg->channel << std::endl;
563+
FLWAY_LOG << "Message Size: " << msg->message_size << std::endl;
564+
FLWAY_LOG << "Message: " << msg->message << std::endl;
565+
566+
auto result = FlutterEngineSendPlatformMessageResponse(engine_, msg->response_handle, NULL, 0);
567+
if (result != kSuccess) {
568+
FLWAY_ERROR << "Could not send platform message response" << std::endl;
569+
return;
570+
}
571+
}
572+
546573
} // namespace flutter

src/wayland_display.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
#pragma once
66

7-
#define USE_FULL_GL 0
8-
97

108
#include <stdexcept>
119
#include <iostream>
@@ -14,12 +12,8 @@
1412
#include <wayland-client-protocol-extra.hpp>
1513
#include <wayland-egl.hpp>
1614

17-
#if USE_FULL_GL
18-
#include <GL/gl.h> /* use full OpenGL */
19-
#else
20-
#include <GLES2/gl2.h> /* use OpenGL ES 2.x */
21-
#endif
22-
#include <EGL/egl.h>
15+
#include <GLES3/gl3.h>
16+
//#include <EGL/egl.h>
2317

2418
#include <linux/input.h>
2519
#include <wayland-cursor.hpp>
@@ -118,6 +112,9 @@ class WaylandDisplay {
118112

119113
uint32_t OnApplicationGetOnscreenFBO();
120114

115+
bool OnApplicationMakeResouceCurrent();
116+
117+
void OnPlatformMessage(const FlutterPlatformMessage* msg);
121118

122119
FLWAY_DISALLOW_COPY_AND_ASSIGN(WaylandDisplay);
123120
};

0 commit comments

Comments
 (0)