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