Browse Source

Code style

pull/1762/head
Benedikt Schroeder 8 years ago
parent
commit
4d525aac6c
  1. 4
      src/Avalonia.Controls/Remote/RemoteWidget.cs
  2. 10
      src/Avalonia.Controls/RenderOptions.cs
  3. 5
      src/Avalonia.Visuals/Media/DrawingContext.cs
  4. 18
      src/Avalonia.Visuals/Media/Imaging/BitmapScalingMode.cs
  5. 4
      src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs
  6. 6
      src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs
  7. 22
      src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs
  8. 4
      src/Skia/Avalonia.Skia/DrawingContextImpl.cs
  9. 8
      src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs
  10. 4
      tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs
  11. 10
      tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/DrawOperationTests.cs

4
src/Avalonia.Controls/Remote/RemoteWidget.cs

@ -10,6 +10,8 @@ using PixelFormat = Avalonia.Platform.PixelFormat;
namespace Avalonia.Controls.Remote
{
using Avalonia.Visuals.Media.Imaging;
public class RemoteWidget : Control
{
private readonly IAvaloniaRemoteTransportConnection _connection;
@ -76,4 +78,4 @@ namespace Avalonia.Controls.Remote
base.Render(context);
}
}
}
}

10
src/Avalonia.Controls/RenderOptions.cs

