Created
August 15, 2016 10:12
-
-
Save mraleph/dd650c4c4b27826c2b00fc1a56d31f34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 4ff0340157287ca9082bca8d70e5958d96ccfd59 | |
Author: Vyacheslav Egorov <[email protected]> | |
Date: Mon Aug 15 12:11:24 2016 +0200 | |
Use library snapshot on Android instead of blobs | |
diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn | |
index 04d4bd9..735a808 100644 | |
--- a/build/config/compiler/BUILD.gn | |
+++ b/build/config/compiler/BUILD.gn | |
@@ -1100,7 +1100,7 @@ if (is_win) { | |
common_optimize_on_ldflags = [] | |
if (is_android) { | |
- if (!using_sanitizer) { | |
+ if (!using_sanitizer && !enable_profiling) { | |
common_optimize_on_cflags += [ "-fomit-frame-pointer" ] | |
} | |
@@ -1167,7 +1167,7 @@ config("no_optimize") { | |
"-fdata-sections", | |
"-ffunction-sections", | |
] | |
- if (!using_sanitizer) { | |
+ if (!using_sanitizer && !enable_profiling) { | |
cflags += [ "-fomit-frame-pointer" ] | |
} | |
ldflags = common_optimize_on_ldflags | |
diff --git a/sky/engine/core/script/dart_init.cc b/sky/engine/core/script/dart_init.cc | |
index b7cfec8..8c16ace 100644 | |
--- a/sky/engine/core/script/dart_init.cc | |
+++ b/sky/engine/core/script/dart_init.cc | |
@@ -46,6 +46,10 @@ | |
#ifdef OS_ANDROID | |
#include "flutter/lib/jni/dart_jni.h" | |
+#include <android/log.h> | |
+ | |
+#define LOG_TAG "DartInit" | |
+#define ALOG(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__) | |
#endif | |
namespace dart { | |
@@ -301,12 +305,16 @@ DartJniIsolateData* GetDartJniDataForCurrentIsolate() { | |
const char* kDartVmIsolateSnapshotBufferName = "kDartVmIsolateSnapshotBuffer"; | |
const char* kDartIsolateSnapshotBufferName = "kDartIsolateSnapshotBuffer"; | |
-const char* kInstructionsSnapshotName = "kInstructionsSnapshot"; | |
-const char* kDataSnapshotName = "kDataSnapshot"; | |
+const char* kInstructionsSnapshotName = "_kInstructionsSnapshot"; | |
+const char* kDataSnapshotName = "_kDataSnapshot"; | |
-#if OS(IOS) | |
+#if OS(IOS) || OS(ANDROID) || 1 | |
+#if OS(IOS) | |
const char* kDartApplicationLibraryPath = "app.dylib"; | |
+#else | |
+const char* kDartApplicationLibraryPath = "app.so"; | |
+#endif | |
static void* DartLookupSymbolInLibrary(const char* symbol_name, | |
const char* library) { | |
@@ -315,27 +323,41 @@ static void* DartLookupSymbolInLibrary(const char* symbol_name, | |
return nullptr; | |
} | |
dlerror(); // clear previous errors on thread | |
+ | |
void* library_handle = dlopen(library, RTLD_NOW); | |
- if (dlerror() != nullptr) { | |
+ const char* errmsg = dlerror(); | |
+ if (errmsg != nullptr) { | |
+ ALOG("failed to load library %s: %s", library, errmsg); | |
return nullptr; | |
} | |
void* sym = dlsym(library_handle, symbol_name); | |
- return dlerror() != nullptr ? nullptr : sym; | |
+ errmsg = dlerror(); | |
+ if (errmsg != nullptr || sym == nullptr) { | |
+ ALOG("failed to locate symbol library %s: %s", symbol_name, errmsg != nullptr ? errmsg : "???"); | |
+ } | |
+ return errmsg != nullptr ? nullptr : sym; | |
} | |
void* _DartSymbolLookup(const char* symbol_name) { | |
+ ALOG("looking for %s", symbol_name); | |
TRACE_EVENT0("flutter", __func__); | |
if (symbol_name == nullptr) { | |
return nullptr; | |
} | |
+ const std::string& aot_snapshot_path = SkySettings::Get().aot_snapshot_path; | |
+ CHECK(!aot_snapshot_path.empty()); | |
+ | |
+ const std::string library_path = aot_snapshot_path + "/" + kDartApplicationLibraryPath; | |
+ | |
// First the application library is checked for the valid symbols. This | |
// library may not necessarily exist. If it does exist, it is loaded and the | |
// symbols resolved. Once the application library is loaded, there is | |
// currently no provision to unload the same. | |
void* symbol = | |
- DartLookupSymbolInLibrary(symbol_name, kDartApplicationLibraryPath); | |
+ DartLookupSymbolInLibrary(symbol_name, library_path.c_str()); | |
if (symbol != nullptr) { | |
+ ALOG("resolved %s to %p", symbol_name, symbol); | |
return symbol; | |
} | |
@@ -376,6 +398,7 @@ void* _DartSymbolLookup(const char* symbol_name) { | |
base::FilePath asset_path = | |
base::FilePath(aot_snapshot_path).Append(symbol_asset.file_name); | |
+ | |
int64 asset_size; | |
if (!base::GetFileSize(asset_path, &asset_size)) | |
return nullptr; | |
diff --git a/sky/shell/BUILD.gn b/sky/shell/BUILD.gn | |
index 5c1e927..660f7fd 100644 | |
--- a/sky/shell/BUILD.gn | |
+++ b/sky/shell/BUILD.gn | |
@@ -111,7 +111,7 @@ source_set("gpu_mojo") { | |
] | |
} | |
-if (is_linux || is_mac) { | |
+if (is_linux || is_mac || is_android) { | |
source_set("testing") { | |
sources = [ | |
@@ -238,6 +238,46 @@ if (is_android) { | |
":sky_shell", | |
] | |
} | |
+ | |
+ source_set("static_sky_shell") { | |
+ sources = [ | |
+ "platform/android/main_android.cc", | |
+ "platform/android/platform_view_android_empty.cc" | |
+ ] | |
+ | |
+ deps = [ | |
+ "//mojo/common", | |
+ "//mojo/edk/base_edk", | |
+ "//mojo/edk/system", | |
+ ":common", | |
+ ":gpu_direct", | |
+ ":testing", | |
+ ] | |
+ } | |
+ | |
+ executable("xshell") { | |
+ output_name = "xsky_shell" | |
+ | |
+ # sources = [ | |
+ # "platform/linux/madsdain_linux.cc", | |
+ # "platform/linux/platform_view_linux.cc" | |
+ # ] | |
+ | |
+ deps = [ | |
+ "//mojo/common", | |
+ "//mojo/edk/base_edk", | |
+ "//mojo/edk/system", | |
+ ":common", | |
+ ":gpu_direct", | |
+ ":testing", | |
+ ":static_sky_shell" | |
+ ] | |
+ | |
+ ldflags = [ | |
+ "-lGLESv2", | |
+ "-lEGL", | |
+ ] | |
+ } | |
} else if (is_ios) { | |
import("//build/config/ios/rules.gni") | |
import("//build/config/ios/ios_sdk.gni") | |
diff --git a/sky/shell/platform/android/io/flutter/view/FlutterMain.java b/sky/shell/platform/android/io/flutter/view/FlutterMain.java | |
index 909e204..8873c7f 100644 | |
--- a/sky/shell/platform/android/io/flutter/view/FlutterMain.java | |
+++ b/sky/shell/platform/android/io/flutter/view/FlutterMain.java | |
@@ -69,7 +69,7 @@ public class FlutterMain { | |
private static final String AOT_RODATA = "snapshot_aot_rodata"; | |
private static final String AOT_VM_ISOLATE = "snapshot_aot_vmisolate"; | |
private static final String[] AOT_RESOURCES = { | |
- AOT_INSTR, AOT_ISOLATE, AOT_RODATA, AOT_VM_ISOLATE | |
+ "app.so" | |
}; | |
private static final String MANIFEST = "flutter.yaml"; | |
diff --git a/sky/shell/platform/android/main_android.cc b/sky/shell/platform/android/main_android.cc | |
new file mode 100644 | |
index 0000000..b7c1b33 | |
--- /dev/null | |
+++ b/sky/shell/platform/android/main_android.cc | |
@@ -0,0 +1,74 @@ | |
+// 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 "base/at_exit.h" | |
+#include "base/basictypes.h" | |
+#include "base/bind.h" | |
+#include "base/command_line.h" | |
+#include "base/logging.h" | |
+#include "base/message_loop/message_loop.h" | |
+#include "mojo/edk/embedder/embedder.h" | |
+#include "mojo/edk/embedder/simple_platform_support.h" | |
+#include "sky/shell/shell.h" | |
+#include "sky/shell/switches.h" | |
+#include "sky/shell/testing/testing.h" | |
+ | |
+#if defined(USE_GLFW) | |
+#include "sky/shell/platform/glfw/init_glfw.h" | |
+#include "sky/shell/platform/glfw/message_pump_glfw.h" | |
+#endif | |
+ | |
+namespace { | |
+ | |
+int RunNonInteractive() { | |
+ base::MessageLoop message_loop; | |
+ mojo::embedder::Init(mojo::embedder::CreateSimplePlatformSupport()); | |
+ sky::shell::Shell::InitStandalone(); | |
+ | |
+ if (!sky::shell::InitForTesting()) { | |
+ sky::shell::switches::PrintUsage("sky_shell"); | |
+ return 1; | |
+ } | |
+ | |
+ message_loop.Run(); | |
+ return 0; | |
+} | |
+ | |
+#if defined(USE_GLFW) | |
+ | |
+int RunInteractive() { | |
+ base::MessageLoop message_loop(sky::shell::MessagePumpGLFW::Create()); | |
+ mojo::embedder::Init(mojo::embedder::CreateSimplePlatformSupport()); | |
+ sky::shell::Shell::InitStandalone(); | |
+ | |
+ if (!sky::shell::InitInteractive()) | |
+ return 1; | |
+ | |
+ message_loop.Run(); | |
+ return 0; | |
+} | |
+ | |
+#endif // defined(USE_GLFW) | |
+ | |
+} // namespace | |
+ | |
+int main(int argc, const char* argv[]) { | |
+ base::AtExitManager exit_manager; | |
+ base::CommandLine::Init(argc, argv); | |
+ | |
+ base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); | |
+ | |
+ if (command_line.HasSwitch(sky::shell::switches::kHelp)) { | |
+ sky::shell::switches::PrintUsage("sky_shell"); | |
+ return 0; | |
+ } | |
+ | |
+#if defined(USE_GLFW) | |
+ if (command_line.HasSwitch(sky::shell::switches::kNonInteractive)) | |
+ return RunNonInteractive(); | |
+ return RunInteractive(); | |
+#endif | |
+ | |
+ return RunNonInteractive(); | |
+} | |
diff --git a/sky/shell/platform/android/platform_view_android_empty.cc b/sky/shell/platform/android/platform_view_android_empty.cc | |
new file mode 100644 | |
index 0000000..73fee52 | |
--- /dev/null | |
+++ b/sky/shell/platform/android/platform_view_android_empty.cc | |
@@ -0,0 +1,15 @@ | |
+// 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 "sky/shell/platform_view.h" | |
+ | |
+namespace sky { | |
+namespace shell { | |
+ | |
+PlatformView* PlatformView::Create(const Config& config) { | |
+ return new PlatformView(config); | |
+} | |
+ | |
+} // namespace shell | |
+} // namespace sky | |
diff --git a/sky/shell/testing/test_runner.cc b/sky/shell/testing/test_runner.cc | |
index 5043dde..ef07a66 100644 | |
--- a/sky/shell/testing/test_runner.cc | |
+++ b/sky/shell/testing/test_runner.cc | |
@@ -44,5 +44,10 @@ void TestRunner::Run(const TestDescriptor& test) { | |
sky_engine_->RunFromFile(test.path, test.packages, ""); | |
} | |
+void TestRunner::RunFromSnapshot(const TestDescriptor& test) { | |
+ sky_engine_->RunFromPrecompiledSnapshot(""); | |
+} | |
+ | |
+ | |
} // namespace shell | |
} // namespace sky | |
diff --git a/sky/shell/testing/test_runner.h b/sky/shell/testing/test_runner.h | |
index 8448eec..359d1ba 100644 | |
--- a/sky/shell/testing/test_runner.h | |
+++ b/sky/shell/testing/test_runner.h | |
@@ -27,6 +27,7 @@ class TestRunner { | |
}; | |
void Run(const TestDescriptor& test); | |
+ void RunFromSnapshot(const TestDescriptor& test); | |
private: | |
TestRunner(); | |
diff --git a/sky/shell/testing/testing.cc b/sky/shell/testing/testing.cc | |
index 5f46a49..be535e3 100644 | |
--- a/sky/shell/testing/testing.cc | |
+++ b/sky/shell/testing/testing.cc | |
@@ -21,7 +21,12 @@ bool InitForTesting() { | |
return false; | |
test.path = args[0]; | |
+#if FLUTTER_AOT | |
+ TestRunner::Shared().RunFromSnapshot(test); | |
+#else | |
TestRunner::Shared().Run(test); | |
+#endif | |
+ | |
return true; | |
} | |
diff --git a/sky/shell/ui/engine.cc b/sky/shell/ui/engine.cc | |
index 1002a50..c79d3fa 100644 | |
--- a/sky/shell/ui/engine.cc | |
+++ b/sky/shell/ui/engine.cc | |
@@ -178,7 +178,9 @@ void Engine::ConfigureZipAssetBundle(const mojo::String& path) { | |
void Engine::RunFromPrecompiledSnapshot(const mojo::String& bundle_path) { | |
TRACE_EVENT0("flutter", "Engine::RunFromPrecompiledSnapshot"); | |
- ConfigureZipAssetBundle(bundle_path); | |
+ if (bundle_path.size() != 0) { | |
+ ConfigureZipAssetBundle(bundle_path); | |
+ } | |
sky_view_ = blink::SkyView::Create(this); | |
sky_view_->CreateView("http://localhost"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment