using System; using System.Collections; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using ComputeSharp.D2D1.Interop; using ComputeSharp.D2D1.Shaders.Loaders; #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 #pragma warning disable CS0618, CS8767 #if WINDOWS_UWP namespace ComputeSharp.D2D1.Uwp; #else namespace ComputeSharp.D2D1.WinUI; #endif /// partial class PixelShaderEffect { /// /// Represents the collection of objects in a instance. /// public sealed class ResourceTextureManagerCollection : IList, IReadOnlyList, IList, IFixedCountList { /// /// The bitmask of valid indices for resource texture managers in the current shader type. /// private static readonly int IndexBitmask = GetIndexBitmask(); /// /// The fixed buffer of instances. /// private ResourceTextureManagerBuffer fixedBuffer; /// /// Creates a new instance with the specified parameters. /// /// The owning instance. internal ResourceTextureManagerCollection(PixelShaderEffect owner) { Owner = owner; } /// public int Count => Indices.Length; /// /// Gets or sets the object at a specified index. /// /// The index of the source to get or set. /// The object at the specified index. /// Thrown if the value is set to . /// Thrown if is not a valid index for the current effect. [DisallowNull] public D2D1ResourceTextureManager? this[int index] { get { default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, 16, nameof(index)); default(ArgumentOutOfRangeException).ThrowIf((IndexBitmask & (1 << index)) == 0, nameof(index)); return Owner.GetResourceTextureManager(index); } set { default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, 16, nameof(index)); default(ArgumentOutOfRangeException).ThrowIf((IndexBitmask & (1 << index)) == 0, nameof(index)); default(ArgumentNullException).ThrowIfNull(value); Owner.SetResourceTextureManager(value, index); } } /// object? IList.this[int index] { get => this[index]; set => this[index] = (D2D1ResourceTextureManager?)value!; } /// /// Gets the collection of valid resource texture indices for the current effect. /// internal static ImmutableArray Indices { get; } = GetIndices(); /// /// The owning instance. /// internal PixelShaderEffect Owner { get; } /// /// Gets a reference to the value containing the available -s. /// internal ref ResourceTextureManagerBuffer 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(D2D1ResourceTextureManager? 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(D2D1ResourceTextureManager? item) { return FixedCountList.IndexOf(this, item) != -1; } /// bool IList.Contains(object? value) { return FixedCountList.IndexOf(this, (D2D1ResourceTextureManager?)value) != -1; } /// void ICollection.CopyTo(D2D1ResourceTextureManager?[] 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(D2D1ResourceTextureManager? item) { return FixedCountList.IndexOf(this, item); } /// int IList.IndexOf(object? value) { return FixedCountList.IndexOf(this, (D2D1ResourceTextureManager?)value); } /// void IList.Insert(int index, D2D1ResourceTextureManager? item) { default(NotSupportedException).Throw(); } /// void IList.Insert(int index, object? value) { default(NotSupportedException).Throw(); } /// bool ICollection.Remove(D2D1ResourceTextureManager? 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 bitmask of indices for resource textures in the target shader. /// /// The bitmask of indices for resource textures in the target shader. private static int GetIndexBitmask() { D2D1IndexBitmaskResourceTextureDescriptionsLoader bitmaskLoader = default; Unsafe.SkipInit(out T shader); shader.LoadResourceTextureDescriptions(ref bitmaskLoader); return bitmaskLoader.GetResultingIndexBitmask(); } /// /// Gets the collection of valid indices for the current effect. /// /// The collection of valid indices for the current effect. private static ImmutableArray GetIndices() { D2D1ImmutableArrayResourceTextureDescriptionsLoader indicesLoader = default; Unsafe.SkipInit(out T shader); shader.LoadResourceTextureDescriptions(ref indicesLoader); return indicesLoader.GetResultingIndices(); } } }