66namespace SixLabors . ImageSharp . Drawing . Processing . Backends ;
77
88/// <summary>
9- /// WebGPU native drawing target exposed through the backend-agnostic <see cref="NativeSurface"/> contract .
9+ /// WebGPU native drawing surface exposed through the backend-agnostic <see cref="NativeSurface"/> base type .
1010/// </summary>
1111internal sealed class WebGPUNativeSurface : NativeSurface
1212{
13- private readonly WebGPUNativeTarget target ;
14-
1513 /// <summary>
1614 /// Initializes a new instance of the <see cref="WebGPUNativeSurface"/> class.
1715 /// </summary>
18- /// <param name="target">The WebGPU target exposed by this surface.</param>
19- internal WebGPUNativeSurface ( WebGPUNativeTarget target )
20- => this . target = target ;
16+ /// <param name="deviceHandle">The wrapped device handle that owns the target texture.</param>
17+ /// <param name="queueHandle">The wrapped queue handle used to submit work against the target texture.</param>
18+ /// <param name="targetTextureHandle">The wrapped target texture handle.</param>
19+ /// <param name="targetTextureViewHandle">The wrapped target texture-view handle.</param>
20+ /// <param name="targetFormat">The target texture format.</param>
21+ /// <param name="width">The surface width in pixels.</param>
22+ /// <param name="height">The surface height in pixels.</param>
23+ public WebGPUNativeSurface (
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+ this . DeviceHandle = deviceHandle ;
38+ this . QueueHandle = queueHandle ;
39+ this . TargetTextureHandle = targetTextureHandle ;
40+ this . TargetTextureViewHandle = targetTextureViewHandle ;
41+ this . TargetFormat = targetFormat ;
42+ this . Width = width ;
43+ this . Height = height ;
44+ }
45+
46+ /// <summary>
47+ /// Gets the wrapped device handle that owns the target texture.
48+ /// </summary>
49+ public WebGPUDeviceHandle DeviceHandle { get ; }
50+
51+ /// <summary>
52+ /// Gets the wrapped queue handle used to submit work against the target texture.
53+ /// </summary>
54+ public WebGPUQueueHandle QueueHandle { get ; }
55+
56+ /// <summary>
57+ /// Gets the wrapped target texture handle.
58+ /// </summary>
59+ public WebGPUTextureHandle TargetTextureHandle { get ; }
60+
61+ /// <summary>
62+ /// Gets the wrapped target texture-view handle.
63+ /// </summary>
64+ public WebGPUTextureViewHandle TargetTextureViewHandle { get ; }
65+
66+ /// <summary>
67+ /// Gets the native render target texture format identifier.
68+ /// </summary>
69+ public WebGPUTextureFormat TargetFormat { get ; }
70+
71+ /// <summary>
72+ /// Gets the surface width in pixels.
73+ /// </summary>
74+ public int Width { get ; }
75+
76+ /// <summary>
77+ /// Gets the surface height in pixels.
78+ /// </summary>
79+ public int Height { get ; }
2180
2281 /// <summary>
2382 /// Allocates a WebGPU render target and creates a native surface over the owned texture handles.
@@ -31,7 +90,7 @@ internal WebGPUNativeSurface(WebGPUNativeTarget target)
3190 /// <param name="textureHandle">Receives the allocated wrapped <c>WGPUTexture*</c> handle.</param>
3291 /// <param name="textureViewHandle">Receives the allocated wrapped <c>WGPUTextureView*</c> handle.</param>
3392 /// <returns>The native surface wrapping the allocated texture.</returns>
34- internal static unsafe NativeSurface Create (
93+ internal static unsafe WebGPUNativeSurface Create (
3594 WebGPU api ,
3695 WebGPUDeviceHandle deviceHandle ,
3796 WebGPUQueueHandle queueHandle ,
@@ -105,7 +164,7 @@ internal static unsafe NativeSurface Create(
105164 {
106165 createdTextureHandle = new WebGPUTextureHandle ( api , ( nint ) texture , ownsHandle : true ) ;
107166 createdTextureViewHandle = new WebGPUTextureViewHandle ( api , ( nint ) textureView , ownsHandle : true ) ;
108- NativeSurface surface = Create (
167+ WebGPUNativeSurface surface = Create (
109168 deviceHandle ,
110169 queueHandle ,
111170 createdTextureHandle ,
@@ -140,7 +199,7 @@ internal static unsafe NativeSurface Create(
140199 /// <summary>
141200 /// Creates a native surface over wrapped WebGPU texture handles.
142201 /// </summary>
143- internal static NativeSurface Create (
202+ internal static WebGPUNativeSurface Create (
144203 WebGPUDeviceHandle deviceHandle ,
145204 WebGPUQueueHandle queueHandle ,
146205 WebGPUTextureHandle targetTextureHandle ,
@@ -157,25 +216,13 @@ internal static NativeSurface Create(
157216 Guard . MustBeGreaterThan ( width , 0 , nameof ( width ) ) ;
158217 Guard . MustBeGreaterThan ( height , 0 , nameof ( height ) ) ;
159218
160- return new WebGPUNativeSurface ( new WebGPUNativeTarget (
219+ return new WebGPUNativeSurface (
161220 deviceHandle ,
162221 queueHandle ,
163222 targetTextureHandle ,
164223 targetTextureViewHandle ,
165224 targetFormat ,
166225 width ,
167- height ) ) ;
168- }
169-
170- /// <inheritdoc />
171- public override TNativeTarget GetNativeTarget < TNativeTarget > ( )
172- where TNativeTarget : class
173- {
174- if ( this . target is TNativeTarget typed )
175- {
176- return typed ;
177- }
178-
179- throw new NotSupportedException ( $ "The native surface does not expose a native target of type '{ typeof ( TNativeTarget ) . Name } '.") ;
226+ height ) ;
180227 }
181228}
0 commit comments