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 public sealed class Sheet : IDisposable
{ {
readonly object textureLock = new object();
bool dirty; bool dirty;
bool releaseBufferOnCommit; bool releaseBufferOnCommit;
ITexture texture; ITexture texture;
@@ -65,16 +64,6 @@ namespace OpenRA.Graphics
} }
public ITexture GetTexture() 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)
{ {
@@ -82,17 +71,15 @@ namespace OpenRA.Graphics
dirty = true; dirty = true;
} }
if (data != null) if (data != null && dirty)
{
if (dirty)
{ {
texture.SetData(data, Size.Width, Size.Height); texture.SetData(data, Size.Width, Size.Height);
dirty = false; dirty = false;
if (releaseBufferOnCommit) if (releaseBufferOnCommit)
data = null; data = null;
} }
}
} return texture;
} }
public Bitmap AsBitmap() public Bitmap AsBitmap()
@@ -140,8 +127,6 @@ namespace OpenRA.Graphics
} }
public void CreateBuffer() public void CreateBuffer()
{
lock (textureLock)
{ {
if (data != null) if (data != null)
return; return;
@@ -151,32 +136,25 @@ namespace OpenRA.Graphics
data = texture.GetData(); data = texture.GetData();
releaseBufferOnCommit = false; releaseBufferOnCommit = false;
} }
}
public void CommitData() public void CommitBufferedData()
{
lock (textureLock)
{ {
if (!Buffered) if (!Buffered)
throw new InvalidOperationException( throw new InvalidOperationException(
"This sheet is unbuffered. You cannot call CommitData on an unbuffered sheet. " + "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 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 you need to make only small changes to the texture data consider creating a buffered sheet instead.");
dirty = true; dirty = true;
} }
}
public void ReleaseBuffer() public void ReleaseBuffer()
{
lock (textureLock)
{ {
if (!Buffered) if (!Buffered)
return; return;
dirty = true; dirty = true;
releaseBufferOnCommit = true; releaseBufferOnCommit = true;
} }
}
public void Dispose() public void Dispose()
{ {

View File

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

View File

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

View File

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

View File

@@ -216,7 +216,7 @@ namespace OpenRA.Mods.Common.Widgets
dirtyShroudCells.Clear(); 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 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); var s = new float2(mapRect.Size.Width, mapRect.Size.Height * radarMinimapHeight);