blob: a2a5a3b130816b538fe656e12a2127bbf90d0419 [file] [log] [blame]
robertphillips@google.com6177e692013-02-28 20:16:25 +00001/*
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 "GrGLContext.h"
jvanverthcba99b82015-06-24 06:59:57 -07009#include "GrGLGLSL.h"
ethannicholas5961bc92016-10-12 06:39:56 -070010#include "SkSLCompiler.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000011
12////////////////////////////////////////////////////////////////////////////////
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000013
Brian Salomon8ab1cc42017-12-07 12:40:00 -050014std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interface,
15 const GrContextOptions& options) {
bsalomon424cc262015-05-22 10:37:30 -070016 if (!interface->validate()) {
halcanary96fcdcc2015-08-27 07:41:13 -070017 return nullptr;
bsalomon424cc262015-05-22 10:37:30 -070018 }
19
Brian Salomon8ab1cc42017-12-07 12:40:00 -050020 const GrGLubyte* verUByte;
21 GR_GL_CALL_RET(interface.get(), verUByte, GetString(GR_GL_VERSION));
22 const char* ver = reinterpret_cast<const char*>(verUByte);
23
24 const GrGLubyte* rendererUByte;
25 GR_GL_CALL_RET(interface.get(), rendererUByte, GetString(GR_GL_RENDERER));
26 const char* renderer = reinterpret_cast<const char*>(rendererUByte);
27
28 ConstructorArgs args;
bsalomon424cc262015-05-22 10:37:30 -070029 args.fGLVersion = GrGLGetVersionFromString(ver);
30 if (GR_GL_INVALID_VER == args.fGLVersion) {
halcanary96fcdcc2015-08-27 07:41:13 -070031 return nullptr;
bsalomon424cc262015-05-22 10:37:30 -070032 }
33
Brian Salomon8ab1cc42017-12-07 12:40:00 -050034 if (!GrGLGetGLSLGeneration(interface.get(), &args.fGLSLGeneration)) {
halcanary96fcdcc2015-08-27 07:41:13 -070035 return nullptr;
bsalomon424cc262015-05-22 10:37:30 -070036 }
37
Brian Salomon8ab1cc42017-12-07 12:40:00 -050038 args.fVendor = GrGLGetVendor(interface.get());
bsalomon424cc262015-05-22 10:37:30 -070039
Brian Salomon4470e342018-04-04 14:27:48 -040040 args.fRenderer = GrGLGetRendererFromStrings(renderer, interface->fExtensions);
joshualitt55999962015-06-18 13:47:10 -070041
Brian Salomon266ef6d2017-09-22 11:27:42 -040042 GrGLGetANGLEInfoFromString(renderer, &args.fANGLEBackend, &args.fANGLEVendor,
43 &args.fANGLERenderer);
bsalomon424cc262015-05-22 10:37:30 -070044 /*
joshualitt55999962015-06-18 13:47:10 -070045 * Qualcomm drivers for the 3xx series have a horrendous bug with some drivers. Though they
46 * claim to support GLES 3.00, some perfectly valid GLSL300 shaders will only compile with
bsalomon424cc262015-05-22 10:37:30 -070047 * #version 100, and will fail to compile with #version 300 es. In the long term, we
48 * need to lock this down to a specific driver version.
joshualitt55999962015-06-18 13:47:10 -070049 * ?????/2015 - This bug is still present in Lollipop pre-mr1
50 * 06/18/2015 - This bug does not affect the nexus 6 (which has an Adreno 4xx).
bsalomon424cc262015-05-22 10:37:30 -070051 */
joshualitt55999962015-06-18 13:47:10 -070052 if (kAdreno3xx_GrGLRenderer == args.fRenderer) {
bsalomon424cc262015-05-22 10:37:30 -070053 args.fGLSLGeneration = k110_GrGLSLGeneration;
54 }
55
Brian Osman06d37462018-05-08 13:00:42 -040056 // 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 (kGLES_GrGLStandard == interface->fStandard &&
62 options.fPreferExternalImagesOverES3 &&
63 !options.fDisableDriverCorrectnessWorkarounds &&
64 interface->hasExtension("GL_OES_EGL_image_external") &&
65 args.fGLSLGeneration >= k330_GrGLSLGeneration &&
66 !interface->hasExtension("GL_OES_EGL_image_external_essl3") &&
67 !interface->hasExtension("OES_EGL_image_external_essl3")) {
68 args.fGLSLGeneration = k110_GrGLSLGeneration;
69 }
70
cdalton1acea862015-06-02 13:05:52 -070071 GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver,
72 &args.fDriver, &args.fDriverVersion);
bsalomon682c2692015-05-22 14:01:46 -070073
74 args.fContextOptions = &options;
Brian Salomon8ab1cc42017-12-07 12:40:00 -050075 args.fInterface = std::move(interface);
bsalomon682c2692015-05-22 14:01:46 -070076
Brian Salomon8ab1cc42017-12-07 12:40:00 -050077 return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args)));
robertphillips@google.com6177e692013-02-28 20:16:25 +000078}
79
ethannicholas5961bc92016-10-12 06:39:56 -070080GrGLContext::~GrGLContext() {
81 delete fCompiler;
82}
83
84SkSL::Compiler* GrGLContext::compiler() const {
85 if (!fCompiler) {
86 fCompiler = new SkSL::Compiler();
87 }
88 return fCompiler;
89}
90
Brian Salomon8ab1cc42017-12-07 12:40:00 -050091GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) {
92 fInterface = std::move(args.fInterface);
bsalomon424cc262015-05-22 10:37:30 -070093 fGLVersion = args.fGLVersion;
94 fGLSLGeneration = args.fGLSLGeneration;
95 fVendor = args.fVendor;
96 fRenderer = args.fRenderer;
cdalton1acea862015-06-02 13:05:52 -070097 fDriver = args.fDriver;
98 fDriverVersion = args.fDriverVersion;
Brian Salomon266ef6d2017-09-22 11:27:42 -040099 fANGLEBackend = args.fANGLEBackend;
100 fANGLEVendor = args.fANGLEVendor;
101 fANGLERenderer = args.fANGLERenderer;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000102
Hal Canary144caf52016-11-07 17:57:18 -0500103 fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get());
robertphillips@google.com6177e692013-02-28 20:16:25 +0000104}