Skip to content

Commit 1290892

Browse files
Remove HybridCanvasFrame and hybrid APIs
1 parent 36f2203 commit 1290892

File tree

7 files changed

+2
-395
lines changed

7 files changed

+2
-395
lines changed

src/ImageSharp.Drawing.WebGPU/WEBGPU_BACKEND.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The public WebGPU surface area around this backend is small and target-first:
2424
- `WebGPUDeviceContext<TPixel>` wraps a shared or caller-owned device and queue and creates native-only or hybrid frames and canvases over external textures
2525
- `WebGPUNativeSurfaceFactory` is the low-level escape hatch for caller-owned native targets
2626

27-
Those types all exist to get a `DrawingCanvas<TPixel>` over a native WebGPU target, sometimes paired with a CPU region through `HybridCanvasFrame<TPixel>`. Once the canvas flushes, `WebGPUDrawingBackend` becomes the execution boundary.
27+
Those types all exist to get a `DrawingCanvas<TPixel>` over a native WebGPU target. Once the canvas flushes, `WebGPUDrawingBackend` becomes the execution boundary.
2828

2929
The support probes also live outside the backend:
3030

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

Lines changed: 0 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Six Labors Split License.
33

44
using Silk.NET.WebGPU;
5-
using SixLabors.ImageSharp.Memory;
65
using SixLabors.ImageSharp.PixelFormats;
76

87
namespace SixLabors.ImageSharp.Drawing.Processing.Backends;
@@ -167,74 +166,6 @@ public NativeCanvasFrame<TPixel> CreateFrame(
167166
int height)
168167
=> new(CreateBounds(width, height), this.CreateSurface(textureHandle, textureViewHandle, format, width, height));
169168

170-
/// <summary>
171-
/// Creates a hybrid frame over an externally-owned WebGPU texture and a caller-provided CPU region.
172-
/// </summary>
173-
/// <param name="textureHandle">The opaque <c>WGPUTexture*</c> handle.</param>
174-
/// <param name="textureViewHandle">The opaque <c>WGPUTextureView*</c> handle.</param>
175-
/// <param name="format">The texture format identifier.</param>
176-
/// <param name="width">The frame width in pixels.</param>
177-
/// <param name="height">The frame height in pixels.</param>
178-
/// <param name="cpuRegion">The CPU region to expose alongside the native surface.</param>
179-
/// <returns>A hybrid canvas frame.</returns>
180-
public HybridCanvasFrame<TPixel> CreateHybridFrame(
181-
nint textureHandle,
182-
nint textureViewHandle,
183-
WebGPUTextureFormatId format,
184-
int width,
185-
int height,
186-
Buffer2DRegion<TPixel> cpuRegion)
187-
=> new(CreateBounds(width, height), cpuRegion, this.CreateSurface(textureHandle, textureViewHandle, format, width, height));
188-
189-
/// <summary>
190-
/// Creates a hybrid frame over an externally-owned WebGPU texture and the root frame of a CPU image.
191-
/// </summary>
192-
/// <param name="textureHandle">The opaque <c>WGPUTexture*</c> handle.</param>
193-
/// <param name="textureViewHandle">The opaque <c>WGPUTextureView*</c> handle.</param>
194-
/// <param name="format">The texture format identifier.</param>
195-
/// <param name="image">The CPU image that backs the frame's CPU region.</param>
196-
/// <returns>A hybrid canvas frame.</returns>
197-
public HybridCanvasFrame<TPixel> CreateHybridFrame(
198-
nint textureHandle,
199-
nint textureViewHandle,
200-
WebGPUTextureFormatId format,
201-
Image<TPixel> image)
202-
{
203-
Guard.NotNull(image, nameof(image));
204-
return this.CreateHybridFrame(
205-
textureHandle,
206-
textureViewHandle,
207-
format,
208-
image.Width,
209-
image.Height,
210-
GetImageRegion(image));
211-
}
212-
213-
/// <summary>
214-
/// Creates a hybrid frame over an externally-owned WebGPU texture and a CPU image frame.
215-
/// </summary>
216-
/// <param name="textureHandle">The opaque <c>WGPUTexture*</c> handle.</param>
217-
/// <param name="textureViewHandle">The opaque <c>WGPUTextureView*</c> handle.</param>
218-
/// <param name="format">The texture format identifier.</param>
219-
/// <param name="imageFrame">The CPU image frame that backs the frame's CPU region.</param>
220-
/// <returns>A hybrid canvas frame.</returns>
221-
public HybridCanvasFrame<TPixel> CreateHybridFrame(
222-
nint textureHandle,
223-
nint textureViewHandle,
224-
WebGPUTextureFormatId format,
225-
ImageFrame<TPixel> imageFrame)
226-
{
227-
Guard.NotNull(imageFrame, nameof(imageFrame));
228-
Rectangle bounds = imageFrame.Bounds;
229-
return this.CreateHybridFrame(
230-
textureHandle,
231-
textureViewHandle,
232-
format,
233-
bounds.Width,
234-
bounds.Height,
235-
GetImageRegion(imageFrame));
236-
}
237-
238169
/// <summary>
239170
/// Creates a drawing canvas over an externally-owned WebGPU texture.
240171
/// </summary>
@@ -271,110 +202,6 @@ public DrawingCanvas<TPixel> CreateCanvas(
271202
DrawingOptions options)
272203
=> new(this.Configuration, this.Backend, this.CreateFrame(textureHandle, textureViewHandle, format, width, height), options);
273204

