2018-11-07 12:24:35 -08:00
|
|
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
2015-05-18 14:48:27 -07:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
2016-08-13 00:18:58 -07:00
|
|
|
#ifndef FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_
|
|
|
|
|
#define FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_
|
2015-05-18 14:48:27 -07:00
|
|
|
|
|
|
|
|
#include <memory>
|
2018-10-17 10:53:01 -07:00
|
|
|
#include <vector>
|
2015-05-21 12:46:36 -07:00
|
|
|
|
2018-04-13 13:48:15 -07:00
|
|
|
#include "flutter/common/task_runners.h"
|
2016-08-09 12:48:29 -07:00
|
|
|
#include "flutter/flow/layers/layer_tree.h"
|
2018-07-26 12:49:34 -07:00
|
|
|
#include "flutter/fml/macros.h"
|
2019-01-14 13:46:38 -08:00
|
|
|
#include "flutter/lib/ui/io_manager.h"
|
2018-06-13 14:28:21 -07:00
|
|
|
#include "flutter/lib/ui/text/font_collection.h"
|
2018-07-16 09:04:20 -07:00
|
|
|
#include "flutter/lib/ui/ui_dart_state.h"
|
2016-09-28 15:50:09 -07:00
|
|
|
#include "flutter/lib/ui/window/pointer_data_packet.h"
|
2016-08-12 16:12:07 -07:00
|
|
|
#include "flutter/lib/ui/window/window.h"
|
2018-04-13 13:48:15 -07:00
|
|
|
#include "flutter/runtime/dart_vm.h"
|
2018-10-17 10:53:01 -07:00
|
|
|
#include "rapidjson/document.h"
|
|
|
|
|
#include "rapidjson/stringbuffer.h"
|
2015-05-18 14:48:27 -07:00
|
|
|
|
2019-04-09 12:44:42 -07:00
|
|
|
namespace flutter {
|
2015-10-25 00:33:41 -07:00
|
|
|
class Scene;
|
2016-08-13 00:18:58 -07:00
|
|
|
class RuntimeDelegate;
|
2015-06-25 13:59:22 -07:00
|
|
|
class View;
|
2015-10-25 00:33:41 -07:00
|
|
|
class Window;
|
2015-05-18 14:48:27 -07:00
|
|
|
|
2018-04-13 13:48:15 -07:00
|
|
|
class RuntimeController final : public WindowClient {
|
2015-05-18 14:48:27 -07:00
|
|
|
public:
|
2019-10-10 12:31:14 -07:00
|
|
|
RuntimeController(
|
|
|
|
|
RuntimeDelegate& client,
|
|
|
|
|
DartVM* vm,
|
|
|
|
|
fml::RefPtr<const DartSnapshot> isolate_snapshot,
|
|
|
|
|
TaskRunners task_runners,
|
2019-10-31 16:57:52 -07:00
|
|
|
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
|
2019-10-10 12:31:14 -07:00
|
|
|
fml::WeakPtr<IOManager> io_manager,
|
2019-10-21 14:15:03 -07:00
|
|
|
fml::RefPtr<SkiaUnrefQueue> unref_queue,
|
|
|
|
|
fml::WeakPtr<ImageDecoder> image_decoder,
|
2019-10-10 12:31:14 -07:00
|
|
|
std::string advisory_script_uri,
|
|
|
|
|
std::string advisory_script_entrypoint,
|
2019-11-22 12:20:02 -08:00
|
|
|
const std::function<void(int64_t)>& idle_notification_callback,
|
|
|
|
|
const fml::closure& isolate_create_callback,
|
|
|
|
|
const fml::closure& isolate_shutdown_callback,
|
2019-10-10 12:31:14 -07:00
|
|
|
std::shared_ptr<const fml::Mapping> persistent_isolate_data);
|
2018-04-13 13:48:15 -07:00
|
|
|
|
2018-11-12 19:59:29 -08:00
|
|
|
~RuntimeController() override;
|
2016-08-13 00:18:58 -07:00
|
|
|
|
2018-04-13 13:48:15 -07:00
|
|
|
std::unique_ptr<RuntimeController> Clone() const;
|
2015-05-18 14:48:27 -07:00
|
|
|
|
2018-04-13 13:48:15 -07:00
|
|
|
bool SetViewportMetrics(const ViewportMetrics& metrics);
|
|
|
|
|
|
2018-10-17 10:53:01 -07:00
|
|
|
bool SetLocales(const std::vector<std::string>& locale_data);
|
2015-09-03 13:32:44 -07:00
|
|
|
|
2018-04-13 13:48:15 -07:00
|
|
|
bool SetUserSettingsData(const std::string& data);
|
2015-05-21 12:46:36 -07:00
|
|
|
|
2019-03-06 15:38:34 -08:00
|
|
|
bool SetLifecycleState(const std::string& data);
|
|
|
|
|
|
2018-04-13 13:48:15 -07:00
|
|
|
bool SetSemanticsEnabled(bool enabled);
|
|
|
|
|
|
2018-07-31 18:18:19 -07:00
|
|
|
bool SetAccessibilityFeatures(int32_t flags);
|
2018-07-16 09:04:20 -07:00
|
|
|
|
2018-07-26 12:49:34 -07:00
|
|
|
bool BeginFrame(fml::TimePoint frame_time);
|
2018-04-13 13:48:15 -07:00
|
|
|
|
2019-06-06 10:42:48 -07:00
|
|
|
bool ReportTimings(std::vector<int64_t> timings);
|
|
|
|
|
|
2018-04-13 13:48:15 -07:00
|
|
|
bool NotifyIdle(int64_t deadline);
|
|
|
|
|
|
2018-04-17 17:10:17 -07:00
|
|
|
bool IsRootIsolateRunning() const;
|
|
|
|
|
|
2018-07-26 12:49:34 -07:00
|
|
|
bool DispatchPlatformMessage(fml::RefPtr<PlatformMessage> message);
|
2018-04-13 13:48:15 -07:00
|
|
|
|
|
|
|
|
bool DispatchPointerDataPacket(const PointerDataPacket& packet);
|
|
|
|
|
|
|
|
|
|
bool DispatchSemanticsAction(int32_t id,
|
2017-12-12 14:25:45 -08:00
|
|
|
SemanticsAction action,
|
|
|
|
|
std::vector<uint8_t> args);
|
2015-05-18 14:48:27 -07:00
|
|
|
|
2016-08-08 13:04:15 -07:00
|
|
|
Dart_Port GetMainPort();
|
2018-04-13 13:48:15 -07:00
|
|
|
|
2016-08-16 12:16:41 -07:00
|
|
|
std::string GetIsolateName();
|
2018-04-13 13:48:15 -07:00
|
|
|
|
2017-01-24 15:39:30 -08:00
|
|
|
bool HasLivePorts();
|
2018-04-13 13:48:15 -07:00
|
|
|
|
2017-01-27 09:59:08 -08:00
|
|
|
tonic::DartErrorHandleType GetLastError();
|
2017-01-24 15:39:30 -08:00
|
|
|
|
2018-07-23 11:49:35 -07:00
|
|
|
std::weak_ptr<DartIsolate> GetRootIsolate();
|
2018-04-13 13:48:15 -07:00
|
|
|
|
|
|
|
|
std::pair<bool, uint32_t> GetRootIsolateReturnCode();
|
|
|
|
|
|
2015-05-18 14:48:27 -07:00
|
|
|
private:
|
2018-10-17 10:53:01 -07:00
|
|
|
struct Locale {
|
|
|
|
|
Locale(std::string language_code_,
|
|
|
|
|
std::string country_code_,
|
|
|
|
|
std::string script_code_,
|
2018-11-12 19:59:29 -08:00
|
|
|
std::string variant_code_);
|
|
|
|
|
|
|
|
|
|
~Locale();
|
2018-10-17 10:53:01 -07:00
|
|
|
|
|
|
|
|
std::string language_code;
|
|
|
|
|
std::string country_code;
|
|
|
|
|
std::string script_code;
|
|
|
|
|
std::string variant_code;
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-12 17:25:56 -08:00
|
|
|
// Stores data about the window to be used at startup
|
|
|
|
|
// as well as on hot restarts. Data kept here will persist
|
|
|
|
|
// after hot restart.
|
2018-04-13 13:48:15 -07:00
|
|
|
struct WindowData {
|
2018-11-12 19:59:29 -08:00
|
|
|
WindowData();
|
|
|
|
|
|
|
|
|
|
WindowData(const WindowData& other);
|
|
|
|
|
|
|
|
|
|
~WindowData();
|
|
|
|
|
|
2018-04-13 13:48:15 -07:00
|
|
|
ViewportMetrics viewport_metrics;
|
|
|
|
|
std::string language_code;
|
|
|
|
|
std::string country_code;
|
2018-10-10 17:22:59 -07:00
|
|
|
std::string script_code;
|
|
|
|
|
std::string variant_code;
|
2018-10-17 10:53:01 -07:00
|
|
|
std::vector<std::string> locale_data;
|
2018-04-13 13:48:15 -07:00
|
|
|
std::string user_settings_data = "{}";
|
2019-11-13 11:26:25 -08:00
|
|
|
std::string lifecycle_state = "AppLifecycleState.detached";
|
2018-04-13 13:48:15 -07:00
|
|
|
bool semantics_enabled = false;
|
2018-07-16 09:04:20 -07:00
|
|
|
bool assistive_technology_enabled = false;
|
2018-07-31 18:18:19 -07:00
|
|
|
int32_t accessibility_feature_flags_ = 0;
|
2018-04-13 13:48:15 -07:00
|
|
|
};
|
2015-05-19 10:55:07 -07:00
|
|
|
|
2018-04-13 13:48:15 -07:00
|
|
|
RuntimeDelegate& client_;
|
2018-06-13 11:57:10 -07:00
|
|
|
DartVM* const vm_;
|
2019-04-03 13:38:12 -07:00
|
|
|
fml::RefPtr<const DartSnapshot> isolate_snapshot_;
|
2018-04-13 13:48:15 -07:00
|
|
|
TaskRunners task_runners_;
|
2019-10-31 16:57:52 -07:00
|
|
|
fml::WeakPtr<SnapshotDelegate> snapshot_delegate_;
|
2019-01-14 13:46:38 -08:00
|
|
|
fml::WeakPtr<IOManager> io_manager_;
|
2019-10-21 14:15:03 -07:00
|
|
|
fml::RefPtr<SkiaUnrefQueue> unref_queue_;
|
2019-07-09 14:59:34 -07:00
|
|
|
fml::WeakPtr<ImageDecoder> image_decoder_;
|
2018-05-29 15:10:12 -07:00
|
|
|
std::string advisory_script_uri_;
|
|
|
|
|
std::string advisory_script_entrypoint_;
|
2019-01-10 14:08:43 -08:00
|
|
|
std::function<void(int64_t)> idle_notification_callback_;
|
2018-04-13 13:48:15 -07:00
|
|
|
WindowData window_data_;
|
2018-07-23 11:49:35 -07:00
|
|
|
std::weak_ptr<DartIsolate> root_isolate_;
|
2018-04-13 13:48:15 -07:00
|
|
|
std::pair<bool, uint32_t> root_isolate_return_code_ = {false, 0};
|
2019-04-19 17:36:36 -07:00
|
|
|
const fml::closure isolate_create_callback_;
|
|
|
|
|
const fml::closure isolate_shutdown_callback_;
|
2019-10-10 12:31:14 -07:00
|
|
|
std::shared_ptr<const fml::Mapping> persistent_isolate_data_;
|
2015-10-25 00:33:41 -07:00
|
|
|
|
2019-10-10 12:31:14 -07:00
|
|
|
RuntimeController(
|
|
|
|
|
RuntimeDelegate& client,
|
|
|
|
|
DartVM* vm,
|
|
|
|
|
fml::RefPtr<const DartSnapshot> isolate_snapshot,
|
|
|
|
|
TaskRunners task_runners,
|
2019-10-31 16:57:52 -07:00
|
|
|
fml::WeakPtr<SnapshotDelegate> snapshot_delegate,
|
2019-10-10 12:31:14 -07:00
|
|
|
fml::WeakPtr<IOManager> io_manager,
|
2019-10-21 14:15:03 -07:00
|
|
|
fml::RefPtr<SkiaUnrefQueue> unref_queue,
|
2019-10-10 12:31:14 -07:00
|
|
|
fml::WeakPtr<ImageDecoder> image_decoder,
|
|
|
|
|
std::string advisory_script_uri,
|
|
|
|
|
std::string advisory_script_entrypoint,
|
2019-11-22 12:20:02 -08:00
|
|
|
const std::function<void(int64_t)>& idle_notification_callback,
|
2019-10-10 12:31:14 -07:00
|
|
|
WindowData data,
|
2019-11-22 12:20:02 -08:00
|
|
|
const fml::closure& isolate_create_callback,
|
|
|
|
|
const fml::closure& isolate_shutdown_callback,
|
2019-10-10 12:31:14 -07:00
|
|
|
std::shared_ptr<const fml::Mapping> persistent_isolate_data);
|
2018-04-13 13:48:15 -07:00
|
|
|
|
|
|
|
|
Window* GetWindowIfAvailable();
|
|
|
|
|
|
|
|
|
|
bool FlushRuntimeStateToIsolate();
|
|
|
|
|
|
2019-04-09 17:50:06 -07:00
|
|
|
// |WindowClient|
|
2017-06-06 10:59:41 +02:00
|
|
|
std::string DefaultRouteName() override;
|
2018-04-13 13:48:15 -07:00
|
|
|
|
2019-04-09 17:50:06 -07:00
|
|
|
// |WindowClient|
|
2015-10-25 00:33:41 -07:00
|
|
|
void ScheduleFrame() override;
|
2018-04-13 13:48:15 -07:00
|
|
|
|
2019-04-09 17:50:06 -07:00
|
|
|
// |WindowClient|
|
2015-10-25 00:33:41 -07:00
|
|
|
void Render(Scene* scene) override;
|
2018-04-13 13:48:15 -07:00
|
|
|
|
2019-04-09 17:50:06 -07:00
|
|
|
// |WindowClient|
|
2016-10-05 12:22:03 -07:00
|
|
|
void UpdateSemantics(SemanticsUpdate* update) override;
|
2018-04-13 13:48:15 -07:00
|
|
|
|
2019-04-09 17:50:06 -07:00
|
|
|
// |WindowClient|
|
2018-07-26 12:49:34 -07:00
|
|
|
void HandlePlatformMessage(fml::RefPtr<PlatformMessage> message) override;
|
2015-05-19 14:20:04 -07:00
|
|
|
|
2019-04-09 17:50:06 -07:00
|
|
|
// |WindowClient|
|
2018-11-16 14:47:40 -08:00
|
|
|
FontCollection& GetFontCollection() override;
|
2018-10-18 14:47:24 -07:00
|
|
|
|
2019-04-09 17:50:06 -07:00
|
|
|
// |WindowClient|
|
2018-11-16 14:47:40 -08:00
|
|
|
void UpdateIsolateDescription(const std::string isolate_name,
|
|
|
|
|
int64_t isolate_port) override;
|
2018-06-13 14:28:21 -07:00
|
|
|
|
2019-06-06 10:42:48 -07:00
|
|
|
// |WindowClient|
|
|
|
|
|
void SetNeedsReportTimings(bool value) override;
|
|
|
|
|
|
2019-10-10 12:31:14 -07:00
|
|
|
// |WindowClient|
|
|
|
|
|
std::shared_ptr<const fml::Mapping> GetPersistentIsolateData() override;
|
|
|
|
|
|
2018-07-26 12:49:34 -07:00
|
|
|
FML_DISALLOW_COPY_AND_ASSIGN(RuntimeController);
|
2015-05-18 14:48:27 -07:00
|
|
|
};
|
|
|
|
|
|
2019-04-09 12:44:42 -07:00
|
|
|
} // namespace flutter
|
2015-05-18 14:48:27 -07:00
|
|
|
|
2016-08-13 00:18:58 -07:00
|
|
|
#endif // FLUTTER_RUNTIME_RUNTIME_CONTROLLER_H_
|