Skip to content

Commit

Permalink
Remove the dependency on System.Composition
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding committed Jul 12, 2021
1 parent d9b81d6 commit 23f673f
Show file tree
Hide file tree
Showing 74 changed files with 846 additions and 632 deletions.
1 change: 0 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.0.0" />
<PackageReference Update="NUnit" Version="3.13.2" />
<PackageReference Update="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Update="System.Composition" Version="5.0.1" />
<PackageReference Update="System.IO.Pipelines" Version="5.0.1" />
<PackageReference Update="TerraFX.Interop.Libc" Version="1.2017.0-beta2" />
<PackageReference Update="TerraFX.Interop.Mimalloc" Version="1.6.0-beta2" />
Expand Down
10 changes: 5 additions & 5 deletions docs/design/Audio.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ public abstract class AudioDecoderOptions
}


public interface IAudioProvider
public abstract class AudioService
{
// Provides sound devices to code, so that they can be requested and used to
// play sound. Implementors are likely to name based on subsystem, e.g. XAudio2AudioProvider, OpenALAudioProvider
// play sound. Implementors are likely to name based on subsystem, e.g. XAudio2AudioService, OpenALAudioService
// Requests an audio device supporting the given options. If none could be
// found, returns null.
IAudioDevice RequestAudioDevice(IAudioDeviceOptions options = null);
public abstract IAudioDevice RequestAudioDevice(IAudioDeviceOptions options = null);

// Returns an enumerable which can be used to enumerate available audio
// devices. Does not initialize them.
IEnumerable<IAudioDeviceOptions> EnumerateAudioDevices();
public abstract IEnumerable<IAudioDeviceOptions> EnumerateAudioDevices();
}


Expand Down Expand Up @@ -164,7 +164,7 @@ public static sealed class WellKnownSampleRates
- How do we name well-known sampling rates?
- `CdAudio` and `DvdAudio` are based on well-known sample rates for CDs and
DVDs, but how do we handle cases, e.g. 192kHz?
- How do we handle cases where an audio provider does not match a requested
- How do we handle cases where an audio service does not match a requested
device?
- If byte order does not match, byte swapping can likely be performed
transparently using vectorised operations
Expand Down
19 changes: 6 additions & 13 deletions docs/design/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ TerraFX aims, first and foremost, to be composable and lightweight. That is, it
aims to provide a lot of possible functionality, but users should not be forced
to pick up more than necessary.

Most of this composability is built around the concept of providers and consumers.
Most of this composability is built around the concept of services and consumers.
TerraFX will be defining the general contract for a given component and that will
itself not provide any functionality outside some of the "primitive" concepts. We
will then expose a set of default providers that users can pick from that provide
will then expose a set of default services that users can pick from that provide
different implementations for a given component. These could be implemented by an
existing framework, in managed code, or some new framework of the providers choosing.
existing framework, in managed code, or some new framework of the services choosing.

The contract defined by TerraFX aims to be general-purpose where possible and to
not dive down into framework specific functionality. Where something is commonly
Expand All @@ -19,7 +19,7 @@ extension point that can light up via feature detection.

## Core Concepts

TerraFX aims to allow the application and provider to decide how things function
TerraFX aims to allow the application and service to decide how things function
where possible. This also applies for concepts like memory management and I/O.

As such, components should be taking a `System.Buffers.MemoryManager<T>` and
Expand All @@ -32,16 +32,9 @@ applications to provide a customized environment where that is important.

Interop should be explicitly blittable to avoid runtime overhead and any implicit
costs associated with marshalling. Interop should also be isolated to interop
specific projects and should not live in the providers themselves. This allows
specific projects and should not live in the services themselves. This allows
better reuse and for the interop functionality to be changed without updating
the provider.

Components should generally be defined in terms of interfaces as this allows the
provider to determine how they want to implement while still minimizing overhead.
For example, writing a provider in native code or via structs should be a completely
valid option and interfaces allow this without having wrappers on the manager side.
Future extensibility is going to likely be addressed via default interface methods
(DIMs).
the service.

## General Structure

