Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
b63e9114
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,发现更多精彩内容 >>
未验证
提交
b63e9114
编写于
12月 02, 2020
作者:
Y
Yegor
提交者:
GitHub
12月 02, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better handle image codec instantiation failure (#22809)
上级
1c2a8f90
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
28 addition
and
27 deletion
+28
-27
lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart
lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart
+1
-1
lib/web_ui/lib/src/engine/canvaskit/image.dart
lib/web_ui/lib/src/engine/canvaskit/image.dart
+7
-4
lib/web_ui/lib/src/ui/painting.dart
lib/web_ui/lib/src/ui/painting.dart
+10
-22
lib/web_ui/test/canvaskit/image_test.dart
lib/web_ui/test/canvaskit/image_test.dart
+10
-0
未找到文件。
lib/web_ui/lib/src/engine/canvaskit/canvaskit_api.dart
浏览文件 @
b63e9114
...
@@ -44,7 +44,7 @@ class CanvasKit {
...
@@ -44,7 +44,7 @@ class CanvasKit {
external
SkTextDirectionEnum
get
TextDirection
;
external
SkTextDirectionEnum
get
TextDirection
;
external
SkFontWeightEnum
get
FontWeight
;
external
SkFontWeightEnum
get
FontWeight
;
external
SkFontSlantEnum
get
FontSlant
;
external
SkFontSlantEnum
get
FontSlant
;
external
SkAnimatedImage
MakeAnimatedImageFromEncoded
(
Uint8List
imageData
);
external
SkAnimatedImage
?
MakeAnimatedImageFromEncoded
(
Uint8List
imageData
);
external
SkShaderNamespace
get
Shader
;
external
SkShaderNamespace
get
Shader
;
external
SkMaskFilterNamespace
get
MaskFilter
;
external
SkMaskFilterNamespace
get
MaskFilter
;
external
SkColorFilterNamespace
get
ColorFilter
;
external
SkColorFilterNamespace
get
ColorFilter
;
...
...
lib/web_ui/lib/src/engine/canvaskit/image.dart
浏览文件 @
b63e9114
...
@@ -6,10 +6,9 @@
...
@@ -6,10 +6,9 @@
part of
engine
;
part of
engine
;
/// Instantiates a [ui.Codec] backed by an `SkAnimatedImage` from Skia.
/// Instantiates a [ui.Codec] backed by an `SkAnimatedImage` from Skia.
void
skiaInstantiateImageCodec
(
Uint8List
list
,
Callback
<
ui
.
Codec
>
callback
,
ui
.
Codec
skiaInstantiateImageCodec
(
Uint8List
list
,
[
int
?
width
,
int
?
height
,
int
?
format
,
int
?
rowBytes
])
{
[
int
?
width
,
int
?
height
,
int
?
format
,
int
?
rowBytes
])
{
final
CkAnimatedImage
codec
=
CkAnimatedImage
.
decodeFromBytes
(
list
);
return
CkAnimatedImage
.
decodeFromBytes
(
list
);
callback
(
codec
);
}
}
/// Instantiates a [ui.Codec] backed by an `SkAnimatedImage` from Skia after
/// Instantiates a [ui.Codec] backed by an `SkAnimatedImage` from Skia after
...
@@ -49,7 +48,11 @@ class CkAnimatedImage extends ManagedSkiaObject<SkAnimatedImage> implements ui.C
...
@@ -49,7 +48,11 @@ class CkAnimatedImage extends ManagedSkiaObject<SkAnimatedImage> implements ui.C
@override
@override
SkAnimatedImage
createDefault
()
{
SkAnimatedImage
createDefault
()
{
return
canvasKit
.
MakeAnimatedImageFromEncoded
(
_bytes
);
final
SkAnimatedImage
?
animatedImage
=
canvasKit
.
MakeAnimatedImageFromEncoded
(
_bytes
);
if
(
animatedImage
==
null
)
{
throw
Exception
(
'Failed to decode image'
);
}
return
animatedImage
;
}
}
@override
@override
...
...
lib/web_ui/lib/src/ui/painting.dart
浏览文件 @
b63e9114
...
@@ -452,20 +452,14 @@ Future<Codec> instantiateImageCodec(
...
@@ -452,20 +452,14 @@ Future<Codec> instantiateImageCodec(
int
?
targetWidth
,
int
?
targetWidth
,
int
?
targetHeight
,
int
?
targetHeight
,
bool
allowUpscaling
=
true
,
bool
allowUpscaling
=
true
,
})
{
})
async
{
return
_futurize
<
Codec
>((
engine
.
Callback
<
Codec
>
callback
)
=>
// TODO: Implement targetWidth and targetHeight support.
_instantiateImageCodec
(
list
,
callback
));
}
String
?
_instantiateImageCodec
(
Uint8List
list
,
engine
.
Callback
<
Codec
>
callback
)
{
if
(
engine
.
useCanvasKit
)
{
if
(
engine
.
useCanvasKit
)
{
engine
.
skiaInstantiateImageCodec
(
list
,
callback
);
// TODO: Implement targetWidth and targetHeight support.
return
null
;
return
engine
.
skiaInstantiateImageCodec
(
list
);
}
else
{
final
html
.
Blob
blob
=
html
.
Blob
(<
dynamic
>[
list
.
buffer
]);
return
engine
.
HtmlBlobCodec
(
blob
);
}
}
final
html
.
Blob
blob
=
html
.
Blob
(<
dynamic
>[
list
.
buffer
]);
callback
(
engine
.
HtmlBlobCodec
(
blob
));
return
null
;
}
}
Future
<
Codec
>
webOnlyInstantiateImageCodecFromUrl
(
Uri
uri
,
Future
<
Codec
>
webOnlyInstantiateImageCodecFromUrl
(
Uri
uri
,
...
@@ -565,12 +559,9 @@ Future<Codec> _createBmp(
...
@@ -565,12 +559,9 @@ Future<Codec> _createBmp(
}
}
}
}
final
Completer
<
Codec
>
codecCompleter
=
Completer
<
Codec
>();
return
instantiateImageCodec
(
_instantiateImageCodec
(
bmpData
.
buffer
.
asUint8List
(),
bmpData
.
buffer
.
asUint8List
(),
(
Codec
codec
)
=>
codecCompleter
.
complete
(
codec
),
);
);
return
codecCompleter
.
future
;
}
}
void
decodeImageFromPixels
(
void
decodeImageFromPixels
(
...
@@ -587,16 +578,13 @@ void decodeImageFromPixels(
...
@@ -587,16 +578,13 @@ void decodeImageFromPixels(
if
(
engine
.
useCanvasKit
)
{
if
(
engine
.
useCanvasKit
)
{
engine
.
skiaInstantiateImageCodec
(
engine
.
skiaInstantiateImageCodec
(
pixels
,
pixels
,
(
Codec
codec
)
{
codec
.
getNextFrame
().
then
((
FrameInfo
info
)
{
callback
(
info
.
image
);
});
},
width
,
width
,
height
,
height
,
format
.
index
,
format
.
index
,
rowBytes
,
rowBytes
,
);
).
getNextFrame
().
then
((
FrameInfo
info
)
{
callback
(
info
.
image
);
});
return
;
return
;
}
}
...
...
lib/web_ui/test/canvaskit/image_test.dart
浏览文件 @
b63e9114
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
// @dart = 2.6
// @dart = 2.6
import
'dart:html'
show
ProgressEvent
;
import
'dart:html'
show
ProgressEvent
;
import
'dart:typed_data'
;
import
'package:test/bootstrap/browser.dart'
;
import
'package:test/bootstrap/browser.dart'
;
import
'package:test/test.dart'
;
import
'package:test/test.dart'
;
...
@@ -114,6 +115,15 @@ void testMain() {
...
@@ -114,6 +115,15 @@ void testMain() {
expect
((
await
image
.
toByteData
(
format:
ui
.
ImageByteFormat
.
png
)).
lengthInBytes
,
greaterThan
(
0
));
expect
((
await
image
.
toByteData
(
format:
ui
.
ImageByteFormat
.
png
)).
lengthInBytes
,
greaterThan
(
0
));
testCollector
.
collectNow
();
testCollector
.
collectNow
();
});
});
test
(
'Reports error when failing to decode image'
,
()
async
{
try
{
await
ui
.
instantiateImageCodec
(
Uint8List
(
0
));
fail
(
'Expected to throw'
);
}
on
Exception
catch
(
exception
)
{
expect
(
exception
.
toString
(),
'Exception: Failed to decode image'
);
}
});
// TODO: https://github.com/flutter/flutter/issues/60040
// TODO: https://github.com/flutter/flutter/issues/60040
},
skip:
isIosSafari
);
},
skip:
isIosSafari
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录