99namespace SixLabors . ImageSharp . Drawing . Processing . Backends ;
1010
1111/// <summary>
12- /// Owning container for the per-surface WebGPU stack: instance, surface, adapter, device, queue, drawing context,
12+ /// Owning container for the per-surface WebGPU stack: instance, surface, adapter, device, queue, device context,
1313/// and the negotiated swapchain texture format.
1414/// </summary>
1515/// <remarks>
@@ -38,19 +38,20 @@ internal sealed unsafe class WebGPUSurfaceResources : IDisposable
3838 private bool frameInFlight ;
3939 private readonly FeatureName requiredFeature ;
4040 private readonly Configuration configuration ;
41+ private WebGPUDeviceContext deviceContext ;
4142
4243 /// <summary>
4344 /// Initializes a new instance of the <see cref="WebGPUSurfaceResources"/> class with already-acquired handles.
4445 /// Only invoked by <see cref="Create"/> after every handle has been successfully bootstrapped.
4546 /// </summary>
4647 /// <param name="api">The shared WebGPU API loader.</param>
47- /// <param name="configuration">The ImageSharp configuration the drawing context uses for its rendering backend.</param>
48+ /// <param name="configuration">The ImageSharp configuration the device context uses for its rendering backend.</param>
4849 /// <param name="instanceHandle">The owned WebGPU instance handle.</param>
4950 /// <param name="surfaceHandle">The owned WebGPU surface handle attached to the native host.</param>
5051 /// <param name="adapterHandle">The owned adapter handle selected for <paramref name="surfaceHandle"/>.</param>
5152 /// <param name="deviceHandle">The owned device handle requested from <paramref name="adapterHandle"/>.</param>
5253 /// <param name="queueHandle">The owned default queue handle paired with <paramref name="deviceHandle"/>.</param>
53- /// <param name="graphics ">The drawing context bound to <paramref name="deviceHandle"/> and <paramref name="queueHandle"/>.</param>
54+ /// <param name="deviceContext ">The device context bound to <paramref name="deviceHandle"/> and <paramref name="queueHandle"/>.</param>
5455 /// <param name="format">The negotiated swapchain texture format.</param>
5556 /// <param name="requiredFeature">The optional WebGPU feature required by the selected texture format.</param>
5657 private WebGPUSurfaceResources (
@@ -61,7 +62,7 @@ private WebGPUSurfaceResources(
6162 WebGPUAdapterHandle adapterHandle ,
6263 WebGPUDeviceHandle deviceHandle ,
6364 WebGPUQueueHandle queueHandle ,
64- WebGPUDeviceContext graphics ,
65+ WebGPUDeviceContext deviceContext ,
6566 WebGPUTextureFormat format ,
6667 FeatureName requiredFeature )
6768 {
@@ -72,7 +73,7 @@ private WebGPUSurfaceResources(
7273 this . AdapterHandle = adapterHandle ;
7374 this . DeviceHandle = deviceHandle ;
7475 this . QueueHandle = queueHandle ;
75- this . Graphics = graphics ;
76+ this . deviceContext = deviceContext ;
7677 this . Format = format ;
7778 this . requiredFeature = requiredFeature ;
7879 }
@@ -108,12 +109,6 @@ private WebGPUSurfaceResources(
108109 /// </summary>
109110 public WebGPUQueueHandle QueueHandle { get ; private set ; }
110111
111- /// <summary>
112- /// Gets the drawing context bound to <see cref="DeviceHandle"/>/<see cref="QueueHandle"/>, used to wrap acquired
113- /// per-frame textures into <see cref="DrawingCanvas"/> instances.
114- /// </summary>
115- internal WebGPUDeviceContext Graphics { get ; private set ; }
116-
117112 /// <summary>
118113 /// Gets the swapchain texture format chosen at construction time.
119114 /// Stable for the lifetime of this instance.
@@ -124,7 +119,7 @@ private WebGPUSurfaceResources(
124119 /// Bootstraps the full per-surface WebGPU stack bound to <paramref name="nativeSource"/> and leaves the surface
125120 /// configured against <paramref name="initialPresentMode"/> and <paramref name="initialFramebufferSize"/>.
126121 /// </summary>
127- /// <param name="configuration">The ImageSharp configuration the drawing context will use for its rendering backend.</param>
122+ /// <param name="configuration">The ImageSharp configuration the device context will use for its rendering backend.</param>
128123 /// <param name="nativeSource">The native surface source that provides the platform handles for surface creation.</param>
129124 /// <param name="format">The swapchain texture format.</param>
130125 /// <param name="initialPresentMode">The present mode to apply to the first surface configuration.</param>
@@ -180,7 +175,7 @@ public static WebGPUSurfaceResources Create(
180175 deviceResources . AdapterHandle ,
181176 deviceResources . DeviceHandle ,
182177 deviceResources . QueueHandle ,
183- deviceResources . Graphics ,
178+ deviceResources . DeviceContext ,
184179 format ,
185180 requiredFeature ) ;
186181
@@ -339,7 +334,7 @@ public bool TryAcquireFrame(
339334 {
340335 textureHandle = new WebGPUTextureHandle ( this . Api , ( nint ) surfaceTexture . Texture , ownsHandle : true ) ;
341336 textureViewHandle = new WebGPUTextureViewHandle ( this . Api , ( nint ) textureView , ownsHandle : true ) ;
342- DrawingCanvas canvas = this . Graphics . CreateCanvas (
337+ DrawingCanvas canvas = this . deviceContext . CreateCanvas (
343338 options ,
344339 textureHandle ,
345340 textureViewHandle ,
@@ -378,7 +373,7 @@ public bool TryAcquireFrame(
378373 }
379374
380375 /// <summary>
381- /// Releases every owned handle in reverse acquisition order (graphics context, queue, device, adapter, surface, instance).
376+ /// Releases every owned handle in reverse acquisition order (device context, queue, device, adapter, surface, instance).
382377 /// Idempotent; subsequent calls are no-ops.
383378 /// </summary>
384379 public void Dispose ( )
@@ -388,7 +383,7 @@ public void Dispose()
388383 return ;
389384 }
390385
391- this . Graphics . Dispose ( ) ;
386+ this . deviceContext . Dispose ( ) ;
392387 this . QueueHandle . Dispose ( ) ;
393388 this . DeviceHandle . Dispose ( ) ;
394389 this . AdapterHandle . Dispose ( ) ;
@@ -398,10 +393,10 @@ public void Dispose()
398393 }
399394
400395 /// <summary>
401- /// Requests the adapter, device, queue, and drawing context for an existing surface.
396+ /// Requests the adapter, device, queue, and device context for an existing surface.
402397 /// </summary>
403398 /// <param name="api">The shared WebGPU API loader.</param>
404- /// <param name="configuration">The ImageSharp configuration the drawing context will use.</param>
399+ /// <param name="configuration">The ImageSharp configuration the device context will use.</param>
405400 /// <param name="instance">The instance that owns the surface.</param>
406401 /// <param name="surface">The surface the adapter must be compatible with.</param>
407402 /// <param name="requiredFeature">The optional WebGPU feature required by the selected texture format.</param>
@@ -417,7 +412,7 @@ private static DeviceResources CreateDeviceResources(
417412 WebGPUAdapterHandle ? adapterHandle = null ;
418413 WebGPUDeviceHandle ? deviceHandle = null ;
419414 WebGPUQueueHandle ? queueHandle = null ;
420- WebGPUDeviceContext ? graphics = null ;
415+ WebGPUDeviceContext ? deviceContext = null ;
421416
422417 try
423418 {
@@ -433,18 +428,18 @@ private static DeviceResources CreateDeviceResources(
433428 }
434429
435430 queueHandle = new WebGPUQueueHandle ( api , ( nint ) queue , ownsHandle : true ) ;
436- graphics = new WebGPUDeviceContext ( configuration , deviceHandle , queueHandle ) ;
431+ deviceContext = new WebGPUDeviceContext ( configuration , deviceHandle , queueHandle ) ;
437432
438- DeviceResources resources = new ( adapterHandle , deviceHandle , queueHandle , graphics ) ;
433+ DeviceResources resources = new ( adapterHandle , deviceHandle , queueHandle , deviceContext ) ;
439434 adapterHandle = null ;
440435 deviceHandle = null ;
441436 queueHandle = null ;
442- graphics = null ;
437+ deviceContext = null ;
443438 return resources ;
444439 }
445440 catch
446441 {
447- graphics ? . Dispose ( ) ;
442+ deviceContext ? . Dispose ( ) ;
448443 queueHandle ? . Dispose ( ) ;
449444 deviceHandle ? . Dispose ( ) ;
450445 adapterHandle ? . Dispose ( ) ;
@@ -460,7 +455,7 @@ private static DeviceResources CreateDeviceResources(
460455
461456 /// <summary>
462457 /// Recovers the device-owned portion of the surface stack after device loss.
463- /// The existing instance and surface remain valid; only adapter, device, queue, and drawing context are replaced.
458+ /// The existing instance and surface remain valid; only adapter, device, queue, and device context are replaced.
464459 /// </summary>
465460 /// <param name="presentMode">The present mode applied to the recovered swapchain.</param>
466461 /// <param name="framebufferSize">The framebuffer size in pixels.</param>
@@ -481,18 +476,18 @@ private void RecoverDeviceResources(WebGPUPresentMode presentMode, Size framebuf
481476
482477 this . ConfigureSurfaceCore ( presentMode , framebufferSize , deviceResources . DeviceHandle ) ;
483478
484- WebGPUDeviceContext oldGraphics = this . Graphics ;
479+ WebGPUDeviceContext oldDeviceContext = this . deviceContext ;
485480 WebGPUQueueHandle oldQueueHandle = this . QueueHandle ;
486481 WebGPUDeviceHandle oldDeviceHandle = this . DeviceHandle ;
487482 WebGPUAdapterHandle oldAdapterHandle = this . AdapterHandle ;
488483
489- this . Graphics = deviceResources . Graphics ;
484+ this . deviceContext = deviceResources . DeviceContext ;
490485 this . QueueHandle = deviceResources . QueueHandle ;
491486 this . DeviceHandle = deviceResources . DeviceHandle ;
492487 this . AdapterHandle = deviceResources . AdapterHandle ;
493488 deviceResources = null ;
494489
495- oldGraphics . Dispose ( ) ;
490+ oldDeviceContext . Dispose ( ) ;
496491 oldQueueHandle . Dispose ( ) ;
497492 oldDeviceHandle . Dispose ( ) ;
498493 oldAdapterHandle . Dispose ( ) ;
@@ -617,12 +612,12 @@ public DeviceResources(
617612 WebGPUAdapterHandle adapterHandle ,
618613 WebGPUDeviceHandle deviceHandle ,
619614 WebGPUQueueHandle queueHandle ,
620- WebGPUDeviceContext graphics )
615+ WebGPUDeviceContext deviceContext )
621616 {
622617 this . AdapterHandle = adapterHandle ;
623618 this . DeviceHandle = deviceHandle ;
624619 this . QueueHandle = queueHandle ;
625- this . Graphics = graphics ;
620+ this . DeviceContext = deviceContext ;
626621 }
627622
628623 public WebGPUAdapterHandle AdapterHandle { get ; }
@@ -631,11 +626,11 @@ public DeviceResources(
631626
632627 public WebGPUQueueHandle QueueHandle { get ; }
633628
634- internal WebGPUDeviceContext Graphics { get ; }
629+ internal WebGPUDeviceContext DeviceContext { get ; }
635630
636631 public void Dispose ( )
637632 {
638- this . Graphics . Dispose ( ) ;
633+ this . DeviceContext . Dispose ( ) ;
639634 this . QueueHandle . Dispose ( ) ;
640635 this . DeviceHandle . Dispose ( ) ;
641636 this . AdapterHandle . Dispose ( ) ;
0 commit comments