Expand Down
23 changes: 11 additions & 12 deletions samples/TerraFX/Audio/EnumerateAudioAdapters.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System;
using System.Reflection;
using System.Threading.Tasks;
using TerraFX.ApplicationModel;
using TerraFX.Audio;
Expand All @@ -12,20 +11,20 @@ namespace TerraFX.Samples.Audio
public sealed class EnumerateAudioAdapters : Sample
{
private readonly bool _async = false;
private IAudioProvider? _provider;
private IAudioService? _service;

public EnumerateAudioAdapters(string name, bool @async, params Assembly[] compositionAssemblies)
: base(name, compositionAssemblies)
public EnumerateAudioAdapters(string name, bool @async, ApplicationServiceProvider serviceProvider)
: base(name, serviceProvider)
{
_async = @async;
_provider = null;
_service = null;
}

public override void Initialize(Application application, TimeSpan timeout)
{
_provider = application.GetService<IAudioProvider>();
_service = application.ServiceProvider.AudioService;

var task = _provider.StartAsync();
var task = _service.StartAsync();
if (!task.IsCompleted)
{
task.AsTask().Wait();
Expand All @@ -36,9 +35,9 @@ public override void Initialize(Application application, TimeSpan timeout)

public override void Cleanup()
{
ExceptionUtilities.ThrowIfNull(_provider, nameof(_provider));
ExceptionUtilities.ThrowIfNull(_service, nameof(_service));

var task = _provider.StopAsync();
var task = _service.StopAsync();
if (!task.IsCompleted)
{
task.AsTask().Wait();
Expand All @@ -57,18 +56,18 @@ protected override void OnIdle(object? sender, ApplicationIdleEventArgs eventArg

private async Task RunAsync(Application application)
{
ExceptionUtilities.ThrowIfNull(_provider, nameof(_provider));
ExceptionUtilities.ThrowIfNull(_service, nameof(_service));

if (_async)
{
await foreach (var audioAdapter in _provider.EnumerateAudioDevices())
await foreach (var audioAdapter in _service.EnumerateAudioDevices())
{
PrintAudioAdapter(audioAdapter);
}
}
else
{
foreach (var audioAdapter in _provider.EnumerateAudioDevices())
foreach (var audioAdapter in _service.EnumerateAudioDevices())
{
PrintAudioAdapter(audioAdapter);
}
Expand Down
23 changes: 11 additions & 12 deletions samples/TerraFX/Audio/PlaySampleAudio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System;
using System.IO.Pipelines;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using TerraFX.ApplicationModel;
Expand All @@ -21,19 +20,19 @@ public sealed class PlaySampleAudio : Sample

// Current position in sine wave, in samples
private int _samplePosition;
private IAudioProvider? _provider;
private IAudioService? _service;

public PlaySampleAudio(string name, params Assembly[] compositionAssemblies)
: base(name, compositionAssemblies)
public PlaySampleAudio(string name, ApplicationServiceProvider serviceProvider)
: base(name, serviceProvider)
{
_provider = null;
_service = null;
}

public override void Initialize(Application application, TimeSpan timeout)
{
_provider = application.GetService<IAudioProvider>();
_service = application.ServiceProvider.AudioService;

var task = _provider.StartAsync();
var task = _service.StartAsync();
if (!task.IsCompleted)
{
task.AsTask().Wait();
Expand All @@ -44,9 +43,9 @@ public override void Initialize(Application application, TimeSpan timeout)

public override void Cleanup()
{
ExceptionUtilities.ThrowIfNull(_provider, nameof(_provider));
ExceptionUtilities.ThrowIfNull(_service, nameof(_service));

var task = _provider.StopAsync();
var task = _service.StopAsync();
if (!task.IsCompleted)
{
task.AsTask().Wait();
Expand All @@ -65,10 +64,10 @@ protected override void OnIdle(object? sender, ApplicationIdleEventArgs eventArg

private async Task RunAsync(Application application)
{
ExceptionUtilities.ThrowIfNull(_provider, nameof(_provider));
ExceptionUtilities.ThrowIfNull(_service, nameof(_service));

IAudioAdapter? preferredAdapter = null;
await foreach (var audioAdapter in _provider.EnumerateAudioDevices())
await foreach (var audioAdapter in _service.EnumerateAudioDevices())
{
if (audioAdapter is PulseSinkAdapter sinkAdapter)
{
Expand All @@ -86,7 +85,7 @@ private async Task RunAsync(Application application)

if (preferredAdapter != null)
{
var device = await _provider.RequestAudioPlaybackDeviceAsync(preferredAdapter);
var device = await _service.RequestAudioPlaybackDeviceAsync(preferredAdapter);

Console.WriteLine($" Playing a {SineWaveFrequency}Hz sine wave...");

Expand Down
10 changes: 4 additions & 6 deletions samples/TerraFX/Graphics/EnumerateGraphicsAdapters.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System;
using System.Reflection;
using TerraFX.ApplicationModel;
using TerraFX.Graphics;
using TerraFX.Utilities;

namespace TerraFX.Samples.Graphics
{
public sealed class EnumerateGraphicsAdapters : Sample
{
public EnumerateGraphicsAdapters(string name, params Assembly[] compositionAssemblies)
: base(name, compositionAssemblies)
public EnumerateGraphicsAdapters(string name, ApplicationServiceProvider serviceProvider)
: base(name, serviceProvider)
{
}

Expand All @@ -21,9 +19,9 @@ protected override void OnIdle(object? sender, ApplicationIdleEventArgs eventArg

var application = (Application)sender;
{
var graphicsProvider = application.GetService<GraphicsProvider>();
var graphicsService = application.ServiceProvider.GraphicsService;

foreach (var graphicsAdapter in graphicsProvider.Adapters)
foreach (var graphicsAdapter in graphicsService.Adapters)
{
Console.WriteLine($" Name: {graphicsAdapter.Name}");
Console.WriteLine($" Device ID: {graphicsAdapter.DeviceId}");
Expand Down
5 changes: 2 additions & 3 deletions samples/TerraFX/Graphics/HelloQuad.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System;
using System.Reflection;
using TerraFX.ApplicationModel;
using TerraFX.Graphics;
using TerraFX.Numerics;
Expand All @@ -15,8 +14,8 @@ public sealed class HelloQuad : HelloWindow
private GraphicsBuffer _indexBuffer = null!;
private GraphicsBuffer _vertexBuffer = null!;

public HelloQuad(string name, params Assembly[] compositionAssemblies)
: base(name, compositionAssemblies)
public HelloQuad(string name, ApplicationServiceProvider serviceProvider)
: base(name, serviceProvider)
{
}

Expand Down
5 changes: 2 additions & 3 deletions samples/TerraFX/Graphics/HelloSierpinski.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

using System;
using System.Collections.Generic;
using System.Reflection;
using TerraFX.ApplicationModel;
using TerraFX.Graphics;
using TerraFX.Numerics;
Expand All @@ -21,8 +20,8 @@ public class HelloSierpinski : HelloWindow
private GraphicsBuffer _vertexBuffer = null!;
private float _texturePosition;

public HelloSierpinski(string name, int recursionDepth, SierpinskiShape shape, params Assembly[] compositionAssemblies)
: base(name, compositionAssemblies)
public HelloSierpinski(string name, int recursionDepth, SierpinskiShape shape, ApplicationServiceProvider serviceProvider)
: base(name, serviceProvider)
{
_recursionDepth = recursionDepth;
_sierpinskiShape = shape;
Expand Down
6 changes: 3 additions & 3 deletions samples/TerraFX/Graphics/HelloSierpinskiPyramid.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System.Reflection;
using TerraFX.ApplicationModel;

namespace TerraFX.Samples.Graphics
{
public class HelloSierpinskiPyramid : HelloSierpinski
{
public HelloSierpinskiPyramid(string name, int recursionDepth, params Assembly[] compositionAssemblies)
: base(name, recursionDepth, SierpinskiShape.Pyramid, compositionAssemblies)
public HelloSierpinskiPyramid(string name, int recursionDepth, ApplicationServiceProvider serviceProvider)
: base(name, recursionDepth, SierpinskiShape.Pyramid, serviceProvider)
{
}
}
Expand Down
6 changes: 3 additions & 3 deletions samples/TerraFX/Graphics/HelloSierpinskiQuad.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System.Reflection;
using TerraFX.ApplicationModel;

namespace TerraFX.Samples.Graphics
{
public class HelloSierpinskiQuad : HelloSierpinski
{
public HelloSierpinskiQuad(string name, int recursionDepth, params Assembly[] compositionAssemblies)
: base(name, recursionDepth, SierpinskiShape.Quad, compositionAssemblies)
public HelloSierpinskiQuad(string name, int recursionDepth, ApplicationServiceProvider serviceProvider)
: base(name, recursionDepth, SierpinskiShape.Quad, serviceProvider)
{
}
}
Expand Down
5 changes: 2 additions & 3 deletions samples/TerraFX/Graphics/HelloSmoke.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System;
using System.Reflection;
using TerraFX.ApplicationModel;
using TerraFX.Graphics;
using TerraFX.Numerics;
Expand All @@ -19,8 +18,8 @@ public sealed class HelloSmoke : HelloWindow
private GraphicsBuffer _vertexBuffer = null!;
private float _texturePosition;

public HelloSmoke(string name, bool isQuickAndDirty, params Assembly[] compositionAssemblies)
: base(name, compositionAssemblies)
public HelloSmoke(string name, bool isQuickAndDirty, ApplicationServiceProvider serviceProvider)
: base(name, serviceProvider)
{
_isQuickAndDirty = isQuickAndDirty;
}
Expand Down
5 changes: 2 additions & 3 deletions samples/TerraFX/Graphics/HelloTexture.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System;
using System.Reflection;
using TerraFX.ApplicationModel;
using TerraFX.Graphics;
using TerraFX.Numerics;
Expand All @@ -14,8 +13,8 @@ public sealed class HelloTexture : HelloWindow
private GraphicsPrimitive _trianglePrimitive = null!;
private GraphicsBuffer _vertexBuffer = null!;

public HelloTexture(string name, params Assembly[] compositionAssemblies)
: base(name, compositionAssemblies)
public HelloTexture(string name, ApplicationServiceProvider serviceProvider)
: base(name, serviceProvider)
{
}

Expand Down
5 changes: 2 additions & 3 deletions samples/TerraFX/Graphics/HelloTexture3D.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System;
using System.Reflection;
using TerraFX.ApplicationModel;
using TerraFX.Graphics;
using TerraFX.Numerics;
Expand All @@ -25,8 +24,8 @@ public class HelloTexture3D : HelloWindow
private float _texturePosition;
private const uint TEXTURE3D_SIDE_LENGTH = 64; // this results in a RowPitch of 256, the minimum allowed

public HelloTexture3D(string name, params Assembly[] compositionAssemblies)
: base(name, compositionAssemblies)
public HelloTexture3D(string name, ApplicationServiceProvider serviceProvider)
: base(name, serviceProvider)
{
}

Expand Down
Loading

0 comments on commit 23f673f

Please sign in to comment.