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