Skip to content

Commit fa24df9

Browse files
authored
Fix asynchronous GLUT main loop utilizing tests that raced against reftest XHR. (#24575)
1 parent faa2069 commit fa24df9

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

test/float_tex.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include <assert.h>
77
#include <math.h>
88
#include <stdio.h>
9+
#ifdef __EMSCRIPTEN__
10+
#include <emscripten.h>
11+
#endif
912

1013
#define GL_GLEXT_PROTOTYPES
1114
#define EGL_EGLEXT_PROTOTYPES
@@ -99,6 +102,9 @@ static void glut_draw_callback(void) {
99102
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL);
100103
glDrawArrays(GL_POINTS, 0, NUM_NODES);
101104
glutSwapBuffers();
105+
#ifdef __EMSCRIPTEN__
106+
EM_ASM({reftestUnblock()}); // All done, perform the JS side image comparison reftest.
107+
#endif
102108
}
103109

104110
GLuint createShader(const char source[], int type) {
@@ -160,6 +166,11 @@ int main(int argc, char *argv[]) {
160166
/* Set up glut callback functions */
161167
glutDisplayFunc(glut_draw_callback);
162168
gl_init();
169+
#ifdef __EMSCRIPTEN__
170+
// This test kicks off an asynchronous glutMainLoop(), so do not perform a synchronous
171+
// reftest immediately after falling out from main.
172+
EM_ASM({reftestBlock()});
173+
#endif
163174
glutMainLoop();
164175
return 0;
165176
}

test/gl_subdata.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include <stdio.h>
88
#include <string.h>
99

10+
#ifdef __EMSCRIPTEN__
11+
#include <emscripten.h>
12+
#endif
13+
1014
#define GL_GLEXT_PROTOTYPES
1115
#define EGL_EGLEXT_PROTOTYPES
1216
#include <GL/gl.h>
@@ -99,6 +103,9 @@ static void glut_draw_callback(void) {
99103
glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL);
100104
glDrawArrays(GL_POINTS, 0, NUM_NODES);
101105
glutSwapBuffers();
106+
#ifdef __EMSCRIPTEN__
107+
EM_ASM({reftestUnblock()}); // All done, perform the JS side image comparison reftest.
108+
#endif
102109
}
103110

104111
GLuint createShader(const char* source, int type) {
@@ -155,6 +162,11 @@ int main(int argc, char *argv[]) {
155162
/* Set up glut callback functions */
156163
glutDisplayFunc(glut_draw_callback);
157164
gl_init();
165+
#ifdef __EMSCRIPTEN__
166+
// This test kicks off an asynchronous glutMainLoop(), so do not perform a synchronous
167+
// reftest immediately after falling out from main.
168+
EM_ASM({reftestBlock()});
169+
#endif
158170
glutMainLoop();
159171
return 0;
160172
}

test/hello_world_gles.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,9 @@ gears_draw(void)
549549
draw_gear(gear3, transform, -3.1, 4.2, -2 * angle - 25.0, blue);
550550

551551
glutSwapBuffers();
552+
#ifdef __EMSCRIPTEN__
553+
EM_ASM({if (typeof reftestUnblock !== 'undefined') reftestUnblock()}); // All done, perform the JS side image comparison reftest.
554+
#endif
552555

553556
#ifdef LONGTEST
554557
glutPostRedisplay(); // check for issues with not throttling calls
@@ -773,6 +776,11 @@ main(int argc, char *argv[])
773776
/* Initialize the gears */
774777
gears_init();
775778

779+
#ifdef __EMSCRIPTEN__
780+
// This test kicks off an asynchronous glutMainLoop(), so do not perform a synchronous
781+
// reftest immediately after falling out from main.
782+
EM_ASM({if (typeof reftestBlock !== 'undefined') reftestBlock()});
783+
#endif
776784
glutMainLoop();
777785

778786
return 0;

test/hello_world_gles_deriv.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
#include <string.h>
4747
#include <sys/time.h>
4848
#include <unistd.h>
49+
#ifdef __EMSCRIPTEN__
50+
#include <emscripten.h>
51+
#endif
4952
#ifdef __APPLE__
5053
#include <OpenGL/gl.h>
5154
#include <Glut/glut.h>
@@ -541,6 +544,9 @@ gears_draw(void)
541544
draw_gear(gear3, transform, -3.1, 4.2, -2 * angle - 25.0, blue);
542545

543546
glutSwapBuffers();
547+
#ifdef __EMSCRIPTEN__
548+
EM_ASM({if (typeof reftestUnblock !== 'undefined') reftestUnblock()}); // All done, perform the JS side image comparison reftest.
549+
#endif
544550
}
545551

546552
/**
@@ -730,6 +736,11 @@ main(int argc, char *argv[])
730736
/* Initialize the gears */
731737
gears_init();
732738

739+
#ifdef __EMSCRIPTEN__
740+
// This test kicks off an asynchronous glutMainLoop(), so do not perform a synchronous
741+
// reftest immediately after falling out from main.
742+
EM_ASM({if (typeof reftestBlock !== 'undefined') reftestBlock()});
743+
#endif
733744
glutMainLoop();
734745

735746
return 0;

test/hello_world_gles_proxy.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#include <string.h>
4848
#include <sys/time.h>
4949
#include <unistd.h>
50+
#ifdef __EMSCRIPTEN__
51+
#include <emscripten.h>
52+
#endif
5053
#ifdef __APPLE__
5154
#include <OpenGL/gl.h>
5255
#include <Glut/glut.h>
@@ -559,12 +562,17 @@ gears_draw(void)
559562
draw_gear(gear3, transform, -3.1, 4.2, -2 * angle - 25.0, blue);
560563

561564
glutSwapBuffers();
565+
#ifdef __EMSCRIPTEN__
566+
EM_ASM({if (typeof reftestUnblock !== 'undefined') reftestUnblock()}); // All done, perform the JS side image comparison reftest.
567+
#endif
562568

563569
#ifdef LONGTEST
564570
glutPostRedisplay(); // check for issues with not throttling calls
565571
#endif
566572

573+
#ifdef __EMSCRIPTEN__
567574
EM_ASM({ window.close() });
575+
#endif
568576
}
569577

570578
/**
@@ -758,7 +766,7 @@ main(int argc, char *argv[])
758766
// Don't trigger the reftest immediately after main finishes,
759767
// this test uses rAF to perform rendering, so let it trigger
760768
// the reftest after having rendered some frames.
761-
EM_ASM(Module['postRun'] = undefined);
769+
EM_ASM({if (typeof reftestBlock !== 'undefined') reftestBlock()});
762770
#endif
763771

764772
/* Initialize the window */

0 commit comments

Comments
 (0)