Surface.cs 1.7 KB

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