Flutter Engine
flutter_engine.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "include/flutter/flutter_engine.h"
6 
7 #include <algorithm>
8 #include <iostream>
9 
10 #include "binary_messenger_impl.h"
11 
12 namespace flutter {
13 
15  FlutterDesktopEngineProperties c_engine_properties = {};
16  c_engine_properties.assets_path = project.assets_path().c_str();
17  c_engine_properties.icu_data_path = project.icu_data_path().c_str();
18  c_engine_properties.aot_library_path = project.aot_library_path().c_str();
19 
20  engine_ = FlutterDesktopEngineCreate(c_engine_properties);
21 
22  auto core_messenger = FlutterDesktopEngineGetMessenger(engine_);
23  messenger_ = std::make_unique<BinaryMessengerImpl>(core_messenger);
24 }
25 
27  ShutDown();
28 }
29 
30 bool FlutterEngine::Run(const char* entry_point) {
31  if (!engine_) {
32  std::cerr << "Cannot run an engine that failed creation." << std::endl;
33  return false;
34  }
35  if (has_been_run_) {
36  std::cerr << "Cannot run an engine more than once." << std::endl;
37  return false;
38  }
39  bool run_succeeded = FlutterDesktopEngineRun(engine_, entry_point);
40  if (!run_succeeded) {
41  std::cerr << "Failed to start engine." << std::endl;
42  }
43  has_been_run_ = true;
44  return run_succeeded;
45 }
46 
48  if (engine_ && owns_engine_) {
50  }
51  engine_ = nullptr;
52 }
53 
54 std::chrono::nanoseconds FlutterEngine::ProcessMessages() {
55  return std::chrono::nanoseconds(FlutterDesktopEngineProcessMessages(engine_));
56 }
57 
60 }
61 
63  const std::string& plugin_name) {
64  if (!engine_) {
65  std::cerr << "Cannot get plugin registrar on an engine that isn't running; "
66  "call Run first."
67  << std::endl;
68  return nullptr;
69  }
70  return FlutterDesktopEngineGetPluginRegistrar(engine_, plugin_name.c_str());
71 }
72 
73 FlutterDesktopEngineRef FlutterEngine::RelinquishEngine() {
74  owns_engine_ = false;
75  return engine_;
76 }
77 
78 } // namespace flutter
FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin(const std::string &plugin_name) override
void FlutterDesktopEngineReloadSystemFonts(FlutterDesktopEngineRef engine)
bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine_ref)
bool Run(const char *entry_point=nullptr)
uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine)
FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger(FlutterDesktopEngineRef engine)
FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(FlutterDesktopEngineRef engine, const char *plugin_name)
std::chrono::nanoseconds ProcessMessages()
FlutterDesktopEngineRef FlutterDesktopEngineCreate(const FlutterDesktopEngineProperties &engine_properties)
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char *entry_point)