Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
9fcfec39
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,发现更多精彩内容 >>
未验证
提交
9fcfec39
编写于
6月 18, 2020
作者:
J
Jason Simmons
提交者:
GitHub
6月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid creating a vector when constructing Dart typed data objects for platform messages (#18838)
上级
1551b742
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
31 addition
and
54 deletion
+31
-54
lib/ui/window/platform_message_response_dart.cc
lib/ui/window/platform_message_response_dart.cc
+3
-33
lib/ui/window/window.cc
lib/ui/window/window.cc
+3
-16
lib/ui/window/window.h
lib/ui/window/window.h
+0
-2
third_party/tonic/typed_data/dart_byte_data.cc
third_party/tonic/typed_data/dart_byte_data.cc
+25
-3
未找到文件。
lib/ui/window/platform_message_response_dart.cc
浏览文件 @
9fcfec39
...
...
@@ -8,43 +8,12 @@
#include "flutter/common/task_runners.h"
#include "flutter/fml/make_copyable.h"
#include "flutter/lib/ui/window/window.h"
#include "third_party/tonic/dart_state.h"
#include "third_party/tonic/logging/dart_invoke.h"
#include "third_party/tonic/typed_data/dart_byte_data.h"
namespace
flutter
{
namespace
{
// Avoid copying the contents of messages beyond a certain size.
const
int
kMessageCopyThreshold
=
1000
;
void
MessageDataFinalizer
(
void
*
isolate_callback_data
,
Dart_WeakPersistentHandle
handle
,
void
*
peer
)
{
std
::
vector
<
uint8_t
>*
data
=
reinterpret_cast
<
std
::
vector
<
uint8_t
>*>
(
peer
);
delete
data
;
}
Dart_Handle
WrapByteData
(
std
::
vector
<
uint8_t
>
data
)
{
if
(
data
.
size
()
<
kMessageCopyThreshold
)
{
return
ToByteData
(
data
);
}
else
{
std
::
vector
<
uint8_t
>*
heap_data
=
new
std
::
vector
<
uint8_t
>
(
std
::
move
(
data
));
return
Dart_NewExternalTypedDataWithFinalizer
(
Dart_TypedData_kByteData
,
heap_data
->
data
(),
heap_data
->
size
(),
heap_data
,
heap_data
->
size
(),
MessageDataFinalizer
);
}
}
Dart_Handle
WrapByteData
(
std
::
unique_ptr
<
fml
::
Mapping
>
mapping
)
{
std
::
vector
<
uint8_t
>
data
(
mapping
->
GetSize
());
memcpy
(
data
.
data
(),
mapping
->
GetMapping
(),
mapping
->
GetSize
());
return
WrapByteData
(
std
::
move
(
data
));
}
}
// anonymous namespace
PlatformMessageResponseDart
::
PlatformMessageResponseDart
(
tonic
::
DartPersistentValue
callback
,
fml
::
RefPtr
<
fml
::
TaskRunner
>
ui_task_runner
)
...
...
@@ -71,7 +40,8 @@ void PlatformMessageResponseDart::Complete(std::unique_ptr<fml::Mapping> data) {
return
;
tonic
::
DartState
::
Scope
scope
(
dart_state
);
Dart_Handle
byte_buffer
=
WrapByteData
(
std
::
move
(
data
));
Dart_Handle
byte_buffer
=
tonic
::
DartByteData
::
Create
(
data
->
GetMapping
(),
data
->
GetSize
());
tonic
::
DartInvoke
(
callback
.
Release
(),
{
byte_buffer
});
}));
}
...
...
lib/ui/window/window.cc
浏览文件 @
9fcfec39
...
...
@@ -166,25 +166,12 @@ void GetPersistentIsolateData(Dart_NativeArguments args) {
persistent_isolate_data
->
GetSize
()));
}
}
// namespace
Dart_Handle
ToByteData
(
const
std
::
vector
<
uint8_t
>&
buffer
)
{
Dart_Handle
data_handle
=
Dart_NewTypedData
(
Dart_TypedData_kByteData
,
buffer
.
size
());
if
(
Dart_IsError
(
data_handle
))
return
data_handle
;
Dart_TypedData_Type
type
;
void
*
data
=
nullptr
;
intptr_t
num_bytes
=
0
;
FML_CHECK
(
!
Dart_IsError
(
Dart_TypedDataAcquireData
(
data_handle
,
&
type
,
&
data
,
&
num_bytes
)));
memcpy
(
data
,
buffer
.
data
(),
num_bytes
);
Dart_TypedDataReleaseData
(
data_handle
);
return
data_handle
;
return
tonic
::
DartByteData
::
Create
(
buffer
.
data
(),
buffer
.
size
());
}
}
// namespace
WindowClient
::~
WindowClient
()
{}
Window
::
Window
(
WindowClient
*
client
)
:
client_
(
client
)
{}
...
...
lib/ui/window/window.h
浏览文件 @
9fcfec39
...
...
@@ -35,8 +35,6 @@ namespace flutter {
class
FontCollection
;
class
Scene
;
Dart_Handle
ToByteData
(
const
std
::
vector
<
uint8_t
>&
buffer
);
// Must match the AccessibilityFeatureFlag enum in window.dart.
enum
class
AccessibilityFeatureFlag
:
int32_t
{
kAccessibleNavigation
=
1
<<
0
,
...
...
third_party/tonic/typed_data/dart_byte_data.cc
浏览文件 @
9fcfec39
...
...
@@ -8,10 +8,32 @@
namespace
tonic
{
namespace
{
// For large objects it is more efficient to use an external typed data object
// with a buffer allocated outside the Dart heap.
const
int
kExternalSizeThreshold
=
1000
;
void
FreeFinalizer
(
void
*
isolate_callback_data
,
Dart_WeakPersistentHandle
handle
,
void
*
peer
)
{
free
(
peer
);
}
}
// anonymous namespace
Dart_Handle
DartByteData
::
Create
(
const
void
*
data
,
size_t
length
)
{
auto
handle
=
DartByteData
{
data
,
length
}.
dart_handle
();
// The destructor should release the typed data.
return
handle
;
if
(
length
<
kExternalSizeThreshold
)
{
auto
handle
=
DartByteData
{
data
,
length
}.
dart_handle
();
// The destructor should release the typed data.
return
handle
;
}
else
{
void
*
buf
=
::
malloc
(
length
);
TONIC_DCHECK
(
buf
);
::
memcpy
(
buf
,
data
,
length
);
return
Dart_NewExternalTypedDataWithFinalizer
(
Dart_TypedData_kByteData
,
buf
,
length
,
buf
,
length
,
FreeFinalizer
);
}
}
DartByteData
::
DartByteData
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录