Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions shell/platform/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -902,3 +902,18 @@ void FlutterEngineTraceEventDurationEnd(const char* name) {
void FlutterEngineTraceEventInstant(const char* name) {
fml::tracing::TraceEventInstant0("flutter", name);
}

FlutterEngineResult FlutterEnginePostRenderThreadTask(FlutterEngine engine,
VoidCallback callback,
void* baton) {
if (engine == nullptr || callback == nullptr) {
return kInvalidArguments;
}

auto task = [callback, baton]() { callback(baton); };

return reinterpret_cast<shell::EmbedderEngine*>(engine)->PostRenderThreadTask(
task)
? kSuccess
: kInternalInconsistency;
}
8 changes: 8 additions & 0 deletions shell/platform/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,14 @@ void FlutterEngineTraceEventDurationEnd(const char* name);
FLUTTER_EXPORT
void FlutterEngineTraceEventInstant(const char* name);

// Posts a task onto the Flutter render thread. Typically, this may be called
// from any thread as long as a |FlutterEngineShutdown| on the specific engine
// has not already been initiated.
FLUTTER_EXPORT
FlutterEngineResult FlutterEnginePostRenderThreadTask(FlutterEngine engine,
VoidCallback callback,
void* callback_data);

#if defined(__cplusplus)
} // extern "C"
#endif
Expand Down
9 changes: 9 additions & 0 deletions shell/platform/embedder/embedder_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,13 @@ bool EmbedderEngine::OnVsyncEvent(intptr_t baton,
frame_target_time);
}

bool EmbedderEngine::PostRenderThreadTask(fml::closure task) {
if (!IsValid()) {
return false;
}

shell_->GetTaskRunners().GetGPUTaskRunner()->PostTask(task);
return true;
}

} // namespace shell
2 changes: 2 additions & 0 deletions shell/platform/embedder/embedder_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class EmbedderEngine {
fml::TimePoint frame_start_time,
fml::TimePoint frame_target_time);

bool PostRenderThreadTask(fml::closure task);

private:
const ThreadHost thread_host_;
std::unique_ptr<Shell> shell_;
Expand Down