• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "src/gpu/gl/GrGLContext.h"
9 
10 #include "include/gpu/GrContextOptions.h"
11 #include "src/gpu/gl/GrGLGLSL.h"
12 
13 #ifdef SK_BUILD_FOR_ANDROID
14 #include <sys/system_properties.h>
15 #endif
16 
17 ////////////////////////////////////////////////////////////////////////////////
18 
Make(sk_sp<const GrGLInterface> interface,const GrContextOptions & options)19 std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interface,
20                                                const GrContextOptions& options) {
21     if (!interface->validate()) {
22         return nullptr;
23     }
24 
25     ConstructorArgs args;
26     args.fDriverInfo = GrGLGetDriverInfo(interface.get());
27     if (args.fDriverInfo.fVersion == GR_GL_INVALID_VER) {
28         return nullptr;
29     }
30 
31     if (!GrGLGetGLSLGeneration(args.fDriverInfo, &args.fGLSLGeneration)) {
32         return nullptr;
33     }
34 
35     /*
36      * Qualcomm drivers for the 3xx series have a horrendous bug with some drivers. Though they
37      * claim to support GLES 3.00, some perfectly valid GLSL300 shaders will only compile with
38      * #version 100, and will fail to compile with #version 300 es.  In the long term, we
39      * need to lock this down to a specific driver version.
40      * ?????/2019 - Qualcomm has fixed this for Android O+ devices (API 26+)
41      * ?????/2015 - This bug is still present in Lollipop pre-mr1
42      * 06/18/2015 - This bug does not affect the nexus 6 (which has an Adreno 4xx).
43      */
44 #ifdef SK_BUILD_FOR_ANDROID
45     if (!options.fDisableDriverCorrectnessWorkarounds &&
46         args.fDriverInfo.fRenderer == GrGLRenderer::kAdreno3xx) {
47         char androidAPIVersion[PROP_VALUE_MAX];
48         int strLength = __system_property_get("ro.build.version.sdk", androidAPIVersion);
49         if (strLength == 0 || atoi(androidAPIVersion) < 26) {
50             args.fGLSLGeneration = k110_GrGLSLGeneration;
51         }
52     }
53 #endif
54 
55     // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
56     // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
57     // extension to be enabled, even when using ESSL3. Some devices appear to only support the ES2
58     // extension. As an extreme (optional) solution, we can fallback to using ES2 shading language
59     // if we want to prioritize external texture support. skbug.com/7713
60     if (GR_IS_GR_GL_ES(interface->fStandard) &&
61         options.fPreferExternalImagesOverES3 &&
62         !options.fDisableDriverCorrectnessWorkarounds &&
63         interface->hasExtension("GL_OES_EGL_image_external") &&
64         args.fGLSLGeneration >= k330_GrGLSLGeneration &&
65         !interface->hasExtension("GL_OES_EGL_image_external_essl3") &&
66         !interface->hasExtension("OES_EGL_image_external_essl3")) {
67         args.fGLSLGeneration = k110_GrGLSLGeneration;
68     }
69 
70     args.fContextOptions = &options;
71     args.fInterface = std::move(interface);
72 
73     return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args)));
74 }
75 
~GrGLContext()76 GrGLContext::~GrGLContext() {}
77 
makeNonAngle() const78 GrGLContextInfo GrGLContextInfo::makeNonAngle() const {
79     GrGLContextInfo copy = *this;
80     if (fDriverInfo.fANGLEBackend == GrGLANGLEBackend::kUnknown) {
81         return copy;
82     }
83 
84     copy.fDriverInfo.fVendor        = copy.fDriverInfo.fANGLEVendor;
85     copy.fDriverInfo.fDriver        = copy.fDriverInfo.fANGLEDriver;
86     copy.fDriverInfo.fDriverVersion = copy.fDriverInfo.fANGLEDriverVersion;
87     copy.fDriverInfo.fRenderer      = copy.fDriverInfo.fANGLERenderer;
88 
89     copy.fDriverInfo.fANGLEBackend       = GrGLANGLEBackend::kUnknown;
90     copy.fDriverInfo.fANGLEVendor        = GrGLVendor::kOther;
91     copy.fDriverInfo.fANGLEDriver        = GrGLDriver::kUnknown;
92     copy.fDriverInfo.fANGLEDriverVersion = GR_GL_DRIVER_UNKNOWN_VER;
93     copy.fDriverInfo.fANGLERenderer      = GrGLRenderer::kOther;
94 
95     return copy;
96 }
97 
GrGLContextInfo(ConstructorArgs && args)98 GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) {
99     fInterface = std::move(args.fInterface);
100     fDriverInfo = args.fDriverInfo;
101     fGLSLGeneration = args.fGLSLGeneration;
102 
103     fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get());
104 }
105