1 /*
2  * Copyright 2020 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 #include "include/gpu/gl/GrGLAssembleInterface.h"
8 #include "include/gpu/gl/GrGLInterface.h"
9 
10 #include "emscripten/html5.h"
11 #include "webgl/webgl1.h"
12 #include "webgl/webgl1_ext.h"
13 #include "webgl/webgl2.h"
14 #include "webgl/webgl2_ext.h"
15 
webgl_get_gl_proc(void * ctx,const char name[])16 static GrGLFuncPtr webgl_get_gl_proc(void* ctx, const char name[]) {
17 
18     #define M(X) if (0 == strcmp(#X, name)) { return (GrGLFuncPtr) emscripten_##X; }
19     M(glGetString)
20     #undef M
21 
22     // We explicitly do not use GetProcAddress or something similar because
23     // its code size is quite large. We shouldn't need GetProcAddress
24     // because emscripten provides us all the valid function pointers
25     // for WebGL via the included headers.
26     // https://github.com/emscripten-core/emscripten/blob/7ba7700902c46734987585409502f3c63beb650f/system/include/emscripten/html5_webgl.h#L93
27     SkASSERTF(false, "Can't lookup fn %s\n", name);
28     return nullptr;
29 }
30 
GrGLMakeNativeInterface()31 sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
32     return GrGLMakeAssembledInterface(nullptr, webgl_get_gl_proc);
33 }
34 
GrGLCreateNativeInterface()35 const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }
36