1 /* 2 * Copyright 2013 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 #include "GrGLContext.h" 9 #include "GrGLGLSL.h" 10 #include "SkSLCompiler.h" 11 12 //////////////////////////////////////////////////////////////////////////////// 13 14 std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interface, 15 const GrContextOptions& options) { 16 if (!interface->validate()) { 17 return nullptr; 18 } 19 20 const GrGLubyte* verUByte; 21 GR_GL_CALL_RET(interface.get(), verUByte, GetString(GR_GL_VERSION)); 22 const char* ver = reinterpret_cast<const char*>(verUByte); 23 24 const GrGLubyte* rendererUByte; 25 GR_GL_CALL_RET(interface.get(), rendererUByte, GetString(GR_GL_RENDERER)); 26 const char* renderer = reinterpret_cast<const char*>(rendererUByte); 27 28 ConstructorArgs args; 29 args.fGLVersion = GrGLGetVersionFromString(ver); 30 if (GR_GL_INVALID_VER == args.fGLVersion) { 31 return nullptr; 32 } 33 34 if (!GrGLGetGLSLGeneration(interface.get(), &args.fGLSLGeneration)) { 35 return nullptr; 36 } 37 38 args.fVendor = GrGLGetVendor(interface.get()); 39 40 args.fRenderer = GrGLGetRendererFromStrings(renderer, interface->fExtensions); 41 42 GrGLGetANGLEInfoFromString(renderer, &args.fANGLEBackend, &args.fANGLEVendor, 43 &args.fANGLERenderer); 44 /* 45 * Qualcomm drivers for the 3xx series have a horrendous bug with some drivers. Though they 46 * claim to support GLES 3.00, some perfectly valid GLSL300 shaders will only compile with 47 * #version 100, and will fail to compile with #version 300 es. In the long term, we 48 * need to lock this down to a specific driver version. 49 * ?????/2015 - This bug is still present in Lollipop pre-mr1 50 * 06/18/2015 - This bug does not affect the nexus 6 (which has an Adreno 4xx). 51 */ 52 if (kAdreno3xx_GrGLRenderer == args.fRenderer) { 53 args.fGLSLGeneration = k110_GrGLSLGeneration; 54 } 55 56 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3 57 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2 58 // extension to be enabled, even when using ESSL3. Some devices appear to only support the ES2 59 // extension. As an extreme (optional) solution, we can fallback to using ES2 shading language 60 // if we want to prioritize external texture support. skbug.com/7713 61 if (kGLES_GrGLStandard == interface->fStandard && 62 options.fPreferExternalImagesOverES3 && 63 !options.fDisableDriverCorrectnessWorkarounds && 64 interface->hasExtension("GL_OES_EGL_image_external") && 65 args.fGLSLGeneration >= k330_GrGLSLGeneration && 66 !interface->hasExtension("GL_OES_EGL_image_external_essl3") && 67 !interface->hasExtension("OES_EGL_image_external_essl3")) { 68 args.fGLSLGeneration = k110_GrGLSLGeneration; 69 } 70 71 GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver, 72 &args.fDriver, &args.fDriverVersion); 73 74 args.fContextOptions = &options; 75 args.fInterface = std::move(interface); 76 77 return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args))); 78 } 79 80 GrGLContext::~GrGLContext() { 81 delete fCompiler; 82 } 83 84 SkSL::Compiler* GrGLContext::compiler() const { 85 if (!fCompiler) { 86 fCompiler = new SkSL::Compiler(); 87 } 88 return fCompiler; 89 } 90 91 GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) { 92 fInterface = std::move(args.fInterface); 93 fGLVersion = args.fGLVersion; 94 fGLSLGeneration = args.fGLSLGeneration; 95 fVendor = args.fVendor; 96 fRenderer = args.fRenderer; 97 fDriver = args.fDriver; 98 fDriverVersion = args.fDriverVersion; 99 fANGLEBackend = args.fANGLEBackend; 100 fANGLEVendor = args.fANGLEVendor; 101 fANGLERenderer = args.fANGLERenderer; 102 103 fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get()); 104 } 105