Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
e26bf9a8
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,发现更多精彩内容 >>
提交
e26bf9a8
编写于
10月 27, 2016
作者:
A
Adam Barth
提交者:
GitHub
10月 27, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Unify the various run methods on engine (#3183)
Now they all flow through some common routines.
上级
0799ce9c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
85 addition
and
50 deletion
+85
-50
shell/common/engine.cc
shell/common/engine.cc
+70
-47
shell/common/engine.h
shell/common/engine.h
+15
-3
未找到文件。
shell/common/engine.cc
浏览文件 @
e26bf9a8
...
...
@@ -21,6 +21,7 @@
#include "flutter/shell/common/animator.h"
#include "flutter/shell/common/platform_view.h"
#include "flutter/sky/engine/public/web/Sky.h"
#include "lib/ftl/files/file.h"
#include "lib/ftl/files/path.h"
#include "lib/ftl/functional/make_copyable.h"
#include "mojo/public/cpp/application/connect.h"
...
...
@@ -52,6 +53,10 @@ std::string FindPackagesPath(const std::string& main_dart) {
return
packages_path
;
}
std
::
string
GetScriptUriFromPath
(
const
std
::
string
&
path
)
{
return
"file://"
+
path
;
}
}
// namespace
Engine
::
Engine
(
PlatformView
*
platform_view
)
...
...
@@ -75,6 +80,56 @@ void Engine::Init() {
blink
::
InitRuntime
();
}
void
Engine
::
RunBundle
(
const
std
::
string
&
bundle_path
)
{
TRACE_EVENT0
(
"flutter"
,
"Engine::RunBundle"
);
ConfigureAssetBundle
(
bundle_path
);
ConfigureRuntime
(
GetScriptUriFromPath
(
bundle_path
));
if
(
blink
::
IsRunningPrecompiledCode
())
{
runtime_
->
dart_controller
()
->
RunFromPrecompiledSnapshot
();
}
else
{
std
::
vector
<
uint8_t
>
snapshot
;
if
(
!
GetAssetAsBuffer
(
blink
::
kSnapshotAssetKey
,
&
snapshot
))
return
;
runtime_
->
dart_controller
()
->
RunFromSnapshot
(
snapshot
.
data
(),
snapshot
.
size
());
}
}
void
Engine
::
RunBundleAndSnapshot
(
const
std
::
string
&
bundle_path
,
const
std
::
string
&
snapshot_override
)
{
TRACE_EVENT0
(
"flutter"
,
"Engine::RunBundleAndSnapshot"
);
if
(
snapshot_override
.
empty
())
{
RunBundle
(
bundle_path
);
return
;
}
ConfigureAssetBundle
(
bundle_path
);
ConfigureRuntime
(
GetScriptUriFromPath
(
bundle_path
));
if
(
blink
::
IsRunningPrecompiledCode
())
{
runtime_
->
dart_controller
()
->
RunFromPrecompiledSnapshot
();
}
else
{
std
::
vector
<
uint8_t
>
snapshot
;
if
(
!
files
::
ReadFileToVector
(
snapshot_override
,
&
snapshot
))
return
;
runtime_
->
dart_controller
()
->
RunFromSnapshot
(
snapshot
.
data
(),
snapshot
.
size
());
}
}
void
Engine
::
RunBundleAndSource
(
const
std
::
string
&
bundle_path
,
const
std
::
string
&
main
,
const
std
::
string
&
packages
)
{
TRACE_EVENT0
(
"flutter"
,
"Engine::RunBundleAndSource"
);
FTL_CHECK
(
!
blink
::
IsRunningPrecompiledCode
())
<<
"Cannot run from source in a precompiled build."
;
std
::
string
packages_path
=
packages
;
if
(
packages_path
.
empty
())
packages_path
=
FindPackagesPath
(
main
);
if
(
!
bundle_path
.
empty
())
ConfigureAssetBundle
(
bundle_path
);
ConfigureRuntime
(
GetScriptUriFromPath
(
main
));
runtime_
->
dart_controller
()
->
RunFromSource
(
main
,
packages_path
);
}
void
Engine
::
BeginFrame
(
ftl
::
TimePoint
frame_time
)
{
TRACE_EVENT0
(
"flutter"
,
"Engine::BeginFrame"
);
if
(
runtime_
)
...
...
@@ -83,15 +138,8 @@ void Engine::BeginFrame(ftl::TimePoint frame_time) {
void
Engine
::
RunFromSource
(
const
std
::
string
&
main
,
const
std
::
string
&
packages
,
const
std
::
string
&
bundle
)
{
TRACE_EVENT0
(
"flutter"
,
"Engine::RunFromSource"
);
std
::
string
packages_path
=
packages
;
if
(
packages_path
.
empty
())
packages_path
=
FindPackagesPath
(
main
);
if
(
!
bundle
.
empty
())
ConfigureAssetBundle
(
bundle
);
ConfigureRuntime
(
main
);
runtime_
->
dart_controller
()
->
RunFromSource
(
main
,
packages_path
);
const
std
::
string
&
bundle_path
)
{
RunBundleAndSource
(
bundle_path
,
main
,
packages
);
}
Dart_Port
Engine
::
GetUIIsolateMainPort
()
{
...
...
@@ -228,20 +276,6 @@ void Engine::SetSemanticsEnabled(bool enabled) {
runtime_
->
SetSemanticsEnabled
(
semantics_enabled_
);
}
void
Engine
::
RunFromSnapshotStream
(
const
std
::
string
&
script_uri
,
mojo
::
ScopedDataPipeConsumerHandle
snapshot
)
{
TRACE_EVENT0
(
"flutter"
,
"Engine::RunFromSnapshotStream"
);
ConfigureRuntime
(
script_uri
);
snapshot_drainer_
.
reset
(
new
glue
::
DrainDataPipeJob
(
std
::
move
(
snapshot
),
[
this
](
std
::
vector
<
uint8_t
>
snapshot
)
{
FTL_DCHECK
(
runtime_
);
FTL_DCHECK
(
runtime_
->
dart_controller
());
runtime_
->
dart_controller
()
->
RunFromSnapshot
(
snapshot
.
data
(),
snapshot
.
size
());
}));
}
void
Engine
::
ConfigureAssetBundle
(
const
std
::
string
&
path
)
{
struct
stat
stat_result
=
{
0
};
...
...
@@ -282,40 +316,24 @@ void Engine::ConfigureRuntime(const std::string& script_uri) {
}
void
Engine
::
RunFromPrecompiledSnapshot
(
const
mojo
::
String
&
bundle_path
)
{
TRACE_EVENT0
(
"flutter"
,
"Engine::RunFromPrecompiledSnapshot"
);
ConfigureAssetBundle
(
bundle_path
.
get
());
ConfigureRuntime
(
"http://localhost"
);
runtime_
->
dart_controller
()
->
RunFromPrecompiledSnapshot
();
RunBundle
(
bundle_path
);
}
void
Engine
::
RunFromFile
(
const
mojo
::
String
&
main
,
const
mojo
::
String
&
packages
,
const
mojo
::
String
&
bundle
)
{
Run
FromSource
(
main
,
packages
,
bundle
);
Run
BundleAndSource
(
bundle
,
main
,
packages
);
}
void
Engine
::
RunFromBundle
(
const
mojo
::
String
&
script_uri
,
const
mojo
::
String
&
path
)
{
TRACE_EVENT0
(
"flutter"
,
"Engine::RunFromBundle"
);
ConfigureAssetBundle
(
path
);
mojo
::
DataPipe
pipe
;
asset_store_
->
GetAsStream
(
blink
::
kSnapshotAssetKey
,
std
::
move
(
pipe
.
producer_handle
));
RunFromSnapshotStream
(
script_uri
,
std
::
move
(
pipe
.
consumer_handle
));
const
mojo
::
String
&
bundle_path
)
{
RunBundle
(
bundle_path
);
}
void
Engine
::
RunFromBundleAndSnapshot
(
const
mojo
::
String
&
script_uri
,
const
mojo
::
String
&
bundle_path
,
const
mojo
::
String
&
snapshot_path
)
{
TRACE_EVENT0
(
"flutter"
,
"Engine::RunFromBundleAndSnapshot"
);
ConfigureAssetBundle
(
bundle_path
);
asset_store_
->
AddOverlayFile
(
blink
::
kSnapshotAssetKey
,
snapshot_path
);
mojo
::
DataPipe
pipe
;
asset_store_
->
GetAsStream
(
blink
::
kSnapshotAssetKey
,
std
::
move
(
pipe
.
producer_handle
));
RunFromSnapshotStream
(
script_uri
,
std
::
move
(
pipe
.
consumer_handle
));
RunBundleAndSnapshot
(
bundle_path
,
snapshot_path
);
}
void
Engine
::
DidCreateMainIsolate
(
Dart_Isolate
isolate
)
{
...
...
@@ -382,13 +400,18 @@ void Engine::HandleAssetPlatformMessage(
std
::
string
asset_name
(
reinterpret_cast
<
const
char
*>
(
data
.
data
()),
data
.
size
());
std
::
vector
<
uint8_t
>
asset_data
;
if
((
directory_asset_bundle_
&&
directory_asset_bundle_
->
GetAsBuffer
(
asset_name
,
&
asset_data
))
||
(
asset_store_
&&
asset_store_
->
GetAsBuffer
(
asset_name
,
&
asset_data
)))
{
if
(
GetAssetAsBuffer
(
asset_name
,
&
asset_data
))
{
response
->
Complete
(
std
::
move
(
asset_data
));
}
else
{
response
->
CompleteWithError
();
}
}
bool
Engine
::
GetAssetAsBuffer
(
const
std
::
string
&
name
,
std
::
vector
<
uint8_t
>*
data
)
{
return
(
directory_asset_bundle_
&&
directory_asset_bundle_
->
GetAsBuffer
(
name
,
data
))
||
(
asset_store_
&&
asset_store_
->
GetAsBuffer
(
name
,
data
));
}
}
// namespace shell
shell/common/engine.h
浏览文件 @
e26bf9a8
...
...
@@ -44,6 +44,20 @@ class Engine : public sky::SkyEngine, public blink::RuntimeDelegate {
static
void
Init
();
void
RunBundle
(
const
std
::
string
&
bundle_path
);
// Uses the given snapshot instead of looking inside the bundle for the
// snapshot. If |snapshot_override| is empty, this function looks for the
// snapshot in the bundle itself.
void
RunBundleAndSnapshot
(
const
std
::
string
&
bundle_path
,
const
std
::
string
&
snapshot_override
);
// Uses the given source code instead of looking inside the bindle for the
// source code.
void
RunBundleAndSource
(
const
std
::
string
&
bundle_path
,
const
std
::
string
&
main
,
const
std
::
string
&
packages
);
void
BeginFrame
(
ftl
::
TimePoint
frame_time
);
void
RunFromSource
(
const
std
::
string
&
main
,
...
...
@@ -84,9 +98,6 @@ class Engine : public sky::SkyEngine, public blink::RuntimeDelegate {
void
DidCreateMainIsolate
(
Dart_Isolate
isolate
)
override
;
void
DidCreateSecondaryIsolate
(
Dart_Isolate
isolate
)
override
;
void
RunFromSnapshotStream
(
const
std
::
string
&
script_uri
,
mojo
::
ScopedDataPipeConsumerHandle
snapshot
);
void
StopAnimator
();
void
StartAnimatorIfPossible
();
...
...
@@ -100,6 +111,7 @@ class Engine : public sky::SkyEngine, public blink::RuntimeDelegate {
ftl
::
RefPtr
<
blink
::
PlatformMessage
>
message
);
void
HandleAssetPlatformMessage
(
ftl
::
RefPtr
<
blink
::
PlatformMessage
>
message
);
bool
GetAssetAsBuffer
(
const
std
::
string
&
name
,
std
::
vector
<
uint8_t
>*
data
);
ftl
::
WeakPtr
<
PlatformView
>
platform_view_
;
std
::
unique_ptr
<
Animator
>
animator_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录