Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 1f87bd6

Browse files
authored
Revert "Gradient Memory Leak, Transformations and Clipping"
1 parent 2bc6b02 commit 1f87bd6

File tree

2 files changed

+5
-78
lines changed

2 files changed

+5
-78
lines changed

source/GameOverlay/Drawing/Graphics.cs

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -350,37 +350,6 @@ public SolidBrush CreateSolidBrush(Color color)
350350
return new SolidBrush(_device, color);
351351
}
352352

353-
/// <summary>
354-
/// Specifies a rectangle to which all subsequent drawing operations are clipped.
355-
/// </summary>
356-
/// <param name="left">The x-coordinate of the upper-left corner of the rectangle.</param>
357-
/// <param name="top">The y-coordinate of the upper-left corner of the rectangle.</param>
358-
/// <param name="right">The x-coordinate of the lower-right corner of the rectangle.</param>
359-
/// <param name="bottom">The y-coordinate of the lower-right corner of the rectangle.</param>
360-
public void ClipRegionStart(float left, float top, float right, float bottom)
361-
{
362-
if (!IsDrawing) ThrowHelper.UseBeginScene();
363-
364-
_device.PushAxisAlignedClip(new RawRectangleF(left, top, right, bottom), PerPrimitiveAntiAliasing ? AntialiasMode.PerPrimitive : AntialiasMode.Aliased);
365-
}
366-
367-
/// <summary>
368-
/// Specifies a rectangle to which all subsequent drawing operations are clipped.
369-
/// </summary>
370-
/// <param name="region">A Rectangle representing the size and position of the clipping area.</param>
371-
public void ClipRegionStart(Rectangle region)
372-
=> ClipRegionStart(region.Left, region.Top, region.Right, region.Bottom);
373-
374-
/// <summary>
375-
/// Removes the last clip from the render target. After this method is called, the clip is no longer applied to subsequent drawing operations.
376-
/// </summary>
377-
public void ClipRegionEnd()
378-
{
379-
if (!IsDrawing) ThrowHelper.UseBeginScene();
380-
381-
_device.PopAxisAlignedClip();
382-
}
383-
384353
/// <summary>
385354
/// Draws a circle with a dashed line by using the given brush and dimension.
386355
/// </summary>
@@ -1255,43 +1224,6 @@ public void DrawTextWithBackground(Font font, float fontSize, IBrush brush, IBru
12551224
layout.Dispose();
12561225
}
12571226

1258-
/// <summary>
1259-
/// Measures the specified string when drawn with the specified Font.
1260-
/// </summary>
1261-
/// <param name="font">Font that defines the text format of the string.</param>
1262-
/// <param name="fontSize">The size of the Font. (does not need to be the same as in Font.FontSize)</param>
1263-
/// <param name="text">String to measure.</param>
1264-
/// <returns>This method returns a Point containing the width (x) and height (y) of the given text.</returns>
1265-
public Point MeasureString(Font font, float fontSize, string text)
1266-
{
1267-
if (!IsDrawing) throw ThrowHelper.UseBeginScene();
1268-
1269-
if (text == null) throw new ArgumentNullException(nameof(text));
1270-
if (text.Length == 0) return default;
1271-
1272-
var layout = new TextLayout(_fontFactory, text, font.TextFormat, Width, Height);
1273-
1274-
if (fontSize != font.FontSize)
1275-
{
1276-
layout.SetFontSize(fontSize, new TextRange(0, text.Length));
1277-
}
1278-
1279-
var result = new Point(layout.Metrics.Width, layout.Metrics.Height);
1280-
1281-
layout.Dispose();
1282-
1283-
return result;
1284-
}
1285-
1286-
/// <summary>
1287-
/// Measures the specified string when drawn with the specified Font.
1288-
/// </summary>
1289-
/// <param name="font">Font that defines the text format of the string.</param>
1290-
/// <param name="text">String to measure.</param>
1291-
/// <returns>This method returns a Point containing the width (x) and height (y) of the given text.</returns>
1292-
public Point MeasureString(Font font, string text)
1293-
=> MeasureString(font, font.FontSize, text);
1294-
12951227
/// <summary>
12961228
/// Draws a string with a background box in behind using the given font, size and position.
12971229
/// </summary>

source/GameOverlay/Drawing/LinearGradientBrush.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace GameOverlay.Drawing
1313
public class LinearGradientBrush : IDisposable, IBrush
1414
{
1515
private SharpDXGradientBrush _brush;
16-
private GradientStopCollection _stopCollection;
1716

1817
/// <summary>
1918
/// Gets or sets the underlying Brush.
@@ -60,11 +59,9 @@ public LinearGradientBrush(RenderTarget device, params Color[] colors)
6059
position += stepSize;
6160
}
6261

63-
_stopCollection = new GradientStopCollection(device, gradientStops, ExtendMode.Clamp);
64-
6562
Brush = new SharpDXGradientBrush(device,
6663
new LinearGradientBrushProperties(),
67-
_stopCollection);
64+
new GradientStopCollection(device, gradientStops, ExtendMode.Clamp));
6865
}
6966

7067
/// <summary>
@@ -157,7 +154,7 @@ public override string ToString()
157154
}
158155

159156
#region IDisposable Support
160-
private bool disposedValue;
157+
private bool disposedValue = false;
161158

162159
/// <summary>
163160
/// Releases all resources used by this LinearGradientBrush.
@@ -167,11 +164,9 @@ protected virtual void Dispose(bool disposing)
167164
{
168165
if (!disposedValue)
169166
{
170-
_brush?.Dispose();
171-
_stopCollection?.Dispose();
172-
173-
_brush = null;
174-
_stopCollection = null;
167+
if (disposing)
168+
{
169+
}
175170

176171
disposedValue = true;
177172
}

0 commit comments

Comments
 (0)