1 //
2 // Copyright 2012 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // renderergl_utils.h: Conversion functions and other utility routines
8 // specific to the OpenGL renderer.
9 
10 #ifndef LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
11 #define LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
12 
13 #include "common/debug.h"
14 #include "libANGLE/Caps.h"
15 #include "libANGLE/Error.h"
16 #include "libANGLE/Version.h"
17 #include "libANGLE/angletypes.h"
18 #include "libANGLE/renderer/driver_utils.h"
19 #include "libANGLE/renderer/gl/functionsgl_typedefs.h"
20 
21 #include <string>
22 #include <vector>
23 
24 namespace angle
25 {
26 struct FeaturesGL;
27 struct FrontendFeatures;
28 }  // namespace angle
29 
30 namespace gl
31 {
32 struct Caps;
33 class TextureCapsMap;
34 struct Extensions;
35 struct Version;
36 }  // namespace gl
37 
38 namespace rx
39 {
40 class BlitGL;
41 class ClearMultiviewGL;
42 class ContextGL;
43 class FunctionsGL;
44 class StateManagerGL;
45 enum class MultiviewImplementationTypeGL
46 {
47     NV_VIEWPORT_ARRAY2,
48     UNSPECIFIED
49 };
50 
51 // State-tracking data for the swap control to allow DisplayGL to remember per
52 // drawable information for swap control.
53 struct SwapControlData
54 {
55     SwapControlData();
56 
57     // Set by the drawable
58     int targetSwapInterval;
59 
60     // DisplayGL-side state-tracking
61     int maxSwapInterval;
62     int currentSwapInterval;
63 };
64 
65 VendorID GetVendorID(const FunctionsGL *functions);
66 
67 // Helpers for extracting the GL helper objects out of a context
68 const FunctionsGL *GetFunctionsGL(const gl::Context *context);
69 StateManagerGL *GetStateManagerGL(const gl::Context *context);
70 BlitGL *GetBlitGL(const gl::Context *context);
71 ClearMultiviewGL *GetMultiviewClearer(const gl::Context *context);
72 const angle::FeaturesGL &GetFeaturesGL(const gl::Context *context);
73 
74 // Clear all errors on the stored context, emits console warnings
75 void ClearErrors(const gl::Context *context,
76                  const char *file,
77                  const char *function,
78                  unsigned int line);
79 
80 // Check for a single error
81 angle::Result CheckError(const gl::Context *context,
82                          const char *call,
83                          const char *file,
84                          const char *function,
85                          unsigned int line);
86 
87 #define ANGLE_GL_TRY_ALWAYS_CHECK(context, call)                      \
88     (ClearErrors(context, __FILE__, __FUNCTION__, __LINE__), (call)); \
89     ANGLE_TRY(CheckError(context, #call, __FILE__, __FUNCTION__, __LINE__))
90 
91 #if defined(ANGLE_ENABLE_ASSERTS)
92 #    define ANGLE_GL_TRY(context, call) ANGLE_GL_TRY_ALWAYS_CHECK(context, call)
93 #else
94 #    define ANGLE_GL_TRY(context, call) call
95 #endif
96 
97 namespace nativegl_gl
98 {
99 
100 void GenerateCaps(const FunctionsGL *functions,
101                   const angle::FeaturesGL &features,
102                   gl::Caps *caps,
103                   gl::TextureCapsMap *textureCapsMap,
104                   gl::Extensions *extensions,
105                   gl::Limitations *limitations,
106                   gl::Version *maxSupportedESVersion,
107                   MultiviewImplementationTypeGL *multiviewImplementationType);
108 
109 void InitializeFeatures(const FunctionsGL *functions, angle::FeaturesGL *features);
110 void InitializeFrontendFeatures(const FunctionsGL *functions, angle::FrontendFeatures *features);
111 void ReInitializeFeaturesAtGPUSwitch(const FunctionsGL *functions, angle::FeaturesGL *features);
112 }  // namespace nativegl_gl
113 
114 namespace nativegl
115 {
116 bool SupportsVertexArrayObjects(const FunctionsGL *functions);
117 bool CanUseDefaultVertexArrayObject(const FunctionsGL *functions);
118 bool SupportsCompute(const FunctionsGL *functions);
119 bool SupportsFenceSync(const FunctionsGL *functions);
120 bool SupportsOcclusionQueries(const FunctionsGL *functions);
121 bool SupportsNativeRendering(const FunctionsGL *functions,
122                              gl::TextureType type,
123                              GLenum internalFormat);
124 bool SupportsTexImage(gl::TextureType type);
125 bool UseTexImage2D(gl::TextureType textureType);
126 bool UseTexImage3D(gl::TextureType textureType);
127 GLenum GetTextureBindingQuery(gl::TextureType textureType);
128 GLenum GetTextureBindingTarget(gl::TextureType textureType);
129 GLenum GetTextureBindingTarget(gl::TextureTarget textureTarget);
130 GLenum GetBufferBindingQuery(gl::BufferBinding bufferBinding);
131 std::string GetBufferBindingString(gl::BufferBinding bufferBinding);
132 gl::TextureType GetNativeTextureType(gl::TextureType type);
133 gl::TextureTarget GetNativeTextureTarget(gl::TextureTarget target);
134 }  // namespace nativegl
135 
136 bool CanMapBufferForRead(const FunctionsGL *functions);
137 uint8_t *MapBufferRangeWithFallback(const FunctionsGL *functions,
138                                     GLenum target,
139                                     size_t offset,
140                                     size_t length,
141                                     GLbitfield access);
142 
143 angle::Result ShouldApplyLastRowPaddingWorkaround(ContextGL *contextGL,
144                                                   const gl::Extents &size,
145                                                   const gl::PixelStoreStateBase &state,
146                                                   const gl::Buffer *pixelBuffer,
147                                                   GLenum format,
148                                                   GLenum type,
149                                                   bool is3D,
150                                                   const void *pixels,
151                                                   bool *shouldApplyOut);
152 
153 struct ContextCreationTry
154 {
155     enum class Type
156     {
157         DESKTOP_CORE,
158         DESKTOP_LEGACY,
159         ES,
160     };
161 
ContextCreationTryContextCreationTry162     ContextCreationTry(EGLint displayType, Type type, gl::Version version)
163         : displayType(displayType), type(type), version(version)
164     {}
165 
166     EGLint displayType;
167     Type type;
168     gl::Version version;
169 };
170 
171 std::vector<ContextCreationTry> GenerateContextCreationToTry(EGLint requestedType, bool isMesaGLX);
172 
173 std::string GetRendererString(const FunctionsGL *functions);
174 std::string GetVendorString(const FunctionsGL *functions);
175 std::string GetVersionString(const FunctionsGL *functions);
176 
177 }  // namespace rx
178 
179 #endif  // LIBANGLE_RENDERER_GL_RENDERERGLUTILS_H_
180