Kevin Lubick | 204c3be | 2020-08-19 14:30:58 -0400 | [diff] [blame] | 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" |
Kevin Lubick | 204c3be | 2020-08-19 14:30:58 -0400 | [diff] [blame] | 9 | |
| 10 | #include "emscripten/html5.h" |
Kevin Lubick | 2f9a098 | 2020-08-20 10:33:39 -0400 | [diff] [blame] | 11 | #include "webgl/webgl1.h" |
| 12 | #include "webgl/webgl1_ext.h" |
| 13 | #include "webgl/webgl2.h" |
| 14 | #include "webgl/webgl2_ext.h" |
Kevin Lubick | 204c3be | 2020-08-19 14:30:58 -0400 | [diff] [blame] | 15 | |
| 16 | static GrGLFuncPtr webgl_get_gl_proc(void* ctx, const char name[]) { |
Kevin Lubick | 204c3be | 2020-08-19 14:30:58 -0400 | [diff] [blame] | 17 | |
Kevin Lubick | 2f9a098 | 2020-08-20 10:33:39 -0400 | [diff] [blame] | 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; |
Kevin Lubick | 204c3be | 2020-08-19 14:30:58 -0400 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | sk_sp<const GrGLInterface> GrGLMakeNativeInterface() { |
| 32 | return GrGLMakeAssembledInterface(nullptr, webgl_get_gl_proc); |
| 33 | } |
| 34 | |
| 35 | const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); } |