Home | History | Annotate | Download | only in gl
      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 
      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;
     35     fGLCaps = ctx.fGLCaps;
     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 = "";
     45     fGLCaps.reset();
     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 
     75             fGLCaps.init(*this);
     76             return true;
     77         }
     78     }
     79     return false;
     80 }
     81 
     82 bool GrGLContextInfo::isInitialized() const {
     83     return kNone_GrGLBinding != fBindingInUse;
     84 }
     85 
     86