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 pushColorFilter in CanvasKit #22838
Merged
harryterkelsen
merged 5 commits into
flutter:master
from
harryterkelsen:canvaskit-colorfilter
Dec 12, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
71dbbb0
Implement pushColorFilter in CanvasKit
harryterkelsen b9af981
Merge branch 'master' into canvaskit-colorfilter
harryterkelsen bdf3a33
Add test
harryterkelsen 05571cb
Merge branch 'master' into canvaskit-colorfilter
harryterkelsen 918f937
Update goldens lock
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| repository: https://github.com/flutter/goldens.git | ||
| revision: ac75f12c6e93461369e1391da6cc20bf8cb08829 | ||
| revision: c808c28c81b6c3143ae969e8c49bed4a6d49aabb |
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,78 @@ | ||
| // 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.12 | ||
| 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 'package:web_engine_tester/golden_tester.dart'; | ||
|
|
||
| import 'common.dart'; | ||
|
|
||
| void main() { | ||
| internalBootstrapBrowserTest(() => testMain); | ||
| } | ||
|
|
||
| const ui.Rect region = const ui.Rect.fromLTRB(0, 0, 500, 250); | ||
|
|
||
| Future<void> matchSceneGolden(String goldenFile, LayerScene scene, | ||
| {bool write = false}) async { | ||
| final EnginePlatformDispatcher dispatcher = | ||
| ui.window.platformDispatcher as EnginePlatformDispatcher; | ||
| dispatcher.rasterizer!.draw(scene.layerTree); | ||
| await matchGoldenFile(goldenFile, region: region, write: write); | ||
| } | ||
|
|
||
| void testMain() { | ||
| group('ColorFilter', () { | ||
| setUpCanvasKitTest(); | ||
|
|
||
| test('ColorFilter.matrix applies a color filter', () async { | ||
| final LayerSceneBuilder builder = LayerSceneBuilder(); | ||
|
|
||
| builder.pushOffset(0, 0); | ||
|
|
||
| // Draw a red circle and apply it to the scene. | ||
| final CkPictureRecorder recorder = CkPictureRecorder(); | ||
| final CkCanvas canvas = recorder.beginRecording(region); | ||
|
|
||
| canvas.drawCircle( | ||
| ui.Offset(75, 125), | ||
| 50, | ||
| CkPaint()..color = ui.Color.fromARGB(255, 255, 0, 0), | ||
| ); | ||
| final CkPicture redCircle = recorder.endRecording(); | ||
|
|
||
| builder.addPicture(ui.Offset.zero, redCircle); | ||
|
|
||
| // Apply a "greyscale" color filter. | ||
| builder.pushColorFilter(ui.ColorFilter.matrix([ | ||
| 0.2126, 0.7152, 0.0722, 0, 0, // | ||
| 0.2126, 0.7152, 0.0722, 0, 0, // | ||
| 0.2126, 0.7152, 0.0722, 0, 0, // | ||
| 0, 0, 0, 1, 0, // | ||
| ])); | ||
|
|
||
| // Draw another red circle and apply it to the scene. | ||
| // This one should be grey since we have the color filter. | ||
| final CkPictureRecorder recorder2 = CkPictureRecorder(); | ||
| final CkCanvas canvas2 = recorder2.beginRecording(region); | ||
|
|
||
| canvas2.drawCircle( | ||
| ui.Offset(425, 125), | ||
| 50, | ||
| CkPaint()..color = ui.Color.fromARGB(255, 255, 0, 0), | ||
| ); | ||
| final CkPicture greyCircle = recorder2.endRecording(); | ||
|
|
||
| builder.addPicture(ui.Offset.zero, greyCircle); | ||
|
|
||
| await matchSceneGolden('canvaskit_colorfilter.png', builder.build()); | ||
| }); | ||
| // TODO: https://github.com/flutter/flutter/issues/60040 | ||
| // TODO: https://github.com/flutter/flutter/issues/71520 | ||
| }, skip: isIosSafari || isFirefox); | ||
| } |
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
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.
Bonus points for making it a screenshot test. To do that, simply rename the file to
scene_golden_test.dartand use golden_tester.dart like normal (example).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.
although the test would need to be skipped outside chrome.