@@ -50,29 +50,28 @@ void WaylandDisplay::InitializeApplication(
50
50
FlutterRendererConfig config = {};
51
51
config.type = kOpenGL ;
52
52
config.open_gl .struct_size = sizeof (config.open_gl );
53
- config.open_gl .make_current = [](void * userdata ) -> bool {
54
- return reinterpret_cast <WaylandDisplay*>(userdata )
55
- ->OnApplicationContextMakeCurrent ();
53
+ config.open_gl .make_current = [](void * context ) -> bool {
54
+ return reinterpret_cast <WaylandDisplay*>(context )
55
+ ->GLMakeCurrent ();
56
56
};
57
- config.open_gl .clear_current = [](void * userdata ) -> bool {
58
- return reinterpret_cast <WaylandDisplay*>(userdata )
59
- ->OnApplicationContextClearCurrent ();
57
+ config.open_gl .clear_current = [](void * context ) -> bool {
58
+ return reinterpret_cast <WaylandDisplay*>(context )
59
+ ->GLClearCurrent ();
60
60
};
61
- config.open_gl .present = [](void * userdata ) -> bool {
62
- return reinterpret_cast <WaylandDisplay*>(userdata )
63
- ->OnApplicationPresent ();
61
+ config.open_gl .present = [](void * context ) -> bool {
62
+ return reinterpret_cast <WaylandDisplay*>(context )
63
+ ->GLPresent ();
64
64
};
65
- config.open_gl .fbo_callback = [](void * userdata ) -> uint32_t {
66
- return reinterpret_cast <WaylandDisplay*>(userdata )
67
- ->OnApplicationGetOnscreenFBO ();
65
+ config.open_gl .fbo_callback = [](void * context ) -> uint32_t {
66
+ return reinterpret_cast <WaylandDisplay*>(context )
67
+ ->GLFboCallback ();
68
68
};
69
- #if 0
70
- config.open_gl.make_resource_current = [](void* userdata) -> bool {
71
- return reinterpret_cast<WaylandDisplay*>(userdata)
72
- ->OnApplicationMakeResouceCurrent();
69
+ config.open_gl .make_resource_current = [](void * context) -> bool {
70
+ return reinterpret_cast <WaylandDisplay*>(context)
71
+ ->GLMakeResourceCurrent ();
73
72
};
74
- # endif
75
- config.open_gl .gl_proc_resolver = [](void * userdata ,
73
+
74
+ config.open_gl .gl_proc_resolver = [](void * context ,
76
75
const char * name) -> void * {
77
76
auto address = eglGetProcAddress (name);
78
77
if (address != nullptr ) {
@@ -103,10 +102,12 @@ void WaylandDisplay::InitializeApplication(
103
102
args.icu_data_path = icu_data_path.c_str ();
104
103
args.command_line_argc = static_cast <int >(command_line_args_c.size ());
105
104
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);
109
- };
105
+ args.platform_message_callback =
106
+ [](const FlutterPlatformMessage* message, void * context) {
107
+ reinterpret_cast <WaylandDisplay*>(context)
108
+ ->PlatformMessageCallback (message);
109
+ };
110
+
110
111
111
112
FlutterEngine engine = nullptr ;
112
113
auto result = FlutterEngineRun (FLUTTER_ENGINE_VERSION, &config, &args,
@@ -176,7 +177,6 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height,
176
177
// create a shell surface
177
178
if (xdg_wm_base)
178
179
{
179
- std::cout << " Using xdg_wm_base" << std::endl;
180
180
xdg_wm_base.on_ping () = [&] (uint32_t serial) { xdg_wm_base.pong (serial); };
181
181
xdg_surface = xdg_wm_base.get_xdg_surface (surface);
182
182
xdg_surface.on_configure () = [&] (uint32_t serial) { xdg_surface.ack_configure (serial); };
@@ -186,7 +186,6 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height,
186
186
}
187
187
else
188
188
{
189
- std::cout << " Not using xdg_wm_base" << std::endl;
190
189
shell_surface = shell.get_shell_surface (surface);
191
190
shell_surface.on_ping () = [&] (uint32_t serial) { shell_surface.pong (serial); };
192
191
shell_surface.set_title (" Flutter" );
@@ -196,17 +195,6 @@ WaylandDisplay::WaylandDisplay(size_t width, size_t height,
196
195
197
196
display.roundtrip ();
198
197
199
- // load cursor theme
200
- #if 0
201
- cursor_theme_t cursor_theme = cursor_theme_t("default", 16, shm);
202
- cursor_t cursor = cursor_theme.get_cursor("cross");
203
- cursor_image = cursor.image(0);
204
- cursor_buffer = cursor_image.get_buffer();
205
-
206
- // create cursor surface
207
- cursor_surface = compositor.create_surface();
208
- #endif
209
-
210
198
if (has_touch)
211
199
{
212
200
std::cout << " Touch Present" << std::endl;
@@ -379,6 +367,8 @@ WaylandDisplay::~WaylandDisplay() noexcept(false) {
379
367
// finialize EGL
380
368
if (eglDestroyContext (egldisplay, eglcontext) == EGL_FALSE)
381
369
throw std::runtime_error (" eglDestroyContext" );
370
+ if (eglDestroyContext (egldisplay, eglresourcecontext) == EGL_FALSE)
371
+ throw std::runtime_error (" eglDestroyContext Resource" );
382
372
if (eglTerminate (egldisplay) == EGL_FALSE)
383
373
throw std::runtime_error (" eglTerminate" );
384
374
@@ -430,6 +420,11 @@ void WaylandDisplay::init_egl()
430
420
eglcontext = eglCreateContext (egldisplay, config, EGL_NO_CONTEXT, context_attribs.data ());
431
421
if (eglcontext == EGL_NO_CONTEXT)
432
422
throw std::runtime_error (" eglCreateContext" );
423
+
424
+ eglresourcecontext = eglCreateContext (
425
+ egldisplay, config, eglcontext, context_attribs.data ());
426
+ if (eglresourcecontext == EGL_NO_CONTEXT)
427
+ throw std::runtime_error (" eglCreateContext" );
433
428
}
434
429
435
430
bool WaylandDisplay::Run () {
@@ -448,126 +443,69 @@ bool WaylandDisplay::Run() {
448
443
return true ;
449
444
}
450
445
451
- static void LogLastEGLError () {
452
- struct EGLNameErrorPair {
453
- const char * name;
454
- EGLint code;
455
- };
456
-
457
- #define _EGL_ERROR_DESC (a ) \
458
- { #a, a }
459
-
460
- const EGLNameErrorPair pairs[] = {
461
- _EGL_ERROR_DESC (EGL_SUCCESS),
462
- _EGL_ERROR_DESC (EGL_NOT_INITIALIZED),
463
- _EGL_ERROR_DESC (EGL_BAD_ACCESS),
464
- _EGL_ERROR_DESC (EGL_BAD_ALLOC),
465
- _EGL_ERROR_DESC (EGL_BAD_ATTRIBUTE),
466
- _EGL_ERROR_DESC (EGL_BAD_CONTEXT),
467
- _EGL_ERROR_DESC (EGL_BAD_CONFIG),
468
- _EGL_ERROR_DESC (EGL_BAD_CURRENT_SURFACE),
469
- _EGL_ERROR_DESC (EGL_BAD_DISPLAY),
470
- _EGL_ERROR_DESC (EGL_BAD_SURFACE),
471
- _EGL_ERROR_DESC (EGL_BAD_MATCH),
472
- _EGL_ERROR_DESC (EGL_BAD_PARAMETER),
473
- _EGL_ERROR_DESC (EGL_BAD_NATIVE_PIXMAP),
474
- _EGL_ERROR_DESC (EGL_BAD_NATIVE_WINDOW),
475
- _EGL_ERROR_DESC (EGL_CONTEXT_LOST),
476
- };
477
-
478
- #undef _EGL_ERROR_DESC
479
-
480
- const auto count = sizeof (pairs) / sizeof (EGLNameErrorPair);
481
-
482
- EGLint last_error = eglGetError ();
483
-
484
- for (size_t i = 0 ; i < count; i++) {
485
- if (last_error == pairs[i].code ) {
486
- FLWAY_ERROR << " EGL Error: " << pairs[i].name << " (" << pairs[i].code
487
- << " )" << std::endl;
488
- return ;
489
- }
446
+ bool WaylandDisplay::GLMakeCurrent () {
447
+ if (!valid_) {
448
+ FLWAY_ERROR << " Invalid display." << std::endl;
449
+ return false ;
490
450
}
491
451
492
- FLWAY_ERROR << " Unknown EGL Error " << std::endl ;
452
+ return ( eglMakeCurrent (egldisplay, eglsurface, eglsurface, eglcontext) == EGL_TRUE) ;
493
453
}
494
454
495
- bool WaylandDisplay::OnApplicationContextMakeCurrent () {
455
+ bool WaylandDisplay::GLClearCurrent () {
496
456
if (!valid_) {
497
457
FLWAY_ERROR << " Invalid display." << std::endl;
498
458
return false ;
499
459
}
500
460
501
- if (eglMakeCurrent (egldisplay, eglsurface, eglsurface, eglcontext) !=
502
- EGL_TRUE) {
503
- FLWAY_ERROR << " Could not make the onscreen context current" << std::endl;
504
- LogLastEGLError ();
505
- return false ;
506
- }
507
-
508
- return true ;
461
+ return (eglMakeCurrent (egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
462
+ EGL_NO_CONTEXT) == EGL_TRUE);
509
463
}
510
464
511
- bool WaylandDisplay::OnApplicationContextClearCurrent () {
465
+ bool WaylandDisplay::GLPresent () {
512
466
if (!valid_) {
513
467
FLWAY_ERROR << " Invalid display." << std::endl;
514
468
return false ;
515
469
}
516
470
517
- if (eglMakeCurrent (egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
518
- EGL_NO_CONTEXT) != EGL_TRUE) {
519
- FLWAY_ERROR << " Could not clear the context." << std::endl;
520
- LogLastEGLError ();
521
- return false ;
522
- }
523
-
524
- return true ;
471
+ return (eglSwapBuffers (egldisplay, eglsurface) == EGL_TRUE);
525
472
}
526
473
527
- bool WaylandDisplay::OnApplicationPresent () {
474
+ uint32_t WaylandDisplay::GLFboCallback () {
528
475
if (!valid_) {
529
476
FLWAY_ERROR << " Invalid display." << std::endl;
530
- return false ;
531
- }
532
-
533
- if (eglSwapBuffers (egldisplay, eglsurface) != EGL_TRUE) {
534
- FLWAY_ERROR << " Could not swap the EGL buffer." << std::endl;
535
- LogLastEGLError ();
536
- return false ;
477
+ return 999 ;
537
478
}
538
479
539
- return true ;
480
+ return 0 ; // FBO0
540
481
}
541
482
542
- uint32_t WaylandDisplay::OnApplicationGetOnscreenFBO () {
483
+ bool WaylandDisplay::GLMakeResourceCurrent () {
543
484
if (!valid_) {
544
485
FLWAY_ERROR << " Invalid display." << std::endl;
545
- return 999 ;
486
+ return false ;
546
487
}
547
488
548
- return 0 ; // FBO0
489
+ return (eglMakeCurrent (egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
490
+ eglresourcecontext) == EGL_TRUE);
549
491
}
550
492
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 ;
493
+ void WaylandDisplay::SetPlatformMessageCallback (
494
+ const std::function<void (const FlutterPlatformMessage*)>& callback) {
495
+ platform_message_callback_ = callback;
558
496
}
559
497
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;
498
+ void WaylandDisplay::PlatformMessageCallback (
499
+ const FlutterPlatformMessage* message) {
565
500
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 ;
501
+ FLWAY_LOG << " Channel: " << message->channel << std::endl;
502
+ FLWAY_LOG << " Message Size: " << message->message_size << std::endl;
503
+ FLWAY_LOG << " Message: " << message->message << std::endl;
504
+
505
+ if (platform_message_callback_) {
506
+ platform_message_callback_ (message);
570
507
}
571
508
}
572
509
510
+
573
511
} // namespace flutter
0 commit comments