diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs index e25ea0f3..c9056ade 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs +++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ICanvasImageInterop.cs @@ -200,7 +200,7 @@ unsafe partial class PixelShaderEffect this.d2D1BufferPrecision = this.d2D1Effect.Get()->GetPrecisionProperty(); // Loop over all effect inputs and update the cache back as well - for (int i = 0; i < SourceCollection.Count; i++) + for (int i = 0; i < Sources.Count; i++) { // If this index has been explicitly requested to be skipped, just dispose the source reference. // This is the case when the effect is being unrealized, and callers will set this value on their own. @@ -286,7 +286,7 @@ unsafe partial class PixelShaderEffect } // Forward all available sources (the effect is being created now, so no need to validate the underlying resources) - for (int i = 0; i < SourceCollection.Count; i++) + for (int i = 0; i < Sources.Count; i++) { if (!SetD2DInput( index: i, @@ -320,7 +320,7 @@ unsafe partial class PixelShaderEffect /// The instance in use. private void RefreshInputs(WIN2D_GET_D2D_IMAGE_FLAGS flags, float targetDpi, ID2D1DeviceContext* deviceContext) { - for (int i = 0; i < SourceCollection.Count; i++) + for (int i = 0; i < Sources.Count; i++) { // Retrieve the managed wrapper for the current source IGraphicsEffectSource? source = GetD2DInput(i); diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Sources.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Sources.cs index 19ccd9c0..83b54ca1 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Sources.cs +++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.Properties.Sources.cs @@ -1,4 +1,6 @@ using System; +using System.Collections; +using System.Collections.Generic; using System.Runtime.CompilerServices; using ComputeSharp.D2D1.Helpers; using ComputeSharp.D2D1.Interop; @@ -13,7 +15,7 @@ partial class PixelShaderEffect /// /// Represents the collection of sources in a instance. /// - public sealed class SourceCollection + public sealed class SourceCollection : IList, IReadOnlyList, IList, IFixedCountList { /// /// The fixed buffer of instances. @@ -29,17 +31,14 @@ partial class PixelShaderEffect Owner = owner; } - /// - /// Gets the actual input count for the current effect. - /// - internal static int Count { get; } = D2D1PixelShader.GetInputCount(); + /// + public int Count + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => D2D1PixelShader.GetInputCount(); + } - /// - /// Gets or sets the source at a specified index. - /// - /// The index of the source to get or set. - /// The source at the specified index. - /// Thrown if is not a valid index for the current effect. + /// public IGraphicsEffectSource? this[int index] { get @@ -56,6 +55,13 @@ partial class PixelShaderEffect } } + /// + object? IList.this[int index] + { + get => this[index]; + set => this[index] = (IGraphicsEffectSource?)value; + } + /// /// The owning instance. /// @@ -66,6 +72,129 @@ partial class PixelShaderEffect /// internal ref GraphicsEffectSourceBuffer Storage => ref this.fixedBuffer; + /// + bool ICollection.IsReadOnly => false; + + /// + bool IList.IsReadOnly => false; + + /// + bool IList.IsFixedSize => true; + + /// + bool ICollection.IsSynchronized => true; + + /// + object ICollection.SyncRoot => throw new NotSupportedException("ICollection.SyncRoot is not supported for SourceCollection."); + + /// + void ICollection.Add(IGraphicsEffectSource? item) + { + throw new NotSupportedException("ICollection.Add is not supported for SourceCollection."); + } + + /// + int IList.Add(object value) + { + throw new NotSupportedException("IList.Add is not supported for SourceCollection."); + } + + /// + void ICollection.Clear() + { + throw new NotSupportedException("ICollection.Clear is not supported for SourceCollection."); + } + + /// + void IList.Clear() + { + throw new NotSupportedException("IList.Clear is not supported for SourceCollection."); + } + + /// + bool ICollection.Contains(IGraphicsEffectSource? item) + { + return FixedCountList.IndexOf(this, item) != -1; + } + + /// + bool IList.Contains(object value) + { + return FixedCountList.IndexOf(this, (IGraphicsEffectSource?)value) != -1; + } + + /// + void ICollection.CopyTo(IGraphicsEffectSource?[] array, int arrayIndex) + { + FixedCountList.CopyTo(this, array, arrayIndex); + } + + /// + void ICollection.CopyTo(Array array, int index) + { + FixedCountList.CopyTo(this, array, index); + } + + /// + IEnumerator IEnumerable.GetEnumerator() + { + return FixedCountList.GetEnumerator(this); + } + + /// + IEnumerator IEnumerable.GetEnumerator() + { + return FixedCountList.GetEnumerator(this); + } + + /// + int IList.IndexOf(IGraphicsEffectSource? item) + { + return FixedCountList.IndexOf(this, item); + } + + /// + int IList.IndexOf(object value) + { + return FixedCountList.IndexOf(this, (IGraphicsEffectSource?)value); + } + + /// + void IList.Insert(int index, IGraphicsEffectSource? item) + { + throw new NotSupportedException("IList.Insert is not supported for SourceCollection."); + } + + /// + void IList.Insert(int index, object value) + { + throw new NotSupportedException("IList.Insert is not supported for SourceCollection."); + } + + /// + bool ICollection.Remove(IGraphicsEffectSource? item) + { + throw new NotSupportedException("ICollection.Remove is not supported for SourceCollection."); + } + + /// + void IList.Remove(object value) + { + throw new NotSupportedException("IList.Remove is not supported for SourceCollection."); + } + + /// + void IList.RemoveAt(int index) + { + throw new NotSupportedException("IList.RemoveAt is not supported for SourceCollection."); + } + + /// + void IList.RemoveAt(int index) + { + throw new NotSupportedException("IList.RemoveAt is not supported for SourceCollection."); + } + /// /// Validates the input index for . /// @@ -74,7 +203,7 @@ partial class PixelShaderEffect [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void ValidateIndex(int index) { - if ((uint)index >= Count) + if ((uint)index >= D2D1PixelShader.GetInputCount()) { ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index), "The input index is not a valid source index for the current effect."); } diff --git a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ReferenceTracking.cs b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ReferenceTracking.cs index e891f878..08548bb1 100644 --- a/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ReferenceTracking.cs +++ b/src/ComputeSharp.D2D1.Uwp/PixelShaderEffect{T}.ReferenceTracking.cs @@ -46,7 +46,7 @@ partial class PixelShaderEffect // Also release all native resources for the used sources. // The transform mapper and resource texture managers don't // need to be disposed, as those could be shared between effects. - for (int i = 0; i < SourceCollection.Count; i++) + for (int i = 0; i < Sources.Count; i++) { Sources.Storage[i].Dispose(); }