blob: dd774cd76d13212e08fcebbe3b9e6a4f3265ecc5 [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
joshualitt55999962015-06-18 13:47:10 -070040 args.fRenderer = GrGLGetRendererFromString(renderer);
41
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
cdalton1acea862015-06-02 13:05:52 -070056 GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver,
57 &args.fDriver, &args.fDriverVersion);
bsalomon682c2692015-05-22 14:01:46 -070058
59 args.fContextOptions = &options;
Brian Salomon8ab1cc42017-12-07 12:40:00 -050060 args.fInterface = std::move(interface);
bsalomon682c2692015-05-22 14:01:46 -070061
Brian Salomon8ab1cc42017-12-07 12:40:00 -050062 return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args)));
robertphillips@google.com6177e692013-02-28 20:16:25 +000063}
64
ethannicholas5961bc92016-10-12 06:39:56 -070065GrGLContext::~GrGLContext() {
66 delete fCompiler;
67}
68
69SkSL::Compiler* GrGLContext::compiler() const {
70 if (!fCompiler) {
71 fCompiler = new SkSL::Compiler();
72 }
73 return fCompiler;
74}
75
Brian Salomon8ab1cc42017-12-07 12:40:00 -050076GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) {
77 fInterface = std::move(args.fInterface);
bsalomon424cc262015-05-22 10:37:30 -070078 fGLVersion = args.fGLVersion;
79 fGLSLGeneration = args.fGLSLGeneration;
80 fVendor = args.fVendor;
81 fRenderer = args.fRenderer;
cdalton1acea862015-06-02 13:05:52 -070082 fDriver = args.fDriver;
83 fDriverVersion = args.fDriverVersion;
Brian Salomon266ef6d2017-09-22 11:27:42 -040084 fANGLEBackend = args.fANGLEBackend;
85 fANGLEVendor = args.fANGLEVendor;
86 fANGLERenderer = args.fANGLERenderer;
robertphillips@google.com6177e692013-02-28 20:16:25 +000087
Hal Canary144caf52016-11-07 17:57:18 -050088 fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get());
robertphillips@google.com6177e692013-02-28 20:16:25 +000089}