This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Image.toByteData and Picture.toImage implementations (#2) #20326
Closed
Closed
Changes from 70 commits
Commits
Show all changes
78 commits
Select commit
Hold shift + click to select a range
93e3f0b
Update image.dart
deakjahn cc827d6
Update html_image_codec.dart
deakjahn 6b9fd73
rebase
deakjahn 352b31a
Update image.dart
deakjahn 4ea7ef2
Update picture.dart
deakjahn f99c8b2
Update picture.dart
deakjahn 1e7188f
Update picture.dart
deakjahn 4017e40
Update html_image_codec.dart
deakjahn ed811cf
Update image.dart
deakjahn d6dc410
Update image.dart
deakjahn c2c70e4
Revert
deakjahn 8b1ed1a
Tested by local engine
deakjahn bad4d45
Add files via upload
deakjahn 22dbcf7
Delete picture_to_image_test.dart
deakjahn 5eb7b8a
Test #1
deakjahn 1feae02
Test to read only
deakjahn 4c9001b
Finally
deakjahn a2ff894
Sorry, spaces
deakjahn 0c72496
Test, finally
deakjahn 91b12ca
@JS refactoring
deakjahn 9eeb7e0
@JS refactoring
deakjahn 6efd763
SkData and SkImageInfo
deakjahn 22d2f96
Unused items
deakjahn f1d49be
Test to write PNG
deakjahn 6675e13
Remove comments
deakjahn ced934c
Add comments
deakjahn 7b78b27
CK test
deakjahn 11c4073
Comment about copying
deakjahn 72ef505
Update image.dart
deakjahn 1afe140
Update html_image_codec.dart
deakjahn 18642e4
rebase
deakjahn a20d80d
Update image.dart
deakjahn e3147c5
Update picture.dart
deakjahn ae8ba90
Update picture.dart
deakjahn abf4f78
Update picture.dart
deakjahn 2abe68f
Update html_image_codec.dart
deakjahn 0b765d8
Update image.dart
deakjahn 1109004
Update image.dart
deakjahn 17a2ef5
Revert
deakjahn 0c2aac9
Tested by local engine
deakjahn 301ae90
Add files via upload
deakjahn fbfd675
Delete picture_to_image_test.dart
deakjahn b49583b
Test #1
deakjahn 26a49fb
Test to read only
deakjahn b23ca62
Test, finally
deakjahn 41d664a
@JS refactoring
deakjahn fcd1d2f
@JS refactoring
deakjahn a29069f
SkData and SkImageInfo
deakjahn 83a7399
Unused items
deakjahn 99eb64c
Test to write PNG
deakjahn 4b28ee1
Remove comments
deakjahn 10f4d4c
CK test
deakjahn 70d9884
Merge branch 'master' of https://github.com/deakjahn/engine
deakjahn a1346ea
Rebase manually
deakjahn 4e41dfc
Rebase manually
deakjahn fb02673
New test
deakjahn 8c2790c
Newline
deakjahn 6a31d41
Rebase dirt
deakjahn dc77edc
SkImageInfo
deakjahn 54e706c
New test
deakjahn d4a07a1
New test
deakjahn 6db0a3a
New test
deakjahn 6daead7
Missing annotation
deakjahn 75770e7
Rebase
deakjahn ad715e1
ColorSpace
deakjahn 69dd265
SkImageInfo correct names
deakjahn 078d6bc
SkImageInfo correct names
deakjahn 5dd02dd
SkImageInfo correct names
deakjahn 5f4d5e7
SkImageInfo properties
deakjahn 107ba3d
Inactive test
deakjahn 93cd91d
Merge remote-tracking branch 'upstream/master'
deakjahn 69ec1cc
Unused import
deakjahn 9d5a611
Merge remote-tracking branch 'upstream/master'
deakjahn 6e1d95d
Squash 2
deakjahn 7da3c86
Merge branch 'master' of https://github.com/deakjahn/engine
deakjahn 90d0b69
Squash 2.
deakjahn 4c39264
Merge branch 'master' of https://github.com/deakjahn/engine
deakjahn 9cf68f8
Merge remote-tracking branch 'upstream/master'
deakjahn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 get alphaType; | ||
| external SkColorSpace get colorSpace; | ||
| external SkColorType get colorType; | ||
| external int get height; | ||
| external bool get isEmpty; | ||
| external bool get isOpaque; | ||
| external SkRect get bounds; | ||
| external int get width; | ||
| external SkImageInfo makeAlphaType(SkAlphaType alphaType); | ||
| external SkImageInfo makeColorSpace(SkColorSpace colorSpace); | ||
| external SkImageInfo makeColorType(SkColorType colorType); | ||
| external SkImageInfo makeWH(int width, int height); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
lib/web_ui/test/golden_tests/engine/canvas_to_picture_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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™. :-)