• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
Make(sk_sp<const GrGLInterface> interface,const GrContextOptions & options)14 std::unique_ptr<GrGLContext> GrGLContext::Make(sk_sp<const GrGLInterface> interface,
15                                                const GrContextOptions& options) {
16     if (!interface->validate()) {
17         return nullptr;
18     }
19 
20     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;
29     args.fGLVersion = GrGLGetVersionFromString(ver);
30     if (GR_GL_INVALID_VER == args.fGLVersion) {
31         return nullptr;
32     }
33 
34     if (!GrGLGetGLSLGeneration(interface.get(), &args.fGLSLGeneration)) {
35         return nullptr;
36     }
37 
38     args.fVendor = GrGLGetVendor(interface.get());
39 
40     args.fRenderer = GrGLGetRendererFromString(renderer);
41 
42     GrGLGetANGLEInfoFromString(renderer, &args.fANGLEBackend, &args.fANGLEVendor,
43                                &args.fANGLERenderer);
44     /*
45      * 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
47      * #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.
49      * ?????/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).
51      */
52     if (kAdreno3xx_GrGLRenderer == args.fRenderer) {
53         args.fGLSLGeneration = k110_GrGLSLGeneration;
54     }
55 
56     GrGLGetDriverInfo(interface->fStandard, args.fVendor, renderer, ver,
57                       &args.fDriver, &args.fDriverVersion);
58 
59     args.fContextOptions = &options;
60     args.fInterface = std::move(interface);
61 
62     return std::unique_ptr<GrGLContext>(new GrGLContext(std::move(args)));
63 }
64 
~GrGLContext()65 GrGLContext::~GrGLContext() {
66     delete fCompiler;
67 }
68 
compiler() const69 SkSL::Compiler* GrGLContext::compiler() const {
70     if (!fCompiler) {
71         fCompiler = new SkSL::Compiler();
72     }
73     return fCompiler;
74 }
75 
GrGLContextInfo(ConstructorArgs && args)76 GrGLContextInfo::GrGLContextInfo(ConstructorArgs&& args) {
77     fInterface = std::move(args.fInterface);
78     fGLVersion = args.fGLVersion;
79     fGLSLGeneration = args.fGLSLGeneration;
80     fVendor = args.fVendor;
81     fRenderer = args.fRenderer;
82     fDriver = args.fDriver;
83     fDriverVersion = args.fDriverVersion;
84     fANGLEBackend = args.fANGLEBackend;
85     fANGLEVendor = args.fANGLEVendor;
86     fANGLERenderer = args.fANGLERenderer;
87 
88     fGLCaps = sk_make_sp<GrGLCaps>(*args.fContextOptions, *this, fInterface.get());
89 }
90