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