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 
      9 #ifndef GrGLContext_DEFINED
     10 #define GrGLContext_DEFINED
     11 
     12 #include "gl/GrGLExtensions.h"
     13 #include "gl/GrGLInterface.h"
     14 #include "GrGLCaps.h"
     15 #include "GrGLUtil.h"
     16 
     17 struct GrContextOptions;
     18 namespace SkSL {
     19     class Compiler;
     20 }
     21 
     22 /**
     23  * Encapsulates information about an OpenGL context including the OpenGL
     24  * version, the GrGLStandard type of the context, and GLSL version.
     25  */
     26 class GrGLContextInfo : public SkRefCnt {
     27 public:
     28     GrGLStandard standard() const { return fInterface->fStandard; }
     29     GrGLVersion version() const { return fGLVersion; }
     30     GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
     31     GrGLVendor vendor() const { return fVendor; }
     32     GrGLRenderer renderer() const { return fRenderer; }
     33     /** What driver is running our GL implementation? This is not necessarily related to the vendor.
     34         (e.g. Intel GPU being driven by Mesa) */
     35     GrGLDriver driver() const { return fDriver; }
     36     GrGLDriverVersion driverVersion() const { return fDriverVersion; }
     37     const GrGLCaps* caps() const { return fGLCaps.get(); }
     38     GrGLCaps* caps() { return fGLCaps.get(); }
     39     bool hasExtension(const char* ext) const {
     40         return fInterface->hasExtension(ext);
     41     }
     42 
     43     const GrGLExtensions& extensions() const { return fInterface->fExtensions; }
     44 
     45     virtual ~GrGLContextInfo() {}
     46 
     47 protected:
     48     struct ConstructorArgs {
     49         const GrGLInterface*                fInterface;
     50         GrGLVersion                         fGLVersion;
     51         GrGLSLGeneration                    fGLSLGeneration;
     52         GrGLVendor                          fVendor;
     53         GrGLRenderer                        fRenderer;
     54         GrGLDriver                          fDriver;
     55         GrGLDriverVersion                   fDriverVersion;
     56         const  GrContextOptions*            fContextOptions;
     57     };
     58 
     59     GrGLContextInfo(const ConstructorArgs& args);
     60 
     61     sk_sp<const GrGLInterface> fInterface;
     62     GrGLVersion                fGLVersion;
     63     GrGLSLGeneration           fGLSLGeneration;
     64     GrGLVendor                 fVendor;
     65     GrGLRenderer               fRenderer;
     66     GrGLDriver                 fDriver;
     67     GrGLDriverVersion          fDriverVersion;
     68     sk_sp<GrGLCaps>            fGLCaps;
     69 };
     70 
     71 /**
     72  * Extension of GrGLContextInfo that also provides access to GrGLInterface and SkSL::Compiler.
     73  */
     74 class GrGLContext : public GrGLContextInfo {
     75 public:
     76     /**
     77      * Creates a GrGLContext from a GrGLInterface and the currently
     78      * bound OpenGL context accessible by the GrGLInterface.
     79      */
     80     static GrGLContext* Create(const GrGLInterface* interface, const GrContextOptions& options);
     81 
     82     const GrGLInterface* interface() const { return fInterface.get(); }
     83 
     84     SkSL::Compiler* compiler() const;
     85 
     86     ~GrGLContext() override;
     87 
     88 private:
     89     GrGLContext(const ConstructorArgs& args)
     90     : INHERITED(args)
     91     , fCompiler(nullptr) {}
     92 
     93     mutable SkSL::Compiler* fCompiler;
     94 
     95     typedef GrGLContextInfo INHERITED;
     96 };
     97 
     98 #endif
     99