-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
145 lines (124 loc) · 4.41 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
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;
namespace SkiaSharpOpenGLBenchmark
{
public partial class Form1 : Form
{
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
HtmlContent content;
Plotter Plot;
public Form1()
{
InitializeComponent();
//CodeGenerator.GeneratePropertyParsers();
//CodeGenerator.GenerateCodeStubs2();
}
Random rand = new Random(0);
private void skglControl1_PaintSurface(object sender, SkiaSharp.Views.Desktop.SKPaintGLSurfaceEventArgs e)
{
var surface = e.Surface;
Plot.Surface.Draw(surface.Canvas, 0, 0, null);
/*
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();
}
}
}