using System; using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; using System.Runtime.CompilerServices; using ComputeSharp.D2D1.Interop; #if WINDOWS_UWP using ComputeSharp.D2D1.Uwp.Buffers; using ComputeSharp.D2D1.Uwp.Collections; #else using ComputeSharp.D2D1.WinUI.Buffers; using ComputeSharp.D2D1.WinUI.Collections; #endif using Windows.Graphics.Effects; #if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; #else namespace ComputeSharp.D2D1.WinUI; #endif /// partial class PixelShaderEffect { /// /// Represents the collection of sources in a instance. /// public sealed class SourceCollection : IList, IReadOnlyList, IList, IFixedCountList { /// /// The collection of valid resource texture indices for the current effect. /// private static readonly ImmutableArray Indices = GetIndices(); /// /// The fixed buffer of instances. /// private GraphicsEffectSourceBuffer fixedBuffer; /// /// Creates a new instance with the specified parameters. /// /// The owning instance. internal SourceCollection(PixelShaderEffect owner) { Owner = owner; } /// public int Count { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => D2D1PixelShader.GetInputCount(); } /// public IGraphicsEffectSource? this[int index] { get { default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, D2D1PixelShader.GetInputCount(), nameof(index)); return Owner.GetSource(index); } set { default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, D2D1PixelShader.GetInputCount(), nameof(index)); Owner.SetSource(value, index); } } /// object? IList.this[int index] { get => this[index]; set => this[index] = (IGraphicsEffectSource?)value; } /// /// The owning instance. /// internal PixelShaderEffect Owner { get; } /// /// Gets a reference to the value containing the available -s. /// internal ref GraphicsEffectSourceBuffer Storage => ref this.fixedBuffer; /// ImmutableArray IFixedCountList.Indices => Indices; /// bool ICollection.IsReadOnly => false; /// bool IList.IsReadOnly => false; /// bool IList.IsFixedSize => true; /// bool ICollection.IsSynchronized => true; /// object ICollection.SyncRoot => default(NotSupportedException).Throw(); /// void ICollection.Add(IGraphicsEffectSource? item) { default(NotSupportedException).Throw(); } /// int IList.Add(object? value) { return default(NotSupportedException).Throw(); } /// void ICollection.Clear() { default(NotSupportedException).Throw(); } /// void IList.Clear() { default(NotSupportedException).Throw(); } /// 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) { default(NotSupportedException).Throw(); } /// void IList.Insert(int index, object? value) { default(NotSupportedException).Throw(); } /// bool ICollection.Remove(IGraphicsEffectSource? item) { return default(NotSupportedException).Throw(); } /// void IList.Remove(object? value) { default(NotSupportedException).Throw(); } /// void IList.RemoveAt(int index) { default(NotSupportedException).Throw(); } /// void IList.RemoveAt(int index) { default(NotSupportedException).Throw(); } /// /// Gets the collection of valid indices for the current effect. /// /// The collection of valid indices for the current effect. private static ImmutableArray GetIndices() { int inputCount = D2D1PixelShader.GetInputCount(); if (inputCount == 0) { return ImmutableArray.Empty; } int[] indices = new int[inputCount]; for (int i = 0; i < indices.Length; i++) { indices[i] = i; } return Unsafe.As>(ref indices); } } }