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

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

Issue 1995163002: Test page for rendering throughput for canvas arcs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments Created 4 years, 7 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/canvas_arcs.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 arcs test on the animometer
5 // benchmark (https://pr.gg/animometer/developer.html).
6 // Javascript code: https://pr.gg/animometer/tests/master/resources/canvas-tests .js
7
8 function CanvasArc() {
9 var x;
10 var y;
11 var radius;
12 var width;
13 var start_angle;
14 var end_angle;
15 var arc_speed;
16 var counterclockwise;
17 var color;
18 var is_stroke;
19
20 this.init = function(arc_speed, max_width, max_height) {
21 // initialize parameters randomly
22
23
24 num_positions_x = 7;
25 position_incr_x = Math.floor(max_width / num_positions_x);
26 this.x = Math.floor(Math.random() * num_positions_x) * position_incr_x;
27
28 num_positions_y = 7;
29 position_incr_y = Math.floor(max_height / num_positions_y);
30 this.y = Math.floor(Math.random() * num_positions_y) * position_incr_y;
31
32 var max_radius = max_height / 10;
33 // radius is in [0.5*max_radius, max_radius)
34 this.radius = ((Math.random() + 1) / 2) * max_radius;
35
36 this.width = 1 + Math.pow(Math.random(), 4) * 30;
37
38 var colors = ["#101010", "#808080", "#c0c0c0",
39 "#e01040", "#10c030", "#e05010"];
40 this.color = colors[Math.floor(Math.random() * colors.length)];
41
42 this.is_stroke = (Math.floor(Math.random() * 3) == 0);
43
44 this.counterclockwise = (Math.floor(Math.random() * 2) == 0);
45
46 this.arc_speed = (Math.random() - 0.5) * Math.PI / 10;
47 this.start_angle = Math.random() * 2 * Math.PI;
48 this.end_angle = Math.random() * 2 * Math.PI;
49 }
50
51 this.draw = function(context) {
52 this.start_angle += this.arc_speed;
53 this.end_angle += this.arc_speed / 2;
54
55 // draw the canvas arc on the given context
56 if (this.is_stroke) {
57 context.strokeStyle = this.color;
58 context.lineWidth = this.width;
59 context.beginPath();
60 context.arc(this.x, this.y, this.radius,
61 this.start_angle, this.end_angle, this.counterclockwise);
62 context.stroke();
63
64 } else {
65 context.fillStyle = this.color;
66 context.beginPath();
67 context.lineTo(this.x, this,y);
68 context.arc(this.x, this.y, this.radius, this.start_angle,
69 this.end_angle, this.couterclockwise);
70 context.lineTo(this.x, this.y);
71 context.fill();
72
73 }
74 }
75 }
76
77 var arcs = (function() {
78 var initialized_arcs;
79 var width;
80 var height;
81
82 var arcs = {};
83
84 arcs.init = function(number_arcs, arc_speed, canvas_width, canvas_height) {
85 // initialize arcs and store variables
86 initialized_arcs = [];
87 for(var i = 0; i < number_arcs; i++) {
88 var new_arc = new CanvasArc();
89 new_arc.init(arc_speed, canvas_width, canvas_height);
90 initialized_arcs.push(new_arc)
91 }
92
93 };
94
95 arcs.draw = function(context) {
96 // draw all initialized_arcs on the context
97 for(var i = 0; i < initialized_arcs.length; i++) {
98 initialized_arcs[i].draw(context);
99 }
100 };
101
102 return arcs;
103 })();
104
105
OLDNEW
« no previous file with comments | « tools/perf/page_sets/tough_canvas_cases/rendering_throughput/canvas_arcs.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698