Skip to content
Permalink
Browse files

[Fonts] Turned various internal parameters from ref to in (C# 7.2)

  • Loading branch information
xen2 committed Oct 23, 2019
1 parent 1a9bfd6 commit f1513b93984b2581c13a8adb35bdfee20d6e3817
@@ -62,7 +62,7 @@ protected struct ElementInfo
/// </summary>
public TDrawInfo DrawInfo;

public ElementInfo(int vertexCount, int indexCount, ref TDrawInfo drawInfo, float depth = 0)
public ElementInfo(int vertexCount, int indexCount, in TDrawInfo drawInfo, float depth = 0)
{
VertexCount = vertexCount;
IndexCount = indexCount;
@@ -522,7 +522,7 @@ private void DrawBatchPerTextureAndPass(ElementInfo[] sprites, int offset, int c
}
}

protected void Draw(Texture texture, ref ElementInfo elementInfo)
protected void Draw(Texture texture, in ElementInfo elementInfo)
{
// Make sure that Begin was called
CheckBeginHasBeenCalled("draw");
@@ -86,7 +86,7 @@ public override bool IsCharPresent(char c)
return CharacterToGlyph.ContainsKey(c);
}

protected override Glyph GetGlyph(CommandList commandList, char character, ref Vector2 fontSize, bool dumb, out Vector2 fixScaling)
protected override Glyph GetGlyph(CommandList commandList, char character, in Vector2 fontSize, bool dumb, out Vector2 fixScaling)
{
Glyph glyph = null;
fixScaling = new Vector2(1, 1);
@@ -97,7 +97,7 @@ public override bool IsCharPresent(char c)
return FontManager.DoesFontContains(FontName, Style, c);
}

protected override Glyph GetGlyph(CommandList commandList, char character, ref Vector2 fontSize, bool uploadGpuResources, out Vector2 fixScaling)
protected override Glyph GetGlyph(CommandList commandList, char character, in Vector2 fontSize, bool uploadGpuResources, out Vector2 fixScaling)
{
// Add a safe guard to prevent the system to generate characters too big for the dynamic font cache texture
var realFontSize = fontSize;
@@ -89,7 +89,7 @@ public override bool IsCharPresent(char c)
return CharacterToGlyph.ContainsKey(c);
}

protected override Glyph GetGlyph(CommandList commandList, char character, ref Vector2 fontSize, bool dumb, out Vector2 fixScaling)
protected override Glyph GetGlyph(CommandList commandList, char character, in Vector2 fontSize, bool dumb, out Vector2 fixScaling)
{
Glyph glyph = null;
fixScaling = new Vector2(1, 1);
@@ -124,7 +124,7 @@ public void Begin(GraphicsContext graphicsContext, Matrix viewProjection, Sprite
depthSprite = projectedPosition.Z / projectedPosition.W;
}

var elementInfo = new ElementInfo(StaticQuadBufferInfo.VertexByElement, StaticQuadBufferInfo.IndicesByElement, ref drawInfo, depthSprite);
var elementInfo = new ElementInfo(StaticQuadBufferInfo.VertexByElement, StaticQuadBufferInfo.IndicesByElement, in drawInfo, depthSprite);

Draw(texture, ref elementInfo);
}
@@ -500,7 +500,7 @@ private void DrawString(SpriteFont spriteFont, ref SpriteFont.StringProxy text,
scale.Y = scale.Y / resolutionRatio.Y;

var fontSize2 = fontSize * ((spriteFont.FontType == SpriteFontType.Dynamic) ? resolutionRatio : Vector2.One);
var drawCommand = new SpriteFont.InternalDrawCommand(this, ref fontSize2, ref position, ref color, rotation, ref origin, ref scale, effects, layerDepth);
var drawCommand = new SpriteFont.InternalDrawCommand(this, in fontSize2, in position, in color, rotation, in origin, in scale, effects, layerDepth);

// snap the position the closest 'real' pixel
Vector2.Modulate(ref drawCommand.Position, ref resolutionRatio, out drawCommand.Position);
@@ -585,7 +585,7 @@ private void DrawString(SpriteFont spriteFont, ref SpriteFont.StringProxy text,
elementInfo.IndexCount = StaticQuadBufferInfo.IndicesByElement;
elementInfo.Depth = depth;

Draw(texture, ref elementInfo);
Draw(texture, in elementInfo);
}

protected override unsafe void UpdateBufferValuesFromElementInfo(ref ElementInfo elementInfo, IntPtr vertexPtr, IntPtr indexPtr, int vertexOffset)
@@ -225,7 +225,7 @@ internal virtual void PreGenerateGlyphs(ref StringProxy text, ref Vector2 size)
{
}

internal void InternalDrawGlyph(ref InternalDrawCommand parameters, ref Vector2 fontSize, ref Glyph glyph, float x, float y, float nextx, ref Vector2 auxiliaryScaling)
internal void InternalDrawGlyph(ref InternalDrawCommand parameters, in Vector2 fontSize, in Glyph glyph, float x, float y, float nextx, ref Vector2 auxiliaryScaling)
{
if (char.IsWhiteSpace((char)glyph.Character) || glyph.Subrect.Width == 0 || glyph.Subrect.Height == 0)
return;
@@ -258,7 +258,7 @@ internal void InternalUIDraw(CommandList commandList, ref StringProxy text, ref
ForEachGlyph(commandList, ref text, ref requestedFontSize, internalUIDrawGlyphAction, ref drawCommand, drawCommand.Alignment, true, textBoxSize);
}

internal void InternalUIDrawGlyph(ref InternalUIDrawCommand parameters, ref Vector2 requestedFontSize, ref Glyph glyph, float x, float y, float nextx, ref Vector2 auxiliaryScaling)
internal void InternalUIDrawGlyph(ref InternalUIDrawCommand parameters, in Vector2 requestedFontSize, in Glyph glyph, float x, float y, float nextx, ref Vector2 auxiliaryScaling)
{
if (char.IsWhiteSpace((char)glyph.Character))
return;
@@ -299,7 +299,7 @@ internal void InternalUIDrawGlyph(ref InternalUIDrawCommand parameters, ref Vect
worldMatrix.M24 *= elementSize.Y;

RectangleF sourceRectangle = glyph.Subrect;
parameters.Batch.DrawCharacter(Textures[glyph.BitmapIndex], ref worldMatrix, ref sourceRectangle, ref parameters.Color, parameters.DepthBias, swizzle);
parameters.Batch.DrawCharacter(Textures[glyph.BitmapIndex], in worldMatrix, in sourceRectangle, in parameters.Color, parameters.DepthBias, swizzle);
}

/// <summary>
@@ -472,13 +472,13 @@ public virtual bool IsCharPresent(char c)
/// <param name="uploadGpuResources">Indicate if the GPU resource should be uploaded or not.</param>
/// <param name="auxiliaryScaling">If the requested font size isn't available, the closest one is chosen and an auxiliary scaling is returned</param>
/// <returns>The glyph corresponding to the request or null if not existing</returns>
protected virtual Glyph GetGlyph(CommandList commandList, char character, ref Vector2 fontSize, bool uploadGpuResources, out Vector2 auxiliaryScaling)
protected virtual Glyph GetGlyph(CommandList commandList, char character, in Vector2 fontSize, bool uploadGpuResources, out Vector2 auxiliaryScaling)
{
auxiliaryScaling = new Vector2(1, 1);
return null;
}

private void MeasureStringGlyph(ref Vector2 result, ref Vector2 fontSize, ref Glyph glyph, float x, float y, float nextx, ref Vector2 auxiliaryScaling)
private void MeasureStringGlyph(ref Vector2 result, in Vector2 fontSize, in Glyph glyph, float x, float y, float nextx, ref Vector2 auxiliaryScaling)
{
// TODO Do we need auxiliaryScaling
var h = y + GetTotalLineSpacing(fontSize.Y);
@@ -492,7 +492,7 @@ private void MeasureStringGlyph(ref Vector2 result, ref Vector2 fontSize, ref Gl
}
}

private delegate void GlyphAction<T>(ref T parameters, ref Vector2 fontSize, ref Glyph glyph, float x, float y, float nextx, ref Vector2 auxiliaryScaling);
private delegate void GlyphAction<T>(ref T parameters, in Vector2 fontSize, in Glyph glyph, float x, float y, float nextx, ref Vector2 auxiliaryScaling);

private static int FindCariageReturn(ref StringProxy text, int startIndex)
{
@@ -572,9 +572,9 @@ private void ForGlyph<T>(CommandList commandList, ref StringProxy text, ref Vect
default:
// Output this character.
Vector2 auxiliaryScaling;
var glyph = GetGlyph(commandList, character, ref fontSize, updateGpuResources, out auxiliaryScaling);
var glyph = GetGlyph(commandList, character, in fontSize, updateGpuResources, out auxiliaryScaling);
if (glyph == null && !IgnoreUnkownCharacters && DefaultCharacter.HasValue)
glyph = GetGlyph(commandList, DefaultCharacter.Value, ref fontSize, updateGpuResources, out auxiliaryScaling);
glyph = GetGlyph(commandList, DefaultCharacter.Value, in fontSize, updateGpuResources, out auxiliaryScaling);
if (glyph == null)
continue;

@@ -587,7 +587,7 @@ private void ForGlyph<T>(CommandList commandList, ref StringProxy text, ref Vect
dx += kerningOffset;

float nextX = x + (glyph.XAdvance + GetExtraSpacing(fontSize.X)) * auxiliaryScaling.X;
action(ref parameters, ref fontSize, ref glyph, x + dx * auxiliaryScaling.X, y, nextX, ref auxiliaryScaling);
action(ref parameters, in fontSize, in glyph, x + dx * auxiliaryScaling.X, y, nextX, ref auxiliaryScaling);
x = nextX;
break;
}
@@ -642,7 +642,7 @@ public StringProxy(StringBuilder text, int length)
/// </summary>
internal struct InternalDrawCommand
{
public InternalDrawCommand(SpriteBatch spriteBatch, ref Vector2 fontSize, ref Vector2 position, ref Color4 color, float rotation, ref Vector2 origin, ref Vector2 scale, SpriteEffects spriteEffects, float depth)
public InternalDrawCommand(SpriteBatch spriteBatch, in Vector2 fontSize, in Vector2 position, in Color4 color, float rotation, in Vector2 origin, in Vector2 scale, SpriteEffects spriteEffects, float depth)
{
SpriteBatch = spriteBatch;
Position = position;
@@ -244,9 +244,9 @@ public void DrawRectangle(ref Matrix worldMatrix, ref Vector3 elementSize, ref C
drawInfo.UnitZWorld = worldViewProjection.Row3;
Vector4.Transform(ref vector4LeftTop, ref worldViewProjection, out drawInfo.LeftTopCornerWorld);

var elementInfo = new ElementInfo(4, 6, ref drawInfo, depthBias);
var elementInfo = new ElementInfo(4, 6, in drawInfo, depthBias);

Draw(whiteTexture, ref elementInfo);
Draw(whiteTexture, in elementInfo);
}

/// <summary>
@@ -306,9 +306,9 @@ private void DrawCube(ref Matrix worldMatrix, ref Vector3 elementSize, ref Color
drawInfo.UnitZWorld = worldViewProjection.Row3;
Vector4.Transform(ref vector4LeftTop, ref worldViewProjection, out drawInfo.LeftTopCornerWorld);

var elementInfo = new ElementInfo(8, 6 * 6, ref drawInfo, depthBias);
var elementInfo = new ElementInfo(8, 6 * 6, in drawInfo, depthBias);

Draw(whiteTexture, ref elementInfo);
Draw(whiteTexture, in elementInfo);
}

/// <summary>
@@ -390,12 +390,12 @@ private void DrawCube(ref Matrix worldMatrix, ref Vector3 elementSize, ref Color
indicesPerElement = 54;
}

var elementInfo = new ElementInfo(verticesPerElement, indicesPerElement, ref drawInfo, depthBias);
var elementInfo = new ElementInfo(verticesPerElement, indicesPerElement, in drawInfo, depthBias);

Draw(texture, ref elementInfo);
Draw(texture, in elementInfo);
}

internal void DrawCharacter(Texture texture, ref Matrix worldViewProjectionMatrix, ref RectangleF sourceRectangle, ref Color color, int depthBias, SwizzleMode swizzle)
internal void DrawCharacter(Texture texture, in Matrix worldViewProjectionMatrix, in RectangleF sourceRectangle, in Color color, int depthBias, SwizzleMode swizzle)
{
if (texture == null) throw new ArgumentNullException(nameof(texture));

@@ -420,9 +420,9 @@ internal void DrawCharacter(Texture texture, ref Matrix worldViewProjectionMatri
LeftTopCornerWorld = worldViewProjectionMatrix.Row4,
};

var elementInfo = new ElementInfo(4, 6, ref drawInfo, depthBias);
var elementInfo = new ElementInfo(4, 6, in drawInfo, depthBias);

Draw(texture, ref elementInfo);
Draw(texture, in elementInfo);
}

internal void DrawString(SpriteFont font, string text, ref SpriteFont.InternalUIDrawCommand drawCommand)

0 comments on commit f1513b9

Please sign in to comment.
You can’t perform that action at this time.