OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 function moduleDidLoad() { | 5 function moduleDidLoad() { |
6 } | 6 } |
7 | 7 |
8 function postThreadFunc(numThreads) { | 8 function postThreadFunc(numThreads) { |
9 return function () { | 9 return function () { |
10 common.naclModule.postMessage({'message' : 'set_threads', | 10 common.naclModule.postMessage({'message' : 'set_threads', |
11 'value' : numThreads}); | 11 'value' : numThreads}); |
12 } | 12 } |
13 } | 13 } |
14 | 14 |
15 // Add event listeners after the NaCl module has loaded. These listeners will | 15 // Add event listeners after the NaCl module has loaded. These listeners will |
16 // forward messages to the NaCl module via postMessage() | 16 // forward messages to the NaCl module via postMessage() |
17 function attachListeners() { | 17 function attachListeners() { |
18 document.getElementById('benchmark').addEventListener('click', | 18 document.getElementById('benchmark').addEventListener('click', |
19 function() { | 19 function() { |
20 common.naclModule.postMessage({'message' : 'run benchmark'}); | 20 common.naclModule.postMessage({'message' : 'run benchmark'}); |
21 common.updateStatus('BENCHMARKING... (please wait)'); | 21 common.updateStatus('BENCHMARKING... (please wait)'); |
22 }); | 22 }); |
23 var threads = [0, 1, 2, 4, 6, 8, 12, 16, 24, 32]; | 23 var threads = [0, 1, 2, 4, 6, 8, 12, 16, 24, 32]; |
24 for (var i = 0; i < threads.length; i++) { | 24 for (var i = 0; i < threads.length; i++) { |
25 document.getElementById('radio'+i).addEventListener('click', | 25 document.getElementById('radio'+i).addEventListener('click', |
26 postThreadFunc(threads[i])); | 26 postThreadFunc(threads[i])); |
27 } | 27 } |
28 document.getElementById('zoomRange').addEventListener('change', | 28 document.getElementById('zoomRange').addEventListener('input', |
29 function() { | 29 function() { |
30 var value = parseFloat(document.getElementById('zoomRange').value); | 30 var value = parseFloat(document.getElementById('zoomRange').value); |
31 common.naclModule.postMessage({'message' : 'set_zoom', | 31 common.naclModule.postMessage({'message' : 'set_zoom', |
32 'value' : value}); | 32 'value' : value}); |
33 }); | 33 }); |
34 document.getElementById('lightRange').addEventListener('change', | 34 document.getElementById('lightRange').addEventListener('input', |
35 function() { | 35 function() { |
36 var value = parseFloat(document.getElementById('lightRange').value); | 36 var value = parseFloat(document.getElementById('lightRange').value); |
37 common.naclModule.postMessage({'message' : 'set_light', | 37 common.naclModule.postMessage({'message' : 'set_light', |
38 'value' : value}); | 38 'value' : value}); |
39 }); | 39 }); |
40 } | 40 } |
41 | 41 |
42 // Load a texture and send pixel data down to NaCl module. | 42 // Load a texture and send pixel data down to NaCl module. |
43 function loadTexture(name) { | 43 function loadTexture(name) { |
44 // Load image from jpg, decompress into canvas. | 44 // Load image from jpg, decompress into canvas. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 var light = message_event.data['value']; | 79 var light = message_event.data['value']; |
80 document.getElementById('lightRange').value = light; | 80 document.getElementById('lightRange').value = light; |
81 } else if (message_event.data['message'] == 'request_textures') { | 81 } else if (message_event.data['message'] == 'request_textures') { |
82 // NaCl module is requesting a set of textures. | 82 // NaCl module is requesting a set of textures. |
83 var names = message_event.data['names']; | 83 var names = message_event.data['names']; |
84 for (var i = 0; i < names.length; i++) | 84 for (var i = 0; i < names.length; i++) |
85 loadTexture(names[i]); | 85 loadTexture(names[i]); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
OLD | NEW |