1 /*
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"
9 #include "GrGLGLSL.h"
10 
11 ////////////////////////////////////////////////////////////////////////////////
12 
Create(const GrGLInterface * interface,const GrContextOptions & options)13 GrGLContext* GrGLContext::Create(const GrGLInterface* interface, const GrContextOptions& options) {
14     // We haven't validated the GrGLInterface yet, so check for GetString function pointer
15     if (!interface->fFunctions.fGetString) {
16         return nullptr;
17     }
18     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()) {
30         return nullptr;
31     }
32 
33     args.fGLVersion = GrGLGetVersionFromString(ver);
34     if (GR_GL_INVALID_VER == args.fGLVersion) {
35         return nullptr;
36     }
37 
38     if (!GrGLGetGLSLGeneration(interface, &args.fGLSLGeneration)) {
39         return nullptr;
40     }
41 
42     args.fVendor = GrGLGetVendor(interface);
43 
44     args.fRenderer = GrGLGetRendererFromString(renderer);
45 
46     /*
47      * 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
49      * #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.
51      * ?????/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).
53      */
54     if (kAdreno3xx_GrGLRenderer == args.fRenderer) {
55         args.fGLSLGeneration = k110_GrGLSLGeneration;
56     }
57 
58     GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver,
59                       &args.fDriver, &args.fDriverVersion);
60 
61     args.fContextOptions = &options;
62 
63     return new GrGLContext(args);
64 }
65 
GrGLContextInfo(const ConstructorArgs & args)66 GrGLContextInfo::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;
72     fDriver = args.fDriver;
73     fDriverVersion = args.fDriverVersion;
74 
75     fGLCaps.reset(new GrGLCaps(*args.fContextOptions, *this, fInterface));
76 }
77