Remove half-baked thread-safety mechanisms from Sheet.

Sheet is now thread-unsafe, rather than attempting to expose a dodgy thread safety model.
This commit is contained in:
RoosterDragon
2015-05-20 18:50:28 +01:00
parent d42c3a9740
commit b48b994f16
5 changed files with 36 additions and 58 deletions

View File

@@ -18,7 +18,6 @@ namespace OpenRA.Graphics
{
public sealed class Sheet : IDisposable
{
readonly object textureLock = new object();
bool dirty;
bool releaseBufferOnCommit;
ITexture texture;
@@ -66,33 +65,21 @@ namespace OpenRA.Graphics
public ITexture GetTexture()
{
// This is only called from the main thread but 'dirty'
// is set from other threads too via CommitData().
GenerateTexture();
return texture;
}
void GenerateTexture()
{
lock (textureLock)
if (texture == null)
{
if (texture == null)
{
texture = Game.Renderer.Device.CreateTexture();
dirty = true;
}
if (data != null)
{
if (dirty)
{
texture.SetData(data, Size.Width, Size.Height);
dirty = false;
if (releaseBufferOnCommit)
data = null;
}
}
texture = Game.Renderer.Device.CreateTexture();
dirty = true;
}
if (data != null && dirty)
{
texture.SetData(data, Size.Width, Size.Height);
dirty = false;
if (releaseBufferOnCommit)
data = null;
}
return texture;
}
public Bitmap AsBitmap()
@@ -141,41 +128,32 @@ namespace OpenRA.Graphics
public void CreateBuffer()
{
lock (textureLock)
{
if (data != null)
return;
if (texture == null)
data = new byte[4 * Size.Width * Size.Height];
else
data = texture.GetData();
releaseBufferOnCommit = false;
}
if (data != null)
return;
if (texture == null)
data = new byte[4 * Size.Width * Size.Height];
else
data = texture.GetData();
releaseBufferOnCommit = false;
}
public void CommitData()
public void CommitBufferedData()
{
lock (textureLock)
{
if (!Buffered)
throw new InvalidOperationException(
"This sheet is unbuffered. You cannot call CommitData on an unbuffered sheet. " +
"If you need to completely replace the texture data you should set data into the texture directly. " +
"If you need to make only small changes to the texture data consider creating a buffered sheet instead.");
if (!Buffered)
throw new InvalidOperationException(
"This sheet is unbuffered. You cannot call CommitBufferedData on an unbuffered sheet. " +
"If you need to completely replace the texture data you should set data into the texture directly. " +
"If you need to make only small changes to the texture data consider creating a buffered sheet instead.");
dirty = true;
}
dirty = true;
}
public void ReleaseBuffer()
{
lock (textureLock)
{
if (!Buffered)
return;
dirty = true;
releaseBufferOnCommit = true;
}
if (!Buffered)
return;
dirty = true;
releaseBufferOnCommit = true;
}
public void Dispose()

View File

@@ -70,7 +70,7 @@ namespace OpenRA.Graphics
var rect = Allocate(size, spriteOffset);
Util.FastCopyIntoChannel(rect, src);
current.CommitData();
current.CommitBufferedData();
return rect;
}
@@ -78,7 +78,7 @@ namespace OpenRA.Graphics
{
var rect = Allocate(src.Size);
Util.FastCopyIntoSprite(rect, src);
current.CommitData();
current.CommitBufferedData();
return rect;
}

View File

@@ -136,7 +136,7 @@ namespace OpenRA.Graphics
}
}
s.Sheet.CommitData();
s.Sheet.CommitBufferedData();
return g;
}

View File

@@ -86,7 +86,7 @@ namespace OpenRA.Graphics
var s = sheetBuilder.Allocate(new Size(su, sv));
Util.FastCopyIntoChannel(s, 0, colors);
Util.FastCopyIntoChannel(s, 1, normals);
s.Sheet.CommitData();
s.Sheet.CommitBufferedData();
var channelP = ChannelSelect[(int)s.Channel];
var channelC = ChannelSelect[(int)s.Channel + 1];

View File

@@ -216,7 +216,7 @@ namespace OpenRA.Mods.Common.Widgets
dirtyShroudCells.Clear();
}
radarSheet.CommitData();
radarSheet.CommitBufferedData();
var o = new float2(mapRect.Location.X, mapRect.Location.Y + world.Map.Bounds.Height * previewScale * (1 - radarMinimapHeight) / 2);
var s = new float2(mapRect.Size.Width, mapRect.Size.Height * radarMinimapHeight);