274-
/// <summary>
275-
/// Creates a hybrid drawing canvas over an externally-owned WebGPU texture and a caller-provided CPU region.
276-
/// </summary>
277-
/// <param name="textureHandle">The opaque <c>WGPUTexture*</c> handle.</param>
278-
/// <param name="textureViewHandle">The opaque <c>WGPUTextureView*</c> handle.</param>
279-
/// <param name="format">The texture format identifier.</param>
280-
/// <param name="width">The frame width in pixels.</param>
281-
/// <param name="height">The frame height in pixels.</param>
282-
/// <param name="cpuRegion">The CPU region to expose alongside the native surface.</param>
283-
/// <returns>A drawing canvas targeting the external texture and CPU region.</returns>
284-
public DrawingCanvas<TPixel> CreateHybridCanvas(
285-
nint textureHandle,
286-
nint textureViewHandle,
287-
WebGPUTextureFormatId format,
288-
int width,
289-
int height,
290-
Buffer2DRegion<TPixel> cpuRegion)
291-
=> new(this.Configuration, this.Backend, this.CreateHybridFrame(textureHandle, textureViewHandle, format, width, height, cpuRegion), new DrawingOptions());
292-
293-
/// <summary>
294-
/// Creates a hybrid drawing canvas over an externally-owned WebGPU texture and a caller-provided CPU region.
295-
/// </summary>
296-
/// <param name="textureHandle">The opaque <c>WGPUTexture*</c> handle.</param>
297-
/// <param name="textureViewHandle">The opaque <c>WGPUTextureView*</c> handle.</param>
298-
/// <param name="format">The texture format identifier.</param>
299-
/// <param name="width">The frame width in pixels.</param>
300-
/// <param name="height">The frame height in pixels.</param>
301-
/// <param name="cpuRegion">The CPU region to expose alongside the native surface.</param>
302-
/// <param name="options">The initial drawing options.</param>
303-
/// <returns>A drawing canvas targeting the external texture and CPU region.</returns>
304-
public DrawingCanvas<TPixel> CreateHybridCanvas(
305-
nint textureHandle,
306-
nint textureViewHandle,
307-
WebGPUTextureFormatId format,
308-
int width,
309-
int height,
310-
Buffer2DRegion<TPixel> cpuRegion,
311-
DrawingOptions options)
312-
=> new(this.Configuration, this.Backend, this.CreateHybridFrame(textureHandle, textureViewHandle, format, width, height, cpuRegion), options);
313-
314-
/// <summary>
315-
/// Creates a hybrid drawing canvas over an externally-owned WebGPU texture and the root frame of a CPU image.
316-
/// </summary>
317-
/// <param name="textureHandle">The opaque <c>WGPUTexture*</c> handle.</param>
318-
/// <param name="textureViewHandle">The opaque <c>WGPUTextureView*</c> handle.</param>
319-
/// <param name="format">The texture format identifier.</param>
320-
/// <param name="image">The CPU image that backs the frame's CPU region.</param>
321-
/// <returns>A drawing canvas targeting the external texture and CPU image.</returns>
322-
public DrawingCanvas<TPixel> CreateHybridCanvas(
323-
nint textureHandle,
324-
nint textureViewHandle,
325-
WebGPUTextureFormatId format,
326-
Image<TPixel> image)
327-
=> new(this.Configuration, this.Backend, this.CreateHybridFrame(textureHandle, textureViewHandle, format, image), new DrawingOptions());
328-
329-
/// <summary>
330-
/// Creates a hybrid drawing canvas over an externally-owned WebGPU texture and a CPU image frame.
331-
/// </summary>
332-
/// <param name="textureHandle">The opaque <c>WGPUTexture*</c> handle.</param>
333-
/// <param name="textureViewHandle">The opaque <c>WGPUTextureView*</c> handle.</param>
334-
/// <param name="format">The texture format identifier.</param>
335-
/// <param name="imageFrame">The CPU image frame that backs the frame's CPU region.</param>
336-
/// <returns>A drawing canvas targeting the external texture and CPU image frame.</returns>
337-
public DrawingCanvas<TPixel> CreateHybridCanvas(
338-
nint textureHandle,
339-
nint textureViewHandle,
340-
WebGPUTextureFormatId format,
341-
ImageFrame<TPixel> imageFrame)
342-
=> new(this.Configuration, this.Backend, this.CreateHybridFrame(textureHandle, textureViewHandle, format, imageFrame), new DrawingOptions());
343-
344-
/// <summary>
345-
/// Creates a hybrid drawing canvas over an externally-owned WebGPU texture and the root frame of a CPU image.
346-
/// </summary>
347-
/// <param name="textureHandle">The opaque <c>WGPUTexture*</c> handle.</param>
348-
/// <param name="textureViewHandle">The opaque <c>WGPUTextureView*</c> handle.</param>
349-
/// <param name="format">The texture format identifier.</param>
350-
/// <param name="image">The CPU image that backs the frame's CPU region.</param>
351-
/// <param name="options">The initial drawing options.</param>
352-
/// <returns>A drawing canvas targeting the external texture and CPU image.</returns>
353-
public DrawingCanvas<TPixel> CreateHybridCanvas(
354-
nint textureHandle,
355-
nint textureViewHandle,
356-
WebGPUTextureFormatId format,
357-
Image<TPixel> image,
358-
DrawingOptions options)
359-
=> new(this.Configuration, this.Backend, this.CreateHybridFrame(textureHandle, textureViewHandle, format, image), options);
360-
361-
/// <summary>
362-
/// Creates a hybrid drawing canvas over an externally-owned WebGPU texture and a CPU image frame.
363-
/// </summary>
364-
/// <param name="textureHandle">The opaque <c>WGPUTexture*</c> handle.</param>
365-
/// <param name="textureViewHandle">The opaque <c>WGPUTextureView*</c> handle.</param>
366-
/// <param name="format">The texture format identifier.</param>
367-
/// <param name="imageFrame">The CPU image frame that backs the frame's CPU region.</param>
368-
/// <param name="options">The initial drawing options.</param>
369-
/// <returns>A drawing canvas targeting the external texture and CPU image frame.</returns>
370-
public DrawingCanvas<TPixel> CreateHybridCanvas(
371-
nint textureHandle,
372-
nint textureViewHandle,
373-
WebGPUTextureFormatId format,
374-
ImageFrame<TPixel> imageFrame,
375-
DrawingOptions options)
376-
=> new(this.Configuration, this.Backend, this.CreateHybridFrame(textureHandle, textureViewHandle, format, imageFrame), options);
377-
378205
/// <summary>
379206
/// Disposes the drawing backend owned by this context.
380207
/// </summary>
@@ -446,10 +273,4 @@ private static Rectangle CreateBounds(int width, int height)
446273

