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
[web] Fix image gap due to svg element without position attribute #21939
Merged
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a56bcf1
Fix image gap due to svg element without position attribute
ferhatb d8a5139
remove screenshot write
ferhatb bf7b8f4
Merge remote-tracking branch 'upstream/master' into filter_gap
ferhatb 00752be
update golden lock
ferhatb ad7f334
address reviewer comments on style
ferhatb 9f7e9fe
Merge remote-tracking branch 'upstream/master' into filter_gap
ferhatb 8ee91f5
remove unnecessary null comparisons
ferhatb 5da6afb
Merge remote-tracking branch 'upstream/master' into filter_gap
ferhatb f0dbaf6
Merge remote-tracking branch 'upstream/master' into filter_gap
ferhatb 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 |
|---|---|---|
|
|
@@ -2,8 +2,9 @@ | |
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| // @dart = 2.6 | ||
| // @dart = 2.10 | ||
| import 'dart:html' as html; | ||
| import 'dart:js_util' as js_util; | ||
|
|
||
| import 'package:test/bootstrap/browser.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
@@ -35,55 +36,118 @@ void testMain() async { | |
| final SurfaceSceneBuilder builder = SurfaceSceneBuilder(); | ||
| final Picture backgroundPicture = _drawBackground(); | ||
| builder.addPicture(Offset.zero, backgroundPicture); | ||
| builder.pushColorFilter(EngineColorFilter.mode(Color(0xF0000080), | ||
| BlendMode.color)); | ||
| builder.pushColorFilter( | ||
| EngineColorFilter.mode(Color(0xF0000080), BlendMode.color)); | ||
| final Picture circles1 = _drawTestPictureWithCircles(30, 30); | ||
| builder.addPicture(Offset.zero, circles1); | ||
| builder.pop(); | ||
| html.document.body.append(builder | ||
| .build() | ||
| .webOnlyRootElement); | ||
| html.document.body!.append(builder.build().webOnlyRootElement!); | ||
|
|
||
| await matchGoldenFile('color_filter_blendMode_color.png', region: region); | ||
| }); | ||
|
|
||
| /// Regression test for https://github.com/flutter/flutter/issues/59451. | ||
| /// | ||
| /// Picture with overlay blend inside a physical shape. Should show image | ||
| /// at 0,0. In the filed issue it was leaving a gap on top. | ||
| test('Should render image with color filter without gap', () async { | ||
| final SurfaceSceneBuilder builder = SurfaceSceneBuilder(); | ||
| final Path path = Path(); | ||
| path.addRRect(RRect.fromRectAndRadius( | ||
| Rect.fromLTRB(0, 0, 400, 400), Radius.circular(2))); | ||
| PhysicalShapeEngineLayer oldLayer = builder.pushPhysicalShape( | ||
| path: path, color: Color(0xFFFFFFFF), elevation: 0); | ||
| final Picture circles1 = _drawTestPictureWithImage( | ||
| ColorFilter.mode(Color(0x3C4043), BlendMode.overlay)); | ||
| builder.addPicture(Offset(10, 0), circles1); | ||
| builder.pop(); | ||
| builder.build(); | ||
|
|
||
| final SurfaceSceneBuilder builder2 = SurfaceSceneBuilder(); | ||
| builder2.pushPhysicalShape( | ||
| path: path, color: Color(0xFFFFFFFF), elevation: 0, oldLayer: oldLayer); | ||
| builder2.addPicture(Offset(10, 0), circles1); | ||
| builder2.pop(); | ||
|
|
||
| html.document.body!.append(builder2.build().webOnlyRootElement!); | ||
|
|
||
| await matchGoldenFile('color_filter_blendMode_overlay.png', | ||
| region: region); | ||
| }); | ||
| } | ||
|
|
||
| Picture _drawTestPictureWithCircles(double offsetX, double offsetY) { | ||
| final EnginePictureRecorder recorder = PictureRecorder(); | ||
| final EnginePictureRecorder recorder = | ||
| PictureRecorder() as EnginePictureRecorder; | ||
| final RecordingCanvas canvas = | ||
| recorder.beginRecording(const Rect.fromLTRB(0, 0, 400, 400)); | ||
| canvas.drawCircle( | ||
| Offset(offsetX + 10, offsetY + 10), 10, Paint()..style = PaintingStyle.fill); | ||
| recorder.beginRecording(const Rect.fromLTRB(0, 0, 400, 400)); | ||
| canvas.drawCircle(Offset(offsetX + 10, offsetY + 10), 10, | ||
| (Paint()..style = PaintingStyle.fill) as SurfacePaint); | ||
| canvas.drawCircle( | ||
| Offset(offsetX + 60, offsetY + 10), | ||
| 10, | ||
| Paint() | ||
| (Paint() | ||
| ..style = PaintingStyle.fill | ||
| ..color = const Color.fromRGBO(255, 0, 0, 1)); | ||
| ..color = const Color.fromRGBO(255, 0, 0, 1)) as SurfacePaint); | ||
| canvas.drawCircle( | ||
| Offset(offsetX + 10, offsetY + 60), | ||
| 10, | ||
| Paint() | ||
| (Paint() | ||
| ..style = PaintingStyle.fill | ||
| ..color = const Color.fromRGBO(0, 255, 0, 1)); | ||
| ..color = const Color.fromRGBO(0, 255, 0, 1)) as SurfacePaint); | ||
| canvas.drawCircle( | ||
| Offset(offsetX + 60, offsetY + 60), | ||
| 10, | ||
| Paint() | ||
| (Paint() | ||
| ..style = PaintingStyle.fill | ||
| ..color = const Color.fromRGBO(0, 0, 255, 1)); | ||
| ..color = const Color.fromRGBO(0, 0, 255, 1)) as SurfacePaint); | ||
| return recorder.endRecording(); | ||
| } | ||
|
|
||
| Picture _drawTestPictureWithImage(ColorFilter filter) { | ||
| final EnginePictureRecorder recorder = | ||
| PictureRecorder() as EnginePictureRecorder; | ||
| final RecordingCanvas canvas = | ||
| recorder.beginRecording(const Rect.fromLTRB(0, 0, 400, 400)); | ||
| Image testImage = createTestImage(); | ||
|
||
| canvas.drawImageRect( | ||
| testImage, | ||
| Rect.fromLTWH(0, 0, 200, 150), | ||
| Rect.fromLTWH(0, 0, 300, 300), | ||
| (Paint() | ||
| ..style = PaintingStyle.fill | ||
| ..colorFilter = filter | ||
| ..color = const Color.fromRGBO(0, 0, 255, 1)) as SurfacePaint); | ||
| return recorder.endRecording(); | ||
| } | ||
|
|
||
| Picture _drawBackground() { | ||
| final EnginePictureRecorder recorder = PictureRecorder(); | ||
| final EnginePictureRecorder recorder = | ||
| PictureRecorder() as EnginePictureRecorder; | ||
| final RecordingCanvas canvas = | ||
| recorder.beginRecording(const Rect.fromLTRB(0, 0, 400, 400)); | ||
| recorder.beginRecording(const Rect.fromLTRB(0, 0, 400, 400)); | ||
| canvas.drawRect( | ||
| Rect.fromLTWH(8, 8, 400.0 - 16, 400.0 - 16), | ||
| Paint() | ||
| (Paint() | ||
| ..style = PaintingStyle.fill | ||
| ..color = Color(0xFFE0FFE0) | ||
| ); | ||
| ..color = Color(0xFFE0FFE0)) as SurfacePaint); | ||
| return recorder.endRecording(); | ||
| } | ||
|
|
||
| HtmlImage createTestImage({int width = 200, int height = 150}) { | ||
| html.CanvasElement canvas = | ||
| new html.CanvasElement(width: width, height: height); | ||
| html.CanvasRenderingContext2D ctx = canvas.context2D; | ||
| ctx.fillStyle = '#E04040'; | ||
| ctx.fillRect(0, 0, width / 3, height); | ||
| ctx.fill(); | ||
| ctx.fillStyle = '#40E080'; | ||
| ctx.fillRect(width / 3, 0, width / 3, height); | ||
| ctx.fill(); | ||
| ctx.fillStyle = '#2040E0'; | ||
| ctx.fillRect(2 * width / 3, 0, width / 3, height); | ||
| ctx.fill(); | ||
| html.ImageElement imageElement = html.ImageElement(); | ||
| imageElement.src = js_util.callMethod(canvas, 'toDataURL', <dynamic>[]); | ||
| return HtmlImage(imageElement, width, height); | ||
| } | ||
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.
very nit: curly braces around this if statement
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.