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