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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | native_client_sdk/src/examples/demo/voronoi/voronoi.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: native_client_sdk/src/examples/demo/voronoi/example.js
===================================================================
--- native_client_sdk/src/examples/demo/voronoi/example.js (revision 208236)
+++ native_client_sdk/src/examples/demo/voronoi/example.js (working copy)
@@ -7,7 +7,8 @@
function postThreadFunc(numThreads) {
return function () {
- common.naclModule.postMessage('threads: ' + numThreads);
+ common.naclModule.postMessage({'message' : 'set_threads',
+ 'value' : numThreads});
}
}
@@ -16,34 +17,31 @@
function attachListeners() {
document.getElementById('benchmark').addEventListener('click',
function() {
- common.naclModule.postMessage('run benchmark');
+ common.naclModule.postMessage({'message' : 'run_benchmark'});
common.updateStatus('BENCHMARKING... (please wait)');
});
document.getElementById('drawPoints').addEventListener('click',
function() {
var checked = document.getElementById('drawPoints').checked;
- if (checked)
- common.naclModule.postMessage('with points');
- else
- common.naclModule.postMessage('without points');
+ common.naclModule.postMessage({'message' : 'draw_points',
+ 'value' : checked});
});
document.getElementById('drawInteriors').addEventListener('click',
function() {
var checked = document.getElementById('drawInteriors').checked;
- if (checked)
- common.naclModule.postMessage('with interiors');
- else
- common.naclModule.postMessage('without interiors');
+ common.naclModule.postMessage({'message' : 'draw_interiors',
+ 'value' : checked});
});
var threads = [0, 1, 2, 4, 6, 8, 12, 16, 24, 32];
for (var i = 0; i < threads.length; i++) {
- document.getElementById('radio'+i).addEventListener('click',
+ document.getElementById('radio' + i).addEventListener('click',
postThreadFunc(threads[i]));
}
document.getElementById('pointRange').addEventListener('change',
function() {
- var value = document.getElementById('pointRange').value;
- common.naclModule.postMessage('points: ' + value);
+ var value = parseFloat(document.getElementById('pointRange').value);
+ common.naclModule.postMessage({'message' : 'set_points',
+ 'value' : value});
document.getElementById('pointCount').textContent = value + ' points';
});
}
@@ -51,9 +49,11 @@
// Handle a message coming from the NaCl module.
// In the Voronoi example, the only message will be the benchmark result.
function handleMessage(message_event) {
- var x = (Math.round(message_event.data * 1000) / 1000).toFixed(3);
- document.getElementById('result').textContent =
- 'Result: ' + x + ' seconds';
- common.updateStatus('SUCCESS')
+ if (message_event.data['message'] == 'benchmark_result') {
+ var x = (Math.round(message_event.data['value'] * 1000) / 1000).toFixed(3);
+ document.getElementById('result').textContent =
+ 'Result: ' + x + ' seconds';
+ common.updateStatus('SUCCESS')
+ }
}
« 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