Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / examples / demo / life_simd / example.js
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.
4
5 function moduleDidLoad() {
6 }
7
8
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',
13     function() {
14       common.naclModule.postMessage({'message' : 'run_benchmark'});
15       common.updateStatus('BENCHMARKING... (please wait)');
16     });
17   document.getElementById('simd').addEventListener('click',
18     function() {
19       var simd = document.getElementById('simd');
20       common.naclModule.postMessage({'message' : 'set_simd',
21           'value' : simd.checked});
22     });
23   document.getElementById('multithread').addEventListener('click',
24     function() {
25       var multithread = document.getElementById('multithread');
26       common.naclModule.postMessage({'message' : 'set_threading',
27           'value' : multithread.checked});
28     });
29   document.getElementById('large').addEventListener('click',
30     function() {
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);
35     });
36 }
37
38
39 // Handle a message coming from the NaCl module.
40 function handleMessage(message_event) {
41   if (message_event.data.message == 'benchmark_result') {
42     // 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');
49   }
50 }
51