1 // Copyright (c) 2013 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.
5 function moduleDidLoad() {
8 function postThreadFunc(numThreads
) {
10 common
.naclModule
.postMessage({'message' : 'set_threads',
11 'value' : numThreads
});
15 // Add event listeners after the NaCl module has loaded. These listeners will
16 // forward messages to the NaCl module via postMessage()
17 function attachListeners() {
18 document
.getElementById('benchmark').addEventListener('click',
20 common
.naclModule
.postMessage({'message' : 'run_benchmark'});
21 common
.updateStatus('BENCHMARKING... (please wait)');
23 document
.getElementById('drawPoints').addEventListener('click',
25 var checked
= document
.getElementById('drawPoints').checked
;
26 common
.naclModule
.postMessage({'message' : 'draw_points',
29 document
.getElementById('drawInteriors').addEventListener('click',
31 var checked
= document
.getElementById('drawInteriors').checked
;
32 common
.naclModule
.postMessage({'message' : 'draw_interiors',
35 var threads
= [0, 1, 2, 4, 6, 8, 12, 16, 24, 32];
36 for (var i
= 0; i
< threads
.length
; i
++) {
37 document
.getElementById('radio' + i
).addEventListener('click',
38 postThreadFunc(threads
[i
]));
40 document
.getElementById('pointRange').addEventListener('input',
42 var value
= parseFloat(document
.getElementById('pointRange').value
);
43 common
.naclModule
.postMessage({'message' : 'set_points',
45 document
.getElementById('pointCount').textContent
= value
+ ' points';
49 // Handle a message coming from the NaCl module.
50 // In the Voronoi example, the only message will be the benchmark result.
51 function handleMessage(message_event
) {
52 if (message_event
.data
['message'] == 'benchmark_result') {
53 var x
= (Math
.round(message_event
.data
['value'] * 1000) / 1000).toFixed(3);
54 document
.getElementById('result').textContent
=
55 'Result: ' + x
+ ' seconds';
56 common
.updateStatus('SUCCESS')