447274
return new Rectangle(0, 0, width, height);
448275
}
449-
450-
private static Buffer2DRegion<TPixel> GetImageRegion(Image<TPixel> image)
451-
=> new(image.Frames.RootFrame.PixelBuffer, image.Bounds);
452-
453-
private static Buffer2DRegion<TPixel> GetImageRegion(ImageFrame<TPixel> imageFrame)
454-
=> new(imageFrame.PixelBuffer, imageFrame.Bounds);
455276
}

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

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -165,40 +165,6 @@ public NativeCanvasFrame<TPixel> CreateFrame()
165165
return this.NativeFrame;
166166
}
167167

168-
/// <summary>
169-
/// Creates a hybrid frame over this render target and a caller-provided CPU region.
170-
/// </summary>
171-
/// <param name="cpuRegion">The CPU region to expose alongside the native surface.</param>
172-
/// <returns>A hybrid frame.</returns>
173-
public HybridCanvasFrame<TPixel> CreateHybridFrame(Buffer2DRegion<TPixel> cpuRegion)
174-
{
175-
this.ThrowIfDisposed();
176-
this.Graphics.ThrowIfDisposed();
177-
return new HybridCanvasFrame<TPixel>(this.Bounds, cpuRegion, this.Surface);
178-
}
179-
180-
/// <summary>
181-
/// Creates a hybrid frame over this render target and the root frame of a CPU image.
182-
/// </summary>
183-
/// <param name="image">The CPU image that backs the frame's CPU region.</param>
184-
/// <returns>A hybrid frame.</returns>
185-
public HybridCanvasFrame<TPixel> CreateHybridFrame(Image<TPixel> image)
186-
{
187-
Guard.NotNull(image, nameof(image));
188-
return this.CreateHybridFrame(new Buffer2DRegion<TPixel>(image.Frames.RootFrame.PixelBuffer, image.Bounds));
189-
}
190-
191-
/// <summary>
192-
/// Creates a hybrid frame over this render target and a CPU image frame.
193-
/// </summary>
194-
/// <param name="imageFrame">The CPU image frame that backs the frame's CPU region.</param>
195-
/// <returns>A hybrid frame.</returns>
196-
public HybridCanvasFrame<TPixel> CreateHybridFrame(ImageFrame<TPixel> imageFrame)
197-
{
198-
Guard.NotNull(imageFrame, nameof(imageFrame));
199-
return this.CreateHybridFrame(new Buffer2DRegion<TPixel>(imageFrame.PixelBuffer, imageFrame.Bounds));
200-
}
201-
202168
/// <summary>
203169
/// Creates a drawing canvas over this native-only render target.
204170
/// </summary>
@@ -218,67 +184,6 @@ public DrawingCanvas<TPixel> CreateCanvas(DrawingOptions options)
218184
return new DrawingCanvas<TPixel>(this.Graphics.Configuration, this.Graphics.Backend, this.NativeFrame, options);
219185
}
220186

