2018-10-17 17:15:50 +00:00
|
|
|
using Ryujinx.Common.Logging;
|
2018-03-12 04:04:52 +00:00
|
|
|
using Ryujinx.Graphics.Gal;
|
2018-09-18 04:30:35 +00:00
|
|
|
using Ryujinx.Graphics.Memory;
|
2018-08-16 23:47:36 +00:00
|
|
|
using Ryujinx.HLE.HOS.Kernel;
|
2018-09-18 04:30:35 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Nv.NvGpuAS;
|
2018-08-16 23:47:36 +00:00
|
|
|
using Ryujinx.HLE.HOS.Services.Nv.NvMap;
|
2018-02-23 21:48:27 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2018-03-20 20:00:00 +00:00
|
|
|
using System.IO;
|
2018-02-23 21:48:27 +00:00
|
|
|
using System.Text;
|
|
|
|
using System.Threading;
|
2018-06-24 00:39:25 +00:00
|
|
|
|
2018-08-16 23:47:36 +00:00
|
|
|
using static Ryujinx.HLE.HOS.Services.Android.Parcel;
|
2018-06-09 16:05:41 +00:00
|
|
|
|
2018-08-16 23:47:36 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Android
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
|
|
|
class NvFlinger : IDisposable
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
private delegate long ServiceProcessParcel(ServiceCtx context, BinaryReader parcelReader);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private Dictionary<(string, int), ServiceProcessParcel> _commands;
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private KEvent _binderEvent;
|
2018-03-19 18:58:46 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private IGalRenderer _renderer;
|
2018-03-19 18:58:46 +00:00
|
|
|
|
2018-02-23 21:48:27 +00: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 02:37:40 +00:00
|
|
|
private struct Rect
|
|
|
|
{
|
|
|
|
public int Top;
|
|
|
|
public int Left;
|
|
|
|
public int Right;
|
|
|
|
public int Bottom;
|
|
|
|
}
|
|
|
|
|
2018-02-23 21:48:27 +00:00
|
|
|
private struct BufferEntry
|
|
|
|
{
|
|
|
|
public BufferState State;
|
|
|
|
|
|
|
|
public HalTransform Transform;
|
|
|
|
|
2018-03-01 02:37:40 +00:00
|
|
|
public Rect Crop;
|
|
|
|
|
2018-02-23 21:48:27 +00:00
|
|
|
public GbpBuffer Data;
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private BufferEntry[] _bufferQueue;
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private AutoResetEvent _waitBufferFree;
|
2018-04-06 04:01:52 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private bool _disposed;
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
public NvFlinger(IGalRenderer renderer, KEvent binderEvent)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
_commands = new Dictionary<(string, int), ServiceProcessParcel>
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0x1), GbpRequestBuffer },
|
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0x3), GbpDequeueBuffer },
|
2018-03-12 04:04:52 +00:00
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0x4), GbpDetachBuffer },
|
2018-02-23 21:48:27 +00:00
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0x7), GbpQueueBuffer },
|
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0x8), GbpCancelBuffer },
|
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0x9), GbpQuery },
|
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0xa), GbpConnect },
|
2018-03-06 20:27:50 +00:00
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0xb), GbpDisconnect },
|
2018-02-23 21:48:27 +00:00
|
|
|
{ ("android.gui.IGraphicBufferProducer", 0xe), GbpPreallocBuffer }
|
|
|
|
};
|
2018-04-06 04:01:52 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_renderer = renderer;
|
|
|
|
_binderEvent = binderEvent;
|
2018-03-12 04:04:52 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_bufferQueue = new BufferEntry[0x40];
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_waitBufferFree = new AutoResetEvent(false);
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
public long ProcessParcelRequest(ServiceCtx context, byte[] parcelData, int code)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
using (MemoryStream ms = new MemoryStream(parcelData))
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
BinaryReader reader = new BinaryReader(ms);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
ms.Seek(4, SeekOrigin.Current);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
int strSize = reader.ReadInt32();
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
string interfaceName = Encoding.Unicode.GetString(reader.ReadBytes(strSize * 2));
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
long remainder = ms.Position & 0xf;
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
if (remainder != 0)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
ms.Seek(0x10 - remainder, SeekOrigin.Current);
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
ms.Seek(0x50, SeekOrigin.Begin);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
if (_commands.TryGetValue((interfaceName, code), out ServiceProcessParcel procReq))
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
Logger.PrintDebug(LogClass.ServiceVi, $"{interfaceName} {procReq.Method.Name}");
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
return procReq(context, reader);
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
throw new NotImplementedException($"{interfaceName} {code}");
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private long GbpRequestBuffer(ServiceCtx context, BinaryReader parcelReader)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
int slot = parcelReader.ReadInt32();
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
using (MemoryStream ms = new MemoryStream())
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
BinaryWriter writer = new BinaryWriter(ms);
|
2018-04-06 04:01:52 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
BufferEntry entry = _bufferQueue[slot];
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
int bufferCount = 1; //?
|
|
|
|
long bufferSize = entry.Data.Size;
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
writer.Write(bufferCount);
|
|
|
|
writer.Write(bufferSize);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
entry.Data.Write(writer);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
writer.Write(0);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
return MakeReplyParcel(context, ms.ToArray());
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private long GbpDequeueBuffer(ServiceCtx context, BinaryReader parcelReader)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
|
|
|
//TODO: Errors.
|
2018-12-06 11:16:24 +00:00
|
|
|
int format = parcelReader.ReadInt32();
|
|
|
|
int width = parcelReader.ReadInt32();
|
|
|
|
int height = parcelReader.ReadInt32();
|
|
|
|
int getTimestamps = parcelReader.ReadInt32();
|
|
|
|
int usage = parcelReader.ReadInt32();
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
int slot = GetFreeSlotBlocking(width, height);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
return MakeReplyParcel(context, slot, 1, 0x24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private long GbpQueueBuffer(ServiceCtx context, BinaryReader parcelReader)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
context.Device.Statistics.RecordGameFrameTime();
|
2018-03-06 20:18:49 +00:00
|
|
|
|
2018-02-23 21:48:27 +00:00
|
|
|
//TODO: Errors.
|
2018-12-06 11:16:24 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
_bufferQueue[slot].Crop.Top = cropTop;
|
|
|
|
_bufferQueue[slot].Crop.Left = cropLeft;
|
|
|
|
_bufferQueue[slot].Crop.Right = cropRight;
|
|
|
|
_bufferQueue[slot].Crop.Bottom = cropBottom;
|
|
|
|
|
|
|
|
_bufferQueue[slot].State = BufferState.Queued;
|
|
|
|
|
|
|
|
SendFrameBuffer(context, slot);
|
|
|
|
|
|
|
|
if (context.Device.EnableDeviceVsync)
|
2018-09-09 23:38:56 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
context.Device.VsyncEvent.WaitOne();
|
2018-09-09 23:38:56 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
return MakeReplyParcel(context, 1280, 720, 0, 0, 0);
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private long GbpDetachBuffer(ServiceCtx context, BinaryReader parcelReader)
|
2018-03-12 04:04:52 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
return MakeReplyParcel(context, 0);
|
2018-03-12 04:04:52 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private long GbpCancelBuffer(ServiceCtx context, BinaryReader parcelReader)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
|
|
|
//TODO: Errors.
|
2018-12-06 11:16:24 +00:00
|
|
|
int slot = parcelReader.ReadInt32();
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_bufferQueue[slot].State = BufferState.Free;
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_waitBufferFree.Set();
|
2018-09-18 23:36:43 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
return MakeReplyParcel(context, 0);
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private long GbpQuery(ServiceCtx context, BinaryReader parcelReader)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
return MakeReplyParcel(context, 0, 0);
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private long GbpConnect(ServiceCtx context, BinaryReader parcelReader)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
return MakeReplyParcel(context, 1280, 720, 0, 0, 0);
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private long GbpDisconnect(ServiceCtx context, BinaryReader parcelReader)
|
2018-03-06 20:27:50 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
return MakeReplyParcel(context, 0);
|
2018-03-06 20:27:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private long GbpPreallocBuffer(ServiceCtx context, BinaryReader parcelReader)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
int slot = parcelReader.ReadInt32();
|
2018-04-06 04:01:52 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
int bufferCount = parcelReader.ReadInt32();
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
if (bufferCount > 0)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
long bufferSize = parcelReader.ReadInt64();
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_bufferQueue[slot].State = BufferState.Free;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_bufferQueue[slot].Data = new GbpBuffer(parcelReader);
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
return MakeReplyParcel(context, 0);
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private long MakeReplyParcel(ServiceCtx context, params int[] ints)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
using (MemoryStream ms = new MemoryStream())
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
BinaryWriter writer = new BinaryWriter(ms);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
foreach (int Int in ints)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
writer.Write(Int);
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
return MakeReplyParcel(context, ms.ToArray());
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private long MakeReplyParcel(ServiceCtx context, byte[] data)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
(long replyPos, long replySize) = context.Request.GetBufferType0x22();
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
byte[] reply = MakeParcel(data, new byte[0]);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
context.Memory.WriteBytes(replyPos, reply);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private void SendFrameBuffer(ServiceCtx context, int slot)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
int fbWidth = _bufferQueue[slot].Data.Width;
|
|
|
|
int fbHeight = _bufferQueue[slot].Data.Height;
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
int nvMapHandle = BitConverter.ToInt32(_bufferQueue[slot].Data.RawData, 0x4c);
|
|
|
|
int bufferOffset = BitConverter.ToInt32(_bufferQueue[slot].Data.RawData, 0x50);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
NvMapHandle map = NvMapIoctl.GetNvMap(context, nvMapHandle);
|
2018-03-20 15:18:25 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
long fbAddr = map.Address + bufferOffset;
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_bufferQueue[slot].State = BufferState.Acquired;
|
2018-03-01 02:37:40 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
Rect crop = _bufferQueue[slot].Crop;
|
2018-03-01 02:37:40 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
bool flipX = _bufferQueue[slot].Transform.HasFlag(HalTransform.FlipX);
|
|
|
|
bool flipY = _bufferQueue[slot].Transform.HasFlag(HalTransform.FlipY);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-09-18 04:30:35 +00:00
|
|
|
//Note: Rotation is being ignored.
|
2018-03-04 23:32:18 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
int top = crop.Top;
|
|
|
|
int left = crop.Left;
|
|
|
|
int right = crop.Right;
|
|
|
|
int bottom = crop.Bottom;
|
2018-03-04 23:32:18 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
NvGpuVmm vmm = NvGpuASIoctl.GetASCtx(context).Vmm;
|
2018-03-12 04:04:52 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_renderer.QueueAction(() =>
|
2018-04-13 18:12:58 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
if (!_renderer.Texture.TryGetImage(fbAddr, out GalImage image))
|
2018-09-18 04:30:35 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
image = new GalImage(
|
|
|
|
fbWidth,
|
|
|
|
fbHeight, 1, 16,
|
2018-09-18 04:30:35 +00:00
|
|
|
GalMemoryLayout.BlockLinear,
|
2018-10-17 21:02:23 +00:00
|
|
|
GalImageFormat.RGBA8 | GalImageFormat.Unorm);
|
2018-09-18 04:30:35 +00:00
|
|
|
}
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
context.Device.Gpu.ResourceManager.ClearPbCache();
|
|
|
|
context.Device.Gpu.ResourceManager.SendTexture(vmm, fbAddr, image);
|
2018-03-12 04:04:52 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_renderer.RenderTarget.SetTransform(flipX, flipY, top, left, right, bottom);
|
|
|
|
_renderer.RenderTarget.Present(fbAddr);
|
2018-03-19 18:58:46 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
ReleaseBuffer(slot);
|
2018-09-18 04:30:35 +00:00
|
|
|
});
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private void ReleaseBuffer(int slot)
|
2018-04-13 18:12:58 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
_bufferQueue[slot].State = BufferState.Free;
|
2018-04-13 18:12:58 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_binderEvent.ReadableEvent.Signal();
|
2018-04-13 18:12:58 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_waitBufferFree.Set();
|
2018-04-13 18:12:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private int GetFreeSlotBlocking(int width, int height)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
int slot;
|
2018-02-23 21:48:27 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
if ((slot = GetFreeSlot(width, height)) != -1)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-09-18 23:36:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
if (_disposed)
|
2018-09-18 23:36:43 +00:00
|
|
|
{
|
|
|
|
break;
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_waitBufferFree.WaitOne();
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
2018-12-06 11:16:24 +00:00
|
|
|
while (!_disposed);
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
return slot;
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
private int GetFreeSlot(int width, int height)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
lock (_bufferQueue)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
for (int slot = 0; slot < _bufferQueue.Length; slot++)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
if (_bufferQueue[slot].State != BufferState.Free)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
GbpBuffer data = _bufferQueue[slot].Data;
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
if (data.Width == width &&
|
|
|
|
data.Height == height)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
_bufferQueue[slot].State = BufferState.Dequeued;
|
2018-02-23 21:48:27 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
return slot;
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
protected virtual void Dispose(bool disposing)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
if (disposing && !_disposed)
|
2018-02-23 21:48:27 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
_disposed = true;
|
2018-03-12 04:04:52 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
_waitBufferFree.Set();
|
|
|
|
_waitBufferFree.Dispose();
|
2018-02-23 21:48:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|