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 // ANGLETest:
7 // Implementation of common ANGLE testing fixture.
8 //
9
10 #ifndef ANGLE_TESTS_ANGLE_TEST_H_
11 #define ANGLE_TESTS_ANGLE_TEST_H_
12
13 #include <gtest/gtest.h>
14 #include <algorithm>
15 #include <array>
16
17 #include "RenderDoc.h"
18 #include "angle_test_configs.h"
19 #include "angle_test_platform.h"
20 #include "common/angleutils.h"
21 #include "common/system_utils.h"
22 #include "common/vector_utils.h"
23 #include "platform/PlatformMethods.h"
24 #include "util/EGLWindow.h"
25 #include "util/shader_utils.h"
26 #include "util/util_gl.h"
27
28 namespace angle
29 {
30 struct SystemInfo;
31 class RNG;
32 } // namespace angle
33
34 #define ASSERT_GL_TRUE(a) ASSERT_EQ(static_cast<GLboolean>(GL_TRUE), (a))
35 #define ASSERT_GL_FALSE(a) ASSERT_EQ(static_cast<GLboolean>(GL_FALSE), (a))
36 #define EXPECT_GL_TRUE(a) EXPECT_EQ(static_cast<GLboolean>(GL_TRUE), (a))
37 #define EXPECT_GL_FALSE(a) EXPECT_EQ(static_cast<GLboolean>(GL_FALSE), (a))
38
39 #define EXPECT_GL_ERROR(err) EXPECT_EQ(static_cast<GLenum>(err), glGetError())
40 #define EXPECT_GL_NO_ERROR() EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
41
42 #define ASSERT_GL_ERROR(err) ASSERT_EQ(static_cast<GLenum>(err), glGetError())
43 #define ASSERT_GL_NO_ERROR() ASSERT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError())
44
45 #define EXPECT_EGL_ERROR(err) EXPECT_EQ((err), eglGetError())
46 #define EXPECT_EGL_SUCCESS() EXPECT_EGL_ERROR(EGL_SUCCESS)
47
48 // EGLBoolean is |unsigned int| but EGL_TRUE is 0, not 0u.
49 #define ASSERT_EGL_TRUE(a) ASSERT_EQ(static_cast<EGLBoolean>(EGL_TRUE), static_cast<EGLBoolean>(a))
50 #define ASSERT_EGL_FALSE(a) \
51 ASSERT_EQ(static_cast<EGLBoolean>(EGL_FALSE), static_cast<EGLBoolean>(a))
52 #define EXPECT_EGL_TRUE(a) EXPECT_EQ(static_cast<EGLBoolean>(EGL_TRUE), static_cast<EGLBoolean>(a))
53 #define EXPECT_EGL_FALSE(a) \
54 EXPECT_EQ(static_cast<EGLBoolean>(EGL_FALSE), static_cast<EGLBoolean>(a))
55
56 #define ASSERT_EGL_ERROR(err) ASSERT_EQ((err), eglGetError())
57 #define ASSERT_EGL_SUCCESS() ASSERT_EGL_ERROR(EGL_SUCCESS)
58
59 #define ASSERT_GLENUM_EQ(expected, actual) \
60 ASSERT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
61 #define EXPECT_GLENUM_EQ(expected, actual) \
62 EXPECT_EQ(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
63 #define ASSERT_GLENUM_NE(expected, actual) \
64 ASSERT_NE(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
65 #define EXPECT_GLENUM_NE(expected, actual) \
66 EXPECT_NE(static_cast<GLenum>(expected), static_cast<GLenum>(actual))
67
68 testing::AssertionResult AssertEGLEnumsEqual(const char *lhsExpr,
69 const char *rhsExpr,
70 EGLenum lhs,
71 EGLenum rhs);
72
73 #define ASSERT_EGLENUM_EQ(expected, actual) \
74 ASSERT_PRED_FORMAT2(AssertEGLEnumsEqual, static_cast<EGLenum>(expected), \
75 static_cast<EGLenum>(actual))
76 #define EXPECT_EGLENUM_EQ(expected, actual) \
77 EXPECT_PRED_FORMAT2(AssertEGLEnumsEqual, static_cast<EGLenum>(expected), \
78 static_cast<EGLenum>(actual))
79
80 #define ASSERT_GL_FRAMEBUFFER_COMPLETE(framebuffer) \
81 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(framebuffer))
82 #define EXPECT_GL_FRAMEBUFFER_COMPLETE(framebuffer) \
83 EXPECT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(framebuffer))
84
85 namespace angle
86 {
87 struct GLColorRGB
88 {
GLColorRGBGLColorRGB89 constexpr GLColorRGB() : R(0), G(0), B(0) {}
GLColorRGBGLColorRGB90 constexpr GLColorRGB(GLubyte r, GLubyte g, GLubyte b) : R(r), G(g), B(b) {}
91 GLColorRGB(const angle::Vector3 &floatColor);
92
dataGLColorRGB93 const GLubyte *data() const { return &R; }
dataGLColorRGB94 GLubyte *data() { return &R; }
95
96 GLubyte R, G, B;
97
98 static const GLColorRGB black;
99 static const GLColorRGB blue;
100 static const GLColorRGB green;
101 static const GLColorRGB red;
102 static const GLColorRGB yellow;
103 };
104
105 struct GLColorRG
106 {
GLColorRGGLColorRG107 constexpr GLColorRG() : R(0), G(0) {}
GLColorRGGLColorRG108 constexpr GLColorRG(GLubyte r, GLubyte g) : R(r), G(g) {}
109 GLColorRG(const angle::Vector2 &floatColor);
110
dataGLColorRG111 const GLubyte *data() const { return &R; }
dataGLColorRG112 GLubyte *data() { return &R; }
113
114 GLubyte R, G;
115 };
116
117 struct GLColorR
118 {
GLColorRGLColorR119 constexpr GLColorR() : R(0) {}
GLColorRGLColorR120 constexpr GLColorR(GLubyte r) : R(r) {}
121 GLColorR(const float floatColor);
122
dataGLColorR123 const GLubyte *data() const { return &R; }
dataGLColorR124 GLubyte *data() { return &R; }
125
126 GLubyte R;
127 };
128
129 struct GLColor
130 {
GLColorGLColor131 constexpr GLColor() : R(0), G(0), B(0), A(0) {}
GLColorGLColor132 constexpr GLColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a) : R(r), G(g), B(b), A(a) {}
133 GLColor(const angle::Vector3 &floatColor);
134 GLColor(const angle::Vector4 &floatColor);
135 GLColor(GLuint colorValue);
136
137 angle::Vector4 toNormalizedVector() const;
138
139 GLubyte &operator[](size_t index) { return (&R)[index]; }
140
141 const GLubyte &operator[](size_t index) const { return (&R)[index]; }
142
dataGLColor143 const GLubyte *data() const { return &R; }
dataGLColor144 GLubyte *data() { return &R; }
145
146 GLuint asUint() const;
147
148 testing::AssertionResult ExpectNear(const GLColor &expected, const GLColor &err) const;
149
150 GLubyte R, G, B, A;
151
152 static const GLColor black;
153 static const GLColor blue;
154 static const GLColor cyan;
155 static const GLColor green;
156 static const GLColor red;
157 static const GLColor transparentBlack;
158 static const GLColor white;
159 static const GLColor yellow;
160 static const GLColor magenta;
161 };
162
163 template <typename T>
164 struct GLColorT
165 {
GLColorTGLColorT166 constexpr GLColorT() : GLColorT(0, 0, 0, 0) {}
GLColorTGLColorT167 constexpr GLColorT(T r, T g, T b, T a) : R(r), G(g), B(b), A(a) {}
168
169 T R, G, B, A;
170 };
171
172 using GLColor16UI = GLColorT<uint16_t>;
173 using GLColor32F = GLColorT<float>;
174 using GLColor32I = GLColorT<int32_t>;
175 using GLColor32UI = GLColorT<uint32_t>;
176
177 static constexpr GLColor32F kFloatBlack = {0.0f, 0.0f, 0.0f, 1.0f};
178 static constexpr GLColor32F kFloatRed = {1.0f, 0.0f, 0.0f, 1.0f};
179 static constexpr GLColor32F kFloatGreen = {0.0f, 1.0f, 0.0f, 1.0f};
180 static constexpr GLColor32F kFloatBlue = {0.0f, 0.0f, 1.0f, 1.0f};
181
182 // The input here for pixelPoints are the expected integer window coordinates, we add .5 to every
183 // one of them and re-scale the numbers to be between [-1,1]. Using this technique, we can make
184 // sure the rasterization stage will end up drawing pixels at the expected locations.
185 void CreatePixelCenterWindowCoords(const std::vector<Vector2> &pixelPoints,
186 int windowWidth,
187 int windowHeight,
188 std::vector<Vector3> *outVertices);
189
190 // Useful to cast any type to GLubyte.
191 template <typename TR, typename TG, typename TB, typename TA>
MakeGLColor(TR r,TG g,TB b,TA a)192 GLColor MakeGLColor(TR r, TG g, TB b, TA a)
193 {
194 return GLColor(static_cast<GLubyte>(r), static_cast<GLubyte>(g), static_cast<GLubyte>(b),
195 static_cast<GLubyte>(a));
196 }
197
198 GLColor RandomColor(angle::RNG *rng);
199
200 bool operator==(const GLColor &a, const GLColor &b);
201 bool operator!=(const GLColor &a, const GLColor &b);
202 std::ostream &operator<<(std::ostream &ostream, const GLColor &color);
203 GLColor ReadColor(GLint x, GLint y);
204
205 bool operator==(const GLColorRGB &a, const GLColorRGB &b);
206 bool operator!=(const GLColorRGB &a, const GLColorRGB &b);
207 std::ostream &operator<<(std::ostream &ostream, const GLColorRGB &color);
208
209 // Useful to cast any type to GLfloat.
210 template <typename TR, typename TG, typename TB, typename TA>
MakeGLColor32F(TR r,TG g,TB b,TA a)211 GLColor32F MakeGLColor32F(TR r, TG g, TB b, TA a)
212 {
213 return GLColor32F(static_cast<GLfloat>(r), static_cast<GLfloat>(g), static_cast<GLfloat>(b),
214 static_cast<GLfloat>(a));
215 }
216
217 template <typename T>
218 bool operator==(const GLColorT<T> &a, const GLColorT<T> &b)
219 {
220 return a.R == b.R && a.G == b.G && a.B == b.B && a.A == b.A;
221 }
222
223 std::ostream &operator<<(std::ostream &ostream, const GLColor32F &color);
224 GLColor32F ReadColor32F(GLint x, GLint y);
225
226 constexpr std::array<GLenum, 6> kCubeFaces = {
227 {GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
228 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
229 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z}};
230
231 void LoadEntryPointsWithUtilLoader(angle::GLESDriverType driver);
232
233 bool IsFormatEmulated(GLenum target);
234 } // namespace angle
235
236 #define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
237 EXPECT_EQ(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
238
239 #define EXPECT_PIXEL_NE(x, y, r, g, b, a) \
240 EXPECT_NE(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
241
242 #define EXPECT_PIXEL_32F_EQ(x, y, r, g, b, a) \
243 EXPECT_EQ(angle::MakeGLColor32F(r, g, b, a), angle::ReadColor32F(x, y))
244
245 #define EXPECT_PIXEL_ALPHA_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor(x, y).A)
246
247 #define EXPECT_PIXEL_ALPHA_NEAR(x, y, a, abs_error) \
248 EXPECT_NEAR(a, angle::ReadColor(x, y).A, abs_error);
249
250 #define EXPECT_PIXEL_ALPHA32F_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor32F(x, y).A)
251
252 #define EXPECT_PIXEL_COLOR_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor(x, y))
253 #define EXPECT_PIXEL_COLOR_EQ_VEC2(vec2, angleColor) \
254 EXPECT_EQ(angleColor, \
255 angle::ReadColor(static_cast<GLint>(vec2.x()), static_cast<GLint>(vec2.y())))
256
257 #define EXPECT_PIXEL_COLOR32F_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor32F(x, y))
258
259 #define EXPECT_PIXEL_RECT_T_EQ(T, x, y, width, height, format, type, color) \
260 do \
261 { \
262 std::vector<T> actualColors((width) * (height)); \
263 glReadPixels((x), (y), (width), (height), format, type, actualColors.data()); \
264 std::vector<T> expectedColors((width) * (height), color); \
265 EXPECT_EQ(expectedColors, actualColors); \
266 } while (0)
267
268 #define EXPECT_PIXEL_RECT_EQ(x, y, width, height, color) \
269 EXPECT_PIXEL_RECT_T_EQ(GLColor, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, color)
270
271 #define EXPECT_PIXEL_RECT32F_EQ(x, y, width, height, color) \
272 EXPECT_PIXEL_RECT_T_EQ(GLColor32F, x, y, width, height, GL_RGBA, GL_FLOAT, color)
273
274 #define EXPECT_PIXEL_RECT32I_EQ(x, y, width, height, color) \
275 EXPECT_PIXEL_RECT_T_EQ(GLColor32I, x, y, width, height, GL_RGBA_INTEGER, GL_INT, color)
276
277 #define EXPECT_PIXEL_RECT32UI_EQ(x, y, width, height, color) \
278 EXPECT_PIXEL_RECT_T_EQ(GLColor32UI, x, y, width, height, GL_RGBA_INTEGER, GL_UNSIGNED_INT, \
279 color)
280
281 #define EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, ctype, format, type) \
282 do \
283 { \
284 ctype pixel[4]; \
285 glReadPixels((x), (y), 1, 1, format, type, pixel); \
286 EXPECT_GL_NO_ERROR(); \
287 EXPECT_NEAR((r), pixel[0], abs_error); \
288 EXPECT_NEAR((g), pixel[1], abs_error); \
289 EXPECT_NEAR((b), pixel[2], abs_error); \
290 EXPECT_NEAR((a), pixel[3], abs_error); \
291 } while (0)
292
293 #define EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, ctype, format, type) \
294 do \
295 { \
296 ctype pixel[4]; \
297 glReadPixels((x), (y), 1, 1, format, type, pixel); \
298 EXPECT_GL_NO_ERROR(); \
299 EXPECT_EQ((r), pixel[0]); \
300 EXPECT_EQ((g), pixel[1]); \
301 EXPECT_EQ((b), pixel[2]); \
302 EXPECT_EQ((a), pixel[3]); \
303 } while (0)
304
305 #define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \
306 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLubyte, GL_RGBA, GL_UNSIGNED_BYTE)
307
308 #define EXPECT_PIXEL_8S_NEAR(x, y, r, g, b, a, abs_error) \
309 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLbyte, GL_RGBA, GL_BYTE)
310
311 #define EXPECT_PIXEL_16S_NEAR(x, y, r, g, b, a, abs_error) \
312 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLshort, GL_RGBA, GL_SHORT)
313
314 #define EXPECT_PIXEL_32F_NEAR(x, y, r, g, b, a, abs_error) \
315 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLfloat, GL_RGBA, GL_FLOAT)
316
317 #define EXPECT_PIXEL_8I(x, y, r, g, b, a) \
318 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLbyte, GL_RGBA_INTEGER, GL_BYTE)
319
320 #define EXPECT_PIXEL_8UI(x, y, r, g, b, a) \
321 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLubyte, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE)
322
323 #define EXPECT_PIXEL_16UI(x, y, r, g, b, a) \
324 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLushort, GL_RGBA, GL_UNSIGNED_SHORT)
325
326 #define EXPECT_PIXEL_16UI_COLOR(x, y, color) \
327 EXPECT_PIXEL_16UI(x, y, color.R, color.G, color.B, color.A)
328
329 // TODO(jmadill): Figure out how we can use GLColor's nice printing with EXPECT_NEAR.
330 #define EXPECT_PIXEL_COLOR_NEAR(x, y, angleColor, abs_error) \
331 EXPECT_PIXEL_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
332
333 #define EXPECT_PIXEL_COLOR32F_NEAR(x, y, angleColor, abs_error) \
334 EXPECT_PIXEL32F_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
335
336 #define EXPECT_COLOR_NEAR(expected, actual, abs_error) \
337 do \
338 { \
339 EXPECT_NEAR(expected.R, actual.R, abs_error); \
340 EXPECT_NEAR(expected.G, actual.G, abs_error); \
341 EXPECT_NEAR(expected.B, actual.B, abs_error); \
342 EXPECT_NEAR(expected.A, actual.A, abs_error); \
343 } while (0)
344 #define EXPECT_PIXEL32F_NEAR(x, y, r, g, b, a, abs_error) \
345 do \
346 { \
347 GLfloat pixel[4]; \
348 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_FLOAT, pixel); \
349 EXPECT_GL_NO_ERROR(); \
350 EXPECT_NEAR((r), pixel[0], abs_error); \
351 EXPECT_NEAR((g), pixel[1], abs_error); \
352 EXPECT_NEAR((b), pixel[2], abs_error); \
353 EXPECT_NEAR((a), pixel[3], abs_error); \
354 } while (0)
355
356 #define EXPECT_PIXEL_COLOR32F_NEAR(x, y, angleColor, abs_error) \
357 EXPECT_PIXEL32F_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
358
359 #define EXPECT_PIXEL_STENCIL_EQ(x, y, expected) \
360 do \
361 { \
362 GLubyte actual; \
363 glReadPixels((x), (y), 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &actual); \
364 EXPECT_GL_NO_ERROR(); \
365 EXPECT_EQ((expected), actual); \
366 } while (0)
367
368 class ANGLETestBase;
369 class EGLWindow;
370 class GLWindowBase;
371 class OSWindow;
372 class WGLWindow;
373
374 struct TestPlatformContext final : private angle::NonCopyable
375 {
376 bool ignoreMessages = false;
377 bool warningsAsErrors = false;
378 ANGLETestBase *currentTest = nullptr;
379 };
380
381 class ANGLETestBase
382 {
383 protected:
384 ANGLETestBase(const angle::PlatformParameters ¶ms);
385 virtual ~ANGLETestBase();
386
387 public:
388 void setWindowVisible(OSWindow *osWindow, bool isVisible);
389
390 static void ReleaseFixtures();
391
isSwiftshader()392 bool isSwiftshader() const
393 {
394 // Renderer might be swiftshader even if local swiftshader not used.
395 return mCurrentParams->isSwiftshader() || angle::IsSwiftshaderDevice();
396 }
397
enableDebugLayers()398 bool enableDebugLayers() const
399 {
400 return mCurrentParams->eglParameters.debugLayersEnabled != EGL_FALSE;
401 }
402
403 protected:
404 void ANGLETestSetUp();
405 void ANGLETestPreTearDown();
406 void ANGLETestTearDown();
407
408 virtual void swapBuffers();
409
410 void setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale);
411 void setupIndexedQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale);
412 void setupIndexedQuadIndexBuffer();
413
414 void drawQuad(GLuint program, const std::string &positionAttribName, GLfloat positionAttribZ);
415 void drawQuad(GLuint program,
416 const std::string &positionAttribName,
417 GLfloat positionAttribZ,
418 GLfloat positionAttribXYScale);
419 void drawQuad(GLuint program,
420 const std::string &positionAttribName,
421 GLfloat positionAttribZ,
422 GLfloat positionAttribXYScale,
423 bool useVertexBuffer);
424 void drawQuadInstanced(GLuint program,
425 const std::string &positionAttribName,
426 GLfloat positionAttribZ,
427 GLfloat positionAttribXYScale,
428 bool useVertexBuffer,
429 GLuint numInstances);
430 void drawPatches(GLuint program,
431 const std::string &positionAttribName,
432 GLfloat positionAttribZ,
433 GLfloat positionAttribXYScale,
434 bool useVertexBuffer);
435
436 void drawQuadPPO(GLuint vertProgram,
437 const std::string &positionAttribName,
438 const GLfloat positionAttribZ,
439 const GLfloat positionAttribXYScale);
440
441 static std::array<angle::Vector3, 6> GetQuadVertices();
442 static std::array<GLushort, 6> GetQuadIndices();
443 static std::array<angle::Vector3, 4> GetIndexedQuadVertices();
444
445 void drawIndexedQuad(GLuint program,
446 const std::string &positionAttribName,
447 GLfloat positionAttribZ);
448 void drawIndexedQuad(GLuint program,
449 const std::string &positionAttribName,
450 GLfloat positionAttribZ,
451 GLfloat positionAttribXYScale);
452 void drawIndexedQuad(GLuint program,
453 const std::string &positionAttribName,
454 GLfloat positionAttribZ,
455 GLfloat positionAttribXYScale,
456 bool useBufferObject);
457
458 void drawIndexedQuad(GLuint program,
459 const std::string &positionAttribName,
460 GLfloat positionAttribZ,
461 GLfloat positionAttribXYScale,
462 bool useBufferObject,
463 bool restrictedRange);
464
465 void draw2DTexturedQuad(GLfloat positionAttribZ,
466 GLfloat positionAttribXYScale,
467 bool useVertexBuffer);
468
469 // The layer parameter chooses the 3D texture layer to sample from.
470 void draw3DTexturedQuad(GLfloat positionAttribZ,
471 GLfloat positionAttribXYScale,
472 bool useVertexBuffer,
473 float layer);
474
475 void setWindowWidth(int width);
476 void setWindowHeight(int height);
477 void setConfigRedBits(int bits);
478 void setConfigGreenBits(int bits);
479 void setConfigBlueBits(int bits);
480 void setConfigAlphaBits(int bits);
481 void setConfigDepthBits(int bits);
482 void setConfigStencilBits(int bits);
483 void setConfigComponentType(EGLenum componentType);
484 void setMultisampleEnabled(bool enabled);
485 void setSamples(EGLint samples);
486 void setDebugEnabled(bool enabled);
487 void setNoErrorEnabled(bool enabled);
488 void setWebGLCompatibilityEnabled(bool webglCompatibility);
489 void setExtensionsEnabled(bool extensionsEnabled);
490 void setRobustAccess(bool enabled);
491 void setBindGeneratesResource(bool bindGeneratesResource);
492 void setClientArraysEnabled(bool enabled);
493 void setRobustResourceInit(bool enabled);
494 void setMutableRenderBuffer(bool enabled);
495 void setContextProgramCacheEnabled(bool enabled);
496 void setContextResetStrategy(EGLenum resetStrategy);
497 void forceNewDisplay();
498
499 // Some EGL extension tests would like to defer the Context init until the test body.
500 void setDeferContextInit(bool enabled);
501
502 int getClientMajorVersion() const;
503 int getClientMinorVersion() const;
504
505 GLWindowBase *getGLWindow() const;
506 EGLWindow *getEGLWindow() const;
507 int getWindowWidth() const;
508 int getWindowHeight() const;
509
510 EGLint getPlatformRenderer() const;
511
512 void ignoreD3D11SDKLayersWarnings();
513
getOSWindow()514 OSWindow *getOSWindow() { return mFixture->osWindow; }
515
516 GLuint get2DTexturedQuadProgram();
517
518 // Has a float uniform "u_layer" to choose the 3D texture layer.
519 GLuint get3DTexturedQuadProgram();
520
521 class [[nodiscard]] ScopedIgnorePlatformMessages : angle::NonCopyable
522 {
523 public:
524 ScopedIgnorePlatformMessages();
525 ~ScopedIgnorePlatformMessages();
526 };
527
528 // Can be used before we get a GL context.
isGLRenderer()529 bool isGLRenderer() const
530 {
531 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
532 }
533
isGLESRenderer()534 bool isGLESRenderer() const
535 {
536 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE;
537 }
538
isD3D11Renderer()539 bool isD3D11Renderer() const
540 {
541 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE;
542 }
543
isVulkanRenderer()544 bool isVulkanRenderer() const
545 {
546 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE;
547 }
548
isVulkanSwiftshaderRenderer()549 bool isVulkanSwiftshaderRenderer() const
550 {
551 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE &&
552 mCurrentParams->isSwiftshader();
553 }
554
555 bool platformSupportsMultithreading() const;
556
557 bool mIsSetUp = false;
558
559 private:
560 void checkD3D11SDKLayersMessages();
561
562 void drawQuad(GLuint program,
563 const std::string &positionAttribName,
564 GLfloat positionAttribZ,
565 GLfloat positionAttribXYScale,
566 bool useVertexBuffer,
567 bool useInstancedDrawCalls,
568 bool useTessellationPatches,
569 GLuint numInstances);
570
571 void initOSWindow();
572
573 struct TestFixture
574 {
575 TestFixture();
576 ~TestFixture();
577
578 EGLWindow *eglWindow = nullptr;
579 WGLWindow *wglWindow = nullptr;
580 OSWindow *osWindow = nullptr;
581 ConfigParameters configParams;
582 uint32_t reuseCounter = 0;
583 };
584
585 int mWidth;
586 int mHeight;
587
588 bool mIgnoreD3D11SDKLayersWarnings;
589
590 // Used for indexed quad rendering
591 GLuint mQuadVertexBuffer;
592 GLuint mQuadIndexBuffer;
593
594 // Used for texture rendering.
595 GLuint m2DTexturedQuadProgram;
596 GLuint m3DTexturedQuadProgram;
597
598 bool mDeferContextInit;
599 bool mAlwaysForceNewDisplay;
600 bool mForceNewDisplay;
601
602 bool mSetUpCalled;
603 bool mTearDownCalled;
604
605 // Usually, we use an OS Window per "fixture" (a frontend and backend combination).
606 // This allows:
607 // 1. Reusing EGL Display on Windows.
608 // Other platforms have issues with display reuse even if a window per fixture is used.
609 // 2. Hiding only SwiftShader OS Window on Linux.
610 // OS Windows for other backends must be visible, to allow driver to communicate with X11.
611 // However, we must use a single OS Window for all backends on Android,
612 // since test Application can have only one window.
613 static OSWindow *mOSWindowSingleton;
614
615 static std::map<angle::PlatformParameters, TestFixture> gFixtures;
616 const angle::PlatformParameters *mCurrentParams;
617 TestFixture *mFixture;
618
619 RenderDoc mRenderDoc;
620
621 // Workaround for NVIDIA not being able to share a window with OpenGL and Vulkan.
622 static Optional<EGLint> mLastRendererType;
623 static Optional<angle::GLESDriverType> mLastLoadedDriver;
624 };
625
626 template <typename Params = angle::PlatformParameters>
627 class ANGLETest : public ANGLETestBase, public ::testing::TestWithParam<Params>
628 {
629 protected:
630 ANGLETest();
631
testSetUp()632 virtual void testSetUp() {}
testTearDown()633 virtual void testTearDown() {}
634
recreateTestFixture()635 void recreateTestFixture()
636 {
637 TearDown();
638 SetUp();
639 }
640
641 private:
SetUp()642 void SetUp() final
643 {
644 ANGLETestBase::ANGLETestSetUp();
645 if (mIsSetUp)
646 {
647 testSetUp();
648 }
649 }
650
TearDown()651 void TearDown() final
652 {
653 ANGLETestBase::ANGLETestPreTearDown();
654 if (mIsSetUp)
655 {
656 testTearDown();
657 }
658 ANGLETestBase::ANGLETestTearDown();
659 }
660 };
661
662 enum class APIExtensionVersion
663 {
664 Core,
665 OES,
666 EXT,
667 };
668
669 template <typename Params>
ANGLETest()670 ANGLETest<Params>::ANGLETest()
671 : ANGLETestBase(std::get<angle::PlatformParameters>(this->GetParam()))
672 {}
673
674 template <>
ANGLETest()675 inline ANGLETest<angle::PlatformParameters>::ANGLETest() : ANGLETestBase(this->GetParam())
676 {}
677
678 class ANGLETestEnvironment : public testing::Environment
679 {
680 public:
681 void SetUp() override;
682 void TearDown() override;
683
684 static angle::Library *GetDriverLibrary(angle::GLESDriverType driver);
685
686 private:
687 static angle::Library *GetAngleEGLLibrary();
688 static angle::Library *GetAngleVulkanSecondariesEGLLibrary();
689 static angle::Library *GetMesaEGLLibrary();
690 static angle::Library *GetSystemEGLLibrary();
691 static angle::Library *GetSystemWGLLibrary();
692
693 // For loading entry points.
694 static std::unique_ptr<angle::Library> gAngleEGLLibrary;
695 static std::unique_ptr<angle::Library> gAngleVulkanSecondariesEGLLibrary;
696 static std::unique_ptr<angle::Library> gMesaEGLLibrary;
697 static std::unique_ptr<angle::Library> gSystemEGLLibrary;
698 static std::unique_ptr<angle::Library> gSystemWGLLibrary;
699 };
700
701 extern angle::PlatformMethods gDefaultPlatformMethods;
702
703 #endif // ANGLE_TESTS_ANGLE_TEST_H_
704