Skip to content

Commit 7c66fb2

Browse files
Remove WebGPUNativeSurfaceFactory
1 parent 66327e4 commit 7c66fb2

7 files changed

Lines changed: 39 additions & 53 deletions

File tree

src/ImageSharp.Drawing.WebGPU/WEBGPU_BACKEND.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@ This document explains the backend as a newcomer would need to understand it:
1616

1717
## Where The Public WebGPU Types Fit
1818

19-
The public WebGPU surface area around this backend is small and target-first. Most applications only reach for the recommended types; the advanced types exist as escape hatches for unusual interop scenarios.
19+
The public WebGPU surface area around this backend is small and target-first.
2020

21-
**Recommended types** — the entry points most applications should use:
21+
**Public types** — the entry points applications should use:
2222

2323
- `WebGPUEnvironment` exposes explicit support probes for the library-managed WebGPU environment
2424
- `WebGPUWindow` owns a native window and either runs a render loop or returns `WebGPUSurfaceFrame` instances through `TryAcquireFrame(...)`
2525
- `WebGPUExternalSurface` attaches to a caller-owned native host via `WebGPUSurfaceHost`; the host application owns the UI object and tells the external surface when the drawable framebuffer resizes
26-
- `WebGPURenderTarget` owns an offscreen native target for GPU rendering, hybrid CPU plus GPU canvases, and readback
27-
28-
**Advanced types** — interop escape hatches for applications that already own a native texture target:
29-
30-
- `WebGPUNativeSurfaceFactory` is the low-level escape hatch for caller-owned native targets
26+
- `WebGPURenderTarget` owns an offscreen native target for GPU rendering and readback
3127

3228
`WebGPUDeviceContext` is internal infrastructure used by targets and surfaces. It is not part of the public WebGPU entry-point model.
3329

@@ -149,7 +145,7 @@ The expensive staged work is delegated:
149145
The public object graph around those responsibilities is also separate:
150146

151147
- `WebGPUEnvironment` handles explicit support probes
152-
- `WebGPUWindow`, `WebGPUExternalSurface`, and `WebGPURenderTarget` are the public target constructors; `WebGPUNativeSurfaceFactory` remains the low-level interop escape hatch for caller-owned textures
148+
- `WebGPUWindow`, `WebGPUExternalSurface`, and `WebGPURenderTarget` are the public target constructors
153149
- `DrawingCanvas` hands prepared `DrawingCommandBatch` ranges to the backend
154150

155151
## The Backend Boundary
@@ -269,7 +265,7 @@ The easiest way to keep this backend straight is to remember that it is not the
269265
If that model is clear, the major types fall into place:
270266

271267
- `WebGPUEnvironment` exposes explicit support probes
272-
- `WebGPUWindow`, `WebGPUExternalSurface`, and `WebGPURenderTarget` are the recommended target types; `WebGPUNativeSurfaceFactory` is the advanced interop escape hatch
268+
- `WebGPUWindow`, `WebGPUExternalSurface`, and `WebGPURenderTarget` are the public target types
273269
- `WebGPUDrawingBackend` orchestrates and decides policy
274270
- `WebGPUFlushContext` owns one flush's execution state
275271
- `WebGPURuntime` owns longer-lived device state

src/ImageSharp.Drawing.WebGPU/WEBGPU_RASTERIZER.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Together, these types turn one retained encoded scene into staged GPU work, sche
1414

1515
This document starts after two earlier boundaries have already been crossed:
1616

17-
- public WebGPU setup has already selected or created a native target through `WebGPUWindow`, `WebGPUExternalSurface`, `WebGPURenderTarget`, or `WebGPUNativeSurfaceFactory`
17+
- public WebGPU setup has already selected or created a native target through `WebGPUWindow`, `WebGPUExternalSurface`, or `WebGPURenderTarget`
1818
- `WebGPUDrawingBackend.RenderScene<TPixel>(...)` has already validated the typed native target
1919

2020
Support probing through `WebGPUEnvironment` also sits outside this document. The rasterizer describes execution of one staged scene, not environment detection or object construction.

src/ImageSharp.Drawing.WebGPU/WebGPUDeviceContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private NativeSurface CreateSurface(
271271
Guard.NotNull(textureHandle, nameof(textureHandle));
272272
Guard.NotNull(textureViewHandle, nameof(textureViewHandle));
273273

274-
return WebGPUNativeSurfaceFactory.Create(
274+
return WebGPUNativeSurface.Create(
275275
this.DeviceHandle,
276276
this.QueueHandle,
277277
textureHandle,

src/ImageSharp.Drawing.WebGPU/WebGPUNativeSurface.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,36 @@ internal sealed class WebGPUNativeSurface : NativeSurface
1717
internal WebGPUNativeSurface(WebGPUNativeTarget target)
1818
=> this.target = target;
1919

20+
/// <summary>
21+
/// Creates a native surface over wrapped WebGPU texture handles.
22+
/// </summary>
23+
internal static NativeSurface Create(
24+
WebGPUDeviceHandle deviceHandle,
25+
WebGPUQueueHandle queueHandle,
26+
WebGPUTextureHandle targetTextureHandle,
27+
WebGPUTextureViewHandle targetTextureViewHandle,
28+
WebGPUTextureFormat targetFormat,
29+
int width,
30+
int height)
31+
{
32+
Guard.NotNull(deviceHandle, nameof(deviceHandle));
33+
Guard.NotNull(queueHandle, nameof(queueHandle));
34+
Guard.NotNull(targetTextureHandle, nameof(targetTextureHandle));
35+
Guard.NotNull(targetTextureViewHandle, nameof(targetTextureViewHandle));
36+
37+
Guard.MustBeGreaterThan(width, 0, nameof(width));
38+
Guard.MustBeGreaterThan(height, 0, nameof(height));
39+
40+
return new WebGPUNativeSurface(new WebGPUNativeTarget(
41+
deviceHandle,
42+
queueHandle,
43+
targetTextureHandle,
44+
targetTextureViewHandle,
45+
targetFormat,
46+
width,
47+
height));
48+
}
49+
2050
/// <inheritdoc />
2151
public override TNativeTarget GetNativeTarget<TNativeTarget>()
2252
where TNativeTarget : class

src/ImageSharp.Drawing.WebGPU/WebGPUNativeSurfaceFactory.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/ImageSharp.Drawing.WebGPU/WebGPURenderTarget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private WebGPURenderTarget(
121121
/// Gets the native surface backing this render target.
122122
/// Most callers should use <see cref="CreateCanvas()"/> or <see cref="Readback{TPixel}"/> instead.
123123
/// </summary>
124-
public NativeSurface Surface { get; }
124+
internal NativeSurface Surface { get; }
125125

126126
/// <summary>
127127
/// Gets the target width in pixels.

src/ImageSharp.Drawing.WebGPU/WebGPURenderTargetAllocation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ internal static NativeSurface CreateRenderTarget(
9696
{
9797
createdTextureHandle = new WebGPUTextureHandle(api, (nint)texture, ownsHandle: true);
9898
createdTextureViewHandle = new WebGPUTextureViewHandle(api, (nint)textureView, ownsHandle: true);
99-
NativeSurface surface = WebGPUNativeSurfaceFactory.Create(
99+
NativeSurface surface = WebGPUNativeSurface.Create(
100100
deviceHandle,
101101
queueHandle,
102102
createdTextureHandle,

0 commit comments

Comments
 (0)