aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Vic/Image/InputSurface.cs
blob: de770c9436ab10a59fb853580e89ee1e82ba12e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;

namespace Ryujinx.Graphics.Vic.Image
{
    ref struct RentedBuffer
    {
        public static RentedBuffer Empty => new(Span<byte>.Empty, -1);

        public Span<byte> Data;
        public int Index;

        public RentedBuffer(Span<byte> data, int index)
        {
            Data = data;
            Index = index;
        }

        public readonly void Return(BufferPool<byte> pool)
        {
            if (Index != -1)
            {
                pool.Return(Index);
            }
        }
    }

    ref struct InputSurface
    {
        public ReadOnlySpan<byte> Buffer0;
        public ReadOnlySpan<byte> Buffer1;
        public ReadOnlySpan<byte> Buffer2;

        public int Buffer0Index;
        public int Buffer1Index;
        public int Buffer2Index;

        public int Width;
        public int Height;

        public int UvWidth;
        public int UvHeight;

        public void Initialize()
        {
            Buffer0Index = -1;
            Buffer1Index = -1;
            Buffer2Index = -1;
        }

        public void SetBuffer0(RentedBuffer buffer)
        {
            Buffer0 = buffer.Data;
            Buffer0Index = buffer.Index;
        }

        public void SetBuffer1(RentedBuffer buffer)
        {
            Buffer1 = buffer.Data;
            Buffer1Index = buffer.Index;
        }

        public void SetBuffer2(RentedBuffer buffer)
        {
            Buffer2 = buffer.Data;
            Buffer2Index = buffer.Index;
        }

        public readonly void Return(BufferPool<byte> pool)
        {
            if (Buffer0Index != -1)
            {
                pool.Return(Buffer0Index);
            }

            if (Buffer1Index != -1)
            {
                pool.Return(Buffer1Index);
            }

            if (Buffer2Index != -1)
            {
                pool.Return(Buffer2Index);
            }
        }
    }
}