Skip to content

Commit 5c7fae3

Browse files
Introduce DrawingCanvas base type and APIs
1 parent 6dc2adc commit 5c7fae3

40 files changed

Lines changed: 384 additions & 241 deletions

samples/DrawingBackendBenchmark/VisualLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private static SKColor ToSkiaColor(Color color)
7070
/// <summary>
7171
/// Draws the shared benchmark scene into the supplied canvas.
7272
/// </summary>
73-
public static void RenderLinesToCanvas(DrawingCanvas<Bgra32> canvas, ReadOnlySpan<VisualLine> lines)
73+
public static void RenderLinesToCanvas(DrawingCanvas canvas, ReadOnlySpan<VisualLine> lines)
7474
{
7575
canvas.Restore();
7676
canvas.Fill(BackgroundBrush);

samples/DrawingBackendBenchmark/WebGpuBenchmarkBackend.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public BenchmarkRenderResult Render(ReadOnlySpan<VisualLine> lines, int width, i
4646
WebGPURenderTarget<Bgra32> renderTarget = this.EnsureRenderTarget(width, height);
4747

4848
Stopwatch stopwatch = Stopwatch.StartNew();
49-
using (DrawingCanvas<Bgra32> canvas = renderTarget.CreateCanvas(new DrawingOptions()))
49+
using (DrawingCanvas canvas = renderTarget.CreateCanvas(new DrawingOptions()))
5050
{
5151
VisualLine.RenderLinesToCanvas(canvas, lines);
5252
canvas.Flush();

samples/WebGPUExternalSurfaceDemo/Controls/WebGPURenderControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public WebGPURenderControl()
4646
/// <summary>
4747
/// Raised each frame once the external surface has acquired a drawable frame.
4848
/// </summary>
49-
public event Action<DrawingCanvas<Bgra32>, TimeSpan>? PaintFrame;
49+
public event Action<DrawingCanvas, TimeSpan>? PaintFrame;
5050

5151
/// <inheritdoc />
5252
protected override void OnHandleCreated(EventArgs e)

samples/WebGPUExternalSurfaceDemo/MainForm.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ public MainForm()
116116
this.Controls.Add(tabs);
117117
}
118118

119-
private void OnPaintClock(DrawingCanvas<Bgra32> canvas, TimeSpan delta)
119+
private void OnPaintClock(DrawingCanvas canvas, TimeSpan delta)
120120
=> this.clockScene.Paint(canvas, delta);
121121

122-
private void OnPaintTiger(DrawingCanvas<Bgra32> canvas, TimeSpan delta)
122+
private void OnPaintTiger(DrawingCanvas canvas, TimeSpan delta)
123123
{
124124
this.tigerScene.Paint(canvas, delta);
125125
this.tigerStatusLabel.Text = this.tigerScene.StatusText;
126126
}
127127

128-
private void OnPaintApply(DrawingCanvas<Bgra32> canvas, TimeSpan delta)
128+
private void OnPaintApply(DrawingCanvas canvas, TimeSpan delta)
129129
=> this.applyScene.Paint(canvas, delta);
130130
}

samples/WebGPUExternalSurfaceDemo/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ It exists to demonstrate:
77
- creating a `WebGPUExternalSurface<Bgra32>` from a `WebGPUSurfaceHost`
88
- keeping the external surface synchronized with the host control's drawable framebuffer size
99
- acquiring `WebGPUSurfaceFrame<TPixel>` instances manually
10-
- drawing with the normal `DrawingCanvas<TPixel>` API
10+
- drawing with the normal `DrawingCanvas` API
1111
- presenting by disposing the acquired frame
1212

1313
## Running
@@ -113,7 +113,7 @@ The scenes are deliberately ordinary canvas code:
113113

114114
Each scene receives:
115115

116-
- `DrawingCanvas<Bgra32>` for the acquired frame
116+
- `DrawingCanvas` for the acquired frame
117117
- elapsed time since the previous frame
118118

119119
## Files

samples/WebGPUExternalSurfaceDemo/Scenes/ApplyReadbackScene.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal sealed class ApplyReadbackScene : RenderScene
3535

3636
public override string DisplayName => "Apply";
3737

38-
public override void Paint(DrawingCanvas<Bgra32> canvas, TimeSpan deltaTime)
38+
public override void Paint(DrawingCanvas canvas, TimeSpan deltaTime)
3939
{
4040
Size viewportSize = canvas.Bounds.Size;
4141

@@ -77,7 +77,7 @@ public override void OnMouseWheel(MouseEventArgs e)
7777
this.regionScale = Math.Clamp(this.regionScale * factor, .5F, 2.4F);
7878
}
7979

80-
private static void DrawPattern(DrawingCanvas<Bgra32> canvas, Size viewportSize)
80+
private static void DrawPattern(DrawingCanvas canvas, Size viewportSize)
8181
{
8282
float stripeWidth = Math.Max(18F, viewportSize.Width / 18F);
8383
float height = viewportSize.Height;

samples/WebGPUExternalSurfaceDemo/Scenes/ClockScene.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public ClockScene()
5252

5353
public override string DisplayName => "Clock";
5454

55-
public override void Paint(DrawingCanvas<Bgra32> canvas, TimeSpan deltaTime)
55+
public override void Paint(DrawingCanvas canvas, TimeSpan deltaTime)
5656
{
5757
Size viewportSize = canvas.Bounds.Size;
5858

@@ -134,7 +134,7 @@ public override void Paint(DrawingCanvas<Bgra32> canvas, TimeSpan deltaTime)
134134
}
135135

136136
private static void DrawHand(
137-
DrawingCanvas<Bgra32> canvas,
137+
DrawingCanvas canvas,
138138
float cx,
139139
float cy,
140140
float angleRadiansFromNoon,

samples/WebGPUExternalSurfaceDemo/Scenes/RenderScene.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal abstract class RenderScene
2323
/// </summary>
2424
/// <param name="canvas">The per-frame drawing canvas bound to the external surface's swap-chain texture.</param>
2525
/// <param name="deltaTime">Elapsed time since the previous frame. Scenes that render from absolute state can ignore it.</param>
26-
public abstract void Paint(DrawingCanvas<Bgra32> canvas, TimeSpan deltaTime);
26+
public abstract void Paint(DrawingCanvas canvas, TimeSpan deltaTime);
2727

2828
/// <summary>
2929
/// Handles a mouse-button press. Default implementation is a no-op.

samples/WebGPUExternalSurfaceDemo/Scenes/TigerViewerScene.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public string StatusText
7171
}
7272
}
7373

74-
public override void Paint(DrawingCanvas<Bgra32> canvas, TimeSpan deltaTime)
74+
public override void Paint(DrawingCanvas canvas, TimeSpan deltaTime)
7575
{
7676
Size viewportSize = canvas.Bounds.Size;
7777

samples/WebGPUWindowDemo/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private void OnUpdate(TimeSpan deltaTime)
149149
/// </remarks>
150150
private void OnRender(WebGPUSurfaceFrame<Bgra32> frame)
151151
{
152-
DrawingCanvas<Bgra32> canvas = frame.Canvas;
152+
DrawingCanvas canvas = frame.Canvas;
153153
Rectangle bounds = canvas.Bounds;
154154
canvas.Fill(Brushes.Solid(Color.FromPixel(new Bgra32(30, 30, 40, 255))));
155155

@@ -180,7 +180,7 @@ private void OnRender(WebGPUSurfaceFrame<Bgra32> frame)
180180
/// <param name="canvas">The destination canvas for the current frame.</param>
181181
/// <param name="width">The current framebuffer width.</param>
182182
/// <param name="height">The current framebuffer height.</param>
183-
private void DrawScrollingText(DrawingCanvas<Bgra32> canvas, int width, int height)
183+
private void DrawScrollingText(DrawingCanvas canvas, int width, int height)
184184
{
185185
if (this.scrollTextHeight <= 0)
186186
{

0 commit comments

Comments
 (0)