@ -1,7 +1,10 @@
namespace Avalonia.Controls
{
using Avalonia.Visuals.Media.Imaging;
// Copyright (c) The Avalonia Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using Avalonia.Visuals.Media.Imaging;
namespace Avalonia.Controls
{
public class RenderOptions
{
/// <summary>
@ -10,7 +13,6 @@
public static readonly StyledProperty<BitmapScalingMode> BitmapScalingModeProperty =
AvaloniaProperty.RegisterAttached<RenderOptions, Control, BitmapScalingMode>(
"BitmapScalingMode",
BitmapScalingMode.LowQuality,
inherits: true);
/// <summary>

5
src/Avalonia.Visuals/Media/DrawingContext.cs

@ -2,11 +2,10 @@ using System;
using System.Collections.Generic;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using Avalonia.Visuals.Media.Imaging;
namespace Avalonia.Media
{
using Avalonia.Visuals.Media.Imaging;
{
public sealed class DrawingContext : IDisposable
{
private int _currentLevel;

18
src/Avalonia.Visuals/Media/Imaging/BitmapScalingMode.cs

@ -3,10 +3,24 @@
namespace Avalonia.Visuals.Media.Imaging
{
/// <summary>
/// Controls the performance and quality of bitmap scaling.
/// </summary>
public enum BitmapScalingMode
{
LowQuality,
/// <summary>
/// Highest quality but worst performance.
/// </summary>
HighQuality,
/// <summary>
/// Good performance an decent image quality.
/// </summary>
MediumQuality,
HighQuality
/// <summary>
/// The best performance but worst image quality.
/// </summary>
LowQuality
}
}

4
src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs

@ -32,8 +32,8 @@ namespace Avalonia.Platform
/// <param name="opacity">The opacity to draw with.</param>
/// <param name="sourceRect">The rect in the image to draw.</param>
/// <param name="destRect">The rect in the output to draw to.</param>
/// <param name="scalingMode">Controls</param>
void DrawImage(IRef<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapScalingMode scalingMode = default);
/// <param name="bitmapScalingMode">Controls</param>
void DrawImage(IRef<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapScalingMode bitmapScalingMode = default);
/// <summary>
/// Draws a bitmap image.

6
src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs

@ -116,13 +116,13 @@ namespace Avalonia.Rendering.SceneGraph
}
/// <inheritdoc/>
public void DrawImage(IRef<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapScalingMode scalingMode = BitmapScalingMode.LowQuality)
public void DrawImage(IRef<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapScalingMode bitmapScalingMode)
{
var next = NextDrawAs<ImageNode>();
if (next == null || !next.Item.Equals(Transform, source, opacity, sourceRect, destRect, scalingMode))
if (next == null || !next.Item.Equals(Transform, source, opacity, sourceRect, destRect, bitmapScalingMode))
{
Add(new ImageNode(Transform, source, opacity, sourceRect, destRect, scalingMode));
Add(new ImageNode(Transform, source, opacity, sourceRect, destRect, bitmapScalingMode));
}
else
{

22
src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs

@ -22,8 +22,8 @@ namespace Avalonia.Rendering.SceneGraph
/// <param name="opacity">The draw opacity.</param>
/// <param name="sourceRect">The source rect.</param>
/// <param name="destRect">The destination rect.</param>
/// <param name="scalingMode"></param>
public ImageNode(Matrix transform, IRef<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapScalingMode scalingMode)
/// <param name="bitmapScalingMode">The bitmap scaling mode.</param>
public ImageNode(Matrix transform, IRef<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapScalingMode bitmapScalingMode)
: base(destRect, transform, null)
{
Transform = transform;
@ -31,10 +31,8 @@ namespace Avalonia.Rendering.SceneGraph
Opacity = opacity;
SourceRect = sourceRect;
DestRect = destRect;
ScalingMode = scalingMode;
}
BitmapScalingMode = bitmapScalingMode;
}
/// <summary>
/// Gets the transform with which the node will be drawn.
@ -62,12 +60,12 @@ namespace Avalonia.Rendering.SceneGraph
public Rect DestRect { get; }
/// <summary>
/// Gets or sets the scaling mode.
/// Gets the bitmap scaling mode.
/// </summary>
/// <value>
/// The scaling mode.
/// </value>
public BitmapScalingMode ScalingMode { get; }
public BitmapScalingMode BitmapScalingMode { get; }
/// <summary>
/// Determines if this draw operation equals another.
@ -77,20 +75,20 @@ namespace Avalonia.Rendering.SceneGraph
/// <param name="opacity">The opacity of the other draw operation.</param>
/// <param name="sourceRect">The source rect of the other draw operation.</param>
/// <param name="destRect">The dest rect of the other draw operation.</param>
/// <param name="scalingMode"></param>
/// <param name="bitmapScalingMode"></param>
/// <returns>True if the draw operations are the same, otherwise false.</returns>
/// <remarks>
/// The properties of the other draw operation are passed in as arguments to prevent
/// allocation of a not-yet-constructed draw operation object.
/// </remarks>
public bool Equals(Matrix transform, IRef<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapScalingMode scalingMode)
public bool Equals(Matrix transform, IRef<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapScalingMode bitmapScalingMode)
{
return transform == Transform &&
Equals(source.Item, Source.Item) &&
opacity == Opacity &&
sourceRect == SourceRect &&
destRect == DestRect &&
scalingMode == ScalingMode;
bitmapScalingMode == BitmapScalingMode;
}
/// <inheritdoc/>
@ -99,7 +97,7 @@ namespace Avalonia.Rendering.SceneGraph
// TODO: Probably need to introduce some kind of locking mechanism in the case of
// WriteableBitmap.
context.Transform = Transform;
context.DrawImage(Source, Opacity, SourceRect, DestRect, ScalingMode);
context.DrawImage(Source, Opacity, SourceRect, DestRect, BitmapScalingMode);
}
/// <inheritdoc/>

4
src/Skia/Avalonia.Skia/DrawingContextImpl.cs

@ -97,7 +97,7 @@ namespace Avalonia.Skia
}
/// <inheritdoc />
public void DrawImage(IRef<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapScalingMode scalingMode)
public void DrawImage(IRef<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapScalingMode bitmapScalingMode)
{
var drawableImage = (IDrawableBitmapImpl)source.Item;
var s = sourceRect.ToSKRect();
@ -109,7 +109,7 @@ namespace Avalonia.Skia
Color = new SKColor(255, 255, 255, (byte)(255 * opacity * _currentOpacity))
})
{
paint.FilterQuality = GetInterpolationMode(scalingMode);
paint.FilterQuality = GetInterpolationMode(bitmapScalingMode);
drawableImage.Draw(this, s, d, paint);
}

8
src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs

@ -102,18 +102,18 @@ namespace Avalonia.Direct2D1.Media
/// <param name="opacity">The opacity to draw with.</param>
/// <param name="sourceRect">The rect in the image to draw.</param>
/// <param name="destRect">The rect in the output to draw to.</param>
/// <param name="scalingMode"></param>
public void DrawImage(IRef<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapScalingMode scalingMode)
/// <param name="bitmapScalingMode"></param>
public void DrawImage(IRef<IBitmapImpl> source, double opacity, Rect sourceRect, Rect destRect, BitmapScalingMode bitmapScalingMode)
{
using (var d2d = ((BitmapImpl)source.Item).GetDirect2DBitmap(_renderTarget))
{
if (_renderTarget is DeviceContext deviceContext)
{
deviceContext.DrawBitmap(d2d.Value, destRect.ToDirect2D(), (float)opacity, GetInterpolationMode(scalingMode), sourceRect.ToDirect2D(), null);
deviceContext.DrawBitmap(d2d.Value, destRect.ToDirect2D(), (float)opacity, GetInterpolationMode(bitmapScalingMode), sourceRect.ToDirect2D(), null);
}
else
{
var interpolationMode = scalingMode == BitmapScalingMode.LowQuality
var interpolationMode = bitmapScalingMode == BitmapScalingMode.LowQuality
? BitmapInterpolationMode.NearestNeighbor
: BitmapInterpolationMode.Linear;

4
tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs

@ -16,6 +16,8 @@ using Xunit;
namespace Avalonia.Visuals.UnitTests.Rendering
{
using Avalonia.Visuals.Media.Imaging;
public class DeferredRendererTests
{
[Fact]
@ -336,7 +338,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering
var context = Mock.Get(target.RenderTarget.CreateDrawingContext(null));
var borderLayer = target.Layers[border].Bitmap;
context.Verify(x => x.DrawImage(borderLayer, 0.5, It.IsAny<Rect>(), It.IsAny<Rect>()));
context.Verify(x => x.DrawImage(borderLayer, 0.5, It.IsAny<Rect>(), It.IsAny<Rect>(), default(BitmapScalingMode)));
}
private DeferredRenderer CreateTargetAndRunFrame(

10
tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/DrawOperationTests.cs

@ -8,6 +8,8 @@ using Xunit;
namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
{
using Avalonia.Visuals.Media.Imaging;
public class DrawOperationTests
{
[Fact]
@ -46,7 +48,13 @@ namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
public void Image_Node_Releases_Reference_To_Bitmap_On_Dispose()
{
var bitmap = RefCountable.Create(Mock.Of<IBitmapImpl>());
var imageNode = new ImageNode(Matrix.Identity, bitmap, 1, new Rect(1,1,1,1), new Rect(1,1,1,1));
var imageNode = new ImageNode(
Matrix.Identity,
bitmap,
1,
new Rect(1, 1, 1, 1),
new Rect(1, 1, 1, 1),
BitmapScalingMode.LowQuality);
Assert.Equal(2, bitmap.RefCount);

Loading…
Cancel
Save