Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: tools/perf/page_sets/tough_canvas_cases/rendering_throughput/stroke_shapes.js

Issue 2047773002: Added telemetry pages for the canvas element. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some formatting Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/perf/page_sets/tough_canvas_cases/rendering_throughput/stroke_shapes.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 // This code in inspired by the canvas stroke shapes test on the animometer
5 // benchmark (https://trac.webkit.org/export/HEAD/trunk/PerformanceTests/Animome ter/developer.html).
6 // Javascript code: https://pr.gg/animometer/tests/simple/resources/simple-canva s-paths.js
7
8 var shape_types = ["quadratic", "bezier", "arc_to",
9 "arc", "rectangle", "ellipse"];
10
11 function CanvasStrokeShape() {
12 this.init = function(canvas_width, canvas_height) {
13 this.shape_type = shape_types[Math.floor(Math.random() * 6)];
14 this.color = get_random_color_string();
15
16 var max_size = Math.floor(Math.random() * 160) + 20;
17
18 var center = new Point(
19 Math.floor(Math.random() * canvas_width),
20 Math.floor(Math.random() * canvas_height));
21
22 this.p1 = new Point(
23 Math.floor(Math.random() * max_size) - max_size/2 + center.x,
24 Math.floor(Math.random() * max_size) - max_size/2 + center.y);
25
26 this.p2 = new Point(
27 Math.floor(Math.random() * max_size) - max_size/2 + center.x,
28 Math.floor(Math.random() * max_size) - max_size/2 + center.y);
29
30 this.p3 = new Point(
31 Math.floor(Math.random() * max_size) - max_size/2 + center.x,
32 Math.floor(Math.random() * max_size) - max_size/2 + center.y);
33
34 this.p4 = new Point(
35 Math.floor(Math.random() * max_size) - max_size/2 + center.x,
36 Math.floor(Math.random() * max_size) - max_size/2 + center.y);
37
38 switch(this.shape_type) {
39 case "quadratic":
40 this.width = Math.floor(Math.random() * 40) + 5;
41 break;
42
43 case "bezier":
44 this.width = Math.floor(Math.random() * 40) + 5;
45 break;
46
47 case "arc_to":
48 this.width = Math.floor(Math.random() * 40) + 5;
49 this.radius = Math.floor(Math.random() * 180) + 20;
50 break;
51
52 case "arc":
53 this.start_angle = Math.random() * 2 * Math.PI;
54 this.end_angle = Math.random() * 2 * Math.PI;
55 this.countclockwise = Math.floor(Math.random * 2);
56
57 this.width = Math.floor(Math.random() * 40) + 5;
58 this.radius = Math.floor(Math.random() * 180) + 20;
59 break;
60
61 case "rectangle":
62 this.width = Math.floor(Math.random() * 180) + 20;
63 this.height = Math.floor(Math.random() * 180) + 20;
64 this.line_width = Math.floor(Math.random() * 15);
65 break;
66
67 case "ellipse":
68 this.radius_w = Math.floor(Math.random() * 180) + 20;
69 this.radius_h = Math.floor(Math.random() * 180) + 20;
70
71 this.countclockwise = Math.floor(Math.random * 2);
72 this.line_width = Math.floor(Math.random() * 15);
73
74 this.rotation = Math.random() * 2 * Math.PI;
75 this.start_angle = Math.random() * 2 * Math.PI;
76 this.end_angle = Math.random() * 2 * Math.PI;
77
78 break;
79 }
80 }
81
82 this.draw_quadratic_segment = function(context) {
83 context.strokeStyle = this.color;
84 context.lineWidth = this.width;
85 context.beginPath();
86 context.moveTo(this.p1.x, this.p1.y);
87 context.quadraticCurveTo(this.p2.x, this.p2.y, this.p3.x, this.p3.y);
88 context.stroke();
89 }
90
91 this.draw_bezier_segment = function(context) {
92 context.strokeStyle = this.color;
93 context.lineWidth = this.width;
94 context.beginPath();
95 context.moveTo(this.p1.x, this.p1.y);
96 context.bezierCurveTo(this.p2.x, this.p2.y, this.p3.x,
97 this.p3.y, this.p4.x, this.p4.y);
98 context.stroke()
99 }
100
101 this.draw_arc_to_segment = function(context) {
102 context.strokeStyle = this.color;
103 context.lineWidth = this.width;
104 context.beginPath();
105 context.moveTo(this.p1.x, this.p1.y);
106 context.arcTo(this.p2.x, this.p2.y, this.p3.x, this.p3.y, this.radius);
107 context.stroke();
108 }
109
110 this.draw_arc_segment = function(context) {
111 context.strokeStyle = this.color;
112 context.lineWidth = this.width;
113 context.beginPath();
114 context.arc(this.p1.x, this.p1.y, this.radius, this.start_angle,
115 this.end_angle, this.counterclockwise);
116 context.stroke();
117 }
118
119 this.draw_rectangle = function(context) {
120 context.strokeStyle = this.color;
121 context.lineWidth = this.line_width;
122 context.beginPath();
123 context.rect(this.p1.x, this.p1.y, this.width, this.height);
124 context.stroke();
125 }
126
127 this.draw_ellipse = function(context) {
128 context.strokeStyle = this.color;
129 context.lineWidth = this.line_width;
130 context.beginPath();
131 context.ellipse(this.p1.x, this.p1.y, this.radius_w, this.radius_h,
132 this.rotation, this.start_angle, this.end_angle,
133 this.counterclockwise);
134 context.stroke();
135 }
136
137 this.draw = function(context) {
138 switch(this.shape_type) {
139 case "quadratic":
140 this.draw_quadratic_segment(context);
141 break;
142 case "bezier":
143 this.draw_bezier_segment(context);
144 break;
145 case "arc_to":
146 this.draw_arc_to_segment(context);
147 break;
148 case "arc":
149 this.draw_arc_segment(context);
150 break;
151 case "rectangle":
152 this.draw_rectangle(context);
153 break;
154 case "ellipse":
155 this.draw_ellipse(context);
156 break;
157 }
158 }
159 }
160
161 var stage_stroke_shapes = (function() {
162 var stage = {};
163 var shapes;
164
165 stage.init = function(number_shapes, canvas_width, canvas_height) {
166 shapes = []
167 for (var i = 0; i < number_shapes; i++) {
168 var shape = new CanvasStrokeShape();
169 shape.init(canvas_width, canvas_height);
170 shapes.push(shape);
171 }
172 };
173
174 stage.draw = function(context) {
175 for (var i = 0; i < shapes.length; i++) {
176 shapes[i].draw(context);
177 }
178 };
179
180 return stage;
181 })();
182
183
OLDNEW
« no previous file with comments | « tools/perf/page_sets/tough_canvas_cases/rendering_throughput/stroke_shapes.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698