-
Notifications
You must be signed in to change notification settings - Fork 6k
Image.toByteData and Picture.toImage implementations (#2) #20326
Changes from 68 commits
93e3f0b
cc827d6
6b9fd73
352b31a
4ea7ef2
f99c8b2
1e7188f
4017e40
ed811cf
d6dc410
c2c70e4
8b1ed1a
bad4d45
22dbcf7
5eb7b8a
1feae02
4c9001b
a2ff894
0c72496
91b12ca
9eeb7e0
6efd763
22d2f96
f1d49be
6675e13
ced934c
7b78b27
11c4073
72ef505
1afe140
18642e4
a20d80d
e3147c5
ae8ba90
abf4f78
2abe68f
0b765d8
1109004
17a2ef5
0c2aac9
301ae90
fbfd675
b49583b
26a49fb
b23ca62
41d664a
fcd1d2f
a29069f
83a7399
99eb64c
4b28ee1
10f4d4c
70d9884
a1346ea
4e41dfc
fb02673
8c2790c
6a31d41
dc77edc
54e706c
d4a07a1
6db0a3a
6daead7
75770e7
ad715e1
69dd265
078d6bc
5dd02dd
5f4d5e7
107ba3d
93cd91d
69ec1cc
9d5a611
6e1d95d
7da3c86
90d0b69
4c39264
9cf68f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
|
|
||
| /// Bindings for CanvasKit JavaScript API. | ||
| /// | ||
| /// Prefer keeping the originl CanvasKit names so it is easier to locate | ||
| /// Prefer keeping the original CanvasKit names so it is easier to locate | ||
| /// the API behind these bindings in the Skia source code. | ||
|
|
||
| // @dart = 2.10 | ||
|
|
@@ -30,6 +30,8 @@ class CanvasKit { | |
| external SkBlurStyleEnum get BlurStyle; | ||
| external SkTileModeEnum get TileMode; | ||
| external SkFillTypeEnum get FillType; | ||
| external SkAlphaTypeEnum get AlphaType; | ||
| external SkColorTypeEnum get ColorType; | ||
| external SkPathOpEnum get PathOp; | ||
| external SkClipOpEnum get ClipOp; | ||
| external SkPointModeEnum get PointMode; | ||
|
|
@@ -61,6 +63,13 @@ class CanvasKit { | |
| external SkParagraphStyle ParagraphStyle( | ||
| SkParagraphStyleProperties properties); | ||
| external SkTextStyle TextStyle(SkTextStyleProperties properties); | ||
| external SkSurface MakeSurface( | ||
| int width, | ||
| int height, | ||
| ); | ||
| external Uint8List getSkDataBytes( | ||
| SkData skData, | ||
| ); | ||
|
|
||
| // Text decoration enum is embedded in the CanvasKit object itself. | ||
| external int get NoDecoration; | ||
|
|
@@ -127,6 +136,7 @@ class SkSurface { | |
| external int width(); | ||
| external int height(); | ||
| external void dispose(); | ||
| external SkImage makeImageSnapshot(); | ||
| } | ||
|
|
||
| @JS() | ||
|
|
@@ -621,6 +631,38 @@ SkTileMode toSkTileMode(ui.TileMode mode) { | |
| return _skTileModes[mode.index]; | ||
| } | ||
|
|
||
| @JS() | ||
| class SkAlphaTypeEnum { | ||
| external SkAlphaType get Opaque; | ||
| external SkAlphaType get Premul; | ||
| external SkAlphaType get Unpremul; | ||
| } | ||
|
|
||
| @JS() | ||
| class SkAlphaType { | ||
| external int get value; | ||
| } | ||
|
|
||
| @JS() | ||
| class SkColorTypeEnum { | ||
| external SkColorType get Alpha_8; | ||
| external SkColorType get RGB_565; | ||
| external SkColorType get ARGB_4444; | ||
| external SkColorType get RGBA_8888; | ||
| external SkColorType get RGB_888x; | ||
| external SkColorType get BGRA_8888; | ||
| external SkColorType get RGBA_1010102; | ||
| external SkColorType get RGB_101010x; | ||
| external SkColorType get Gray_8; | ||
| external SkColorType get RGBA_F16; | ||
| external SkColorType get RGBA_F32; | ||
| } | ||
|
|
||
| @JS() | ||
| class SkColorType { | ||
| external int get value; | ||
| } | ||
|
|
||
| @JS() | ||
| class SkAnimatedImage { | ||
| external int getFrameCount(); | ||
|
|
@@ -631,6 +673,8 @@ class SkAnimatedImage { | |
| external SkImage getCurrentFrame(); | ||
| external int width(); | ||
| external int height(); | ||
| external Uint8List readPixels(SkImageInfo imageInfo, int srcX, int srcY); | ||
| external SkData encodeToData(); | ||
|
|
||
| /// Deletes the C++ object. | ||
| /// | ||
|
|
@@ -648,6 +692,8 @@ class SkImage { | |
| SkTileMode tileModeY, | ||
| Float32List? matrix, // 3x3 matrix | ||
| ); | ||
| external Uint8List readPixels(SkImageInfo imageInfo, int srcX, int srcY); | ||
| external SkData encodeToData(); | ||
| } | ||
|
|
||
| @JS() | ||
|
|
@@ -1641,3 +1687,34 @@ external Object? get _finalizationRegistryConstructor; | |
|
|
||
| /// Whether the current browser supports `FinalizationRegistry`. | ||
| bool browserSupportsFinalizationRegistry = _finalizationRegistryConstructor != null; | ||
|
|
||
| @JS() | ||
| class SkData { | ||
| external int size(); | ||
| external bool isEmpty(); | ||
| external Uint8List bytes(); | ||
| } | ||
|
|
||
| @JS() | ||
| @anonymous | ||
| class SkImageInfo { | ||
| external factory SkImageInfo({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Flutter style prefers putting factories and constructors above everything else. |
||
| required int width, | ||
| required int height, | ||
| SkAlphaType alphaType, | ||
| SkColorSpace colorSpace, | ||
| SkColorType colorType, | ||
| }); | ||
| external SkAlphaType alphaType(); | ||
| external SkColorSpace colorSpace(); | ||
| external SkColorType colorType(); | ||
| external int height(); | ||
| external bool isEmpty(); | ||
| external bool isOpaque(); | ||
| external SkRect bounds(); | ||
| external int width(); | ||
|
||
| external SkImageInfo makeAlphaType(SkAlphaType alphaType); | ||
| external SkImageInfo makeColorSpace(SkColorSpace colorSpace); | ||
| external SkImageInfo makeColorType(SkColorType colorType); | ||
| external SkImageInfo makeWH(int width, int height); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| // @dart = 2.6 | ||
| import 'dart:html' as html; | ||
|
|
||
| import 'package:ui/ui.dart'; | ||
| import 'package:ui/src/engine.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| import 'package:web_engine_tester/golden_tester.dart'; | ||
|
|
||
| void main() async { | ||
| final Rect region = Rect.fromLTWH(0, 0, 500, 500); | ||
|
|
||
| setUp(() async { | ||
| debugShowClipLayers = true; | ||
| SurfaceSceneBuilder.debugForgetFrameScene(); | ||
| for (html.Node scene in html.document.querySelectorAll('flt-scene')) { | ||
| scene.remove(); | ||
| } | ||
|
|
||
| await webOnlyInitializePlatform(); | ||
| webOnlyFontCollection.debugRegisterTestFonts(); | ||
| await webOnlyFontCollection.ensureFontsLoaded(); | ||
| }); | ||
|
|
||
| test('Convert Canvas to Picture', () async { | ||
| final SurfaceSceneBuilder builder = SurfaceSceneBuilder(); | ||
| final Picture testPicture = await _drawTestPictureWithCircle(region); | ||
| builder.addPicture(Offset.zero, testPicture); | ||
|
|
||
| html.document.body.append(builder | ||
| .build() | ||
| .webOnlyRootElement); | ||
|
|
||
| await matchGoldenFile('canvas_to_picture.png', region: region, write: true); | ||
|
||
| }); | ||
| } | ||
|
|
||
| Picture _drawTestPictureWithCircle(Rect region) { | ||
| final EnginePictureRecorder recorder = PictureRecorder(); | ||
| final RecordingCanvas canvas = recorder.beginRecording(region); | ||
| canvas.drawOval( | ||
| region, | ||
| Paint() | ||
| ..style = PaintingStyle.fill | ||
| ..color = Color(0xFF00FF00)); | ||
| return recorder.endRecording(); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be annotated with
@JS()Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Used to be before the Big Reorganization™. :-)