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 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 14 | GrGLContext* GrGLContext::Create(const GrGLInterface* interface, const GrContextOptions& options) { |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 15 | // We haven't validated the GrGLInterface yet, so check for GetString function pointer |
| 16 | if (!interface->fFunctions.fGetString) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 17 | return nullptr; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 18 | } |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 19 | ConstructorArgs args; |
| 20 | args.fInterface = interface; |
| 21 | |
| 22 | const GrGLubyte* verUByte; |
| 23 | GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); |
| 24 | const char* ver = reinterpret_cast<const char*>(verUByte); |
| 25 | |
| 26 | const GrGLubyte* rendererUByte; |
| 27 | GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER)); |
| 28 | const char* renderer = reinterpret_cast<const char*>(rendererUByte); |
| 29 | |
| 30 | if (!interface->validate()) { |
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 | |
| 34 | args.fGLVersion = GrGLGetVersionFromString(ver); |
| 35 | if (GR_GL_INVALID_VER == args.fGLVersion) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 36 | return nullptr; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 37 | } |
| 38 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 39 | if (!GrGLGetGLSLGeneration(interface, &args.fGLSLGeneration)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 40 | return nullptr; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | args.fVendor = GrGLGetVendor(interface); |
| 44 | |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 45 | args.fRenderer = GrGLGetRendererFromString(renderer); |
| 46 | |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 47 | GrGLGetANGLEInfoFromString(renderer, &args.fANGLEBackend, &args.fANGLEVendor, |
| 48 | &args.fANGLERenderer); |
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. |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 54 | * ?????/2015 - This bug is still present in Lollipop pre-mr1 |
| 55 | * 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] | 56 | */ |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 57 | if (kAdreno3xx_GrGLRenderer == args.fRenderer) { |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 58 | args.fGLSLGeneration = k110_GrGLSLGeneration; |
| 59 | } |
| 60 | |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 61 | GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver, |
| 62 | &args.fDriver, &args.fDriverVersion); |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 63 | |
| 64 | args.fContextOptions = &options; |
| 65 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 66 | return new GrGLContext(args); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 67 | } |
| 68 | |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 69 | GrGLContext::~GrGLContext() { |
| 70 | delete fCompiler; |
| 71 | } |
| 72 | |
| 73 | SkSL::Compiler* GrGLContext::compiler() const { |
| 74 | if (!fCompiler) { |
| 75 | fCompiler = new SkSL::Compiler(); |
| 76 | } |
| 77 | return fCompiler; |
| 78 | } |
| 79 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 80 | GrGLContextInfo::GrGLContextInfo(const ConstructorArgs& args) { |
| 81 | fInterface.reset(SkRef(args.fInterface)); |
| 82 | fGLVersion = args.fGLVersion; |
| 83 | fGLSLGeneration = args.fGLSLGeneration; |
| 84 | fVendor = args.fVendor; |
| 85 | fRenderer = args.fRenderer; |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 86 | fDriver = args.fDriver; |
| 87 | fDriverVersion = args.fDriverVersion; |
Brian Salomon | 266ef6d | 2017-09-22 11:27:42 -0400 | [diff] [blame] | 88 | fANGLEBackend = args.fANGLEBackend; |
| 89 | fANGLEVendor = args.fANGLEVendor; |
| 90 | fANGLERenderer = args.fANGLERenderer; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 91 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 92 | fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get()); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 93 | } |