blob: e6257e7b892825cd7b580ac3c58fbce89fb18067 [file] [log] [blame]
bsalomon@google.com89ec61e2012-02-10 20:05:18 +00001#include "GrGLContextInfo.h"
2
3GrGLContextInfo::~GrGLContextInfo() {
4 GrSafeUnref(fInterface);
5}
6
7GrGLContextInfo::GrGLContextInfo() {
8 this->reset();
9}
10
11GrGLContextInfo::GrGLContextInfo(const GrGLInterface* interface) {
12 fInterface = NULL;
13 this->initialize(interface);
14}
15
16GrGLContextInfo::GrGLContextInfo(const GrGLContextInfo& ctx) {
17 fInterface = NULL;
18 *this = ctx;
19}
20
21GrGLContextInfo& GrGLContextInfo::operator = (const GrGLContextInfo& ctx) {
22 GrSafeAssign(fInterface, ctx.fInterface);
23 fBindingInUse = ctx.fBindingInUse;
24 fGLVersion = ctx.fGLVersion;
25 fGLSLGeneration = ctx.fGLSLGeneration;
26 fExtensionString = ctx.fExtensionString;
27 return *this;
28}
29
30void GrGLContextInfo::reset() {
31 GrSafeSetNull(fInterface);
32 fBindingInUse = kNone_GrGLBinding;
33 fGLVersion = GR_GL_VER(0, 0);
34 fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
35 fExtensionString = "";
36}
37
38bool GrGLContextInfo::initialize(const GrGLInterface* interface) {
39 this->reset();
40 // We haven't validated the GrGLInterface yet, so check for GetString
41 // function pointer
42 if (NULL != interface->fGetString) {
43
44 const GrGLubyte* verUByte;
45 GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
46 const char* ver = reinterpret_cast<const char*>(verUByte);
47 GrGLBinding binding = GrGLGetBindingInUseFromString(ver);
48
49 if (!interface->validate(fBindingInUse)) {
50
51 fInterface = interface;
52 interface->ref();
53
54 fBindingInUse = binding;
55
56 fGLVersion = GrGLGetVersionFromString(ver);
57
58 fGLSLGeneration = GrGetGLSLGeneration(fBindingInUse,
59 this->interface());
60
61 const GrGLubyte* ext;
62 GR_GL_CALL_RET(interface, ext, GetString(GR_GL_EXTENSIONS));
63 fExtensionString = reinterpret_cast<const char*>(ext);
64
65 return true;
66 }
67 }
68 return false;
69}
70
71bool GrGLContextInfo::isInitialized() const {
72 return kNone_GrGLBinding != fBindingInUse;
73}
74