mirror of
https://github.com/encounter/engine.git
synced 2026-03-30 11:09:55 -07:00
ec19da1c80
* Read core platform kernel file during Dart initialization. Currently service isolate is initialized from the source code parsed by VM. This CL changes it so service isolate created during Dart initialization is created from the kernel platform.dill file if it is present in the application bundle. Then this platform kernel file is kept in dart_init module and reused for application sciprt isolates. * Reformat and merge * Use accessor method * Avoid passing running_from_kernel param. Add TODO for cleanup. Rename param.
72 lines
2.3 KiB
C++
72 lines
2.3 KiB
C++
// Copyright 2015 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "flutter/shell/platform/android/flutter_main.h"
|
|
|
|
#include <vector>
|
|
|
|
#include "flutter/fml/platform/android/jni_util.h"
|
|
#include "flutter/runtime/start_up.h"
|
|
#include "flutter/shell/common/shell.h"
|
|
#include "lib/fxl/arraysize.h"
|
|
#include "lib/fxl/command_line.h"
|
|
#include "lib/fxl/macros.h"
|
|
#include "third_party/dart/runtime/include/dart_tools_api.h"
|
|
|
|
namespace shell {
|
|
|
|
static void Init(JNIEnv* env,
|
|
jclass clazz,
|
|
jobject context,
|
|
jobjectArray jargs,
|
|
jstring bundlePath) {
|
|
// Prepare command line arguments and initialize the shell.
|
|
std::vector<std::string> args;
|
|
args.push_back("flutter_tester");
|
|
for (auto& arg : fml::jni::StringArrayToVector(env, jargs)) {
|
|
args.push_back(std::move(arg));
|
|
}
|
|
|
|
auto command_line = fxl::CommandLineFromIterators(args.begin(), args.end());
|
|
std::string icu_data_path =
|
|
command_line.GetOptionValueWithDefault("icu-data-file-path", "");
|
|
Shell::InitStandalone(std::move(command_line), std::move(icu_data_path),
|
|
/* application_library_path= */ "",
|
|
fml::jni::JavaStringToString(env, bundlePath));
|
|
}
|
|
|
|
static void RecordStartTimestamp(JNIEnv* env,
|
|
jclass jcaller,
|
|
jlong initTimeMillis) {
|
|
int64_t initTimeMicros =
|
|
static_cast<int64_t>(initTimeMillis) * static_cast<int64_t>(1000);
|
|
blink::engine_main_enter_ts = Dart_TimelineGetMicros() - initTimeMicros;
|
|
}
|
|
|
|
bool RegisterFlutterMain(JNIEnv* env) {
|
|
static const JNINativeMethod methods[] = {
|
|
{
|
|
.name = "nativeInit",
|
|
.signature = "(Landroid/content/Context;[Ljava/lang/String;Ljava/"
|
|
"lang/String;)V",
|
|
.fnPtr = reinterpret_cast<void*>(&Init),
|
|
},
|
|
{
|
|
.name = "nativeRecordStartTimestamp",
|
|
.signature = "(J)V",
|
|
.fnPtr = reinterpret_cast<void*>(&RecordStartTimestamp),
|
|
},
|
|
};
|
|
|
|
jclass clazz = env->FindClass("io/flutter/view/FlutterMain");
|
|
|
|
if (clazz == nullptr) {
|
|
return false;
|
|
}
|
|
|
|
return env->RegisterNatives(clazz, methods, arraysize(methods)) == 0;
|
|
}
|
|
|
|
} // namespace shell
|