• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012 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 #ifndef GrGLUtil_DEFINED
9 #define GrGLUtil_DEFINED
10 
11 #include "gl/GrGLInterface.h"
12 #include "GrGLDefines.h"
13 #include "GrStencilSettings.h"
14 #include "GrTypesPriv.h"
15 
16 class SkMatrix;
17 
18 ////////////////////////////////////////////////////////////////////////////////
19 
20 typedef uint32_t GrGLVersion;
21 typedef uint32_t GrGLSLVersion;
22 typedef uint64_t GrGLDriverVersion;
23 
24 #define GR_GL_VER(major, minor) ((static_cast<uint32_t>(major) << 16) | \
25                                  static_cast<uint32_t>(minor))
26 #define GR_GLSL_VER(major, minor) ((static_cast<uint32_t>(major) << 16) | \
27                                     static_cast<uint32_t>(minor))
28 #define GR_GL_DRIVER_VER(major, minor, point) ((static_cast<uint64_t>(major) << 32) | \
29                                                (static_cast<uint64_t>(minor) << 16) | \
30                                                 static_cast<uint64_t>(point))
31 
32 #define GR_GL_INVALID_VER GR_GL_VER(0, 0)
33 #define GR_GLSL_INVALID_VER GR_GLSL_VER(0, 0)
34 #define GR_GL_DRIVER_UNKNOWN_VER GR_GL_DRIVER_VER(0, 0, 0)
35 
36 /**
37  * The Vendor and Renderer enum values are lazily updated as required.
38  */
39 enum GrGLVendor {
40     kARM_GrGLVendor,
41     kGoogle_GrGLVendor,
42     kImagination_GrGLVendor,
43     kIntel_GrGLVendor,
44     kQualcomm_GrGLVendor,
45     kNVIDIA_GrGLVendor,
46     kATI_GrGLVendor,
47 
48     kOther_GrGLVendor
49 };
50 
51 enum GrGLRenderer {
52     kTegra_PreK1_GrGLRenderer,  // Legacy Tegra architecture (pre-K1).
53     kTegra_GrGLRenderer,  // Tegra with the same architecture as NVIDIA desktop GPUs (K1+).
54     kPowerVR54x_GrGLRenderer,
55     kPowerVRRogue_GrGLRenderer,
56     kAdreno3xx_GrGLRenderer,
57     kAdreno430_GrGLRenderer,
58     kAdreno4xx_other_GrGLRenderer,
59     kAdreno5xx_GrGLRenderer,
60     kOSMesa_GrGLRenderer,
61     kGoogleSwiftShader_GrGLRenderer,
62     kIntelIrisPro_GrGLRenderer,
63     /** Either HD 4xxx or Iris 4xxx */
64     kIntel4xxx_GrGLRenderer,
65     /** Either HD 6xxx or Iris 6xxx */
66     kIntel6xxx_GrGLRenderer,
67     kIntelSandyBridge_GrGLRenderer,
68     kIntelBayTrail_GrGLRenderer,
69     kIntelSkylake_GrGLRenderer,
70     kGalliumLLVM_GrGLRenderer,
71     kMali4xx_GrGLRenderer,
72     /** T-6xx, T-7xx, or T-8xx */
73     kMaliT_GrGLRenderer,
74     kANGLE_GrGLRenderer,
75 
76     kAMDRadeonHD7xxx_GrGLRenderer,  // AMD Radeon HD 7000 Series
77     kAMDRadeonR9M4xx_GrGLRenderer,  // AMD Radeon R9 M400 Series
78 
79     kOther_GrGLRenderer
80 };
81 
82 enum GrGLDriver {
83     kMesa_GrGLDriver,
84     kChromium_GrGLDriver,
85     kNVIDIA_GrGLDriver,
86     kIntel_GrGLDriver,
87     kANGLE_GrGLDriver,
88     kSwiftShader_GrGLDriver,
89     kQualcomm_GrGLDriver,
90     kUnknown_GrGLDriver
91 };
92 
93 enum class GrGLANGLEBackend {
94     kUnknown,
95     kD3D9,
96     kD3D11,
97     kOpenGL
98 };
99 
100 enum class GrGLANGLEVendor {
101     kUnknown,
102     kIntel
103 };
104 
105 enum class GrGLANGLERenderer {
106     kUnknown,
107     kSandyBridge,
108     kIvyBridge,
109     kSkylake
110 };
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 
114 /**
115  *  Some drivers want the var-int arg to be zero-initialized on input.
116  */
117 #define GR_GL_INIT_ZERO     0
118 #define GR_GL_GetIntegerv(gl, e, p)                                            \
119     do {                                                                       \
120         *(p) = GR_GL_INIT_ZERO;                                                \
121         GR_GL_CALL(gl, GetIntegerv(e, p));                                     \
122     } while (0)
123 
124 #define GR_GL_GetFramebufferAttachmentParameteriv(gl, t, a, pname, p)          \
125     do {                                                                       \
126         *(p) = GR_GL_INIT_ZERO;                                                \
127         GR_GL_CALL(gl, GetFramebufferAttachmentParameteriv(t, a, pname, p));   \
128     } while (0)
129 
130 #define GR_GL_GetInternalformativ(gl, t, f, n, s, p)                           \
131     do {                                                                       \
132         *(p) = GR_GL_INIT_ZERO;                                                \
133         GR_GL_CALL(gl, GetInternalformativ(t, f, n, s, p));                    \
134     } while (0)
135 
136 #define GR_GL_GetNamedFramebufferAttachmentParameteriv(gl, fb, a, pname, p)          \
137     do {                                                                             \
138         *(p) = GR_GL_INIT_ZERO;                                                      \
139         GR_GL_CALL(gl, GetNamedFramebufferAttachmentParameteriv(fb, a, pname, p));   \
140     } while (0)
141 
142 #define GR_GL_GetRenderbufferParameteriv(gl, t, pname, p)                      \
143     do {                                                                       \
144         *(p) = GR_GL_INIT_ZERO;                                                \
145         GR_GL_CALL(gl, GetRenderbufferParameteriv(t, pname, p));               \
146     } while (0)
147 
148 #define GR_GL_GetTexLevelParameteriv(gl, t, l, pname, p)                       \
149     do {                                                                       \
150         *(p) = GR_GL_INIT_ZERO;                                                \
151         GR_GL_CALL(gl, GetTexLevelParameteriv(t, l, pname, p));                \
152     } while (0)
153 
154 #define GR_GL_GetShaderPrecisionFormat(gl, st, pt, range, precision)           \
155     do {                                                                       \
156         (range)[0] = GR_GL_INIT_ZERO;                                          \
157         (range)[1] = GR_GL_INIT_ZERO;                                          \
158         (*precision) = GR_GL_INIT_ZERO;                                        \
159         GR_GL_CALL(gl, GetShaderPrecisionFormat(st, pt, range, precision));    \
160     } while (0)
161 
162 ////////////////////////////////////////////////////////////////////////////////
163 
164 /**
165  * Helpers for glGetString()
166  */
167 
168 // these variants assume caller already has a string from glGetString()
169 GrGLVersion GrGLGetVersionFromString(const char* versionString);
170 GrGLStandard GrGLGetStandardInUseFromString(const char* versionString);
171 GrGLSLVersion GrGLGetGLSLVersionFromString(const char* versionString);
172 GrGLVendor GrGLGetVendorFromString(const char* vendorString);
173 GrGLRenderer GrGLGetRendererFromStrings(const char* rendererString, const GrGLExtensions&);
174 void GrGLGetANGLEInfoFromString(const char* rendererString, GrGLANGLEBackend*,
175                                 GrGLANGLEVendor*, GrGLANGLERenderer*);
176 
177 void GrGLGetDriverInfo(GrGLStandard standard,
178                        GrGLVendor vendor,
179                        const char* rendererString,
180                        const char* versionString,
181                        GrGLDriver* outDriver,
182                        GrGLDriverVersion* outVersion);
183 
184 // these variants call glGetString()
185 GrGLVersion GrGLGetVersion(const GrGLInterface*);
186 GrGLSLVersion GrGLGetGLSLVersion(const GrGLInterface*);
187 GrGLVendor GrGLGetVendor(const GrGLInterface*);
188 GrGLRenderer GrGLGetRenderer(const GrGLInterface*);
189 
190 /**
191  * Helpers for glGetError()
192  */
193 
194 void GrGLCheckErr(const GrGLInterface* gl,
195                   const char* location,
196                   const char* call);
197 
198 void GrGLClearErr(const GrGLInterface* gl);
199 
200 ////////////////////////////////////////////////////////////////////////////////
201 
202 /**
203  * Macros for using GrGLInterface to make GL calls
204  */
205 
206 // internal macro to conditionally call glGetError based on compile-time and
207 // run-time flags.
208 #if GR_GL_CHECK_ERROR
209     extern bool gCheckErrorGL;
210     #define GR_GL_CHECK_ERROR_IMPL(IFACE, X)                    \
211         if (gCheckErrorGL)                                      \
212             GrGLCheckErr(IFACE, GR_FILE_AND_LINE_STR, #X)
213 #else
214     #define GR_GL_CHECK_ERROR_IMPL(IFACE, X)
215 #endif
216 
217 // internal macro to conditionally log the gl call using SkDebugf based on
218 // compile-time and run-time flags.
219 #if GR_GL_LOG_CALLS
220     extern bool gLogCallsGL;
221     #define GR_GL_LOG_CALLS_IMPL(X)                             \
222         if (gLogCallsGL)                                        \
223             SkDebugf(GR_FILE_AND_LINE_STR "GL: " #X "\n")
224 #else
225     #define GR_GL_LOG_CALLS_IMPL(X)
226 #endif
227 
228 // makes a GL call on the interface and does any error checking and logging
229 #define GR_GL_CALL(IFACE, X)                                    \
230     do {                                                        \
231         GR_GL_CALL_NOERRCHECK(IFACE, X);                        \
232         GR_GL_CHECK_ERROR_IMPL(IFACE, X);                       \
233     } while (false)
234 
235 // Variant of above that always skips the error check. This is useful when
236 // the caller wants to do its own glGetError() call and examine the error value.
237 #define GR_GL_CALL_NOERRCHECK(IFACE, X)                         \
238     do {                                                        \
239         (IFACE)->fFunctions.f##X;                               \
240         GR_GL_LOG_CALLS_IMPL(X);                                \
241     } while (false)
242 
243 // same as GR_GL_CALL but stores the return value of the gl call in RET
244 #define GR_GL_CALL_RET(IFACE, RET, X)                           \
245     do {                                                        \
246         GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X);               \
247         GR_GL_CHECK_ERROR_IMPL(IFACE, X);                       \
248     } while (false)
249 
250 // same as GR_GL_CALL_RET but always skips the error check.
251 #define GR_GL_CALL_RET_NOERRCHECK(IFACE, RET, X)                \
252     do {                                                        \
253         (RET) = (IFACE)->fFunctions.f##X;                       \
254         GR_GL_LOG_CALLS_IMPL(X);                                \
255     } while (false)
256 
257 // call glGetError without doing a redundant error check or logging.
258 #define GR_GL_GET_ERROR(IFACE) (IFACE)->fFunctions.fGetError()
259 
260 GrGLenum GrToGLStencilFunc(GrStencilTest test);
261 
262 #endif
263