OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 function moduleDidLoad() { |
| 6 } |
| 7 |
| 8 function postThreadFunc(numThreads) { |
| 9 return function () { |
| 10 common.naclModule.postMessage('threads: ' + numThreads); |
| 11 } |
| 12 } |
| 13 |
| 14 // Add event listeners after the NaCl module has loaded. These listeners will |
| 15 // forward messages to the NaCl module via postMessage() |
| 16 function attachListeners() { |
| 17 document.getElementById('benchmark').addEventListener('click', |
| 18 function() { |
| 19 common.naclModule.postMessage('run benchmark'); |
| 20 common.updateStatus('BENCHMARKING... (please wait)'); |
| 21 }); |
| 22 document.getElementById('drawPoints').addEventListener('click', |
| 23 function() { |
| 24 var checked = document.getElementById('drawPoints').checked; |
| 25 if (checked) |
| 26 common.naclModule.postMessage('with points'); |
| 27 else |
| 28 common.naclModule.postMessage('without points'); |
| 29 }); |
| 30 document.getElementById('drawInteriors').addEventListener('click', |
| 31 function() { |
| 32 var checked = document.getElementById('drawInteriors').checked; |
| 33 if (checked) |
| 34 common.naclModule.postMessage('with interiors'); |
| 35 else |
| 36 common.naclModule.postMessage('without interiors'); |
| 37 }); |
| 38 var threads = [0, 1, 2, 4, 6, 8, 12, 16, 24, 32]; |
| 39 for (var i = 0; i < threads.length; i++) { |
| 40 document.getElementById('radio'+i).addEventListener('click', |
| 41 postThreadFunc(threads[i])); |
| 42 } |
| 43 document.getElementById('pointRange').addEventListener('change', |
| 44 function() { |
| 45 var value = document.getElementById('pointRange').value; |
| 46 common.naclModule.postMessage('points: ' + value); |
| 47 document.getElementById('pointCount').textContent = value + ' points'; |
| 48 }); |
| 49 } |
| 50 |
| 51 // Handle a message coming from the NaCl module. |
| 52 // In the Voronoi example, the only message will be the benchmark result. |
| 53 function handleMessage(message_event) { |
| 54 var x = (Math.round(message_event.data * 1000) / 1000).toFixed(3); |
| 55 document.getElementById('result').textContent = |
| 56 'Result: ' + x + ' seconds'; |
| 57 common.updateStatus('SUCCESS') |
| 58 } |
| 59 |
OLD | NEW |