Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
cc44ca5d
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
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,发现更多精彩内容 >>
未验证
提交
cc44ca5d
编写于
9月 26, 2018
作者:
C
Chinmay Garde
提交者:
GitHub
9月 26, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Perform persistent cache stores on the IO thread outside the frame workload. (#6350)
上级
f2a3df97
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
108 addition
and
22 deletion
+108
-22
shell/common/persistent_cache.cc
shell/common/persistent_cache.cc
+85
-21
shell/common/persistent_cache.h
shell/common/persistent_cache.h
+16
-1
shell/common/shell.cc
shell/common/shell.cc
+7
-0
未找到文件。
shell/common/persistent_cache.cc
浏览文件 @
cc44ca5d
...
...
@@ -9,6 +9,7 @@
#include "flutter/fml/base32.h"
#include "flutter/fml/file.h"
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/mapping.h"
#include "flutter/fml/paths.h"
#include "flutter/fml/trace_event.h"
...
...
@@ -40,15 +41,16 @@ PersistentCache* PersistentCache::GetCacheForProcess() {
}
PersistentCache
::
PersistentCache
()
:
cache_directory_
(
CreateDirectory
(
fml
::
paths
::
GetCachesDirectory
(),
{
"flutter_engine"
,
//
GetFlutterEngineVersion
(),
//
"skia"
,
//
GetSkiaVersion
()
//
},
fml
::
FilePermission
::
kReadWrite
))
{
if
(
!
cache_directory_
.
is_valid
())
{
:
cache_directory_
(
std
::
make_shared
<
fml
::
UniqueFD
>
(
CreateDirectory
(
fml
::
paths
::
GetCachesDirectory
(),
{
"flutter_engine"
,
//
GetFlutterEngineVersion
(),
//
"skia"
,
//
GetSkiaVersion
()
//
},
fml
::
FilePermission
::
kReadWrite
)))
{
if
(
!
IsValid
())
{
FML_LOG
(
ERROR
)
<<
"Could not acquire the persistent cache directory. "
"Caching of GPU resources on disk is disabled."
;
}
...
...
@@ -56,17 +58,21 @@ PersistentCache::PersistentCache()
PersistentCache
::~
PersistentCache
()
=
default
;
bool
PersistentCache
::
IsValid
()
const
{
return
cache_directory_
&&
cache_directory_
->
is_valid
();
}
// |GrContextOptions::PersistentCache|
sk_sp
<
SkData
>
PersistentCache
::
load
(
const
SkData
&
key
)
{
TRACE_EVENT0
(
"flutter"
,
"PersistentCacheLoad"
);
if
(
!
cache_directory_
.
is_v
alid
())
{
if
(
!
IsV
alid
())
{
return
nullptr
;
}
auto
file_name
=
SkKeyToFilePath
(
key
);
if
(
file_name
.
size
()
==
0
)
{
return
nullptr
;
}
auto
file
=
fml
::
OpenFile
(
cache_directory_
,
file_name
.
c_str
(),
false
,
auto
file
=
fml
::
OpenFile
(
*
cache_directory_
,
file_name
.
c_str
(),
false
,
fml
::
FilePermission
::
kRead
);
if
(
!
file
.
is_valid
())
{
return
nullptr
;
...
...
@@ -80,23 +86,81 @@ sk_sp<SkData> PersistentCache::load(const SkData& key) {
return
SkData
::
MakeWithCopy
(
mapping
->
GetMapping
(),
mapping
->
GetSize
());
}
static
void
PersistentCacheStore
(
fml
::
RefPtr
<
fml
::
TaskRunner
>
worker
,
std
::
shared_ptr
<
fml
::
UniqueFD
>
cache_directory
,
std
::
string
key
,
std
::
unique_ptr
<
fml
::
Mapping
>
value
)
{
auto
task
=
fml
::
MakeCopyable
([
cache_directory
,
//
file_name
=
std
::
move
(
key
),
//
mapping
=
std
::
move
(
value
)
//
]()
mutable
{
TRACE_EVENT0
(
"flutter"
,
"PersistentCacheStore"
);
if
(
!
fml
::
WriteAtomically
(
*
cache_directory
,
//
file_name
.
c_str
(),
//
*
mapping
)
//
)
{
FML_DLOG
(
ERROR
)
<<
"Could not write cache contents to persistent store."
;
}
});
if
(
!
worker
)
{
FML_LOG
(
ERROR
)
<<
"The persistent cache has no available workers. Performing the task "
"on the current thread. This slow operation is going to occur on a "
"frame workload."
;
task
();
}
else
{
worker
->
PostTask
(
std
::
move
(
task
));
}
}
// |GrContextOptions::PersistentCache|
void
PersistentCache
::
store
(
const
SkData
&
key
,
const
SkData
&
data
)
{
TRACE_EVENT0
(
"flutter"
,
"PersistentCacheStore"
);
if
(
!
cache_directory_
.
is_valid
())
{
if
(
!
IsValid
())
{
return
;
}
auto
file_name
=
SkKeyToFilePath
(
key
);
auto
mapping
=
std
::
make_unique
<
fml
::
NonOwnedMapping
>
(
data
.
bytes
(),
data
.
size
());
if
(
!
fml
::
WriteAtomically
(
cache_directory_
,
//
file_name
.
c_str
(),
//
*
mapping
)
//
)
{
FML_DLOG
(
ERROR
)
<<
"Could not write cache contents to persistent store."
;
if
(
file_name
.
size
()
==
0
)
{
return
;
}
auto
mapping
=
std
::
make_unique
<
fml
::
DataMapping
>
(
std
::
vector
<
uint8_t
>
{
data
.
bytes
(),
data
.
bytes
()
+
data
.
size
()});
if
(
mapping
==
nullptr
||
mapping
->
GetSize
()
==
0
)
{
return
;
}
PersistentCacheStore
(
GetWorkerTaskRunner
(),
cache_directory_
,
std
::
move
(
file_name
),
std
::
move
(
mapping
));
}
void
PersistentCache
::
AddWorkerTaskRunner
(
fml
::
RefPtr
<
fml
::
TaskRunner
>
task_runner
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
worker_task_runners_mutex_
);
worker_task_runners_
.
insert
(
task_runner
);
}
void
PersistentCache
::
RemoveWorkerTaskRunner
(
fml
::
RefPtr
<
fml
::
TaskRunner
>
task_runner
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
worker_task_runners_mutex_
);
auto
found
=
worker_task_runners_
.
find
(
task_runner
);
if
(
found
!=
worker_task_runners_
.
end
())
{
worker_task_runners_
.
erase
(
found
);
}
}
fml
::
RefPtr
<
fml
::
TaskRunner
>
PersistentCache
::
GetWorkerTaskRunner
()
const
{
fml
::
RefPtr
<
fml
::
TaskRunner
>
worker
;
std
::
lock_guard
<
std
::
mutex
>
lock
(
worker_task_runners_mutex_
);
if
(
!
worker_task_runners_
.
empty
())
{
worker
=
*
worker_task_runners_
.
begin
();
}
return
worker
;
}
}
// namespace shell
shell/common/persistent_cache.h
浏览文件 @
cc44ca5d
...
...
@@ -5,9 +5,13 @@
#ifndef FLUTTER_SHELL_COMMON_PERSISTENT_CACHE_H_
#define FLUTTER_SHELL_COMMON_PERSISTENT_CACHE_H_
#include <memory>
#include <mutex>
#include <set>
#include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/fml/task_runner.h"
#include "flutter/fml/unique_fd.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"
...
...
@@ -19,8 +23,17 @@ class PersistentCache : public GrContextOptions::PersistentCache {
~
PersistentCache
()
override
;
void
AddWorkerTaskRunner
(
fml
::
RefPtr
<
fml
::
TaskRunner
>
task_runner
);
void
RemoveWorkerTaskRunner
(
fml
::
RefPtr
<
fml
::
TaskRunner
>
task_runner
);
private:
fml
::
UniqueFD
cache_directory_
;
std
::
shared_ptr
<
fml
::
UniqueFD
>
cache_directory_
;
mutable
std
::
mutex
worker_task_runners_mutex_
;
std
::
multiset
<
fml
::
RefPtr
<
fml
::
TaskRunner
>>
worker_task_runners_
FML_GUARDED_BY
(
worker_task_runners_mutex_
);
bool
IsValid
()
const
;
PersistentCache
();
...
...
@@ -30,6 +43,8 @@ class PersistentCache : public GrContextOptions::PersistentCache {
// |GrContextOptions::PersistentCache|
void
store
(
const
SkData
&
key
,
const
SkData
&
data
)
override
;
fml
::
RefPtr
<
fml
::
TaskRunner
>
GetWorkerTaskRunner
()
const
;
FML_DISALLOW_COPY_AND_ASSIGN
(
PersistentCache
);
};
...
...
shell/common/shell.cc
浏览文件 @
cc44ca5d
...
...
@@ -23,6 +23,7 @@
#include "flutter/runtime/dart_vm.h"
#include "flutter/runtime/start_up.h"
#include "flutter/shell/common/engine.h"
#include "flutter/shell/common/persistent_cache.h"
#include "flutter/shell/common/skia_event_tracer_impl.h"
#include "flutter/shell/common/switches.h"
#include "flutter/shell/common/vsync_waiter.h"
...
...
@@ -293,6 +294,9 @@ Shell::Shell(blink::TaskRunners task_runners, blink::Settings settings)
}
Shell
::~
Shell
()
{
PersistentCache
::
GetCacheForProcess
()
->
RemoveWorkerTaskRunner
(
task_runners_
.
GetIOTaskRunner
());
if
(
auto
vm
=
blink
::
DartVM
::
ForProcessIfInitialized
())
{
vm
->
GetServiceProtocol
().
RemoveHandler
(
this
);
}
...
...
@@ -370,6 +374,9 @@ bool Shell::Setup(std::unique_ptr<PlatformView> platform_view,
vm
->
GetServiceProtocol
().
AddHandler
(
this
);
}
PersistentCache
::
GetCacheForProcess
()
->
AddWorkerTaskRunner
(
task_runners_
.
GetIOTaskRunner
());
return
true
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录