public void Invalidate_CallMultipleTimes_Success() { using (var context = new BufferedGraphicsContext()) { context.Invalidate(); context.Invalidate(); } }
private static async Task Render() { RenderStopWatch.Restart(); if (_workerWindow == IntPtr.Zero && !DesktopHandler.TryGetWorkerWindow(out _workerWindow)) { return; } if (!DesktopHandler.TryGetDeviceContext(_workerWindow, out var deviceContext)) { return; } using (var bufferedGraphics = _bufferedGraphicsContext.Allocate(deviceContext, _area)) { await _widgetService.Render(bufferedGraphics.Graphics); bufferedGraphics.Render(deviceContext); _bufferedGraphicsContext.Invalidate(); } Native.ReleaseDC(_workerWindow, deviceContext); Debug.WriteLine($"Render() took: {RenderStopWatch.ElapsedMilliseconds}ms"); }
public void Draw() { var tmpG = Graphics.FromImage(bitmap); tmpG.Clear(ForeColor); MoveTmpToNormal(); tmpG.SmoothingMode = SmoothingMode.AntiAlias; foreach (GraphItem obj in root.Children) { var state = tmpG.Save(); obj.OnPaint(tmpG, new Rectangle(0, 0, Width, Height), matrix); tmpG.Restore(state); } if (matrix != null) { matrix.Reset(); } BufferedGraphicsContext ctx = new BufferedGraphicsContext(); BufferedGraphics graphBuffer = ctx.Allocate(g, new Rectangle(0, 0, Width, Height)); Graphics diaplayGraphic = graphBuffer.Graphics; diaplayGraphic.Clear(ForeColor); diaplayGraphic.DrawImage(bitmap, 0, 0); graphBuffer.Render(); graphBuffer.Dispose(); ctx.Invalidate(); ctx.Dispose(); }
public void Allocate_LargeRectWithTargetGraphics_Success() { using (var context = new BufferedGraphicsContext()) using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) using (BufferedGraphics bufferedGraphics = context.Allocate(graphics, new Rectangle(0, 0, context.MaximumBuffer.Width + 1, context.MaximumBuffer.Height + 1))) { Assert.NotNull(bufferedGraphics.Graphics); context.Invalidate(); } }
public void Allocate_ValidTargetGraphics_Success() { using (var context = new BufferedGraphicsContext()) using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) using (BufferedGraphics bufferedGraphics = context.Allocate(graphics, Rectangle.Empty)) { Assert.NotNull(bufferedGraphics.Graphics); context.Invalidate(); } }
public void Dispose_BusyAndInvalidated_ThrowsInvalidOperationException() { using (var context = new BufferedGraphicsContext()) using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { using (context.Allocate(graphics, Rectangle.Empty)) { context.Invalidate(); Assert.Throws <InvalidOperationException>(() => context.Dispose()); } } }
private void DisposeBuffer() { if (_graphicsContext != null) { _graphicsContext.Invalidate(); } if (_bufferedGraphics != null) { _bufferedGraphics.Dispose(); _bufferedGraphics = null; } }
public void Allocate_LargeRectWithTargetHdc_Success() { using (var context = new BufferedGraphicsContext()) using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { try { IntPtr hdc = graphics.GetHdc(); using (BufferedGraphics bufferedGraphics = context.Allocate(hdc, new Rectangle(0, 0, context.MaximumBuffer.Width + 1, context.MaximumBuffer.Height + 1))) { Assert.NotNull(bufferedGraphics.Graphics); } context.Invalidate(); } finally { graphics.ReleaseHdc(); } } }
public void Allocate_ValidTargetHdc_Success() { using (var context = new BufferedGraphicsContext()) using (var image = new Bitmap(10, 10)) using (Graphics graphics = Graphics.FromImage(image)) { try { IntPtr hdc = graphics.GetHdc(); using (BufferedGraphics bufferedGraphics = context.Allocate(hdc, Rectangle.Empty)) { Assert.NotNull(bufferedGraphics.Graphics); } context.Invalidate(); } finally { graphics.ReleaseHdc(); } } }