Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: native_client_sdk/src/examples/demo/voronoi/example.js

Issue 17575016: Update voronoi demo to use dictionary messages. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | native_client_sdk/src/examples/demo/voronoi/voronoi.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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('threads: ' + numThreads); 10 common.naclModule.postMessage({'message' : 'set_threads',
11 'value' : numThreads});
11 } 12 }
12 } 13 }
13 14
14 // 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
15 // forward messages to the NaCl module via postMessage() 16 // forward messages to the NaCl module via postMessage()
16 function attachListeners() { 17 function attachListeners() {
17 document.getElementById('benchmark').addEventListener('click', 18 document.getElementById('benchmark').addEventListener('click',
18 function() { 19 function() {
19 common.naclModule.postMessage('run benchmark'); 20 common.naclModule.postMessage({'message' : 'run_benchmark'});
20 common.updateStatus('BENCHMARKING... (please wait)'); 21 common.updateStatus('BENCHMARKING... (please wait)');
21 }); 22 });
22 document.getElementById('drawPoints').addEventListener('click', 23 document.getElementById('drawPoints').addEventListener('click',
23 function() { 24 function() {
24 var checked = document.getElementById('drawPoints').checked; 25 var checked = document.getElementById('drawPoints').checked;
25 if (checked) 26 common.naclModule.postMessage({'message' : 'draw_points',
26 common.naclModule.postMessage('with points'); 27 'value' : checked});
27 else
28 common.naclModule.postMessage('without points');
29 }); 28 });
30 document.getElementById('drawInteriors').addEventListener('click', 29 document.getElementById('drawInteriors').addEventListener('click',
31 function() { 30 function() {
32 var checked = document.getElementById('drawInteriors').checked; 31 var checked = document.getElementById('drawInteriors').checked;
33 if (checked) 32 common.naclModule.postMessage({'message' : 'draw_interiors',
34 common.naclModule.postMessage('with interiors'); 33 'value' : checked});
35 else
36 common.naclModule.postMessage('without interiors');
37 }); 34 });
38 var threads = [0, 1, 2, 4, 6, 8, 12, 16, 24, 32]; 35 var threads = [0, 1, 2, 4, 6, 8, 12, 16, 24, 32];
39 for (var i = 0; i < threads.length; i++) { 36 for (var i = 0; i < threads.length; i++) {
40 document.getElementById('radio'+i).addEventListener('click', 37 document.getElementById('radio' + i).addEventListener('click',
41 postThreadFunc(threads[i])); 38 postThreadFunc(threads[i]));
42 } 39 }
43 document.getElementById('pointRange').addEventListener('change', 40 document.getElementById('pointRange').addEventListener('change',
44 function() { 41 function() {
45 var value = document.getElementById('pointRange').value; 42 var value = parseFloat(document.getElementById('pointRange').value);
46 common.naclModule.postMessage('points: ' + value); 43 common.naclModule.postMessage({'message' : 'set_points',
44 'value' : value});
47 document.getElementById('pointCount').textContent = value + ' points'; 45 document.getElementById('pointCount').textContent = value + ' points';
48 }); 46 });
49 } 47 }
50 48
51 // Handle a message coming from the NaCl module. 49 // Handle a message coming from the NaCl module.
52 // In the Voronoi example, the only message will be the benchmark result. 50 // In the Voronoi example, the only message will be the benchmark result.
53 function handleMessage(message_event) { 51 function handleMessage(message_event) {
54 var x = (Math.round(message_event.data * 1000) / 1000).toFixed(3); 52 if (message_event.data['message'] == 'benchmark_result') {
55 document.getElementById('result').textContent = 53 var x = (Math.round(message_event.data['value'] * 1000) / 1000).toFixed(3);
56 'Result: ' + x + ' seconds'; 54 document.getElementById('result').textContent =
57 common.updateStatus('SUCCESS') 55 'Result: ' + x + ' seconds';
56 common.updateStatus('SUCCESS')
57 }
58 } 58 }
59 59
OLDNEW
« no previous file with comments | « no previous file | native_client_sdk/src/examples/demo/voronoi/voronoi.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698