mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Embedders may use this to specify a thread whose event loop is managed by them
instead of the engine. In addition, specifying the same task runner for both
the platform and render task runners allows embedders to effectively perform
GPU rendering operations on the platform thread.
To affect this change, the following non breaking changes to the API have been
made:
* The `FlutterCustomTaskRunners` struct now has a new field `render_task_runner`
for the specification of a custom render task runner.
* The `FlutterTaskRunnerDescription` has a new field `identifier`. Embedders
must supply a unique identifier for each task runner they specify. In
addition, when describing multiple task runners that run their tasks on the
same thread, their identifiers must match.
* The embedder may need to process tasks during `FlutterEngineRun` and
`FlutterEngineShutdown`. However, the embedder doesn't have the Flutter engine
handle before `FlutterEngineRun` and is supposed to relinquish handle right
before `FlutterEngineShutdown`. Since the embedder needs the Flutter engine
handle to service tasks on other threads while these calls are underway,
there exist opportunities for deadlock. To work around this scenario, three
new calls have been added that allow more deliberate management of the Flutter
engine instance.
* `FlutterEngineRun` can be replaced with `FlutterEngineInitialize` and
`FlutterEngineRunInitialized`. The embedder can obtain a handle to the
engine after the first call but the engine will not post any tasks to custom
task runners specified by the embedder till the
`FlutterEngineRunInitialized` call. Embedders can guard the Flutter engine
handle behind a mutex for safe task runner interop.
* `FlutterEngineShutdown` can be preceded by the `FlutterEngineDeinitialize`
call. After this call the Flutter engine will no longer post tasks onto
embedder managed task runners. It is still embedder responsibility to
collect the Flutter engine handle via `FlutterEngineShutdown`.
* To maintain backwards compatibility with the old APIs, `FlutterEngineRun` is
now just a convenience for `FlutterEngineInitialize` and
`FlutterEngineRunInitilaized`. `FlutterEngineShutdown` now implicitly calls
`FlutterEngineDeinitialize` as well. This allows existing users who don't care
are custom task runner interop to keep using the old APIs.
* Adds complete test coverage for both old and new paths.
Fixes https://github.com/flutter/flutter/issues/42460
Prerequisite for https://github.com/flutter/flutter/issues/17579
98 lines
2.8 KiB
C++
98 lines
2.8 KiB
C++
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_ENGINE_H_
|
|
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_ENGINE_H_
|
|
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
|
|
#include "flutter/fml/macros.h"
|
|
#include "flutter/shell/common/shell.h"
|
|
#include "flutter/shell/common/thread_host.h"
|
|
#include "flutter/shell/platform/embedder/embedder.h"
|
|
#include "flutter/shell/platform/embedder/embedder_engine.h"
|
|
#include "flutter/shell/platform/embedder/embedder_external_texture_gl.h"
|
|
#include "flutter/shell/platform/embedder/embedder_thread_host.h"
|
|
|
|
namespace flutter {
|
|
|
|
struct ShellArgs;
|
|
|
|
// The object that is returned to the embedder as an opaque pointer to the
|
|
// instance of the Flutter engine.
|
|
class EmbedderEngine {
|
|
public:
|
|
EmbedderEngine(std::unique_ptr<EmbedderThreadHost> thread_host,
|
|
TaskRunners task_runners,
|
|
Settings settings,
|
|
RunConfiguration run_configuration,
|
|
Shell::CreateCallback<PlatformView> on_create_platform_view,
|
|
Shell::CreateCallback<Rasterizer> on_create_rasterizer,
|
|
EmbedderExternalTextureGL::ExternalTextureCallback
|
|
external_texture_callback);
|
|
|
|
~EmbedderEngine();
|
|
|
|
bool LaunchShell();
|
|
|
|
bool CollectShell();
|
|
|
|
const TaskRunners& GetTaskRunners() const;
|
|
|
|
bool NotifyCreated();
|
|
|
|
bool NotifyDestroyed();
|
|
|
|
bool RunRootIsolate();
|
|
|
|
bool IsValid() const;
|
|
|
|
bool SetViewportMetrics(flutter::ViewportMetrics metrics);
|
|
|
|
bool DispatchPointerDataPacket(
|
|
std::unique_ptr<flutter::PointerDataPacket> packet);
|
|
|
|
bool SendPlatformMessage(fml::RefPtr<flutter::PlatformMessage> message);
|
|
|
|
bool RegisterTexture(int64_t texture);
|
|
|
|
bool UnregisterTexture(int64_t texture);
|
|
|
|
bool MarkTextureFrameAvailable(int64_t texture);
|
|
|
|
bool SetSemanticsEnabled(bool enabled);
|
|
|
|
bool SetAccessibilityFeatures(int32_t flags);
|
|
|
|
bool DispatchSemanticsAction(int id,
|
|
flutter::SemanticsAction action,
|
|
std::vector<uint8_t> args);
|
|
|
|
bool OnVsyncEvent(intptr_t baton,
|
|
fml::TimePoint frame_start_time,
|
|
fml::TimePoint frame_target_time);
|
|
|
|
bool ReloadSystemFonts();
|
|
|
|
bool PostRenderThreadTask(fml::closure task);
|
|
|
|
bool RunTask(const FlutterTask* task);
|
|
|
|
private:
|
|
const std::unique_ptr<EmbedderThreadHost> thread_host_;
|
|
TaskRunners task_runners_;
|
|
RunConfiguration run_configuration_;
|
|
std::unique_ptr<ShellArgs> shell_args_;
|
|
std::unique_ptr<Shell> shell_;
|
|
const EmbedderExternalTextureGL::ExternalTextureCallback
|
|
external_texture_callback_;
|
|
|
|
FML_DISALLOW_COPY_AND_ASSIGN(EmbedderEngine);
|
|
};
|
|
|
|
} // namespace flutter
|
|
|
|
#endif // FLUTTER_SHELL_PLATFORM_EMBEDDER_EMBEDDER_ENGINE_H_
|