1 // Copyright 2014 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() {
9 // Add event listeners after the NaCl module has loaded. These listeners will
10 // forward messages to the NaCl module via postMessage()
11 function attachListeners() {
12 document
.getElementById('benchmark').addEventListener('click',
14 common
.naclModule
.postMessage({'message' : 'run_benchmark'});
15 common
.updateStatus('BENCHMARKING... (please wait)');
17 document
.getElementById('simd').addEventListener('click',
19 var simd
= document
.getElementById('simd');
20 common
.naclModule
.postMessage({'message' : 'set_simd',
21 'value' : simd
.checked
});
23 document
.getElementById('multithread').addEventListener('click',
25 var multithread
= document
.getElementById('multithread');
26 common
.naclModule
.postMessage({'message' : 'set_threading',
27 'value' : multithread
.checked
});
29 document
.getElementById('large').addEventListener('click',
31 var large
= document
.getElementById('large');
32 var nacl
= document
.getElementById('nacl_module');
33 nacl
.setAttribute('width', large
.checked
? 1280 : 640);
34 nacl
.setAttribute('height', large
.checked
? 1024 : 640);
39 // Handle a message coming from the NaCl module.
40 function handleMessage(message_event
) {
41 if (message_event
.data
.message
== 'benchmark_result') {
43 var result
= message_event
.data
.value
;
44 console
.log('Benchmark result:' + result
);
45 result
= (Math
.round(result
* 1000) / 1000).toFixed(3);
46 document
.getElementById('result').textContent
=
47 'Result: ' + result
+ ' seconds';
48 common
.updateStatus('SUCCESS');