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()