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 renderInterface = new Mock <IPlatformRenderInterface>(); var target = new DeferredRenderer( root, loop.Object, sceneBuilder: sceneBuilder.Object, //layerFactory: layers.Object, dispatcher: dispatcher); target.Start(); RunFrame(loop); var context = Mock.Get(root.CreateRenderTarget().CreateDrawingContext(null)); context.Verify(x => x.CreateLayer(root.ClientSize)); }
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 rootLayer = CreateLayer(); var borderLayer = CreateLayer(); var renderTargetContext = Mock.Get(root.CreateRenderTarget().CreateDrawingContext(null)); renderTargetContext.SetupSequence(x => x.CreateLayer(It.IsAny <Size>())) .Returns(rootLayer) .Returns(borderLayer); var loop = new Mock <IRenderLoop>(); var target = new DeferredRenderer( root, loop.Object, dispatcher: new ImmediateDispatcher()); root.Renderer = target; target.Start(); RunFrame(loop); var rootContext = Mock.Get(rootLayer.CreateDrawingContext(null)); var borderContext = Mock.Get(borderLayer.CreateDrawingContext(null)); 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); Mock.Get(borderLayer).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); }