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