public void Update(DrawProc Proc) { pw.WaitOne(); pw.Reset(); Proc?.Invoke(View); var old_proc = load_buffer; load_buffer = new WICBitmap(iFactory, buffer, BitmapCreateCacheOption.CacheOnLoad); old_proc?.Dispose(); Updated = true; pw.Set(); }
private void DrawingEvent() { Stopwatch sys_watch = new Stopwatch(); while (true) { sys_watch.Start(); timer.Start(); m_info.View.BeginDraw(); var result = DrawProc?.Invoke(m_info.View); m_info.View.EndDraw(); if (result == DrawResultW.Death) { Dispose(); return; } if (result == DrawResultW.Commit) { m_info.swapChain.Present(0, PresentFlags.None); } timer.Stop(); while (CleanTasks.Count > 0) { CleanTasks[0].Dispose(); CleanTasks.RemoveAt(0); } decimal time = timer.ElapsedTicks / (decimal)Stopwatch.Frequency * 1000; decimal wait_time = 1000.0M / (decimal)AskedFrames - time; timer.Reset(); // _renderForm.Text = time.ToString(); if (wait_time <= 0) { wait_time = 0; } Thread.Sleep((int)wait_time); sys_watch.Stop(); decimal stime = sys_watch.ElapsedTicks / (decimal)Stopwatch.Frequency * 1000; FrameRate = (int)(1000.0M / stime); sys_watch.Reset(); } }
public void DrawStartup(System.Windows.Controls.Image contorl) { if (FirstDraw != null) { try { FirstDraw(m_d2d_info, null, Width, Height); contorl.Dispatcher.Invoke(new Action(() => { Commit(); })); } catch (Exception e) { MessageBox.Show(e.ToString()); } } m_Dipter = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(1) }; m_Dipter.Tick += (e, v) => { Dpis = Times; Debug.WriteLine("Speed:" + Dpis.ToString()); Times = 0; }; m_Dipter2 = new Thread(() => {//绘图代码 while (isRunning) { DrawProcResult?UpData = null; Stopwatch sw = new Stopwatch(); sw.Start(); UpData = DrawProc?.Invoke(m_d2d_info, Loadedsouce, Width, Height); if (!(UpData == DrawProcResult.Ignore || UpData == null)) { contorl.Dispatcher.Invoke(new Action(() => { Commit(); })); } sw.Stop(); decimal time = sw.ElapsedTicks / (decimal)Stopwatch.Frequency * 1000; decimal wait_time = 1000.0M / (decimal)TargetDpi - time; if (wait_time < 0) { wait_time = 0; } if (UpData == DrawProcResult.Normal || UpData == null) { Thread.Sleep((int)wait_time); Times++; continue; } if (UpData == DrawProcResult.Ignore) { continue; } if (UpData == DrawProcResult.Death) { this.Dispose(); break; } } Disposing?.Invoke(Loadedsouce, this); buffer = null; ////// D2dRelease(m_d2d_info); Disposed?.Invoke(); }) { IsBackground = true }; contorl.Source = buffer; m_Dipter.Start(); m_Dipter2.Start(); }
public void DrawStartup() { buffer = new WriteableBitmap((int)Width, (int)Height, 72, 72, System.Windows.Media.PixelFormats.Pbgra32, null); this.Source = buffer; TargetDpi = 60; Speed = 1.0d / TargetDpi; isRunning = true; m_d2d_info = D2dInit(new Size2((int)Width, (int)Height)); if (FirstDraw != null) { try { FirstDraw(m_d2d_info, null); this.Dispatcher.Invoke(new Action(() => { Commit(); })); } catch (Exception e) { MessageBox.Show(e.ToString()); } } m_Dipter = new DispatcherTimer() { Interval = TimeSpan.FromSeconds(1) }; m_Dipter.Tick += (e, v) => { FrameRate = Times; Debug.WriteLine("Speed:" + FrameRate.ToString()); Times = 0; }; m_Dipter2 = new Thread(() => {//绘图代码 while (isRunning) { DrawProcResult?UpData = null; Stopwatch sw = new Stopwatch(); sw.Start(); UpData = DrawProc?.Invoke(m_d2d_info); if (!(UpData == DrawProcResult.Ignore || UpData == null)) { this.Dispatcher.Invoke(new Action(() => { Commit(); })); } sw.Stop(); while (CleanTasks.Count > 0) { CleanTasks[0].Dispose(); CleanTasks.RemoveAt(0); } decimal time = sw.ElapsedTicks / (decimal)Stopwatch.Frequency * 1000; decimal wait_time = 1000.0M / (decimal)TargetDpi - time; if (wait_time < 0) { wait_time = 0; } if (UpData == DrawProcResult.Normal || UpData == null) { Thread.Sleep((int)wait_time); Times++; continue; } if (UpData == DrawProcResult.Ignore) { continue; } if (UpData == DrawProcResult.Death) { this.Dispose(); break; } } Disposing?.Invoke(this); buffer = null; ////// D2dRelease(m_d2d_info); Disposed?.Invoke(); }) { IsBackground = true }; Stretch = System.Windows.Media.Stretch.Fill; m_Dipter.Start(); m_Dipter2.Start(); }