GrGLContext.cpp revision 9e90aed5de82732cc9921f01388d3063a41a053b
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////////////////////////////////////////////////////////////////////////////////
11GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& ctxInfo) {
12    fStandard = ctxInfo.fStandard;
13    fGLVersion = ctxInfo.fGLVersion;
14    fGLSLGeneration = ctxInfo.fGLSLGeneration;
15    fVendor = ctxInfo.fVendor;
16    fRenderer = ctxInfo.fRenderer;
17    fExtensions = ctxInfo.fExtensions;
18    fIsMesa = ctxInfo.fIsMesa;
19    fIsChromium = ctxInfo.fIsChromium;
20    *fGLCaps = *ctxInfo.fGLCaps.get();
21    return *this;
22}
23
24bool 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->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() && fExtensions.init(interface)) {
38
39            fGLVersion = GrGLGetVersionFromString(ver);
40
41            fGLSLGeneration = GrGetGLSLGeneration(interface);
42
43            fVendor = GrGLGetVendor(interface);
44
45            fRenderer = GrGLGetRendererFromString(renderer);
46
47            fIsMesa = GrGLIsMesaFromVersionString(ver);
48
49            fIsChromium = GrGLIsChromiumFromRendererString(renderer);
50
51            fGLCaps->init(*this, interface);
52
53            fStandard = interface->fStandard;
54            return true;
55        }
56    }
57    return false;
58}
59
60bool GrGLContextInfo::isInitialized() const {
61    return kNone_GrGLStandard != fStandard;
62}
63
64void GrGLContextInfo::reset() {
65    fStandard = kNone_GrGLStandard;
66    fGLVersion = GR_GL_VER(0, 0);
67    fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
68    fVendor = kOther_GrGLVendor;
69    fRenderer = kOther_GrGLRenderer;
70    fIsMesa = false;
71    fIsChromium = false;
72    fExtensions.reset();
73    fGLCaps->reset();
74}
75
76////////////////////////////////////////////////////////////////////////////////
77GrGLContext::GrGLContext(const GrGLInterface* interface) {
78    fInterface = NULL;
79    this->initialize(interface);
80}
81
82GrGLContext::GrGLContext(const GrGLContext& ctx) {
83    fInterface = NULL;
84    *this = ctx;
85}
86
87GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) {
88    SkRefCnt_SafeAssign(fInterface, ctx.fInterface);
89    fInfo = ctx.fInfo;
90    return *this;
91}
92
93void GrGLContext::reset() {
94    SkSafeSetNull(fInterface);
95    fInfo.reset();
96}
97
98bool GrGLContext::initialize(const GrGLInterface* interface) {
99    if (fInfo.initialize(interface)) {
100        fInterface = interface;
101        interface->ref();
102        return true;
103    }
104    return false;
105}
106