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 struct GLColor16UI
164 {
GLColor16UIGLColor16UI165 constexpr GLColor16UI() : GLColor16UI(0, 0, 0, 0) {}
GLColor16UIGLColor16UI166 constexpr GLColor16UI(GLushort r, GLushort g, GLushort b, GLushort a) : R(r), G(g), B(b), A(a)
167 {}
168
169 GLushort R, G, B, A;
170 };
171
172 struct GLColor32F
173 {
GLColor32FGLColor32F174 constexpr GLColor32F() : GLColor32F(0.0f, 0.0f, 0.0f, 0.0f) {}
GLColor32FGLColor32F175 constexpr GLColor32F(GLfloat r, GLfloat g, GLfloat b, GLfloat a) : R(r), G(g), B(b), A(a) {}
176
177 GLfloat R, G, B, A;
178 };
179
180 static constexpr GLColor32F kFloatBlack = {0.0f, 0.0f, 0.0f, 1.0f};
181 static constexpr GLColor32F kFloatRed = {1.0f, 0.0f, 0.0f, 1.0f};
182 static constexpr GLColor32F kFloatGreen = {0.0f, 1.0f, 0.0f, 1.0f};
183 static constexpr GLColor32F kFloatBlue = {0.0f, 0.0f, 1.0f, 1.0f};
184
185 // The input here for pixelPoints are the expected integer window coordinates, we add .5 to every
186 // one of them and re-scale the numbers to be between [-1,1]. Using this technique, we can make
187 // sure the rasterization stage will end up drawing pixels at the expected locations.
188 void CreatePixelCenterWindowCoords(const std::vector<Vector2> &pixelPoints,
189 int windowWidth,
190 int windowHeight,
191 std::vector<Vector3> *outVertices);
192
193 // Useful to cast any type to GLubyte.
194 template <typename TR, typename TG, typename TB, typename TA>
MakeGLColor(TR r,TG g,TB b,TA a)195 GLColor MakeGLColor(TR r, TG g, TB b, TA a)
196 {
197 return GLColor(static_cast<GLubyte>(r), static_cast<GLubyte>(g), static_cast<GLubyte>(b),
198 static_cast<GLubyte>(a));
199 }
200
201 GLColor RandomColor(angle::RNG *rng);
202
203 bool operator==(const GLColor &a, const GLColor &b);
204 bool operator!=(const GLColor &a, const GLColor &b);
205 std::ostream &operator<<(std::ostream &ostream, const GLColor &color);
206 GLColor ReadColor(GLint x, GLint y);
207
208 bool operator==(const GLColorRGB &a, const GLColorRGB &b);
209 bool operator!=(const GLColorRGB &a, const GLColorRGB &b);
210 std::ostream &operator<<(std::ostream &ostream, const GLColorRGB &color);
211
212 // Useful to cast any type to GLfloat.
213 template <typename TR, typename TG, typename TB, typename TA>
MakeGLColor32F(TR r,TG g,TB b,TA a)214 GLColor32F MakeGLColor32F(TR r, TG g, TB b, TA a)
215 {
216 return GLColor32F(static_cast<GLfloat>(r), static_cast<GLfloat>(g), static_cast<GLfloat>(b),
217 static_cast<GLfloat>(a));
218 }
219
220 bool operator==(const GLColor32F &a, const GLColor32F &b);
221 std::ostream &operator<<(std::ostream &ostream, const GLColor32F &color);
222 GLColor32F ReadColor32F(GLint x, GLint y);
223
224 constexpr std::array<GLenum, 6> kCubeFaces = {
225 {GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
226 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
227 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z}};
228
229 void LoadEntryPointsWithUtilLoader(angle::GLESDriverType driver);
230
231 } // namespace angle
232
233 #define EXPECT_PIXEL_EQ(x, y, r, g, b, a) \
234 EXPECT_EQ(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
235
236 #define EXPECT_PIXEL_NE(x, y, r, g, b, a) \
237 EXPECT_NE(angle::MakeGLColor(r, g, b, a), angle::ReadColor(x, y))
238
239 #define EXPECT_PIXEL_32F_EQ(x, y, r, g, b, a) \
240 EXPECT_EQ(angle::MakeGLColor32F(r, g, b, a), angle::ReadColor32F(x, y))
241
242 #define EXPECT_PIXEL_ALPHA_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor(x, y).A)
243
244 #define EXPECT_PIXEL_ALPHA32F_EQ(x, y, a) EXPECT_EQ(a, angle::ReadColor32F(x, y).A)
245
246 #define EXPECT_PIXEL_COLOR_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor(x, y))
247 #define EXPECT_PIXEL_COLOR_EQ_VEC2(vec2, angleColor) \
248 EXPECT_EQ(angleColor, \
249 angle::ReadColor(static_cast<GLint>(vec2.x()), static_cast<GLint>(vec2.y())))
250
251 #define EXPECT_PIXEL_COLOR32F_EQ(x, y, angleColor) EXPECT_EQ(angleColor, angle::ReadColor32F(x, y))
252
253 #define EXPECT_PIXEL_RECT_EQ(x, y, width, height, color) \
254 do \
255 { \
256 std::vector<GLColor> actualColors((width) * (height)); \
257 glReadPixels((x), (y), (width), (height), GL_RGBA, GL_UNSIGNED_BYTE, actualColors.data()); \
258 std::vector<GLColor> expectedColors((width) * (height), color); \
259 EXPECT_EQ(expectedColors, actualColors); \
260 } while (0)
261
262 #define EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, ctype, format, type) \
263 do \
264 { \
265 ctype pixel[4]; \
266 glReadPixels((x), (y), 1, 1, format, type, pixel); \
267 EXPECT_GL_NO_ERROR(); \
268 EXPECT_NEAR((r), pixel[0], abs_error); \
269 EXPECT_NEAR((g), pixel[1], abs_error); \
270 EXPECT_NEAR((b), pixel[2], abs_error); \
271 EXPECT_NEAR((a), pixel[3], abs_error); \
272 } while (0)
273
274 #define EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, ctype, format, type) \
275 do \
276 { \
277 ctype pixel[4]; \
278 glReadPixels((x), (y), 1, 1, format, type, pixel); \
279 EXPECT_GL_NO_ERROR(); \
280 EXPECT_EQ((r), pixel[0]); \
281 EXPECT_EQ((g), pixel[1]); \
282 EXPECT_EQ((b), pixel[2]); \
283 EXPECT_EQ((a), pixel[3]); \
284 } while (0)
285
286 #define EXPECT_PIXEL_NEAR(x, y, r, g, b, a, abs_error) \
287 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLubyte, GL_RGBA, GL_UNSIGNED_BYTE)
288
289 #define EXPECT_PIXEL_32F_NEAR(x, y, r, g, b, a, abs_error) \
290 EXPECT_PIXEL_NEAR_HELPER(x, y, r, g, b, a, abs_error, GLfloat, GL_RGBA, GL_FLOAT)
291
292 #define EXPECT_PIXEL_8I(x, y, r, g, b, a) \
293 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLbyte, GL_RGBA_INTEGER, GL_BYTE)
294
295 #define EXPECT_PIXEL_8UI(x, y, r, g, b, a) \
296 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLubyte, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE)
297
298 #define EXPECT_PIXEL_16UI(x, y, r, g, b, a) \
299 EXPECT_PIXEL_EQ_HELPER(x, y, r, g, b, a, GLushort, GL_RGBA, GL_UNSIGNED_SHORT)
300
301 #define EXPECT_PIXEL_16UI_COLOR(x, y, color) \
302 EXPECT_PIXEL_16UI(x, y, color.R, color.G, color.B, color.A)
303
304 // TODO(jmadill): Figure out how we can use GLColor's nice printing with EXPECT_NEAR.
305 #define EXPECT_PIXEL_COLOR_NEAR(x, y, angleColor, abs_error) \
306 EXPECT_PIXEL_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
307
308 #define EXPECT_PIXEL_COLOR32F_NEAR(x, y, angleColor, abs_error) \
309 EXPECT_PIXEL32F_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
310
311 #define EXPECT_COLOR_NEAR(expected, actual, abs_error) \
312 do \
313 { \
314 EXPECT_NEAR(expected.R, actual.R, abs_error); \
315 EXPECT_NEAR(expected.G, actual.G, abs_error); \
316 EXPECT_NEAR(expected.B, actual.B, abs_error); \
317 EXPECT_NEAR(expected.A, actual.A, abs_error); \
318 } while (0)
319 #define EXPECT_PIXEL32F_NEAR(x, y, r, g, b, a, abs_error) \
320 do \
321 { \
322 GLfloat pixel[4]; \
323 glReadPixels((x), (y), 1, 1, GL_RGBA, GL_FLOAT, pixel); \
324 EXPECT_GL_NO_ERROR(); \
325 EXPECT_NEAR((r), pixel[0], abs_error); \
326 EXPECT_NEAR((g), pixel[1], abs_error); \
327 EXPECT_NEAR((b), pixel[2], abs_error); \
328 EXPECT_NEAR((a), pixel[3], abs_error); \
329 } while (0)
330
331 #define EXPECT_PIXEL_COLOR32F_NEAR(x, y, angleColor, abs_error) \
332 EXPECT_PIXEL32F_NEAR(x, y, angleColor.R, angleColor.G, angleColor.B, angleColor.A, abs_error)
333
334 #define EXPECT_PIXEL_STENCIL_EQ(x, y, expected) \
335 do \
336 { \
337 GLubyte actual; \
338 glReadPixels((x), (y), 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, &actual); \
339 EXPECT_GL_NO_ERROR(); \
340 EXPECT_EQ((expected), actual); \
341 } while (0)
342
343 class ANGLETestBase;
344 class EGLWindow;
345 class GLWindowBase;
346 class OSWindow;
347 class WGLWindow;
348
349 struct TestPlatformContext final : private angle::NonCopyable
350 {
351 bool ignoreMessages = false;
352 bool warningsAsErrors = false;
353 ANGLETestBase *currentTest = nullptr;
354 };
355
356 class ANGLETestBase
357 {
358 protected:
359 ANGLETestBase(const angle::PlatformParameters ¶ms);
360 virtual ~ANGLETestBase();
361
362 public:
363 void setWindowVisible(OSWindow *osWindow, bool isVisible);
364
365 static void ReleaseFixtures();
366
isSwiftshader()367 bool isSwiftshader() const
368 {
369 // Renderer might be swiftshader even if local swiftshader not used.
370 return mCurrentParams->isSwiftshader() || angle::IsSwiftshaderDevice();
371 }
372
enableDebugLayers()373 bool enableDebugLayers() const
374 {
375 return mCurrentParams->eglParameters.debugLayersEnabled != EGL_FALSE;
376 }
377
378 protected:
379 void ANGLETestSetUp();
380 void ANGLETestPreTearDown();
381 void ANGLETestTearDown();
382
383 virtual void swapBuffers();
384
385 void setupQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale);
386 void setupIndexedQuadVertexBuffer(GLfloat positionAttribZ, GLfloat positionAttribXYScale);
387 void setupIndexedQuadIndexBuffer();
388
389 void drawQuad(GLuint program, const std::string &positionAttribName, GLfloat positionAttribZ);
390 void drawQuad(GLuint program,
391 const std::string &positionAttribName,
392 GLfloat positionAttribZ,
393 GLfloat positionAttribXYScale);
394 void drawQuad(GLuint program,
395 const std::string &positionAttribName,
396 GLfloat positionAttribZ,
397 GLfloat positionAttribXYScale,
398 bool useVertexBuffer);
399 void drawQuadInstanced(GLuint program,
400 const std::string &positionAttribName,
401 GLfloat positionAttribZ,
402 GLfloat positionAttribXYScale,
403 bool useVertexBuffer,
404 GLuint numInstances);
405 void drawPatches(GLuint program,
406 const std::string &positionAttribName,
407 GLfloat positionAttribZ,
408 GLfloat positionAttribXYScale,
409 bool useVertexBuffer);
410
411 void drawQuadPPO(GLuint vertProgram,
412 const std::string &positionAttribName,
413 const GLfloat positionAttribZ,
414 const GLfloat positionAttribXYScale);
415
416 static std::array<angle::Vector3, 6> GetQuadVertices();
417 static std::array<GLushort, 6> GetQuadIndices();
418 static std::array<angle::Vector3, 4> GetIndexedQuadVertices();
419
420 void drawIndexedQuad(GLuint program,
421 const std::string &positionAttribName,
422 GLfloat positionAttribZ);
423 void drawIndexedQuad(GLuint program,
424 const std::string &positionAttribName,
425 GLfloat positionAttribZ,
426 GLfloat positionAttribXYScale);
427 void drawIndexedQuad(GLuint program,
428 const std::string &positionAttribName,
429 GLfloat positionAttribZ,
430 GLfloat positionAttribXYScale,
431 bool useBufferObject);
432
433 void drawIndexedQuad(GLuint program,
434 const std::string &positionAttribName,
435 GLfloat positionAttribZ,
436 GLfloat positionAttribXYScale,
437 bool useBufferObject,
438 bool restrictedRange);
439
440 void draw2DTexturedQuad(GLfloat positionAttribZ,
441 GLfloat positionAttribXYScale,
442 bool useVertexBuffer);
443
444 // The layer parameter chooses the 3D texture layer to sample from.
445 void draw3DTexturedQuad(GLfloat positionAttribZ,
446 GLfloat positionAttribXYScale,
447 bool useVertexBuffer,
448 float layer);
449
450 void setWindowWidth(int width);
451 void setWindowHeight(int height);
452 void setConfigRedBits(int bits);
453 void setConfigGreenBits(int bits);
454 void setConfigBlueBits(int bits);
455 void setConfigAlphaBits(int bits);
456 void setConfigDepthBits(int bits);
457 void setConfigStencilBits(int bits);
458 void setConfigComponentType(EGLenum componentType);
459 void setMultisampleEnabled(bool enabled);
460 void setSamples(EGLint samples);
461 void setDebugEnabled(bool enabled);
462 void setNoErrorEnabled(bool enabled);
463 void setWebGLCompatibilityEnabled(bool webglCompatibility);
464 void setExtensionsEnabled(bool extensionsEnabled);
465 void setRobustAccess(bool enabled);
466 void setBindGeneratesResource(bool bindGeneratesResource);
467 void setClientArraysEnabled(bool enabled);
468 void setRobustResourceInit(bool enabled);
469 void setContextProgramCacheEnabled(bool enabled);
470 void setContextResetStrategy(EGLenum resetStrategy);
471 void forceNewDisplay();
472
473 // Some EGL extension tests would like to defer the Context init until the test body.
474 void setDeferContextInit(bool enabled);
475
476 int getClientMajorVersion() const;
477 int getClientMinorVersion() const;
478
479 GLWindowBase *getGLWindow() const;
480 EGLWindow *getEGLWindow() const;
481 int getWindowWidth() const;
482 int getWindowHeight() const;
483
484 EGLint getPlatformRenderer() const;
485
486 void ignoreD3D11SDKLayersWarnings();
487
488 // Allows a test to be more restrictive about platform warnings.
489 void treatPlatformWarningsAsErrors();
490
getOSWindow()491 OSWindow *getOSWindow() { return mFixture->osWindow; }
492
493 GLuint get2DTexturedQuadProgram();
494
495 // Has a float uniform "u_layer" to choose the 3D texture layer.
496 GLuint get3DTexturedQuadProgram();
497
498 class ANGLE_NO_DISCARD ScopedIgnorePlatformMessages : angle::NonCopyable
499 {
500 public:
501 ScopedIgnorePlatformMessages();
502 ~ScopedIgnorePlatformMessages();
503 };
504
505 // Can be used before we get a GL context.
isGLRenderer()506 bool isGLRenderer() const
507 {
508 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE;
509 }
510
isGLESRenderer()511 bool isGLESRenderer() const
512 {
513 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE;
514 }
515
isD3D11Renderer()516 bool isD3D11Renderer() const
517 {
518 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE;
519 }
520
isVulkanRenderer()521 bool isVulkanRenderer() const
522 {
523 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE;
524 }
525
isVulkanSwiftshaderRenderer()526 bool isVulkanSwiftshaderRenderer() const
527 {
528 return mCurrentParams->getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE &&
529 mCurrentParams->isSwiftshader();
530 }
531
532 bool platformSupportsMultithreading() const;
533
534 bool mIsSetUp = false;
535
536 private:
537 void checkD3D11SDKLayersMessages();
538
539 void drawQuad(GLuint program,
540 const std::string &positionAttribName,
541 GLfloat positionAttribZ,
542 GLfloat positionAttribXYScale,
543 bool useVertexBuffer,
544 bool useInstancedDrawCalls,
545 bool useTessellationPatches,
546 GLuint numInstances);
547
548 void initOSWindow();
549
550 struct TestFixture
551 {
552 TestFixture();
553 ~TestFixture();
554
555 EGLWindow *eglWindow = nullptr;
556 WGLWindow *wglWindow = nullptr;
557 OSWindow *osWindow = nullptr;
558 ConfigParameters configParams;
559 uint32_t reuseCounter = 0;
560 };
561
562 int mWidth;
563 int mHeight;
564
565 bool mIgnoreD3D11SDKLayersWarnings;
566
567 // Used for indexed quad rendering
568 GLuint mQuadVertexBuffer;
569 GLuint mQuadIndexBuffer;
570
571 // Used for texture rendering.
572 GLuint m2DTexturedQuadProgram;
573 GLuint m3DTexturedQuadProgram;
574
575 bool mDeferContextInit;
576 bool mAlwaysForceNewDisplay;
577 bool mForceNewDisplay;
578
579 bool mSetUpCalled;
580 bool mTearDownCalled;
581
582 // Usually, we use an OS Window per "fixture" (a frontend and backend combination).
583 // This allows:
584 // 1. Reusing EGL Display on Windows.
585 // Other platforms have issues with display reuse even if a window per fixture is used.
586 // 2. Hiding only SwiftShader OS Window on Linux.
587 // OS Windows for other backends must be visible, to allow driver to communicate with X11.
588 // However, we must use a single OS Window for all backends on Android,
589 // since test Application can have only one window.
590 static OSWindow *mOSWindowSingleton;
591
592 static std::map<angle::PlatformParameters, TestFixture> gFixtures;
593 const angle::PlatformParameters *mCurrentParams;
594 TestFixture *mFixture;
595
596 RenderDoc mRenderDoc;
597
598 // Workaround for NVIDIA not being able to share a window with OpenGL and Vulkan.
599 static Optional<EGLint> mLastRendererType;
600 static Optional<angle::GLESDriverType> mLastLoadedDriver;
601 };
602
603 template <typename Params = angle::PlatformParameters>
604 class ANGLETestWithParam : public ANGLETestBase, public ::testing::TestWithParam<Params>
605 {
606 protected:
607 ANGLETestWithParam();
608
testSetUp()609 virtual void testSetUp() {}
testTearDown()610 virtual void testTearDown() {}
611
recreateTestFixture()612 void recreateTestFixture()
613 {
614 TearDown();
615 SetUp();
616 }
617
618 private:
SetUp()619 void SetUp() final
620 {
621 ANGLETestBase::ANGLETestSetUp();
622 if (mIsSetUp)
623 {
624 testSetUp();
625 }
626 }
627
TearDown()628 void TearDown() final
629 {
630 ANGLETestBase::ANGLETestPreTearDown();
631 if (mIsSetUp)
632 {
633 testTearDown();
634 }
635 ANGLETestBase::ANGLETestTearDown();
636 }
637 };
638
639 template <typename Params>
ANGLETestWithParam()640 ANGLETestWithParam<Params>::ANGLETestWithParam()
641 : ANGLETestBase(std::get<angle::PlatformParameters>(this->GetParam()))
642 {}
643
644 template <>
ANGLETestWithParam()645 inline ANGLETestWithParam<angle::PlatformParameters>::ANGLETestWithParam()
646 : ANGLETestBase(this->GetParam())
647 {}
648
649 // Note: this hack is not necessary in C++17. Once we switch to C++17, we can just rename
650 // ANGLETestWithParam to ANGLETest.
651 using ANGLETest = ANGLETestWithParam<>;
652
653 class ANGLETestEnvironment : public testing::Environment
654 {
655 public:
656 void SetUp() override;
657 void TearDown() override;
658
659 static angle::Library *GetDriverLibrary(angle::GLESDriverType driver);
660
661 private:
662 static angle::Library *GetAngleEGLLibrary();
663 static angle::Library *GetSystemEGLLibrary();
664 static angle::Library *GetSystemWGLLibrary();
665
666 // For loading entry points.
667 static std::unique_ptr<angle::Library> gAngleEGLLibrary;
668 static std::unique_ptr<angle::Library> gSystemEGLLibrary;
669 static std::unique_ptr<angle::Library> gSystemWGLLibrary;
670 };
671
672 extern angle::PlatformMethods gDefaultPlatformMethods;
673
674 #endif // ANGLE_TESTS_ANGLE_TEST_H_
675