4
4
// found in the LICENSE file.
5
5
6
6
#include " wayland_display.h"
7
- #include " utils.h"
8
7
9
8
#include < linux/input-event-codes.h>
9
+ #include < rapidjson/document.h>
10
+ #include < rapidjson/stringbuffer.h>
11
+ #include < rapidjson/writer.h>
10
12
#include < sys/mman.h>
11
13
#include < sys/types.h>
12
14
#include < unistd.h>
13
15
#include < xkbcommon/xkbcommon.h>
16
+
14
17
#include < chrono>
15
18
#include < sstream>
16
19
#include < thread>
17
20
#include < vector>
18
21
19
- #include < rapidjson/document.h>
20
- #include < rapidjson/stringbuffer.h>
21
- #include < rapidjson/writer.h>
22
+ #include " utils.h"
22
23
23
24
namespace flutter {
24
25
@@ -68,7 +69,6 @@ void WaylandDisplay::InitializeApplication(
68
69
config.open_gl .make_resource_current = [](void * context) -> bool {
69
70
return reinterpret_cast <WaylandDisplay*>(context)->GLMakeResourceCurrent ();
70
71
};
71
-
72
72
config.open_gl .gl_proc_resolver = [](void * context,
73
73
const char * name) -> void * {
74
74
auto address = eglGetProcAddress (name);
@@ -78,6 +78,14 @@ void WaylandDisplay::InitializeApplication(
78
78
FLWAY_ERROR << " Tried unsuccessfully to resolve: " << name << std::endl;
79
79
return nullptr ;
80
80
};
81
+ #if 0
82
+ config.open_gl.gl_external_texture_frame_callback =
83
+ [](void* context, int64_t texture_id, size_t width, size_t height,
84
+ FlutterOpenGLTexture* texture) -> bool {
85
+ return reinterpret_cast<WaylandDisplay*>(context)
86
+ ->GLExternalTextureFrameCallback(texture_id, width, height, texture);
87
+ };
88
+ #endif
81
89
82
90
auto icu_data_path = GetICUDataPath ();
83
91
@@ -106,12 +114,34 @@ void WaylandDisplay::InitializeApplication(
106
114
message);
107
115
};
108
116
117
+ // Configure task runner interop
118
+ FlutterTaskRunnerDescription platform_task_runner = {};
119
+ platform_task_runner.struct_size = sizeof (FlutterTaskRunnerDescription);
120
+ platform_task_runner.user_data = this ;
121
+ platform_task_runner.runs_task_on_current_thread_callback =
122
+ [](void * context) -> bool { return true ; };
123
+ platform_task_runner.post_task_callback =
124
+ [](FlutterTask task, uint64_t target_time, void * context) -> void {
125
+ reinterpret_cast <WaylandDisplay*>(context)->PostTaskCallback (task,
126
+ target_time);
127
+ };
128
+
129
+ FlutterCustomTaskRunners custom_task_runners = {};
130
+ custom_task_runners.struct_size = sizeof (FlutterCustomTaskRunners);
131
+ custom_task_runners.platform_task_runner = &platform_task_runner;
132
+ args.custom_task_runners = &custom_task_runners;
133
+
109
134
FlutterEngine engine = nullptr ;
110
- auto result = FlutterEngineRun (FLUTTER_ENGINE_VERSION, &config, &args,
111
- this /* userdata */ , &engine_);
135
+ auto result = FlutterEngineInitialize (FLUTTER_ENGINE_VERSION, &config, &args,
136
+ this , &engine_);
137
+ if (result != kSuccess ) {
138
+ FLWAY_ERROR << " Could not Initialize the Flutter engine" << std::endl;
139
+ return ;
140
+ }
112
141
142
+ result = FlutterEngineRunInitialized (engine_);
113
143
if (result != kSuccess ) {
114
- FLWAY_ERROR << " Could not run the Flutter engine" << std::endl;
144
+ FLWAY_ERROR << " Could not run the initialized Flutter engine" << std::endl;
115
145
return ;
116
146
}
117
147
@@ -131,10 +161,6 @@ bool WaylandDisplay::SetWindowSize(size_t width, size_t height) {
131
161
return FlutterEngineSendWindowMetricsEvent (engine_, &event) == kSuccess ;
132
162
}
133
163
134
- void WaylandDisplay::ProcessEvents () {
135
- __FlutterEngineFlushPendingTasksNow ();
136
- }
137
-
138
164
WaylandDisplay::WaylandDisplay (size_t width,
139
165
size_t height,
140
166
std::string bundle_path,
@@ -519,6 +545,15 @@ bool WaylandDisplay::Run() {
519
545
// event loop
520
546
while (running && valid_) {
521
547
display.dispatch ();
548
+
549
+ if (!TaskRunner.empty ()) {
550
+ uint64_t current = FlutterEngineGetCurrentTime ();
551
+ if (current >= TaskRunner.top ().first ) {
552
+ auto item = TaskRunner.top ();
553
+ TaskRunner.pop ();
554
+ auto result = FlutterEngineRunTask (engine_, &item.second );
555
+ }
556
+ }
522
557
}
523
558
524
559
return true ;
@@ -572,6 +607,18 @@ bool WaylandDisplay::GLMakeResourceCurrent() {
572
607
eglresourcecontext) == EGL_TRUE);
573
608
}
574
609
610
+ bool WaylandDisplay::GLExternalTextureFrameCallback (
611
+ int64_t texture_id,
612
+ size_t width,
613
+ size_t height,
614
+ FlutterOpenGLTexture* texture) {
615
+ return true ;
616
+ }
617
+
618
+ void WaylandDisplay::PostTaskCallback (FlutterTask task, uint64_t target_time) {
619
+ TaskRunner.push (std::make_pair (target_time, task));
620
+ }
621
+
575
622
void WaylandDisplay::PlatformMessageCallback (
576
623
const FlutterPlatformMessage* message) {
577
624
FLWAY_LOG << " Channel: " << message->channel << std::endl;
0 commit comments