Skip to content

Commit c147cce

Browse files
author
Avaer Kazmer
authored
Merge pull request #1330 from exokitxr/sync-contextless
Sync contextless 2d iframes
2 parents b8b06a1 + 892d0fa commit c147cce

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

deps/exokit-bindings/egl/src/egl.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ void SetCurrentWindowContext(NATIVEwindow *window) {
115115
}
116116
} */
117117

118+
NAN_METHOD(HasCurrentWindowContext) {
119+
info.GetReturnValue().Set(JS_BOOL(currentWindow != nullptr));
120+
}
121+
122+
NAN_METHOD(GetCurrentWindowContext) {
123+
if (currentWindow != nullptr) {
124+
info.GetReturnValue().Set(pointerToArray(currentWindow));
125+
} else {
126+
info.GetReturnValue().Set(Nan::Null());
127+
}
128+
}
129+
118130
NAN_METHOD(SetCurrentWindowContext) {
119131
NATIVEwindow *window = (NATIVEwindow *)arrayToPointer(Local<Array>::Cast(info[0]));
120132
SetCurrentWindowContext(window);
@@ -422,6 +434,8 @@ Local<Object> makeWindow() {
422434
Nan::SetMethod(target, "setClipboard", egl::SetClipboard);
423435
Nan::SetMethod(target, "blitTopFrameBuffer", egl::BlitTopFrameBuffer);
424436
Nan::SetMethod(target, "blitChildFrameBuffer", egl::BlitChildFrameBuffer);
437+
Nan::SetMethod(target, "hasCurrentWindowContext", egl::HasCurrentWindowContext);
438+
Nan::SetMethod(target, "getCurrentWindowContext", egl::GetCurrentWindowContext);
425439
Nan::SetMethod(target, "setCurrentWindowContext", egl::SetCurrentWindowContext);
426440

427441
return scope.Escape(target);

deps/exokit-bindings/glfw/src/glfw.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,18 @@ void ReadPixels(WebGLRenderingContext *gl, unsigned int fbo, int x, int y, int w
942942
}
943943
}
944944

945+
NAN_METHOD(HasCurrentWindowContext) {
946+
info.GetReturnValue().Set(JS_BOOL(currentWindow != nullptr));
947+
}
948+
949+
NAN_METHOD(GetCurrentWindowContext) {
950+
if (currentWindow != nullptr) {
951+
info.GetReturnValue().Set(pointerToArray(currentWindow));
952+
} else {
953+
info.GetReturnValue().Set(Nan::Null());
954+
}
955+
}
956+
945957
NAN_METHOD(SetCurrentWindowContext) {
946958
NATIVEwindow *window = (NATIVEwindow *)arrayToPointer(Local<Array>::Cast(info[0]));
947959
SetCurrentWindowContext(window);
@@ -1758,6 +1770,8 @@ Local<Object> makeWindow() {
17581770
Nan::SetMethod(target, "setClipboard", glfw::SetClipboard);
17591771
Nan::SetMethod(target, "blitTopFrameBuffer", glfw::BlitTopFrameBuffer);
17601772
Nan::SetMethod(target, "blitChildFrameBuffer", glfw::BlitChildFrameBuffer);
1773+
Nan::SetMethod(target, "hasCurrentWindowContext", glfw::HasCurrentWindowContext);
1774+
Nan::SetMethod(target, "getCurrentWindowContext", glfw::GetCurrentWindowContext);
17611775
Nan::SetMethod(target, "setCurrentWindowContext", glfw::SetCurrentWindowContext);
17621776
#ifdef MAIN_THREAD_POLLING
17631777
Nan::SetMethod(target, "pollEvents", glfw::PollEvents);

src/Window.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,15 +1000,20 @@ const _makeRequestAnimationFrame = window => (fn, priority = 0) => {
10001000
const _waitLocalSyncs = syncs => {
10011001
if (vrPresentState.glContext) {
10021002
nativeWindow.setCurrentWindowContext(vrPresentState.glContext.getWindowHandle());
1003-
10041003
for (let i = 0; i < syncs.length; i++) {
10051004
const sync = syncs[i];
10061005
nativeWindow.waitSync(sync);
10071006
prevSyncs.push(sync);
10081007
}
1008+
return [];
10091009
} else {
1010-
for (let i = 0; i < syncs.length; i++) {
1011-
nativeWindow.deleteSync(syncs[i]);
1010+
if (nativeWindow.hasCurrentWindowContext()) {
1011+
for (let i = 0; i < syncs.length; i++) {
1012+
nativeWindow.deleteSync(syncs[i]);
1013+
}
1014+
return [];
1015+
} else {
1016+
return syncs;
10121017
}
10131018
}
10141019
};
@@ -1118,12 +1123,13 @@ const _makeRequestAnimationFrame = window => (fn, priority = 0) => {
11181123
}
11191124
}
11201125

1121-
return Promise.resolve(syncs);
1126+
return syncs;
11221127
};
11231128
const _renderLocal = (syncs, layered) => {
1124-
_waitLocalSyncs(syncs);
1129+
syncs = _waitLocalSyncs(syncs);
11251130
_tickLocalRafs();
1126-
return _composeLocalLayers(layered);
1131+
syncs.push.apply(syncs, _composeLocalLayers(layered));
1132+
return Promise.resolve(syncs);
11271133
};
11281134
const _makeRenderChild = window => (syncs, layered) => window.runAsync({
11291135
method: 'tickAnimationFrame',

0 commit comments

Comments
 (0)