robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/gl/GrGLContext.h" |
| 9 | #include "src/gpu/gl/GrGLGLSL.h" |
| 10 | #include "src/sksl/SkSLCompiler.h" |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 11 | |
Derek Sollenberger | 11b34d9 | 2019-06-17 09:19:21 -0400 | [diff] [blame] | 12 | #ifdef SK_BUILD_FOR_ANDROID |
| 13 | #include <sys/system_properties.h> |
| 14 | #endif |
| 15 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 16 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 17 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 18 | std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interface, |
| 19 | const GrContextOptions& options) { |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 20 | if (!interface->validate()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 21 | return nullptr; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 22 | } |
| 23 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 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; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 33 | args.fGLVersion = GrGLGetVersionFromString(ver); |
| 34 | if (GR_GL_INVALID_VER == args.fGLVersion) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 35 | return nullptr; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 38 | if (!GrGLGetGLSLGeneration(interface.get(), &args.fGLSLGeneration)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 39 | return nullptr; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 42 | args.fVendor = GrGLGetVendor(interface.get()); |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 43 | |
Brian Salomon | 4470e34 | 2018-04-04 14:27:48 -0400 | [diff] [blame] | 44 | args.fRenderer = GrGLGetRendererFromStrings(renderer, interface->fExtensions); |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 45 | |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 46 | GrGLGetANGLEInfoFromString(renderer, &args.fANGLEBackend, &args.fANGLEVendor, |
| 47 | &args.fANGLERenderer); |
Derek Sollenberger | 11b34d9 | 2019-06-17 09:19:21 -0400 | [diff] [blame] | 48 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 49 | /* |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 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 |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 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. |
Derek Sollenberger | 11b34d9 | 2019-06-17 09:19:21 -0400 | [diff] [blame] | 54 | * ?????/2019 - Qualcomm has fixed this for Android O+ devices (API 26+) |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 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). |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 57 | */ |
Derek Sollenberger | 11b34d9 | 2019-06-17 09:19:21 -0400 | [diff] [blame] | 58 | #ifdef SK_BUILD_FOR_ANDROID |
| 59 | if (!options.fDisableDriverCorrectnessWorkarounds && |
| 60 | kAdreno3xx_GrGLRenderer == args.fRenderer) { |
| 61 | char androidAPIVersion[PROP_VALUE_MAX]; |
Derek Sollenberger | 91032f8 | 2019-06-21 14:57:42 -0400 | [diff] [blame] | 62 | int strLength = __system_property_get("ro.build.version.sdk", androidAPIVersion); |
Derek Sollenberger | 11b34d9 | 2019-06-17 09:19:21 -0400 | [diff] [blame] | 63 | if (strLength == 0 || atoi(androidAPIVersion) < 26) { |
| 64 | args.fGLSLGeneration = k110_GrGLSLGeneration; |
| 65 | } |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 66 | } |
Derek Sollenberger | 11b34d9 | 2019-06-17 09:19:21 -0400 | [diff] [blame] | 67 | #endif |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 68 | |
Brian Osman | 06d3746 | 2018-05-08 13:00:42 -0400 | [diff] [blame] | 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 |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 74 | if (GR_IS_GR_GL_ES(interface->fStandard) && |
Brian Osman | 06d3746 | 2018-05-08 13:00:42 -0400 | [diff] [blame] | 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 | |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 84 | GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver, |
| 85 | &args.fDriver, &args.fDriverVersion); |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 86 | |
| 87 | args.fContextOptions = &options; |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 88 | args.fInterface = std::move(interface); |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 89 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 90 | return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args))); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 91 | } |
| 92 | |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 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 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 104 | GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) { |
| 105 | fInterface = std::move(args.fInterface); |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 106 | fGLVersion = args.fGLVersion; |
| 107 | fGLSLGeneration = args.fGLSLGeneration; |
| 108 | fVendor = args.fVendor; |
| 109 | fRenderer = args.fRenderer; |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 110 | fDriver = args.fDriver; |
| 111 | fDriverVersion = args.fDriverVersion; |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 112 | fANGLEBackend = args.fANGLEBackend; |
| 113 | fANGLEVendor = args.fANGLEVendor; |
| 114 | fANGLERenderer = args.fANGLERenderer; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 115 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 116 | fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get()); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 117 | } |