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" |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 10 | |
| 11 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 12 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 13 | GrGLContext* GrGLContext::Create(const GrGLInterface* interface, const GrContextOptions& options) { |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 14 | // We haven't validated the GrGLInterface yet, so check for GetString function pointer |
| 15 | if (!interface->fFunctions.fGetString) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 16 | return nullptr; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 17 | } |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 18 | ConstructorArgs args; |
| 19 | args.fInterface = interface; |
| 20 | |
| 21 | const GrGLubyte* verUByte; |
| 22 | GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); |
| 23 | const char* ver = reinterpret_cast<const char*>(verUByte); |
| 24 | |
| 25 | const GrGLubyte* rendererUByte; |
| 26 | GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER)); |
| 27 | const char* renderer = reinterpret_cast<const char*>(rendererUByte); |
| 28 | |
| 29 | if (!interface->validate()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 30 | return nullptr; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 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 | |
jvanverth | cba99b8 | 2015-06-24 06:59:57 -0700 | [diff] [blame] | 38 | if (!GrGLGetGLSLGeneration(interface, &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 | |
| 42 | args.fVendor = GrGLGetVendor(interface); |
| 43 | |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 44 | args.fRenderer = GrGLGetRendererFromString(renderer); |
| 45 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 46 | /* |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 47 | * Qualcomm drivers for the 3xx series have a horrendous bug with some drivers. Though they |
| 48 | * 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] | 49 | * #version 100, and will fail to compile with #version 300 es. In the long term, we |
| 50 | * need to lock this down to a specific driver version. |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 51 | * ?????/2015 - This bug is still present in Lollipop pre-mr1 |
| 52 | * 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] | 53 | */ |
joshualitt | 5599996 | 2015-06-18 13:47:10 -0700 | [diff] [blame] | 54 | if (kAdreno3xx_GrGLRenderer == args.fRenderer) { |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 55 | args.fGLSLGeneration = k110_GrGLSLGeneration; |
| 56 | } |
| 57 | |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 58 | GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver, |
| 59 | &args.fDriver, &args.fDriverVersion); |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 60 | |
| 61 | args.fContextOptions = &options; |
| 62 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 63 | return new GrGLContext(args); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 64 | } |
| 65 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 66 | GrGLContextInfo::GrGLContextInfo(const ConstructorArgs& args) { |
| 67 | fInterface.reset(SkRef(args.fInterface)); |
| 68 | fGLVersion = args.fGLVersion; |
| 69 | fGLSLGeneration = args.fGLSLGeneration; |
| 70 | fVendor = args.fVendor; |
| 71 | fRenderer = args.fRenderer; |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 72 | fDriver = args.fDriver; |
| 73 | fDriverVersion = args.fDriverVersion; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 74 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 75 | fGLCaps.reset(new GrGLCaps(*args.fContextOptions, *this, fInterface)); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 76 | } |