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 #include "SkSLCompiler.h"
11
12 ////////////////////////////////////////////////////////////////////////////////
13
Create(const GrGLInterface * interface,const GrContextOptions & options)14 GrGLContext* GrGLContext::Create(const GrGLInterface* interface, const GrContextOptions& options) {
15 // We haven't validated the GrGLInterface yet, so check for GetString function pointer
16 if (!interface->fFunctions.fGetString) {
17 return nullptr;
18 }
19 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()) {
31 return nullptr;
32 }
33
34 args.fGLVersion = GrGLGetVersionFromString(ver);
35 if (GR_GL_INVALID_VER == args.fGLVersion) {
36 return nullptr;
37 }
38
39 if (!GrGLGetGLSLGeneration(interface, &args.fGLSLGeneration)) {
40 return nullptr;
41 }
42
43 args.fVendor = GrGLGetVendor(interface);
44
45 args.fRenderer = GrGLGetRendererFromString(renderer);
46
47 /*
48 * 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
50 * #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.
52 * ?????/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).
54 */
55 if (kAdreno3xx_GrGLRenderer == args.fRenderer) {
56 args.fGLSLGeneration = k110_GrGLSLGeneration;
57 }
58
59 GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver,
60 &args.fDriver, &args.fDriverVersion);
61
62 args.fContextOptions = &options;
63
64 return new GrGLContext(args);
65 }
66
~GrGLContext()67 GrGLContext::~GrGLContext() {
68 delete fCompiler;
69 }
70
compiler() const71 SkSL::Compiler* GrGLContext::compiler() const {
72 if (!fCompiler) {
73 fCompiler = new SkSL::Compiler();
74 }
75 return fCompiler;
76 }
77
GrGLContextInfo(const ConstructorArgs & args)78 GrGLContextInfo::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;
84 fDriver = args.fDriver;
85 fDriverVersion = args.fDriverVersion;
86
87 fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get());
88 }
89