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: standard()28 GrGLStandard standard() const { return fInterface->fStandard; } version()29 GrGLVersion version() const { return fGLVersion; } glslGeneration()30 GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; } vendor()31 GrGLVendor vendor() const { return fVendor; } renderer()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) */ driver()35 GrGLDriver driver() const { return fDriver; } driverVersion()36 GrGLDriverVersion driverVersion() const { return fDriverVersion; } caps()37 const GrGLCaps* caps() const { return fGLCaps.get(); } caps()38 GrGLCaps* caps() { return fGLCaps.get(); } hasExtension(const char * ext)39 bool hasExtension(const char* ext) const { 40 return fInterface->hasExtension(ext); 41 } 42 extensions()43 const GrGLExtensions& extensions() const { return fInterface->fExtensions; } 44 ~GrGLContextInfo()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 interface()82 const GrGLInterface* interface() const { return fInterface.get(); } 83 84 SkSL::Compiler* compiler() const; 85 86 ~GrGLContext() override; 87 88 private: GrGLContext(const ConstructorArgs & args)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