Skip to content

[WIP] Multithreaded rendering #603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 116 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
ebcb05f
Bump libnode.a version
Nov 18, 2018
68e2339
Update build scripts to use node 11.2.0
Nov 18, 2018
8e0baae
Bugfix v8 TryCatch::StackTrace call
Nov 19, 2018
b061c51
Bump window-worker version
Nov 19, 2018
fccb4dd
Use native util TextEncoder/TextDecoder
Nov 19, 2018
d485e59
Remove dead window-text-encoding module from package.json
Nov 19, 2018
c2d89a8
Bump vm-one module version
Nov 20, 2018
36627f7
Bump vm-one module version
Nov 21, 2018
813a4ef
Bump vm-one module version
Nov 22, 2018
3af19ec
Bump vm-one module version
Nov 24, 2018
df8a619
Bugfix require typo
Nov 24, 2018
b7ef1f9
Remove prototype normalization from fetch implementation
Nov 25, 2018
1e24d2c
Remove dead oldUrl code
Nov 25, 2018
790539d
More fetch implementation cleanup
Nov 25, 2018
849993e
Remove prototype normalization from Response implementation
Nov 25, 2018
e2a97f0
Remove prototype normalization from Blob implementation
Nov 25, 2018
59f1db8
Remove prototype normalization from XMLHttpRequest implementation
Nov 25, 2018
b2d39e1
Remove prototype normalization from WebSocket implementation
Nov 25, 2018
1319f5f
Remove prototype normalization from http/ws implementation
Nov 25, 2018
9222ba4
Remove prototype normalization from magic leap implementation
Nov 25, 2018
47efb73
Remove dead utils._normalizePrototype
Nov 25, 2018
9872fca
Remove window _storeOriginalWindowPrototypes call
Nov 25, 2018
bcb34df
Spacing cleanup
Nov 25, 2018
119fd55
Begin to refactor window into VM
Nov 25, 2018
6db57a8
Remove exokit.{THREE,getAllGamepads}
Nov 25, 2018
3cc357c
Remove dead parseJson method
Nov 25, 2018
a677ad6
Bump vm-one module version
Nov 25, 2018
c40b558
Break out core.js window management into Window.js
Nov 25, 2018
9268bc0
Hook in new window vm construction into HTMLIFrameElement
Nov 25, 2018
1fc22b5
Remove Window.js exokit reference
Nov 25, 2018
08211d0
Remove duplicate Window.js autorun
Nov 25, 2018
827763f
Bugfix index.js THREE require
Nov 25, 2018
982245e
Bump vm-one module version
Nov 25, 2018
c1d8963
Bump vm-one module version
Nov 25, 2018
c9822f3
Clean up core export naming
Nov 26, 2018
30bb2a8
Remove dead core native module initialization code
Nov 26, 2018
b917f53
Comment out core main initialization
Nov 26, 2018
765827c
Core typo bugfix
Nov 26, 2018
d2044c5
Remove dead core variable
Nov 26, 2018
6b79994
Move window vm initialization code to WindowVm.js
Nov 26, 2018
2a74248
Small index native-bindings require cleanup
Nov 26, 2018
85a03e1
Comment out screenshotting code
Nov 26, 2018
5b555f8
Remove core setNativeBindingsModule call
Nov 26, 2018
cdbbc8e
Make index _bindWindow operate on window vm event emitter
Nov 26, 2018
7feeeee
Remove dead utils GlobalContext require
Dec 4, 2018
5a0dc6b
Move runHtml method to utils
Dec 4, 2018
a1bbf74
Dead code deletion in core.js
Dec 4, 2018
6aa0111
Move resources tracking into Document.js
Dec 4, 2018
e5d7d4b
Bugfix utils _fromAst references
Dec 4, 2018
3ccb347
Small DocumentFragment reference fix
Dec 4, 2018
4789bc2
Small Event Document reference fix
Dec 4, 2018
fd53abb
Remove dead Document/DocumentFragment references in Document.js
Dec 4, 2018
1cf30b7
Small Event.js reference cleanup
Dec 4, 2018
6a0311c
Remove dead WindowVm Document requires
Dec 4, 2018
a9b654a
Move parse document methods from Document to utils
Dec 4, 2018
25127ee
Remove dead core styleEpoch set
Dec 4, 2018
5163645
Localize styleEpoch to window
Dec 4, 2018
7d4a028
Bump vm-one module version
Dec 4, 2018
04cab82
Patch vm-one module usage in _makeWindowVm
Dec 4, 2018
9f931ed
Clean up WindowVm args initialization
Dec 5, 2018
4f3ce96
Bugfix DOM.js _makeWindowsVm reference
Dec 5, 2018
3b435fd
Patch more GlobalContext.args references
Dec 5, 2018
111ac3a
Clean up Window.js initialization
Dec 5, 2018
1113f5c
Add Window.js Worker initialization comment
Dec 5, 2018
11bc5e7
Add DOM.js native implementation note
Dec 5, 2018
9435072
Small Window.js cleanup
Dec 5, 2018
e1d55b5
More Window.js initialization bugfixing
Dec 5, 2018
c96391f
Clean up Window.js worker startup script injection
Dec 5, 2018
3354935
Remove dead GlobalContext reference in Document.js
Dec 6, 2018
71ac6fc
Remove bindings decoration from WindowsVm.js
Dec 6, 2018
fc8f0f2
Remove old bindings set native require code from Window.js
Dec 6, 2018
1fac67b
Remove vm-one/window-worker requires from natiive-bindings
Dec 6, 2018
7f7e73e
Add nativeRequire support in nativeBindings.js
Dec 6, 2018
f1a5479
Set native require for vm-one/window-worker
Dec 6, 2018
70f331e
Remove dead bindings.js
Dec 6, 2018
6c2917a
Wrap Window.js in IIFE
Dec 7, 2018
633a216
Add new Worker.js implementation
Dec 7, 2018
8eefe9c
Remove window-worker require
Dec 7, 2018
16cb00f
Small worker implementation cleanup
Dec 7, 2018
49ad1ee
Hook in new Worker implementation to Window.js
Dec 7, 2018
8d3e010
Add magic leap --experimental-worker start flag
Dec 7, 2018
0f67d02
Comment out temporary process.chdir
Dec 7, 2018
74b17b9
Add node 11 boot check
Dec 7, 2018
fa1f18d
Add --experimental-worker flag auto-add
Dec 7, 2018
8652e53
Bugfix Window.js VR.js require
Dec 7, 2018
cb6a078
Clean up DOM.js nativeBindings require
Dec 7, 2018
5dd6ea2
Major WindowVm dead code removal
Dec 7, 2018
f21e90a
More WindowVm dead code removal
Dec 7, 2018
aa81319
Remove dead Window.js bindings require
Dec 7, 2018
6bb7f16
Bump vm-one module version
Dec 7, 2018
4547660
Major native bindings set refactoring
Dec 7, 2018
2cada1e
Do version check only if running as main module
Dec 7, 2018
7dc1a93
Bugfixing VR bindings in index.js
Dec 7, 2018
72b0189
Major contexts contstruction refactor into internal Window
Dec 7, 2018
f98199f
Clean up frame logging implementation
Dec 7, 2018
5a1722d
Bugfix window Worker getters/setters
Dec 7, 2018
6adfdec
Clean up Worker onmessage/onerror handling
Dec 7, 2018
11937e6
Remove dead WindowVm displays tracking code
Dec 7, 2018
7171885
More WindowVm dead code removal
Dec 7, 2018
3f51dfa
Major WindowVm tickAnimationFrame work
Dec 7, 2018
146416a
Remove WindowVm comments
Dec 7, 2018
33016f9
Remove dead Window global bindings code
Dec 7, 2018
5542f98
Comment out Window postMessage binding
Dec 7, 2018
806fc61
Remove dead window destroyTimeouts call
Dec 7, 2018
18ffca5
More Window dead code removal
Dec 7, 2018
4ad4342
Major Window animation frame update work
Dec 7, 2018
9948600
Move windowsystem event handling to Window.js
Dec 7, 2018
d37b594
Revert "Move windowsystem event handling to Window.js"
Dec 7, 2018
9de8ed1
Temporarily move vr/ml management to Window.js
Dec 7, 2018
bdab5e8
Add window event handling to Window implementation
Dec 7, 2018
87cc13f
Add WindowVm postEvent support
Dec 7, 2018
21ed331
Add index.js postEvent routing
Dec 7, 2018
e1f5e7c
Add initial updateXrFrame routing
Dec 7, 2018
a7bffc4
Small Window updateXrFrame cleanup
Dec 7, 2018
bc9290f
Clean up index.js tickAnimationFrame routing
Dec 7, 2018
0546686
Replace index.js blit flow with WindowVm submitAnimationFrame flow
Dec 7, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ matrix:
- brew install glfw glew
install:
- npm install -g appdmg
- curl "https://nodejs.org/dist/v10.6.0/node-v10.6.0-darwin-x64.tar.gz" >node.tar.gz
- curl "https://nodejs.org/dist/v11.2.0/node-v11.2.0-darwin-x64.tar.gz" >node.tar.gz
- tar -zxf node.tar.gz
- rm node.tar.gz
- mv node-v10.6.0-darwin-x64 node
- mv node-v11.2.0-darwin-x64 node
- export PATH="$(pwd)/node/bin:$PATH"
- unset NVM_NODEJS_ORG_MIRROR
- "./node/bin/npm install"
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ ADD . /app
WORKDIR /app

