generalize context proxying to support not just 2d contexts
This commit is contained in:
Родитель
5652d5678f
Коммит
e543d370ae
2
emcc
2
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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
// WebGLWorker client code
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// WebGLWorker worker code
|
||||
|
Загрузка…
Ссылка в новой задаче