|
@@ -30,7 +30,6 @@ namespace Avalonia.Visuals.UnitTests.Rendering
|
|
|
root,
|
|
root,
|
|
|
loop.Object,
|
|
loop.Object,
|
|
|
sceneBuilder: MockSceneBuilder(root).Object,
|
|
sceneBuilder: MockSceneBuilder(root).Object,
|
|
|
- layerFactory: MockLayerFactory(root).Object,
|
|
|
|
|
dispatcher: dispatcher.Object);
|
|
dispatcher: dispatcher.Object);
|
|
|
|
|
|
|
|
target.Start();
|
|
target.Start();
|
|
@@ -55,7 +54,6 @@ namespace Avalonia.Visuals.UnitTests.Rendering
|
|
|
root,
|
|
root,
|
|
|
loop.Object,
|
|
loop.Object,
|
|
|
sceneBuilder: sceneBuilder.Object,
|
|
sceneBuilder: sceneBuilder.Object,
|
|
|
- layerFactory: MockLayerFactory(root).Object,
|
|
|
|
|
dispatcher: dispatcher);
|
|
dispatcher: dispatcher);
|
|
|
|
|
|
|
|
target.Start();
|
|
target.Start();
|
|
@@ -75,7 +73,6 @@ namespace Avalonia.Visuals.UnitTests.Rendering
|
|
|
root,
|
|
root,
|
|
|
loop.Object,
|
|
loop.Object,
|
|
|
sceneBuilder: sceneBuilder.Object,
|
|
sceneBuilder: sceneBuilder.Object,
|
|
|
- layerFactory: MockLayerFactory(root).Object,
|
|
|
|
|
dispatcher: dispatcher);
|
|
dispatcher: dispatcher);
|
|
|
|
|
|
|
|
target.Start();
|
|
target.Start();
|
|
@@ -111,7 +108,6 @@ namespace Avalonia.Visuals.UnitTests.Rendering
|
|
|
root,
|
|
root,
|
|
|
loop.Object,
|
|
loop.Object,
|
|
|
sceneBuilder: sceneBuilder.Object,
|
|
sceneBuilder: sceneBuilder.Object,
|
|
|
- layerFactory: MockLayerFactory(root).Object,
|
|
|
|
|
dispatcher: dispatcher);
|
|
dispatcher: dispatcher);
|
|
|
|
|
|
|
|
target.Start();
|
|
target.Start();
|
|
@@ -133,100 +129,102 @@ namespace Avalonia.Visuals.UnitTests.Rendering
|
|
|
[Fact]
|
|
[Fact]
|
|
|
public void Frame_Should_Create_Layer_For_Root()
|
|
public void Frame_Should_Create_Layer_For_Root()
|
|
|
{
|
|
{
|
|
|
- var loop = new Mock<IRenderLoop>();
|
|
|
|
|
- var root = new TestRoot();
|
|
|
|
|
- var rootLayer = new Mock<IRenderTargetBitmapImpl>();
|
|
|
|
|
- var dispatcher = new ImmediateDispatcher();
|
|
|
|
|
-
|
|
|
|
|
- var sceneBuilder = new Mock<ISceneBuilder>();
|
|
|
|
|
- sceneBuilder.Setup(x => x.UpdateAll(It.IsAny<Scene>()))
|
|
|
|
|
- .Callback<Scene>(scene =>
|
|
|
|
|
- {
|
|
|
|
|
- scene.Size = root.ClientSize;
|
|
|
|
|
- scene.Layers.Add(root).Dirty.Add(new Rect(root.ClientSize));
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- var layers = new Mock<IRenderLayerFactory>();
|
|
|
|
|
- layers.Setup(x => x.CreateLayer(root, root.ClientSize, 96, 96)).Returns(CreateLayer());
|
|
|
|
|
-
|
|
|
|
|
- var renderInterface = new Mock<IPlatformRenderInterface>();
|
|
|
|
|
-
|
|
|
|
|
- var target = new DeferredRenderer(
|
|
|
|
|
- root,
|
|
|
|
|
- loop.Object,
|
|
|
|
|
- sceneBuilder: sceneBuilder.Object,
|
|
|
|
|
- layerFactory: layers.Object,
|
|
|
|
|
- dispatcher: dispatcher);
|
|
|
|
|
-
|
|
|
|
|
- target.Start();
|
|
|
|
|
- RunFrame(loop);
|
|
|
|
|
-
|
|
|
|
|
- layers.Verify(x => x.CreateLayer(root, root.ClientSize, 96, 96));
|
|
|
|
|
|
|
+ throw new NotImplementedException();
|
|
|
|
|
+ //var loop = new Mock<IRenderLoop>();
|
|
|
|
|
+ //var root = new TestRoot();
|
|
|
|
|
+ //var rootLayer = new Mock<IRenderTargetBitmapImpl>();
|
|
|
|
|
+ //var dispatcher = new ImmediateDispatcher();
|
|
|
|
|
+
|
|
|
|
|
+ //var sceneBuilder = new Mock<ISceneBuilder>();
|
|
|
|
|
+ //sceneBuilder.Setup(x => x.UpdateAll(It.IsAny<Scene>()))
|
|
|
|
|
+ // .Callback<Scene>(scene =>
|
|
|
|
|
+ // {
|
|
|
|
|
+ // scene.Size = root.ClientSize;
|
|
|
|
|
+ // scene.Layers.Add(root).Dirty.Add(new Rect(root.ClientSize));
|
|
|
|
|
+ // });
|
|
|
|
|
+
|
|
|
|
|
+ //var layers = new Mock<IRenderLayerFactory>();
|
|
|
|
|
+ //layers.Setup(x => x.CreateLayer(root, root.ClientSize, 96, 96)).Returns(CreateLayer());
|
|
|
|
|
+
|
|
|
|
|
+ //var renderInterface = new Mock<IPlatformRenderInterface>();
|
|
|
|
|
+
|
|
|
|
|
+ //var target = new DeferredRenderer(
|
|
|
|
|
+ // root,
|
|
|
|
|
+ // loop.Object,
|
|
|
|
|
+ // sceneBuilder: sceneBuilder.Object,
|
|
|
|
|
+ // layerFactory: layers.Object,
|
|
|
|
|
+ // dispatcher: dispatcher);
|
|
|
|
|
+
|
|
|
|
|
+ //target.Start();
|
|
|
|
|
+ //RunFrame(loop);
|
|
|
|
|
+
|
|
|
|
|
+ //layers.Verify(x => x.CreateLayer(root, root.ClientSize, 96, 96));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
[Fact]
|
|
|
public void Should_Create_And_Delete_Layers_For_Transparent_Controls()
|
|
public void Should_Create_And_Delete_Layers_For_Transparent_Controls()
|
|
|
{
|
|
{
|
|
|
- Border border;
|
|
|
|
|
- var root = new TestRoot
|
|
|
|
|
- {
|
|
|
|
|
- Width = 100,
|
|
|
|
|
- Height = 100,
|
|
|
|
|
- Child = new Border
|
|
|
|
|
- {
|
|
|
|
|
- Background = Brushes.Red,
|
|
|
|
|
- Child = border = new Border
|
|
|
|
|
- {
|
|
|
|
|
- Background = Brushes.Green,
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- root.Measure(Size.Infinity);
|
|
|
|
|
- root.Arrange(new Rect(root.DesiredSize));
|
|
|
|
|
-
|
|
|
|
|
- var loop = new Mock<IRenderLoop>();
|
|
|
|
|
- var layerFactory = new MockRenderLayerFactory(new Dictionary<IVisual, IRenderTargetBitmapImpl>
|
|
|
|
|
- {
|
|
|
|
|
- { root, CreateLayer() },
|
|
|
|
|
- { border, CreateLayer() },
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- var target = new DeferredRenderer(
|
|
|
|
|
- root,
|
|
|
|
|
- loop.Object,
|
|
|
|
|
- layerFactory: layerFactory,
|
|
|
|
|
- dispatcher: new ImmediateDispatcher());
|
|
|
|
|
- root.Renderer = target;
|
|
|
|
|
-
|
|
|
|
|
- target.Start();
|
|
|
|
|
- RunFrame(loop);
|
|
|
|
|
-
|
|
|
|
|
- var rootContext = layerFactory.GetMockDrawingContext(root);
|
|
|
|
|
- var borderContext = layerFactory.GetMockDrawingContext(border);
|
|
|
|
|
-
|
|
|
|
|
- rootContext.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
|
|
|
|
|
- rootContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Once);
|
|
|
|
|
- borderContext.Verify(x => x.FillRectangle(It.IsAny<IBrush>(), It.IsAny<Rect>(), It.IsAny<float>()), Times.Never);
|
|
|
|
|
-
|
|
|
|
|
- rootContext.ResetCalls();
|
|
|
|
|
- borderContext.ResetCalls();
|
|
|
|
|
- border.Opacity = 0.5;
|
|
|
|
|
- RunFrame(loop);
|
|
|
|
|
-
|
|
|
|
|
- rootContext.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
|
|
|
|
|
- rootContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Never);
|
|
|
|
|
- borderContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Once);
|
|
|
|
|
-
|
|
|
|
|
- rootContext.ResetCalls();
|
|
|
|
|
- borderContext.ResetCalls();
|
|
|
|
|
- border.Opacity = 1;
|
|
|
|
|
- RunFrame(loop);
|
|
|
|
|
-
|
|
|
|
|
- layerFactory.GetMockBitmap(border).Verify(x => x.Dispose());
|
|
|
|
|
- rootContext.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
|
|
|
|
|
- rootContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Once);
|
|
|
|
|
- borderContext.Verify(x => x.FillRectangle(It.IsAny<IBrush>(), It.IsAny<Rect>(), It.IsAny<float>()), Times.Never);
|
|
|
|
|
|
|
+ throw new NotImplementedException();
|
|
|
|
|
+ //Border border;
|
|
|
|
|
+ //var root = new TestRoot
|
|
|
|
|
+ //{
|
|
|
|
|
+ // Width = 100,
|
|
|
|
|
+ // Height = 100,
|
|
|
|
|
+ // Child = new Border
|
|
|
|
|
+ // {
|
|
|
|
|
+ // Background = Brushes.Red,
|
|
|
|
|
+ // Child = border = new Border
|
|
|
|
|
+ // {
|
|
|
|
|
+ // Background = Brushes.Green,
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
+ //};
|
|
|
|
|
+
|
|
|
|
|
+ //root.Measure(Size.Infinity);
|
|
|
|
|
+ //root.Arrange(new Rect(root.DesiredSize));
|
|
|
|
|
+
|
|
|
|
|
+ //var loop = new Mock<IRenderLoop>();
|
|
|
|
|
+ //var layerFactory = new MockRenderLayerFactory(new Dictionary<IVisual, IRenderTargetBitmapImpl>
|
|
|
|
|
+ //{
|
|
|
|
|
+ // { root, CreateLayer() },
|
|
|
|
|
+ // { border, CreateLayer() },
|
|
|
|
|
+ //});
|
|
|
|
|
+
|
|
|
|
|
+ //var target = new DeferredRenderer(
|
|
|
|
|
+ // root,
|
|
|
|
|
+ // loop.Object,
|
|
|
|
|
+ // layerFactory: layerFactory,
|
|
|
|
|
+ // dispatcher: new ImmediateDispatcher());
|
|
|
|
|
+ //root.Renderer = target;
|
|
|
|
|
+
|
|
|
|
|
+ //target.Start();
|
|
|
|
|
+ //RunFrame(loop);
|
|
|
|
|
+
|
|
|
|
|
+ //var rootContext = layerFactory.GetMockDrawingContext(root);
|
|
|
|
|
+ //var borderContext = layerFactory.GetMockDrawingContext(border);
|
|
|
|
|
+
|
|
|
|
|
+ //rootContext.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
|
|
|
|
|
+ //rootContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Once);
|
|
|
|
|
+ //borderContext.Verify(x => x.FillRectangle(It.IsAny<IBrush>(), It.IsAny<Rect>(), It.IsAny<float>()), Times.Never);
|
|
|
|
|
+
|
|
|
|
|
+ //rootContext.ResetCalls();
|
|
|
|
|
+ //borderContext.ResetCalls();
|
|
|
|
|
+ //border.Opacity = 0.5;
|
|
|
|
|
+ //RunFrame(loop);
|
|
|
|
|
+
|
|
|
|
|
+ //rootContext.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
|
|
|
|
|
+ //rootContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Never);
|
|
|
|
|
+ //borderContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Once);
|
|
|
|
|
+
|
|
|
|
|
+ //rootContext.ResetCalls();
|
|
|
|
|
+ //borderContext.ResetCalls();
|
|
|
|
|
+ //border.Opacity = 1;
|
|
|
|
|
+ //RunFrame(loop);
|
|
|
|
|
+
|
|
|
|
|
+ //layerFactory.GetMockBitmap(border).Verify(x => x.Dispose());
|
|
|
|
|
+ //rootContext.Verify(x => x.FillRectangle(Brushes.Red, new Rect(0, 0, 100, 100), 0), Times.Once);
|
|
|
|
|
+ //rootContext.Verify(x => x.FillRectangle(Brushes.Green, new Rect(0, 0, 100, 100), 0), Times.Once);
|
|
|
|
|
+ //borderContext.Verify(x => x.FillRectangle(It.IsAny<IBrush>(), It.IsAny<Rect>(), It.IsAny<float>()), Times.Never);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void IgnoreFirstFrame(Mock<IRenderLoop> loop, Mock<ISceneBuilder> sceneBuilder)
|
|
private void IgnoreFirstFrame(Mock<IRenderLoop> loop, Mock<ISceneBuilder> sceneBuilder)
|
|
@@ -246,13 +244,6 @@ namespace Avalonia.Visuals.UnitTests.Rendering
|
|
|
x.CreateDrawingContext(It.IsAny<IVisualBrushRenderer>()) == Mock.Of<IDrawingContextImpl>());
|
|
x.CreateDrawingContext(It.IsAny<IVisualBrushRenderer>()) == Mock.Of<IDrawingContextImpl>());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private Mock<IRenderLayerFactory> MockLayerFactory(IRenderRoot root)
|
|
|
|
|
- {
|
|
|
|
|
- var result = new Mock<IRenderLayerFactory>();
|
|
|
|
|
- result.Setup(x => x.CreateLayer(root, root.ClientSize, 96, 96)).Returns(CreateLayer());
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
private Mock<ISceneBuilder> MockSceneBuilder(IRenderRoot root)
|
|
private Mock<ISceneBuilder> MockSceneBuilder(IRenderRoot root)
|
|
|
{
|
|
{
|
|
|
var result = new Mock<ISceneBuilder>();
|
|
var result = new Mock<ISceneBuilder>();
|
|
@@ -260,34 +251,5 @@ namespace Avalonia.Visuals.UnitTests.Rendering
|
|
|
.Callback<Scene>(x => x.Layers.Add(root).Dirty.Add(new Rect(root.ClientSize)));
|
|
.Callback<Scene>(x => x.Layers.Add(root).Dirty.Add(new Rect(root.ClientSize)));
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- private class MockRenderLayerFactory : IRenderLayerFactory
|
|
|
|
|
- {
|
|
|
|
|
- private IDictionary<IVisual, IRenderTargetBitmapImpl> _layers;
|
|
|
|
|
-
|
|
|
|
|
- public MockRenderLayerFactory(IDictionary<IVisual, IRenderTargetBitmapImpl> layers)
|
|
|
|
|
- {
|
|
|
|
|
- _layers = layers;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public IRenderTargetBitmapImpl CreateLayer(
|
|
|
|
|
- IVisual layerRoot,
|
|
|
|
|
- Size size,
|
|
|
|
|
- double dpiX,
|
|
|
|
|
- double dpiY)
|
|
|
|
|
- {
|
|
|
|
|
- return _layers[layerRoot];
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public Mock<IRenderTargetBitmapImpl> GetMockBitmap(IVisual layerRoot)
|
|
|
|
|
- {
|
|
|
|
|
- return Mock.Get(_layers[layerRoot]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public Mock<IDrawingContextImpl> GetMockDrawingContext(IVisual layerRoot)
|
|
|
|
|
- {
|
|
|
|
|
- return Mock.Get(_layers[layerRoot].CreateDrawingContext(null));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|