blob: 33e19ab0609e44990bdc8665ca1e85390cb5d0eb [file] [log] [blame]
bsalomon@google.com4ebf2b42012-02-10 21:35:35 +00001
2/*
3 * Copyright 2012 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
bsalomon@google.com89ec61e2012-02-10 20:05:18 +00009#include "GrGLContextInfo.h"
10
11GrGLContextInfo::~GrGLContextInfo() {
12 GrSafeUnref(fInterface);
13}
14
15GrGLContextInfo::GrGLContextInfo() {
16 this->reset();
17}
18
19GrGLContextInfo::GrGLContextInfo(const GrGLInterface* interface) {
20 fInterface = NULL;
21 this->initialize(interface);
22}
23
24GrGLContextInfo::GrGLContextInfo(const GrGLContextInfo& ctx) {
25 fInterface = NULL;
26 *this = ctx;
27}
28
29GrGLContextInfo& GrGLContextInfo::operator = (const GrGLContextInfo& ctx) {
30 GrSafeAssign(fInterface, ctx.fInterface);
31 fBindingInUse = ctx.fBindingInUse;
32 fGLVersion = ctx.fGLVersion;
33 fGLSLGeneration = ctx.fGLSLGeneration;
34 fExtensionString = ctx.fExtensionString;
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000035 fGLCaps = ctx.fGLCaps;
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000036 return *this;
37}
38
39void GrGLContextInfo::reset() {
40 GrSafeSetNull(fInterface);
41 fBindingInUse = kNone_GrGLBinding;
42 fGLVersion = GR_GL_VER(0, 0);
43 fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
44 fExtensionString = "";
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000045 fGLCaps.reset();
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000046}
47
48bool GrGLContextInfo::initialize(const GrGLInterface* interface) {
49 this->reset();
50 // We haven't validated the GrGLInterface yet, so check for GetString
51 // function pointer
52 if (NULL != interface->fGetString) {
53
54 const GrGLubyte* verUByte;
55 GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
56 const char* ver = reinterpret_cast<const char*>(verUByte);
57 GrGLBinding binding = GrGLGetBindingInUseFromString(ver);
58
59 if (!interface->validate(fBindingInUse)) {
60
61 fInterface = interface;
62 interface->ref();
63
64 fBindingInUse = binding;
65
66 fGLVersion = GrGLGetVersionFromString(ver);
67
68 fGLSLGeneration = GrGetGLSLGeneration(fBindingInUse,
69 this->interface());
70
71 const GrGLubyte* ext;
72 GR_GL_CALL_RET(interface, ext, GetString(GR_GL_EXTENSIONS));
73 fExtensionString = reinterpret_cast<const char*>(ext);
74
bsalomon@google.comf7fa8062012-02-14 14:09:57 +000075 fGLCaps.init(*this);
bsalomon@google.com89ec61e2012-02-10 20:05:18 +000076 return true;
77 }
78 }
79 return false;
80}
81
82bool GrGLContextInfo::isInitialized() const {
83 return kNone_GrGLBinding != fBindingInUse;
84}
85