blob: 26dacbf5c5c625146420ea70e9588aeb844beb4b [file] [log] [blame]
Kevin Lubick5509dac2019-03-25 17:23:55 -04001// 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 "gl/GrGLAssembleInterface.h"
19#include "gl/GrGLAssembleHelpers.h"
20#include "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 std::move(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 "gl/GrGLAssembleInterface.h"
96#include "gl/GrGLAssembleHelpers.h"
97#include "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 std::move(interface);
147}
148#endif
149`
150
151const VALIDATE_INTERFACE = `/*
152 * Copyright 2011 Google Inc.
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 "gl/GrGLInterface.h"
163#include "gl/GrGLExtensions.h"
164#include "gl/GrGLUtil.h"
165
166#include <stdio.h>
167
168GrGLInterface::GrGLInterface() {
169 fStandard = kNone_GrGLStandard;
170}
171
172#define RETURN_FALSE_INTERFACE \
173 SkDEBUGF("%s:%d GrGLInterface::validate() failed.\n", __FILE__, __LINE__); \
174 return false
175
176bool GrGLInterface::validate() const {
177
178 if (kNone_GrGLStandard == fStandard) {
179 RETURN_FALSE_INTERFACE;
180 }
181
182 if (!fExtensions.isInitialized()) {
183 RETURN_FALSE_INTERFACE;
184 }
185
186 GrGLVersion glVer = GrGLGetVersion(this);
187 if (GR_GL_INVALID_VER == glVer) {
188 RETURN_FALSE_INTERFACE;
189 }
190 // Autogenerated content follows
191[[content]]
192 // End autogenerated content
193 return true;
194}
195
196#if GR_TEST_UTILS
197
198void GrGLInterface::abandon() const {
199 const_cast<GrGLInterface*>(this)->fFunctions = GrGLInterface::Functions();
200}
201
202#endif // GR_TEST_UTILS
203`