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