| bsalomon@google.com | 4ebf2b4 | 2012-02-10 21:35:35 +0000 | [diff] [blame] | 1 | |
| 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.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 9 | #include "GrGLContextInfo.h" |
| 10 | |
| 11 | GrGLContextInfo::~GrGLContextInfo() { |
| 12 | GrSafeUnref(fInterface); |
| 13 | } |
| 14 | |
| 15 | GrGLContextInfo::GrGLContextInfo() { |
| 16 | this->reset(); |
| 17 | } |
| 18 | |
| 19 | GrGLContextInfo::GrGLContextInfo(const GrGLInterface* interface) { |
| 20 | fInterface = NULL; |
| 21 | this->initialize(interface); |
| 22 | } |
| 23 | |
| 24 | GrGLContextInfo::GrGLContextInfo(const GrGLContextInfo& ctx) { |
| 25 | fInterface = NULL; |
| 26 | *this = ctx; |
| 27 | } |
| 28 | |
| 29 | GrGLContextInfo& 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.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame^] | 35 | fGLCaps = ctx.fGLCaps; |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 36 | return *this; |
| 37 | } |
| 38 | |
| 39 | void 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.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame^] | 45 | fGLCaps.reset(); |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | bool 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.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame^] | 75 | fGLCaps.init(*this); |
| bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 76 | return true; |
| 77 | } |
| 78 | } |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | bool GrGLContextInfo::isInitialized() const { |
| 83 | return kNone_GrGLBinding != fBindingInUse; |
| 84 | } |
| 85 | |