RUN \
wget "https://nodejs.org/dist/v10.6.0/node-v10.6.0-linux-x64.tar.gz" -O node.tar.gz && \
wget "https://nodejs.org/dist/v11.2.0/node-v11.2.0-linux-x64.tar.gz" -O node.tar.gz && \
tar -zxf node.tar.gz && \
rm node.tar.gz && \
mv node-v10.6.0-linux-x64 node
mv node-v11.2.0-linux-x64 node
RUN \
export PATH="$PATH:$(pwd)/node/bin" && \
npm install --unsafe-perm . && \
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ test_script:

after_test:
- ps: |
wget "https://nodejs.org/dist/v10.6.0/node-v10.6.0-win-x64.zip" -OutFile node.zip
wget "https://nodejs.org/dist/v11.2.0/node-v11.2.0-win-x64.zip" -OutFile node.zip
7z x node.zip
rm node.zip
mv node-v10.6.0-win-x64 node
mv node-v11.2.0-win-x64 node
$env:Path = "$pwd\node;$env:Path";
.\node\npm install
.\node\npm run test:ci
Expand Down
2 changes: 1 addition & 1 deletion exokit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void callFunction(const char *funcname, const int argc, Local<Value> argv[]) {

if (result.IsEmpty()) {
String::Utf8Value error(try_catch.Exception());
String::Utf8Value stacktrace(try_catch.StackTrace());
String::Utf8Value stacktrace(try_catch.StackTrace(localContext).ToLocalChecked());
// LOGI("Error calling %s: %s:\n%s",funcname,*error,*stacktrace);
} else {
// LOGI("%s called",funcname);
Expand Down
37 changes: 34 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <errno.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <thread>
#include <v8.h>
Expand Down Expand Up @@ -97,9 +98,39 @@ const MLPrivilegeID privileges[] = {
MLPrivilegeID_NormalNotificationsUsage,
};

int Start(int argc, char **argv) {
size_t argc2 = argc + 1;
std::vector<char *> argv2(argc2);

char argsString[4096];
int index = 0;
for (int i = 0; i < 1; i++) {
char *dstArg = argsString + index;
const char *srcArg = argv[i];
strncpy(dstArg, srcArg, sizeof(argsString) - index);
argv2[i] = dstArg;
index += strlen(srcArg) + 1;
}

const char *experimentalWorkerString = "--experimental-worker";
char *experimentalWorkerArg = argsString + i;
strncpy(experimentalWorkerArg, experimentalWorkerString, sizeof(argsString) - i);
index += strlen(experimentalWorkerString) + 1;

for (int i = 1; i < argc; i++) {
char *dstArg = argsString + index;
const char *srcArg = argv[i];
strncpy(dstArg, srcArg, sizeof(argsString) - index);
argv2[i + 1] = dstArg;
index += strlen(srcArg) + 1;
}

return node::Start(argc2.data(), argv2);
}

int main(int argc, char **argv) {
if (argc > 1) {
return node::Start(argc, argv);
return Start(argc, argv);
}

registerDlibs(node::dlibs);
Expand Down Expand Up @@ -229,7 +260,7 @@ int main(int argc, char **argv) {
}
}

return node::Start(argc, argv);
return Start(argc, argv);
} else {
const char *jsString;
if (access("/package/app/index.html", F_OK) != -1) {
Expand Down Expand Up @@ -258,7 +289,7 @@ int main(int argc, char **argv) {
char *argv[] = {nodeArg, dotArg, jsArg};
size_t argc = sizeof(argv) / sizeof(argv[0]);

return node::Start(argc, argv);
return Start(argc, argv);
}
} else { // child
ML_LOG_TAG(Info, LOG_TAG, "---------------------exokit start 1");
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"history": "^4.7.2",
"isolator": "0.0.9",
"leapmotion": "0.0.4",
"libnode.a": "0.0.1",
"libnode.a": "0.0.2",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"nan": "^2.10.0",
Expand All @@ -73,13 +73,11 @@
"repl.history": "^0.1.4",
"rimraf": "^2.6.2",
"upng-js": "^2.1.0",
"vm-one": "0.0.22",
"vm-one": "0.0.31",
"webgl-to-opengl": "0.0.12",
"window-classlist": "0.0.4",
"window-fetch": "0.0.9",
"window-selector": "0.0.5",
"window-text-encoding": "0.0.2",
"window-worker": "0.0.98",
"window-xhr": "0.0.20",
"ws": "^6.0.0"
},
Expand Down
49 changes: 27 additions & 22 deletions src/DOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ const selector = require('window-selector');
const url = require('url');
const util = require('util');

const bindings = require('./bindings');
const nativeBindings = require('./native-bindings');
const {defaultCanvasSize} = require('./constants');
const {Event, EventTarget, MouseEvent, ErrorEvent} = require('./Event');
const GlobalContext = require('./GlobalContext');
const {_makeWindowVm} = require('./WindowVm');
const symbols = require('./symbols');
const urls = require('./urls').urls;
const utils = require('./utils');
Expand Down Expand Up @@ -699,7 +700,7 @@ class Element extends Node {
})
.childNodes
.map(childNode =>
GlobalContext._fromAST(childNode, this.ownerDocument.defaultView, this, this.ownerDocument, true)
utils._fromAST(childNode, this.ownerDocument.defaultView, this, this.ownerDocument, true)
);
switch (position) {
case 'beforebegin': {
Expand Down Expand Up @@ -950,7 +951,7 @@ class Element extends Node {
})
.childNodes
.map(childNode =>
GlobalContext._fromAST(childNode, this.ownerDocument.defaultView, this, this.ownerDocument, true)
utils._fromAST(childNode, this.ownerDocument.defaultView, this, this.ownerDocument, true)
)
);
this.childNodes = newChildNodes;
Expand All @@ -962,7 +963,7 @@ class Element extends Node {
this._emit('children', newChildNodes, oldChildNodes, null, null);
this.ownerDocument._emit('domchange');

_promiseSerial(newChildNodes.map(childNode => () => GlobalContext._runHtml(childNode, this.ownerDocument.defaultView)))
_promiseSerial(newChildNodes.map(childNode => () => utils._runHtml(childNode, this.ownerDocument.defaultView)))
.catch(err => {
console.warn(err);
});
Expand Down Expand Up @@ -1372,7 +1373,7 @@ class HTMLStyleElement extends HTMLLoadableElement {
.then(() => css.parse(innerHTML).stylesheet)
.then(stylesheet => {
this.stylesheet = stylesheet;
GlobalContext.styleEpoch++;
this.ownerDocument.defaultView[styleEpochSymbol]++;
this.dispatchEvent(new Event('load', {target: this}));
})
.catch(err => {
Expand Down Expand Up @@ -1438,7 +1439,7 @@ class HTMLLinkElement extends HTMLLoadableElement {
.then(s => css.parse(s).stylesheet)
.then(stylesheet => {
this.stylesheet = stylesheet;
GlobalContext.styleEpoch++;
this.ownerDocument.defaultView[styleEpochSymbol]++;

this.readyState = 'complete';

Expand Down Expand Up @@ -1816,6 +1817,9 @@ class HTMLIFrameElement extends HTMLSrcableElement {

this.contentWindow = null;
this.contentDocument = null;

// non-standard
this.vm = null;
this.live = true;
this.xrOffset = {
position: new Float32Array(3),
Expand Down Expand Up @@ -1848,23 +1852,24 @@ class HTMLIFrameElement extends HTMLSrcableElement {
const options = parentWindow[symbols.optionsSymbol];

url = utils._makeNormalizeUrl(options.baseUrl)(url);
const contentWindow = GlobalContext._makeWindow({
/* const contentWindow = GlobalContext._makeWindowVm(htmlString, {
url,
baseUrl: url,
dataPath: options.dataPath,
}, parentWindow, parentWindow.top);
const contentDocument = GlobalContext._parseDocument(htmlString, contentWindow);
});
const contentDocument = utils._parseDocument(htmlString, contentWindow);
contentDocument.hidden = this.hidden;
contentDocument.xrOffset = this.xrOffset;

contentWindow.document = contentDocument;

this.contentWindow = contentWindow;
this.contentDocument = contentDocument;
contentWindow.document = contentDocument; */

contentWindow.on('destroy', e => {
parentWindow.emit('destroy', e);
this.vm = _makeWindowVm(htmlString, {
url,
baseUrl: url,
dataPath: options.dataPath,
});
this.contentWindow = {};
this.contentDocument = {};

this.readyState = 'complete';

Expand Down Expand Up @@ -2015,15 +2020,15 @@ class HTMLCanvasElement extends HTMLElement {
this._context = null;
}
if (this._context === null) {
this._context = new GlobalContext.CanvasRenderingContext2D(this);
this._context = new GlobalContext.CanvasRenderingContext2D(this); // XXX latch lative
}
} else if (contextType === 'webgl' || contextType === 'webgl2' || contextType === 'xrpresent') {
if (this._context && this._context.constructor && this._context.constructor.name !== 'WebGLRenderingContext' && this._context.constructor.name !== 'WebGL2RenderingContext') {
this._context.destroy();
this._context = null;
}
if (this._context === null) {
if (GlobalContext.args.webgl === '1') {
if (global.args.webgl === '1') {
if (contextType === 'webgl' || contextType === 'xrpresent') {
this._context = new WebGLRenderingContext(this);
}
Expand Down Expand Up @@ -2065,7 +2070,7 @@ class HTMLTemplateElement extends HTMLElement {
}

get content() {
const content = new GlobalContext.DocumentFragment();
const content = new this.ownerDocument.defaultView.DocumentFragment();
content.ownerDocument = this.ownerDocument;
content.childNodes = new NodeList(this._childNodes);
return content;
Expand Down Expand Up @@ -2210,7 +2215,7 @@ class HTMLImageElement extends HTMLSrcableElement {
const [attrs = [], value = '', location = null] = arguments;
super('IMG', attrs, value, location);

this.image = new bindings.nativeImage();
this.image = new nativeBindings.nativeImage();

this.on('attribute', (name, value) => {
if (name === 'src' && value) {
Expand Down Expand Up @@ -2335,7 +2340,7 @@ class HTMLAudioElement extends HTMLMediaElement {
super('AUDIO', attrs, value);

this.readyState = HTMLMediaElement.HAVE_NOTHING;
this.audio = new bindings.nativeAudio.Audio();
this.audio = new nativeBindings.nativeAudio.Audio();

this.on('attribute', (name, value) => {
if (name === 'src' && value) {
Expand Down Expand Up @@ -2451,7 +2456,7 @@ class HTMLVideoElement extends HTMLMediaElement {

if (urls.has(value)) {
const blob = urls.get(value);
if (blob instanceof Bindings.bindings.nativeVideo.VideoDevice) {
if (blob instanceof nativeBindings.nativeVideo.VideoDevice) {
this.video = blob;
}
}
Expand Down Expand Up @@ -2552,7 +2557,7 @@ class HTMLVideoElement extends HTMLMediaElement {
super('VIDEO', attrs, value);

this.readyState = HTMLMediaElement.HAVE_NOTHING;
this.video = new bindings.nativeVideo.Video();
this.video = new nativeBindings.nativeVideo.Video();

this.on('attribute', (name, value) => {
if (name === 'src' && value) {
Expand Down
Loading