Debian Codegraph @

src/gpu/ganesh/gl/GrGLContext.cpp

raw
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/ganesh/gl/GrGLContext.h"
9
10 #include <cstdlib>
11
12 #include "include/gpu/ganesh/GrContextOptions.h"
13 #include "src/gpu/ganesh/gl/GrGLGLSL.h"
14 #include "src/sksl/SkSLGLSL.h"
15
16 #ifdef SK_BUILD_FOR_ANDROID
17 #include <sys/system_properties.h>
18 #endif
19
20 ////////////////////////////////////////////////////////////////////////////////
21
22 std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interface,
23 const GrContextOptions& options) {
24 if (!interface->validate()) {
25 return nullptr;
26 }
27
28 ConstructorArgs args;
29 args.fDriverInfo = GrGLGetDriverInfo(interface.get());
30 if (args.fDriverInfo.fVersion == GR_GL_INVALID_VER) {
31 return nullptr;
32 }
33
34 if (!GrGLGetGLSLGeneration(args.fDriverInfo, &args.fGLSLGeneration)) {
35 return nullptr;
36 }
37
38 #ifdef SK_BUILD_FOR_ANDROID
39 auto getAndroidAPIVersion = []() {
40 char androidAPIVersion[PROP_VALUE_MAX];
41 int strLength = __system_property_get("ro.build.version.sdk", androidAPIVersion);
42 return strLength == 0 ? -1 : atoi(androidAPIVersion);
43 };
44
45 /*
46 * Qualcomm drivers for the 3xx series have a horrendous bug with some drivers. Though they
47 * claim to support GLES 3.00, some perfectly valid GLSL300 shaders will only compile with
48 * #version 100, and will fail to compile with #version 300 es. In the long term, we
49 * need to lock this down to a specific driver version.
50 * ?????/2019 - Qualcomm has fixed this for Android O+ devices (API 26+)
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).
53 */
54 if (!options.fDisableDriverCorrectnessWorkarounds &&
55 args.fDriverInfo.fRenderer == GrGLRenderer::kAdreno3xx) {
56 if (getAndroidAPIVersion() < 26) {
57 args.fGLSLGeneration = SkSL::GLSLGeneration::k100es;
58 }
59 }
60
61 /*
62 * Older versions of the Android emulator running on SwiftShader have a bug where
63 * GLSL 3.00 shaders can cause the emulator to hard crash.
64 * We workaround this by using #version 100 shaders.
65 */
66 if (!options.fDisableDriverCorrectnessWorkarounds &&
67 args.fDriverInfo.fRenderer == GrGLRenderer::kAndroidEmulator) {
68 args.fGLSLGeneration = SkSL::GLSLGeneration::k100es;
69 }
70 #endif
71
72 // Many ES3 drivers only advertise the ES2 image_external extension, but support the _essl3
73 // extension, and require that it be enabled to work with ESSL3. Other devices require the ES2
74 // extension to be enabled, even when using ESSL3. Some devices appear to only support the ES2
75 // extension. As an extreme (optional) solution, we can fallback to using ES2 shading language
76 // if we want to prioritize external texture support. skbug.com/40038974
77 if (GR_IS_GR_GL_ES(interface->fStandard) &&
78 options.fPreferExternalImagesOverES3 &&
79 !options.fDisableDriverCorrectnessWorkarounds &&
80 interface->hasExtension("GL_OES_EGL_image_external") &&
81 args.fGLSLGeneration >= SkSL::GLSLGeneration::k330 &&
82 !interface->hasExtension("GL_OES_EGL_image_external_essl3") &&
83 !interface->hasExtension("OES_EGL_image_external_essl3")) {
84 args.fGLSLGeneration = SkSL::GLSLGeneration::k100es;
85 }
86
87 args.fContextOptions = &options;
88 args.fInterface = std::move(interface);
89
90 return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args)));
91 }
92
93 GrGLContext::~GrGLContext() {}
94
95 GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) {
96 fInterface = std::move(args.fInterface);
97 fDriverInfo = args.fDriverInfo;
98 fGLSLGeneration = args.fGLSLGeneration;
99
100 fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get());
101 }