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