/ src / Ryujinx.Graphics.Vic / Image / Surface.cs
Surface.cs
 1  using System;
 2  using System.Runtime.CompilerServices;
 3  
 4  namespace Ryujinx.Graphics.Vic.Image
 5  {
 6      readonly struct Surface : IDisposable
 7      {
 8          private readonly int _bufferIndex;
 9  
10          private readonly BufferPool<Pixel> _pool;
11  
12          public Pixel[] Data { get; }
13  
14          public int Width { get; }
15          public int Height { get; }
16  
17          public Surface(BufferPool<Pixel> pool, int width, int height)
18          {
19              _bufferIndex = pool.RentMinimum(width * height, out Pixel[] data);
20              _pool = pool;
21              Data = data;
22              Width = width;
23              Height = height;
24          }
25  
26          [MethodImpl(MethodImplOptions.AggressiveInlining)]
27          public ushort GetR(int x, int y) => Data[y * Width + x].R;
28          [MethodImpl(MethodImplOptions.AggressiveInlining)]
29          public ushort GetG(int x, int y) => Data[y * Width + x].G;
30          [MethodImpl(MethodImplOptions.AggressiveInlining)]
31          public ushort GetB(int x, int y) => Data[y * Width + x].B;
32          [MethodImpl(MethodImplOptions.AggressiveInlining)]
33          public ushort GetA(int x, int y) => Data[y * Width + x].A;
34  
35          [MethodImpl(MethodImplOptions.AggressiveInlining)]
36          public void SetR(int x, int y, ushort value) => Data[y * Width + x].R = value;
37          [MethodImpl(MethodImplOptions.AggressiveInlining)]
38          public void SetG(int x, int y, ushort value) => Data[y * Width + x].G = value;
39          [MethodImpl(MethodImplOptions.AggressiveInlining)]
40          public void SetB(int x, int y, ushort value) => Data[y * Width + x].B = value;
41          [MethodImpl(MethodImplOptions.AggressiveInlining)]
42          public void SetA(int x, int y, ushort value) => Data[y * Width + x].A = value;
43  
44          public void Dispose() => _pool.Return(_bufferIndex);
45      }
46  }