提交 12fab2f2 编写于 作者: A Adam Barth 提交者: GitHub

Move dart:jni to //flutter/lib/jni (#2744)

This patch disentangles dart:jni from //sky/engine and moves it into
//flutter/lib/jni. Eventually dart:ui will move into a peer directory.
上级 fabd183e
# Copyright 2016 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.
source_set("jni") {
sources = [
"dart_jni.cc",
"dart_jni.h",
"jni_api.cc",
"jni_api.h",
"jni_array.cc",
"jni_array.h",
"jni_class.cc",
"jni_class.h",
"jni_object.cc",
"jni_object.h",
"jni_string.cc",
"jni_string.h",
]
deps = [
"//base",
"//flutter/tonic",
]
}
......@@ -2,20 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/bindings/jni/dart_jni.h"
#include "flutter/lib/jni/dart_jni.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/logging.h"
#include "flutter/lib/jni/jni_api.h"
#include "flutter/lib/jni/jni_array.h"
#include "flutter/lib/jni/jni_class.h"
#include "flutter/lib/jni/jni_object.h"
#include "flutter/lib/jni/jni_string.h"
#include "flutter/tonic/dart_args.h"
#include "flutter/tonic/dart_binding_macros.h"
#include "flutter/tonic/dart_converter.h"
#include "sky/engine/bindings/flutter_dart_state.h"
#include "sky/engine/bindings/jni/jni_api.h"
#include "sky/engine/bindings/jni/jni_array.h"
#include "sky/engine/bindings/jni/jni_class.h"
#include "sky/engine/bindings/jni/jni_object.h"
#include "sky/engine/bindings/jni/jni_string.h"
namespace blink {
......@@ -45,14 +45,10 @@ struct DartJniJvmData {
};
DartJniJvmData* g_jvm_data = nullptr;
void CreateIsolateData() {
static_cast<FlutterDartState*>(DartState::Current())->set_jni_data(
std::unique_ptr<DartJniIsolateData>(new DartJniIsolateData()));
}
DartJniIsolateDataProvider g_isolate_data_provider = nullptr;
DartJniIsolateData* IsolateData() {
return static_cast<FlutterDartState*>(DartState::Current())->jni_data();
return g_isolate_data_provider();
}
} // anonymous namespace
......@@ -185,7 +181,10 @@ DART_NATIVE_CALLBACK_STATIC(JniString, Create);
FOR_EACH_BINDING(DART_NATIVE_CALLBACK)
void DartJni::InitForGlobal() {
void DartJni::InitForGlobal(DartJniIsolateDataProvider provider) {
if (!g_isolate_data_provider)
g_isolate_data_provider = provider;
if (!g_natives) {
g_natives = new DartLibraryNatives();
......@@ -220,8 +219,6 @@ void DartJni::InitForIsolate() {
DART_CHECK_VALID(Dart_SetNativeResolver(
jni_library, GetNativeFunction, GetSymbol));
CreateIsolateData();
Dart_Handle object_type = Dart_GetType(
jni_library, ToDart("JniObject"), 0, nullptr);
DART_CHECK_VALID(object_type);
......
# Copyright 2016 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.
dart_jni_files = [
"//flutter/lib/jni/jni_helper.dart",
"//flutter/lib/jni/jni_raw.dart",
"//flutter/lib/jni/jni.dart",
]
dart_jni_path = "//flutter/lib/jni/jni.dart"
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_BINDINGS_JNI_DART_JNI_H_
#define SKY_ENGINE_BINDINGS_JNI_DART_JNI_H_
#ifndef FLUTTER_LIB_JNI_DART_JNI_H_
#define FLUTTER_LIB_JNI_DART_JNI_H_
#include <vector>
......@@ -22,9 +22,17 @@ namespace blink {
bool CheckJniException(JNIEnv* env, Dart_Handle *exception);
bool CheckDartException(Dart_Handle result, Dart_Handle* exception);
// Data cached for each Dart isolate.
struct DartJniIsolateData {
Dart_PersistentHandle jni_object_type;
Dart_PersistentHandle jni_float_type;
};
typedef DartJniIsolateData* (*DartJniIsolateDataProvider)();
class DartJni {
public:
static void InitForGlobal();
static void InitForGlobal(DartJniIsolateDataProvider provider);
static void InitForIsolate();
static bool InitJni();
static void OnThreadExit();
......@@ -43,12 +51,6 @@ class DartJni {
static Dart_Handle jni_float_type();
};
// Data cached for each Dart isolate.
struct DartJniIsolateData {
Dart_PersistentHandle jni_object_type;
Dart_PersistentHandle jni_float_type;
};
class JniMethodArgs {
public:
void Convert(JNIEnv* env,
......@@ -92,4 +94,4 @@ struct DartConverter<jmethodID> {
} // namespace blink
#endif // SKY_ENGINE_BINDINGS_JNI_DART_JNI_H_
#endif // FLUTTER_LIB_JNI_DART_JNI_H_
......@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/bindings/jni/jni_api.h"
#include "flutter/lib/jni/jni_api.h"
#include "sky/engine/bindings/jni/dart_jni.h"
#include "flutter/lib/jni/dart_jni.h"
namespace blink {
......
......@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_BINDINGS_JNI_JNI_API_H_
#define SKY_ENGINE_BINDINGS_JNI_JNI_API_H_
#ifndef FLUTTER_LIB_JNI_JNI_API_H_
#define FLUTTER_LIB_JNI_JNI_API_H_
#include "sky/engine/bindings/jni/jni_class.h"
#include "sky/engine/bindings/jni/jni_object.h"
#include "flutter/lib/jni/jni_class.h"
#include "flutter/lib/jni/jni_object.h"
namespace blink {
......@@ -21,4 +21,4 @@ class JniApi {
} // namespace blink
#endif // SKY_ENGINE_BINDINGS_JNI_JNI_API_H_
#endif // FLUTTER_LIB_JNI_JNI_API_H_
......@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/bindings/jni/jni_array.h"
#include "flutter/lib/jni/jni_array.h"
#include "sky/engine/bindings/jni/dart_jni.h"
#include "flutter/lib/jni/dart_jni.h"
namespace blink {
......
......@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_BINDINGS_JNI_JNI_ARRAY_H_
#define SKY_ENGINE_BINDINGS_JNI_JNI_ARRAY_H_
#ifndef FLUTTER_LIB_JNI_JNI_ARRAY_H_
#define FLUTTER_LIB_JNI_JNI_ARRAY_H_
#include <jni.h>
#include "sky/engine/bindings/jni/jni_class.h"
#include "sky/engine/bindings/jni/jni_object.h"
#include "flutter/lib/jni/jni_class.h"
#include "flutter/lib/jni/jni_object.h"
namespace blink {
......@@ -163,4 +163,4 @@ class JniDoubleArray : public JniArray {
} // namespace blink
#endif // SKY_ENGINE_BINDINGS_JNI_JNI_ARRAY_H_
#endif // FLUTTER_LIB_JNI_JNI_ARRAY_H_
......@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/bindings/jni/jni_class.h"
#include "flutter/lib/jni/jni_class.h"
#include "sky/engine/bindings/jni/dart_jni.h"
#include "flutter/lib/jni/dart_jni.h"
namespace blink {
......
......@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_BINDINGS_JNI_JNI_CLASS_H_
#define SKY_ENGINE_BINDINGS_JNI_JNI_CLASS_H_
#ifndef FLUTTER_LIB_JNI_JNI_CLASS_H_
#define FLUTTER_LIB_JNI_JNI_CLASS_H_
#include <jni.h>
#include "base/android/jni_android.h"
#include "base/memory/ref_counted.h"
#include "flutter/lib/jni/jni_object.h"
#include "flutter/tonic/dart_wrappable.h"
#include "sky/engine/bindings/jni/jni_object.h"
namespace blink {
......@@ -84,4 +84,4 @@ class JniClass : public JniObject {
} // namespace blink
#endif // SKY_ENGINE_BINDINGS_JNI_JNI_CLASS_H_
#endif // FLUTTER_LIB_JNI_JNI_CLASS_H_
......@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/bindings/jni/jni_object.h"
#include "flutter/lib/jni/jni_object.h"
#include "base/strings/string_util.h"
#include "sky/engine/bindings/jni/dart_jni.h"
#include "sky/engine/bindings/jni/jni_array.h"
#include "sky/engine/bindings/jni/jni_class.h"
#include "sky/engine/bindings/jni/jni_string.h"
#include "flutter/lib/jni/dart_jni.h"
#include "flutter/lib/jni/jni_array.h"
#include "flutter/lib/jni/jni_class.h"
#include "flutter/lib/jni/jni_string.h"
namespace blink {
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_BINDINGS_JNI_JNI_OBJECT_H_
#define SKY_ENGINE_BINDINGS_JNI_JNI_OBJECT_H_
#ifndef FLUTTER_LIB_JNI_JNI_OBJECT_H_
#define FLUTTER_LIB_JNI_JNI_OBJECT_H_
#include <jni.h>
......@@ -77,4 +77,4 @@ class JniObject : public base::RefCountedThreadSafe<JniObject>, public DartWrapp
} // namespace blink
#endif // SKY_ENGINE_BINDINGS_JNI_JNI_OBJECT_H_
#endif // FLUTTER_LIB_JNI_JNI_OBJECT_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sky/engine/bindings/jni/jni_string.h"
#include "flutter/lib/jni/jni_string.h"
namespace blink {
......
......@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SKY_ENGINE_BINDINGS_JNI_JNI_STRING_H_
#define SKY_ENGINE_BINDINGS_JNI_JNI_STRING_H_
#ifndef FLUTTER_LIB_JNI_JNI_STRING_H_
#define FLUTTER_LIB_JNI_JNI_STRING_H_
#include "sky/engine/bindings/jni/dart_jni.h"
#include "sky/engine/bindings/jni/jni_object.h"
#include "flutter/lib/jni/dart_jni.h"
#include "flutter/lib/jni/jni_object.h"
namespace blink {
......@@ -29,4 +29,4 @@ class JniString : public JniObject {
} // namespace blink
#endif // SKY_ENGINE_BINDINGS_JNI_JNI_STRING_H_
#endif // FLUTTER_LIB_JNI_JNI_STRING_H_
......@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//flutter/lib/jni/dart_jni.gni")
import("//mojo/dart/packages/mojo/sdk_ext_sources.gni")
import("//sky/engine/bindings/bindings.gni")
import("//sky/engine/core/core.gni")
......@@ -20,23 +21,6 @@ source_set("bindings") {
"mojo_services.h",
]
if (is_android) {
sources += [
"jni/dart_jni.cc",
"jni/dart_jni.h",
"jni/jni_api.cc",
"jni/jni_api.h",
"jni/jni_array.cc",
"jni/jni_array.h",
"jni/jni_class.cc",
"jni/jni_class.h",
"jni/jni_object.cc",
"jni/jni_object.h",
"jni/jni_string.cc",
"jni/jni_string.h",
]
}
defines = [ "DART_IO_SECURE_SOCKET_DISABLED" ]
deps = [
......@@ -58,6 +42,10 @@ source_set("bindings") {
"//sky/services/engine:interfaces",
]
if (is_android) {
deps += [ "//flutter/lib/jni" ]
}
# On iOS (device), precompiled snapshots contain the instruction buffer.
# Generation of the same requires all application specific script code to be
# specified up front. In such cases, there can be no updater or generic
......@@ -83,11 +71,9 @@ action("generate_snapshot_bin") {
]
inputs = [
"//dart/runtime/tools/create_snapshot_bin.py",
"//sky/engine/bindings/jni/jni.dart",
"//sky/engine/bindings/jni/jni_raw.dart",
"//sky/engine/bindings/jni/jni_helper.dart",
"snapshot.dart",
] + rebase_path(dart_mojo_internal_sdk_sources,
] + dart_jni_files
+ rebase_path(dart_mojo_internal_sdk_sources,
"",
"//mojo/dart/packages/mojo")
vm_isolate_snapshot = "$target_gen_dir/vm_isolate_snapshot.bin"
......@@ -99,8 +85,8 @@ action("generate_snapshot_bin") {
dart_mojo_internal_path =
rebase_path("//mojo/dart/packages/mojo/sdk_ext/internal.dart")
dart_ui_path = rebase_path("$bindings_output_dir/dart_ui.dart")
dart_jni_path = rebase_path("//sky/engine/bindings/jni/jni.dart")
rebased_dart_ui_path = rebase_path("$bindings_output_dir/dart_ui.dart")
rebased_dart_jni_path = rebase_path(dart_jni_path)
gen_snapshot_dir =
get_label_info("//dart/runtime/bin:gen_snapshot($dart_host_toolchain)",
......@@ -121,8 +107,8 @@ action("generate_snapshot_bin") {
"--target_os",
target_os,
"--url_mapping=dart:mojo.internal,$dart_mojo_internal_path",
"--url_mapping=dart:ui,$dart_ui_path",
"--url_mapping=dart:jni,$dart_jni_path",
"--url_mapping=dart:ui,$rebased_dart_ui_path",
"--url_mapping=dart:jni,$rebased_dart_jni_path",
]
}
......@@ -176,11 +162,7 @@ copy("generate_dart_ui") {
}
copy("generate_dart_jni") {
sources = [
"jni/jni.dart",
"jni/jni_helper.dart",
"jni/jni_raw.dart",
]
sources = dart_jni_files
outputs = [
"$bindings_output_dir/dart_jni/{{source_file_part}}",
......
......@@ -8,7 +8,7 @@
#include "sky/engine/bindings/mojo_services.h"
#ifdef OS_ANDROID
#include "sky/engine/bindings/jni/dart_jni.h"
#include "flutter/lib/jni/dart_jni.h"
#endif
namespace blink {
......@@ -19,6 +19,9 @@ IsolateClient::~IsolateClient() {
FlutterDartState::FlutterDartState(IsolateClient* isolate_client,
const std::string& url)
: isolate_client_(isolate_client), url_(url) {
#ifdef OS_ANDROID
jni_data_.reset(new DartJniIsolateData());
#endif
}
FlutterDartState::~FlutterDartState() {
......@@ -58,11 +61,6 @@ MojoServices* FlutterDartState::mojo_services() {
}
#ifdef OS_ANDROID
void FlutterDartState::set_jni_data(
std::unique_ptr<DartJniIsolateData> jni_data) {
jni_data_ = std::move(jni_data);
}
DartJniIsolateData* FlutterDartState::jni_data() {
return jni_data_.get();
}
......
......@@ -48,7 +48,6 @@ class FlutterDartState : public DartState {
MojoServices* mojo_services();
#ifdef OS_ANDROID
void set_jni_data(std::unique_ptr<DartJniIsolateData> jni_data);
DartJniIsolateData* jni_data();
#endif
......
......@@ -27,6 +27,12 @@ source_set("libraries") {
"//third_party/qcms",
"//third_party/zlib",
]
if (is_android) {
public_deps += [
"//flutter/lib/jni",
]
}
}
source_set("prerequisites") {
......
......@@ -35,7 +35,7 @@
#include "sky/engine/wtf/MakeUnique.h"
#ifdef OS_ANDROID
#include "sky/engine/bindings/jni/dart_jni.h"
#include "flutter/lib/jni/dart_jni.h"
#endif
namespace blink {
......
......@@ -45,7 +45,7 @@
#include "sky/engine/wtf/MakeUnique.h"
#ifdef OS_ANDROID
#include "sky/engine/bindings/jni/dart_jni.h"
#include "flutter/lib/jni/dart_jni.h"
#endif
namespace dart {
......@@ -287,6 +287,14 @@ static void ServiceStreamCancelCallback(const char* stream_id) {
}
}
#ifdef OS_ANDROID
DartJniIsolateData* GetDartJniDataForCurrentIsolate() {
return FlutterDartState::Current()->jni_data();
}
#endif
} // namespace
#if DART_ALLOW_DYNAMIC_RESOLUTION
......@@ -541,7 +549,7 @@ void InitDartVM() {
DartUI::InitForGlobal();
#ifdef OS_ANDROID
DartJni::InitForGlobal();
DartJni::InitForGlobal(GetDartJniDataForCurrentIsolate);
#endif
// Setup embedder tracing hooks. To avoid data races, it is recommended that
......
......@@ -150,13 +150,14 @@ if (is_android) {
]
deps = [
":common",
":gpu_direct",
":jni_headers",
"//flutter/lib/jni",
"//mojo/android:libsystem_java",
"//mojo/edk/base_edk",
"//mojo/edk/system",
"//ui/gl",
":common",
":gpu_direct",
":jni_headers",
]
ldflags = [
......
......@@ -9,11 +9,11 @@
#include "base/android/library_loader/library_loader_hooks.h"
#include "base/bind.h"
#include "base/logging.h"
#include "flutter/lib/jni/dart_jni.h"
#include "mojo/android/system/base_run_loop.h"
#include "mojo/android/system/core_impl.h"
#include "sky/engine/bindings/jni/dart_jni.h"
#include "sky/shell/platform/android/platform_view_android.h"
#include "sky/shell/platform/android/flutter_main.h"
#include "sky/shell/platform/android/platform_view_android.h"
namespace {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册