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
Implement Scene.toImage() in CanvasKit mode. #22085
Merged
harryterkelsen
merged 5 commits into
flutter:master
from
harryterkelsen:canvaskit-scene-toimage
Nov 20, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a352e07
Implement Scene.toImage() in CanvasKit mode.
harryterkelsen 60b10e6
Merge branch 'master' into canvaskit-scene-toimage
harryterkelsen d942c69
Add test
harryterkelsen 4dc3290
Delete unused import
harryterkelsen af43d1d
Skip tests on Safari
harryterkelsen 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // 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 'package:test/bootstrap/browser.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| import 'package:ui/src/engine.dart'; | ||
| import 'package:ui/ui.dart' as ui; | ||
|
|
||
| import 'common.dart'; | ||
|
|
||
| void main() { | ||
| internalBootstrapBrowserTest(() => testMain); | ||
| } | ||
|
|
||
| void testMain() { | ||
| group('LayerScene', () { | ||
| setUpAll(() async { | ||
| await ui.webOnlyInitializePlatform(); | ||
| }); | ||
|
|
||
| test('toImage returns an image', () async { | ||
| final ui.PictureRecorder recorder = ui.PictureRecorder(); | ||
| expect(recorder, isA<CkPictureRecorder>()); | ||
|
|
||
| final ui.Canvas canvas = ui.Canvas(recorder); | ||
| expect(canvas, isA<CanvasKitCanvas>()); | ||
|
|
||
| final ui.Paint paint = ui.Paint(); | ||
| expect(paint, isA<CkPaint>()); | ||
| paint.color = ui.Color.fromARGB(255, 255, 0, 0); | ||
|
|
||
| // Draw a red circle. | ||
| canvas.drawCircle(ui.Offset(20, 20), 10, paint); | ||
|
|
||
| final ui.Picture picture = recorder.endRecording(); | ||
| expect(picture, isA<CkPicture>()); | ||
|
|
||
| final ui.SceneBuilder builder = ui.SceneBuilder(); | ||
| expect(builder, isA<LayerSceneBuilder>()); | ||
|
|
||
| builder.pushOffset(0, 0); | ||
| builder.addPicture(ui.Offset(0, 0), picture); | ||
|
|
||
| final ui.Scene scene = builder.build(); | ||
|
|
||
| final ui.Image sceneImage = await scene.toImage(100, 100); | ||
| expect(sceneImage, isA<CkImage>()); | ||
| }); | ||
| // TODO: https://github.com/flutter/flutter/issues/60040 | ||
| }, skip: isIosSafari); | ||
| } |
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.
Let's add a unit-test.
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.
Done.