blob: 9e70b472c5379535f5c02bd6b35e4232fd30e7a4 [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"
robertphillips@google.com6177e692013-02-28 20:16:25 +000010
11////////////////////////////////////////////////////////////////////////////////
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000012
bsalomon682c2692015-05-22 14:01:46 -070013GrGLContext* GrGLContext::Create(const GrGLInterface* interface, const GrContextOptions& options) {
bsalomon424cc262015-05-22 10:37:30 -070014 // We haven't validated the GrGLInterface yet, so check for GetString function pointer
15 if (!interface->fFunctions.fGetString) {
halcanary96fcdcc2015-08-27 07:41:13 -070016 return nullptr;
robertphillips@google.com6177e692013-02-28 20:16:25 +000017 }
bsalomon424cc262015-05-22 10:37:30 -070018 ConstructorArgs args;
19 args.fInterface = interface;
20
21 const GrGLubyte* verUByte;
22 GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
23 const char* ver = reinterpret_cast<const char*>(verUByte);
24
25 const GrGLubyte* rendererUByte;
26 GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER));
27 const char* renderer = reinterpret_cast<const char*>(rendererUByte);
28
29 if (!interface->validate()) {
halcanary96fcdcc2015-08-27 07:41:13 -070030 return nullptr;
bsalomon424cc262015-05-22 10:37:30 -070031 }
32
33 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
jvanverthcba99b82015-06-24 06:59:57 -070038 if (!GrGLGetGLSLGeneration(interface, &args.fGLSLGeneration)) {
halcanary96fcdcc2015-08-27 07:41:13 -070039 return nullptr;
bsalomon424cc262015-05-22 10:37:30 -070040 }
41
42 args.fVendor = GrGLGetVendor(interface);
43
joshualitt55999962015-06-18 13:47:10 -070044 args.fRenderer = GrGLGetRendererFromString(renderer);
45
bsalomon424cc262015-05-22 10:37:30 -070046 /*
joshualitt55999962015-06-18 13:47:10 -070047 * Qualcomm drivers for the 3xx series have a horrendous bug with some drivers. Though they
48 * claim to support GLES 3.00, some perfectly valid GLSL300 shaders will only compile with
bsalomon424cc262015-05-22 10:37:30 -070049 * #version 100, and will fail to compile with #version 300 es. In the long term, we
50 * need to lock this down to a specific driver version.
joshualitt55999962015-06-18 13:47:10 -070051 * ?????/2015 - This bug is still present in Lollipop pre-mr1
52 * 06/18/2015 - This bug does not affect the nexus 6 (which has an Adreno 4xx).
bsalomon424cc262015-05-22 10:37:30 -070053 */
joshualitt55999962015-06-18 13:47:10 -070054 if (kAdreno3xx_GrGLRenderer == args.fRenderer) {
bsalomon424cc262015-05-22 10:37:30 -070055 args.fGLSLGeneration = k110_GrGLSLGeneration;
56 }
57
cdalton1acea862015-06-02 13:05:52 -070058 GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver,
59 &args.fDriver, &args.fDriverVersion);
bsalomon682c2692015-05-22 14:01:46 -070060
61 args.fContextOptions = &options;
62
halcanary385fe4d2015-08-26 13:07:48 -070063 return new GrGLContext(args);
robertphillips@google.com6177e692013-02-28 20:16:25 +000064}
65
bsalomon424cc262015-05-22 10:37:30 -070066GrGLContextInfo::GrGLContextInfo(const ConstructorArgs& args) {
67 fInterface.reset(SkRef(args.fInterface));
68 fGLVersion = args.fGLVersion;
69 fGLSLGeneration = args.fGLSLGeneration;
70 fVendor = args.fVendor;
71 fRenderer = args.fRenderer;
cdalton1acea862015-06-02 13:05:52 -070072 fDriver = args.fDriver;
73 fDriverVersion = args.fDriverVersion;
robertphillips@google.com6177e692013-02-28 20:16:25 +000074
halcanary385fe4d2015-08-26 13:07:48 -070075 fGLCaps.reset(new GrGLCaps(*args.fContextOptions, *this, fInterface));
robertphillips@google.com6177e692013-02-28 20:16:25 +000076}