Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[web] fix ==/hashCode/toString for several classes across renderers #49786

Merged
merged 4 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 1 addition & 14 deletions lib/web_ui/lib/src/engine/canvaskit/image_filter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,6 @@ class _CkBlurImageFilter extends CkImageFilter {
borrow(_ref.nativeObject);
}

String get _modeString {
switch (tileMode) {
case ui.TileMode.clamp:
return 'clamp';
case ui.TileMode.mirror:
return 'mirror';
case ui.TileMode.repeated:
return 'repeated';
case ui.TileMode.decal:
return 'decal';
}
}

@override
bool operator ==(Object other) {
if (runtimeType != other.runtimeType) {
Expand All @@ -149,7 +136,7 @@ class _CkBlurImageFilter extends CkImageFilter {

@override
String toString() {
return 'ImageFilter.blur($sigmaX, $sigmaY, $_modeString)';
return 'ImageFilter.blur($sigmaX, $sigmaY, ${tileModeString(tileMode)})';
}
}

Expand Down
79 changes: 79 additions & 0 deletions lib/web_ui/lib/src/engine/canvaskit/painting.dart
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,85 @@ class CkPaint implements ui.Paint {
void dispose() {
_ref.dispose();
}

// Must be kept in sync with the default in paint.cc.
static const double _kStrokeMiterLimitDefault = 4.0;

// Must be kept in sync with the default in paint.cc.
static const int _kColorDefault = 0xFF000000;

// Must be kept in sync with the default in paint.cc.
static final int _kBlendModeDefault = ui.BlendMode.srcOver.index;

@override
String toString() {
String resultString = 'Paint()';

assert(() {
final StringBuffer result = StringBuffer();
String semicolon = '';
result.write('Paint(');
if (style == ui.PaintingStyle.stroke) {
result.write('$style');
if (strokeWidth != 0.0) {
result.write(' ${strokeWidth.toStringAsFixed(1)}');
} else {
result.write(' hairline');
}
if (strokeCap != ui.StrokeCap.butt) {
result.write(' $strokeCap');
}
if (strokeJoin == ui.StrokeJoin.miter) {
if (strokeMiterLimit != _kStrokeMiterLimitDefault) {
result.write(' $strokeJoin up to ${strokeMiterLimit.toStringAsFixed(1)}');
}
} else {
result.write(' $strokeJoin');
}
semicolon = '; ';
}
if (!isAntiAlias) {
result.write('${semicolon}antialias off');
semicolon = '; ';
}
if (color != const ui.Color(_kColorDefault)) {
result.write('$semicolon$color');
semicolon = '; ';
}
if (blendMode.index != _kBlendModeDefault) {
result.write('$semicolon$blendMode');
semicolon = '; ';
}
if (colorFilter != null) {
result.write('${semicolon}colorFilter: $colorFilter');
semicolon = '; ';
}
if (maskFilter != null) {
result.write('${semicolon}maskFilter: $maskFilter');
semicolon = '; ';
}
if (filterQuality != ui.FilterQuality.none) {
result.write('${semicolon}filterQuality: $filterQuality');
semicolon = '; ';
}
if (shader != null) {
result.write('${semicolon}shader: $shader');
semicolon = '; ';
}
if (imageFilter != null) {
result.write('${semicolon}imageFilter: $imageFilter');
semicolon = '; ';
}
if (invertColors) {
result.write('${semicolon}invert: $invertColors');
}
result.write(')');
resultString = result.toString();
return true;
}());

return resultString;
}
}

final Float32List _invertColorMatrix = Float32List.fromList(const <double>[
Expand Down
9 changes: 9 additions & 0 deletions lib/web_ui/lib/src/engine/canvaskit/shader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ abstract class SimpleCkShader implements CkShader {
void dispose() {
_ref.dispose();
}

@override
String toString() => 'Gradient()';
}

class CkGradientSweep extends SimpleCkShader implements ui.Gradient {
Expand Down Expand Up @@ -133,6 +136,9 @@ class CkGradientLinear extends SimpleCkShader implements ui.Gradient {
matrix4 != null ? toSkMatrixFromFloat32(matrix4!) : null,
);
}

@override
String toString() => 'Gradient()';
}

class CkGradientRadial extends SimpleCkShader implements ui.Gradient {
Expand Down Expand Up @@ -161,6 +167,9 @@ class CkGradientRadial extends SimpleCkShader implements ui.Gradient {
0,
);
}

@override
String toString() => 'Gradient()';
}

class CkGradientConical extends SimpleCkShader implements ui.Gradient {
Expand Down
Loading