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 | |
| 8 | #include "GrGLContext.h" |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 9 | #include "GrGLGLSL.h" |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 10 | #include "SkSLCompiler.h" |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 11 | |
| 12 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 13 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 14 | std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interface, |
| 15 | const GrContextOptions& options) { |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 16 | if (!interface->validate()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 17 | return nullptr; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 18 | } |
| 19 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 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; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 29 | args.fGLVersion = GrGLGetVersionFromString(ver); |
| 30 | if (GR_GL_INVALID_VER == args.fGLVersion) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 31 | return nullptr; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 34 | if (!GrGLGetGLSLGeneration(interface.get(), &args.fGLSLGeneration)) { |
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 | args.fVendor = GrGLGetVendor(interface.get()); |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 39 | |
Brian Salomon | 4470e34 | 2018-04-04 14:27:48 -0400 | [diff] [blame] | 40 | args.fRenderer = GrGLGetRendererFromStrings(renderer, interface->fExtensions); |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 41 | |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 42 | GrGLGetANGLEInfoFromString(renderer, &args.fANGLEBackend, &args.fANGLEVendor, |
| 43 | &args.fANGLERenderer); |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 44 | /* |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 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 |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 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. |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 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). |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 51 | */ |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 52 | if (kAdreno3xx_GrGLRenderer == args.fRenderer) { |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 53 | args.fGLSLGeneration = k110_GrGLSLGeneration; |
| 54 | } |
| 55 | |
Brian Osman | 06d3746 | 2018-05-08 13:00:42 -0400 | [diff] [blame] | 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 |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame^] | 61 | if (GR_IS_GR_GL_ES(interface->fStandard) && |
Brian Osman | 06d3746 | 2018-05-08 13:00:42 -0400 | [diff] [blame] | 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 | |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 71 | GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver, |
| 72 | &args.fDriver, &args.fDriverVersion); |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 73 | |
| 74 | args.fContextOptions = &options; |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 75 | args.fInterface = std::move(interface); |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 76 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 77 | return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args))); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 78 | } |
| 79 | |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 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 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 91 | GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) { |
| 92 | fInterface = std::move(args.fInterface); |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 93 | fGLVersion = args.fGLVersion; |
| 94 | fGLSLGeneration = args.fGLSLGeneration; |
| 95 | fVendor = args.fVendor; |
| 96 | fRenderer = args.fRenderer; |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 97 | fDriver = args.fDriver; |
| 98 | fDriverVersion = args.fDriverVersion; |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 99 | fANGLEBackend = args.fANGLEBackend; |
| 100 | fANGLEVendor = args.fANGLEVendor; |
| 101 | fANGLERenderer = args.fANGLERenderer; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 102 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 103 | fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get()); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 104 | } |