/src/skia/src/gpu/gl/GrGLContext.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
19 | | std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interface, |
20 | 0 | const GrContextOptions& options) { |
21 | 0 | if (!interface->validate()) { |
22 | 0 | return nullptr; |
23 | 0 | } |
24 | | |
25 | 0 | ConstructorArgs args; |
26 | 0 | args.fDriverInfo = GrGLGetDriverInfo(interface.get()); |
27 | 0 | if (args.fDriverInfo.fVersion == GR_GL_INVALID_VER) { |
28 | 0 | return nullptr; |
29 | 0 | } |
30 | | |
31 | 0 | if (!GrGLGetGLSLGeneration(args.fDriverInfo, &args.fGLSLGeneration)) { |
32 | 0 | return nullptr; |
33 | 0 | } |
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 | 0 | if (GR_IS_GR_GL_ES(interface->fStandard) && |
61 | 0 | options.fPreferExternalImagesOverES3 && |
62 | 0 | !options.fDisableDriverCorrectnessWorkarounds && |
63 | 0 | interface->hasExtension("GL_OES_EGL_image_external") && |
64 | 0 | args.fGLSLGeneration >= k330_GrGLSLGeneration && |
65 | 0 | !interface->hasExtension("GL_OES_EGL_image_external_essl3") && |
66 | 0 | !interface->hasExtension("OES_EGL_image_external_essl3")) { |
67 | 0 | args.fGLSLGeneration = k110_GrGLSLGeneration; |
68 | 0 | } |
69 | |
|
70 | 0 | args.fContextOptions = &options; |
71 | 0 | args.fInterface = std::move(interface); |
72 | |
|
73 | 0 | return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args))); |
74 | 0 | } |
75 | | |
76 | 0 | GrGLContext::~GrGLContext() {} |
77 | | |
78 | 0 | GrGLContextInfo GrGLContextInfo::makeNonAngle() const { |
79 | 0 | GrGLContextInfo copy = *this; |
80 | 0 | if (fDriverInfo.fANGLEBackend == GrGLANGLEBackend::kUnknown) { |
81 | 0 | return copy; |
82 | 0 | } |
83 | | |
84 | 0 | copy.fDriverInfo.fVendor = copy.fDriverInfo.fANGLEVendor; |
85 | 0 | copy.fDriverInfo.fDriver = copy.fDriverInfo.fANGLEDriver; |
86 | 0 | copy.fDriverInfo.fDriverVersion = copy.fDriverInfo.fANGLEDriverVersion; |
87 | 0 | copy.fDriverInfo.fRenderer = copy.fDriverInfo.fANGLERenderer; |
88 | |
|
89 | 0 | copy.fDriverInfo.fANGLEBackend = GrGLANGLEBackend::kUnknown; |
90 | 0 | copy.fDriverInfo.fANGLEVendor = GrGLVendor::kOther; |
91 | 0 | copy.fDriverInfo.fANGLEDriver = GrGLDriver::kUnknown; |
92 | 0 | copy.fDriverInfo.fANGLEDriverVersion = GR_GL_DRIVER_UNKNOWN_VER; |
93 | 0 | copy.fDriverInfo.fANGLERenderer = GrGLRenderer::kOther; |
94 | |
|
95 | 0 | return copy; |
96 | 0 | } |
97 | | |
98 | 0 | GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) { |
99 | 0 | fInterface = std::move(args.fInterface); |
100 | 0 | fDriverInfo = args.fDriverInfo; |
101 | 0 | fGLSLGeneration = args.fGLSLGeneration; |
102 | |
|
103 | 0 | fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get()); |
104 | 0 | } |