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 "include/gpu/gl/GrGLExtensions.h" 13 #include "include/gpu/gl/GrGLInterface.h" 14 #include "src/gpu/ganesh/gl/GrGLCaps.h" 15 #include "src/gpu/ganesh/gl/GrGLUtil.h" 16 17 struct GrContextOptions; 18 19 /** 20 * Encapsulates information about an OpenGL context including the OpenGL 21 * version, the GrGLStandard type of the context, and GLSL version. 22 */ 23 class GrGLContextInfo { 24 public: 25 GrGLContextInfo(GrGLContextInfo&&) = default; 26 GrGLContextInfo& operator=(GrGLContextInfo&&) = default; 27 ~GrGLContextInfo()28 virtual ~GrGLContextInfo() {} 29 standard()30 GrGLStandard standard() const { return fInterface->fStandard; } version()31 GrGLVersion version() const { return fDriverInfo.fVersion; } glslGeneration()32 SkSL::GLSLGeneration glslGeneration() const { return fGLSLGeneration; } 33 /** 34 * We've accumlated a lot of GL driver workarounds and performance preferences based on vendor 35 * and renderer. When we have GL sitting on top of Angle it is not clear which of these are 36 * necessary and which are handle by Angle. Thus to be safe we get the underlying GL vendor and 37 * renderer from Angle so we can enable these workarounds. It may mean that the same workaround 38 * is implemented both in Skia and Angle, but that is better than missing out on one. 39 */ vendor()40 GrGLVendor vendor() const { 41 if (this->angleBackend() == GrGLANGLEBackend::kOpenGL) { 42 return this->angleVendor(); 43 } else { 44 return fDriverInfo.fVendor; 45 } 46 } renderer()47 GrGLRenderer renderer() const { 48 if (this->angleBackend() == GrGLANGLEBackend::kOpenGL) { 49 return this->angleRenderer(); 50 } else { 51 return fDriverInfo.fRenderer; 52 } 53 } angleBackend()54 GrGLANGLEBackend angleBackend() const { return fDriverInfo.fANGLEBackend; } angleDriver()55 GrGLDriver angleDriver() const { return fDriverInfo.fANGLEDriver; } angleVendor()56 GrGLVendor angleVendor() const { return fDriverInfo.fANGLEVendor; } angleRenderer()57 GrGLRenderer angleRenderer() const { return fDriverInfo.fANGLERenderer; } 58 webglVendor()59 GrGLVendor webglVendor() const { return fDriverInfo.fWebGLVendor; } webglRenderer()60 GrGLRenderer webglRenderer() const { return fDriverInfo.fWebGLRenderer; } 61 62 /** What driver is running our GL implementation? This is not necessarily related to the vendor. 63 (e.g. Intel GPU being driven by Mesa) */ driver()64 GrGLDriver driver() const { return fDriverInfo.fDriver; } driverVersion()65 GrGLDriverVersion driverVersion() const { return fDriverInfo.fDriverVersion; } isOverCommandBuffer()66 bool isOverCommandBuffer() const { return fDriverInfo.fIsOverCommandBuffer; } isRunningOverVirgl()67 bool isRunningOverVirgl() const { return fDriverInfo.fIsRunningOverVirgl; } 68 caps()69 const GrGLCaps* caps() const { return fGLCaps.get(); } caps()70 GrGLCaps* caps() { return fGLCaps.get(); } 71 hasExtension(const char * ext)72 bool hasExtension(const char* ext) const { 73 return fInterface->hasExtension(ext); 74 } 75 extensions()76 const GrGLExtensions& extensions() const { return fInterface->fExtensions; } 77 78 protected: 79 GrGLContextInfo& operator=(const GrGLContextInfo&) = default; 80 GrGLContextInfo(const GrGLContextInfo&) = default; 81 82 struct ConstructorArgs { 83 sk_sp<const GrGLInterface> fInterface; 84 GrGLDriverInfo fDriverInfo; 85 SkSL::GLSLGeneration fGLSLGeneration; 86 const GrContextOptions* fContextOptions; 87 }; 88 89 GrGLContextInfo(ConstructorArgs&&); 90 91 sk_sp<const GrGLInterface> fInterface; 92 GrGLDriverInfo fDriverInfo; 93 SkSL::GLSLGeneration fGLSLGeneration; 94 sk_sp<GrGLCaps> fGLCaps; 95 }; 96 97 /** 98 * Extension of GrGLContextInfo that also provides access to GrGLInterface. 99 */ 100 class GrGLContext : public GrGLContextInfo { 101 public: 102 /** 103 * Creates a GrGLContext from a GrGLInterface and the currently 104 * bound OpenGL context accessible by the GrGLInterface. 105 */ 106 static std::unique_ptr<GrGLContext> Make(sk_sp<const GrGLInterface>, const GrContextOptions&); 107 glInterface()108 const GrGLInterface* glInterface() const { return fInterface.get(); } 109 110 ~GrGLContext() override; 111 112 private: GrGLContext(ConstructorArgs && args)113 GrGLContext(ConstructorArgs&& args) : INHERITED(std::move(args)) {} 114 115 using INHERITED = GrGLContextInfo; 116 }; 117 118 #endif 119