221-
/// <summary>
222-
/// Creates a hybrid drawing canvas over this render target and a caller-provided CPU region.
223-
/// </summary>
224-
/// <param name="cpuRegion">The CPU region to expose alongside the native surface.</param>
225-
/// <returns>A drawing canvas targeting this render target and CPU region.</returns>
226-
public DrawingCanvas<TPixel> CreateHybridCanvas(Buffer2DRegion<TPixel> cpuRegion)
227-
=> this.CreateHybridCanvas(cpuRegion, new DrawingOptions());
228-
229-
/// <summary>
230-
/// Creates a hybrid drawing canvas over this render target and a caller-provided CPU region.
231-
/// </summary>
232-
/// <param name="cpuRegion">The CPU region to expose alongside the native surface.</param>
233-
/// <param name="options">The initial drawing options.</param>
234-
/// <returns>A drawing canvas targeting this render target and CPU region.</returns>
235-
public DrawingCanvas<TPixel> CreateHybridCanvas(Buffer2DRegion<TPixel> cpuRegion, DrawingOptions options)
236-
{
237-
this.ThrowIfDisposed();
238-
this.Graphics.ThrowIfDisposed();
239-
return new DrawingCanvas<TPixel>(this.Graphics.Configuration, this.Graphics.Backend, this.CreateHybridFrame(cpuRegion), options);
240-
}
241-
242-
/// <summary>
243-
/// Creates a hybrid drawing canvas over this render target and the root frame of a CPU image.
244-
/// </summary>
245-
/// <param name="image">The CPU image that backs the frame's CPU region.</param>
246-
/// <returns>A drawing canvas targeting this render target and CPU image.</returns>
247-
public DrawingCanvas<TPixel> CreateHybridCanvas(Image<TPixel> image)
248-
=> this.CreateHybridCanvas(image, new DrawingOptions());
249-
250-
/// <summary>
251-
/// Creates a hybrid drawing canvas over this render target and the root frame of a CPU image.
252-
/// </summary>
253-
/// <param name="image">The CPU image that backs the frame's CPU region.</param>
254-
/// <param name="options">The initial drawing options.</param>
255-
/// <returns>A drawing canvas targeting this render target and CPU image.</returns>
256-
public DrawingCanvas<TPixel> CreateHybridCanvas(Image<TPixel> image, DrawingOptions options)
257-
{
258-
Guard.NotNull(image, nameof(image));
259-
return this.CreateHybridCanvas(new Buffer2DRegion<TPixel>(image.Frames.RootFrame.PixelBuffer, image.Bounds), options);
260-
}
261-
262-
/// <summary>
263-
/// Creates a hybrid drawing canvas over this render target and a CPU image frame.
264-
/// </summary>
265-
/// <param name="imageFrame">The CPU image frame that backs the frame's CPU region.</param>
266-
/// <returns>A drawing canvas targeting this render target and CPU image frame.</returns>
267-
public DrawingCanvas<TPixel> CreateHybridCanvas(ImageFrame<TPixel> imageFrame)
268-
=> this.CreateHybridCanvas(imageFrame, new DrawingOptions());
269-
270-
/// <summary>
271-
/// Creates a hybrid drawing canvas over this render target and a CPU image frame.
272-
/// </summary>
273-
/// <param name="imageFrame">The CPU image frame that backs the frame's CPU region.</param>
274-
/// <param name="options">The initial drawing options.</param>
275-
/// <returns>A drawing canvas targeting this render target and CPU image frame.</returns>
276-
public DrawingCanvas<TPixel> CreateHybridCanvas(ImageFrame<TPixel> imageFrame, DrawingOptions options)
277-
{
278-
Guard.NotNull(imageFrame, nameof(imageFrame));
279-
return this.CreateHybridCanvas(new Buffer2DRegion<TPixel>(imageFrame.PixelBuffer, imageFrame.Bounds), options);
280-
}
281-
282187
/// <summary>
283188
/// Attempts to read the current GPU texture contents back into a new CPU image.
284189
/// </summary>

src/ImageSharp.Drawing/Processing/Backends/HybridCanvasFrame{TPixel}.cs

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

src/ImageSharp.Drawing/Processing/DRAWING_CANVAS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ That abstraction lets the same canvas target:
119119

120120
- pure CPU memory with `MemoryCanvasFrame<TPixel>`
121121
- a native or GPU surface with `NativeCanvasFrame<TPixel>`
122-
- a combined CPU plus native target with `HybridCanvasFrame<TPixel>`
122+
- a combined CPU plus native target
123123
- a clipped view over another frame with `CanvasRegionFrame<TPixel>`
124124

125125
The point is not to hide all differences. The point is to express the minimum target contract the backends need.

0 commit comments

Comments
 (0)