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 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 "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 std::move(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(SK_USE_WEBGL) 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/webgl 173#include <webgl/webgl1.h> 174#include <webgl/webgl1_ext.h> 175#include <webgl/webgl2.h> 176#include <webgl/webgl2_ext.h> 177 178#define GET_PROC(F) functions->f##F = emscripten_gl##F 179#define GET_PROC_SUFFIX(F, S) functions->f##F = emscripten_gl##F##S 180 181// Adapter from standard GL signature to emscripten. 182void emscripten_glWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) { 183 uint32_t timeoutLo = timeout; 184 uint32_t timeoutHi = timeout >> 32; 185 emscripten_glWaitSync(sync, flags, timeoutLo, timeoutHi); 186} 187 188// Adapter from standard GL signature to emscripten. 189GLenum emscripten_glClientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) { 190 uint32_t timeoutLo = timeout; 191 uint32_t timeoutHi = timeout >> 32; 192 return emscripten_glClientWaitSync(sync, flags, timeoutLo, timeoutHi); 193} 194 195sk_sp<const GrGLInterface> GrGLMakeAssembledWebGLInterface(void *ctx, GrGLGetProc get) { 196 const char* verStr = reinterpret_cast<const char*>(emscripten_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, emscripten_glGetString, emscripten_glGetStringi, 204 emscripten_glGetIntegerv)) { 205 return nullptr; 206 } 207 208 sk_sp<GrGLInterface> interface(new GrGLInterface); 209 GrGLInterface::Functions* functions = &interface->fFunctions; 210 211 // Autogenerated content follows 212[[content]] 213 // End autogenerated content 214 215 interface->fStandard = kWebGL_GrGLStandard; 216 interface->fExtensions.swap(&extensions); 217 218 return std::move(interface); 219} 220#endif 221` 222 223const VALIDATE_INTERFACE = `/* 224 * Copyright 2011 Google Inc. 225 * 226 * Use of this source code is governed by a BSD-style license that can be 227 * found in the LICENSE file. 228 * 229 * THIS FILE IS AUTOGENERATED 230 * Make edits to tools/gpu/gl/interface/templates.go or they will 231 * be overwritten. 232 */ 233 234#include "include/gpu/gl/GrGLExtensions.h" 235#include "include/gpu/gl/GrGLInterface.h" 236#include "src/gpu/ganesh/gl/GrGLUtil.h" 237 238#include <stdio.h> 239 240GrGLInterface::GrGLInterface() { 241 fStandard = kNone_GrGLStandard; 242} 243 244#if GR_GL_CHECK_ERROR 245static const char* get_error_string(GrGLenum err) { 246 switch (err) { 247 case GR_GL_NO_ERROR: 248 return ""; 249 case GR_GL_INVALID_ENUM: 250 return "Invalid Enum"; 251 case GR_GL_INVALID_VALUE: 252 return "Invalid Value"; 253 case GR_GL_INVALID_OPERATION: 254 return "Invalid Operation"; 255 case GR_GL_OUT_OF_MEMORY: 256 return "Out of Memory"; 257 case GR_GL_CONTEXT_LOST: 258 return "Context Lost"; 259 } 260 return "Unknown"; 261} 262 263GrGLenum GrGLInterface::checkError(const char* location, const char* call) const { 264 GrGLenum error = fFunctions.fGetError(); 265 if (error != GR_GL_NO_ERROR && !fSuppressErrorLogging) { 266 SkDebugf("---- glGetError 0x%x(%s)", error, get_error_string(error)); 267 if (location) { 268 SkDebugf(" at\n\t%s", location); 269 } 270 if (call) { 271 SkDebugf("\n\t\t%s", call); 272 } 273 SkDebugf("\n"); 274 if (error == GR_GL_OUT_OF_MEMORY) { 275 fOOMed = true; 276 } 277 } 278 return error; 279} 280 281bool GrGLInterface::checkAndResetOOMed() const { 282 if (fOOMed) { 283 fOOMed = false; 284 return true; 285 } 286 return false; 287} 288 289void GrGLInterface::suppressErrorLogging() { fSuppressErrorLogging = true; } 290#endif 291 292#define RETURN_FALSE_INTERFACE \ 293 SkDEBUGF("%s:%d GrGLInterface::validate() failed.\n", __FILE__, __LINE__); \ 294 return false 295 296bool GrGLInterface::validate() const { 297 298 if (kNone_GrGLStandard == fStandard) { 299 RETURN_FALSE_INTERFACE; 300 } 301 302 if (!fExtensions.isInitialized()) { 303 RETURN_FALSE_INTERFACE; 304 } 305 306 GrGLVersion glVer = GrGLGetVersion(this); 307 if (GR_GL_INVALID_VER == glVer) { 308 RETURN_FALSE_INTERFACE; 309 } 310 // Autogenerated content follows 311[[content]] 312 // End autogenerated content 313 return true; 314} 315 316#if GR_TEST_UTILS 317 318void GrGLInterface::abandon() const { 319 const_cast<GrGLInterface*>(this)->fFunctions = GrGLInterface::Functions(); 320} 321 322#endif // GR_TEST_UTILS 323` 324