aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGLContextInfo.cpp
blob: 060d236b22d6a1a7707668101d1deac542eba024 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "GrGLContextInfo.h"

GrGLContextInfo::~GrGLContextInfo() {
    GrSafeUnref(fInterface);
}

GrGLContextInfo::GrGLContextInfo() {
    this->reset();
}

GrGLContextInfo::GrGLContextInfo(const GrGLInterface* interface) {
    fInterface = NULL;
    this->initialize(interface);
}

GrGLContextInfo::GrGLContextInfo(const GrGLContextInfo& ctx) {
    fInterface = NULL;
    *this = ctx;
}

GrGLContextInfo& GrGLContextInfo::operator = (const GrGLContextInfo& ctx) {
    GrSafeAssign(fInterface, ctx.fInterface);
    fBindingInUse = ctx.fBindingInUse;
    fGLVersion = ctx.fGLVersion;
    fGLSLGeneration = ctx.fGLSLGeneration;
    fVendor = ctx.fVendor;
    fExtensionString = ctx.fExtensionString;
    fGLCaps = ctx.fGLCaps;
    return *this;
}

void GrGLContextInfo::reset() {
    GrSafeSetNull(fInterface);
    fBindingInUse = kNone_GrGLBinding;
    fGLVersion = GR_GL_VER(0, 0);
    fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
    fVendor = kOther_GrGLVendor;
    fExtensionString = "";
    fGLCaps.reset();
}

bool GrGLContextInfo::initialize(const GrGLInterface* interface) {
    this->reset();
    // We haven't validated the GrGLInterface yet, so check for GetString
    // function pointer
    if (NULL != interface->fGetString) {

        const GrGLubyte* verUByte;
        GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
        const char* ver = reinterpret_cast<const char*>(verUByte);
        GrGLBinding binding = GrGLGetBindingInUseFromString(ver);

        if (interface->validate(binding)) {

            fInterface = interface;
            interface->ref();

            fBindingInUse = binding;

            fGLVersion = GrGLGetVersionFromString(ver);

            fGLSLGeneration = GrGetGLSLGeneration(fBindingInUse,
                                                  this->interface());

            const GrGLubyte* ext;
            GR_GL_CALL_RET(interface, ext, GetString(GR_GL_EXTENSIONS));
            fExtensionString = reinterpret_cast<const char*>(ext);
            fVendor = GrGLGetVendor(interface);
            fGLCaps.init(*this);
            return true;
        }
    }
    return false;
}

bool GrGLContextInfo::isInitialized() const {
    return kNone_GrGLBinding != fBindingInUse;
}