summaryrefslogtreecommitdiff
path: root/src/proxyWorker.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/proxyWorker.js')
-rw-r--r--src/proxyWorker.js40
1 files changed, 22 insertions, 18 deletions
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() {