Don't cast emscripten pointers when assembling WebGL interface

Since we are now referencing the exact methods instead of calling
GetProcAddress, there is no need to cast the function pointers. This
also catches a bug where the emscripten signatures for glWaitSync and
glClientWaitSync did not match the OpenGL API.

Change-Id: If365a8f6090961cb4b44146d87e102430bc5b30f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/320659
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/src/gpu/gl/GrGLAssembleWebGLInterfaceAutogen.cpp b/src/gpu/gl/GrGLAssembleWebGLInterfaceAutogen.cpp
index f47a03c..2cd1194 100644
--- a/src/gpu/gl/GrGLAssembleWebGLInterfaceAutogen.cpp
+++ b/src/gpu/gl/GrGLAssembleWebGLInterfaceAutogen.cpp
@@ -25,27 +25,33 @@
 #include "webgl/webgl2.h"
 #include "webgl/webgl2_ext.h"
 
-#define GET_PROC(F) functions->f##F = (GrGL##F##Fn*) &emscripten_gl##F
-#define GET_PROC_SUFFIX(F, S) functions->f##F = (GrGL##F##Fn*) &emscripten_gl##F##S
-#define GET_PROC_LOCAL(F) GrGL##F##Fn* F = (GrGL##F##Fn*) &emscripten_gl##F
+#define GET_PROC(F) functions->f##F = emscripten_gl##F
+#define GET_PROC_SUFFIX(F, S) functions->f##F = emscripten_gl##F##S
+
+// Adapter from standard GL signature to emscripten.
+void emscripten_glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) {
+    uint32_t timeoutLo = timeout;
+    uint32_t timeoutHi = timeout >> 32;
+    emscripten_glWaitSync(sync, flags, timeoutLo, timeoutHi);
+}
+
+// Adapter from standard GL signature to emscripten.
+GLenum emscripten_glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) {
+    uint32_t timeoutLo = timeout;
+    uint32_t timeoutHi = timeout >> 32;
+    return emscripten_glClientWaitSync(sync, flags, timeoutLo, timeoutHi);
+}
 
 sk_sp<const GrGLInterface> GrGLMakeAssembledWebGLInterface(void *ctx, GrGLGetProc get) {
-    GET_PROC_LOCAL(GetString);
-    if (nullptr == GetString) {
-        return nullptr;
-    }
-
-    const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION));
+    const char* verStr = reinterpret_cast<const char*>(emscripten_glGetString(GR_GL_VERSION));
     GrGLVersion glVer = GrGLGetVersionFromString(verStr);
-
     if (glVer < GR_GL_VER(1,0)) {
         return nullptr;
     }
 
-    GET_PROC_LOCAL(GetIntegerv);
-    GET_PROC_LOCAL(GetStringi);
     GrGLExtensions extensions;
-    if (!extensions.init(kWebGL_GrGLStandard, GetString, GetStringi, GetIntegerv)) {
+    if (!extensions.init(kWebGL_GrGLStandard, emscripten_glGetString, emscripten_glGetStringi,
+                         emscripten_glGetIntegerv)) {
         return nullptr;
     }
 
diff --git a/tools/gpu/gl/interface/templates.go b/tools/gpu/gl/interface/templates.go
index abf6049..4701aa2 100644
--- a/tools/gpu/gl/interface/templates.go
+++ b/tools/gpu/gl/interface/templates.go
@@ -175,27 +175,33 @@
 #include "webgl/webgl2.h"
 #include "webgl/webgl2_ext.h"
 
-#define GET_PROC(F) functions->f##F = (GrGL##F##Fn*) &emscripten_gl##F
-#define GET_PROC_SUFFIX(F, S) functions->f##F = (GrGL##F##Fn*) &emscripten_gl##F##S
-#define GET_PROC_LOCAL(F) GrGL##F##Fn* F = (GrGL##F##Fn*) &emscripten_gl##F
+#define GET_PROC(F) functions->f##F = emscripten_gl##F
+#define GET_PROC_SUFFIX(F, S) functions->f##F = emscripten_gl##F##S
+
+// Adapter from standard GL signature to emscripten.
+void emscripten_glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) {
+    uint32_t timeoutLo = timeout;
+    uint32_t timeoutHi = timeout >> 32;
+    emscripten_glWaitSync(sync, flags, timeoutLo, timeoutHi);
+}
+
+// Adapter from standard GL signature to emscripten.
+GLenum emscripten_glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) {
+    uint32_t timeoutLo = timeout;
+    uint32_t timeoutHi = timeout >> 32;
+    return emscripten_glClientWaitSync(sync, flags, timeoutLo, timeoutHi);
+}
 
 sk_sp<const GrGLInterface> GrGLMakeAssembledWebGLInterface(void *ctx, GrGLGetProc get) {
-    GET_PROC_LOCAL(GetString);
-    if (nullptr == GetString) {
-        return nullptr;
-    }
-
-    const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION));
+    const char* verStr = reinterpret_cast<const char*>(emscripten_glGetString(GR_GL_VERSION));
     GrGLVersion glVer = GrGLGetVersionFromString(verStr);
-
     if (glVer < GR_GL_VER(1,0)) {
         return nullptr;
     }
 
-    GET_PROC_LOCAL(GetIntegerv);
-    GET_PROC_LOCAL(GetStringi);
     GrGLExtensions extensions;
-    if (!extensions.init(kWebGL_GrGLStandard, GetString, GetStringi, GetIntegerv)) {
+    if (!extensions.init(kWebGL_GrGLStandard, emscripten_glGetString, emscripten_glGetStringi,
+                         emscripten_glGetIntegerv)) {
         return nullptr;
     }