Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/recording_canvas.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/render_vertices.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/scene.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/scene_builder.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/shaders/normalized_gradient.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/shaders/shader.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/shaders/shader_builder.dart
FILE: ../../../flutter/lib/web_ui/lib/src/engine/html/surface.dart
Expand Down
2 changes: 1 addition & 1 deletion lib/web_ui/dev/goldens_lock.yaml
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
1 change: 1 addition & 0 deletions lib/web_ui/lib/src/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ part 'engine/html/recording_canvas.dart';
part 'engine/html/render_vertices.dart';
part 'engine/html/scene.dart';
part 'engine/html/scene_builder.dart';
part 'engine/html/shaders/normalized_gradient.dart';
part 'engine/html/shaders/shader.dart';
part 'engine/html/shaders/shader_builder.dart';
part 'engine/html/surface.dart';
Expand Down
58 changes: 46 additions & 12 deletions lib/web_ui/lib/src/engine/bitmap_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. Now only using

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) {
Expand Down Expand Up @@ -966,3 +999,4 @@ String _maskFilterToCanvasFilter(ui.MaskFilter? maskFilter) {
}
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

4 changes: 2 additions & 2 deletions lib/web_ui/lib/src/engine/canvas_pool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ class ContextStateHandle {
/// Sets paint properties on the current canvas.
///
/// [tearDownPaint] must be called after calling this method.
void setUpPaint(SurfacePaintData paint) {
void setUpPaint(SurfacePaintData paint, ui.Rect? shaderBounds) {
if (assertionsEnabled) {
assert(!_debugIsPaintSetUp);
_debugIsPaintSetUp = true;
Expand All @@ -776,7 +776,7 @@ class ContextStateHandle {
if (paint.shader != null) {
final EngineGradient engineShader = paint.shader as EngineGradient;
final Object paintStyle =
engineShader.createPaintStyle(_canvasPool.context);
engineShader.createPaintStyle(_canvasPool.context, shaderBounds);
fillStyle = paintStyle;
strokeStyle = paintStyle;
} else if (paint.color != null) {
Expand Down
Loading