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] Implement sweep gradient #21873
Merged
Merged
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
33a96c8
Update paintStyle to pass shaderBounds to gradient
ferhatb d24bc2a
Merge remote-tracking branch 'upstream/master' into sweepgradient
ferhatb 8762753
implement normalized gradient
ferhatb 4ccd655
Sweepgradient shader. NNBD update.
ferhatb 9b14730
Add golden test
ferhatb c1f14b8
Merge remote-tracking branch 'upstream/master' into sweepgradient
ferhatb 054aea6
Fix flipped image data on webgl1
ferhatb 153269b
remove print
ferhatb 56a8b3f
update golden locks
ferhatb a02edfc
Merge remote-tracking branch 'upstream/master' into sweepgradient
ferhatb e767618
cleanup
ferhatb e904cfe
Fix position/color vertex attribute location
ferhatb 57fa14d
fix golden names
ferhatb 5bce12a
Merge remote-tracking branch 'upstream/master' into sweepgradient
ferhatb 46b5faa
addressed reviewer comment
ferhatb acbe5d9
Address reviewer comments
ferhatb 59238f8
change computeScreenBounds to picture bounds
ferhatb daaa346
golden merge conflict
ferhatb a9a2b79
Merge remote-tracking branch 'upstream/master' into sweepgradient
ferhatb c95a8d0
address review comments
ferhatb 075c7f0
Merge remote-tracking branch 'upstream/master' into sweepgradient
ferhatb f7def02
merge
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| repository: https://github.com/flutter/goldens.git | ||
| revision: 672510dc52daa5b059081f6990582bccdb4ea48f | ||
| revision: 7171fa6b2844b39d08aab87ca5b4e923c18e3b39 |
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 |
|---|---|---|
|
|
@@ -208,8 +208,8 @@ class BitmapCanvas extends EngineCanvas { | |
| } | ||
|
|
||
| /// Sets the global paint styles to correspond to [paint]. | ||
| void _setUpPaint(SurfacePaintData paint) { | ||
| _canvasPool.contextHandle.setUpPaint(paint); | ||
| void _setUpPaint(SurfacePaintData paint, ui.Rect? shaderBounds) { | ||
| _canvasPool.contextHandle.setUpPaint(paint, shaderBounds); | ||
| } | ||
|
|
||
| void _tearDownPaint() { | ||
|
|
@@ -292,56 +292,61 @@ class BitmapCanvas extends EngineCanvas { | |
|
|
||
| @override | ||
| void drawLine(ui.Offset p1, ui.Offset p2, SurfacePaintData paint) { | ||
| _setUpPaint(paint); | ||
| ui.Rect? shaderBounds = (paint.shader != null) ? | ||
| ui.Rect.fromPoints(p1, p2) : null; | ||
| _setUpPaint(paint, shaderBounds); | ||
| _canvasPool.strokeLine(p1, p2); | ||
| _tearDownPaint(); | ||
| } | ||
|
|
||
| @override | ||
| void drawPaint(SurfacePaintData paint) { | ||
| _setUpPaint(paint); | ||
| ui.Rect? shaderBounds = (paint.shader != null) ? | ||
| _computeScreenBounds(_canvasPool._currentTransform) : null; | ||
| _setUpPaint(paint, shaderBounds); | ||
| _canvasPool.fill(); | ||
| _tearDownPaint(); | ||
| } | ||
|
|
||
| @override | ||
| void drawRect(ui.Rect rect, SurfacePaintData paint) { | ||
| _setUpPaint(paint); | ||
| _setUpPaint(paint, rect); | ||
| _canvasPool.drawRect(rect, paint.style); | ||
| _tearDownPaint(); | ||
| } | ||
|
|
||
| @override | ||
| void drawRRect(ui.RRect rrect, SurfacePaintData paint) { | ||
| _setUpPaint(paint); | ||
| _setUpPaint(paint, rrect.outerRect); | ||
| _canvasPool.drawRRect(rrect, paint.style); | ||
| _tearDownPaint(); | ||
| } | ||
|
|
||
| @override | ||
| void drawDRRect(ui.RRect outer, ui.RRect inner, SurfacePaintData paint) { | ||
| _setUpPaint(paint); | ||
| _setUpPaint(paint, outer.outerRect); | ||
| _canvasPool.drawDRRect(outer, inner, paint.style); | ||
| _tearDownPaint(); | ||
| } | ||
|
|
||
| @override | ||
| void drawOval(ui.Rect rect, SurfacePaintData paint) { | ||
| _setUpPaint(paint); | ||
| _setUpPaint(paint, rect); | ||
| _canvasPool.drawOval(rect, paint.style); | ||
| _tearDownPaint(); | ||
| } | ||
|
|
||
| @override | ||
| void drawCircle(ui.Offset c, double radius, SurfacePaintData paint) { | ||
| _setUpPaint(paint); | ||
| _setUpPaint(paint, paint.shader != null | ||
| ? ui.Rect.fromCircle(center: c, radius: radius) : null); | ||
| _canvasPool.drawCircle(c, radius, paint.style); | ||
| _tearDownPaint(); | ||
| } | ||
|
|
||
| @override | ||
| void drawPath(ui.Path path, SurfacePaintData paint) { | ||
| _setUpPaint(paint); | ||
| _setUpPaint(paint, paint.shader != null ? path.getBounds() : null); | ||
| _canvasPool.drawPath(path, paint.style); | ||
| _tearDownPaint(); | ||
| } | ||
|
|
@@ -655,7 +660,7 @@ class BitmapCanvas extends EngineCanvas { | |
| ctx.font = style.cssFontString; | ||
| _cachedLastStyle = style; | ||
| } | ||
| _setUpPaint(paragraph._paint!.paintData); | ||
| _setUpPaint(paragraph._paint!.paintData, null); | ||
| double y = offset.dy + paragraph.alphabeticBaseline; | ||
| final int len = lines.length; | ||
| for (int i = 0; i < len; i++) { | ||
|
|
@@ -761,7 +766,7 @@ class BitmapCanvas extends EngineCanvas { | |
| _drawPointsPaint.strokeWidth = paint.strokeWidth; | ||
| _drawPointsPaint.maskFilter = paint.maskFilter; | ||
|
|
||
| _setUpPaint(_drawPointsPaint); | ||
| _setUpPaint(_drawPointsPaint, null); | ||
| _canvasPool.drawPoints(pointMode, points, paint.strokeWidth! / 2.0); | ||
| _tearDownPaint(); | ||
| } | ||
|
|
@@ -771,6 +776,34 @@ class BitmapCanvas extends EngineCanvas { | |
| _canvasPool.endOfPaint(); | ||
| _elementCache?.commitFrame(); | ||
| } | ||
|
|
||
| /// Computes paint bounds given [targetTransform] to completely cover window | ||
| /// viewport. | ||
| ui.Rect _computeScreenBounds(Matrix4 targetTransform) { | ||
| final Matrix4 inverted = targetTransform.clone()..invert(); | ||
| final double dpr = ui.window.devicePixelRatio; | ||
| final double width = ui.window.physicalSize.width * dpr; | ||
| final double height = ui.window.physicalSize.height * dpr; | ||
| Vector3 topLeft = inverted.perspectiveTransform(Vector3(0, 0, 0)); | ||
| Vector3 topRight = inverted.perspectiveTransform(Vector3(width, 0, 0)); | ||
| Vector3 bottomRight = | ||
| inverted.perspectiveTransform(Vector3(width, height, 0)); | ||
| Vector3 bottomLeft = inverted.perspectiveTransform(Vector3(0, height, 0)); | ||
| return ui.Rect.fromLTRB( | ||
| math.min(topLeft.x, | ||
| math.min(topRight.x, math.min(bottomRight.x, bottomLeft.x))) - | ||
| bounds.left, | ||
| math.min(topLeft.y, | ||
| math.min(topRight.y, math.min(bottomRight.y, bottomLeft.y))) - | ||
| bounds.top, | ||
| math.max(topLeft.x, | ||
| math.max(topRight.x, math.max(bottomRight.x, bottomLeft.x))) - | ||
| bounds.left, | ||
| math.max(topLeft.y, | ||
| math.max(topRight.y, math.max(bottomRight.y, bottomLeft.y))) - | ||
| bounds.top, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| String? _stringForBlendMode(ui.BlendMode? blendMode) { | ||
|
|
@@ -966,3 +999,4 @@ String _maskFilterToCanvasFilter(ui.MaskFilter? maskFilter) { | |
| } | ||
| } | ||
|
|
||
|
|
||
|
||
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
Oops, something went wrong.
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.
Due do layer transforms, this may not work. Using picture bounds should be sufficient because those already take the projected window clip into account.
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.
Updated. Now only using