mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Roll CanvasKit to 0.24. (flutter/engine#24498)
* Update tests for new API * Update goldens and respond to comment
This commit is contained in:
parent
39c2754bc4
commit
4954a033ec
@ -1,2 +1,2 @@
|
||||
repository: https://github.com/flutter/goldens.git
|
||||
revision: a1e78be938fe79544eeacccce1e2a5ace3d4058e
|
||||
revision: 2eb81061582dbe73939811d4471d6167b463f11c
|
||||
|
||||
@ -742,7 +742,7 @@ class SkImage {
|
||||
Float32List? matrix, // 3x3 matrix
|
||||
);
|
||||
external Uint8List readPixels(int srcX, int srcY, SkImageInfo imageInfo);
|
||||
external SkData encodeToData();
|
||||
external Uint8List? encodeToBytes();
|
||||
external bool isAliasOf(SkImage other);
|
||||
external bool isDeleted();
|
||||
}
|
||||
|
||||
@ -172,13 +172,18 @@ class CkImage implements ui.Image, StackTraceDebugger {
|
||||
// IMPORTANT: the alphaType, colorType, and colorSpace passed to
|
||||
// _encodeImage and to canvasKit.MakeImage must be the same. Otherwise
|
||||
// Skia will misinterpret the pixels and corrupt the image.
|
||||
final ByteData originalBytes = _encodeImage(
|
||||
final ByteData? originalBytes = _encodeImage(
|
||||
skImage: skImage,
|
||||
format: ui.ImageByteFormat.rawRgba,
|
||||
alphaType: canvasKit.AlphaType.Premul,
|
||||
colorType: canvasKit.ColorType.RGBA_8888,
|
||||
colorSpace: SkColorSpaceSRGB,
|
||||
);
|
||||
if (originalBytes == null) {
|
||||
html.window.console.warn('Unable to encode image to bytes. We will not '
|
||||
'be able to resurrect it once it has been garbage collected.');
|
||||
return;
|
||||
}
|
||||
final int originalWidth = skImage.width();
|
||||
final int originalHeight = skImage.height();
|
||||
box = SkiaObjectBox<CkImage, SkImage>.resurrectable(this, skImage, () {
|
||||
@ -276,23 +281,28 @@ class CkImage implements ui.Image, StackTraceDebugger {
|
||||
ui.ImageByteFormat format = ui.ImageByteFormat.rawRgba,
|
||||
}) {
|
||||
assert(_debugCheckIsNotDisposed());
|
||||
return Future<ByteData>.value(_encodeImage(
|
||||
ByteData? data = _encodeImage(
|
||||
skImage: skImage,
|
||||
format: format,
|
||||
alphaType: canvasKit.AlphaType.Premul,
|
||||
colorType: canvasKit.ColorType.RGBA_8888,
|
||||
colorSpace: SkColorSpaceSRGB,
|
||||
));
|
||||
);
|
||||
if (data == null) {
|
||||
return Future<ByteData>.error('Failed to encode the image into bytes.');
|
||||
} else {
|
||||
return Future<ByteData>.value(data);
|
||||
}
|
||||
}
|
||||
|
||||
static ByteData _encodeImage({
|
||||
static ByteData? _encodeImage({
|
||||
required SkImage skImage,
|
||||
required ui.ImageByteFormat format,
|
||||
required SkAlphaType alphaType,
|
||||
required SkColorType colorType,
|
||||
required ColorSpace colorSpace,
|
||||
}) {
|
||||
Uint8List bytes;
|
||||
Uint8List? bytes;
|
||||
|
||||
if (format == ui.ImageByteFormat.rawRgba) {
|
||||
final SkImageInfo imageInfo = SkImageInfo(
|
||||
@ -304,13 +314,10 @@ class CkImage implements ui.Image, StackTraceDebugger {
|
||||
);
|
||||
bytes = skImage.readPixels(0, 0, imageInfo);
|
||||
} else {
|
||||
final SkData skData = skImage.encodeToData(); //defaults to PNG 100%
|
||||
// make a copy that we can return
|
||||
bytes = Uint8List.fromList(canvasKit.getDataBytes(skData));
|
||||
skData.delete();
|
||||
bytes = skImage.encodeToBytes(); //defaults to PNG 100%
|
||||
}
|
||||
|
||||
return bytes.buffer.asByteData(0, bytes.length);
|
||||
return bytes?.buffer.asByteData(0, bytes.length);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -75,10 +75,12 @@ const bool canvasKitForceCpuOnly = bool.fromEnvironment(
|
||||
/// NPM, update this URL to `https://unpkg.com/canvaskit-wasm@0.34.0/bin/`.
|
||||
const String canvasKitBaseUrl = String.fromEnvironment(
|
||||
'FLUTTER_WEB_CANVASKIT_URL',
|
||||
defaultValue: 'https://unpkg.com/canvaskit-wasm@0.22.0/bin/',
|
||||
defaultValue: 'https://unpkg.com/canvaskit-wasm@0.24.0/bin/',
|
||||
);
|
||||
final String canvasKitBuildUrl = canvasKitBaseUrl + (kProfileMode ? 'profiling/' : '');
|
||||
final String canvasKitJavaScriptBindingsUrl = canvasKitBuildUrl + 'canvaskit.js';
|
||||
final String canvasKitBuildUrl =
|
||||
canvasKitBaseUrl + (kProfileMode ? 'profiling/' : '');
|
||||
final String canvasKitJavaScriptBindingsUrl =
|
||||
canvasKitBuildUrl + 'canvaskit.js';
|
||||
String canvasKitWasmModuleUrl(String file) => canvasKitBuildUrl + file;
|
||||
|
||||
/// Initialize CanvasKit.
|
||||
@ -89,8 +91,10 @@ Future<void> initializeCanvasKit() {
|
||||
late StreamSubscription<html.Event> loadSubscription;
|
||||
loadSubscription = domRenderer.canvasKitScript!.onLoad.listen((_) {
|
||||
loadSubscription.cancel();
|
||||
final CanvasKitInitPromise canvasKitInitPromise = CanvasKitInit(CanvasKitInitOptions(
|
||||
locateFile: js.allowInterop((String file, String unusedBase) => canvasKitWasmModuleUrl(file)),
|
||||
final CanvasKitInitPromise canvasKitInitPromise =
|
||||
CanvasKitInit(CanvasKitInitOptions(
|
||||
locateFile: js.allowInterop(
|
||||
(String file, String unusedBase) => canvasKitWasmModuleUrl(file)),
|
||||
));
|
||||
canvasKitInitPromise.then(js.allowInterop((CanvasKit ck) {
|
||||
canvasKit = ck;
|
||||
|
||||
@ -1313,7 +1313,7 @@ void _paragraphTests() {
|
||||
expect(paragraph.getIdeographicBaseline(), within<double>(distance: 0.5, from: 28));
|
||||
expect(paragraph.getLongestLine(), 50);
|
||||
expect(paragraph.getMaxIntrinsicWidth(), 50);
|
||||
expect(paragraph.getMinIntrinsicWidth(), 0);
|
||||
expect(paragraph.getMinIntrinsicWidth(), 50);
|
||||
expect(paragraph.getMaxWidth(), 55);
|
||||
expect(paragraph.getRectsForRange(1, 3, canvasKit.RectHeightStyle.Tight, canvasKit.RectWidthStyle.Max), <double>[]);
|
||||
expect(paragraph.getRectsForPlaceholders(), hasLength(1));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user