Skip to content

Commit dc538ad

Browse files
Use auto-properties; drop isRoot flag
1 parent 8344111 commit dc538ad

3 files changed

Lines changed: 28 additions & 38 deletions

File tree

src/ImageSharp.Drawing/Processing/DRAWING_CANVAS.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ DrawingCanvas<TPixel> : IDrawingCanvas, IDisposable
1818
savedStates : Stack<DrawingCanvasState> (min depth 1)
1919
layerDataStack : Stack<LayerData<TPixel>> (one per active SaveLayer)
2020
pendingImageResources : List<Image<TPixel>> (temp images awaiting flush)
21-
isRoot : bool (only root releases frame resources)
2221
isDisposed : bool
2322
```
2423

@@ -238,7 +237,6 @@ CreateRegion(region)
238237
-> create child canvas:
239238
- shares backend and batcher with parent
240239
- snapshots current state
241-
- isRoot = false (no resource release on dispose)
242240
- local origin is (0,0) within clipped region
243241
```
244242

@@ -258,7 +256,6 @@ Dispose()
258256
259257
Phase 3: Cleanup (in finally)
260258
-> DisposePendingImageResources()
261-
-> if isRoot: backend.ReleaseFrameResources(target)
262259
-> isDisposed = true
263260
```
264261

src/ImageSharp.Drawing/Processing/DrawingCanvas{TPixel}.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ internal DrawingCanvas(
115115
backend,
116116
targetFrame,
117117
new DrawingCanvasBatcher<TPixel>(configuration, backend, targetFrame),
118-
new DrawingCanvasState(options, clipPaths),
119-
isRoot: true)
118+
new DrawingCanvasState(options, clipPaths))
120119
{
121120
}
122121

@@ -350,8 +349,7 @@ public DrawingCanvas<TPixel> CreateRegion(Rectangle region)
350349
this.backend,
351350
childFrame,
352351
this.batcher,
353-
this.ResolveState(),
354-
isRoot: false);
352+
this.ResolveState());
355353
}
356354

357355
/// <inheritdoc />

src/ImageSharp.Drawing/Processing/RadialGradientBrush.cs

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ namespace SixLabors.ImageSharp.Drawing.Processing;
1515
/// </summary>
1616
public sealed class RadialGradientBrush : GradientBrush
1717
{
18-
private readonly PointF center0;
19-
private readonly float radius0;
20-
private readonly PointF? center1; // null means single-circle form
21-
private readonly float? radius1;
22-
2318
/// <summary>
2419
/// Initializes a new instance of the <see cref="RadialGradientBrush"/> class using a single circle.
2520
/// </summary>
@@ -34,10 +29,10 @@ public RadialGradientBrush(
3429
params ColorStop[] colorStops)
3530
: base(repetitionMode, colorStops)
3631
{
37-
this.center0 = center;
38-
this.radius0 = radius;
39-
this.center1 = null;
40-
this.radius1 = null;
32+
this.Center0 = center;
33+
this.Radius0 = radius;
34+
this.Center1 = null;
35+
this.Radius1 = null;
4136
}
4237

4338
/// <summary>
@@ -58,49 +53,49 @@ public RadialGradientBrush(
5853
params ColorStop[] colorStops)
5954
: base(repetitionMode, colorStops)
6055
{
61-
this.center0 = startCenter;
62-
this.radius0 = startRadius;
63-
this.center1 = endCenter;
64-
this.radius1 = endRadius;
56+
this.Center0 = startCenter;
57+
this.Radius0 = startRadius;
58+
this.Center1 = endCenter;
59+
this.Radius1 = endRadius;
6560
}
6661

6762
/// <summary>
6863
/// Gets the center of the starting circle.
6964
/// </summary>
70-
public PointF Center0 => this.center0;
65+
public PointF Center0 { get; }
7166

7267
/// <summary>
7368
/// Gets the radius of the starting circle.
7469
/// </summary>
75-
public float Radius0 => this.radius0;
70+
public float Radius0 { get; }
7671

7772
/// <summary>
7873
/// Gets the center of the ending circle, or <see langword="null"/> for single-circle form.
7974
/// </summary>
80-
public PointF? Center1 => this.center1;
75+
public PointF? Center1 { get; }
8176

8277
/// <summary>
8378
/// Gets the radius of the ending circle, or <see langword="null"/> for single-circle form.
8479
/// </summary>
85-
public float? Radius1 => this.radius1;
80+
public float? Radius1 { get; }
8681

8782
/// <summary>
8883
/// Gets a value indicating whether this is a two-circle radial gradient.
8984
/// </summary>
90-
public bool IsTwoCircle => this.center1.HasValue && this.radius1.HasValue;
85+
public bool IsTwoCircle => this.Center1.HasValue && this.Radius1.HasValue;
9186

9287
/// <inheritdoc/>
9388
public override Brush Transform(Matrix4x4 matrix)
9489
{
95-
PointF tc0 = PointF.Transform(this.center0, matrix);
90+
PointF tc0 = PointF.Transform(this.Center0, matrix);
9691
float scale = MatrixUtilities.GetAverageScale(in matrix);
9792
if (this.IsTwoCircle)
9893
{
99-
PointF tc1 = PointF.Transform(this.center1!.Value, matrix);
100-
return new RadialGradientBrush(tc0, this.radius0 * scale, tc1, this.radius1!.Value * scale, this.RepetitionMode, this.ColorStopsArray);
94+
PointF tc1 = PointF.Transform(this.Center1!.Value, matrix);
95+
return new RadialGradientBrush(tc0, this.Radius0 * scale, tc1, this.Radius1!.Value * scale, this.RepetitionMode, this.ColorStopsArray);
10196
}
10297

103-
return new RadialGradientBrush(tc0, this.radius0 * scale, this.RepetitionMode, this.ColorStopsArray);
98+
return new RadialGradientBrush(tc0, this.Radius0 * scale, this.RepetitionMode, this.ColorStopsArray);
10499
}
105100

106101
/// <inheritdoc/>
@@ -109,18 +104,18 @@ public override bool Equals(Brush? other)
109104
if (other is RadialGradientBrush b)
110105
{
111106
return base.Equals(other)
112-
&& this.center0.Equals(b.center0)
113-
&& this.radius0.Equals(b.radius0)
114-
&& Nullable.Equals(this.center1, b.center1)
115-
&& Nullable.Equals(this.radius1, b.radius1);
107+
&& this.Center0.Equals(b.Center0)
108+
&& this.Radius0.Equals(b.Radius0)
109+
&& Nullable.Equals(this.Center1, b.Center1)
110+
&& Nullable.Equals(this.Radius1, b.Radius1);
116111
}
117112

118113
return false;
119114
}
120115

121116
/// <inheritdoc/>
122117
public override int GetHashCode()
123-
=> HashCode.Combine(base.GetHashCode(), this.center0, this.radius0, this.center1, this.radius1);
118+
=> HashCode.Combine(base.GetHashCode(), this.Center0, this.Radius0, this.Center1, this.Radius1);
124119

125120
/// <inheritdoc />
126121
public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
@@ -132,10 +127,10 @@ public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
132127
configuration,
133128
options,
134129
targetRegion,
135-
this.center0,
136-
this.radius0,
137-
this.center1,
138-
this.radius1,
130+
this.Center0,
131+
this.Radius0,
132+
this.Center1,
133+
this.Radius1,
139134
this.ColorStopsArray,
140135
this.RepetitionMode);
141136

0 commit comments

Comments
 (0)