-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
207 lines (168 loc) · 6.36 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using HtmlParserSharp.Common;
using HtmlParserSharp.Core;
using System.Reflection;
using System.Drawing.Drawing2D;
using System;
using System.Xml.Linq;
using web;
namespace SkiaSharpOpenGLBenchmark
{
public partial class Form1 : Form
{
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
HtmlContent content;
Plotter Plot;
private FormElements floatingWindow;
public Form1()
{
// Disable DPI scaling
AutoScaleMode = AutoScaleMode.None;
InitializeComponent();
//CodeGenerator.GeneratePropertyParsers();
//CodeGenerator.GenerateCodeStubs2();
// Manually add another SkiaSharp control
skglControl2 = new SkiaSharp.Views.Desktop.SKGLControl();
skglControl2.AutoScaleMode = AutoScaleMode.None;
skglControl2.BackColor = System.Drawing.Color.Gray;
skglControl2.Location = new Point(10, 10);
skglControl2.Margin = new Padding(10, 10, 10, 10);
skglControl2.Name = "skglControl2";
skglControl2.Size = new Size(100, 100);
skglControl2.TabIndex = 4;
skglControl2.VSync = false;
skglControl2.PaintSurface += skglControl2_PaintSurface;
//skglControl2.Height = 100;
//skglControl2.Scale(new SizeF(0.666f, 0.666f));
//Controls.Add(skglControl2);
//Scale(0.666f);
//skglControl1.Scale(new SizeF(0.666f, 0.666f));
// Create a floating window for the TreeView
floatingWindow = new FormElements();
floatingWindow.Show();
// Load and parse HTML into the TreeView
floatingWindow.LoadHtmlToTreeView("<html><body><p>Hello, World!</p></body></html>"); // Replace with your HTML source
}
private void skglControl2_PaintSurface(object sender, SkiaSharp.Views.Desktop.SKPaintGLSurfaceEventArgs e)
{
}
Random rand = new Random(0);
private void skglControl1_PaintSurface(object sender, SkiaSharp.Views.Desktop.SKPaintGLSurfaceEventArgs e)
{
var csize = skglControl1.CanvasSize;
var surface = e.Surface;
//surface.Canvas.Scale(0.666f);
Plot.Surface.Draw(surface.Canvas, 0, 0, null);
var paint = new SKPaint
{
Style = SKPaintStyle.Stroke,
Color = new SKColor(0xffdddddd)
};
var rect = new SKRect(100, 100, 110, 110);
surface.Canvas.DrawRect(rect, paint);
/*
surface.Canvas.Clear(SKColor.Parse("#003366"));
for (int i = 0; i < lineCount; i++)
{
var paint = new SKPaint
{
Color = new SKColor(
red: (byte)rand.Next(255),
green: (byte)rand.Next(255),
blue: (byte)rand.Next(255),
alpha: (byte)rand.Next(255)),
StrokeWidth = rand.Next(1, 10),
IsAntialias = true
};
surface.Canvas.DrawLine(
x0: rand.Next(skglControl1.Width),
y0: rand.Next(skglControl1.Height),
x1: rand.Next(skglControl1.Width),
y1: rand.Next(skglControl1.Height),
paint: paint);
}
var paint2 = new SKPaint();
//paint2.StrikeThruText = true;
paint2.TextSize = 24;
paint2.Color = SKColors.Yellow;
//paint2.UnderlineText = true;
paint2.IsAntialias = true;
paint2.Typeface = SKTypeface.FromFamilyName(
"Arial",
SKFontStyleWeight.Bold,
SKFontStyleWidth.Normal,
SKFontStyleSlant.Italic);
surface.Canvas.DrawText("Fancy Text", 30, 30, paint2);
// Measure text
var s1 = "Test String";
//SkString text(s1);
var paint3 = new SKPaint();
//paint3.setTextSize(SkIntToScalar(font_size));
paint3.TextSize = 14;
//paint3.getFontMetrics(&metrics);
SKFontMetrics metrics;
paint3.GetFontMetrics(out metrics);
SKRect bounds = new SKRect();
float textWidth = paint3.MeasureText(s1, ref bounds);
*/
}
int lineCount;
List<double> renderTimesMsec = new List<double>();
private void Benchmark(int lineCount, int times = 10)
{
rand = new Random(0);
renderTimesMsec.Clear();
this.lineCount = lineCount;
Stopwatch stopwatch = new Stopwatch();
for (int i = 0; i < times; i++)
{
stopwatch.Restart();
skglControl1.Invalidate();
Application.DoEvents();
stopwatch.Stop();
renderTimesMsec.Add(1000.0 * stopwatch.ElapsedTicks / Stopwatch.Frequency);
double mean = renderTimesMsec.Sum() / renderTimesMsec.Count();
Debug.WriteLine($"Render {renderTimesMsec.Count:00} " +
$"took {renderTimesMsec.Last():0.000} ms " +
$"(running mean: {mean:0.000} ms)");
}
}
private void button1_Click(object sender, EventArgs e)
{
Benchmark(10);
}
private void button2_Click(object sender, EventArgs e)
{
Benchmark(1_000);
}
private void button3_Click(object sender, EventArgs e)
{
Benchmark(10_000);
}
private void button4_Click(object sender, EventArgs e)
{
//Benchmark(100_000);
}
private void Form1_Load(object sender, EventArgs e)
{
AllocConsole();
Plot = new Plotter();
content = new HtmlContent(Plot);
content.LoadDocument();
}
}
}