Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
6999c4d4
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,发现更多精彩内容 >>
未验证
提交
6999c4d4
编写于
10月 23, 2020
作者:
F
Ferhat
提交者:
GitHub
10月 23, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
When picture is updated and bitmapcanvas reused, clear element cache (#22072)
上级
9bddfc9b
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
50 addition
and
4 deletion
+50
-4
lib/web_ui/lib/src/engine/bitmap_canvas.dart
lib/web_ui/lib/src/engine/bitmap_canvas.dart
+1
-1
lib/web_ui/lib/src/engine/html/picture.dart
lib/web_ui/lib/src/engine/html/picture.dart
+13
-3
lib/web_ui/test/engine/surface/scene_builder_test.dart
lib/web_ui/test/engine/surface/scene_builder_test.dart
+36
-0
未找到文件。
lib/web_ui/lib/src/engine/bitmap_canvas.dart
浏览文件 @
6999c4d4
...
...
@@ -135,7 +135,7 @@ class BitmapCanvas extends EngineCanvas {
}
/// Setup cache for reusing DOM elements across frames.
void
setElementCache
(
CrossFrameCache
<
html
.
HtmlElement
>
cache
)
{
void
setElementCache
(
CrossFrameCache
<
html
.
HtmlElement
>
?
cache
)
{
_elementCache
=
cache
;
}
...
...
lib/web_ui/lib/src/engine/html/picture.dart
浏览文件 @
6999c4d4
...
...
@@ -52,6 +52,7 @@ List<_PaintRequest> _paintQueue = <_PaintRequest>[];
void
_recycleCanvas
(
EngineCanvas
?
canvas
)
{
if
(
canvas
is
BitmapCanvas
)
{
canvas
.
setElementCache
(
null
);
if
(
canvas
.
isReusable
())
{
_recycledCanvases
.
add
(
canvas
);
if
(
_recycledCanvases
.
length
>
_kCanvasCacheSize
)
{
...
...
@@ -91,7 +92,7 @@ class PersistedPicture extends PersistedLeafSurface {
final
int
hints
;
/// Cache for reusing elements such as images across picture updates.
CrossFrameCache
<
html
.
HtmlElement
>
_elementCache
=
CrossFrameCache
<
html
.
HtmlElement
>
?
_elementCache
=
CrossFrameCache
<
html
.
HtmlElement
>();
@override
...
...
@@ -386,6 +387,7 @@ class PersistedPicture extends PersistedLeafSurface {
if
(
_debugShowCanvasReuseStats
)
{
DebugCanvasReuseOverlay
.
instance
.
keptCount
++;
}
// Re-use old bitmap canvas.
oldCanvas
.
bounds
=
_optimalLocalCullRect
!;
_canvas
=
oldCanvas
;
oldCanvas
.
setElementCache
(
_elementCache
);
...
...
@@ -395,6 +397,10 @@ class PersistedPicture extends PersistedLeafSurface {
// We can't use the old canvas because the size has changed, so we put
// it in a cache for later reuse.
_recycleCanvas
(
oldCanvas
);
if
(
_canvas
is
BitmapCanvas
)
{
(
_canvas
as
BitmapCanvas
).
setElementCache
(
null
);
}
_canvas
=
null
;
// We cannot paint immediately because not all canvases that we may be
// able to reuse have been released yet. So instead we enqueue this
// picture to be painted after the update cycle is done syncing the layer
...
...
@@ -403,8 +409,9 @@ class PersistedPicture extends PersistedLeafSurface {
canvasSize:
_optimalLocalCullRect
!.
size
,
paintCallback:
()
{
_canvas
=
_findOrCreateCanvas
(
_optimalLocalCullRect
!);
assert
(
_canvas
is
BitmapCanvas
&&
(
_canvas
as
BitmapCanvas
?)!.
_elementCache
==
_elementCache
);
if
(
_canvas
is
BitmapCanvas
)
{
(
_canvas
as
BitmapCanvas
).
setElementCache
(
_elementCache
);
}
if
(
_debugExplainSurfaceStats
)
{
final
BitmapCanvas
bitmapCanvas
=
_canvas
as
BitmapCanvas
;
_surfaceStatsFor
(
this
).
paintPixelCount
+=
...
...
@@ -518,6 +525,9 @@ class PersistedPicture extends PersistedLeafSurface {
super
.
update
(
oldSurface
);
// Transfer element cache over.
_elementCache
=
oldSurface
.
_elementCache
;
if
(
oldSurface
!=
this
)
{
oldSurface
.
_elementCache
=
null
;
}
if
(
dx
!=
oldSurface
.
dx
||
dy
!=
oldSurface
.
dy
)
{
_applyTranslate
();
...
...
lib/web_ui/test/engine/surface/scene_builder_test.dart
浏览文件 @
6999c4d4
...
...
@@ -258,6 +258,42 @@ void testMain() {
});
});
/// Verify elementCache is passed during update to reuse existing
/// image elements.
test
(
'Should retain same image element'
,
()
async
{
final
SurfaceSceneBuilder
builder
=
SurfaceSceneBuilder
();
final
Picture
picture1
=
_drawPathImagePath
();
EngineLayer
oldLayer
=
builder
.
pushClipRect
(
const
Rect
.
fromLTRB
(
10
,
10
,
300
,
300
),
);
builder
.
addPicture
(
Offset
.
zero
,
picture1
);
builder
.
pop
();
html
.
HtmlElement
content
=
builder
.
build
().
webOnlyRootElement
;
html
.
document
.
body
.
append
(
content
);
List
<
html
.
ImageElement
>
list
=
content
.
querySelectorAll
(
'img'
);
for
(
html
.
ImageElement
image
in
list
)
{
image
.
alt
=
'marked'
;
}
// Force update to scene which will utilize reuse code path.
final
SurfaceSceneBuilder
builder2
=
SurfaceSceneBuilder
();
builder2
.
pushClipRect
(
const
Rect
.
fromLTRB
(
5
,
10
,
300
,
300
),
oldLayer:
oldLayer
);
final
Picture
picture2
=
_drawPathImagePath
();
builder2
.
addPicture
(
Offset
.
zero
,
picture2
);
builder2
.
pop
();
html
.
HtmlElement
contentAfterReuse
=
builder2
.
build
().
webOnlyRootElement
;
list
=
contentAfterReuse
.
querySelectorAll
(
'img'
);
for
(
html
.
ImageElement
image
in
list
)
{
expect
(
image
.
alt
,
'marked'
);
}
expect
(
list
.
length
,
1
);
});
PersistedPicture
findPictureSurfaceChild
(
PersistedContainerSurface
parent
)
{
PersistedPicture
pictureSurface
;
parent
.
visitChildren
((
PersistedSurface
child
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录