blob: 9d18b5fee2e848e0f75e447bfb0724e4e8c8e9fb [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
bsalomon682c2692015-05-22 14:01:46 -070014GrGLContext* GrGLContext::Create(const GrGLInterface* interface, const GrContextOptions& options) {
bsalomon424cc262015-05-22 10:37:30 -070015 // We haven't validated the GrGLInterface yet, so check for GetString function pointer
16 if (!interface->fFunctions.fGetString) {
halcanary96fcdcc2015-08-27 07:41:13 -070017 return nullptr;
robertphillips@google.com6177e692013-02-28 20:16:25 +000018 }
bsalomon424cc262015-05-22 10:37:30 -070019 ConstructorArgs args;
20 args.fInterface = interface;
21
22 const GrGLubyte* verUByte;
23 GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
24 const char* ver = reinterpret_cast<const char*>(verUByte);
25
26 const GrGLubyte* rendererUByte;
27 GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER));
28 const char* renderer = reinterpret_cast<const char*>(rendererUByte);
29
30 if (!interface->validate()) {
halcanary96fcdcc2015-08-27 07:41:13 -070031 return nullptr;
bsalomon424cc262015-05-22 10:37:30 -070032 }
33
34 args.fGLVersion = GrGLGetVersionFromString(ver);
35 if (GR_GL_INVALID_VER == args.fGLVersion) {
halcanary96fcdcc2015-08-27 07:41:13 -070036 return nullptr;
bsalomon424cc262015-05-22 10:37:30 -070037 }
38
jvanverthcba99b82015-06-24 06:59:57 -070039 if (!GrGLGetGLSLGeneration(interface, &args.fGLSLGeneration)) {
halcanary96fcdcc2015-08-27 07:41:13 -070040 return nullptr;
bsalomon424cc262015-05-22 10:37:30 -070041 }
42
43 args.fVendor = GrGLGetVendor(interface);
44
joshualitt55999962015-06-18 13:47:10 -070045 args.fRenderer = GrGLGetRendererFromString(renderer);
46
Brian Salomon266ef6d2017-09-22 11:27:42 -040047 GrGLGetANGLEInfoFromString(renderer, &args.fANGLEBackend, &args.fANGLEVendor,
48 &args.fANGLERenderer);
bsalomon424cc262015-05-22 10:37:30 -070049 /*
joshualitt55999962015-06-18 13:47:10 -070050 * Qualcomm drivers for the 3xx series have a horrendous bug with some drivers. Though they
51 * claim to support GLES 3.00, some perfectly valid GLSL300 shaders will only compile with
bsalomon424cc262015-05-22 10:37:30 -070052 * #version 100, and will fail to compile with #version 300 es. In the long term, we
53 * need to lock this down to a specific driver version.
joshualitt55999962015-06-18 13:47:10 -070054 * ?????/2015 - This bug is still present in Lollipop pre-mr1
55 * 06/18/2015 - This bug does not affect the nexus 6 (which has an Adreno 4xx).
bsalomon424cc262015-05-22 10:37:30 -070056 */
joshualitt55999962015-06-18 13:47:10 -070057 if (kAdreno3xx_GrGLRenderer == args.fRenderer) {
bsalomon424cc262015-05-22 10:37:30 -070058 args.fGLSLGeneration = k110_GrGLSLGeneration;
59 }
60
cdalton1acea862015-06-02 13:05:52 -070061 GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver,
62 &args.fDriver, &args.fDriverVersion);
bsalomon682c2692015-05-22 14:01:46 -070063
64 args.fContextOptions = &options;
65
halcanary385fe4d2015-08-26 13:07:48 -070066 return new GrGLContext(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
bsalomon424cc262015-05-22 10:37:30 -070080GrGLContextInfo::GrGLContextInfo(const ConstructorArgs& args) {
81 fInterface.reset(SkRef(args.fInterface));
82 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}