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