summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-06-05 16:04:03 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-06-05 16:04:03 -0700
commite543d370ae643bba784002a93e283591573ab252 (patch)
tree1ebd7ce49bbc1f21af1ebd4c5b1e4bb41fba4689
parent5652d5678fc9bda3cecd9431e77063bc90755b58 (diff)
generalize context proxying to support not just 2d contexts
-rwxr-xr-xemcc2
-rw-r--r--src/jsifier.js1
-rw-r--r--src/proxyClient.js7
-rw-r--r--src/proxyWorker.js40
-rw-r--r--src/webGLClient.js2
-rw-r--r--src/webGLWorker.js2
6 files changed, 33 insertions, 21 deletions
diff --git a/emcc b/emcc
index 5e57bc37..9f3eb154 100755
--- a/emcc
+++ b/emcc
@@ -1830,7 +1830,7 @@ try:
js_target = unsuffixed(target) + '.js'
base_js_target = os.path.basename(js_target)
if proxy_to_worker:
- html.write(shell.replace('{{{ SCRIPT }}}', '<script>' + open(shared.path_from_root('src', 'proxyClient.js')).read().replace('{{{ filename }}}', target_basename) + '</script>'))
+ html.write(shell.replace('{{{ SCRIPT }}}', '<script>' + open(shared.path_from_root('src', 'webGLClient.js')).read() + '\n' + open(shared.path_from_root('src', 'proxyClient.js')).read().replace('{{{ filename }}}', target_basename) + '</script>'))
shutil.move(final, js_target)
elif not Compression.on:
# Normal code generation path
diff --git a/src/jsifier.js b/src/jsifier.js
index 791273f4..e35fef1a 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -1899,6 +1899,7 @@ function JSify(data, functionsOnly) {
print('}');
}
if (PROXY_TO_WORKER) {
+ print(read('webGLWorker.js'));
print(read('proxyWorker.js'));
}
if (RUNTIME_TYPE_INFO) {
diff --git a/src/proxyClient.js b/src/proxyClient.js
index 2d1c76fe..5adc2917 100644
--- a/src/proxyClient.js
+++ b/src/proxyClient.js
@@ -1,8 +1,6 @@
// proxy to/from worker
-Module.ctx = Module.canvas.getContext('2d');
-
// render
var renderFrameData = null;
@@ -31,6 +29,7 @@ var worker = new Worker('{{{ filename }}}.js');
var workerResponded = false;
worker.onmessage = function worker_onmessage(event) {
+ //console.log(JSON.stringify(event.data));
if (!workerResponded) {
workerResponded = true;
if (Module.setStatus) Module.setStatus('');
@@ -52,6 +51,10 @@ worker.onmessage = function worker_onmessage(event) {
}
case 'canvas': {
switch (data.op) {
+ case 'getContext': {
+ Module.ctx = Module.canvas.getContext(data.type);
+ break;
+ }
case 'resize': {
Module.canvas.width = data.width;
Module.canvas.height = data.height;
diff --git a/src/proxyWorker.js b/src/proxyWorker.js
index cfe0c26e..225b4493 100644
--- a/src/proxyWorker.js
+++ b/src/proxyWorker.js
@@ -43,24 +43,28 @@ document.createElement = function document_createElement(what) {
}
};
canvas.getContext = function canvas_getContext(type) {
- assert(type == '2d');
- return {
- getImageData: function(x, y, w, h) {
- assert(x == 0 && y == 0 && w == canvas.width && h == canvas.height);
- canvas.ensureData();
- return {
- width: canvas.data.width,
- height: canvas.data.height,
- data: new Uint8Array(canvas.data.data) // TODO: can we avoid this copy?
- };
- },
- putImageData: function(image, x, y) {
- canvas.ensureData();
- assert(x == 0 && y == 0 && image.width == canvas.width && image.height == canvas.height);
- canvas.data.data.set(image.data); // TODO: can we avoid this copy?
- postMessage({ target: 'canvas', op: 'render', image: canvas.data });
- }
- };
+ postMessage({ target: 'canvas', op: 'getContext', type: type });
+ if (type === '2d') {
+ return {
+ getImageData: function(x, y, w, h) {
+ assert(x == 0 && y == 0 && w == canvas.width && h == canvas.height);
+ canvas.ensureData();
+ return {
+ width: canvas.data.width,
+ height: canvas.data.height,
+ data: new Uint8Array(canvas.data.data) // TODO: can we avoid this copy?
+ };
+ },
+ putImageData: function(image, x, y) {
+ canvas.ensureData();
+ assert(x == 0 && y == 0 && image.width == canvas.width && image.height == canvas.height);
+ canvas.data.data.set(image.data); // TODO: can we avoid this copy?
+ postMessage({ target: 'canvas', op: 'render', image: canvas.data });
+ }
+ };
+ } else {
+ return new WebGLWorker();
+ }
};
canvas.boundingClientRect = {};
canvas.getBoundingClientRect = function canvas_getBoundingClientRect() {
diff --git a/src/webGLClient.js b/src/webGLClient.js
new file mode 100644
index 00000000..8828f181
--- /dev/null
+++ b/src/webGLClient.js
@@ -0,0 +1,2 @@
+// WebGLWorker client code
+
diff --git a/src/webGLWorker.js b/src/webGLWorker.js
new file mode 100644
index 00000000..5ea68f73
--- /dev/null
+++ b/src/webGLWorker.js
@@ -0,0 +1,2 @@
+// WebGLWorker worker code
+