Skip to content

Consider adding Windows plugin API to post tasks to main thread #79213

@stuartmorgan-g

Description

@stuartmorgan-g

There are plugin APIs that can only be called from the main thread, but there's not a particularly good way for Windows plugins to move calls to that thread AFAIK. Options include:

  • Each plugin doing the hidden-window message loop implementation themselves.
  • Using the top-level window proc override registration to send themselves a custom message and hope nobody else uses it in a way that interferes.

This came up in the Texture PR and the solution there was to make most of it thread-safe; applying that more broadly is another option (e.g., to event streams). But a generic way to move things to the main thread would avoid needing to make lots of thread-safe APIs.

Proposed API:

class FlutterEngine : public PluginRegistry {

  // ...

  // Schedule a callback to be called on the platform thread.
  //
  // This may be called on any thread. The callback is executed only
  // once on the platform thread.
  void PostPlatformThreadTask(std::function<void()> callback);
}
// Schedule a callback to be invoked on the engine's platform thread.
//
// This may be called on any thread. The callback is executed only
// once on the platform thread.
FLUTTER_EXPORT void FlutterDesktopEnginePostPlatformThreadTask(
    FlutterDesktopEngineRef engine,
    VoidCallback callback,
    void* user_data);

/cc @cbracken

(We would only do one of #134346 and this.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projecta: desktopRunning on desktopa: pluginsSupport for writing, building, and running plugin packagesc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterengineflutter/engine related. See also e: labels.good first issueRelatively approachable for first-time contributorsplatform-windowsBuilding on or for Windows specificallyteam-windowsOwned by the Windows platform teamtriaged-windowsTriaged by the Windows platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions