GrGLContext.cpp revision a4de8c257ea0be8ff7081f645249b6afe5c48e7e
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    fBindingInUse = ctxInfo.fBindingInUse;
13    fGLVersion = ctxInfo.fGLVersion;
14    fGLSLGeneration = ctxInfo.fGLSLGeneration;
15    fVendor = ctxInfo.fVendor;
16    fExtensions = ctxInfo.fExtensions;
17    fIsMesa = ctxInfo.fIsMesa;
18    *fGLCaps = *ctxInfo.fGLCaps.get();
19    return *this;
20}
21
22bool GrGLContextInfo::initialize(const GrGLInterface* interface) {
23    this->reset();
24    // We haven't validated the GrGLInterface yet, so check for GetString
25    // function pointer
26    if (interface->fGetString) {
27        const GrGLubyte* verUByte;
28        GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
29        const char* ver = reinterpret_cast<const char*>(verUByte);
30        GrGLBinding binding = GrGLGetBindingInUseFromString(ver);
31
32        if (0 != binding && interface->validate(binding) && fExtensions.init(binding, interface)) {
33            fBindingInUse = binding;
34
35            fGLVersion = GrGLGetVersionFromString(ver);
36
37            fGLSLGeneration = GrGetGLSLGeneration(fBindingInUse, interface);
38
39            fVendor = GrGLGetVendor(interface);
40
41            fIsMesa = GrGLIsMesaFromVersionString(ver);
42
43            fGLCaps->init(*this, interface);
44            return true;
45        }
46    }
47    return false;
48}
49
50bool GrGLContextInfo::isInitialized() const {
51    return kNone_GrGLBinding != fBindingInUse;
52}
53
54void GrGLContextInfo::reset() {
55    fBindingInUse = kNone_GrGLBinding;
56    fGLVersion = GR_GL_VER(0, 0);
57    fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
58    fVendor = kOther_GrGLVendor;
59    fIsMesa = false;
60    fExtensions.reset();
61    fGLCaps->reset();
62}
63
64////////////////////////////////////////////////////////////////////////////////
65GrGLContext::GrGLContext(const GrGLInterface* interface) {
66    fInterface = NULL;
67    this->initialize(interface);
68}
69
70GrGLContext::GrGLContext(const GrGLContext& ctx) {
71    fInterface = NULL;
72    *this = ctx;
73}
74
75GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) {
76    SkRefCnt_SafeAssign(fInterface, ctx.fInterface);
77    fInfo = ctx.fInfo;
78    return *this;
79}
80
81void GrGLContext::reset() {
82    SkSafeSetNull(fInterface);
83    fInfo.reset();
84}
85
86bool GrGLContext::initialize(const GrGLInterface* interface) {
87    if (fInfo.initialize(interface)) {
88        fInterface = interface;
89        interface->ref();
90        return true;
91    }
92    return false;
93}
94