Skip to content

Commit c2e93f8

Browse files
Remove Present method; auto-present on Dispose
1 parent dedd939 commit c2e93f8

2 files changed

Lines changed: 7 additions & 33 deletions

File tree

samples/WebGPUWindowDemo/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Separating animation from rendering keeps the sample structure close to a normal
108108
this.window.Run(this.OnRender);
109109
```
110110

111-
`WebGPUWindow<TPixel>.Run(...)` acquires one `WebGPUSurfaceFrame<TPixel>` per render callback and disposes it automatically after your callback returns. In this sample that means you do not call `Present()` or `Flush()` yourself.
111+
`WebGPUWindow<TPixel>.Run(...)` acquires one `WebGPUSurfaceFrame<TPixel>` per render callback and disposes it automatically after your callback returns. In this sample that means you do not call `Flush()` yourself.
112112

113113
Inside `OnRender(...)` the sample:
114114

@@ -154,7 +154,7 @@ This sample uses the `Run(Action<WebGPUSurfaceFrame<TPixel>>)` overload, so fram
154154
Two practical consequences:
155155

156156
- you do not need to call `canvas.Flush()` in this sample
157-
- you only need `frame.Present()` if you are driving frames manually and want to present before disposal
157+
- manual frame loops should dispose each acquired frame exactly once
158158

159159
## What actually runs on the GPU
160160

@@ -186,7 +186,7 @@ Notes:
186186

187187
- a `false` result is normal retry behavior, not necessarily an error
188188
- this can happen when the surface is outdated, lost, timed out, or the framebuffer is currently zero-sized
189-
- disposing the frame is normally enough; explicit `Present()` is optional
189+
- disposing the frame flushes queued canvas work, presents the surface, and releases per-frame resources
190190

191191
## Resize behavior
192192

src/ImageSharp.Drawing.WebGPU/WebGPUSurfaceFrame{TPixel}.cs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
88

99
/// <summary>
1010
/// A single acquired drawable frame returned by a WebGPU surface.
11-
/// Use the <see cref="Canvas"/> to draw the frame contents, then either call <see cref="Present"/> or dispose
12-
/// the frame to show it on screen.
11+
/// Use the <see cref="Canvas"/> to draw the frame contents, then dispose the frame to show it on screen.
1312
/// </summary>
1413
/// <typeparam name="TPixel">The canvas pixel format.</typeparam>
1514
public sealed unsafe class WebGPUSurfaceFrame<TPixel> : IDisposable
@@ -21,7 +20,6 @@ public sealed unsafe class WebGPUSurfaceFrame<TPixel> : IDisposable
2120
private readonly WebGPUTextureViewHandle textureViewHandle;
2221
private readonly Action? onDisposed;
2322
private bool isDisposed;
24-
private bool presented;
2523

2624
internal WebGPUSurfaceFrame(
2725
WebGPU api,
@@ -45,27 +43,7 @@ internal WebGPUSurfaceFrame(
4543
public DrawingCanvas<TPixel> Canvas { get; }
4644

4745
/// <summary>
48-
/// Flushes pending canvas work and presents the frame on screen.
49-
/// </summary>
50-
/// <remarks>
51-
/// This method finalizes the current frame. If you do not call it explicitly, <see cref="Dispose"/>
52-
/// will flush and present the frame automatically.
53-
/// </remarks>
54-
public void Present()
55-
{
56-
ObjectDisposedException.ThrowIf(this.isDisposed, this);
57-
if (this.presented)
58-
{
59-
return;
60-
}
61-
62-
this.Canvas.Flush();
63-
this.api.SurfacePresent((Surface*)this.surfaceReference.Handle);
64-
this.presented = true;
65-
}
66-
67-
/// <summary>
68-
/// Disposes the frame, flushing and presenting it if needed, then releasing the per-frame WebGPU resources.
46+
/// Disposes the frame, flushing and presenting it, then releasing the per-frame WebGPU resources.
6947
/// </summary>
7048
public void Dispose()
7149
{
@@ -76,12 +54,8 @@ public void Dispose()
7654

7755
try
7856
{
79-
if (!this.presented)
80-
{
81-
this.Canvas.Flush();
82-
this.api.SurfacePresent((Surface*)this.surfaceReference.Handle);
83-
this.presented = true;
84-
}
57+
this.Canvas.Flush();
58+
this.api.SurfacePresent((Surface*)this.surfaceReference.Handle);
8559
}
8660
finally
8761
{

0 commit comments

Comments
 (0)