From d5d2c87d68627b908f624373486bdf85a1898a66 Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 5 Aug 2014 01:03:16 +0000 Subject: [PATCH] butcher rendering performance test for more speed --- .../CustomControls/GDITextRenderer.cs | 38 +++++++++-- .../tools/NES/NESNameTableViewer.Designer.cs | 1 - .../tools/NES/NameTableViewer.cs | 67 ++++++++++--------- 3 files changed, 69 insertions(+), 37 deletions(-) diff --git a/BizHawk.Client.EmuHawk/CustomControls/GDITextRenderer.cs b/BizHawk.Client.EmuHawk/CustomControls/GDITextRenderer.cs index a827490ab7..592baac8d7 100644 --- a/BizHawk.Client.EmuHawk/CustomControls/GDITextRenderer.cs +++ b/BizHawk.Client.EmuHawk/CustomControls/GDITextRenderer.cs @@ -42,6 +42,17 @@ namespace BizHawk.Client.EmuHawk.CustomControls #endregion + public NativeTextRenderer(System.Windows.Forms.Control c) + { + _c = c; + _hdc = GetDC(c.Handle); + } + + System.Windows.Forms.Control _c; + [DllImport("user32.dll")] + private static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); + [DllImport("user32.dll")] + private static extern IntPtr GetDC(IntPtr hWnd); /// /// Init. @@ -50,14 +61,14 @@ namespace BizHawk.Client.EmuHawk.CustomControls { _g = g; - var clip = _g.Clip.GetHrgn(_g); + //var clip = _g.Clip.GetHrgn(_g); _hdc = _g.GetHdc(); SetBkMode(_hdc, 1); - SelectClipRgn(_hdc, clip); + //SelectClipRgn(_hdc, clip); - DeleteObject(clip); + //DeleteObject(clip); } /// @@ -107,11 +118,14 @@ namespace BizHawk.Client.EmuHawk.CustomControls /// the text color to set /// the location to start string draw (top-left) public void DrawString(String str, Font font, Color color, Point point) + { + TextOut(_hdc, point.X, point.Y, str, str.Length); + } + + public void PrepDrawString(String str, Font font, Color color, Point point) { SetFont(font); SetTextColor(color); - - TextOut(_hdc, point.X, point.Y, str, str.Length); } /// @@ -137,6 +151,12 @@ namespace BizHawk.Client.EmuHawk.CustomControls /// public void Dispose() { + if (_c != null) + { + ReleaseDC(_c.Handle, _hdc); + _hdc = IntPtr.Zero; + } + if (_hdc != IntPtr.Zero) { SelectClipRgn(_hdc, IntPtr.Zero); @@ -200,6 +220,14 @@ namespace BizHawk.Client.EmuHawk.CustomControls SetTextColor(_hdc, rgb); } + public void DrawRectangle(int nLeftRect,int nTopRect,int nRightRect,int nBottomRect) + { + Rectangle(_hdc, nLeftRect, nTopRect, nRightRect, nBottomRect); + } + + [DllImport("gdi32.dll")] + private static extern int Rectangle(IntPtr hdc,int nLeftRect,int nTopRect,int nRightRect,int nBottomRect); + [DllImport("gdi32.dll")] private static extern int SetBkMode(IntPtr hdc, int mode); diff --git a/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.Designer.cs b/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.Designer.cs index 6b6bbb3dd5..10685284a4 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/NESNameTableViewer.Designer.cs @@ -91,7 +91,6 @@ // // NameTableView // - this.NameTableView.BackColor = System.Drawing.Color.Transparent; this.NameTableView.ContextMenuStrip = this.contextMenuStrip1; this.NameTableView.Location = new System.Drawing.Point(6, 19); this.NameTableView.Name = "NameTableView"; diff --git a/BizHawk.Client.EmuHawk/tools/NES/NameTableViewer.cs b/BizHawk.Client.EmuHawk/tools/NES/NameTableViewer.cs index 8eeda6bd13..be69e36159 100644 --- a/BizHawk.Client.EmuHawk/tools/NES/NameTableViewer.cs +++ b/BizHawk.Client.EmuHawk/tools/NES/NameTableViewer.cs @@ -23,11 +23,11 @@ namespace BizHawk.Client.EmuHawk Nametables = new Bitmap(pSize.Width, pSize.Height); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.UserPaint, true); - SetStyle(ControlStyles.DoubleBuffer, true); - SetStyle(ControlStyles.SupportsTransparentBackColor, true); - //SetStyle(ControlStyles.Opaque, true); + SetStyle(ControlStyles.DoubleBuffer, false); + // SetStyle(ControlStyles.SupportsTransparentBackColor, false); + SetStyle(ControlStyles.Opaque, true); Size = new Size(256, 224); - BackColor = Color.Transparent; + //BackColor = Color.Transparent; //Paint += NameTableViewer_Paint; } @@ -38,38 +38,43 @@ namespace BizHawk.Client.EmuHawk public WhichNametable Which = WhichNametable.NT_ALL; - protected override void OnPaint(PaintEventArgs e) + + protected override void OnPaintBackground(PaintEventArgs pevent) { - using (var ntr = new NativeTextRenderer(e.Graphics)) - { - for (int y = 0; y < 16; y++) - { - StringBuilder sb = new StringBuilder(); - Random r = new Random((int)DateTime.Now.Ticks); - for (int i = 0; i < 64; i++) - { - sb.Append((char)r.Next(0, 255)); - } + } + protected override void OnPaint(PaintEventArgs e) + { + var font = this.Font; - ntr.DrawString(sb.ToString(), this.Font, Color.Black, new Point(15, y * 30)); - //e.Graphics.DrawString(sb.ToString(), this.Font, Brushes.Black, new Point(15, y * 30)); - } - } - - /* - for (int y = 0; y < 16; y++) - { - StringBuilder sb = new StringBuilder(); - Random r = new Random((int)DateTime.Now.Ticks); - for (int i = 0; i < 64; i++) - { - sb.Append((char)r.Next(0, 255)); - } - e.Graphics.DrawString(sb.ToString(), this.Font, Brushes.Black, new Point(15, y * 30)); + StringBuilder sb = new StringBuilder(128); + Random r = new Random((int)DateTime.Now.Ticks); + for (int i = 0; i < 64; i++) + { + sb.Append((char)r.Next('a', 'z')); } - */ + string junk = sb.ToString(); + + + using (var ntr = new NativeTextRenderer(this)) + { + ntr.PrepDrawString(junk, font, Color.Black, new Point(0, 0)); + ntr.DrawRectangle(0, 0, ClientRectangle.Right, ClientRectangle.Bottom); + for (int y = 0; y < 16; y++) + { + ntr.DrawString(junk, font, Color.Black, new Point(15, y * 30)); + //e.Graphics.DrawString(sb.ToString(), this.Font, Brushes.Black, new Point(15, y * 30)); + } + } + + + //e.Graphics.FillRectangle(Brushes.White, ClientRectangle); + //for (int y = 0; y < 16; y++) + //{ + // e.Graphics.DrawString(junk, font, Brushes.Black, new Point(15, y * 30)); + //} + //base.OnPaint(e); }