• Home
  • History
  • Annotate
  • 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 
10 ////////////////////////////////////////////////////////////////////////////////
11 
operator =(const GrGLContextInfo & that)12 GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& that) {
13     fInterface.reset(SkSafeRef(that.fInterface.get()));
14     fGLVersion      = that.fGLVersion;
15     fGLSLGeneration = that.fGLSLGeneration;
16     fVendor         = that.fVendor;
17     fRenderer       = that.fRenderer;
18     fIsMesa         = that.fIsMesa;
19     fIsChromium     = that.fIsChromium;
20     *fGLCaps        = *that.fGLCaps.get();
21     return *this;
22 }
23 
initialize(const GrGLInterface * interface)24 bool GrGLContextInfo::initialize(const GrGLInterface* interface) {
25     this->reset();
26     // We haven't validated the GrGLInterface yet, so check for GetString
27     // function pointer
28     if (interface->fFunctions.fGetString) {
29         const GrGLubyte* verUByte;
30         GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
31         const char* ver = reinterpret_cast<const char*>(verUByte);
32 
33         const GrGLubyte* rendererUByte;
34         GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER));
35         const char* renderer = reinterpret_cast<const char*>(rendererUByte);
36 
37         if (interface->validate()) {
38 
39             fGLVersion = GrGLGetVersionFromString(ver);
40             if (GR_GL_INVALID_VER == fGLVersion) {
41                 return false;
42             }
43 
44             if (!GrGetGLSLGeneration(interface, &fGLSLGeneration)) {
45                 return false;
46             }
47 
48             fVendor = GrGLGetVendor(interface);
49 
50             fRenderer = GrGLGetRendererFromString(renderer);
51 
52             fIsMesa = GrGLIsMesaFromVersionString(ver);
53 
54             fIsChromium = GrGLIsChromiumFromRendererString(renderer);
55 
56             // This must occur before caps init.
57             fInterface.reset(SkRef(interface));
58 
59             return fGLCaps->init(*this, interface);
60         }
61     }
62     return false;
63 }
64 
isInitialized() const65 bool GrGLContextInfo::isInitialized() const { return SkToBool(fInterface.get()); }
66 
reset()67 void GrGLContextInfo::reset() {
68     fInterface.reset(NULL);
69     fGLVersion = GR_GL_VER(0, 0);
70     fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
71     fVendor = kOther_GrGLVendor;
72     fRenderer = kOther_GrGLRenderer;
73     fIsMesa = false;
74     fIsChromium = false;
75     fGLCaps->reset();
76 }
77