blob: 2ae47101e69f5bb501f8a5308333bea946be5b70 [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
Chris Dalton0090ef62018-03-28 17:35:00 -060028 const GrGLubyte* extensionsUByte;
29 GR_GL_CALL_RET(interface.get(), extensionsUByte, GetString(GR_GL_EXTENSIONS));
30 const char* extensions = reinterpret_cast<const char*>(extensionsUByte);
31
Brian Salomon8ab1cc42017-12-07 12:40:00 -050032 ConstructorArgs args;
bsalomon424cc262015-05-22 10:37:30 -070033 args.fGLVersion = GrGLGetVersionFromString(ver);
34 if (GR_GL_INVALID_VER == args.fGLVersion) {
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 if (!GrGLGetGLSLGeneration(interface.get(), &args.fGLSLGeneration)) {
halcanary96fcdcc2015-08-27 07:41:13 -070039 return nullptr;
bsalomon424cc262015-05-22 10:37:30 -070040 }
41
Brian Salomon8ab1cc42017-12-07 12:40:00 -050042 args.fVendor = GrGLGetVendor(interface.get());
bsalomon424cc262015-05-22 10:37:30 -070043
Chris Dalton0090ef62018-03-28 17:35:00 -060044 args.fRenderer = GrGLGetRendererFromStrings(renderer, extensions);
joshualitt55999962015-06-18 13:47:10 -070045
Brian Salomon266ef6d2017-09-22 11:27:42 -040046 GrGLGetANGLEInfoFromString(renderer, &args.fANGLEBackend, &args.fANGLEVendor,
47 &args.fANGLERenderer);
bsalomon424cc262015-05-22 10:37:30 -070048 /*
joshualitt55999962015-06-18 13:47:10 -070049 * Qualcomm drivers for the 3xx series have a horrendous bug with some drivers. Though they
50 * claim to support GLES 3.00, some perfectly valid GLSL300 shaders will only compile with
bsalomon424cc262015-05-22 10:37:30 -070051 * #version 100, and will fail to compile with #version 300 es. In the long term, we
52 * need to lock this down to a specific driver version.
joshualitt55999962015-06-18 13:47:10 -070053 * ?????/2015 - This bug is still present in Lollipop pre-mr1
54 * 06/18/2015 - This bug does not affect the nexus 6 (which has an Adreno 4xx).
bsalomon424cc262015-05-22 10:37:30 -070055 */
joshualitt55999962015-06-18 13:47:10 -070056 if (kAdreno3xx_GrGLRenderer == args.fRenderer) {
bsalomon424cc262015-05-22 10:37:30 -070057 args.fGLSLGeneration = k110_GrGLSLGeneration;
58 }
59
cdalton1acea862015-06-02 13:05:52 -070060 GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver,
61 &args.fDriver, &args.fDriverVersion);
bsalomon682c2692015-05-22 14:01:46 -070062
63 args.fContextOptions = &options;
Brian Salomon8ab1cc42017-12-07 12:40:00 -050064 args.fInterface = std::move(interface);
bsalomon682c2692015-05-22 14:01:46 -070065
Brian Salomon8ab1cc42017-12-07 12:40:00 -050066 return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args)));
robertphillips@google.com6177e692013-02-28 20:16:25 +000067}
68
ethannicholas5961bc92016-10-12 06:39:56 -070069GrGLContext::~GrGLContext() {
70 delete fCompiler;
71}
72
73SkSL::Compiler* GrGLContext::compiler() const {
74 if (!fCompiler) {
75 fCompiler = new SkSL::Compiler();
76 }
77 return fCompiler;
78}
79
Brian Salomon8ab1cc42017-12-07 12:40:00 -050080GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) {
81 fInterface = std::move(args.fInterface);
bsalomon424cc262015-05-22 10:37:30 -070082 fGLVersion = args.fGLVersion;
83 fGLSLGeneration = args.fGLSLGeneration;
84 fVendor = args.fVendor;
85 fRenderer = args.fRenderer;
cdalton1acea862015-06-02 13:05:52 -070086 fDriver = args.fDriver;
87 fDriverVersion = args.fDriverVersion;
Brian Salomon266ef6d2017-09-22 11:27:42 -040088 fANGLEBackend = args.fANGLEBackend;
89 fANGLEVendor = args.fANGLEVendor;
90 fANGLERenderer = args.fANGLERenderer;
robertphillips@google.com6177e692013-02-28 20:16:25 +000091
Hal Canary144caf52016-11-07 17:57:18 -050092 fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get());
robertphillips@google.com6177e692013-02-28 20:16:25 +000093}