Home | History | Annotate | Download | only in gl
      1 /*
      2  * Copyright 2013 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 "GrGLContext.h"
      9 
     10 ////////////////////////////////////////////////////////////////////////////////
     11 GrGLContextInfo& GrGLContextInfo::operator= (const GrGLContextInfo& ctxInfo) {
     12     fBindingInUse = ctxInfo.fBindingInUse;
     13     fGLVersion = ctxInfo.fGLVersion;
     14     fGLSLGeneration = ctxInfo.fGLSLGeneration;
     15     fVendor = ctxInfo.fVendor;
     16     fRenderer = ctxInfo.fRenderer;
     17     fExtensions = ctxInfo.fExtensions;
     18     fIsMesa = ctxInfo.fIsMesa;
     19     fIsChromium = ctxInfo.fIsChromium;
     20     *fGLCaps = *ctxInfo.fGLCaps.get();
     21     return *this;
     22 }
     23 
     24 bool GrGLContextInfo::initialize(const GrGLInterface* interface) {
     25     this->reset();
     26     // We haven't validated the GrGLInterface yet, so check for GetString
     27     // function pointer
     28     if (interface->fGetString) {
     29         const GrGLubyte* verUByte;
     30         GR_GL_CALL_RET(interface, verUByte, GetString(GR_GL_VERSION));
     31         const char* ver = reinterpret_cast<const char*>(verUByte);
     32 
     33         const GrGLubyte* rendererUByte;
     34         GR_GL_CALL_RET(interface, rendererUByte, GetString(GR_GL_RENDERER));
     35         const char* renderer = reinterpret_cast<const char*>(rendererUByte);
     36 
     37         GrGLBinding binding = GrGLGetBindingInUseFromString(ver);
     38 
     39         if (0 != binding && interface->validate(binding) && fExtensions.init(binding, interface)) {
     40             fBindingInUse = binding;
     41 
     42             fGLVersion = GrGLGetVersionFromString(ver);
     43 
     44             fGLSLGeneration = GrGetGLSLGeneration(fBindingInUse, interface);
     45 
     46             fVendor = GrGLGetVendor(interface);
     47 
     48             fRenderer = GrGLGetRendererFromString(renderer);
     49 
     50             fIsMesa = GrGLIsMesaFromVersionString(ver);
     51 
     52             fIsChromium = GrGLIsChromiumFromRendererString(renderer);
     53 
     54             fGLCaps->init(*this, interface);
     55             return true;
     56         }
     57     }
     58     return false;
     59 }
     60 
     61 bool GrGLContextInfo::isInitialized() const {
     62     return kNone_GrGLBinding != fBindingInUse;
     63 }
     64 
     65 void GrGLContextInfo::reset() {
     66     fBindingInUse = kNone_GrGLBinding;
     67     fGLVersion = GR_GL_VER(0, 0);
     68     fGLSLGeneration = static_cast<GrGLSLGeneration>(0);
     69     fVendor = kOther_GrGLVendor;
     70     fRenderer = kOther_GrGLRenderer;
     71     fIsMesa = false;
     72     fIsChromium = false;
     73     fExtensions.reset();
     74     fGLCaps->reset();
     75 }
     76 
     77 ////////////////////////////////////////////////////////////////////////////////
     78 GrGLContext::GrGLContext(const GrGLInterface* interface) {
     79     fInterface = NULL;
     80     this->initialize(interface);
     81 }
     82 
     83 GrGLContext::GrGLContext(const GrGLContext& ctx) {
     84     fInterface = NULL;
     85     *this = ctx;
     86 }
     87 
     88 GrGLContext& GrGLContext::operator = (const GrGLContext& ctx) {
     89     SkRefCnt_SafeAssign(fInterface, ctx.fInterface);
     90     fInfo = ctx.fInfo;
     91     return *this;
     92 }
     93 
     94 void GrGLContext::reset() {
     95     SkSafeSetNull(fInterface);
     96     fInfo.reset();
     97 }
     98 
     99 bool GrGLContext::initialize(const GrGLInterface* interface) {
    100     if (fInfo.initialize(interface)) {
    101         fInterface = interface;
    102         interface->ref();
    103         return true;
    104     }
    105     return false;
    106 }
    107