GrGLContext.cpp revision b1854a85095f9924947bc00e665da47b0c0bdfb9
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
12GrGLContextInfo& 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    fExtensions     = that.fExtensions;
19    fIsMesa         = that.fIsMesa;
20    fIsChromium     = that.fIsChromium;
21    *fGLCaps        = *that.fGLCaps.get();
22    return *this;
23}
24
25bool GrGLContextInfo::initialize(const GrGLInterface* interface) {
26    this->reset();
27    // We haven't validated the GrGLInterface yet, so check for GetString
28    // function pointer
29    if (interface->fGetString) {
30        const GrGLubyte* verUByte;
31        GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
32        const char* ver = reinterpret_cast<const char*>(verUByte);
33
34        const GrGLubyte* rendererUByte;
35        GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER));
36        const char* renderer = reinterpret_cast<const char*>(rendererUByte);
37
38        if (interface->validate() && fExtensions.init(interface)) {
39
40            fGLVersion = GrGLGetVersionFromString(ver);
41
42            fGLSLGeneration = GrGetGLSLGeneration(interface);
43
44            fVendor = GrGLGetVendor(interface);
45
46            fRenderer = GrGLGetRendererFromString(renderer);
47
48            fIsMesa = GrGLIsMesaFromVersionString(ver);
49
50            fIsChromium = GrGLIsChromiumFromRendererString(renderer);
51
52            // This must occur before caps init.
53            fInterface.reset(SkRef(interface));
54
55            fGLCaps->init(*this, interface);
56
57            return true;
58        }
59    }
60    return false;
61}
62
63bool GrGLContextInfo::isInitialized() const {
64    return NULL != fInterface.get();
65}
66
67void 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    fExtensions.reset();
76    fGLCaps->reset();
77}
78