Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
a50f1ef5
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,发现更多精彩内容 >>
未验证
提交
a50f1ef5
编写于
1月 07, 2020
作者:
G
George Wright
提交者:
GitHub
1月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Migrate flutter_runner from flutter_runner::{Thread,Loop} to fml::{Thread,MessageLoop} (#15118)
上级
27a221d6
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
75 addition
and
448 deletion
+75
-448
ci/licenses_golden/licenses_flutter
ci/licenses_golden/licenses_flutter
+0
-8
fml/thread.cc
fml/thread.cc
+4
-0
shell/platform/fuchsia/flutter/BUILD.gn
shell/platform/fuchsia/flutter/BUILD.gn
+0
-8
shell/platform/fuchsia/flutter/component.cc
shell/platform/fuchsia/flutter/component.cc
+11
-14
shell/platform/fuchsia/flutter/component.h
shell/platform/fuchsia/flutter/component.h
+2
-2
shell/platform/fuchsia/flutter/engine.cc
shell/platform/fuchsia/flutter/engine.cc
+13
-19
shell/platform/fuchsia/flutter/engine.h
shell/platform/fuchsia/flutter/engine.h
+2
-2
shell/platform/fuchsia/flutter/engine_flutter_runner.gni
shell/platform/fuchsia/flutter/engine_flutter_runner.gni
+0
-8
shell/platform/fuchsia/flutter/fuchsia_intl.cc
shell/platform/fuchsia/flutter/fuchsia_intl.cc
+0
-1
shell/platform/fuchsia/flutter/loop.cc
shell/platform/fuchsia/flutter/loop.cc
+0
-47
shell/platform/fuchsia/flutter/loop.h
shell/platform/fuchsia/flutter/loop.h
+0
-17
shell/platform/fuchsia/flutter/main.cc
shell/platform/fuchsia/flutter/main.cc
+9
-5
shell/platform/fuchsia/flutter/runner.cc
shell/platform/fuchsia/flutter/runner.cc
+23
-25
shell/platform/fuchsia/flutter/runner.h
shell/platform/fuchsia/flutter/runner.h
+2
-3
shell/platform/fuchsia/flutter/task_observers.cc
shell/platform/fuchsia/flutter/task_observers.cc
+0
-30
shell/platform/fuchsia/flutter/task_observers.h
shell/platform/fuchsia/flutter/task_observers.h
+0
-21
shell/platform/fuchsia/flutter/task_runner_adapter.cc
shell/platform/fuchsia/flutter/task_runner_adapter.cc
+0
-56
shell/platform/fuchsia/flutter/task_runner_adapter.h
shell/platform/fuchsia/flutter/task_runner_adapter.h
+0
-16
shell/platform/fuchsia/flutter/thread.cc
shell/platform/fuchsia/flutter/thread.cc
+0
-103
shell/platform/fuchsia/flutter/thread.h
shell/platform/fuchsia/flutter/thread.h
+0
-45
shell/platform/fuchsia/flutter/vsync_waiter_unittests.cc
shell/platform/fuchsia/flutter/vsync_waiter_unittests.cc
+9
-18
未找到文件。
ci/licenses_golden/licenses_flutter
浏览文件 @
a50f1ef5
...
...
@@ -1022,8 +1022,6 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/kernel/extract_far.dart
FILE: ../../../flutter/shell/platform/fuchsia/flutter/kernel/framework_shim.dart
FILE: ../../../flutter/shell/platform/fuchsia/flutter/kernel/libraries.json
FILE: ../../../flutter/shell/platform/fuchsia/flutter/logging.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/loop.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/loop.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/main.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/aot_product_runtime
FILE: ../../../flutter/shell/platform/fuchsia/flutter/meta/aot_runtime
...
...
@@ -1046,12 +1044,6 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/session_connection.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/session_connection.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/surface.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/surface.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_observers.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_observers.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_runner_adapter.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_runner_adapter.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/thread.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/thread.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/unique_fdio_ns.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/vsync_recorder.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/vsync_recorder.h
...
...
fml/thread.cc
浏览文件 @
a50f1ef5
...
...
@@ -10,6 +10,8 @@
#if defined(OS_WIN)
#include <windows.h>
#elif defined(OS_FUCHSIA)
#include <lib/zx/thread.h>
#else
#include <pthread.h>
#endif
...
...
@@ -85,6 +87,8 @@ void Thread::SetCurrentThreadName(const std::string& name) {
reinterpret_cast
<
DWORD_PTR
*>
(
&
info
));
}
__except
(
EXCEPTION_CONTINUE_EXECUTION
)
{
}
#elif OS_FUCHSIA
zx
::
thread
::
self
()
->
set_property
(
ZX_PROP_NAME
,
name
.
c_str
(),
name
.
size
());
#else
FML_DLOG
(
INFO
)
<<
"Could not set the thread name to '"
<<
name
<<
"' on this platform."
;
...
...
shell/platform/fuchsia/flutter/BUILD.gn
浏览文件 @
a50f1ef5
...
...
@@ -303,8 +303,6 @@ executable("flutter_runner_unittests") {
"fuchsia_intl.h",
"fuchsia_intl_unittest.cc",
"logging.h",
"loop.cc",
"loop.h",
"platform_view.cc",
"platform_view.h",
"platform_view_unittest.cc",
...
...
@@ -313,12 +311,6 @@ executable("flutter_runner_unittests") {
"runner_unittest.cc",
"surface.cc",
"surface.h",
"task_observers.cc",
"task_observers.h",
"task_runner_adapter.cc",
"task_runner_adapter.h",
"thread.cc",
"thread.h",
"vsync_recorder.cc",
"vsync_recorder.h",
"vsync_waiter.cc",
...
...
shell/platform/fuchsia/flutter/component.cc
浏览文件 @
a50f1ef5
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#define FML_USED_ON_EMBEDDER
#include "component.h"
#include <dlfcn.h>
...
...
@@ -35,10 +37,6 @@
#include "runtime/dart/utils/tempfs.h"
#include "runtime/dart/utils/vmo.h"
#include "task_observers.h"
#include "task_runner_adapter.h"
#include "thread.h"
// TODO(kaushikiska): Use these constants from ::llcpp::fuchsia::io
// Can read from target object.
constexpr
uint32_t
OPEN_RIGHT_READABLE
=
1u
;
...
...
@@ -58,11 +56,11 @@ ActiveApplication Application::Create(
fuchsia
::
sys
::
StartupInfo
startup_info
,
std
::
shared_ptr
<
sys
::
ServiceDirectory
>
runner_incoming_services
,
fidl
::
InterfaceRequest
<
fuchsia
::
sys
::
ComponentController
>
controller
)
{
std
::
unique_ptr
<
Thread
>
thread
=
std
::
make_unique
<
Thread
>
();
std
::
unique_ptr
<
fml
::
Thread
>
thread
=
std
::
make_unique
<
fml
::
Thread
>
();
std
::
unique_ptr
<
Application
>
application
;
fml
::
AutoResetWaitableEvent
latch
;
async
::
PostTask
(
thread
->
dispatch
er
(),
[
&
]()
mutable
{
fml
::
TaskRunner
::
RunNowOrPostTask
(
thread
->
GetTaskRunn
er
(),
[
&
]()
mutable
{
application
.
reset
(
new
Application
(
std
::
move
(
termination_callback
),
std
::
move
(
package
),
std
::
move
(
startup_info
),
runner_incoming_services
,
...
...
@@ -340,12 +338,12 @@ Application::Application(
settings_
.
disable_dart_asserts
=
true
;
#endif
settings_
.
task_observer_add
=
std
::
bind
(
&
CurrentMessageLoopAddAfterTaskObserver
,
std
::
placeholders
::
_1
,
std
::
placeholders
::
_2
)
;
settings_
.
task_observer_remove
=
std
::
bind
(
&
CurrentMessageLoopRemoveAfterTaskObserver
,
std
::
placeholders
::
_1
)
;
settings_
.
task_observer_add
=
[](
intptr_t
key
,
fml
::
closure
callback
)
{
fml
::
MessageLoop
::
GetCurrent
().
AddTaskObserver
(
key
,
std
::
move
(
callback
));
}
;
settings_
.
task_observer_remove
=
[](
intptr_t
key
)
{
fml
::
MessageLoop
::
GetCurrent
().
RemoveTaskObserver
(
key
);
}
;
// TODO(FL-117): Re-enable causal async stack traces when this issue is
// addressed.
...
...
@@ -372,8 +370,7 @@ Application::Application(
#endif // defined(__aarch64__)
auto
weak_application
=
weak_factory_
.
GetWeakPtr
();
auto
platform_task_runner
=
CreateFMLTaskRunner
(
async_get_default_dispatcher
());
auto
platform_task_runner
=
fml
::
MessageLoop
::
GetCurrent
().
GetTaskRunner
();
const
std
::
string
component_url
=
package
.
resolved_url
;
settings_
.
unhandled_exception_callback
=
[
weak_application
,
platform_task_runner
,
...
...
shell/platform/fuchsia/flutter/component.h
浏览文件 @
a50f1ef5
...
...
@@ -24,8 +24,8 @@
#include "engine.h"
#include "flutter/common/settings.h"
#include "flutter/fml/macros.h"
#include "flutter/fml/thread.h"
#include "thread.h"
#include "unique_fdio_ns.h"
namespace
flutter_runner
{
...
...
@@ -33,7 +33,7 @@ namespace flutter_runner {
class
Application
;
struct
ActiveApplication
{
std
::
unique_ptr
<
Thread
>
thread
;
std
::
unique_ptr
<
fml
::
Thread
>
thread
;
std
::
unique_ptr
<
Application
>
application
;
ActiveApplication
&
operator
=
(
ActiveApplication
&&
other
)
noexcept
{
...
...
shell/platform/fuchsia/flutter/engine.cc
浏览文件 @
a50f1ef5
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#define FML_USED_ON_EMBEDDER
#include "engine.h"
#include <lib/async/cpp/task.h>
...
...
@@ -18,9 +20,7 @@
#include "fuchsia_intl.h"
#include "platform_view.h"
#include "runtime/dart/utils/files.h"
#include "task_runner_adapter.h"
#include "third_party/skia/include/ports/SkFontMgr_fuchsia.h"
#include "thread.h"
namespace
flutter_runner
{
...
...
@@ -60,6 +60,10 @@ Engine::Engine(Delegate& delegate,
fidl
::
InterfaceRequest
<
fuchsia
::
io
::
Directory
>
directory_request
)
:
delegate_
(
delegate
),
thread_label_
(
std
::
move
(
thread_label
)),
thread_host_
(
thread_label_
+
"."
,
flutter
::
ThreadHost
::
Type
::
IO
|
flutter
::
ThreadHost
::
Type
::
UI
|
flutter
::
ThreadHost
::
Type
::
GPU
),
settings_
(
std
::
move
(
settings
)),
weak_factory_
(
this
)
{
if
(
zx
::
event
::
create
(
0
,
&
vsync_event_
)
!=
ZX_OK
)
{
...
...
@@ -67,12 +71,6 @@ Engine::Engine(Delegate& delegate,
return
;
}
// Launch the threads that will be used to run the shell. These threads will
// be joined in the destructor.
for
(
auto
&
thread
:
threads_
)
{
thread
.
reset
(
new
Thread
());
}
// Set up the session connection.
auto
scenic
=
svc
->
Connect
<
fuchsia
::
ui
::
scenic
::
Scenic
>
();
fidl
::
InterfaceHandle
<
fuchsia
::
ui
::
scenic
::
Session
>
session
;
...
...
@@ -167,12 +165,14 @@ Engine::Engine(Delegate& delegate,
// Get the task runners from the managed threads. The current thread will be
// used as the "platform" thread.
fml
::
MessageLoop
::
EnsureInitializedForCurrentThread
();
const
flutter
::
TaskRunners
task_runners
(
thread_label_
,
// Dart thread labels
CreateFMLTaskRunner
(
async_get_default_dispatcher
()
),
// platform
CreateFMLTaskRunner
(
threads_
[
0
]
->
dispatcher
()),
// gpu
CreateFMLTaskRunner
(
threads_
[
1
]
->
dispatcher
()),
// ui
CreateFMLTaskRunner
(
threads_
[
2
]
->
dispatcher
())
// io
thread_label_
,
// Dart thread labels
fml
::
MessageLoop
::
GetCurrent
().
GetTaskRunner
(
),
// platform
thread_host_
.
gpu_thread
->
GetTaskRunner
(),
// gpu
thread_host_
.
ui_thread
->
GetTaskRunner
(),
// ui
thread_host_
.
io_thread
->
GetTaskRunner
()
// io
);
// Setup the callback that will instantiate the rasterizer.
...
...
@@ -352,12 +352,6 @@ Engine::Engine(Delegate& delegate,
Engine
::~
Engine
()
{
shell_
.
reset
();
for
(
const
auto
&
thread
:
threads_
)
{
thread
->
Quit
();
}
for
(
const
auto
&
thread
:
threads_
)
{
thread
->
Join
();
}
}
std
::
pair
<
bool
,
uint32_t
>
Engine
::
GetEngineReturnCode
()
const
{
...
...
shell/platform/fuchsia/flutter/engine.h
浏览文件 @
a50f1ef5
...
...
@@ -16,8 +16,8 @@
#include "flutter/fml/macros.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/thread_host.h"
#include "isolate_configurator.h"
#include "thread.h"
namespace
flutter_runner
{
...
...
@@ -53,8 +53,8 @@ class Engine final {
private:
Delegate
&
delegate_
;
const
std
::
string
thread_label_
;
flutter
::
ThreadHost
thread_host_
;
flutter
::
Settings
settings_
;
std
::
array
<
std
::
unique_ptr
<
Thread
>
,
3
>
threads_
;
std
::
unique_ptr
<
IsolateConfigurator
>
isolate_configurator_
;
std
::
unique_ptr
<
flutter
::
Shell
>
shell_
;
zx
::
event
vsync_event_
;
...
...
shell/platform/fuchsia/flutter/engine_flutter_runner.gni
浏览文件 @
a50f1ef5
...
...
@@ -55,8 +55,6 @@ template("flutter_runner") {
"isolate_configurator.cc",
"isolate_configurator.h",
"logging.h",
"loop.cc",
"loop.h",
"main.cc",
"platform_view.cc",
"platform_view.h",
...
...
@@ -66,12 +64,6 @@ template("flutter_runner") {
"session_connection.h",
"surface.cc",
"surface.h",
"task_observers.cc",
"task_observers.h",
"task_runner_adapter.cc",
"task_runner_adapter.h",
"thread.cc",
"thread.h",
"unique_fdio_ns.h",
"vsync_recorder.cc",
"vsync_recorder.h",
...
...
shell/platform/fuchsia/flutter/fuchsia_intl.cc
浏览文件 @
a50f1ef5
...
...
@@ -8,7 +8,6 @@
#include <string>
#include <vector>
#include "loop.h"
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
...
...
shell/platform/fuchsia/flutter/loop.cc
已删除
100644 → 0
浏览文件 @
27a221d6
// Copyright 2013 The Flutter 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 "loop.h"
#include <lib/async-loop/loop.h>
#include <lib/async/default.h>
#include "task_observers.h"
namespace
flutter_runner
{
namespace
{
static
void
LoopEpilogue
(
async_loop_t
*
,
void
*
)
{
ExecuteAfterTaskObservers
();
}
constexpr
async_loop_config_t
kAttachedLoopConfig
=
{
.
default_accessors
=
{
.
getter
=
async_get_default_dispatcher
,
.
setter
=
async_set_default_dispatcher
,
},
.
make_default_for_current_thread
=
true
,
.
epilogue
=
&
LoopEpilogue
,
};
constexpr
async_loop_config_t
kDetachedLoopConfig
=
{
.
default_accessors
=
{
.
getter
=
async_get_default_dispatcher
,
.
setter
=
async_set_default_dispatcher
,
},
.
make_default_for_current_thread
=
false
,
.
epilogue
=
&
LoopEpilogue
,
};
}
// namespace
async
::
Loop
*
MakeObservableLoop
(
bool
attachToThread
)
{
return
new
async
::
Loop
(
&
(
attachToThread
?
kAttachedLoopConfig
:
kDetachedLoopConfig
));
}
}
// namespace flutter_runner
shell/platform/fuchsia/flutter/loop.h
已删除
100644 → 0
浏览文件 @
27a221d6
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_LOOP_H_
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_LOOP_H_
#include <lib/async-loop/cpp/loop.h>
namespace
flutter_runner
{
// Creates a loop which allows task observers to be attached to it.
async
::
Loop
*
MakeObservableLoop
(
bool
attachToThread
);
}
// namespace flutter_runner
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_LOOP_H_
shell/platform/fuchsia/flutter/main.cc
浏览文件 @
a50f1ef5
...
...
@@ -2,18 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#define FML_USED_ON_EMBEDDER
#include <lib/async-loop/cpp/loop.h>
#include <lib/async-loop/default.h>
#include <lib/trace-provider/provider.h>
#include <lib/trace/event.h>
#include <cstdlib>
#include "loop.h"
#include "runner.h"
#include "runtime/dart/utils/tempfs.h"
int
main
(
int
argc
,
char
const
*
argv
[])
{
std
::
unique_ptr
<
async
::
Loop
>
loop
(
flutter_runner
::
MakeObservableLoop
(
true
));
fml
::
MessageLoop
::
EnsureInitializedForCurrentThread
();
auto
&
message_loop
=
fml
::
MessageLoop
::
GetCurrent
();
std
::
unique_ptr
<
trace
::
TraceProviderWithFdio
>
provider
;
{
...
...
@@ -21,7 +24,8 @@ int main(int argc, char const* argv[]) {
bool
already_started
;
// Use CreateSynchronously to prevent loss of early events.
trace
::
TraceProviderWithFdio
::
CreateSynchronously
(
loop
->
dispatcher
(),
"flutter_runner"
,
&
provider
,
&
already_started
);
async_get_default_dispatcher
(),
"flutter_runner"
,
&
provider
,
&
already_started
);
}
// Set up the process-wide /tmp memfs.
...
...
@@ -29,9 +33,9 @@ int main(int argc, char const* argv[]) {
FML_DLOG
(
INFO
)
<<
"Flutter application services initialized."
;
flutter_runner
::
Runner
runner
(
loop
.
get
()
);
flutter_runner
::
Runner
runner
(
message_loop
);
loop
->
Run
();
message_loop
.
Run
();
FML_DLOG
(
INFO
)
<<
"Flutter application services terminated."
;
...
...
shell/platform/fuchsia/flutter/runner.cc
浏览文件 @
a50f1ef5
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#define FML_USED_ON_EMBEDDER
#include "runner.h"
#include <fuchsia/mem/cpp/fidl.h>
...
...
@@ -128,11 +130,6 @@ static void SetProcessName() {
zx
::
process
::
self
()
->
set_property
(
ZX_PROP_NAME
,
name
.
c_str
(),
name
.
size
());
}
static
void
SetThreadName
(
const
std
::
string
&
thread_name
)
{
zx
::
thread
::
self
()
->
set_property
(
ZX_PROP_NAME
,
thread_name
.
c_str
(),
thread_name
.
size
());
}
#if !defined(DART_PRODUCT)
// Register native symbol information for the Dart VM's profiler.
static
void
RegisterProfilerSymbols
(
const
char
*
symbols_path
,
...
...
@@ -146,8 +143,8 @@ static void RegisterProfilerSymbols(const char* symbols_path,
}
#endif // !defined(DART_PRODUCT)
Runner
::
Runner
(
async
::
Loop
*
loop
)
:
loop_
(
loop
),
context_
(
sys
::
ComponentContext
::
Create
())
{
Runner
::
Runner
(
fml
::
MessageLoop
&
message_
loop
)
:
message_loop_
(
message_
loop
),
context_
(
sys
::
ComponentContext
::
Create
())
{
#if !defined(DART_PRODUCT)
// The VM service isolate uses the process-wide namespace. It writes the
// vm service protocol port under /tmp. The VMServiceObject exposes that
...
...
@@ -165,7 +162,7 @@ Runner::Runner(async::Loop* loop)
SetProcessName
();
Se
tThreadName
(
"io.flutter.runner.main"
);
fml
::
Thread
::
SetCurren
tThreadName
(
"io.flutter.runner.main"
);
context_
->
outgoing
()
->
AddPublicService
<
fuchsia
::
sys
::
Runner
>
(
std
::
bind
(
&
Runner
::
RegisterApplication
,
this
,
std
::
placeholders
::
_1
));
...
...
@@ -214,12 +211,13 @@ void Runner::StartComponent(
// there being multiple application runner instance in the process at the same
// time. So it is safe to use the raw pointer.
Application
::
TerminationCallback
termination_callback
=
[
task_runner
=
loop_
->
dispatch
er
(),
//
application_runner
=
this
//
[
task_runner
=
message_loop_
.
GetTaskRunn
er
(),
//
application_runner
=
this
//
](
const
Application
*
application
)
{
async
::
PostTask
(
task_runner
,
[
application_runner
,
application
]()
{
application_runner
->
OnApplicationTerminate
(
application
);
});
fml
::
TaskRunner
::
RunNowOrPostTask
(
task_runner
,
[
application_runner
,
application
]()
{
application_runner
->
OnApplicationTerminate
(
application
);
});
};
auto
active_application
=
Application
::
Create
(
...
...
@@ -254,13 +252,11 @@ void Runner::OnApplicationTerminate(const Application* application) {
active_applications_
.
erase
(
application
);
// Post the task to destroy the application and quit its message loop.
async
::
PostTask
(
application_thread
->
dispatcher
(),
fml
::
MakeCopyable
([
instance
=
std
::
move
(
application_to_destroy
),
thread
=
application_thread
.
get
()]()
mutable
{
instance
.
reset
();
thread
->
Quit
();
}));
fml
::
TaskRunner
::
RunNowOrPostTask
(
application_thread
->
GetTaskRunner
(),
fml
::
MakeCopyable
(
[
instance
=
std
::
move
(
application_to_destroy
),
thread
=
application_thread
.
get
()]()
mutable
{
instance
.
reset
();
}));
// This works because just posted the quit task on the hosted thread.
application_thread
->
Join
();
...
...
@@ -287,7 +283,8 @@ bool Runner::SetupTZDataInternal() {
#if !defined(DART_PRODUCT)
void
Runner
::
SetupTraceObserver
()
{
trace_observer_
=
std
::
make_unique
<
trace
::
TraceObserver
>
();
trace_observer_
->
Start
(
loop_
->
dispatcher
(),
[
runner
=
this
]()
{
FML_DCHECK
(
message_loop_
.
GetTaskRunner
()
->
RunsTasksOnCurrentThread
());
trace_observer_
->
Start
(
async_get_default_dispatcher
(),
[
runner
=
this
]()
{
if
(
!
trace_is_category_enabled
(
"dart:profiler"
))
{
return
;
}
...
...
@@ -297,10 +294,11 @@ void Runner::SetupTraceObserver() {
}
else
if
(
trace_state
()
==
TRACE_STOPPING
)
{
for
(
auto
&
it
:
runner
->
active_applications_
)
{
fml
::
AutoResetWaitableEvent
latch
;
async
::
PostTask
(
it
.
second
.
thread
->
dispatcher
(),
[
&
]()
{
it
.
second
.
application
->
WriteProfileToTrace
();
latch
.
Signal
();
});
fml
::
TaskRunner
::
RunNowOrPostTask
(
it
.
second
.
thread
->
GetTaskRunner
(),
[
&
]()
{
it
.
second
.
application
->
WriteProfileToTrace
();
latch
.
Signal
();
});
latch
.
Wait
();
}
Dart_StopProfiling
();
...
...
shell/platform/fuchsia/flutter/runner.h
浏览文件 @
a50f1ef5
...
...
@@ -25,13 +25,12 @@ namespace flutter_runner {
// their own threads.
class
Runner
final
:
public
fuchsia
::
sys
::
Runner
{
public:
explicit
Runner
(
async
::
Loop
*
loop
);
explicit
Runner
(
fml
::
MessageLoop
&
message_
loop
);
~
Runner
();
private:
async
::
Loop
*
loop_
;
fml
::
MessageLoop
&
message_loop_
;
std
::
unique_ptr
<
sys
::
ComponentContext
>
context_
;
fidl
::
BindingSet
<
fuchsia
::
sys
::
Runner
>
active_applications_bindings_
;
std
::
unordered_map
<
const
Application
*
,
ActiveApplication
>
...
...
shell/platform/fuchsia/flutter/task_observers.cc
已删除
100644 → 0
浏览文件 @
27a221d6
// Copyright 2013 The Flutter 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 "task_observers.h"
#include <map>
namespace
flutter_runner
{
thread_local
std
::
map
<
intptr_t
,
fit
::
closure
>
tTaskObservers
;
void
ExecuteAfterTaskObservers
()
{
for
(
const
auto
&
callback
:
tTaskObservers
)
{
callback
.
second
();
}
}
void
CurrentMessageLoopAddAfterTaskObserver
(
intptr_t
key
,
fit
::
closure
observer
)
{
if
(
observer
)
{
tTaskObservers
[
key
]
=
std
::
move
(
observer
);
}
}
void
CurrentMessageLoopRemoveAfterTaskObserver
(
intptr_t
key
)
{
tTaskObservers
.
erase
(
key
);
}
}
// namespace flutter_runner
shell/platform/fuchsia/flutter/task_observers.h
已删除
100644 → 0
浏览文件 @
27a221d6
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_TASK_OBSERVERS_H_
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_TASK_OBSERVERS_H_
#include <lib/fit/function.h>
namespace
flutter_runner
{
void
ExecuteAfterTaskObservers
();
void
CurrentMessageLoopAddAfterTaskObserver
(
intptr_t
key
,
fit
::
closure
observer
);
void
CurrentMessageLoopRemoveAfterTaskObserver
(
intptr_t
key
);
}
// namespace flutter_runner
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_TASK_OBSERVERS_H_
shell/platform/fuchsia/flutter/task_runner_adapter.cc
已删除
100644 → 0
浏览文件 @
27a221d6
// Copyright 2013 The Flutter 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 "task_runner_adapter.h"
#include <lib/async/cpp/task.h>
#include <lib/async/default.h>
#include <lib/zx/time.h>
#include "flutter/fml/message_loop_impl.h"
namespace
flutter_runner
{
class
CompatTaskRunner
:
public
fml
::
TaskRunner
{
public:
CompatTaskRunner
(
async_dispatcher_t
*
dispatcher
)
:
fml
::
TaskRunner
(
nullptr
),
forwarding_target_
(
dispatcher
)
{
FML_DCHECK
(
forwarding_target_
);
}
void
PostTask
(
const
fml
::
closure
&
task
)
override
{
async
::
PostTask
(
forwarding_target_
,
task
);
}
void
PostTaskForTime
(
const
fml
::
closure
&
task
,
fml
::
TimePoint
target_time
)
override
{
async
::
PostTaskForTime
(
forwarding_target_
,
task
,
zx
::
time
(
target_time
.
ToEpochDelta
().
ToNanoseconds
()));
}
void
PostDelayedTask
(
const
fml
::
closure
&
task
,
fml
::
TimeDelta
delay
)
override
{
async
::
PostDelayedTask
(
forwarding_target_
,
task
,
zx
::
duration
(
delay
.
ToNanoseconds
()));
}
bool
RunsTasksOnCurrentThread
()
override
{
return
forwarding_target_
==
async_get_default_dispatcher
();
}
private:
async_dispatcher_t
*
forwarding_target_
;
FML_DISALLOW_COPY_AND_ASSIGN
(
CompatTaskRunner
);
FML_FRIEND_MAKE_REF_COUNTED
(
CompatTaskRunner
);
FML_FRIEND_REF_COUNTED_THREAD_SAFE
(
CompatTaskRunner
);
};
fml
::
RefPtr
<
fml
::
TaskRunner
>
CreateFMLTaskRunner
(
async_dispatcher_t
*
dispatcher
)
{
return
fml
::
MakeRefCounted
<
CompatTaskRunner
>
(
dispatcher
);
}
}
// namespace flutter_runner
shell/platform/fuchsia/flutter/task_runner_adapter.h
已删除
100644 → 0
浏览文件 @
27a221d6
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#pragma once
#include <lib/async/dispatcher.h>
#include "flutter/fml/task_runner.h"
namespace
flutter_runner
{
fml
::
RefPtr
<
fml
::
TaskRunner
>
CreateFMLTaskRunner
(
async_dispatcher_t
*
dispatcher
);
}
// namespace flutter_runner
shell/platform/fuchsia/flutter/thread.cc
已删除
100644 → 0
浏览文件 @
27a221d6
// Copyright 2013 The Flutter 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 "thread.h"
#include <limits.h>
#include <unistd.h>
#include <algorithm>
#include <lib/async-loop/cpp/loop.h>
#include "flutter/fml/logging.h"
#include "loop.h"
namespace
flutter_runner
{
typedef
void
(
*
ThreadEntry
)(
Thread
*
);
namespace
{
size_t
NextPageSizeMultiple
(
size_t
size
)
{
const
size_t
page_size
=
sysconf
(
_SC_PAGE_SIZE
);
FML_CHECK
(
page_size
!=
0
);
size
=
std
::
max
<
size_t
>
(
size
,
page_size
);
size_t
rem
=
size
%
page_size
;
if
(
rem
==
0
)
{
return
size
;
}
return
size
+
page_size
-
rem
;
}
bool
CreateThread
(
pthread_t
*
thread
,
ThreadEntry
main
,
Thread
*
argument
,
size_t
stack_size
)
{
pthread_attr_t
thread_attributes
;
if
(
pthread_attr_init
(
&
thread_attributes
)
!=
0
)
{
return
false
;
}
stack_size
=
std
::
max
<
size_t
>
(
NextPageSizeMultiple
(
PTHREAD_STACK_MIN
),
NextPageSizeMultiple
(
stack_size
));
if
(
pthread_attr_setstacksize
(
&
thread_attributes
,
stack_size
)
!=
0
)
{
return
false
;
}
auto
result
=
pthread_create
(
thread
,
&
thread_attributes
,
reinterpret_cast
<
void
*
(
*
)(
void
*
)
>
(
main
),
argument
);
pthread_attr_destroy
(
&
thread_attributes
);
return
result
==
0
;
}
}
// anonymous namespace
Thread
::
Thread
()
{
loop_
.
reset
(
MakeObservableLoop
(
false
));
valid_
=
CreateThread
(
&
thread_
,
[](
Thread
*
thread
)
{
thread
->
Main
();
},
this
,
1
<<
20
);
}
Thread
::~
Thread
()
{
Join
();
}
bool
Thread
::
IsValid
()
const
{
return
valid_
;
}
async_dispatcher_t
*
Thread
::
dispatcher
()
const
{
return
loop_
->
dispatcher
();
}
void
Thread
::
Main
()
{
async_set_default_dispatcher
(
loop_
->
dispatcher
());
loop_
->
Run
();
}
void
Thread
::
Quit
()
{
loop_
->
Quit
();
}
bool
Thread
::
Join
()
{
if
(
!
valid_
)
{
return
false
;
}
bool
result
=
pthread_join
(
thread_
,
nullptr
)
==
0
;
valid_
=
false
;
return
result
;
}
}
// namespace flutter_runner
shell/platform/fuchsia/flutter/thread.h
已删除
100644 → 0
浏览文件 @
27a221d6
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_THREAD_H_
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_THREAD_H_
#include <pthread.h>
#include <functional>
#include <lib/async-loop/cpp/loop.h>
#include <lib/async/default.h>
#include "flutter/fml/macros.h"
namespace
flutter_runner
{
class
Thread
{
public:
Thread
();
~
Thread
();
void
Quit
();
bool
Join
();
bool
IsValid
()
const
;
async_dispatcher_t
*
dispatcher
()
const
;
private:
bool
valid_
;
pthread_t
thread_
;
std
::
unique_ptr
<
async
::
Loop
>
loop_
;
void
Main
();
FML_DISALLOW_COPY_AND_ASSIGN
(
Thread
);
};
}
// namespace flutter_runner
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_THREAD_H_
shell/platform/fuchsia/flutter/vsync_waiter_unittests.cc
浏览文件 @
a50f1ef5
...
...
@@ -14,8 +14,6 @@
#include "flutter/fml/time/time_point.h"
#include "flutter/shell/common/thread_host.h"
#include "flutter/shell/common/vsync_waiter.h"
#include "flutter/shell/platform/fuchsia/flutter/task_runner_adapter.h"
#include "flutter/shell/platform/fuchsia/flutter/thread.h"
#include "flutter/shell/platform/fuchsia/flutter/vsync_waiter.h"
namespace
flutter_runner_test
{
...
...
@@ -50,21 +48,17 @@ class VsyncWaiterTest : public testing::Test {
};
TEST_F
(
VsyncWaiterTest
,
AwaitVsync
)
{
std
::
array
<
std
::
unique_ptr
<
flutter_runner
::
Thread
>
,
3
>
threads
;
for
(
auto
&
thread
:
threads
)
{
thread
.
reset
(
new
flutter_runner
::
Thread
());
}
async
::
Loop
loop
(
&
kAsyncLoopConfigAttachToCurrentThread
);
flutter
::
ThreadHost
thread_host
(
"VsyncWaiterTests."
,
flutter
::
ThreadHost
::
Type
::
Platform
|
flutter
::
ThreadHost
::
Type
::
IO
|
flutter
::
ThreadHost
::
Type
::
UI
|
flutter
::
ThreadHost
::
Type
::
GPU
);
const
flutter
::
TaskRunners
task_runners
(
"VsyncWaiterTests"
,
// Dart thread labels
flutter_runner
::
CreateFMLTaskRunner
(
async_get_default_dispatcher
()),
// platform
flutter_runner
::
CreateFMLTaskRunner
(
threads
[
0
]
->
dispatcher
()),
// gpu
flutter_runner
::
CreateFMLTaskRunner
(
threads
[
1
]
->
dispatcher
()),
// ui
flutter_runner
::
CreateFMLTaskRunner
(
threads
[
2
]
->
dispatcher
())
// io
"VsyncWaiterTests"
,
// Dart thread labels
thread_host
.
platform_thread
->
GetTaskRunner
(),
// platform
thread_host
.
gpu_thread
->
GetTaskRunner
(),
// gpu
thread_host
.
ui_thread
->
GetTaskRunner
(),
// ui
thread_host
.
io_thread
->
GetTaskRunner
()
// io
);
auto
vsync_waiter
=
CreateVsyncWaiter
(
std
::
move
(
task_runners
));
...
...
@@ -82,9 +76,6 @@ TEST_F(VsyncWaiterTest, AwaitVsync) {
EXPECT_FALSE
(
did_timeout
);
vsync_waiter
.
reset
();
for
(
const
auto
&
thread
:
threads
)
{
thread
->
Quit
();
}
}
TEST_F
(
VsyncWaiterTest
,
SnapToNextPhaseOverlapsWithNow
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录