Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 simd = document.getElementById('simd'); | |
|
binji
2014/08/08 00:31:40
var simd
nfullagar
2014/08/08 20:51:48
Done.
| |
| 20 common.naclModule.postMessage({'message' : 'set_simd', | |
| 21 'value' : simd.checked ? 'enable' : 'disable'}); | |
|
binji
2014/08/08 00:31:40
probably simpler to just send a bool, rather than
nfullagar
2014/08/08 20:51:47
Done.
| |
| 22 }); | |
| 23 document.getElementById('multithread').addEventListener('click', | |
| 24 function() { | |
| 25 multithread = document.getElementById('multithread'); | |
| 26 common.naclModule.postMessage({'message' : 'set_threading', | |
| 27 'value' : multithread.checked ? 'enable' : 'disable'}); | |
| 28 }); | |
| 29 document.getElementById('large').addEventListener('click', | |
| 30 function() { | |
| 31 large = document.getElementById('large'); | |
| 32 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') { | |
|
binji
2014/08/08 00:31:40
data.message is more conventional
nfullagar
2014/08/08 20:51:47
Done.
| |
| 42 // benchmark result | |
| 43 var result = message_event.data['value']; | |
|
binji
2014/08/08 00:31:40
data.value
nfullagar
2014/08/08 20:51:48
Done.
| |
| 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 | |
| OLD | NEW |