blob: 2126314a7be8f677b7fea1d6b9a1fa19d4b20c39 [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"
ethannicholasdcfe6db2016-10-10 10:09:00 -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
bsalomon424cc262015-05-22 10:37:30 -070047 /*
joshualitt55999962015-06-18 13:47:10 -070048 * Qualcomm drivers for the 3xx series have a horrendous bug with some drivers. Though they
49 * claim to support GLES 3.00, some perfectly valid GLSL300 shaders will only compile with
bsalomon424cc262015-05-22 10:37:30 -070050 * #version 100, and will fail to compile with #version 300 es. In the long term, we
51 * need to lock this down to a specific driver version.
joshualitt55999962015-06-18 13:47:10 -070052 * ?????/2015 - This bug is still present in Lollipop pre-mr1
53 * 06/18/2015 - This bug does not affect the nexus 6 (which has an Adreno 4xx).
bsalomon424cc262015-05-22 10:37:30 -070054 */
joshualitt55999962015-06-18 13:47:10 -070055 if (kAdreno3xx_GrGLRenderer == args.fRenderer) {
bsalomon424cc262015-05-22 10:37:30 -070056 args.fGLSLGeneration = k110_GrGLSLGeneration;
57 }
58
cdalton1acea862015-06-02 13:05:52 -070059 GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver,
60 &args.fDriver, &args.fDriverVersion);
bsalomon682c2692015-05-22 14:01:46 -070061
62 args.fContextOptions = &options;
63
halcanary385fe4d2015-08-26 13:07:48 -070064 return new GrGLContext(args);
robertphillips@google.com6177e692013-02-28 20:16:25 +000065}
66
ethannicholasdcfe6db2016-10-10 10:09:00 -070067GrGLContext::~GrGLContext() {
68 delete fCompiler;
69}
70
71SkSL::Compiler* GrGLContext::compiler() const {
72 if (!fCompiler) {
73 fCompiler = new SkSL::Compiler();
74 }
75 return fCompiler;
76}
77
bsalomon424cc262015-05-22 10:37:30 -070078GrGLContextInfo::GrGLContextInfo(const ConstructorArgs& args) {
79 fInterface.reset(SkRef(args.fInterface));
80 fGLVersion = args.fGLVersion;
81 fGLSLGeneration = args.fGLSLGeneration;
82 fVendor = args.fVendor;
83 fRenderer = args.fRenderer;
cdalton1acea862015-06-02 13:05:52 -070084 fDriver = args.fDriver;
85 fDriverVersion = args.fDriverVersion;
robertphillips@google.com6177e692013-02-28 20:16:25 +000086
halcanary385fe4d2015-08-26 13:07:48 -070087 fGLCaps.reset(new GrGLCaps(*args.fContextOptions, *this, fInterface));
robertphillips@google.com6177e692013-02-28 20:16:25 +000088}