1/* 2 * Copyright 2012 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 "GrGLContextInfo.h" 9 10GrGLContextInfo::~GrGLContextInfo() { 11 GrSafeUnref(fInterface); 12} 13 14GrGLContextInfo::GrGLContextInfo() { 15 this->reset(); 16} 17 18GrGLContextInfo::GrGLContextInfo(const GrGLInterface* interface) { 19 fInterface = NULL; 20 this->initialize(interface); 21} 22 23GrGLContextInfo::GrGLContextInfo(const GrGLContextInfo& ctx) { 24 fInterface = NULL; 25 *this = ctx; 26} 27 28GrGLContextInfo& GrGLContextInfo::operator = (const GrGLContextInfo& ctx) { 29 GrSafeAssign(fInterface, ctx.fInterface); 30 fBindingInUse = ctx.fBindingInUse; 31 fGLVersion = ctx.fGLVersion; 32 fGLSLGeneration = ctx.fGLSLGeneration; 33 fVendor = ctx.fVendor; 34 fExtensionString = ctx.fExtensionString; 35 fGLCaps = ctx.fGLCaps; 36 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 fVendor = kOther_GrGLVendor; 45 fExtensionString = ""; 46 fGLCaps.reset(); 47} 48 49bool GrGLContextInfo::initialize(const GrGLInterface* interface) { 50 this->reset(); 51 // We haven't validated the GrGLInterface yet, so check for GetString 52 // function pointer 53 if (NULL != interface->fGetString) { 54 55 const GrGLubyte* verUByte; 56 GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION)); 57 const char* ver = reinterpret_cast<const char*>(verUByte); 58 GrGLBinding binding = GrGLGetBindingInUseFromString(ver); 59 60 if (interface->validate(binding)) { 61 62 fInterface = interface; 63 interface->ref(); 64 65 fBindingInUse = binding; 66 67 fGLVersion = GrGLGetVersionFromString(ver); 68 69 fGLSLGeneration = GrGetGLSLGeneration(fBindingInUse, 70 this->interface()); 71 72 const GrGLubyte* ext; 73 GR_GL_CALL_RET(interface, ext, GetString(GR_GL_EXTENSIONS)); 74 fExtensionString = reinterpret_cast<const char*>(ext); 75 fVendor = GrGLGetVendor(interface); 76 fGLCaps.init(*this); 77 return true; 78 } 79 } 80 return false; 81} 82 83bool GrGLContextInfo::isInitialized() const { 84 return kNone_GrGLBinding != fBindingInUse; 85} 86