Skip to content

Commit 5c9c390

Browse files
authored
Cleanup handleWebGLProxying. NFC (#24793)
The check here was changed from `SHARED_MEMORY` to `PTHREADS` since wasm workers don't support proxying.
1 parent ec93a04 commit 5c9c390

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

src/lib/libhtml5_webgl.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -545,45 +545,45 @@ var LibraryHtml5WebGL = {
545545
emscripten_webgl_get_parameter_i64v: (param, dst) => writeI53ToI64(dst, GLctx.getParameter(param)),
546546
};
547547

548-
function handleWebGLProxying(funcs) {
549-
#if SHARED_MEMORY
550-
// Process 'sync_on_webgl_context_handle_thread' and 'sync_on_current_webgl_context_thread' pseudo-proxying modes
551-
// to appropriate proxying mechanism, either proxying on-demand, unconditionally, or never, depending on build modes.
552-
// 'sync_on_webgl_context_handle_thread' is used for function signatures that take a HTML5 WebGL context handle
553-
// object as the first argument. 'sync_on_current_webgl_context_thread' is used for functions that operate on the
554-
// implicit "current WebGL context" as activated via emscripten_webgl_make_current() function.
555548

549+
function handleWebGLProxying(funcs) {
550+
#if PTHREADS
551+
// Process 'sync_on_webgl_context_handle_thread' and
552+
// 'sync_on_current_webgl_context_thread' pseudo-proxying modes to appropriate
553+
// proxying mechanism, either proxying on-demand, unconditionally, or never,
554+
// depending on build modes.
555+
// 'sync_on_webgl_context_handle_thread' is used for function signatures that
556+
// take a HTML5 WebGL context handle object as the first argument.
557+
// 'sync_on_current_webgl_context_thread' is used for functions that operate on
558+
// the implicit "current WebGL context" as activated via
559+
// emscripten_webgl_make_current() function.
556560
function listOfNFunctionArgs(func) {
557-
var args = [];
561+
const args = [];
558562
for (var i = 0; i < func.length; ++i) {
559563
args.push('p' + i);
560564
}
561565
return args;
562566
}
563567

564-
var targetingOffscreenCanvas, targetingOffscreenFramebuffer;
565-
#if OFFSCREENCANVAS_SUPPORT
566-
targetingOffscreenCanvas = true;
567-
#endif
568-
#if OFFSCREEN_FRAMEBUFFER
569-
targetingOffscreenFramebuffer = true;
570-
#endif
568+
const targetingOffscreenCanvas = {{{ OFFSCREENCANVAS_SUPPORT }}};
569+
const targetingOffscreenFramebuffer = {{{ OFFSCREEN_FRAMEBUFFER }}};
571570

572-
for (var i in funcs) {
571+
for (const i in funcs) {
573572
// Is this a function that takes GL context handle as first argument?
574-
var proxyContextHandle = funcs[i + '__proxy'] == 'sync_on_webgl_context_handle_thread';
573+
const proxyContextHandle = funcs[i + '__proxy'] == 'sync_on_webgl_context_handle_thread';
575574

576575
// Is this a function that operates on the implicit current GL context object?
577-
var proxyCurrentContext = funcs[i + '__proxy'] == 'sync_on_current_webgl_context_thread';
576+
const proxyCurrentContext = funcs[i + '__proxy'] == 'sync_on_current_webgl_context_thread';
578577

579578
if (!proxyContextHandle && !proxyCurrentContext) {
580579
continue; // no resolving of pseudo-proxying needed for this function.
581580
}
582581

583582
if (targetingOffscreenCanvas && (targetingOffscreenFramebuffer || proxyContextHandle)) {
584-
// Dynamically check at runtime whether the current thread owns the GL context handle/current GL context
585-
// object. If not, proxy the call to main thread.
586-
// TODO: this handles the calling pthread and main thread cases, but not yet the case from pthread->pthread.
583+
// Dynamically check at runtime whether the current thread owns the GL context
584+
// handle/current GL context object. If not, proxy the call to main thread.
585+
// TODO: this handles the calling pthread and main thread cases, but not yet
586+
// the case from pthread->pthread.
587587
const sig = funcs[i + '__sig'] || LibraryManager.library[i + '__sig']
588588
assert(sig);
589589
funcs[i + '_calling_thread'] = funcs[i];
@@ -594,10 +594,10 @@ function handleWebGLProxying(funcs) {
594594
funcs[i + '__deps'].push(i + '_calling_thread');
595595
funcs[i + '__deps'].push(i + '_main_thread');
596596
delete funcs[i + '__proxy'];
597-
var funcArgs = listOfNFunctionArgs(funcs[i]);
598-
var funcArgsString = funcArgs.join(',');
599-
var retStatement = sig[0] != 'v' ? 'return' : '';
600-
var contextCheck = proxyContextHandle ? 'GL.contexts[p0]' : 'GLctx';
597+
const funcArgs = listOfNFunctionArgs(funcs[i]);
598+
const funcArgsString = funcArgs.join(',');
599+
const retStatement = sig[0] != 'v' ? 'return' : '';
600+
const contextCheck = proxyContextHandle ? 'GL.contexts[p0]' : 'GLctx';
601601
var funcBody = `${retStatement} ${contextCheck} ? _${i}_calling_thread(${funcArgsString}) : _${i}_main_thread(${funcArgsString});`;
602602
if (funcs[i + '_before_on_calling_thread']) {
603603
funcs[i + '__deps'].push('$' + i + '_before_on_calling_thread');
@@ -606,8 +606,8 @@ function handleWebGLProxying(funcs) {
606606
funcArgs.push(funcBody);
607607
funcs[i] = new (Function.prototype.bind.call(Function, Function, ...funcArgs));
608608
} else if (targetingOffscreenFramebuffer) {
609-
// When targeting only OFFSCREEN_FRAMEBUFFER, unconditionally proxy all GL calls to
610-
// main thread.
609+
// When targeting only OFFSCREEN_FRAMEBUFFER, unconditionally proxy all GL
610+
// calls to main thread.
611611
funcs[i + '__proxy'] = 'sync';
612612
} else {
613613
// Building without OFFSCREENCANVAS_SUPPORT or OFFSCREEN_FRAMEBUFFER; or building
@@ -620,10 +620,10 @@ function handleWebGLProxying(funcs) {
620620
#else
621621
// In single threaded mode just delete our custom __proxy addributes, otherwise
622622
// they will causes errors in the JS compiler.
623-
for (var i in funcs) {
623+
for (const i in funcs) {
624624
delete funcs[i + '__proxy'];
625625
}
626-
#endif // SHARED_MEMORY
626+
#endif // PTHREADS
627627
}
628628

629629
handleWebGLProxying(LibraryHtml5WebGL);

0 commit comments

Comments
 (0)