public void Render(IDrawingContextImpl context) { var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas; if (canvas != null) { if (_images?.Any() == true) { canvas.Clear(SKColor.Parse("#f0f0f0")); // draw stuff int startx = 0; int starty = 0; try { foreach (var img in _images) { canvas.DrawImage(img, startx, starty, _paintQuality); starty += img.Height; } } catch { // failed to render, collection may be modified } } } }
public void Render(IDrawingContextImpl context) { if (Pages.Count <= 0) { return; } LimitScale(); LimitTranslate(); var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas; if (canvas == null) { throw new InvalidOperationException($"Context needs to be ISkiaDrawingContextImpl but got {nameof(context)}"); } var originalMatrix = canvas.TotalMatrix; canvas.Translate(Width / 2, 0); canvas.Scale(Scale); canvas.Translate(TranslateX, -TranslateY + SafeZone / Scale); foreach (var page in Pages) { canvas.Translate(-page.Width / 2f, 0); DrawBlankPage(canvas, page.Width, page.Height); canvas.DrawPicture(page.Picture); canvas.Translate(page.Width / 2f, page.Height + PageSpacing); } canvas.SetMatrix(originalMatrix); DrawInnerGradient(canvas); }
private void Render(IDrawingContextImpl context, VisualNode node, IVisual layer, Rect clipBounds) { if (layer == null || node.LayerRoot == layer) { clipBounds = node.ClipBounds.Intersect(clipBounds); if (!clipBounds.IsEmpty && node.Opacity > 0) { var isLayerRoot = node.Visual == layer; node.BeginRender(context, isLayerRoot); var drawOperations = node.DrawOperations; var drawOperationsCount = drawOperations.Count; for (int i = 0; i < drawOperationsCount; i++) { var operation = drawOperations[i]; _currentDraw = operation; operation.Item.Render(context); _currentDraw = null; } var children = node.Children; var childrenCount = children.Count; for (int i = 0; i < childrenCount; i++) { var child = children[i]; Render(context, (VisualNode)child, layer, clipBounds); } node.EndRender(context, isLayerRoot); } } }
public void Render(IDrawingContextImpl context) { if (context is ISkiaDrawingContextImpl skia) { Parent.Chart?.Draw(skia.SkCanvas, (int)Parent.Bounds.Width, (int)Parent.Bounds.Height); } }
/// <inheritdoc/> public void BeginRender(IDrawingContextImpl context, bool skipOpacity) { transformRestore = context.Transform; if (ClipToBounds) { context.Transform = Matrix.Identity; context.PushClip(ClipBounds); } context.Transform = Transform; if (Opacity != 1 && !skipOpacity) { context.PushOpacity(Opacity); } if (GeometryClip != null) { context.PushGeometryClip(GeometryClip); } if (OpacityMask != null) { context.PushOpacityMask(OpacityMask, ClipBounds); } }
protected void RenderFps(IDrawingContextImpl context, Rect clientRect, int?layerCount) { var now = _stopwatch.Elapsed; var elapsed = now - _lastFpsUpdate; ++_framesThisSecond; if (elapsed.TotalSeconds > 1) { _fps = (int)(_framesThisSecond / elapsed.TotalSeconds); _framesThisSecond = 0; _lastFpsUpdate = now; } if (layerCount.HasValue) { _fpsText.Text = string.Format("Layers: {0} FPS: {1:000}", layerCount, _fps); } else { _fpsText.Text = string.Format("FPS: {0:000}", _fps); } var size = _fpsText.Bounds.Size; var rect = new Rect(clientRect.Right - size.Width, 0, size.Width, size.Height); context.Transform = Matrix.Identity; context.DrawRectangle(Brushes.Black, null, rect); context.DrawText(Brushes.White, rect.TopLeft, _fpsText.PlatformImpl); }
/// <inheritdoc/> public void EndRender(IDrawingContextImpl context, bool skipOpacity) { if (OpacityMask != null) { context.PopOpacityMask(); } if (GeometryClip != null) { context.PopGeometryClip(); } if (Opacity != 1 && !skipOpacity) { context.PopOpacity(); } if (ClipToBounds) { context.Transform = Matrix.Identity; context.PopClip(); } context.Transform = transformRestore; }
public override void Render(IDrawingContextImpl drw_context) { if (drw_context is ISkiaDrawingContextImpl context) { var canvas = context.SkCanvas; canvas.Save(); var info = new SKImageInfo((int)Bounds.Width, (int)Bounds.Height); var s_r = stroke / 2; SKRect rect = new SKRect(s_r, s_r, info.Height - s_r, info.Width - s_r); using (var paint = new SKPaint()) { paint.Shader = SKShader.CreateColor(StrokeColor.ToSKColor()); paint.Style = SKPaintStyle.Stroke; paint.StrokeWidth = stroke; paint.IsAntialias = true; paint.Color = StrokeColor.ToSKColor(); canvas.DrawArc(rect, _angle1, _angle2, false, paint); } canvas.Restore(); Debug.WriteLine(StrokeColor.ToString()); Debug.WriteLine("Arc rendered"); } }
protected void RenderFps(IDrawingContextImpl context, Rect clientRect, bool incrementFrameCount) { var now = _stopwatch.Elapsed; var elapsed = now - _lastFpsUpdate; if (incrementFrameCount) { ++_framesThisSecond; } if (elapsed.TotalSeconds > 1) { _fps = (int)(_framesThisSecond / elapsed.TotalSeconds); _framesThisSecond = 0; _lastFpsUpdate = now; } _fpsText.Text = string.Format("FPS: {0:000}", _fps); var size = _fpsText.Measure(); var rect = new Rect(clientRect.Right - size.Width, 0, size.Width, size.Height); context.Transform = Matrix.Identity; context.FillRectangle(Brushes.Black, rect); context.DrawText(Brushes.White, rect.TopLeft, _fpsText.PlatformImpl); }
public void Update(Scene scene, IDrawingContextImpl context) { for (var i = scene.Layers.Count - 1; i >= 0; --i) { var src = scene.Layers[i]; if (!_index.TryGetValue(src.LayerRoot, out var layer)) { layer = new RenderLayer(context, scene.Size, scene.Scaling, src.LayerRoot); _inner.Add(layer); _index.Add(src.LayerRoot, layer); } else { layer.RecreateBitmap(context, scene.Size, scene.Scaling); } } for (var i = 0; i < _inner.Count;) { var layer = _inner[i]; if (!scene.Layers.Exists(layer.LayerRoot)) { layer.Bitmap.Dispose(); _inner.RemoveAt(i); _index.Remove(layer.LayerRoot); } else { i++; } } }
/// <inheritdoc/> public override void Draw(IDrawingContextImpl drawingContext, Point origin) { if (GlyphRun.GlyphIndices.Length == 0) { return; } if (Style.TextFormat.Typeface == null) { return; } if (Style.Foreground == null) { return; } drawingContext.DrawGlyphRun(Style.Foreground, GlyphRun, origin); if (Style.TextDecorations == null) { return; } foreach (var textDecoration in Style.TextDecorations) { DrawTextDecoration(drawingContext, textDecoration, origin); } }
public void Render(IDrawingContextImpl context) { var finalRenderSurface = context.CreateLayer(_destRect.Size); if (finalRenderSurface is null) { context.Clear(Colors.Aqua); return; } using (var renderSurfaceCtx = finalRenderSurface.CreateDrawingContext(null)) { using (_lottieCanvas.CreateSession(_destRect.Size, finalRenderSurface, new DrawingContext(renderSurfaceCtx))) { _compositionLayer.Draw(_lottieCanvas, _matrix, 255); } } context.DrawBitmap(RefCountable.Create(finalRenderSurface), 1, new Rect(new Point(), finalRenderSurface.PixelSize.ToSize(1)), _destRect); finalRenderSurface.Dispose(); }
public void Render(IDrawingContextImpl context) { var eglSurface = _eglInterop.CreateEglSurface(); var textureHandle = _eglInterop.BindTexture(eglSurface); var grContext = (context as ISkiaDrawingContextImpl).GrContext; var desc = new GRBackendTextureDesc { TextureHandle = new IntPtr(textureHandle), Config = GRPixelConfig.Rgba8888, Height = 600, Width = 800, Origin = GRSurfaceOrigin.TopLeft }; using (var texture = new GRBackendTexture(600, 800, false, new GRGlTextureInfo(GlConsts.GL_TEXTURE_2D, textureHandle, GlConsts.GL_RGBA8))) { using (var surface = SKSurface.Create(grContext, texture, SKColorType.Rgba8888)) { var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas; canvas.DrawSurface(surface, new SKPoint(10, 10)); } } }
private void Render(Scene scene) { bool renderOverlay = DrawDirtyRects || DrawFps; bool composite = false; if (RenderTarget == null) { RenderTarget = ((IRenderRoot)_root).CreateRenderTarget(); } if (renderOverlay) { _dirtyRectsDisplay.Tick(); } try { if (scene != null && scene.Size != Size.Empty) { IDrawingContextImpl context = null; if (scene.Generation != _lastSceneId) { context = RenderTarget.CreateDrawingContext(this); Layers.Update(scene, context); RenderToLayers(scene); if (DebugFramesPath != null) { SaveDebugFrames(scene.Generation); } _lastSceneId = scene.Generation; composite = true; } if (renderOverlay) { context = context ?? RenderTarget.CreateDrawingContext(this); RenderOverlay(scene, context); RenderComposite(scene, context); } else if (composite) { context = context ?? RenderTarget.CreateDrawingContext(this); RenderComposite(scene, context); } context?.Dispose(); } } catch (RenderTargetCorruptedException ex) { Logging.Logger.Information("Renderer", this, "Render target was corrupted. Exception: {0}", ex); RenderTarget?.Dispose(); RenderTarget = null; } }
/// <inheritdoc/> public void BeginRender(IDrawingContextImpl context, bool skipOpacity) { transformRestore = context.Transform; if (ClipToBounds) { context.Transform = Matrix.Identity; if (ClipToBoundsRadius.IsEmpty) { context.PushClip(ClipBounds); } else { context.PushClip(new RoundedRect(ClipBounds, ClipToBoundsRadius)); } } context.Transform = Transform; if (Opacity != 1 && !skipOpacity) { context.PushOpacity(Opacity); } if (GeometryClip != null) { context.PushGeometryClip(GeometryClip); } if (OpacityMask != null) { context.PushOpacityMask(OpacityMask, LayoutBounds); } }
/// <inheritdoc/> public override void Render(IDrawingContextImpl context) { // TODO: Probably need to introduce some kind of locking mechanism in the case of // WriteableBitmap. context.Transform = Transform; context.DrawImage(Source, Opacity, SourceRect, DestRect, BitmapInterpolationMode); }
public override void Render(IDrawingContextImpl drw_context) { base.Render(drw_context); if (drw_context is ISkiaDrawingContextImpl context) { var canvas = context.SkCanvas; if (_data == null) { return; } using (var bitmap = SKBitmap.Decode(_data.ToArray())) using (var paint = new SKPaint()) { if (bitmap == null) { Debug.WriteLine("bitmap is null"); return; } var img = SKImage.FromBitmap(bitmap); paint.ImageFilter = SKImageFilter.CreateBlur(_levelx, _levely); canvas.DrawImage(img, _dest.ToSKRect(), Bounds.ToSKRect(), paint); } } }
private void Render(IDrawingContextImpl context, VisualNode node, IVisual layer, Rect clipBounds) { if (layer == null || node.LayerRoot == layer) { clipBounds = node.ClipBounds.Intersect(clipBounds); if (!clipBounds.IsEmpty && node.Opacity > 0) { var isLayerRoot = node.Visual == layer; node.BeginRender(context, isLayerRoot); foreach (var operation in node.DrawOperations) { _currentDraw = operation; operation.Item.Render(context); _currentDraw = null; } foreach (var child in node.Children) { Render(context, (VisualNode)child, layer, clipBounds); } node.EndRender(context, isLayerRoot); } } }
private void Render(bool forceComposite) { using (var l = _lock.TryLock()) { if (l == null) { return; } IDrawingContextImpl context = null; try { try { var(scene, updated) = UpdateRenderLayersAndConsumeSceneIfNeeded(ref context); if (updated) { FpsTick(); } using (scene) { if (scene?.Item != null) { try { var overlay = DrawDirtyRects || DrawFps; if (DrawDirtyRects) { _dirtyRectsDisplay.Tick(); } if (overlay) { RenderOverlay(scene.Item, ref context); } if (updated || forceComposite || overlay) { RenderComposite(scene.Item, ref context); } } finally { scene.Item.MarkAsRendered(); } } } } finally { context?.Dispose(); } } catch (RenderTargetCorruptedException ex) { Logger.TryGet(LogEventLevel.Information, LogArea.Animations)?.Log(this, "Render target was corrupted. Exception: {0}", ex); RenderTarget?.Dispose(); RenderTarget = null; } } }
public void Render(IDrawingContextImpl context) { var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas; if (canvas == null) { using (var c = new DrawingContext(context, false)) { c.DrawText(_noSkia, new Point()); } } else { canvas.Save(); // create the first shader var colors = new SKColor[] { new SKColor(0, 255, 255), new SKColor(255, 0, 255), new SKColor(255, 255, 0), new SKColor(0, 255, 255) }; var sx = Animate(100, 2, 10); var sy = Animate(1000, 5, 15); var lightPosition = new SKPoint( (float)(Bounds.Width / 2 + Math.Cos(St.Elapsed.TotalSeconds) * Bounds.Width / 4), (float)(Bounds.Height / 2 + Math.Sin(St.Elapsed.TotalSeconds) * Bounds.Height / 4)); using (var sweep = SKShader.CreateSweepGradient(new SKPoint((int)Bounds.Width / 2, (int)Bounds.Height / 2), colors, null)) using (var turbulence = SKShader.CreatePerlinNoiseFractalNoise(0.05f, 0.05f, 4, 0)) using (var shader = SKShader.CreateCompose(sweep, turbulence, SKBlendMode.SrcATop)) using (var blur = SKImageFilter.CreateBlur(Animate(100, 2, 10), Animate(100, 5, 15))) using (var paint = new SKPaint { Shader = shader, ImageFilter = blur }) canvas.DrawPaint(paint); using (var pseudoLight = SKShader.CreateRadialGradient( lightPosition, (float)(Bounds.Width / 3), new [] { new SKColor(255, 200, 200, 100), SKColors.Transparent, new SKColor(40, 40, 40, 220), new SKColor(20, 20, 20, (byte)Animate(100, 200, 220)) }, new float[] { 0.3f, 0.3f, 0.8f, 1 }, SKShaderTileMode.Clamp)) using (var paint = new SKPaint { Shader = pseudoLight }) canvas.DrawPaint(paint); canvas.Restore(); } }
private void RenderDirtyRects(IDrawingContextImpl context) { foreach (var r in _dirtyRectsDisplay) { var brush = new ImmutableSolidColorBrush(Colors.Magenta, r.Opacity); context.FillRectangle(brush, r.Rect); } }
public RenderTargetSave(IDrawingContextImpl renderTarget, int paintFlags, PorterDuffXfermode paintXfermode, byte paintAlpha) { RenderTarget = renderTarget; PaintFlags = paintFlags; PaintXfermode = paintXfermode; PaintAlpha = paintAlpha; }
private void Render(bool forceComposite) { using (var l = _lock.TryLock()) { if (l == null) { return; } IDrawingContextImpl context = null; try { try { IDrawingContextImpl GetContext() { if (context != null) { return(context); } if (RenderTarget == null) { RenderTarget = ((IRenderRoot)_root).CreateRenderTarget(); } return(context = RenderTarget.CreateDrawingContext(this)); } var(scene, updated) = UpdateRenderLayersAndConsumeSceneIfNeeded(GetContext); using (scene) { var overlay = DrawDirtyRects || DrawFps; if (DrawDirtyRects) { _dirtyRectsDisplay.Tick(); } if (overlay) { RenderOverlay(scene.Item, GetContext()); } if (updated || forceComposite || overlay) { RenderComposite(scene.Item, GetContext()); } } } finally { context?.Dispose(); } } catch (RenderTargetCorruptedException ex) { Logging.Logger.Information("Renderer", this, "Render target was corrupted. Exception: {0}", ex); RenderTarget?.Dispose(); RenderTarget = null; } } }
/// <inheritdoc/> void IVisualBrushRenderer.RenderVisualBrush(IDrawingContextImpl context, IVisualBrush brush) { var childScene = TryGetChildScene(_currentDraw); if (childScene != null) { Render(context, (VisualNode)childScene.Root, null, new Rect(childScene.Size)); } }
public void Render(IDrawingContextImpl context) { var canvas = (context as ISkiaDrawingContextImpl)?.SkCanvas; if (canvas != null && _picture != null) { canvas.DrawPicture(_picture); } }
/// <inheritdoc/> void IVisualBrushRenderer.RenderVisualBrush(IDrawingContextImpl context, IVisualBrush brush) { var childScene = (_currentDraw.Item as BrushDrawOperation)?.ChildScenes?[brush.Visual]; if (childScene != null) { Render(context, (VisualNode)childScene.Root, null, new Rect(childScene.Size)); } }
public void RenderVisualBrush(IDrawingContextImpl context, IVisualBrush brush) { if (VisualBrushDrawList != null) { foreach (var cmd in VisualBrushDrawList) { cmd.Item.Render(context); } } }
public void RecreateBitmap(IDrawingContextImpl drawingContext, Size size, double scaling) { if (Size != size || Scaling != scaling) { var resized = RefCountable.Create(drawingContext.CreateLayer(size)); using (var context = resized.Item.CreateDrawingContext(null)) { Bitmap.Dispose(); context.Clear(default);
private void RenderComposite(Scene scene, ref IDrawingContextImpl context) { EnsureDrawingContext(ref context); context.Clear(Colors.Transparent); var clientRect = new Rect(scene.Size); var firstLayer = true; foreach (var layer in scene.Layers) { var bitmap = Layers[layer.LayerRoot].Bitmap; var sourceRect = new Rect(0, 0, bitmap.Item.PixelSize.Width, bitmap.Item.PixelSize.Height); if (layer.GeometryClip != null) { context.PushGeometryClip(layer.GeometryClip); } if (layer.OpacityMask == null) { if (firstLayer && bitmap.Item.CanBlit) { bitmap.Item.Blit(context); } else { context.DrawBitmap(bitmap, layer.Opacity, sourceRect, clientRect); } } else { context.DrawBitmap(bitmap, layer.OpacityMask, layer.OpacityMaskRect, sourceRect); } if (layer.GeometryClip != null) { context.PopGeometryClip(); } firstLayer = false; } if (_overlay != null) { var sourceRect = new Rect(0, 0, _overlay.Item.PixelSize.Width, _overlay.Item.PixelSize.Height); context.DrawBitmap(_overlay, 0.5, sourceRect, clientRect); } if (DrawFps) { RenderFps(context, clientRect, scene.Layers.Count); } }
private void DrawGrid(IBrush brush, IDrawingContextImpl context) { for (var i = 0; i <= Cols; i++) { for (var j = 0; j <= Rows; j++) { context.DrawLine(new ImmutablePen(brush), new Point(i * Resolution, 0), new Point(i * Resolution, Height)); context.DrawLine(new ImmutablePen(brush), new Point(0, j * Resolution), new Point(Width, j * Resolution)); } } }
public DrawingContext(IDrawingContextImpl impl) { this.drawingContext = impl; }
public DrawingContext(IDrawingContextImpl impl, Matrix? hiddenPostTransform = null) { _impl = impl; _hiddenPostTransform = hiddenPostTransform; }
public DrawingContext(IDrawingContextImpl impl) { _impl = impl; }