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({'message' : 'set_threads', 11 'value' : numThreads}); 12 } 13 } 14 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', 19 function() { 20 common.naclModule.postMessage({'message' : 'run_benchmark'}); 21 common.updateStatus('BENCHMARKING... (please wait)'); 22 }); 23 document.getElementById('drawPoints').addEventListener('click', 24 function() { 25 var checked = document.getElementById('drawPoints').checked; 26 common.naclModule.postMessage({'message' : 'draw_points', 27 'value' : checked}); 28 }); 29 document.getElementById('drawInteriors').addEventListener('click', 30 function() { 31 var checked = document.getElementById('drawInteriors').checked; 32 common.naclModule.postMessage({'message' : 'draw_interiors', 33 'value' : checked}); 34 }); 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])); 39 } 40 document.getElementById('pointRange').addEventListener('input', 41 function() { 42 var value = parseFloat(document.getElementById('pointRange').value); 43 common.naclModule.postMessage({'message' : 'set_points', 44 'value' : value}); 45 document.getElementById('pointCount').textContent = value + ' points'; 46 }); 47 } 48 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') 57 } 58 } 59 60