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/GrContextOptions.h"
11 #include "src/gpu/ganesh/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 = SkSL::GLSLGeneration::k100es;
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 >= SkSL::GLSLGeneration::k330 &&
65 !interface->hasExtension("GL_OES_EGL_image_external_essl3") &&
66 !interface->hasExtension("OES_EGL_image_external_essl3")) {
67 args.fGLSLGeneration = SkSL::GLSLGeneration::k100es;
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
GrGLContextInfo(ConstructorArgs && args)78 GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) {
79 fInterface = std::move(args.fInterface);
80 fDriverInfo = args.fDriverInfo;
81 fGLSLGeneration = args.fGLSLGeneration;
82
83 fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get());
84 }
85