Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
470118b0
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
470118b0
编写于
2月 24, 2016
作者:
J
Jason Simmons
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support spawning new Dart isolates from within a Flutter app
上级
52c516bd
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
83 addition
and
67 deletion
+83
-67
services/asset_bundle/zip_asset_bundle.cc
services/asset_bundle/zip_asset_bundle.cc
+4
-11
services/asset_bundle/zip_asset_bundle.h
services/asset_bundle/zip_asset_bundle.h
+8
-12
sky/engine/bindings/dart_runtime_hooks.cc
sky/engine/bindings/dart_runtime_hooks.cc
+14
-1
sky/engine/bindings/dart_runtime_hooks.h
sky/engine/bindings/dart_runtime_hooks.h
+1
-1
sky/engine/bindings/dart_vm_entry_points.txt
sky/engine/bindings/dart_vm_entry_points.txt
+1
-0
sky/engine/core/BUILD.gn
sky/engine/core/BUILD.gn
+1
-0
sky/engine/core/script/dart_controller.cc
sky/engine/core/script/dart_controller.cc
+2
-1
sky/engine/core/script/dart_init.cc
sky/engine/core/script/dart_init.cc
+24
-13
sky/engine/core/script/dart_init.h
sky/engine/core/script/dart_init.h
+3
-0
sky/engine/public/sky/sky_view.cc
sky/engine/public/sky/sky_view.cc
+3
-4
sky/engine/public/sky/sky_view.h
sky/engine/public/sky/sky_view.h
+2
-3
sky/shell/ui/engine.cc
sky/shell/ui/engine.cc
+20
-21
未找到文件。
services/asset_bundle/zip_asset_bundle.cc
浏览文件 @
470118b0
...
...
@@ -21,25 +21,18 @@ void Ignored(bool) {
}
// namespace
unzFile
ScopedUnzFileTraits
::
InvalidValue
()
{
void
*
ScopedUnzFileTraits
::
InvalidValue
()
{
return
nullptr
;
}
void
ScopedUnzFileTraits
::
Free
(
unzFile
file
)
{
void
ScopedUnzFileTraits
::
Free
(
void
*
file
)
{
unzClose
(
file
);
}
scoped_refptr
<
ZipAssetBundle
>
ZipAssetService
::
Create
(
void
ZipAssetService
::
Create
(
InterfaceRequest
<
AssetBundle
>
request
,
const
base
::
FilePath
&
zip_path
,
scoped_refptr
<
base
::
TaskRunner
>
worker_runner
)
{
scoped_refptr
<
ZipAssetBundle
>
zip_asset_bundle
(
new
ZipAssetBundle
(
zip_path
,
worker_runner
.
Pass
()));
// Register as a Mojo service.
const
scoped_refptr
<
ZipAssetBundle
>&
zip_asset_bundle
)
{
new
ZipAssetService
(
request
.
Pass
(),
zip_asset_bundle
);
return
zip_asset_bundle
;
}
ZipAssetService
::
ZipAssetService
(
...
...
services/asset_bundle/zip_asset_bundle.h
浏览文件 @
470118b0
...
...
@@ -13,7 +13,6 @@
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/environment/async_waiter.h"
#include "mojo/services/asset_bundle/interfaces/asset_bundle.mojom.h"
#include "third_party/zlib/contrib/minizip/unzip.h"
namespace
mojo
{
namespace
asset_bundle
{
...
...
@@ -24,6 +23,9 @@ class ZipAssetBundle : public base::RefCountedThreadSafe<ZipAssetBundle> {
friend
class
ZipAssetService
;
public:
ZipAssetBundle
(
const
base
::
FilePath
&
zip_path
,
scoped_refptr
<
base
::
TaskRunner
>
worker_runner
);
// AssetBundle implementation
void
GetAsStream
(
const
String
&
asset_name
,
...
...
@@ -40,10 +42,6 @@ class ZipAssetBundle : public base::RefCountedThreadSafe<ZipAssetBundle> {
friend
class
base
::
RefCountedThreadSafe
<
ZipAssetBundle
>
;
virtual
~
ZipAssetBundle
();
private:
ZipAssetBundle
(
const
base
::
FilePath
&
zip_path
,
scoped_refptr
<
base
::
TaskRunner
>
worker_runner
);
const
base
::
FilePath
zip_path_
;
scoped_refptr
<
base
::
TaskRunner
>
worker_runner_
;
std
::
map
<
String
,
base
::
FilePath
>
overlay_files_
;
...
...
@@ -54,11 +52,9 @@ class ZipAssetBundle : public base::RefCountedThreadSafe<ZipAssetBundle> {
// Wrapper that exposes the ZipAssetBundle as a Mojo service.
class
ZipAssetService
:
public
AssetBundle
{
public:
// Construct a ZipAssetBundle and register it as a Mojo service.
static
scoped_refptr
<
ZipAssetBundle
>
Create
(
static
void
Create
(
InterfaceRequest
<
AssetBundle
>
request
,
const
base
::
FilePath
&
zip_path
,
scoped_refptr
<
base
::
TaskRunner
>
worker_runner
);
const
scoped_refptr
<
ZipAssetBundle
>&
zip_asset_bundle
);
public:
void
GetAsStream
(
...
...
@@ -76,11 +72,11 @@ class ZipAssetService : public AssetBundle {
};
struct
ScopedUnzFileTraits
{
static
unzFile
InvalidValue
();
static
void
Free
(
unzFile
file
);
static
void
*
InvalidValue
();
static
void
Free
(
void
*
unz_
file
);
};
typedef
base
::
ScopedGeneric
<
unzFile
,
ScopedUnzFileTraits
>
ScopedUnzFile
;
typedef
base
::
ScopedGeneric
<
void
*
,
ScopedUnzFileTraits
>
ScopedUnzFile
;
// Reads an asset from a ZIP archive and writes it to a Mojo pipe.
class
ZipAssetHandler
{
...
...
sky/engine/bindings/dart_runtime_hooks.cc
浏览文件 @
470118b0
...
...
@@ -123,12 +123,25 @@ static void InitDartAsync(Dart_Handle builtin_library,
&
schedule_microtask
));
}
void
DartRuntimeHooks
::
Install
(
IsolateType
isolate_type
)
{
static
void
InitDartIo
(
const
std
::
string
&
script_uri
)
{
if
(
!
script_uri
.
empty
())
{
Dart_Handle
io_lib
=
Dart_LookupLibrary
(
ToDart
(
"dart:io"
));
DART_CHECK_VALID
(
io_lib
);
Dart_Handle
platform_type
=
Dart_GetType
(
io_lib
,
ToDart
(
"_Platform"
),
0
,
nullptr
);
DART_CHECK_VALID
(
platform_type
);
DART_CHECK_VALID
(
Dart_SetField
(
platform_type
,
ToDart
(
"_nativeScript"
),
ToDart
(
script_uri
)));
}
}
void
DartRuntimeHooks
::
Install
(
IsolateType
isolate_type
,
const
std
::
string
&
script_uri
)
{
Dart_Handle
builtin
=
Dart_LookupLibrary
(
ToDart
(
"dart:ui"
));
DART_CHECK_VALID
(
builtin
);
InitDartInternal
(
builtin
,
isolate_type
);
InitDartCore
(
builtin
);
InitDartAsync
(
builtin
,
isolate_type
);
InitDartIo
(
script_uri
);
}
// Implementation of native functions which are used for some
...
...
sky/engine/bindings/dart_runtime_hooks.h
浏览文件 @
470118b0
...
...
@@ -18,7 +18,7 @@ class DartRuntimeHooks {
DartIOIsolate
,
};
static
void
Install
(
IsolateType
isolate_type
);
static
void
Install
(
IsolateType
isolate_type
,
const
std
::
string
&
script_uri
);
static
void
RegisterNatives
(
DartLibraryNatives
*
natives
);
private:
...
...
sky/engine/bindings/dart_vm_entry_points.txt
浏览文件 @
470118b0
dart:io,::,_setupHooks
dart:io,_Platform,set:_nativeScript
dart:isolate,::,_startMainIsolate
dart:mojo.internal,MojoHandleWatcher,mojoControlHandle
dart:ui,::,_beginFrame
...
...
sky/engine/core/BUILD.gn
浏览文件 @
470118b0
...
...
@@ -66,6 +66,7 @@ static_library("core") {
":generate_sky_embedder_service_isolate_resources_cc",
":libraries",
":prerequisites",
"//services/asset_bundle:lib",
"//sky/engine/platform",
"//sky/engine/bindings",
"//sky/services/engine:interfaces",
...
...
sky/engine/core/script/dart_controller.cc
浏览文件 @
470118b0
...
...
@@ -193,7 +193,8 @@ void DartController::CreateIsolateFor(std::unique_ptr<DOMDartState> state) {
DartIO
::
InitForIsolate
();
DartUI
::
InitForIsolate
();
DartMojoInternal
::
InitForIsolate
();
DartRuntimeHooks
::
Install
(
DartRuntimeHooks
::
MainIsolate
);
DartRuntimeHooks
::
Install
(
DartRuntimeHooks
::
MainIsolate
,
dom_dart_state_
->
url
().
c_str
());
dart_state
()
->
class_library
().
add_provider
(
"ui"
,
...
...
sky/engine/core/script/dart_init.cc
浏览文件 @
470118b0
...
...
@@ -13,6 +13,7 @@
#include "dart/runtime/bin/embedded_dart_io.h"
#include "dart/runtime/include/dart_mirrors_api.h"
#include "mojo/public/platform/dart/dart_handle_watcher.h"
#include "services/asset_bundle/zip_asset_bundle.h"
#include "sky/engine/bindings/dart_mojo_internal.h"
#include "sky/engine/bindings/dart_runtime_hooks.h"
#include "sky/engine/bindings/dart_ui.h"
...
...
@@ -51,6 +52,10 @@ extern const uint8_t* observatory_assets_archive;
namespace
blink
{
using
mojo
::
asset_bundle
::
ZipAssetBundle
;
const
char
kSnapshotAssetKey
[]
=
"snapshot_blob.bin"
;
Dart_Handle
DartLibraryTagHandler
(
Dart_LibraryTag
tag
,
Dart_Handle
library
,
Dart_Handle
url
)
{
...
...
@@ -59,13 +64,6 @@ Dart_Handle DartLibraryTagHandler(Dart_LibraryTag tag,
namespace
{
void
CreateEmptyRootLibraryIfNeeded
()
{
if
(
Dart_IsNull
(
Dart_RootLibrary
()))
{
Dart_LoadScript
(
Dart_NewStringFromCString
(
"dart:empty"
),
Dart_EmptyString
(),
0
,
0
);
}
}
static
const
char
*
kDartArgs
[]
=
{
"--enable_mirrors=false"
,
// Dart assumes ARM devices are insufficiently powerful and sets the
...
...
@@ -100,6 +98,8 @@ static const char* kDartStartPausedArgs[]{
"--pause_isolates_on_start"
,
};
const
char
kFileUriPrefix
[]
=
"file://"
;
void
IsolateShutdownCallback
(
void
*
callback_data
)
{
// TODO(dart)
}
...
...
@@ -138,7 +138,7 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
#ifdef OS_ANDROID
DartJni
::
InitForIsolate
();
#endif
DartRuntimeHooks
::
Install
(
DartRuntimeHooks
::
DartIOIsolate
);
DartRuntimeHooks
::
Install
(
DartRuntimeHooks
::
DartIOIsolate
,
""
);
const
SkySettings
&
settings
=
SkySettings
::
Get
();
if
(
settings
.
enable_observatory
)
{
std
::
string
ip
=
"127.0.0.1"
;
...
...
@@ -152,11 +152,19 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
return
isolate
;
}
// Create & start the handle watcher isolate
// TODO(abarth): Who deletes this DartState instance?
std
::
vector
<
uint8_t
>
snapshot_data
;
if
(
!
IsRunningPrecompiledCode
())
{
CHECK
(
base
::
StartsWith
(
script_uri
,
kFileUriPrefix
,
base
::
CompareCase
::
SENSITIVE
));
base
::
FilePath
flx_path
(
script_uri
+
strlen
(
kFileUriPrefix
));
scoped_refptr
<
ZipAssetBundle
>
zip_asset_bundle
(
new
ZipAssetBundle
(
flx_path
,
nullptr
));
CHECK
(
zip_asset_bundle
->
GetAsBuffer
(
kSnapshotAssetKey
,
&
snapshot_data
));
}
DartState
*
dart_state
=
new
DartState
();
Dart_Isolate
isolate
=
Dart_CreateIsolate
(
"sky:handle_watcher"
,
""
,
script_uri
,
main
,
reinterpret_cast
<
uint8_t
*>
(
DART_SYMBOL
(
kDartIsolateSnapshotBuffer
)),
nullptr
,
dart_state
,
error
);
CHECK
(
isolate
)
<<
error
;
...
...
@@ -172,9 +180,12 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
#ifdef OS_ANDROID
DartJni
::
InitForIsolate
();
#endif
DartRuntimeHooks
::
Install
(
DartRuntimeHooks
::
MainIsolate
,
script_uri
);
if
(
!
script_uri
)
CreateEmptyRootLibraryIfNeeded
();
if
(
!
snapshot_data
.
empty
())
{
CHECK
(
!
LogIfError
(
Dart_LoadScriptFromSnapshot
(
snapshot_data
.
data
(),
snapshot_data
.
size
())));
}
}
Dart_ExitIsolate
();
...
...
sky/engine/core/script/dart_init.h
浏览文件 @
470118b0
...
...
@@ -33,6 +33,9 @@ extern void* kDartIsolateSnapshotBuffer;
#endif // DART_ALLOW_DYNAMIC_RESOLUTION
// Name of the snapshot blob asset within the FLX bundle.
extern
const
char
kSnapshotAssetKey
[];
bool
IsRunningPrecompiledCode
();
void
InitDartVM
();
...
...
sky/engine/public/sky/sky_view.cc
浏览文件 @
470118b0
...
...
@@ -51,12 +51,12 @@ void SkyView::PopRoute() {
GetWindow
()
->
PopRoute
();
}
void
SkyView
::
CreateView
(
const
std
::
string
&
name
)
{
void
SkyView
::
CreateView
(
const
std
::
string
&
script_uri
)
{
DCHECK
(
!
dart_controller_
);
dart_controller_
=
WTF
::
MakeUnique
<
DartController
>
();
dart_controller_
->
CreateIsolateFor
(
WTF
::
MakeUnique
<
DOMDartState
>
(
WTF
::
MakeUnique
<
Window
>
(
this
),
name
));
WTF
::
MakeUnique
<
Window
>
(
this
),
script_uri
));
DOMDartState
*
dart_state
=
dart_controller_
->
dart_state
();
DartState
::
Scope
scope
(
dart_state
);
...
...
@@ -76,8 +76,7 @@ void SkyView::RunFromPrecompiledSnapshot() {
dart_controller_
->
RunFromPrecompiledSnapshot
();
}
void
SkyView
::
RunFromSnapshot
(
const
std
::
string
&
name
,
mojo
::
ScopedDataPipeConsumerHandle
snapshot
)
{
void
SkyView
::
RunFromSnapshot
(
mojo
::
ScopedDataPipeConsumerHandle
snapshot
)
{
dart_controller_
->
RunFromSnapshot
(
snapshot
.
Pass
());
}
...
...
sky/engine/public/sky/sky_view.h
浏览文件 @
470118b0
...
...
@@ -47,13 +47,12 @@ class SkyView : public WindowClient {
std
::
unique_ptr
<
flow
::
LayerTree
>
BeginFrame
(
base
::
TimeTicks
frame_time
);
void
CreateView
(
const
std
::
string
&
name
);
void
CreateView
(
const
std
::
string
&
script_uri
);
void
RunFromLibrary
(
const
std
::
string
&
name
,
DartLibraryProvider
*
library_provider
);
void
RunFromPrecompiledSnapshot
();
void
RunFromSnapshot
(
const
std
::
string
&
name
,
mojo
::
ScopedDataPipeConsumerHandle
snapshot
);
void
RunFromSnapshot
(
mojo
::
ScopedDataPipeConsumerHandle
snapshot
);
void
HandlePointerPacket
(
const
pointer
::
PointerPacketPtr
&
packet
);
...
...
sky/shell/ui/engine.cc
浏览文件 @
470118b0
...
...
@@ -13,6 +13,8 @@
#include "mojo/public/cpp/application/connect.h"
#include "services/asset_bundle/zip_asset_bundle.h"
#include "sky/engine/bindings/mojo_services.h"
#include "sky/engine/core/script/dart_init.h"
#include "sky/engine/core/script/dom_dart_state.h"
#include "sky/engine/public/platform/sky_display_metrics.h"
#include "sky/engine/public/platform/WebInputEvent.h"
#include "sky/engine/public/web/Sky.h"
...
...
@@ -28,8 +30,6 @@ namespace sky {
namespace
shell
{
namespace
{
const
char
kSnapshotKey
[]
=
"snapshot_blob.bin"
;
PlatformImpl
*
g_platform_impl
=
nullptr
;
}
// namespace
...
...
@@ -172,12 +172,13 @@ void Engine::RunFromLibrary(const std::string& name) {
}
void
Engine
::
RunFromSnapshotStream
(
const
std
::
string
&
name
,
const
std
::
string
&
bundle_path
,
mojo
::
ScopedDataPipeConsumerHandle
snapshot
)
{
TRACE_EVENT0
(
"flutter"
,
"Engine::RunFromSnapshotStream"
);
std
::
string
script_uri
=
std
::
string
(
"file://"
)
+
bundle_path
;
sky_view_
=
blink
::
SkyView
::
Create
(
this
);
sky_view_
->
CreateView
(
name
);
sky_view_
->
RunFromSnapshot
(
name
,
snapshot
.
Pass
());
sky_view_
->
CreateView
(
script_uri
);
sky_view_
->
RunFromSnapshot
(
snapshot
.
Pass
());
sky_view_
->
SetDisplayMetrics
(
display_metrics_
);
sky_view_
->
SetLocale
(
language_code_
,
country_code_
);
if
(
!
initial_route_
.
empty
())
...
...
@@ -188,10 +189,9 @@ void Engine::RunFromPrecompiledSnapshot(const mojo::String& bundle_path) {
TRACE_EVENT0
(
"flutter"
,
"Engine::RunFromPrecompiledSnapshot"
);
std
::
string
path_str
=
bundle_path
;
zip_asset_bundle_
=
ZipAssetService
::
Create
(
mojo
::
GetProxy
(
&
root_bundle_
),
base
::
FilePath
(
path_str
),
base
::
WorkerPool
::
GetTaskRunner
(
true
));
zip_asset_bundle_
=
new
ZipAssetBundle
(
base
::
FilePath
(
path_str
),
base
::
WorkerPool
::
GetTaskRunner
(
true
));
ZipAssetService
::
Create
(
mojo
::
GetProxy
(
&
root_bundle_
),
zip_asset_bundle_
);
sky_view_
=
blink
::
SkyView
::
Create
(
this
);
sky_view_
->
CreateView
(
"http://localhost"
);
...
...
@@ -214,12 +214,11 @@ void Engine::RunFromFile(const mojo::String& main,
void
Engine
::
RunFromBundle
(
const
mojo
::
String
&
path
)
{
TRACE_EVENT0
(
"flutter"
,
"Engine::RunFromBundle"
);
std
::
string
path_str
=
path
;
zip_asset_bundle_
=
ZipAssetService
::
Create
(
mojo
::
GetProxy
(
&
root_bundle_
),
base
::
FilePath
(
path_str
),
base
::
WorkerPool
::
GetTaskRunner
(
true
));
zip_asset_bundle_
=
new
ZipAssetBundle
(
base
::
FilePath
(
path_str
),
base
::
WorkerPool
::
GetTaskRunner
(
true
));
ZipAssetService
::
Create
(
mojo
::
GetProxy
(
&
root_bundle_
),
zip_asset_bundle_
);
root_bundle_
->
GetAsStream
(
kSnapsho
tKey
,
root_bundle_
->
GetAsStream
(
blink
::
kSnapshotAsse
tKey
,
base
::
Bind
(
&
Engine
::
RunFromSnapshotStream
,
weak_factory_
.
GetWeakPtr
(),
path_str
));
}
...
...
@@ -228,16 +227,15 @@ void Engine::RunFromBundleAndSnapshot(const mojo::String& bundle_path,
const
mojo
::
String
&
snapshot_path
)
{
TRACE_EVENT0
(
"flutter"
,
"Engine::RunFromBundleAndSnapshot"
);
std
::
string
bundle_path_str
=
bundle_path
;
zip_asset_bundle_
=
ZipAssetService
::
Create
(
mojo
::
GetProxy
(
&
root_bundle_
),
base
::
FilePath
(
bundle_path_str
),
base
::
WorkerPool
::
GetTaskRunner
(
true
));
zip_asset_bundle_
=
new
ZipAssetBundle
(
base
::
FilePath
(
bundle_path_str
),
base
::
WorkerPool
::
GetTaskRunner
(
true
));
ZipAssetService
::
Create
(
mojo
::
GetProxy
(
&
root_bundle_
),
zip_asset_bundle_
);
std
::
string
snapshot_path_str
=
snapshot_path
;
zip_asset_bundle_
->
AddOverlayFile
(
kSnapsho
tKey
,
zip_asset_bundle_
->
AddOverlayFile
(
blink
::
kSnapshotAsse
tKey
,
base
::
FilePath
(
snapshot_path_str
));
root_bundle_
->
GetAsStream
(
kSnapsho
tKey
,
root_bundle_
->
GetAsStream
(
blink
::
kSnapshotAsse
tKey
,
base
::
Bind
(
&
Engine
::
RunFromSnapshotStream
,
weak_factory_
.
GetWeakPtr
(),
bundle_path_str
));
...
...
@@ -275,8 +273,9 @@ void Engine::OnAppLifecycleStateChanged(sky::AppLifecycleState state) {
void
Engine
::
DidCreateIsolate
(
Dart_Isolate
isolate
)
{
blink
::
MojoServices
::
Create
(
isolate
,
services_
.
Pass
(),
root_bundle_
.
Pass
());
if
(
zip_asset_bundle_
)
if
(
zip_asset_bundle_
)
{
FlutterFontSelector
::
install
(
zip_asset_bundle_
);
}
}
void
Engine
::
StopAnimator
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录