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 | dcfe6db | 2016-10-10 10:09:00 -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 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 47 | /* |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 48 | * Qualcomm drivers for the 3xx series have a horrendous bug with some drivers. Though they |
| 49 | * 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] | 50 | * #version 100, and will fail to compile with #version 300 es. In the long term, we |
| 51 | * need to lock this down to a specific driver version. |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 52 | * ?????/2015 - This bug is still present in Lollipop pre-mr1 |
| 53 | * 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] | 54 | */ |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 55 | if (kAdreno3xx_GrGLRenderer == args.fRenderer) { |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 56 | args.fGLSLGeneration = k110_GrGLSLGeneration; |
| 57 | } |
| 58 | |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 59 | GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver, |
| 60 | &args.fDriver, &args.fDriverVersion); |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 61 | |
| 62 | args.fContextOptions = &options; |
| 63 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 64 | return new GrGLContext(args); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 65 | } |
| 66 | |
ethannicholas | dcfe6db | 2016-10-10 10:09:00 -0700 | [diff] [blame^] | 67 | GrGLContext::~GrGLContext() { |
| 68 | delete fCompiler; |
| 69 | } |
| 70 | |
| 71 | SkSL::Compiler* GrGLContext::compiler() const { |
| 72 | if (!fCompiler) { |
| 73 | fCompiler = new SkSL::Compiler(); |
| 74 | } |
| 75 | return fCompiler; |
| 76 | } |
| 77 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 78 | GrGLContextInfo::GrGLContextInfo(const ConstructorArgs& args) { |
| 79 | fInterface.reset(SkRef(args.fInterface)); |
| 80 | fGLVersion = args.fGLVersion; |
| 81 | fGLSLGeneration = args.fGLSLGeneration; |
| 82 | fVendor = args.fVendor; |
| 83 | fRenderer = args.fRenderer; |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 84 | fDriver = args.fDriver; |
| 85 | fDriverVersion = args.fDriverVersion; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 86 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 87 | fGLCaps.reset(new GrGLCaps(*args.fContextOptions, *this, fInterface)); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 88 | } |