// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; using System.Buffers; using osu.Framework.Graphics.Primitives; using osuTK.Graphics.ES30; using SixLabors.ImageSharp.PixelFormats; namespace osu.Framework.Graphics.Textures { public class ArrayPoolTextureUpload : ITextureUpload { private readonly ArrayPool arrayPool; private readonly Rgba32[] data; /// /// Create an empty raw texture with an efficient shared memory backing. /// /// The width of the texture. /// The height of the texture. /// The source pool to retrieve memory from. Shared default is used if null. public ArrayPoolTextureUpload(int width, int height, ArrayPool arrayPool = null) { this.arrayPool = arrayPool ?? ArrayPool.Shared; data = this.arrayPool.Rent(width * height); } public void Dispose() { arrayPool.Return(data); } public Span RawData => data; public ReadOnlySpan Data => data; public int Level { get; set; } public virtual PixelFormat Format => PixelFormat.Rgba; public RectangleI Bounds { get; set; } } }