bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame^] | 1 | #include "GrGLContextInfo.h" |
| 2 | |
| 3 | GrGLContextInfo::~GrGLContextInfo() { |
| 4 | GrSafeUnref(fInterface); |
| 5 | } |
| 6 | |
| 7 | GrGLContextInfo::GrGLContextInfo() { |
| 8 | this->reset(); |
| 9 | } |
| 10 | |
| 11 | GrGLContextInfo::GrGLContextInfo(const GrGLInterface* interface) { |
| 12 | fInterface = NULL; |
| 13 | this->initialize(interface); |
| 14 | } |
| 15 | |
| 16 | GrGLContextInfo::GrGLContextInfo(const GrGLContextInfo& ctx) { |
| 17 | fInterface = NULL; |
| 18 | *this = ctx; |
| 19 | } |
| 20 | |
| 21 | GrGLContextInfo& 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 | |
| 30 | void 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 | |
| 38 | bool 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 | |
| 71 | bool GrGLContextInfo::isInitialized() const { |
| 72 | return kNone_GrGLBinding != fBindingInUse; |
| 73 | } |
| 74 | |