blob: 59404f128916f284a6af3da87be88a0ee740fc15 [file] [log] [blame]
Kevin Lubick204c3be2020-08-19 14:30:58 -04001/*
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 Lubick204c3be2020-08-19 14:30:58 -04009
10#include "emscripten/html5.h"
Kevin Lubick2f9a0982020-08-20 10:33:39 -040011#include "webgl/webgl1.h"
12#include "webgl/webgl1_ext.h"
13#include "webgl/webgl2.h"
14#include "webgl/webgl2_ext.h"
Kevin Lubick204c3be2020-08-19 14:30:58 -040015
16static GrGLFuncPtr webgl_get_gl_proc(void* ctx, const char name[]) {
Kevin Lubick204c3be2020-08-19 14:30:58 -040017
Kevin Lubick2f9a0982020-08-20 10:33:39 -040018 #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 Lubick204c3be2020-08-19 14:30:58 -040029}
30
31sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
32 return GrGLMakeAssembledInterface(nullptr, webgl_get_gl_proc);
33}
34
35const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }