1/*
2 * Copyright 2014 Google Inc.
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
8
9#include "include/gpu/gl/GrGLAssembleHelpers.h"
10#include "include/gpu/gl/GrGLAssembleInterface.h"
11#include "src/gpu/gl/GrGLUtil.h"
12
13#define GET_PROC_LOCAL(F) GrGL##F##Fn* F = (GrGL##F##Fn*)get(ctx, "gl" #F)
14
15sk_sp<const GrGLInterface> GrGLMakeAssembledInterface(void *ctx, GrGLGetProc get) {
16 GET_PROC_LOCAL(GetString);
17 if (nullptr == GetString) {
18 return nullptr;
19 }
20
21 const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION));
22 if (nullptr == verStr) {
23 return nullptr;
24 }
25
26 GrGLStandard standard = GrGLGetStandardInUseFromString(verStr);
27 // standard can be unused (optimzed away) if SK_ASSUME_GL_ES is set
28 sk_ignore_unused_variable(standard);
29
30 if (GR_IS_GR_GL_ES(standard)) {
31 return GrGLMakeAssembledGLESInterface(ctx, get);
32 } else if (GR_IS_GR_GL(standard)) {
33 return GrGLMakeAssembledGLInterface(ctx, get);
34 } else if (GR_IS_GR_WEBGL(standard)) {
35 return GrGLMakeAssembledWebGLInterface(ctx, get);
36 }
37 return nullptr;
38}
39
40const GrGLInterface* GrGLAssembleInterface(void *ctx, GrGLGetProc get) {
41 return GrGLMakeAssembledInterface(ctx, get).release();
42}
43