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