• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package main
6
7const ASSEMBLE_INTERFACE_GL_ES = `/*
8 * Copyright 2019 Google LLC
9 *
10 * Use of this source code is governed by a BSD-style license that can be
11 * found in the LICENSE file.
12 *
13 * THIS FILE IS AUTOGENERATED
14 * Make edits to tools/gpu/gl/interface/templates.go or they will
15 * be overwritten.
16 */
17
18#include "include/gpu/gl/GrGLAssembleHelpers.h"
19#include "include/gpu/gl/GrGLAssembleInterface.h"
20#include "src/gpu/ganesh/gl/GrGLUtil.h"
21
22#define GET_PROC(F) functions->f##F = (GrGL##F##Fn*)get(ctx, "gl" #F)
23#define GET_PROC_SUFFIX(F, S) functions->f##F = (GrGL##F##Fn*)get(ctx, "gl" #F #S)
24#define GET_PROC_LOCAL(F) GrGL##F##Fn* F = (GrGL##F##Fn*)get(ctx, "gl" #F)
25
26#define GET_EGL_PROC_SUFFIX(F, S) functions->fEGL##F = (GrEGL##F##Fn*)get(ctx, "egl" #F #S)
27
28#if SK_DISABLE_GL_ES_INTERFACE
29sk_sp<const GrGLInterface> GrGLMakeAssembledGLESInterface(void *ctx, GrGLGetProc get) {
30    return nullptr;
31}
32#else
33sk_sp<const GrGLInterface> GrGLMakeAssembledGLESInterface(void *ctx, GrGLGetProc get) {
34    GET_PROC_LOCAL(GetString);
35    if (nullptr == GetString) {
36        return nullptr;
37    }
38
39    const char* verStr = reinterpret_cast<const char*>(GetString(GR_GL_VERSION));
40    GrGLVersion glVer = GrGLGetVersionFromString(verStr);
41
42    if (glVer < GR_GL_VER(2,0)) {
43        return nullptr;
44    }
45
46    GET_PROC_LOCAL(GetIntegerv);
47    GET_PROC_LOCAL(GetStringi);
48    GrEGLQueryStringFn* queryString;
49    GrEGLDisplay display;
50    GrGetEGLQueryAndDisplay(&queryString, &display, ctx, get);
51    GrGLExtensions extensions;
52    if (!extensions.init(kGLES_GrGLStandard, GetString, GetStringi, GetIntegerv, queryString,
53                         display)) {
54        return nullptr;
55    }
56
57    sk_sp<GrGLInterface> interface(new GrGLInterface);
58    GrGLInterface::Functions* functions = &interface->fFunctions;
59
60    // Autogenerated content follows
61[[content]]
62    // End autogenerated content
63    // TODO(kjlubick): Do we want a feature that removes the extension if it doesn't have
64    // the function? This is common on some low-end GPUs.
65
66    if (extensions.has("GL_KHR_debug")) {
67        // In general we have a policy against removing extension strings when the driver does
68        // not provide function pointers for an advertised extension. However, because there is a
69        // known device that advertises GL_KHR_debug but fails to provide the functions and this is
70        // a debugging- only extension we've made an exception. This also can happen when using
71        // APITRACE.
72        if (!interface->fFunctions.fDebugMessageControl) {
73            extensions.remove("GL_KHR_debug");
74        }
75    }
76    interface->fStandard = kGLES_GrGLStandard;
77    interface->fExtensions.swap(&extensions);
78
79    return interface;
80}
81#endif
82`
83
84const ASSEMBLE_INTERFACE_GL = `/*
85 * Copyright 2019 Google LLC
86 *
87 * Use of this source code is governed by a BSD-style license that can be
88 * found in the LICENSE file.
89 *
90 * THIS FILE IS AUTOGENERATED
91 * Make edits to tools/gpu/gl/interface/templates.go or they will
92 * be overwritten.
93 */
94
95#include "include/gpu/gl/GrGLAssembleHelpers.h"
96#include "include/gpu/gl/GrGLAssembleInterface.h"
97#include "src/gpu/ganesh/gl/GrGLUtil.h"
98
99#define GET_PROC(F) functions->f##F = (GrGL##F##Fn*)get(ctx, "gl" #F)
100#define GET_PROC_SUFFIX(F, S) functions->f##F = (GrGL##F##Fn*)get(ctx, "gl" #F #S)
101#define GET_PROC_LOCAL(F) GrGL##F##Fn* F = (GrGL##F##Fn*)get(ctx, "gl" #F)
102
103#define GET_EGL_PROC_SUFFIX(F, S) functions->fEGL##F = (GrEGL##F##Fn*)get(ctx, "egl" #F #S)
104
105#if SK_DISABLE_GL_INTERFACE
106sk_sp<const GrGLInterface> GrGLMakeAssembledGLInterface(void *ctx, GrGLGetProc get) {
107    return nullptr;
108}
109#else
110sk_sp<const GrGLInterface> GrGLMakeAssembledGLInterface(void *ctx, GrGLGetProc get) {
111    GET_PROC_LOCAL(GetString);
112    GET_PROC_LOCAL(GetStringi);
113    GET_PROC_LOCAL(GetIntegerv);
114
115    // GetStringi may be nullptr depending on the GL version.
116    if (nullptr == GetString || nullptr == GetIntegerv) {
117        return nullptr;
118    }
119
120    const char* versionString = (const char*) GetString(GR_GL_VERSION);
121    GrGLVersion glVer = GrGLGetVersionFromString(versionString);
122
123    if (glVer < GR_GL_VER(2,0) || GR_GL_INVALID_VER == glVer) {
124        // This is our minimum for non-ES GL.
125        return nullptr;
126    }
127
128    GrEGLQueryStringFn* queryString;
129    GrEGLDisplay display;
130    GrGetEGLQueryAndDisplay(&queryString, &display, ctx, get);
131    GrGLExtensions extensions;
132    if (!extensions.init(kGL_GrGLStandard, GetString, GetStringi, GetIntegerv, queryString,
133                         display)) {
134        return nullptr;
135    }
136
137    sk_sp<GrGLInterface> interface(new GrGLInterface());
138    GrGLInterface::Functions* functions = &interface->fFunctions;
139
140    // Autogenerated content follows
141[[content]]
142    // End autogenerated content
143    interface->fStandard = kGL_GrGLStandard;
144    interface->fExtensions.swap(&extensions);
145
146    return interface;
147}
148#endif
149`
150
151const ASSEMBLE_INTERFACE_WEBGL = `/*
152 * Copyright 2019 Google LLC
153 *
154 * Use of this source code is governed by a BSD-style license that can be
155 * found in the LICENSE file.
156 *
157 * THIS FILE IS AUTOGENERATED
158 * Make edits to tools/gpu/gl/interface/templates.go or they will
159 * be overwritten.
160 */
161
162#include "include/gpu/gl/GrGLAssembleHelpers.h"
163#include "include/gpu/gl/GrGLAssembleInterface.h"
164#include "src/gpu/ganesh/gl/GrGLUtil.h"
165
166#if SK_DISABLE_WEBGL_INTERFACE || !defined(__EMSCRIPTEN__)
167sk_sp<const GrGLInterface> GrGLMakeAssembledWebGLInterface(void *ctx, GrGLGetProc get) {
168    return nullptr;
169}
170#else
171
172// Located https://github.com/emscripten-core/emscripten/tree/7ba7700902c46734987585409502f3c63beb650f/system/include/GLES3
173#define GL_GLEXT_PROTOTYPES
174#include <GLES3/gl32.h>
175#include <GLES3/gl2ext.h>
176#include <webgl/webgl2_ext.h>
177
178#define GET_PROC(F) functions->f##F = gl##F
179#define GET_PROC_SUFFIX(F, S) functions->f##F = gl##F##S
180
181sk_sp<const GrGLInterface> GrGLMakeAssembledWebGLInterface(void *ctx, GrGLGetProc get) {
182    const char* verStr = reinterpret_cast<const char*>(glGetString(GR_GL_VERSION));
183    GrGLVersion glVer = GrGLGetVersionFromString(verStr);
184    if (glVer < GR_GL_VER(1,0)) {
185        return nullptr;
186    }
187
188    GrGLExtensions extensions;
189    if (!extensions.init(kWebGL_GrGLStandard, glGetString, glGetStringi, glGetIntegerv)) {
190        return nullptr;
191    }
192
193    sk_sp<GrGLInterface> interface(new GrGLInterface);
194    GrGLInterface::Functions* functions = &interface->fFunctions;
195
196    // Autogenerated content follows
197[[content]]
198    // End autogenerated content
199
200    interface->fStandard = kWebGL_GrGLStandard;
201    interface->fExtensions.swap(&extensions);
202
203    return interface;
204}
205#endif
206`
207
208const VALIDATE_INTERFACE = `/*
209 * Copyright 2011 Google Inc.
210 *
211 * Use of this source code is governed by a BSD-style license that can be
212 * found in the LICENSE file.
213 *
214 * THIS FILE IS AUTOGENERATED
215 * Make edits to tools/gpu/gl/interface/templates.go or they will
216 * be overwritten.
217 */
218
219#include "include/gpu/gl/GrGLExtensions.h"
220#include "include/gpu/gl/GrGLInterface.h"
221#include "src/gpu/ganesh/gl/GrGLUtil.h"
222
223#include <stdio.h>
224
225GrGLInterface::GrGLInterface() {
226    fStandard = kNone_GrGLStandard;
227}
228
229#if GR_GL_CHECK_ERROR
230static const char* get_error_string(GrGLenum err) {
231    switch (err) {
232        case GR_GL_NO_ERROR:
233            return "";
234        case GR_GL_INVALID_ENUM:
235            return "Invalid Enum";
236        case GR_GL_INVALID_VALUE:
237            return "Invalid Value";
238        case GR_GL_INVALID_OPERATION:
239            return "Invalid Operation";
240        case GR_GL_OUT_OF_MEMORY:
241            return "Out of Memory";
242        case GR_GL_CONTEXT_LOST:
243            return "Context Lost";
244    }
245    return "Unknown";
246}
247
248GrGLenum GrGLInterface::checkError(const char* location, const char* call) const {
249    GrGLenum error = fFunctions.fGetError();
250    if (error != GR_GL_NO_ERROR && !fSuppressErrorLogging) {
251        SkDebugf("---- glGetError 0x%x(%s)", error, get_error_string(error));
252        if (location) {
253            SkDebugf(" at\n\t%s", location);
254        }
255        if (call) {
256            SkDebugf("\n\t\t%s", call);
257        }
258        SkDebugf("\n");
259        if (error == GR_GL_OUT_OF_MEMORY) {
260            fOOMed = true;
261        }
262    }
263    return error;
264}
265
266bool GrGLInterface::checkAndResetOOMed() const {
267    if (fOOMed) {
268        fOOMed = false;
269        return true;
270    }
271    return false;
272}
273
274void GrGLInterface::suppressErrorLogging() { fSuppressErrorLogging = true; }
275#endif
276
277#define RETURN_FALSE_INTERFACE                                                 \
278    SkDEBUGF("%s:%d GrGLInterface::validate() failed.\n", __FILE__, __LINE__); \
279    return false
280
281bool GrGLInterface::validate() const {
282
283    if (kNone_GrGLStandard == fStandard) {
284        RETURN_FALSE_INTERFACE;
285    }
286
287    if (!fExtensions.isInitialized()) {
288        RETURN_FALSE_INTERFACE;
289    }
290
291    GrGLVersion glVer = GrGLGetVersion(this);
292    if (GR_GL_INVALID_VER == glVer) {
293        RETURN_FALSE_INTERFACE;
294    }
295    // Autogenerated content follows
296[[content]]
297    // End autogenerated content
298    return true;
299}
300
301#if defined(GR_TEST_UTILS)
302
303void GrGLInterface::abandon() const {
304    const_cast<GrGLInterface*>(this)->fFunctions = GrGLInterface::Functions();
305}
306
307#endif // defined(GR_TEST_UTILS)
308`
309