2018-02-23 22:48:27 +01:00
|
|
|
using ChocolArm64.Memory;
|
2018-03-19 19:58:46 +01:00
|
|
|
using Ryujinx.Core.OsHle.Handles;
|
2018-03-20 21:00:00 +01:00
|
|
|
using Ryujinx.Core.OsHle.Services.Nv;
|
2018-03-12 05:04:52 +01:00
|
|
|
using Ryujinx.Graphics.Gal;
|
2018-02-23 22:48:27 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2018-03-20 21:00:00 +01:00
|
|
|
using System.IO;
|
2018-02-23 22:48:27 +01:00
|
|
|
using System.Text;
|
|
|
|
using System.Threading;
|
2018-03-20 21:00:00 +01:00
|
|
|
using static Ryujinx.Core.OsHle.Services.Android.Parcel;
|
2018-02-23 22:48:27 +01:00
|
|
|
|
2018-03-20 21:00:00 +01:00
|
|
|
namespace Ryujinx.Core.OsHle.Services.Android
|
2018-02-23 22:48:27 +01:00
|
|
|
{
|
|
|
|
class NvFlinger : IDisposable
|
|
|
|
{
|
|
|
|
private delegate long ServiceProcessParcel(ServiceCtx Context, BinaryReader ParcelReader);
|
|
|
|
|
|
|
|
private Dictionary<(string, int), ServiceProcessParcel> Commands;
|
|
|
|
|
2018-03-19 19:58:46 +01:00
|
|
|
private KEvent ReleaseEvent;
|
|
|
|
|
|
|
|
private IGalRenderer Renderer;
|
|
|
|
|
2018-02-23 22:48:27 +01:00
|
|
|
private const int BufferQueueCount = 0x40;
|
|
|
|
private const int BufferQueueMask = BufferQueueCount - 1;
|
|
|
|
|
|
|
|
[Flags]
|
|
|
|
private enum HalTransform
|
|
|
|
{
|
|
|
|
FlipX = 1 << 0,
|
|
|
|
FlipY = 1 << 1,
|
|
|
|
Rotate90 = 1 << 2
|
|
|
|
}
|
|
|
|
|
|
|
|
private enum BufferState
|
|
|
|
{
|
|
|
|
Free,
|
|
|
|
Dequeued,
|
|
|
|
Queued,
|
|
|
|
Acquired
|
|
|
|
}
|
|
|
|
|
2018-03-01 03:37:40 +01:00
|
|
|
private struct Rect
|
|
|
|
{
|
|
|
|
public int Top;
|
|
|
|
public int Left;
|
|
|
|
public int Right;
|
|
|
|
public int Bottom;
|
|
|
|
}
|
|
|
|
|
2018-02-23 22:48:27 +01:00
|
|
|
private struct BufferEntry
|
|
|
|
{
|
|
|
|
public BufferState State;
|
|
|
|
|
|
|
|
public HalTransform Transform;
|
|
|
|
|
2018-03-01 03:37:40 +01:00
|
|
|
public Rect Crop;
|
|
|
|
|
2018-02-23 22:48:27 +01:00
|
|
|
public GbpBuffer Data;
|
|
|
|
}
|
|
|
|
|
|
|
|
private BufferEntry[] BufferQueue;
|
|
|
|
|
|
|
|
private ManualResetEvent WaitBufferFree;
|
2018-03-12 05:04:52 +01:00
|
|
|
|
|
|
|
private object RenderQueueLock;
|
|
|
|
|
|
|
|
private int RenderQueueCount;
|
|
|
|
|
|
|
|
private bool NvFlingerDisposed;
|
2018-02-23 22:48:27 +01:00
|
|
|
|
|
|
|
private bool KeepRunning;
|
|
|
|
|
2018-03-19 19:58:46 +01:00
|
|
|
public NvFlinger(IGalRenderer Renderer, KEvent ReleaseEvent)
|
2018-02-23 22:48:27 +01:00
|
|
|
{
|
|
|
|
Commands = new Dictionary<(string, int), ServiceProcessParcel>()
|
|
|
|
{
|
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0x1), GbpRequestBuffer },
|
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0x3), GbpDequeueBuffer },
|
2018-03-12 05:04:52 +01:00
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0x4), GbpDetachBuffer },
|
2018-02-23 22:48:27 +01:00
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0x7), GbpQueueBuffer },
|
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0x8), GbpCancelBuffer },
|
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0x9), GbpQuery },
|
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0xa), GbpConnect },
|
2018-03-06 21:27:50 +01:00
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0xb), GbpDisconnect },
|
2018-02-23 22:48:27 +01:00
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0xe), GbpPreallocBuffer }
|
|
|
|
};
|
2018-03-19 19:58:46 +01:00
|
|
|
|
|
|
|
this.Renderer = Renderer;
|
|
|
|
this.ReleaseEvent = ReleaseEvent;
|
2018-03-12 05:04:52 +01:00
|
|
|
|
2018-02-23 22:48:27 +01:00
|
|
|
BufferQueue = new BufferEntry[0x40];
|
|
|
|
|
|
|
|
WaitBufferFree = new ManualResetEvent(false);
|
|
|
|
|
2018-03-12 05:04:52 +01:00
|
|
|
RenderQueueLock = new object();
|
|
|
|
|
2018-02-23 22:48:27 +01:00
|
|
|
KeepRunning = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long ProcessParcelRequest(ServiceCtx Context, byte[] ParcelData, int Code)
|
|
|
|
{
|
|
|
|
using (MemoryStream MS = new MemoryStream(ParcelData))
|
|
|
|
{
|
|
|
|
BinaryReader Reader = new BinaryReader(MS);
|
|
|
|
|
|
|
|
MS.Seek(4, SeekOrigin.Current);
|
|
|
|
|
|
|
|
int StrSize = Reader.ReadInt32();
|
|
|
|
|
|
|
|
string InterfaceName = Encoding.Unicode.GetString(Reader.ReadBytes(StrSize * 2));
|
|
|
|
|
|
|
|
long Remainder = MS.Position & 0xf;
|
|
|
|
|
|
|
|
if (Remainder != 0)
|
|
|
|
{
|
|
|
|
MS.Seek(0x10 - Remainder, SeekOrigin.Current);
|
|
|
|
}
|
|
|
|
|
|
|
|
MS.Seek(0x50, SeekOrigin.Begin);
|
|
|
|
|
|
|
|
if (Commands.TryGetValue((InterfaceName, Code), out ServiceProcessParcel ProcReq))
|
|
|
|
{
|
|
|
|
Logging.Debug($"{InterfaceName} {ProcReq.Method.Name}");
|
|
|
|
|
|
|
|
return ProcReq(Context, Reader);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new NotImplementedException($"{InterfaceName} {Code}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private long GbpRequestBuffer(ServiceCtx Context, BinaryReader ParcelReader)
|
|
|
|
{
|
|
|
|
int Slot = ParcelReader.ReadInt32();
|
|
|
|
|
|
|
|
using (MemoryStream MS = new MemoryStream())
|
|
|
|
{
|
|
|
|
BinaryWriter Writer = new BinaryWriter(MS);
|
|
|
|
|
|
|
|
BufferEntry Entry = BufferQueue[Slot];
|
|
|
|
|
|
|
|
int BufferCount = 1; //?
|
|
|
|
long BufferSize = Entry.Data.Size;
|
|
|
|
|
|
|
|
Writer.Write(BufferCount);
|
|
|
|
Writer.Write(BufferSize);
|
|
|
|
|
|
|
|
Entry.Data.Write(Writer);
|
|
|
|
|
|
|
|
Writer.Write(0);
|
|
|
|
|
|
|
|
return MakeReplyParcel(Context, MS.ToArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private long GbpDequeueBuffer(ServiceCtx Context, BinaryReader ParcelReader)
|
|
|
|
{
|
|
|
|
//TODO: Errors.
|
|
|
|
int Format = ParcelReader.ReadInt32();
|
|
|
|
int Width = ParcelReader.ReadInt32();
|
|
|
|
int Height = ParcelReader.ReadInt32();
|
|
|
|
int GetTimestamps = ParcelReader.ReadInt32();
|
|
|
|
int Usage = ParcelReader.ReadInt32();
|
|
|
|
|
|
|
|
int Slot = GetFreeSlotBlocking(Width, Height);
|
|
|
|
|
|
|
|
return MakeReplyParcel(Context, Slot, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private long GbpQueueBuffer(ServiceCtx Context, BinaryReader ParcelReader)
|
|
|
|
{
|
2018-03-06 21:18:49 +01:00
|
|
|
Context.Ns.Statistics.RecordGameFrameTime();
|
|
|
|
|
2018-02-23 22:48:27 +01:00
|
|
|
//TODO: Errors.
|
|
|
|
int Slot = ParcelReader.ReadInt32();
|
|
|
|
int Unknown4 = ParcelReader.ReadInt32();
|
|
|
|
int Unknown8 = ParcelReader.ReadInt32();
|
|
|
|
int Unknownc = ParcelReader.ReadInt32();
|
|
|
|
int Timestamp = ParcelReader.ReadInt32();
|
|
|
|
int IsAutoTimestamp = ParcelReader.ReadInt32();
|
|
|
|
int CropTop = ParcelReader.ReadInt32();
|
|
|
|
int CropLeft = ParcelReader.ReadInt32();
|
|
|
|
int CropRight = ParcelReader.ReadInt32();
|
|
|
|
int CropBottom = ParcelReader.ReadInt32();
|
|
|
|
int ScalingMode = ParcelReader.ReadInt32();
|
|
|
|
int Transform = ParcelReader.ReadInt32();
|
|
|
|
int StickyTransform = ParcelReader.ReadInt32();
|
|
|
|
int Unknown34 = ParcelReader.ReadInt32();
|
|
|
|
int Unknown38 = ParcelReader.ReadInt32();
|
|
|
|
int IsFenceValid = ParcelReader.ReadInt32();
|
|
|
|
int Fence0Id = ParcelReader.ReadInt32();
|
|
|
|
int Fence0Value = ParcelReader.ReadInt32();
|
|
|
|
int Fence1Id = ParcelReader.ReadInt32();
|
|
|
|
int Fence1Value = ParcelReader.ReadInt32();
|
|
|
|
|
|
|
|
BufferQueue[Slot].Transform = (HalTransform)Transform;
|
|
|
|
|
2018-03-01 03:37:40 +01:00
|
|
|
BufferQueue[Slot].Crop.Top = CropTop;
|
|
|
|
BufferQueue[Slot].Crop.Left = CropLeft;
|
|
|
|
BufferQueue[Slot].Crop.Right = CropRight;
|
|
|
|
BufferQueue[Slot].Crop.Bottom = CropBottom;
|
|
|
|
|
2018-02-23 22:48:27 +01:00
|
|
|
BufferQueue[Slot].State = BufferState.Queued;
|
|
|
|
|
|
|
|
SendFrameBuffer(Context, Slot);
|
|
|
|
|
|
|
|
return MakeReplyParcel(Context, 1280, 720, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2018-03-12 05:04:52 +01:00
|
|
|
private long GbpDetachBuffer(ServiceCtx Context, BinaryReader ParcelReader)
|
|
|
|
{
|
|
|
|
return MakeReplyParcel(Context, 0);
|
|
|
|
}
|
|
|
|
|
2018-02-23 22:48:27 +01:00
|
|
|
private long GbpCancelBuffer(ServiceCtx Context, BinaryReader ParcelReader)
|
|
|
|
{
|
|
|
|
//TODO: Errors.
|
|
|
|
int Slot = ParcelReader.ReadInt32();
|
|
|
|
|
|
|
|
BufferQueue[Slot].State = BufferState.Free;
|
|
|
|
|
|
|
|
return MakeReplyParcel(Context, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private long GbpQuery(ServiceCtx Context, BinaryReader ParcelReader)
|
|
|
|
{
|
|
|
|
return MakeReplyParcel(Context, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private long GbpConnect(ServiceCtx Context, BinaryReader ParcelReader)
|
|
|
|
{
|
|
|
|
return MakeReplyParcel(Context, 1280, 720, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
2018-03-06 21:27:50 +01:00
|
|
|
private long GbpDisconnect(ServiceCtx Context, BinaryReader ParcelReader)
|
|
|
|
{
|
|
|
|
return MakeReplyParcel(Context, 0);
|
|
|
|
}
|
|
|
|
|
2018-02-23 22:48:27 +01:00
|
|
|
private long GbpPreallocBuffer(ServiceCtx Context, BinaryReader ParcelReader)
|
|
|
|
{
|
|
|
|
int Slot = ParcelReader.ReadInt32();
|
|
|
|
|
|
|
|
int BufferCount = ParcelReader.ReadInt32();
|
|
|
|
long BufferSize = ParcelReader.ReadInt64();
|
|
|
|
|
|
|
|
BufferQueue[Slot].State = BufferState.Free;
|
|
|
|
|
|
|
|
BufferQueue[Slot].Data = new GbpBuffer(ParcelReader);
|
|
|
|
|
|
|
|
return MakeReplyParcel(Context, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private long MakeReplyParcel(ServiceCtx Context, params int[] Ints)
|
|
|
|
{
|
|
|
|
using (MemoryStream MS = new MemoryStream())
|
|
|
|
{
|
|
|
|
BinaryWriter Writer = new BinaryWriter(MS);
|
|
|
|
|
|
|
|
foreach (int Int in Ints)
|
|
|
|
{
|
|
|
|
Writer.Write(Int);
|
|
|
|
}
|
|
|
|
|
|
|
|
return MakeReplyParcel(Context, MS.ToArray());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private long MakeReplyParcel(ServiceCtx Context, byte[] Data)
|
|
|
|
{
|
|
|
|
long ReplyPos = Context.Request.ReceiveBuff[0].Position;
|
|
|
|
long ReplySize = Context.Request.ReceiveBuff[0].Size;
|
|
|
|
|
|
|
|
byte[] Reply = MakeParcel(Data, new byte[0]);
|
|
|
|
|
|
|
|
AMemoryHelper.WriteBytes(Context.Memory, ReplyPos, Reply);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private unsafe void SendFrameBuffer(ServiceCtx Context, int Slot)
|
|
|
|
{
|
|
|
|
int FbWidth = BufferQueue[Slot].Data.Width;
|
|
|
|
int FbHeight = BufferQueue[Slot].Data.Height;
|
|
|
|
|
2018-03-10 03:12:57 +01:00
|
|
|
long FbSize = (uint)FbWidth * FbHeight * 4;
|
2018-02-23 22:48:27 +01:00
|
|
|
|
2018-03-20 16:18:25 +01:00
|
|
|
NvMap Map = GetNvMap(Context, Slot);
|
2018-02-23 22:48:27 +01:00
|
|
|
|
2018-03-20 16:18:25 +01:00
|
|
|
NvMapFb MapFb = (NvMapFb)ServiceNvDrv.NvMapsFb.GetData(Context.Process, 0);
|
|
|
|
|
|
|
|
long Address = Map.CpuAddress;
|
|
|
|
|
|
|
|
if (MapFb.HasBufferOffset(Slot))
|
|
|
|
{
|
|
|
|
Address += MapFb.GetBufferOffset(Slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ulong)(Address + FbSize) > AMemoryMgr.AddrSize)
|
2018-02-23 22:48:27 +01:00
|
|
|
{
|
2018-03-20 16:18:25 +01:00
|
|
|
Logging.Error($"Frame buffer address {Address:x16} is invalid!");
|
2018-02-23 22:48:27 +01:00
|
|
|
|
|
|
|
BufferQueue[Slot].State = BufferState.Free;
|
|
|
|
|
2018-03-19 19:58:46 +01:00
|
|
|
ReleaseEvent.Handle.Set();
|
|
|
|
|
2018-02-23 22:48:27 +01:00
|
|
|
WaitBufferFree.Set();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-01 03:37:40 +01:00
|
|
|
BufferQueue[Slot].State = BufferState.Acquired;
|
|
|
|
|
|
|
|
Rect Crop = BufferQueue[Slot].Crop;
|
|
|
|
|
|
|
|
int RealWidth = FbWidth;
|
|
|
|
int RealHeight = FbHeight;
|
2018-02-23 22:48:27 +01:00
|
|
|
|
2018-03-05 00:32:18 +01:00
|
|
|
float XSign = BufferQueue[Slot].Transform.HasFlag(HalTransform.FlipX) ? -1 : 1;
|
|
|
|
float YSign = BufferQueue[Slot].Transform.HasFlag(HalTransform.FlipY) ? -1 : 1;
|
|
|
|
|
2018-02-23 22:48:27 +01:00
|
|
|
float ScaleX = 1;
|
|
|
|
float ScaleY = 1;
|
2018-03-05 00:32:18 +01:00
|
|
|
|
2018-03-01 03:37:40 +01:00
|
|
|
float OffsX = 0;
|
|
|
|
float OffsY = 0;
|
|
|
|
|
|
|
|
if (Crop.Right != 0 &&
|
|
|
|
Crop.Bottom != 0)
|
|
|
|
{
|
2018-03-05 00:32:18 +01:00
|
|
|
//Who knows if this is right, I was never good with math...
|
2018-03-01 03:37:40 +01:00
|
|
|
RealWidth = Crop.Right - Crop.Left;
|
|
|
|
RealHeight = Crop.Bottom - Crop.Top;
|
|
|
|
|
2018-03-05 00:32:18 +01:00
|
|
|
if (BufferQueue[Slot].Transform.HasFlag(HalTransform.Rotate90))
|
|
|
|
{
|
|
|
|
ScaleY = (float)FbHeight / RealHeight;
|
|
|
|
ScaleX = (float)FbWidth / RealWidth;
|
2018-03-01 03:37:40 +01:00
|
|
|
|
2018-03-05 00:32:18 +01:00
|
|
|
OffsY = ((-(float)Crop.Left / Crop.Right) + ScaleX - 1) * -XSign;
|
|
|
|
OffsX = ((-(float)Crop.Top / Crop.Bottom) + ScaleY - 1) * -YSign;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ScaleX = (float)FbWidth / RealWidth;
|
|
|
|
ScaleY = (float)FbHeight / RealHeight;
|
2018-03-01 03:37:40 +01:00
|
|
|
|
2018-03-05 00:32:18 +01:00
|
|
|
OffsX = ((-(float)Crop.Left / Crop.Right) + ScaleX - 1) * XSign;
|
|
|
|
OffsY = ((-(float)Crop.Top / Crop.Bottom) + ScaleY - 1) * -YSign;
|
|
|
|
}
|
2018-03-01 03:37:40 +01:00
|
|
|
}
|
|
|
|
|
2018-03-05 00:32:18 +01:00
|
|
|
ScaleX *= XSign;
|
|
|
|
ScaleY *= YSign;
|
2018-02-23 22:48:27 +01:00
|
|
|
|
2018-03-05 00:32:18 +01:00
|
|
|
float Rotate = 0;
|
2018-02-23 22:48:27 +01:00
|
|
|
|
|
|
|
if (BufferQueue[Slot].Transform.HasFlag(HalTransform.Rotate90))
|
|
|
|
{
|
2018-02-28 23:21:04 +01:00
|
|
|
Rotate = -MathF.PI * 0.5f;
|
2018-02-23 22:48:27 +01:00
|
|
|
}
|
|
|
|
|
2018-03-12 05:04:52 +01:00
|
|
|
lock (RenderQueueLock)
|
|
|
|
{
|
|
|
|
if (NvFlingerDisposed)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Interlocked.Increment(ref RenderQueueCount);
|
|
|
|
}
|
|
|
|
|
2018-03-20 16:18:25 +01:00
|
|
|
byte* Fb = (byte*)Context.Memory.Ram + Address;
|
2018-02-23 22:48:27 +01:00
|
|
|
|
|
|
|
Context.Ns.Gpu.Renderer.QueueAction(delegate()
|
|
|
|
{
|
|
|
|
Context.Ns.Gpu.Renderer.SetFrameBuffer(
|
|
|
|
Fb,
|
|
|
|
FbWidth,
|
|
|
|
FbHeight,
|
|
|
|
ScaleX,
|
|
|
|
ScaleY,
|
2018-03-01 03:37:40 +01:00
|
|
|
OffsX,
|
|
|
|
OffsY,
|
2018-02-23 22:48:27 +01:00
|
|
|
Rotate);
|
|
|
|
|
|
|
|
BufferQueue[Slot].State = BufferState.Free;
|
|
|
|
|
2018-03-12 05:04:52 +01:00
|
|
|
Interlocked.Decrement(ref RenderQueueCount);
|
|
|
|
|
2018-03-19 19:58:46 +01:00
|
|
|
ReleaseEvent.Handle.Set();
|
|
|
|
|
2018-02-24 15:19:28 +01:00
|
|
|
lock (WaitBufferFree)
|
|
|
|
{
|
|
|
|
WaitBufferFree.Set();
|
|
|
|
}
|
2018-02-23 22:48:27 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-12 05:04:52 +01:00
|
|
|
private NvMap GetNvMap(ServiceCtx Context, int Slot)
|
2018-02-23 22:48:27 +01:00
|
|
|
{
|
|
|
|
int NvMapHandle = BitConverter.ToInt32(BufferQueue[Slot].Data.RawData, 0x4c);
|
|
|
|
|
|
|
|
if (!BitConverter.IsLittleEndian)
|
|
|
|
{
|
|
|
|
byte[] RawValue = BitConverter.GetBytes(NvMapHandle);
|
|
|
|
|
|
|
|
Array.Reverse(RawValue);
|
|
|
|
|
|
|
|
NvMapHandle = BitConverter.ToInt32(RawValue, 0);
|
|
|
|
}
|
|
|
|
|
2018-03-19 19:58:46 +01:00
|
|
|
return ServiceNvDrv.NvMaps.GetData<NvMap>(Context.Process, NvMapHandle);
|
2018-02-23 22:48:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private int GetFreeSlotBlocking(int Width, int Height)
|
|
|
|
{
|
|
|
|
int Slot;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2018-02-24 15:19:28 +01:00
|
|
|
lock (WaitBufferFree)
|
2018-02-23 22:48:27 +01:00
|
|
|
{
|
2018-02-24 15:19:28 +01:00
|
|
|
if ((Slot = GetFreeSlot(Width, Height)) != -1)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-02-23 22:48:27 +01:00
|
|
|
|
2018-02-24 15:19:28 +01:00
|
|
|
Logging.Debug("Waiting for a free BufferQueue slot...");
|
2018-02-23 22:48:27 +01:00
|
|
|
|
|
|
|
if (!KeepRunning)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitBufferFree.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitBufferFree.WaitOne();
|
|
|
|
}
|
|
|
|
while (KeepRunning);
|
|
|
|
|
|
|
|
Logging.Debug($"Found free BufferQueue slot {Slot}!");
|
|
|
|
|
|
|
|
return Slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int GetFreeSlot(int Width, int Height)
|
|
|
|
{
|
|
|
|
lock (BufferQueue)
|
|
|
|
{
|
|
|
|
for (int Slot = 0; Slot < BufferQueue.Length; Slot++)
|
|
|
|
{
|
|
|
|
if (BufferQueue[Slot].State != BufferState.Free)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
GbpBuffer Data = BufferQueue[Slot].Data;
|
|
|
|
|
|
|
|
if (Data.Width == Width &&
|
|
|
|
Data.Height == Height)
|
|
|
|
{
|
|
|
|
BufferQueue[Slot].State = BufferState.Dequeued;
|
|
|
|
|
|
|
|
return Slot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
2018-03-12 05:04:52 +01:00
|
|
|
protected virtual void Dispose(bool Disposing)
|
2018-02-23 22:48:27 +01:00
|
|
|
{
|
2018-03-12 05:04:52 +01:00
|
|
|
if (Disposing && !NvFlingerDisposed)
|
2018-02-23 22:48:27 +01:00
|
|
|
{
|
2018-03-12 05:04:52 +01:00
|
|
|
lock (RenderQueueLock)
|
|
|
|
{
|
|
|
|
NvFlingerDisposed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Ensure that all pending actions was sent before
|
|
|
|
//we can safely assume that the class was disposed.
|
|
|
|
while (RenderQueueCount > 0)
|
|
|
|
{
|
|
|
|
Thread.Yield();
|
|
|
|
}
|
|
|
|
|
|
|
|
Renderer.ResetFrameBuffer();
|
|
|
|
|
2018-02-23 22:48:27 +01:00
|
|
|
lock (WaitBufferFree)
|
|
|
|
{
|
|
|
|
KeepRunning = false;
|
|
|
|
|
|
|
|
WaitBufferFree.Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
WaitBufferFree.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|